下面列出了javax.persistence.Cache#javax.enterprise.inject.spi.InjectionPoint 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
public static SubscriptionPublisherInjectionWrapper createInvocationHandler(Bean<?> bean, BeanManager beanManager) {
SubscriptionPublisherProducer subscriptionPublisherProducer = getSubscriptionPublisherProducerReference(beanManager);
Class proxiedInterface = SubscriptionPublisherInjection.class;
Class subscriptionPublisherClass = null;
Class beanClass = bean.getBeanClass();
for (InjectionPoint injectionPoint : bean.getInjectionPoints()) {
if (!injectionPoint.getQualifiers().contains(SUBSCRIPTION_PUBLISHER_ANNOTATION_LITERAL)) {
continue;
}
Type baseType = injectionPoint.getAnnotated().getBaseType();
if (baseType instanceof Class && SubscriptionPublisher.class.isAssignableFrom((Class) baseType)) {
subscriptionPublisherClass = (Class) baseType;
break;
}
}
logger.debug("Found injector {} and publisher {} classes.", proxiedInterface, subscriptionPublisherClass);
if (subscriptionPublisherClass == null || proxiedInterface == null) {
throw new JoynrIllegalStateException("Cannot create subscription publisher injection wrapper proxy for bean which doesn't inject a concrete SubscriptionPublisher.");
}
return new SubscriptionPublisherInjectionWrapper(proxiedInterface,
subscriptionPublisherClass,
subscriptionPublisherProducer,
beanClass);
}
@SuppressWarnings("unchecked")
@ConfigurationValue("")
@Dependent
@Produces
<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(resolve(injectionPoint, valueType));
}
@Produces
@Claim("")
Long getClaimAsLong(InjectionPoint ip) {
CDILogging.log.getClaimAsLong(ip);
if (currentToken == null) {
return null;
}
String name = getName(ip);
Optional<Object> optValue = currentToken.claim(name);
Long returnValue = null;
if (optValue.isPresent()) {
Object value = optValue.get();
if (value instanceof JsonNumber) {
JsonNumber jsonValue = (JsonNumber) value;
returnValue = jsonValue.longValue();
} else {
returnValue = Long.parseLong(value.toString());
}
}
return returnValue;
}
@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
}
}
@Produces
@Dependent
@Location
public LocationId produceLocationId(InjectionPoint injectionPoint)
{
String configuredValue = getStringPropertyValue(injectionPoint);
/*
//alternative to @ConfigProperty#defaultValue
if (configuredValue == null)
{
return LocationId.LOCATION_X;
}
*/
return LocationId.valueOf(configuredValue.trim().toUpperCase());
}
@Produces
@Dependent
@ConfigProperty(name = "ignored")
// we actually don't need the name
public List<Double> produceDoubleListConfiguration(InjectionPoint injectionPoint) {
String propertyValue = getStringPropertyValue(injectionPoint);
String[] values = StringUtils.split(propertyValue, ",");
ArrayList<Double> list = new ArrayList<>();
if (values != null) {
for (String value : values) {
try {
list.add(Double.parseDouble(value));
} catch (NumberFormatException nfe) {
ConfigProperty configProperty = getAnnotation(injectionPoint, ConfigProperty.class);
throw new RuntimeException("Error while converting Double property '" + configProperty.name() + "' value: " + value + " of "
+ propertyValue + " happening in bean " + injectionPoint.getBean(), nfe);
}
}
}
return list;
}
protected void registerCustomBeans(@Observes AfterBeanDiscovery abd, BeanManager bm) {
Set<Class<?>> customTypes = new HashSet<>();
for (InjectionPoint ip : injectionPoints) {
Type requiredType = ip.getType();
if (requiredType instanceof ParameterizedType) {
ParameterizedType type = (ParameterizedType) requiredType;
// TODO We should probably handle all parameterized types correctly
if (type.getRawType().equals(Provider.class) || type.getRawType().equals(Instance.class)) {
// These injection points are satisfied by the built-in Instance bean
Type typeArgument = type.getActualTypeArguments()[0];
if (typeArgument instanceof Class && !isClassHandledByConfigProducer(typeArgument)) {
customTypes.add((Class<?>) typeArgument);
}
}
} else if (requiredType instanceof Class
&& !isClassHandledByConfigProducer(requiredType)) {
// type is not produced by ConfigProducer
customTypes.add((Class<?>) requiredType);
}
}
for (Class<?> customType : customTypes) {
abd.addBean(new ConfigInjectionBean(bm, customType));
}
}
@Produces @Dependent
public static MonetaryAmountFactory amountFactory(InjectionPoint ip){
Amount specAnnot = ip.getAnnotated()!=null?ip.getAnnotated().getAnnotation(Amount.class):null;
if(specAnnot!=null){
return Monetary.getAmountFactory(createAmountQuery(specAnnot));
}
return Monetary.getDefaultAmountFactory();
}
@Produces
@Dependent
public GroupedConversation getGroupedConversation(InjectionPoint injectionPoint, BeanManager beanManager)
{
ConversationKey conversationKey =
ConversationUtils.convertToConversationKey(injectionPoint.getBean(), beanManager);
return new InjectableGroupedConversation(conversationKey, getGroupedConversationManager());
}
@Produces
@Claim("")
public Optional<String> getStringValue(InjectionPoint ip) {
String name = getName(ip);
Optional<String> value = Optional.of(name);
return value;
}
/**
* Produces an Optional claim value wrapping a Boolean.
*
* @param ip reference to the injection point
* @return an optional claim value
*/
@Produces
@Claim("")
public Optional<Boolean> getOptionalBoolean(InjectionPoint ip) {
CDILogging.log.getOptionalBoolean(ip);
if (currentToken == null) {
return Optional.empty();
}
return Optional.ofNullable((Boolean) JsonUtils.convert(Boolean.class, currentToken.getClaim(getName(ip))));
}
@Produces
@HttpParam("")
String getParamValue(InjectionPoint ip)
{
ServletRequest request = (ServletRequest) FacesContext.getCurrentInstance().getExternalContext().getRequest();
return request.getParameter(ip.getAnnotated().getAnnotation(HttpParam.class).value());
}
@Override
public ResourceReferenceFactory<Object> registerEjbInjectionPoint(InjectionPoint injectionPoint) {
return new ResourceReferenceFactory<Object>() {
@Override
public ResourceReference<Object> createResource() {
return new SimpleResourceReference<Object>(ejbFactory.apply(injectionPoint));
}
};
}
@Produces
@Dependent
@ConfigProperty(name = "ignored") // we actually don't need the name
public Boolean produceBooleanConfiguration(InjectionPoint injectionPoint)
{
return getPropertyWithException(injectionPoint, Boolean.class);
}
static String getName(InjectionPoint ip) {
String name = null;
for (Annotation ann : ip.getQualifiers()) {
if (ann instanceof Claim) {
Claim claim = (Claim) ann;
name = claim.standard() == Claims.UNKNOWN ? claim.value() : claim.standard().name();
}
}
return name;
}
public static <T> T getValue(InjectionPoint injectionPoint, Config config) {
String name = getName(injectionPoint);
if (name == null) {
return null;
}
final SmallRyeConfig src = (SmallRyeConfig) config;
Converter<T> converter = resolveConverter(injectionPoint, src);
String rawValue = getRawValue(name, src);
if (rawValue == null) {
rawValue = getDefaultValue(injectionPoint);
}
T converted;
if (rawValue == null) {
// convert an empty value
try {
converted = converter.convert("");
} catch (IllegalArgumentException ignored) {
throw InjectionMessages.msg.propertyNotFound(name);
}
} else {
converted = converter.convert(rawValue);
}
if (converted == null) {
throw InjectionMessages.msg.propertyNotFound(name);
}
return converted;
}
@Produces @Dependent
public static CurrencyUnit currencyUnit(InjectionPoint ip){
AmountCurrency specAnnot = ip.getAnnotated()!=null?
ip.getAnnotated().getAnnotation(AmountCurrency.class):
null;
if(specAnnot==null){
java.util.Currency jdkDefault = java.util.Currency.getInstance(Locale.getDefault());
if(jdkDefault!=null) {
return Monetary.getCurrency(jdkDefault.getCurrencyCode());
}else{
throw new MonetaryException("No default currency found.");
}
}
return Monetary.getCurrency(createCurrencyQuery(specAnnot));
}
@Produces
@Dependent
@ConfigProperty(name = "ignored") // we actually don't need the name
public Class produceClassConfiguration(InjectionPoint injectionPoint)
{
return getPropertyWithException(injectionPoint, Class.class);
}
@Produces
@BatchProperty
public Pattern producePatternProperty(final InjectionPoint injectionPoint) {
final String v = produceProperty(injectionPoint);
if (v != null) {
return DependencyInjections.convertTo(v, Pattern.class, Pattern.class);
}
return null;
}
public static ConfigValue getConfigValue(InjectionPoint injectionPoint, Config config) {
String name = getName(injectionPoint);
if (name == null) {
return null;
}
ConfigValue configValue = ((SmallRyeConfig) config).getConfigValue(name);
if (configValue.getValue() == null) {
configValue = configValue.withValue(getDefaultValue(injectionPoint));
}
return configValue;
}
protected void validate(@Observes AfterDeploymentValidation adv) {
Config config = ConfigProvider.getConfig(getContextClassLoader());
Set<String> configNames = StreamSupport.stream(config.getPropertyNames().spliterator(), false).collect(toSet());
for (InjectionPoint injectionPoint : injectionPoints) {
Type type = injectionPoint.getType();
// We don't validate the Optional / Provider / Supplier / ConfigValue for defaultValue.
if (type instanceof Class && ConfigValue.class.isAssignableFrom((Class<?>) type)
|| type instanceof Class && OptionalInt.class.isAssignableFrom((Class<?>) type)
|| type instanceof Class && OptionalLong.class.isAssignableFrom((Class<?>) type)
|| type instanceof Class && OptionalDouble.class.isAssignableFrom((Class<?>) type)
|| type instanceof ParameterizedType
&& (Optional.class.isAssignableFrom((Class<?>) ((ParameterizedType) type).getRawType())
|| Provider.class.isAssignableFrom((Class<?>) ((ParameterizedType) type).getRawType())
|| Supplier.class.isAssignableFrom((Class<?>) ((ParameterizedType) type).getRawType()))) {
return;
}
ConfigProperty configProperty = injectionPoint.getAnnotated().getAnnotation(ConfigProperty.class);
String name = ConfigProducerUtil.getConfigKey(injectionPoint, configProperty);
// Check if the name is part of the properties first. Since properties can be a subset, then search for the actual property for a value.
if (!configNames.contains(name) && ConfigProducerUtil.getRawValue(name, (SmallRyeConfig) config) == null) {
if (configProperty.defaultValue().equals(ConfigProperty.UNCONFIGURED_VALUE)) {
adv.addDeploymentProblem(InjectionMessages.msg.noConfigValue(name));
}
}
try {
// Check if there is a Converter registed for the injected type
Converter<?> resolvedConverter = ConfigProducerUtil.resolveConverter(injectionPoint, (SmallRyeConfig) config);
// Check if the value can be converted. The TCK checks this, but this requires to get the value eagerly.
// This should not be required!
SecretKeys.doUnlocked(() -> ((SmallRyeConfig) config).getOptionalValue(name, resolvedConverter));
} catch (IllegalArgumentException e) {
adv.addDeploymentProblem(e);
}
}
}
@Override
@Alternative
@Specializes
@Produces
@Dependent
@ConfigProperty(name = "ignored")
// we actually don't need the name
public String produceStringConfiguration(InjectionPoint injectionPoint) {
return super.produceStringConfiguration(injectionPoint);
}
@Override
@Alternative
@Specializes
@Produces
@Dependent
@ConfigProperty(name = "ignored")
// we actually don't need the name
public Long produceLongConfiguration(InjectionPoint injectionPoint) {
return super.produceLongConfiguration(injectionPoint);
}
/**
* @since 7.3
*/
@Produces
@ProcessVariableLocalTyped
protected TypedValue getProcessVariableLocalTyped(InjectionPoint ip) {
String processVariableName = getVariableLocalTypedName(ip);
if (logger.isLoggable(Level.FINE)) {
logger.fine("Getting local typed process variable '" + processVariableName + "' from ProcessInstance[" + businessProcess.getProcessInstanceId() + "].");
}
return businessProcess.getVariableLocalTyped(processVariableName);
}
private Resource getResourceAnnotation(InjectionPoint injectionPoint) {
Annotated annotated = injectionPoint.getAnnotated();
if (annotated instanceof AnnotatedParameter<?>) {
annotated = ((AnnotatedParameter<?>) annotated).getDeclaringCallable();
}
return annotated.getAnnotation(Resource.class);
}
public static String getName(InjectionPoint injectionPoint) {
for (Annotation qualifier : injectionPoint.getQualifiers()) {
if (qualifier.annotationType().equals(ConfigProperty.class)) {
ConfigProperty configProperty = ((ConfigProperty) qualifier);
return getConfigKey(injectionPoint, configProperty);
}
}
return null;
}
@Produces
@Config("")
public String exposeConfig(InjectionPoint injectionPoint) {
final Config config = injectionPoint.getAnnotated().getAnnotation(Config.class);
if (config != null)
return properties.getProperty(config.value());
return null;
}
@Test
public void testBeanIsInjected() {
assertNotNull(unusedBean);
InjectionPoint injectionPoint = unusedBean.getInjectionPoint();
assertNotNull(injectionPoint);
assertEquals(UnusedBean.class, injectionPoint.getType());
assertEquals(1, injectionPoint.getQualifiers().size());
assertEquals(Default.class, injectionPoint.getQualifiers().iterator().next().annotationType());
assertTrue(injectionPoint.getMember() instanceof Field);
assertTrue(injectionPoint.getAnnotated().isAnnotationPresent(Inject.class));
}
@Produces
@BatchProperty
public Date produceDateProperty(final InjectionPoint injectionPoint) {
final String v = produceProperty(injectionPoint);
if (v != null) {
return DependencyInjections.convertTo(v, Date.class, Date.class);
}
return null;
}
@Dependent
@PortletParam
@Produces
public Float getFloatParam(ClientDataRequest clientDataRequest, PortletResponse portletResponse,
InjectionPoint injectionPoint) {
String value = getStringParam(clientDataRequest, portletResponse, injectionPoint);
if (value == null) {
return null;
}
Annotated field = injectionPoint.getAnnotated();
Annotation[] fieldAnnotations = _getFieldAnnotations(field);
ParamConverter<Float> paramConverter = _getParamConverter(Float.class, field.getBaseType(), fieldAnnotations);
if (paramConverter != null) {
try {
return paramConverter.fromString(value);
}
catch (IllegalArgumentException iae) {
_addBindingError(fieldAnnotations, iae.getMessage(), value);
return null;
}
}
if (LOG.isWarnEnabled()) {
LOG.warn("Unable to find a ParamConverterProvider for type Float");
}
return null;
}