本文整理匯總了Java中javax.enterprise.context.Dependent類的典型用法代碼示例。如果您正苦於以下問題:Java Dependent類的具體用法?Java Dependent怎麽用?Java Dependent使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
Dependent類屬於javax.enterprise.context包,在下文中一共展示了Dependent類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: decorateContext
import javax.enterprise.context.Dependent; //導入依賴的package包/類
private <X> AnnotatedField<X> decorateContext(AnnotatedField<X> field) {
final PersistenceContext persistenceContext = field.getAnnotation(PersistenceContext.class);
final UniqueIdentifier identifier = UniqueIdentifierLitteral.random();
Set<Annotation> templateQualifiers = new HashSet<>();
templateQualifiers.add(ServiceLiteral.SERVICE);
if (hasUnitName(persistenceContext)) {
templateQualifiers.add(new FilterLiteral("(osgi.unit.name=" + persistenceContext.unitName() + ")"));
}
Bean<JpaTemplate> bean = manager.getExtension(OsgiExtension.class)
.globalDependency(JpaTemplate.class, templateQualifiers);
Set<Annotation> qualifiers = new HashSet<>();
qualifiers.add(identifier);
Bean<EntityManager> b = new SimpleBean<>(EntityManager.class, Dependent.class, Collections.singleton(EntityManager.class), qualifiers, () -> {
CreationalContext<JpaTemplate> context = manager.createCreationalContext(bean);
JpaTemplate template = (JpaTemplate) manager.getReference(bean, JpaTemplate.class, context);
return EntityManagerProducer.create(template);
});
beans.add(b);
Set<Annotation> fieldAnnotations = new HashSet<>();
fieldAnnotations.add(InjectLiteral.INJECT);
fieldAnnotations.add(identifier);
return new SyntheticAnnotatedField<>(field, fieldAnnotations);
}
示例2: decorateUnit
import javax.enterprise.context.Dependent; //導入依賴的package包/類
private <X> AnnotatedField<X> decorateUnit(AnnotatedField<X> field) {
final PersistenceUnit persistenceUnit = field.getAnnotation(PersistenceUnit.class);
final UniqueIdentifier identifier = UniqueIdentifierLitteral.random();
Set<Annotation> templateQualifiers = new HashSet<>();
templateQualifiers.add(ServiceLiteral.SERVICE);
if (hasUnitName(persistenceUnit)) {
templateQualifiers.add(new FilterLiteral("(osgi.unit.name=" + persistenceUnit.unitName() + ")"));
}
Bean<EntityManagerFactory> bean = manager.getExtension(OsgiExtension.class)
.globalDependency(EntityManagerFactory.class, templateQualifiers);
Set<Annotation> qualifiers = new HashSet<>();
qualifiers.add(identifier);
Bean<EntityManagerFactory> b = new SimpleBean<>(EntityManagerFactory.class, Dependent.class, Collections.singleton(EntityManagerFactory.class), qualifiers, () -> {
CreationalContext<EntityManagerFactory> context = manager.createCreationalContext(bean);
return (EntityManagerFactory) manager.getReference(bean, EntityManagerFactory.class, context);
});
beans.add(b);
Set<Annotation> fieldAnnotations = new HashSet<>();
fieldAnnotations.add(InjectLiteral.INJECT);
fieldAnnotations.add(identifier);
return new SyntheticAnnotatedField<>(field, fieldAnnotations);
}
示例3: produceOptionalConfigValue
import javax.enterprise.context.Dependent; //導入依賴的package包/類
@SuppressWarnings("unchecked")
@Dependent
@Produces @ConfigProperty
<T> Optional<T> produceOptionalConfigValue(InjectionPoint injectionPoint) {
Type type = injectionPoint.getAnnotated().getBaseType();
final Class<T> valueType;
if (type instanceof ParameterizedType) {
ParameterizedType parameterizedType = (ParameterizedType) type;
Type[] typeArguments = parameterizedType.getActualTypeArguments();
valueType = unwrapType(typeArguments[0]);
} else {
valueType = (Class<T>) String.class;
}
return Optional.ofNullable(getValue(injectionPoint, valueType));
}
示例4: pathParam
import javax.enterprise.context.Dependent; //導入依賴的package包/類
/**
*
* @param ip
* @param parser
* @param msg
* @param dc
* @return
*/
@Produces @Dependent @PathParam("nonbinding")
public static String pathParam(InjectionPoint ip, PathParser parser, Message msg, DestinationChanged dc) {
final String destination;
if (msg != null) {
destination = msg.frame().destination().get();
} else if (dc != null) {
destination = dc.getDestination();
} else {
throw new IllegalStateException("Neither MessageEvent or DestinationEvent is resolvable!");
}
final PathParam param = ip
.getAnnotated()
.getAnnotation(PathParam.class);
final Result r = parser.parse(destination);
if (r.isSuccess()) {
return r.get(param.value());
}
return null;
}
示例5: createBeanAdapter
import javax.enterprise.context.Dependent; //導入依賴的package包/類
/**
*
* @param ip
* @param beanManager
* @return
*/
private <T> Bean<T> createBeanAdapter(InjectionPoint ip, BeanManager beanManager) {
final Type type = ip.getType();
final Class<T> rawType = ReflectionUtils.getRawType(type);
final ContextualLifecycle<T> lifecycleAdapter = new BodyLifecycle<T>(ip, beanManager);
final BeanBuilder<T> beanBuilder = new BeanBuilder<T>(beanManager)
.readFromType(new AnnotatedTypeBuilder<T>().readFromType(rawType).create())
.beanClass(Body.class) // see https://issues.jboss.org/browse/WELD-2165
.name(ip.getMember().getName())
.qualifiers(ip.getQualifiers())
.beanLifecycle(lifecycleAdapter)
.scope(Dependent.class)
.passivationCapable(false)
.alternative(false)
.nullable(true)
.id("BodyBean#" + type.toString())
.addType(type); //java.lang.Object needs to be present (as type) in any case
return beanBuilder.create();
}
示例6: lookup
import javax.enterprise.context.Dependent; //導入依賴的package包/類
/**
* Creates a SnoopEEServiceClient for the named service.
*
* @param ip The injection point
* @return a configured SnoopEE service client
*/
@SnoopEE
@Produces
@Dependent
public SnoopEEServiceClient lookup(InjectionPoint ip) {
final String applicationName = ip.getAnnotated().getAnnotation(SnoopEE.class).serviceName();
LOGGER.config(() -> "producing " + applicationName);
String serviceUrl = "http://" + readProperty("snoopeeService", snoopeeConfig);
LOGGER.config(() -> "Service URL: " + serviceUrl);
return new SnoopEEServiceClient.Builder(applicationName)
.serviceUrl(serviceUrl)
.build();
}
示例7: afterBeanDiscovery
import javax.enterprise.context.Dependent; //導入依賴的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);
}
示例8: produceBooleanProperty
import javax.enterprise.context.Dependent; //導入依賴的package包/類
@Produces
@Dependent
@Property
public Boolean produceBooleanProperty(InjectionPoint injectionPoint) {
try {
final String value = getProperty(injectionPoint);
if (value != null) {
return Boolean.valueOf(value);
}
final Type type = injectionPoint.getType();
return type.equals(boolean.class) ? Boolean.FALSE : null;
} catch (Exception e) {
throw new InjectionException(e);
}
}
示例9: produceIntegerProperty
import javax.enterprise.context.Dependent; //導入依賴的package包/類
@Produces
@Dependent
@Property
public Integer produceIntegerProperty(InjectionPoint injectionPoint) {
try {
final String value = getProperty(injectionPoint);
if (value != null) {
return Integer.valueOf(value);
}
final Type type = injectionPoint.getType();
return type.equals(int.class) ? Integer.valueOf(0) : null;
} catch (Exception e) {
throw new InjectionException(e);
}
}
示例10: produceLongProperty
import javax.enterprise.context.Dependent; //導入依賴的package包/類
@Produces
@Dependent
@Property
public Long produceLongProperty(InjectionPoint injectionPoint) {
try {
final String value = getProperty(injectionPoint);
if (value != null) {
return Long.valueOf(value);
}
final Type type = injectionPoint.getType();
return type.equals(long.class) ? Long.valueOf(0L) : null;
} catch (Exception e) {
throw new InjectionException(e);
}
}
示例11: produceFloatProperty
import javax.enterprise.context.Dependent; //導入依賴的package包/類
@Produces
@Dependent
@Property
public Float produceFloatProperty(InjectionPoint injectionPoint) {
try {
final String value = getProperty(injectionPoint);
if (value != null) {
return Float.valueOf(value);
}
final Type type = injectionPoint.getType();
return type.equals(float.class) ? Float.valueOf(0f) : null;
} catch (Exception e) {
throw new InjectionException(e);
}
}
示例12: produceDoubleProperty
import javax.enterprise.context.Dependent; //導入依賴的package包/類
@Produces
@Dependent
@Property
public Double produceDoubleProperty(InjectionPoint injectionPoint) {
try {
final String value = getProperty(injectionPoint);
if (value != null) {
return Double.valueOf(value);
}
final Type type = injectionPoint.getType();
return type.equals(double.class) ? Double.valueOf(0d) : null;
} catch (Exception e) {
throw new InjectionException(e);
}
}
示例13: produceBigIntegerProperty
import javax.enterprise.context.Dependent; //導入依賴的package包/類
@Produces
@Dependent
@Property
public BigInteger produceBigIntegerProperty(InjectionPoint injectionPoint) {
try {
final BigDecimal value = produceBigDecimalProperty(injectionPoint);
if (value != null) {
return value.toBigInteger();
}
} catch (Exception e) {
throw new InjectionException(e);
}
return null;
}
示例14: produceDateProperty
import javax.enterprise.context.Dependent; //導入依賴的package包/類
@Produces
@Dependent
@Property
public Date produceDateProperty(InjectionPoint injectionPoint) {
try {
final String value = getProperty(injectionPoint);
final Date date;
if (value != null) {
final Property annotation = injectionPoint.getAnnotated().getAnnotation(Property.class);
final String pattern = annotation.pattern();
DateFormat format = new SimpleDateFormat(pattern.isEmpty() ? "yyyy-MM-dd'T'HH:mm:ss.SSSZ" : pattern);
date = format.parse(value);
} else {
date = null;
}
return date;
} catch (Exception e) {
throw new InjectionException(e);
}
}
示例15: getDatasourceJndiName
import javax.enterprise.context.Dependent; //導入依賴的package包/類
@Produces
@Dependent
@DefaultDatasource
public String getDatasourceJndiName() {
if (this.defaultDatasourceJndiName == null && this.defaultDatasourceName != null) {
for (DataSource ds : this.fraction.subresources().dataSources()) {
if (this.defaultDatasourceName.equals(ds.getKey())) {
if (ds.jndiName() != null) {
return ds.jndiName();
}
return "java:jboss/datasources/" + this.defaultDatasourceName;
}
}
}
return this.defaultDatasourceJndiName;
}