本文整理汇总了Java中javax.enterprise.inject.Default类的典型用法代码示例。如果您正苦于以下问题:Java Default类的具体用法?Java Default怎么用?Java Default使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Default类属于javax.enterprise.inject包,在下文中一共展示了Default类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: afterBeanDiscovery
import javax.enterprise.inject.Default; //导入依赖的package包/类
void afterBeanDiscovery(@Observes AfterBeanDiscovery event, BeanManager beanManager) {
final CommandContextImpl commandContext = new CommandContextImpl();
// Register the command context
event.addContext(commandContext);
// Register the command context bean using CDI 2 configurators API
event.addBean()
.addType(CommandContext.class)
.createWith(ctx -> new InjectableCommandContext(commandContext, beanManager))
.addQualifier(Default.Literal.INSTANCE)
.scope(Dependent.class)
.beanClass(CommandExtension.class);
// Register the CommandExecution bean using CDI 2 configurators API
event.addBean()
.createWith(ctx -> commandContext.getCurrentCommandExecution())
.addType(CommandExecution.class)
.addQualifier(Default.Literal.INSTANCE)
.scope(CommandScoped.class)
.beanClass(CommandExtension.class);
}
示例2: index
import javax.enterprise.inject.Default; //导入依赖的package包/类
@Produces
@DeploymentScoped
@Default
IndexView index() {
Indexer indexer = new Indexer();
Map<ArchivePath, Node> c = context.getCurrentArchive().getContent();
try {
for (Map.Entry<ArchivePath, Node> each : c.entrySet()) {
if (each.getKey().get().endsWith(CLASS_SUFFIX)) {
indexer.index(each.getValue().getAsset().openStream());
}
}
} catch (IOException e) {
throw new RuntimeException(e);
}
return indexer.complete();
}
示例3: lookupEntityManager
import javax.enterprise.inject.Default; //导入依赖的package包/类
private static EntityManager lookupEntityManager(InjectionPoint ip, BeanManager bm) {
final Class def = Default.class;
@SuppressWarnings("unchecked")
final Class<? extends Annotation> annotation = ip.getQualifiers()
.stream()
.filter(q -> q.annotationType() == DAO.class)
.map(q -> ((DAO) q).value())
.findFirst()
.orElse(def);
if (bm.isQualifier(annotation)) {
return lookupEntityManager(bm, annotation);
} else {
throw new ContextNotActiveException("no datasource qualifier nor stereotype presents in the "
+ "injection point " + ip);
}
}
示例4: ClientProxyBean
import javax.enterprise.inject.Default; //导入依赖的package包/类
/**
* Public constructor.
*
* @param serviceName The name of the ESB Service being proxied to.
* @param proxyInterface The proxy Interface.
* @param qualifiers The CDI bean qualifiers. Copied from the injection point.
* @param beanDeploymentMetaData Deployment metadata.
*/
public ClientProxyBean(String serviceName, Class<?> proxyInterface, Set<Annotation> qualifiers, BeanDeploymentMetaData beanDeploymentMetaData) {
this._serviceName = serviceName;
this._serviceInterface = proxyInterface;
if (qualifiers != null) {
this._qualifiers = qualifiers;
} else {
this._qualifiers = new HashSet<Annotation>();
this._qualifiers.add(new AnnotationLiteral<Default>() {
});
this._qualifiers.add(new AnnotationLiteral<Any>() {
});
}
_proxyBean = Proxy.newProxyInstance(beanDeploymentMetaData.getDeploymentClassLoader(),
new Class[]{_serviceInterface},
new ClientProxyInvocationHandler(_serviceInterface));
}
示例5: getMongoClientConfiguration
import javax.enterprise.inject.Default; //导入依赖的package包/类
/**
* Reads the {@code config.json} configuration file in the classpath and builds a
* {@link MongoClientConfiguration} from it.
*
* @return the {@link MongoClientConfiguration}
* @throws IOException if a problem occurred when reading the config file
*/
@SuppressWarnings("static-method")
@Produces
@Default
public MongoClientConfiguration getMongoClientConfiguration() throws IOException {
try (
final InputStream jsonConfigFile =
Thread.currentThread().getContextClassLoader().getResourceAsStream("config.json");
final JsonReader reader = Json.createReader(jsonConfigFile);) {
final JsonObject root = (JsonObject) reader.read();
final String databaseName = ((JsonString) root.get("databaseName")).getString();
LOGGER.debug("Database name: {}", databaseName);
final MongoClientConfiguration mongoClientConfiguration =
new MongoClientConfiguration(databaseName);
return mongoClientConfiguration;
}
}
示例6: sendMessageToProducer
import javax.enterprise.inject.Default; //导入依赖的package包/类
@Test
public void sendMessageToProducer(@Uri("direct:produce") ProducerTemplate producer) throws InterruptedException {
long random = Math.round(Math.random() * Long.MAX_VALUE);
produced.expectedMessageCount(1);
produced.expectedBodiesReceived(random);
produced.message(0).predicate(exchange -> {
EventMetadata metadata = exchange.getIn().getHeader("metadata", EventMetadata.class);
return metadata.getType().equals(Long.class) && metadata.getQualifiers().equals(new HashSet<>(Arrays.asList(new AnnotationLiteral<Any>() {}, new AnnotationLiteral<Default>() {})));
});
consumed.expectedMessageCount(1);
consumed.expectedBodiesReceived(random);
producer.sendBody(random);
assertIsSatisfied(2L, TimeUnit.SECONDS, consumed, produced);
}
示例7: validate
import javax.enterprise.inject.Default; //导入依赖的package包/类
@Override
public void validate(final EjbModule ejbModule) {
if (ejbModule.getBeans() == null) {
return;
}
try {
for (final Field field : ejbModule.getFinder().findAnnotatedFields(Inject.class)) {
if (!field.getType().equals(InjectionPoint.class) || !HttpServlet.class.isAssignableFrom(field.getDeclaringClass())) {
continue;
}
final Annotation[] annotations = field.getAnnotations();
if (annotations.length == 1 || (annotations.length == 2 && field.getAnnotation(Default.class) != null)) {
throw new DefinitionException("Can't inject InjectionPoint in " + field.getDeclaringClass());
} // else we should check is there is no other qualifier than @Default but too early
}
} catch (final NoClassDefFoundError noClassDefFoundError) {
// ignored: can't check but maybe it is because of an optional dep so ignore it
// not important to skip it since the failure will be reported elsewhere
// this validator doesn't check it
}
}
示例8: WiresCanvasPresenter
import javax.enterprise.inject.Default; //导入依赖的package包/类
@Inject
public WiresCanvasPresenter(final Event<CanvasClearEvent> canvasClearEvent,
final Event<CanvasShapeAddedEvent> canvasShapeAddedEvent,
final Event<CanvasShapeRemovedEvent> canvasShapeRemovedEvent,
final Event<CanvasDrawnEvent> canvasDrawnEvent,
final Event<CanvasFocusedEvent> canvasFocusedEvent,
final @Lienzo Layer layer,
final WiresCanvas.View view,
final LienzoPanel lienzoPanel,
final @Default WiresControlFactory wiresControlFactory) {
super(canvasClearEvent,
canvasShapeAddedEvent,
canvasShapeRemovedEvent,
canvasDrawnEvent,
canvasFocusedEvent,
layer,
view);
this.lienzoPanel = lienzoPanel;
this.wiresControlFactory = wiresControlFactory;
}
示例9: resolve
import javax.enterprise.inject.Default; //导入依赖的package包/类
private QueryExecutor resolve(final String technology) {
if (anyExecutor.isUnsatisfied()) {
throw new RuntimeException(
"please provide QueryExecutor-Implementations!");
} else if ("default".equalsIgnoreCase(technology)) {
if (anyExecutor.isAmbiguous()) {
final Instance<QueryExecutor> defaultExecutors =
anyExecutor.select(new AnnotationLiteral<Default>() {
private static final long serialVersionUID = 1L;
});
return resolve(defaultExecutors, technology);
} else {
return anyExecutor.get();
}
} else {
final Instance<QueryExecutor> executorsByTechnology =
anyExecutor.select(new TechnologyLiteral(technology));
return resolve(executorsByTechnology, technology);
}
}
示例10: resolveEntityManagerQualifiers
import javax.enterprise.inject.Default; //导入依赖的package包/类
/**
* <p>This method uses the InvocationContext to scan the @Transactional
* interceptor for a manually specified Qualifier.</p>
*
* <p>If none is given (defaults to Any.class) then we scan the intercepted
* instance and resolve the Qualifiers of all it's injected EntityManagers.</p>
*
* <p>Please note that we will only pickup the first Qualifier on the
* injected EntityManager. We also do <b>not</b> parse for binding or
* &h#064;NonBinding values. A @Qualifier should not have any parameter at all.</p>
* @param entityManagerMetadata the metadata to locate the entity manager
* @param interceptedTargetClass the Class of the intercepted target
*/
public Set<Class<? extends Annotation>> resolveEntityManagerQualifiers(EntityManagerMetadata entityManagerMetadata,
Class interceptedTargetClass)
{
Set<Class<? extends Annotation>> emQualifiers = new HashSet<Class<? extends Annotation>>();
Class<? extends Annotation>[] qualifierClasses = entityManagerMetadata.getQualifiers();
if (qualifierClasses == null || qualifierClasses.length == 1 && Any.class.equals(qualifierClasses[0]) )
{
// this means we have no special EntityManager configured in the interceptor
// thus we should scan all the EntityManagers ourselfs from the intercepted class
collectEntityManagerQualifiersOnClass(emQualifiers, interceptedTargetClass);
}
else
{
// take the qualifierKeys from the qualifierClasses
Collections.addAll(emQualifiers, qualifierClasses);
}
//see DELTASPIKE-320
if (emQualifiers.isEmpty())
{
emQualifiers.add(Default.class);
}
return emQualifiers;
}
示例11: modifyAnnotationsOnConstructorParameter
import javax.enterprise.inject.Default; //导入依赖的package包/类
@Test
public void modifyAnnotationsOnConstructorParameter() throws NoSuchMethodException
{
final AnnotatedTypeBuilder<Cat> builder = new AnnotatedTypeBuilder<Cat>();
builder.readFromType(Cat.class, true);
builder.removeFromConstructorParameter(Cat.class.getConstructor(String.class, String.class), 1, Default.class);
builder.addToConstructorParameter(Cat.class.getConstructor(String.class, String.class), 1, new AnyLiteral());
final AnnotatedType<Cat> catAnnotatedType = builder.create();
Set<AnnotatedConstructor<Cat>> catCtors = catAnnotatedType.getConstructors();
assertThat(catCtors.size(), is(2));
for (AnnotatedConstructor<Cat> ctor : catCtors)
{
if (ctor.getParameters().size() == 2)
{
List<AnnotatedParameter<Cat>> ctorParams = ctor.getParameters();
assertThat(ctorParams.get(1).getAnnotations().size(), is(1));
assertThat((AnyLiteral) ctorParams.get(1).getAnnotations().toArray()[0], is(new AnyLiteral()));
}
}
}
示例12: ConversationKey
import javax.enterprise.inject.Default; //导入依赖的package包/类
public ConversationKey(Class<?> groupKey, Annotation... qualifiers)
{
this.groupKey = groupKey;
//TODO maybe we have to add a real qualifier instead
Class<? extends Annotation> annotationType;
for (Annotation qualifier : qualifiers)
{
annotationType = qualifier.annotationType();
if (Any.class.isAssignableFrom(annotationType) ||
Default.class.isAssignableFrom(annotationType) ||
Named.class.isAssignableFrom(annotationType) ||
ConversationGroup.class.isAssignableFrom(annotationType))
{
//won't be used for this key!
continue;
}
if (this.qualifiers == null)
{
this.qualifiers = new HashSet<Annotation>();
}
this.qualifiers.add(qualifier);
}
}
示例13: injectionPoints
import javax.enterprise.inject.Default; //导入依赖的package包/类
public <T, X> void injectionPoints(
final @Observes ProcessInjectionPoint<T, X> processInjectionPoint
) {
final Type type = processInjectionPoint.getInjectionPoint().getType();
final Object mock = mockStore.findFor(type);
if (mock == null) {
return;
}
LOG.debug("Mocking injection point: {}", processInjectionPoint.getInjectionPoint());
final InjectionPoint original = processInjectionPoint.getInjectionPoint();
processInjectionPoint.setInjectionPoint(new ForwardingInjectionPoint() {
@Override
public Set<Annotation> getQualifiers() {
final Set<Annotation> ret = new HashSet<>(super.getQualifiers()).stream()
.filter(it -> !(it instanceof Default))
.collect(toSet());
ret.add(MOCKED);
return ret;
}
@Override
protected InjectionPoint delegate() {
return original;
}
});
mockedInjectionPoints.add(original);
}
示例14: testAnnotationLiteral
import javax.enterprise.inject.Default; //导入依赖的package包/类
/**
* Tests annotation literals in a jar archive
*/
@Test
public void testAnnotationLiteral() {
logger.info("starting util event test");
Set<Bean<?>> beans = beanManager.getBeans(ConfigurationBean.class, new AnnotationLiteral<Default>() {
private static final long serialVersionUID = -4378964126487759035L;
});
assertEquals("The configuration bean has by default the @Default qualifier and it is a ManagedBean", 1,
beans.size());
}
开发者ID:PacktPublishing,项目名称:Mastering-Java-EE-Development-with-WildFly,代码行数:14,代码来源:UtilTestCase.java
示例15: testParametersNeedExtraAnnotation
import javax.enterprise.inject.Default; //导入依赖的package包/类
@Test
@ExtendWith(CustomExtension.class)
@ExplicitParamInjection
public void testParametersNeedExtraAnnotation(@Default Foo foo, Bar bar, @MyQualifier BeanWithQualifier bean) {
// Bar should be resolved by another extension
Assertions.assertNotNull(bar);
Assertions.assertEquals(CustomExtension.class.getSimpleName(), bar.ping());
// Foo should be resolved as usual
Assertions.assertNotNull(foo);
Assertions.assertEquals(Foo.class.getSimpleName(), foo.ping());
// BeanWithQualifier should be resolved
Assertions.assertNotNull(bean);
Assertions.assertEquals(BeanWithQualifier.class.getSimpleName(), bean.ping());
}