本文整理了Java中javax.enterprise.inject.spi.Decorator
类的一些代码示例,展示了Decorator
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Decorator
类的具体详情如下:
包路径:javax.enterprise.inject.spi.Decorator
类名称:Decorator
[英]Decorator Bean.
[中]装饰豆。
代码示例来源:origin: org.jboss.cdi.tck/cdi-tck-impl
protected void checkDecorator(Decorator<?> decorator, Class<?> beanClass, Set<Type> decoratedTypes, Type delegateType) {
assertEquals(decorator.getBeanClass(), beanClass);
assertEquals(decorator.getDecoratedTypes(), decoratedTypes);
assertEquals(decorator.getDelegateType(), delegateType);
}
代码示例来源:origin: org.jboss.cdi.tck/cdi-tck-impl
@SuppressWarnings("unchecked")
@Test
@SpecAssertions({ @SpecAssertion(section = DELEGATE_ATTRIBUTE, id = "a"), @SpecAssertion(section = DECORATOR, id = "c") })
public void testDelegateInjectionPoint() {
List<Decorator<?>> decorators = getCurrentManager().resolveDecorators(Logger.TYPES);
assertEquals(decorators.size(), 1);
Decorator<?> decorator = decorators.get(0);
assertEquals(decorator.getInjectionPoints().size(), 1);
assertEquals(decorator.getInjectionPoints().iterator().next().getType(),Logger.class);
assertTrue(decorator.getInjectionPoints().iterator().next().getAnnotated().isAnnotationPresent(Delegate.class));
assertEquals(decorator.getDelegateType(), Logger.class);
assertEquals(decorator.getDelegateQualifiers().size(), 1);
assertAnnotationSetMatches(decorator.getDelegateQualifiers(), Default.class);
}
代码示例来源:origin: org.jboss.weld.se/weld-se
private void validateDecorator(Decorator<?> decorator) {
Set<Annotation> qualifiers = decorator.getDelegateQualifiers();
if (decorator.getDelegateType() == null) {
throw BeanLogger.LOG.decoratorMethodReturnsNull("getDelegateType", decorator);
}
Bindings.validateQualifiers(qualifiers, getBeanManager(), decorator, "Decorator.getDelegateQualifiers");
if (decorator.getDecoratedTypes() == null) {
throw BeanLogger.LOG.decoratorMethodReturnsNull("getDecoratedTypes", decorator);
}
}
代码示例来源:origin: weld/core
/**
* Check whether the delegate type implements or extends all decorated types.
*
* @param decorator
* @throws DefinitionException If the delegate type doesn't implement or extend all decorated types
*/
public static void checkDelegateType(Decorator<?> decorator) {
Set<Type> types = new HierarchyDiscovery(decorator.getDelegateType()).getTypeClosure();
for (Type decoratedType : decorator.getDecoratedTypes()) {
if(!types.contains(decoratedType)) {
throw BeanLogger.LOG.delegateMustSupportEveryDecoratedType(decoratedType, decorator);
}
}
}
代码示例来源:origin: weld/core
public static void checkBeanMetadataInjectionPoint(Object bean, InjectionPoint ip, Type expectedTypeArgument) {
if (!(ip.getType() instanceof ParameterizedType)) {
throw ValidatorLogger.LOG.invalidBeanMetadataInjectionPointType(ip.getType(), ip, Formats.formatAsStackTraceElement(ip));
ParameterizedType parameterizedType = (ParameterizedType) ip.getType();
if (parameterizedType.getActualTypeArguments().length != 1) {
throw ValidatorLogger.LOG.invalidBeanMetadataInjectionPointType(ip.getType(), ip, Formats.formatAsStackTraceElement(ip));
throw ValidatorLogger.LOG.injectionIntoNonBean(ip, Formats.formatAsStackTraceElement(ip));
throw ValidatorLogger.LOG.invalidBeanMetadataInjectionPointType(ip.getType(), ip, Formats.formatAsStackTraceElement(ip));
if (!typeArgument.equals(decorator.getDelegateType())) {
throw ValidatorLogger.LOG.invalidBeanMetadataInjectionPointTypeArgument(typeArgument, ip, Formats.formatAsStackTraceElement(ip));
代码示例来源:origin: org.apache.openwebbeans/openwebbeans-impl
for (InjectionPoint injectionPoint : injectionPoints)
if (injectionPoint.getAnnotated().isAnnotationPresent(Decorated.class))
else if (injectionPoint.getAnnotated().isAnnotationPresent(Intercepted.class))
rawType.equals(Interceptor.class))
Type[] types = ClassUtil.getActualTypeArguments(injectionPoint.getType());
if (types.length != 1 || !GenericsUtil.isAssignableFrom(false, AbstractProducerBean.class.isInstance(bean), bean.getBeanClass(), types[0]))
if (!abstractMethods.isEmpty())
Set<Type> types = ((javax.enterprise.inject.spi.Decorator) bean).getDecoratedTypes();
for (Method abstractMethod : abstractMethods)
代码示例来源:origin: org.jboss.weld.se/weld-se
protected void validateDecorator(Decorator<?> decorator, Collection<CommonBean<?>> specializedBeans, BeanManagerImpl manager) {
if (decorator.getDecoratedTypes().isEmpty()) {
throw ValidatorLogger.LOG.noDecoratedTypes(decorator);
if (!decorator.getScope().equals(Dependent.class)) {
throw ValidatorLogger.LOG.interceptorOrDecoratorMustBeDependent(decorator);
Decorators.checkDelegateType(decorator);
Type delegateType = decorator.getDelegateType();
if (delegateType instanceof ParameterizedType) {
ParameterizedType parameterizedDelegateType = (ParameterizedType) delegateType;
if (!Decorators.isPassivationCapable(decorator)) {
if (Instance.class.equals(parameterizedDelegateType.getRawType()) || Provider.class.equals(parameterizedDelegateType.getRawType())) {
throw ValidatorLogger.LOG.builtinBeanWithNonserializableDecorator(decorator, Instance.class.getName());
validateRIBean((CommonBean<?>) decorator, manager, specializedBeans);
validateGeneralBean(decorator, manager);
Decorators.findDelegateInjectionPoint(annotated, decorator.getInjectionPoints());
代码示例来源:origin: org.jboss.weld.se/weld-se
private void validateDecorators(BeanManagerImpl beanManager, DecorableBean<?> bean) {
if (!(beanManager.isPassivatingScope(bean.getScope()) || bean instanceof AbstractDecorableBuiltInBean<?>)) {
return;
}
List<Decorator<?>> decorators = bean.getDecorators();
if (decorators.isEmpty()) {
return;
}
for (Decorator<?> decorator : decorators) {
if (!Decorators.isPassivationCapable(decorator)) {
if (bean instanceof AbstractDecorableBuiltInBean<?>) {
throw ValidatorLogger.LOG.builtinBeanWithNonserializableDecorator(decorator, bean);
} else {
throw ValidatorLogger.LOG.passivatingBeanWithNonserializableDecorator(bean, decorator);
}
}
if (decorator instanceof DecoratorImpl) {
beanManager = ((DecoratorImpl<?>) decorator).getBeanManager();
}
for (InjectionPoint ij : decorator.getInjectionPoints()) {
if (!ij.isDelegate()) {
Bean<?> resolvedBean = beanManager.resolve(beanManager.getBeans(ij));
validateInterceptorDecoratorInjectionPointPassivationCapable(ij, resolvedBean, beanManager, bean);
}
}
}
}
代码示例来源:origin: org.jboss.cdi.tck/cdi-tck-impl
public void testIsDelegate() {
assert !getContextualReference(FieldInjectionPointBean.class).getInjectedBean().getInjectedMetadata().isDelegate();
assert cat.getBeanManager() != null;
assert cat.getInjectionPoint() != null;
assert !cat.getInjectionPoint().isDelegate();
for (Decorator<?> animalDecorator : animalDecorators) {
assert animalDecorator.getInjectionPoints().size() == 2;
for (InjectionPoint injectionPoint : animalDecorator.getInjectionPoints()) {
if (injectionPoint.getType().equals(InjectionPoint.class)) {
assertFalse(injectionPoint.isDelegate());
} else if (injectionPoint.getType().equals(Animal.class)) {
代码示例来源:origin: org.apache.openwebbeans/openwebbeans-impl
private void validateDecorated(Bean<?> bean, boolean isDecorator, InjectionPoint injectionPoint)
{
if (isDecorator)
{
Type[] types = ClassUtil.getActualTypeArguments(injectionPoint.getType());
if (types.length != 1 ||
!((javax.enterprise.inject.spi.Decorator) bean).getDecoratedTypes().contains(types[0]))
{
throw new WebBeansConfigurationException("ParametrizedType must be a DecoratedTyp at InjectionPoint " + injectionPoint);
}
}
else
{
throw new WebBeansConfigurationException(injectionPoint.getBean().getBeanClass() + " must be a Decorator");
}
}
代码示例来源:origin: com.caucho/resin
Object instance = manager.getReference(bean, bean.getBeanClass(), env);
if (ip.getMember() instanceof Field) {
Field field = (Field) ip.getMember();
field.setAccessible(true);
throw new InjectionException(e);
} else if (ip.getMember() instanceof Method) {
Method method = (Method) ip.getMember();
method.setAccessible(true);
代码示例来源:origin: org.jboss.weld.se/weld-se
if (BeanKind.INTERCEPTOR.equals(kind) || BeanKind.DECORATOR.equals(kind) || bean.isAlternative()) {
JsonObjectBuilder enablementBuilder = Json.objectBuilder();
AnnotationApiAbstraction annotationApi = beanManager.getServices().get(AnnotationApiAbstraction.class);
Object priority = bean.getBeanClass().getAnnotation(annotationApi.PRIORITY_ANNOTATION_CLASS);
if (priority != null) {
Collection<BeanManagerImpl> beanManagers = Container.instance(beanManager).beanDeploymentArchives().values();
for (BeanManagerImpl manager : beanManagers) {
ModuleEnablement enablement = manager.getEnabled();
if ((BeanKind.INTERCEPTOR.equals(kind) && enablement.isInterceptorEnabled(bean.getBeanClass()))
|| (BeanKind.DECORATOR.equals(kind) && enablement.isDecoratorEnabled(bean.getBeanClass()))
|| isSelectedAlternative(enablement, bean)) {
bdasBuilder.add(createSimpleBdaJson(manager.getId()));
beanBuilder.add(DELEGATE_TYPE, Formats.formatType(decorator.getDelegateType(), false));
beanBuilder.add(DELEGATE_QUALIFIERS, createQualifiers(decorator.getDelegateQualifiers(), false));
JsonArrayBuilder decoratedTypes = Json.arrayBuilder(true);
for (Type type : decorator.getDecoratedTypes()) {
decoratedTypes.add(Formats.formatType(type, false));
代码示例来源:origin: org.jboss.cdi.tck/cdi-tck-impl
@Test
@SpecAssertions({ @SpecAssertion(section = INJECTION_POINT_CONFIGURATOR, id = "bc"),
@SpecAssertion(section = INJECTION_POINT_CONFIGURATOR, id = "be")
})
public void replaceQualifiersAndDelegate() {
List<Decorator<?>> vehicleDecorators = getCurrentManager().resolveDecorators(Collections.<Type>singleton(Car.class), Driving.DrivingLiteral.INSTANCE);
assertEquals(vehicleDecorators.size(), 1);
Decorator<Car> vehicleDecorator = (Decorator<Car>) vehicleDecorators.get(0);
assertEquals(vehicleDecorator.getInjectionPoints().size(), 1);
InjectionPoint vehicleIp = vehicleDecorator.getInjectionPoints().iterator().next();
assertEquals(vehicleIp.isDelegate(), true);
assertEquals(vehicleIp.getQualifiers(), Collections.singleton(Driving.DrivingLiteral.INSTANCE));
}
代码示例来源:origin: weld/core
@Override
protected boolean matches(Resolvable resolvable, Decorator<?> bean) {
return rules.matches(Collections.singleton(bean.getDelegateType()), resolvable.getTypes())
&& Beans.containsAllQualifiers(QualifierInstance.of(bean.getDelegateQualifiers(), getStore()), resolvable.getQualifiers())
&& getBeanManager().getEnabled().isDecoratorEnabled(bean.getBeanClass());
}
代码示例来源:origin: weld/core
private CustomDecoratorWrapper(Decorator<T> delegate, BeanManagerImpl beanManager) {
this.delegate = delegate;
this.weldClass = beanManager.getServices().get(ClassTransformer.class).getEnhancedAnnotatedType(Reflections.<Class<T>>cast(delegate.getBeanClass()), beanManager.getId());
this.decoratedMethods = new DecoratedMethods(beanManager, this);
}
代码示例来源:origin: weld/core
private void validateEnabledDecoratorClasses(BeanManagerImpl beanManager, BeanDeployment deployment) {
BeansXml beansXml = deployment.getBeanDeploymentArchive().getBeansXml();
if (beansXml != null && !beansXml.getEnabledDecorators().isEmpty()) {
Set<String> decoratorBeanClasses = new HashSet<String>();
for (Decorator<?> bean : beanManager.getDynamicAccessibleDecorators()) {
decoratorBeanClasses.add(bean.getBeanClass().getName());
}
for (Metadata<String> decoratorClassName : beansXml.getEnabledDecorators()) {
if (!decoratorBeanClasses.contains(decoratorClassName.getValue())) {
throw ValidatorLogger.LOG.decoratorClassNotBeanClassOfDecorator(decoratorClassName.getValue(), WeldCollections.toMultiRowString(decoratorBeanClasses));
}
}
}
}
代码示例来源:origin: com.caucho/resin
private static InjectionPoint getDelegate(Decorator<?> bean)
{
if (bean instanceof DecoratorBean)
return ((DecoratorBean) bean).getDelegateInjectionPoint();
for (InjectionPoint ip : bean.getInjectionPoints()) {
if (ip.isDelegate())
return ip;
}
throw new IllegalStateException(String.valueOf(bean));
}
代码示例来源:origin: org.jboss.weld.se/weld-se
@Override
public Set<Type> getDecoratedTypes() {
return delegate().getDecoratedTypes();
}
代码示例来源:origin: org.jboss.weld.se/weld-se
@Override
public Type getDelegateType() {
return delegate().getDelegateType();
}
代码示例来源:origin: org.jboss.weld.se/weld-se
@Override
public Set<Annotation> getDelegateQualifiers() {
return delegate().getDelegateQualifiers();
}
内容来源于网络,如有侵权,请联系作者删除!