本文整理汇总了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));
}
}
示例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>");
}
示例3: getRealmName
import javax.enterprise.inject.Alternative; //导入依赖的package包/类
@Alternative
@Produces
@RealmName
public String getRealmName() {
return configuration.getRealmName();
}
示例4: getRealmResourceName
import javax.enterprise.inject.Alternative; //导入依赖的package包/类
@Alternative
@Produces
@RealmResourceName
public String getRealmResourceName() {
return configuration.getResourceName();
}
示例5: getRealmResourceSecret
import javax.enterprise.inject.Alternative; //导入依赖的package包/类
@Alternative
@Produces
@RealmResourceSecret
public String getRealmResourceSecret() {
return configuration.getResourceSecret();
}
示例6: getAuthServerUrl
import javax.enterprise.inject.Alternative; //导入依赖的package包/类
@Alternative
@Produces
@AuthServerUrl
public String getAuthServerUrl() {
return configuration.getAuthServerUrl();
}
示例7: buildService
import javax.enterprise.inject.Alternative; //导入依赖的package包/类
@Produces
@Alternative
public BuildService buildService() {
return mock(BuildService.class);
}
示例8: projectService
import javax.enterprise.inject.Alternative; //导入依赖的package包/类
@Produces
@Alternative
public ProjectService<Project> projectService() {
return mock(ProjectService.class);
}
示例9: projectProjectFactory
import javax.enterprise.inject.Alternative; //导入依赖的package包/类
@Produces
@Alternative
public ProjectFactory<Project> projectProjectFactory() {
return mock(ProjectFactory.class);
}
示例10: mock
import javax.enterprise.inject.Alternative; //导入依赖的package包/类
@Produces
@Alternative
public M2RepoService m2RepoService() {
return mock(M2RepoService.class);
}
示例11: servletContext
import javax.enterprise.inject.Alternative; //导入依赖的package包/类
@Produces
@Alternative
@Named("uf")
public ServletContext servletContext() {
return mock(ServletContext.class);
}
示例12: sessionInfo
import javax.enterprise.inject.Alternative; //导入依赖的package包/类
@Produces
@Alternative
public SessionInfo sessionInfo() {
return mock(SessionInfo.class);
}
示例13: getIdentity
import javax.enterprise.inject.Alternative; //导入依赖的package包/类
@Produces
@Alternative
public User getIdentity() {
return identity;
}
示例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));
}
示例15: getGreeting
import javax.enterprise.inject.Alternative; //导入依赖的package包/类
@Produces
@Alternative
public Greeting getGreeting() {
return new SimpleGreeting();
}