本文整理汇总了Java中com.google.inject.spi.BindingScopingVisitor类的典型用法代码示例。如果您正苦于以下问题:Java BindingScopingVisitor类的具体用法?Java BindingScopingVisitor怎么用?Java BindingScopingVisitor使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
BindingScopingVisitor类属于com.google.inject.spi包,在下文中一共展示了BindingScopingVisitor类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: applyScoping
import com.google.inject.spi.BindingScopingVisitor; //导入依赖的package包/类
protected void applyScoping(Binding<?> binding, final ScopedBindingBuilder scopedBindingBuilder) {
binding.acceptScopingVisitor(new BindingScopingVisitor<Void>() {
public Void visitEagerSingleton() {
if (scopedBindingBuilder != null) {
scopedBindingBuilder.asEagerSingleton();
}
return null;
}
public Void visitScope(Scope scope) {
scopedBindingBuilder.in(scope);
return null;
}
public Void visitScopeAnnotation(Class<? extends Annotation> scopeAnnotation) {
scopedBindingBuilder.in(scopeAnnotation);
return null;
}
public Void visitNoScoping() {
// do nothing
return null;
}
});
}
示例2: isSingleton
import com.google.inject.spi.BindingScopingVisitor; //导入依赖的package包/类
private static boolean isSingleton(Binding<?> binding) {
return binding.acceptScopingVisitor(new BindingScopingVisitor<Boolean>() {
@Override
public Boolean visitNoScoping() {
return false;
}
@Override
public Boolean visitScopeAnnotation(Class<? extends Annotation> visitedAnnotation) {
return visitedAnnotation.equals(Singleton.class);
}
@Override
public Boolean visitScope(Scope visitedScope) {
return visitedScope.equals(Scopes.SINGLETON);
}
@Override
public Boolean visitEagerSingleton() {
return true;
}
});
}
示例3: isWorkerScope
import com.google.inject.spi.BindingScopingVisitor; //导入依赖的package包/类
public static boolean isWorkerScope(Binding<?> binding) {
return binding.acceptScopingVisitor(new BindingScopingVisitor<Boolean>() {
public Boolean visitNoScoping() {
return false;
}
public Boolean visitScopeAnnotation(Class<? extends Annotation> visitedAnnotation) {
return visitedAnnotation == Worker.class;
}
public Boolean visitScope(Scope visitedScope) {
return visitedScope.getClass() == WorkerPoolScope.class;
}
public Boolean visitEagerSingleton() {
return false;
}
});
}
示例4: scoped
import com.google.inject.spi.BindingScopingVisitor; //导入依赖的package包/类
private static String scoped(final Binding<?> binding, final String statement) {
return binding.acceptScopingVisitor(new BindingScopingVisitor<String>() {
@Override
public String visitEagerSingleton() {
if (binding instanceof InstanceBinding<?>) {
return statement;
}
throw new DeguicifierException();
}
@Override
public String visitScope(Scope scope) {
return scopeFieldName(scope) + ".scope(null, " + guicify(statement) + ")";
}
@Override
public String visitScopeAnnotation(Class<? extends Annotation> scopeAnnotation) {
throw new DeguicifierException();
}
@Override
public String visitNoScoping() {
return statement;
}
});
}
示例5: getComponentScope
import com.google.inject.spi.BindingScopingVisitor; //导入依赖的package包/类
private ComponentScope getComponentScope(Key<?> key, Injector i) {
return i.getBinding(key).acceptScopingVisitor(new BindingScopingVisitor<ComponentScope>() {
@Override
public ComponentScope visitEagerSingleton() {
return ComponentScope.Singleton;
}
@Override
public ComponentScope visitScope(Scope theScope) {
ComponentScope cs = scopeMap.get(theScope);
return (cs != null) ? cs : ComponentScope.Undefined;
}
@Override
public ComponentScope visitScopeAnnotation(Class scopeAnnotation) {
// This method is not invoked for Injector bindings
throw new UnsupportedOperationException();
}
@Override
public ComponentScope visitNoScoping() {
return ComponentScope.PerRequest;
}
});
}
示例6: forAnnotation
import com.google.inject.spi.BindingScopingVisitor; //导入依赖的package包/类
public static Scoping forAnnotation(final Class<? extends Annotation> scopingAnnotation) {
if (scopingAnnotation == Singleton.class
|| scopingAnnotation == javax.inject.Singleton.class) {
return SINGLETON_ANNOTATION;
}
return new Scoping() {
@Override public <V> V acceptVisitor(BindingScopingVisitor<V> visitor) {
return visitor.visitScopeAnnotation(scopingAnnotation);
}
@Override public Class<? extends Annotation> getScopeAnnotation() {
return scopingAnnotation;
}
@Override public String toString() {
return scopingAnnotation.getName();
}
@Override public void applyTo(ScopedBindingBuilder scopedBindingBuilder) {
scopedBindingBuilder.in(scopingAnnotation);
}
};
}
示例7: forInstance
import com.google.inject.spi.BindingScopingVisitor; //导入依赖的package包/类
public static Scoping forInstance(final Scope scope) {
if (scope == Scopes.SINGLETON) {
return SINGLETON_INSTANCE;
}
return new Scoping() {
@Override public <V> V acceptVisitor(BindingScopingVisitor<V> visitor) {
return visitor.visitScope(scope);
}
@Override public Scope getScopeInstance() {
return scope;
}
@Override public String toString() {
return scope.toString();
}
@Override public void applyTo(ScopedBindingBuilder scopedBindingBuilder) {
scopedBindingBuilder.in(scope);
}
};
}
示例8: forAnnotation
import com.google.inject.spi.BindingScopingVisitor; //导入依赖的package包/类
public static Scoping forAnnotation(final Class<? extends Annotation> scopingAnnotation) {
if (scopingAnnotation == Singleton.class
|| scopingAnnotation == javax.inject.Singleton.class) {
return SINGLETON_ANNOTATION;
}
return new Scoping() {
public <V> V acceptVisitor(BindingScopingVisitor<V> visitor) {
return visitor.visitScopeAnnotation(scopingAnnotation);
}
@Override public Class<? extends Annotation> getScopeAnnotation() {
return scopingAnnotation;
}
@Override public String toString() {
return scopingAnnotation.getName();
}
public void applyTo(ScopedBindingBuilder scopedBindingBuilder) {
scopedBindingBuilder.in(scopingAnnotation);
}
};
}
示例9: forInstance
import com.google.inject.spi.BindingScopingVisitor; //导入依赖的package包/类
public static Scoping forInstance(final Scope scope) {
if (scope == Scopes.SINGLETON) {
return SINGLETON_INSTANCE;
}
return new Scoping() {
public <V> V acceptVisitor(BindingScopingVisitor<V> visitor) {
return visitor.visitScope(scope);
}
@Override public Scope getScopeInstance() {
return scope;
}
@Override public String toString() {
return scope.toString();
}
public void applyTo(ScopedBindingBuilder scopedBindingBuilder) {
scopedBindingBuilder.in(scope);
}
};
}
示例10: forAnnotation
import com.google.inject.spi.BindingScopingVisitor; //导入依赖的package包/类
public static Scoping forAnnotation(final Class<? extends Annotation> scopingAnnotation) {
if (scopingAnnotation == Singleton.class || scopingAnnotation == javax.inject.Singleton.class) {
return SINGLETON_ANNOTATION;
}
return new Scoping() {
@Override
public <V> V acceptVisitor(BindingScopingVisitor<V> visitor) {
return visitor.visitScopeAnnotation(scopingAnnotation);
}
@Override
public Class<? extends Annotation> getScopeAnnotation() {
return scopingAnnotation;
}
@Override
public String toString() {
return scopingAnnotation.getName();
}
@Override
public void applyTo(ScopedBindingBuilder scopedBindingBuilder) {
scopedBindingBuilder.in(scopingAnnotation);
}
};
}
示例11: forInstance
import com.google.inject.spi.BindingScopingVisitor; //导入依赖的package包/类
public static Scoping forInstance(final Scope scope) {
if (scope == Scopes.SINGLETON) {
return SINGLETON_INSTANCE;
} else if (scope == Scopes.NO_SCOPE) {
return EXPLICITLY_UNSCOPED;
}
return new Scoping() {
@Override
public <V> V acceptVisitor(BindingScopingVisitor<V> visitor) {
return visitor.visitScope(scope);
}
@Override
public Scope getScopeInstance() {
return scope;
}
@Override
public String toString() {
return scope.toString();
}
@Override
public void applyTo(ScopedBindingBuilder scopedBindingBuilder) {
scopedBindingBuilder.in(scope);
}
};
}
示例12: buildServiceDependencyManager
import com.google.inject.spi.BindingScopingVisitor; //导入依赖的package包/类
public static ServiceDependencyManager buildServiceDependencyManager(
final Injector injector,
Iterable<Key<? extends BaseService<?>>> serviceKeys
) {
final Multimap<ResolvedBinding<BaseService<?>>, ResolvedBinding<? extends BaseService<?>>> graph = computeInterdependencies(
serviceKeys,
injector);
for (ResolvedBinding<? extends BaseService<?>> binding : graph.values()) {
checkArgument(binding.getBinding().acceptScopingVisitor(new BindingScopingVisitor<Boolean>() {
public Boolean visitEagerSingleton() { return true; }
public Boolean visitScope(Scope scope) { return scope == Scopes.SINGLETON; }
public Boolean visitScopeAnnotation(Class<? extends Annotation> scopeAnnotation) {
return scopeAnnotation.equals(Singleton.class);
}
public Boolean visitNoScoping() { return false; }
}), "Managed service must be bound as Singleton", binding);
}
return ServiceDependencyManager.buildServicesWithDependencies(
ResolvedBinding.<BaseService<?>>resolver(injector)
.andThen(ResolvedBinding::get)
.transform(serviceKeys)
.toList(),
Functional.funPairs(graph.entries())
.mapKeys(ResolvedBinding::get)
.mapValues((F<ResolvedBinding<? extends BaseService<?>>, BaseService<?>>) binding -> binding.get())
.toList()
);
}
示例13: servletPath
import com.google.inject.spi.BindingScopingVisitor; //导入依赖的package包/类
private void servletPath(
final String requestPath, String mapping, final String expectedServletPath)
throws IOException, ServletException {
Injector injector = createMock(Injector.class);
Binding binding = createMock(Binding.class);
HttpServletRequest request = createMock(HttpServletRequest.class);
HttpServletResponse response = createMock(HttpServletResponse.class);
expect(binding.acceptScopingVisitor((BindingScopingVisitor) anyObject())).andReturn(true);
expect(injector.getBinding(Key.get(HttpServlet.class))).andReturn(binding);
final boolean[] run = new boolean[1];
//get an instance of this servlet
expect(injector.getInstance(Key.get(HttpServlet.class)))
.andReturn(
new HttpServlet() {
@Override
protected void service(
HttpServletRequest servletRequest, HttpServletResponse httpServletResponse)
throws ServletException, IOException {
final String path = servletRequest.getServletPath();
assertEquals(
String.format("expected [%s] but was [%s]", expectedServletPath, path),
expectedServletPath,
path);
run[0] = true;
}
});
expect(request.getServletPath()).andReturn(requestPath);
replay(injector, binding, request);
ServletDefinition servletDefinition =
new ServletDefinition(
Key.get(HttpServlet.class),
UriPatternType.get(UriPatternType.SERVLET, mapping),
new HashMap<String, String>(),
null);
servletDefinition.init(null, injector, Sets.<HttpServlet>newIdentityHashSet());
servletDefinition.doService(request, response);
assertTrue("Servlet did not run!", run[0]);
verify(injector, binding, request);
}
示例14: pathInfoWithServletStyleMatching
import com.google.inject.spi.BindingScopingVisitor; //导入依赖的package包/类
private void pathInfoWithServletStyleMatching(
final String requestUri,
final String contextPath,
String mapping,
final String expectedPathInfo,
final String servletPath)
throws IOException, ServletException {
Injector injector = createMock(Injector.class);
Binding binding = createMock(Binding.class);
HttpServletRequest request = createMock(HttpServletRequest.class);
HttpServletResponse response = createMock(HttpServletResponse.class);
expect(binding.acceptScopingVisitor((BindingScopingVisitor) anyObject())).andReturn(true);
expect(injector.getBinding(Key.get(HttpServlet.class))).andReturn(binding);
final boolean[] run = new boolean[1];
//get an instance of this servlet
expect(injector.getInstance(Key.get(HttpServlet.class)))
.andReturn(
new HttpServlet() {
@Override
protected void service(
HttpServletRequest servletRequest, HttpServletResponse httpServletResponse)
throws ServletException, IOException {
final String path = servletRequest.getPathInfo();
if (null == expectedPathInfo) {
assertNull(
String.format("expected [%s] but was [%s]", expectedPathInfo, path), path);
} else {
assertEquals(
String.format("expected [%s] but was [%s]", expectedPathInfo, path),
expectedPathInfo,
path);
}
//assert memoizer
//noinspection StringEquality
assertSame("memo field did not work", path, servletRequest.getPathInfo());
run[0] = true;
}
});
expect(request.getRequestURI()).andReturn(requestUri);
expect(request.getServletPath()).andReturn(servletPath).anyTimes();
expect(request.getContextPath()).andReturn(contextPath);
expect(request.getAttribute(REQUEST_DISPATCHER_REQUEST)).andReturn(null);
replay(injector, binding, request);
ServletDefinition servletDefinition =
new ServletDefinition(
Key.get(HttpServlet.class),
UriPatternType.get(UriPatternType.SERVLET, mapping),
new HashMap<String, String>(),
null);
servletDefinition.init(null, injector, Sets.<HttpServlet>newIdentityHashSet());
servletDefinition.doService(request, response);
assertTrue("Servlet did not run!", run[0]);
verify(injector, binding, request);
}
示例15: pathInfoWithRegexMatching
import com.google.inject.spi.BindingScopingVisitor; //导入依赖的package包/类
public final void pathInfoWithRegexMatching(
final String requestUri,
final String contextPath,
String mapping,
final String expectedPathInfo,
final String servletPath)
throws IOException, ServletException {
Injector injector = createMock(Injector.class);
Binding binding = createMock(Binding.class);
HttpServletRequest request = createMock(HttpServletRequest.class);
HttpServletResponse response = createMock(HttpServletResponse.class);
expect(binding.acceptScopingVisitor((BindingScopingVisitor) anyObject())).andReturn(true);
expect(injector.getBinding(Key.get(HttpServlet.class))).andReturn(binding);
final boolean[] run = new boolean[1];
//get an instance of this servlet
expect(injector.getInstance(Key.get(HttpServlet.class)))
.andReturn(
new HttpServlet() {
@Override
protected void service(
HttpServletRequest servletRequest, HttpServletResponse httpServletResponse)
throws ServletException, IOException {
final String path = servletRequest.getPathInfo();
if (null == expectedPathInfo) {
assertNull(
String.format("expected [%s] but was [%s]", expectedPathInfo, path), path);
} else {
assertEquals(
String.format("expected [%s] but was [%s]", expectedPathInfo, path),
expectedPathInfo,
path);
}
//assert memoizer
//noinspection StringEquality
assertSame("memo field did not work", path, servletRequest.getPathInfo());
run[0] = true;
}
});
expect(request.getRequestURI()).andReturn(requestUri);
expect(request.getServletPath()).andReturn(servletPath).anyTimes();
expect(request.getContextPath()).andReturn(contextPath);
expect(request.getAttribute(REQUEST_DISPATCHER_REQUEST)).andReturn(null);
replay(injector, binding, request);
ServletDefinition servletDefinition =
new ServletDefinition(
Key.get(HttpServlet.class),
UriPatternType.get(UriPatternType.REGEX, mapping),
new HashMap<String, String>(),
null);
servletDefinition.init(null, injector, Sets.<HttpServlet>newIdentityHashSet());
servletDefinition.doService(request, response);
assertTrue("Servlet did not run!", run[0]);
verify(injector, binding, request);
}