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


Java Alternative类代码示例

本文整理汇总了Java中javax.enterprise.inject.Alternative的典型用法代码示例。如果您正苦于以下问题:Java Alternative类的具体用法?Java Alternative怎么用?Java Alternative使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


Alternative类属于javax.enterprise.inject包,在下文中一共展示了Alternative类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: alternatives

import javax.enterprise.inject.Alternative; //导入依赖的package包/类
/**
 * Activates the alternatives declared with {@code @Beans} globally for the
 * application.
 * <p/>
 * For every types and every methods of every types declared with
 * {@link Beans#alternatives()}, the {@code Priority} annotation is added
 * so that the corresponding alternatives are selected globally for the
 * entire application.
 *
 * @see Beans
 */
private <T> void alternatives(@Observes @WithAnnotations(Alternative.class) ProcessAnnotatedType<T> pat) {
    AnnotatedType<T> type = pat.getAnnotatedType();

    if (!Arrays.asList(beans.alternatives()).contains(type.getJavaClass())) {
        // Only select globally the alternatives that are declared with @Beans
        return;
    }

    Set<AnnotatedMethod<? super T>> methods = new HashSet<>();
    for (AnnotatedMethod<? super T> method : type.getMethods()) {
        if (method.isAnnotationPresent(Alternative.class) && !method.isAnnotationPresent(Priority.class)) {
            methods.add(new AnnotatedMethodDecorator<>(method, PriorityLiteral.of(APPLICATION)));
        }
    }

    if (type.isAnnotationPresent(Alternative.class) && !type.isAnnotationPresent(Priority.class)) {
        pat.setAnnotatedType(new AnnotatedTypeDecorator<>(type, PriorityLiteral.of(APPLICATION), methods));
    } else if (!methods.isEmpty()) {
        pat.setAnnotatedType(new AnnotatedTypeDecorator<>(type, methods));
    }
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:33,代码来源:CamelCdiTestExtension.java

示例2: doGet

import javax.enterprise.inject.Alternative; //导入依赖的package包/类
@SuppressWarnings("serial")
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
	PrintWriter writer = response.getWriter();

	writer.print("<html><body>");

	String typeCalculator = request.getParameter("type");
	String rawAmmount = request.getParameter("ammount");

	if (rawAmmount == null) {
		writer.print("<p><strong>Invalid ammount!</strong></p>");
	} else {
		double ammount = Double.parseDouble(rawAmmount);

		Instance<Calculator> calc = null;
		
		// lookup the choosen calculator
		if("high".equals(typeCalculator)) {
			calc = calculator.select(new AnnotationLiteral<High>(){});
		} else if("low".equals(typeCalculator)) {
			calc = calculator.select(new AnnotationLiteral<Low>(){});
		} else {
			calc = calculator.select(new AnnotationLiteral<Alternative>(){});
		}
		
		writer.print("Ammount: " + ammount);
		writer.print("<br/>Calculator: " + calc.get());
		writer.print("<br/>Ammount with tax: " + calc.get().applyTax(ammount));
		writer.print("<br/>Ammount with discount: " + calc.get().applyDiscount(ammount));
	}
	writer.print("</body></html>");
}
 
开发者ID:wesleyegberto,项目名称:javaee_projects,代码行数:33,代码来源:ManuallyLookupServlet.java

示例3: getRealmName

import javax.enterprise.inject.Alternative; //导入依赖的package包/类
@Alternative
@Produces
@RealmName
public String getRealmName() {
    return configuration.getRealmName();
}
 
开发者ID:jpkrohling,项目名称:secret-store,代码行数:7,代码来源:ApplicationResources.java

示例4: getRealmResourceName

import javax.enterprise.inject.Alternative; //导入依赖的package包/类
@Alternative
@Produces
@RealmResourceName
public String getRealmResourceName() {
    return configuration.getResourceName();
}
 
开发者ID:jpkrohling,项目名称:secret-store,代码行数:7,代码来源:ApplicationResources.java

示例5: getRealmResourceSecret

import javax.enterprise.inject.Alternative; //导入依赖的package包/类
@Alternative
@Produces
@RealmResourceSecret
public String getRealmResourceSecret() {
    return configuration.getResourceSecret();
}
 
开发者ID:jpkrohling,项目名称:secret-store,代码行数:7,代码来源:ApplicationResources.java

示例6: getAuthServerUrl

import javax.enterprise.inject.Alternative; //导入依赖的package包/类
@Alternative
@Produces
@AuthServerUrl
public String getAuthServerUrl() {
    return configuration.getAuthServerUrl();
}
 
开发者ID:jpkrohling,项目名称:secret-store,代码行数:7,代码来源:ApplicationResources.java

示例7: buildService

import javax.enterprise.inject.Alternative; //导入依赖的package包/类
@Produces
@Alternative
public BuildService buildService() {
    return mock(BuildService.class);
}
 
开发者ID:kiegroup,项目名称:appformer,代码行数:6,代码来源:TestAppSetup.java

示例8: projectService

import javax.enterprise.inject.Alternative; //导入依赖的package包/类
@Produces
@Alternative
public ProjectService<Project> projectService() {
    return mock(ProjectService.class);
}
 
开发者ID:kiegroup,项目名称:appformer,代码行数:6,代码来源:TestAppSetup.java

示例9: projectProjectFactory

import javax.enterprise.inject.Alternative; //导入依赖的package包/类
@Produces
@Alternative
public ProjectFactory<Project> projectProjectFactory() {
    return mock(ProjectFactory.class);
}
 
开发者ID:kiegroup,项目名称:appformer,代码行数:6,代码来源:TestAppSetup.java

示例10: mock

import javax.enterprise.inject.Alternative; //导入依赖的package包/类
@Produces
@Alternative
public M2RepoService m2RepoService() {
    return mock(M2RepoService.class);
}
 
开发者ID:kiegroup,项目名称:appformer,代码行数:6,代码来源:TestAppSetup.java

示例11: servletContext

import javax.enterprise.inject.Alternative; //导入依赖的package包/类
@Produces
@Alternative
@Named("uf")
public ServletContext servletContext() {
    return mock(ServletContext.class);
}
 
开发者ID:kiegroup,项目名称:appformer,代码行数:7,代码来源:TestAppSetup.java

示例12: sessionInfo

import javax.enterprise.inject.Alternative; //导入依赖的package包/类
@Produces
@Alternative
public SessionInfo sessionInfo() {
    return mock(SessionInfo.class);
}
 
开发者ID:kiegroup,项目名称:appformer,代码行数:6,代码来源:GuvnorTestAppSetup.java

示例13: getIdentity

import javax.enterprise.inject.Alternative; //导入依赖的package包/类
@Produces
@Alternative
public User getIdentity() {
    return identity;
}
 
开发者ID:kiegroup,项目名称:appformer,代码行数:6,代码来源:TestIdentityFactory.java

示例14: getAnnotation

import javax.enterprise.inject.Alternative; //导入依赖的package包/类
@Override
public <X extends Annotation> X getAnnotation(final Class<X> annType) {
	return (X) (annType.equals(Alternative.class) ? OSCLITERAL : type.getAnnotation(annType));
}
 
开发者ID:ocelotds,项目名称:ocelot,代码行数:5,代码来源:SpringConfigurationWrapper.java

示例15: getGreeting

import javax.enterprise.inject.Alternative; //导入依赖的package包/类
@Produces
@Alternative
public Greeting getGreeting() {
	return new SimpleGreeting();
}
 
开发者ID:ftomassetti,项目名称:JavaIncrementalParser,代码行数:6,代码来源:ProducerMethodGreeting.java


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