@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()); } } }
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; } }); }
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; } } ); }
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; } } ); }
@Override public ConstantBindingBuilder annotatedWith( Class<? extends Annotation> annotationType) { return new ConstantBindingBuilderImpl( delegate.annotatedWith(annotationType)); }
@Override public ConstantBindingBuilder annotatedWith(Annotation annotation) { return new ConstantBindingBuilderImpl( delegate.annotatedWith(annotation)); }
public ConstantBindingBuilderAdapter(ConstantBindingBuilder guiceBuilder) { this.guiceBuilder = guiceBuilder; }
protected ConstantBindingBuilder bindProperty(String propertyName) { return bindConstant().annotatedWith(Names.named(propertyName)); }
@Override public ConstantBindingBuilder annotatedWith(Class<? extends Annotation> annotationType) { annotatedWithInternal(annotationType); return this; }
@Override public ConstantBindingBuilder annotatedWith(Annotation annotation) { annotatedWithInternal(annotation); return this; }
public ConstantBindingBuilder annotatedWith(Class<? extends Annotation> annotationType) { annotatedWithInternal(annotationType); return this; }
public ConstantBindingBuilder annotatedWith(Annotation annotation) { annotatedWithInternal(annotation); return this; }
private ConstantBindingBuilder bindProperty(String name) { return bindConstant().annotatedWith(named(name)); }
/** * 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)); }
/** * 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)); }