當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。