本文整理汇总了Java中com.google.inject.Injector.getProvider方法的典型用法代码示例。如果您正苦于以下问题:Java Injector.getProvider方法的具体用法?Java Injector.getProvider怎么用?Java Injector.getProvider使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.google.inject.Injector
的用法示例。
在下文中一共展示了Injector.getProvider方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: addAjaxFilters
import com.google.inject.Injector; //导入方法依赖的package包/类
private void addAjaxFilters()
{
Injector injector = getInjector();
for (Key<?> key : injector.getBindings().keySet())
{
Class<?> atype = key.getAnnotationType();
if (atype != null && Filtering.class.isAssignableFrom(atype))
{
String scriptName = Filtering.class.cast(key.getAnnotation()).value();
Provider<AjaxFilter> provider = injector.getProvider((Key<AjaxFilter>) key);
if ("".equals(scriptName))
{
addAjaxFilter(new InternalAjaxFilter(provider));
}
else
{
addAjaxFilter(new InternalAjaxFilter(provider), scriptName);
}
}
}
}
示例2: addConverters
import com.google.inject.Injector; //导入方法依赖的package包/类
private void addConverters()
{
Injector injector = getInjector();
for (Key<?> key : injector.getBindings().keySet())
{
Class<?> atype = key.getAnnotationType();
if (atype != null && Converting.class.isAssignableFrom(atype))
{
Converting ann = Converting.class.cast(key.getAnnotation());
String match = ann.match();
Class type = ann.type();
Class impl = ann.impl();
if ("".equals(match))
{
// Use the type name as a match string
match = type.getName();
}
Provider<Converter> provider = null;
Class cvtType;
if (impl.equals(Void.class))
{
// No impl specified, so there should be a Converter
// for this key.
provider = injector.getProvider((Key<Converter>) key);
cvtType = type;
}
else
{
// Impl class specified, so the Converter for key is
// bogus (the injected constructor InternalConverter
// is just to keep Guice happy); see the two-arg
// bindConversion method in AbstractDwrModule.
try
{
// First try looking for a Converter for impl in the bindings.
Key<Converter> ikey = Key.get(Converter.class, new ConvertingImpl(impl));
provider = injector.getProvider(ikey);
}
catch (RuntimeException e)
{
// Ignore any trouble we have looking things up.
}
if (provider == null)
{
// It wasn't in the bindings, so use a Provider that
// looks in the underlying ConverterManager.
final String implMatch = impl.getName();
provider = new Provider<Converter>()
{
public Converter get()
{
return getConverterByMatchString(implMatch);
}
};
}
cvtType = impl;
}
addConverter(match, new InternalConverter(cvtType, provider));
}
}
}