本文整理汇总了Java中com.google.inject.binder.ConstantBindingBuilder类的典型用法代码示例。如果您正苦于以下问题:Java ConstantBindingBuilder类的具体用法?Java ConstantBindingBuilder怎么用?Java ConstantBindingBuilder使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ConstantBindingBuilder类属于com.google.inject.binder包,在下文中一共展示了ConstantBindingBuilder类的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: configure
import com.google.inject.binder.ConstantBindingBuilder; //导入依赖的package包/类
@Override
protected void configure() {
Map<String, Object> config = parser.loadAsMap();
for (String name : config.keySet()) {
Object value = config.get(name);
ConstantBindingBuilder builder = bindConstant().annotatedWith(Names.named(name));
if (value instanceof String) {
builder.to((String)value);
} else if (value instanceof Integer) {
builder.to((Integer)value);
} else if (value instanceof Long) {
builder.to((Long)value);
} else if (value instanceof Boolean) {
builder.to((Boolean)value);
} else {
// TODO - throw more appropriate exception?
throw new RuntimeException("don't know how to bind constant to value of type" + value.getClass());
}
}
}
示例2: testBindConstantWithMultipleTargetsAddsError
import com.google.inject.binder.ConstantBindingBuilder; //导入依赖的package包/类
public void testBindConstantWithMultipleTargetsAddsError() {
checkModule(
new AbstractModule() {
@Override
protected void configure() {
ConstantBindingBuilder cbb = bindConstant().annotatedWith(SampleAnnotation.class);
cbb.to("A");
cbb.to("B");
}
},
new FailingElementVisitor() {
@Override
public <T> Void visit(Binding<T> command) {
return null;
}
},
new FailingElementVisitor() {
@Override
public Void visit(Message message) {
assertEquals("Constant value is set more than once.", message.getMessage());
assertNull(message.getCause());
assertContains(message.getSource(), getDeclaringSourcePart(ElementsTest.class));
return null;
}
});
}
示例3: testBindConstantWithMultipleTargetsAddsError
import com.google.inject.binder.ConstantBindingBuilder; //导入依赖的package包/类
public void testBindConstantWithMultipleTargetsAddsError() {
checkModule(
new AbstractModule() {
protected void configure() {
ConstantBindingBuilder cbb = bindConstant().annotatedWith(SampleAnnotation.class);
cbb.to("A");
cbb.to("B");
}
},
new FailingElementVisitor() {
@Override public <T> Void visit(Binding<T> command) {
return null;
}
},
new FailingElementVisitor() {
@Override public Void visit(Message message) {
assertEquals("Constant value is set more than once.", message.getMessage());
assertNull(message.getCause());
assertContains(message.getSource(), getDeclaringSourcePart(ElementsTest.class));
return null;
}
}
);
}
示例4: testBindConstantWithMultipleTargetsAddsError
import com.google.inject.binder.ConstantBindingBuilder; //导入依赖的package包/类
public void testBindConstantWithMultipleTargetsAddsError() {
checkModule(
new AbstractModule() {
protected void configure() {
ConstantBindingBuilder cbb = bindConstant().annotatedWith(SampleAnnotation.class);
cbb.to("A");
cbb.to("B");
}
},
new FailingElementVisitor() {
@Override public <T> Void visit(Binding<T> command) {
return null;
}
},
new FailingElementVisitor() {
@Override public Void visit(Message message) {
assertEquals("Constant value is set more than once.", message.getMessage());
assertNull(message.getCause());
assertContains(message.getSource(), "ElementsTest.java");
return null;
}
}
);
}
示例5: annotatedWith
import com.google.inject.binder.ConstantBindingBuilder; //导入依赖的package包/类
@Override
public ConstantBindingBuilder annotatedWith(
Class<? extends Annotation> annotationType) {
return new ConstantBindingBuilderImpl(
delegate.annotatedWith(annotationType));
}
示例6: ConstantBindingBuilderAdapter
import com.google.inject.binder.ConstantBindingBuilder; //导入依赖的package包/类
public ConstantBindingBuilderAdapter(ConstantBindingBuilder guiceBuilder) {
this.guiceBuilder = guiceBuilder;
}
示例7: bindProperty
import com.google.inject.binder.ConstantBindingBuilder; //导入依赖的package包/类
protected ConstantBindingBuilder bindProperty(String propertyName) {
return bindConstant().annotatedWith(Names.named(propertyName));
}
示例8: annotatedWith
import com.google.inject.binder.ConstantBindingBuilder; //导入依赖的package包/类
@Override
public ConstantBindingBuilder annotatedWith(Class<? extends Annotation> annotationType) {
annotatedWithInternal(annotationType);
return this;
}
示例9: annotatedWith
import com.google.inject.binder.ConstantBindingBuilder; //导入依赖的package包/类
public ConstantBindingBuilder annotatedWith(Class<? extends Annotation> annotationType) {
annotatedWithInternal(annotationType);
return this;
}
示例10: bindProperty
import com.google.inject.binder.ConstantBindingBuilder; //导入依赖的package包/类
private ConstantBindingBuilder bindProperty(String name) {
return bindConstant().annotatedWith(named(name));
}
开发者ID:Adobe-Marketing-Cloud,项目名称:cq-java-securecq-maven-plugin,代码行数:4,代码来源:SecureCQComponentsModule.java
示例11: bindParameter
import com.google.inject.binder.ConstantBindingBuilder; //导入依赖的package包/类
/**
* Call this method in
* {@link org.directwebremoting.guice.AbstractDwrModule#configure configure}
* to create a binding for a DWR parameter.
* @param paramName a parameter name supported by DWR
*/
protected ConstantBindingBuilder bindParameter(ParamName paramName)
{
return bindConstant()
.annotatedWith(new InitParamImpl(paramName));
}
示例12: bindParameter
import com.google.inject.binder.ConstantBindingBuilder; //导入依赖的package包/类
/**
* Call this method in
* {@link org.directwebremoting.guice.AbstractDwrModule#configure configure}
* to create a binding for a DWR parameter.
* @param paramName a parameter name supported by DWR
*/
protected ConstantBindingBuilder bindParameter(ParamName paramName)
{
return bindConstant()
.annotatedWith(new InitParamImpl(paramName));
}
示例13: bindConstantNamed
import com.google.inject.binder.ConstantBindingBuilder; //导入依赖的package包/类
/**
* Binds a constant with the qualifier annotation {@code @@Named(name)}, where {@code name} is the given name.
* This is an abbreviation for {@code bindConstant().annotatedWith(Names.named(named))}.
*/
default ConstantBindingBuilder bindConstantNamed(String name) {
return binder().bindConstant().annotatedWith(named(name));
}