Java 类com.google.inject.binder.ConstantBindingBuilder 实例源码

项目:open-kilda    文件:YamlConfigModule.java   
@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());
        }
    }
}
项目:open-kilda    文件:YamlConfigModule.java   
@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());
        }
    }
}
项目:guice    文件:ElementsTest.java   
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;
        }
      });
}
项目:guice-old    文件:ElementsTest.java   
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;
        }
      }
  );
}
项目:google-guice    文件:ElementsTest.java   
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;
        }
      }
  );
}
项目:salta    文件:AnnotatedConstantBindingBuilderImpl.java   
@Override
public ConstantBindingBuilder annotatedWith(
        Class<? extends Annotation> annotationType) {
    return new ConstantBindingBuilderImpl(
            delegate.annotatedWith(annotationType));
}
项目:salta    文件:AnnotatedConstantBindingBuilderImpl.java   
@Override
public ConstantBindingBuilder annotatedWith(Annotation annotation) {
    return new ConstantBindingBuilderImpl(
            delegate.annotatedWith(annotation));
}
项目:google-gin    文件:ConstantBindingBuilderAdapter.java   
public ConstantBindingBuilderAdapter(ConstantBindingBuilder guiceBuilder) {
  this.guiceBuilder = guiceBuilder;
}
项目:http-exposer    文件:HttpSystemMainModule.java   
protected ConstantBindingBuilder bindProperty(String propertyName) {
    return bindConstant().annotatedWith(Names.named(propertyName));
}
项目:guice    文件:ConstantBindingBuilderImpl.java   
@Override
public ConstantBindingBuilder annotatedWith(Class<? extends Annotation> annotationType) {
  annotatedWithInternal(annotationType);
  return this;
}
项目:guice    文件:ConstantBindingBuilderImpl.java   
@Override
public ConstantBindingBuilder annotatedWith(Annotation annotation) {
  annotatedWithInternal(annotation);
  return this;
}
项目:guice-old    文件:ConstantBindingBuilderImpl.java   
public ConstantBindingBuilder annotatedWith(Class<? extends Annotation> annotationType) {
  annotatedWithInternal(annotationType);
  return this;
}
项目:guice-old    文件:ConstantBindingBuilderImpl.java   
public ConstantBindingBuilder annotatedWith(Annotation annotation) {
  annotatedWithInternal(annotation);
  return this;
}
项目:cq-java-securecq-maven-plugin    文件:SecureCQComponentsModule.java   
private ConstantBindingBuilder bindProperty(String name) {
    return bindConstant().annotatedWith(named(name));
}
项目:google-guice    文件:ConstantBindingBuilderImpl.java   
public ConstantBindingBuilder annotatedWith(Class<? extends Annotation> annotationType) {
  annotatedWithInternal(annotationType);
  return this;
}
项目:google-guice    文件:ConstantBindingBuilderImpl.java   
public ConstantBindingBuilder annotatedWith(Annotation annotation) {
  annotatedWithInternal(annotation);
  return this;
}
项目:parabuild-ci    文件:AbstractDwrModule.java   
/**
 * 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));
}
项目:dwr    文件:AbstractDwrModule.java   
/**
 * 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));
}
项目:neuron-di    文件:BinderLike.java   
/**
 * 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));
}