本文整理汇总了Java中com.google.inject.Scopes.isCircularProxy方法的典型用法代码示例。如果您正苦于以下问题:Java Scopes.isCircularProxy方法的具体用法?Java Scopes.isCircularProxy怎么用?Java Scopes.isCircularProxy使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.google.inject.Scopes
的用法示例。
在下文中一共展示了Scopes.isCircularProxy方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: scope
import com.google.inject.Scopes; //导入方法依赖的package包/类
@Override
public <T> Provider<T> scope(Key<T> key, Provider<T> unscoped) {
return () -> {
Context context = contextRef.get();
if (null != context) {
@SuppressWarnings("unchecked")
T t = (T) context.objectsMap.get(key);
if (t == null) {
t = unscoped.get();
if (!Scopes.isCircularProxy(t)) {
context.objectsMap.put(key, t);
}
}
return t;
} else {
throw new OutOfScopeException("Not currently in a document scope");
}
};
}
示例2: scope
import com.google.inject.Scopes; //导入方法依赖的package包/类
public <T> Provider<T> scope(final Key<T> key, final Provider<T> unscoped) {
return () -> {
Map<Key<?>, Object> scopedObjects = getScopedObjects(key);
@SuppressWarnings("unchecked")
T current = (T) scopedObjects.get(key);
if (current == null && !scopedObjects.containsKey(key)) {
current = unscoped.get();
// don't remember proxies; these exist only to serve circular dependencies
if (Scopes.isCircularProxy(current)) {
return current;
}
scopedObjects.put(key, current);
}
return current;
};
}
示例3: provide
import com.google.inject.Scopes; //导入方法依赖的package包/类
public <T> T provide(Key<T> key, Provider<T> provider) {
T t = (T) map.get(key);
if(t != null) return t;
t = provider.get();
if(!Scopes.isCircularProxy(t)) {
store(key, t);
}
return t;
}
示例4: scope
import com.google.inject.Scopes; //导入方法依赖的package包/类
@Override
public <T> Provider<T> scope(Key<T> key, Provider<T> unscoped) {
final String name = key.toString();
return new Provider<T>() {
@Override
public T get() {
final FacesContext facesContext = FacesContext.getCurrentInstance();
final UIViewRoot viewRoot = facesContext.getViewRoot();
// fallback if no view is active
if (viewRoot == null) {
return unscoped.get();
}
final Map<String, Object> viewMap = viewRoot.getViewMap(true);
synchronized (viewMap) {
Object obj = viewMap.get(name);
if (obj == NullObject.INSTANCE) {
return null;
}
@SuppressWarnings("unchecked")
T t = (T) obj;
if (t == null) {
t = unscoped.get();
if (!Scopes.isCircularProxy(t)) {
viewRoot.getViewMap().put(name, t == null
? NullObject.INSTANCE
: t);
}
}
return t;
}
}
@Override
public String toString() {
return String.format("%s[%s]", unscoped, ViewScopeImpl.this);
}
};
}