本文整理匯總了Java中javax.enterprise.inject.spi.InjectionPoint類的典型用法代碼示例。如果您正苦於以下問題:Java InjectionPoint類的具體用法?Java InjectionPoint怎麽用?Java InjectionPoint使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
InjectionPoint類屬於javax.enterprise.inject.spi包,在下文中一共展示了InjectionPoint類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: registerEjbInjectionPoint
import javax.enterprise.inject.spi.InjectionPoint; //導入依賴的package包/類
@Override
@SuppressWarnings("unchecked")
public ResourceReferenceFactory<Object> registerEjbInjectionPoint(
final InjectionPoint injectionPoint
) {
if (injectionPoint.getAnnotated().getAnnotation(EJB.class) == null) {
throw new IllegalStateException("Unhandled injection point: " + injectionPoint);
}
final Type type = injectionPoint.getType();
final ResourceReferenceFactory<Object> alternative = alternatives.alternativeFor(type);
if (alternative != null) {
return alternative;
}
final EjbDescriptor<Object> descriptor = (EjbDescriptor<Object>) lookup.lookup(type);
if (descriptor == null) {
throw new IllegalStateException("No EJB descriptor found for EJB injection point: " + injectionPoint);
}
return factory.createInstance(descriptor);
}
示例2: factory
import javax.enterprise.inject.spi.InjectionPoint; //導入依賴的package包/類
private <T> ProducerFactory<T> factory(final Object mock) {
return new ProducerFactory<T>() {
@Override
public <T1> Producer<T1> createProducer(final Bean<T1> bean) {
return new Producer<T1>() {
@Override
public T1 produce(final CreationalContext<T1> ctx) {
return (T1) mock;
}
@Override
public void dispose(final T1 instance) {
}
@Override
public Set<InjectionPoint> getInjectionPoints() {
return Collections.emptySet();
}
};
}
};
}
示例3: resolveResource
import javax.enterprise.inject.spi.InjectionPoint; //導入依賴的package包/類
@Override
public Object resolveResource(InjectionPoint injectionPoint) {
Resource resource = getResourceAnnotation(injectionPoint);
if (resource == null) {
throw new IllegalArgumentException("No @Resource annotation found on " + injectionPoint);
}
if (injectionPoint.getMember() instanceof Method && ((Method) injectionPoint.getMember()).getParameterTypes().length != 1) {
throw new IllegalArgumentException(
"Injection point represents a method which doesn't follow JavaBean conventions (must have exactly one parameter) " + injectionPoint);
}
String name;
if (!resource.lookup().equals("")) {
name = resource.lookup();
} else {
name = getResourceName(injectionPoint);
}
return resources.get(name);
}
示例4: getResourceName
import javax.enterprise.inject.spi.InjectionPoint; //導入依賴的package包/類
private String getResourceName(InjectionPoint injectionPoint) {
Resource resource = getResourceAnnotation(injectionPoint);
String mappedName = resource.mappedName();
if (!mappedName.equals("")) {
return mappedName;
}
String name = resource.name();
if (!name.equals("")) {
return RESOURCE_LOOKUP_PREFIX + "/" + name;
}
String propertyName;
if (injectionPoint.getMember() instanceof Field) {
propertyName = injectionPoint.getMember().getName();
} else if (injectionPoint.getMember() instanceof Method) {
propertyName = getPropertyName((Method) injectionPoint.getMember());
if (propertyName == null) {
throw new IllegalArgumentException("Injection point represents a method which doesn't follow "
+ "JavaBean conventions (unable to determine property name) " + injectionPoint);
}
} else {
throw new AssertionError("Unable to inject into " + injectionPoint);
}
String className = injectionPoint.getMember().getDeclaringClass().getName();
return RESOURCE_LOOKUP_PREFIX + "/" + className + "/" + propertyName;
}
示例5: CrudService
import javax.enterprise.inject.spi.InjectionPoint; //導入依賴的package包/類
@Inject
protected void CrudService(InjectionPoint ip) {
if (ip != null && ip.getType() != null && ip.getMember() != null) {
try {
//Used for generic service injection, e.g: @Inject @Service CrudService<Entity,Key>
resolveEntity(ip);
} catch (Exception e) {
LOG.warning(String.format("Could not resolve entity type and entity key via injection point [%s]. Now trying to resolve via generic superclass of [%s].", ip.getMember().getName(), getClass().getName()));
}
}
if (entityClass == null) {
//Used on service inheritance, e.g: MyService extends CrudService<Entity, Key>
entityClass = (Class<T>) ((ParameterizedType) getClass().getGenericSuperclass()).getActualTypeArguments()[0];
entityKey = (Class<PK>) ((ParameterizedType) getClass().getGenericSuperclass()).getActualTypeArguments()[1];
}
}
示例6: getAppDataValueAsString
import javax.enterprise.inject.spi.InjectionPoint; //導入依賴的package包/類
@Produces
@AppData("PRODUCER")
public String getAppDataValueAsString(InjectionPoint injectionPoint) {
Annotated annotated = injectionPoint.getAnnotated();
String key = null;
String value = null;
if (annotated.isAnnotationPresent(AppData.class)) {
AppData annotation = annotated.getAnnotation(AppData.class);
key = annotation.value();
value = properties.getProperty(key);
}
if (value == null) {
throw new IllegalArgumentException("No AppData value found for key " + key);
}
return value;
}
示例7: getUserSetting
import javax.enterprise.inject.spi.InjectionPoint; //導入依賴的package包/類
@Produces
@CoreSetting("PRODUCER")
public String getUserSetting(InjectionPoint injectionPoint) {
Annotated annotated = injectionPoint.getAnnotated();
if (annotated.isAnnotationPresent(CoreSetting.class)) {
String settingPath = annotated.getAnnotation(CoreSetting.class).value();
Object object = yamlCoreSettings;
String[] split = settingPath.split("\\.");
int c = 0;
while (c < split.length) {
try {
object = PropertyUtils.getProperty(object, split[c]);
c++;
} catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException e) {
LogManager.getLogger(getClass()).error("Failed retrieving setting " + settingPath, e);
return null;
}
}
return String.valueOf(object);
}
return null;
}
示例8: createL10nMap
import javax.enterprise.inject.spi.InjectionPoint; //導入依賴的package包/類
@Produces
public I18nMap createL10nMap(InjectionPoint injectionPoint) {
Annotated annotated = injectionPoint.getAnnotated();
String baseName;
if (annotated.isAnnotationPresent(I18nData.class)) {
baseName = annotated.getAnnotation(I18nData.class).value().getSimpleName();
} else {
baseName = injectionPoint.getBean().getBeanClass().getSimpleName();
}
File langFile = new File(langBase, baseName + ".properties");
I18NMapImpl l10NMap = new I18NMapImpl(commonLang);
try (InputStream stream = new FileInputStream(langFile)) {
l10NMap.load(stream);
} catch (IOException e) {
// I18n data will be injected in all components,
// but a component is not required to have a language definition
// This implementation will return an empty I18nMap containing only able to supply common strings
}
return l10NMap;
}
示例9: produceOptionalConfigValue
import javax.enterprise.inject.spi.InjectionPoint; //導入依賴的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));
}
示例10: getConfig
import javax.enterprise.inject.spi.InjectionPoint; //導入依賴的package包/類
private <T> T getValue
(InjectionPoint injectionPoint, Class<T> target) {
Config config = getConfig(injectionPoint);
String name = getName(injectionPoint);
try {
if (name == null) {
return null;
}
Optional<T> optionalValue = config.getOptionalValue(name, target);
if (optionalValue.isPresent()) {
return optionalValue.get();
} else {
String defaultValue = getDefaultValue(injectionPoint);
if (defaultValue != null) {
return ((WildFlyConfig)config).convert(defaultValue, target);
} else {
return null;
}
}
} catch (RuntimeException e) {
return null;
}
}
示例11: validate
import javax.enterprise.inject.spi.InjectionPoint; //導入依賴的package包/類
public void validate(@Observes AfterDeploymentValidation add, BeanManager bm) {
List<String> deploymentProblems = new ArrayList<>();
Config config = ConfigProvider.getConfig();
for (InjectionPoint injectionPoint : injectionPoints) {
Type type = injectionPoint.getType();
ConfigProperty configProperty = injectionPoint.getAnnotated().getAnnotation(ConfigProperty.class);
if (type instanceof Class) {
String key = getConfigKey(injectionPoint, configProperty);
if (!config.getOptionalValue(key, (Class)type).isPresent()) {
String defaultValue = configProperty.defaultValue();
if (defaultValue == null ||
defaultValue.equals(ConfigProperty.UNCONFIGURED_VALUE)) {
deploymentProblems.add("No Config Value exists for " + key);
}
}
}
}
if (!deploymentProblems.isEmpty()) {
add.addDeploymentProblem(new DeploymentException("Error while validating Configuration\n"
+ String.join("\n", deploymentProblems)));
}
}
示例12: getConfigKey
import javax.enterprise.inject.spi.InjectionPoint; //導入依賴的package包/類
static String getConfigKey(InjectionPoint ip, ConfigProperty configProperty) {
String key = configProperty.name();
if (!key.trim().isEmpty()) {
return key;
}
if (ip.getAnnotated() instanceof AnnotatedMember) {
AnnotatedMember member = (AnnotatedMember) ip.getAnnotated();
AnnotatedType declaringType = member.getDeclaringType();
if (declaringType != null) {
String[] parts = declaringType.getJavaClass().getCanonicalName().split("\\.");
StringBuilder sb = new StringBuilder(parts[0]);
for (int i = 1; i < parts.length; i++) {
sb.append(".").append(parts[i]);
}
sb.append(".").append(member.getJavaMember().getName());
return sb.toString();
}
}
throw new IllegalStateException("Could not find default name for @ConfigProperty InjectionPoint " + ip);
}
示例13: passwordEncoder
import javax.enterprise.inject.spi.InjectionPoint; //導入依賴的package包/類
@Produces
@Crypto
public PasswordEncoder passwordEncoder(InjectionPoint ip) {
Crypto crypto = ip.getAnnotated().getAnnotation(Crypto.class);
Crypto.Type type = crypto.value();
PasswordEncoder encoder;
switch (type) {
case PLAIN:
encoder = new PlainPasswordEncoder();
break;
case BCRYPT:
encoder = new BCryptPasswordEncoder();
break;
default:
encoder = new PlainPasswordEncoder();
break;
}
return encoder;
}
示例14: createBeanAdapter
import javax.enterprise.inject.spi.InjectionPoint; //導入依賴的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();
}
示例15: logger_injectionPoint_noBean
import javax.enterprise.inject.spi.InjectionPoint; //導入依賴的package包/類
@Test
@SuppressWarnings({ "rawtypes", "unchecked" })
public void logger_injectionPoint_noBean() {
final InjectionPoint ip = mock(InjectionPoint.class);
final Member member = mock(Member.class);
when(ip.getMember()).thenReturn(member);
when(member.getDeclaringClass()).thenReturn((Class) LogProducerTest.class);
final Logger log = LogProducer.logger(ip);
assertEquals("NOP", log.getName());
verify(ip).getBean();
verify(ip).getMember();
verify(member).getDeclaringClass();
verifyNoMoreInteractions(ip, member);
}