当前位置: 首页>>代码示例>>Java>>正文


Java ConstantBindingBuilder类代码示例

本文整理汇总了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());
        }
	}
}
 
开发者ID:telstra,项目名称:open-kilda,代码行数:23,代码来源:YamlConfigModule.java

示例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;
        }
      });
}
 
开发者ID:google,项目名称:guice,代码行数:27,代码来源:ElementsTest.java

示例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;
        }
      }
  );
}
 
开发者ID:cgruber,项目名称:guice-old,代码行数:27,代码来源:ElementsTest.java

示例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;
        }
      }
  );
}
 
开发者ID:utopiazh,项目名称:google-guice,代码行数:27,代码来源:ElementsTest.java

示例5: annotatedWith

import com.google.inject.binder.ConstantBindingBuilder; //导入依赖的package包/类
@Override
public ConstantBindingBuilder annotatedWith(
        Class<? extends Annotation> annotationType) {
    return new ConstantBindingBuilderImpl(
            delegate.annotatedWith(annotationType));
}
 
开发者ID:ruediste,项目名称:salta,代码行数:7,代码来源:AnnotatedConstantBindingBuilderImpl.java

示例6: ConstantBindingBuilderAdapter

import com.google.inject.binder.ConstantBindingBuilder; //导入依赖的package包/类
public ConstantBindingBuilderAdapter(ConstantBindingBuilder guiceBuilder) {
  this.guiceBuilder = guiceBuilder;
}
 
开发者ID:google-code-export,项目名称:google-gin,代码行数:4,代码来源:ConstantBindingBuilderAdapter.java

示例7: bindProperty

import com.google.inject.binder.ConstantBindingBuilder; //导入依赖的package包/类
protected ConstantBindingBuilder bindProperty(String propertyName) {
    return bindConstant().annotatedWith(Names.named(propertyName));
}
 
开发者ID:bioko,项目名称:http-exposer,代码行数:4,代码来源:HttpSystemMainModule.java

示例8: annotatedWith

import com.google.inject.binder.ConstantBindingBuilder; //导入依赖的package包/类
@Override
public ConstantBindingBuilder annotatedWith(Class<? extends Annotation> annotationType) {
  annotatedWithInternal(annotationType);
  return this;
}
 
开发者ID:google,项目名称:guice,代码行数:6,代码来源:ConstantBindingBuilderImpl.java

示例9: annotatedWith

import com.google.inject.binder.ConstantBindingBuilder; //导入依赖的package包/类
public ConstantBindingBuilder annotatedWith(Class<? extends Annotation> annotationType) {
  annotatedWithInternal(annotationType);
  return this;
}
 
开发者ID:cgruber,项目名称:guice-old,代码行数:5,代码来源:ConstantBindingBuilderImpl.java

示例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));
}
 
开发者ID:parabuild-ci,项目名称:parabuild-ci,代码行数:12,代码来源:AbstractDwrModule.java

示例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));
}
 
开发者ID:directwebremoting,项目名称:dwr,代码行数:12,代码来源:AbstractDwrModule.java

示例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));
}
 
开发者ID:christian-schlichtherle,项目名称:neuron-di,代码行数:8,代码来源:BinderLike.java


注:本文中的com.google.inject.binder.ConstantBindingBuilder类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。