Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 69572200C8F for ; Fri, 9 Jun 2017 16:47:35 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id 65E49160BC8; Fri, 9 Jun 2017 14:47:35 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 0FB3B160B9C for ; Fri, 9 Jun 2017 16:47:33 +0200 (CEST) Received: (qmail 24493 invoked by uid 500); 9 Jun 2017 14:47:33 -0000 Mailing-List: contact commits-help@openwebbeans.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@openwebbeans.apache.org Delivered-To: mailing list commits@openwebbeans.apache.org Received: (qmail 24481 invoked by uid 99); 9 Jun 2017 14:47:31 -0000 Received: from Unknown (HELO svn01-us-west.apache.org) (209.188.14.144) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 09 Jun 2017 14:47:31 +0000 Received: from svn01-us-west.apache.org (localhost [127.0.0.1]) by svn01-us-west.apache.org (ASF Mail Server at svn01-us-west.apache.org) with ESMTP id 9EF423A040C for ; Fri, 9 Jun 2017 14:47:30 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1798230 - in /openwebbeans/trunk: webbeans-impl/src/main/java/org/apache/webbeans/component/ webbeans-impl/src/main/java/org/apache/webbeans/config/ webbeans-impl/src/main/java/org/apache/webbeans/configurator/ webbeans-impl/src/main/java/... Date: Fri, 09 Jun 2017 14:47:27 -0000 To: commits@openwebbeans.apache.org From: struberg@apache.org X-Mailer: svnmailer-1.0.9 Message-Id: <20170609144730.9EF423A040C@svn01-us-west.apache.org> archived-at: Fri, 09 Jun 2017 14:47:35 -0000 Author: struberg Date: Fri Jun 9 14:47:27 2017 New Revision: 1798230 URL: http://svn.apache.org/viewvc?rev=1798230&view=rev Log: OWB-1187 implement BeanConfigurator Not able to finish it since the spec is ambiguous and the TCK is broken :/ Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/WebBeansType.java openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/config/BeansDeployer.java openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/configurator/BeanConfiguratorImpl.java openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/events/discovery/AfterBeanDiscoveryImpl.java openwebbeans/trunk/webbeans-tck/standalone-suite.xml Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/WebBeansType.java URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/WebBeansType.java?rev=1798230&r1=1798229&r2=1798230&view=diff ============================================================================== --- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/WebBeansType.java (original) +++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/WebBeansType.java Fri Jun 9 14:47:27 2017 @@ -49,7 +49,8 @@ package org.apache.webbeans.component; */ public enum WebBeansType { - MANAGED, + MANAGED, + CONFIGURED, PRODUCERMETHOD, PRODUCERFIELD, RESOURCEBEAN, Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/config/BeansDeployer.java URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/config/BeansDeployer.java?rev=1798230&r1=1798229&r2=1798230&view=diff ============================================================================== --- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/config/BeansDeployer.java (original) +++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/config/BeansDeployer.java Fri Jun 9 14:47:27 2017 @@ -759,6 +759,7 @@ public class BeansDeployer final AfterBeanDiscoveryImpl event = new AfterBeanDiscoveryImpl(webBeansContext); manager.fireLifecycleEvent(event); + event.deployConfiguredBeans(); webBeansContext.getWebBeansUtil().inspectDefinitionErrorStack( "There are errors that are added by AfterBeanDiscovery event observers. Look at logs for further details"); Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/configurator/BeanConfiguratorImpl.java URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/configurator/BeanConfiguratorImpl.java?rev=1798230&r1=1798229&r2=1798230&view=diff ============================================================================== --- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/configurator/BeanConfiguratorImpl.java (original) +++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/configurator/BeanConfiguratorImpl.java Fri Jun 9 14:47:27 2017 @@ -18,205 +18,546 @@ */ package org.apache.webbeans.configurator; +import javax.enterprise.context.Dependent; import javax.enterprise.context.spi.CreationalContext; import javax.enterprise.inject.Instance; import javax.enterprise.inject.spi.AnnotatedType; +import javax.enterprise.inject.spi.Bean; import javax.enterprise.inject.spi.BeanAttributes; import javax.enterprise.inject.spi.InjectionPoint; +import javax.enterprise.inject.spi.PassivationCapable; +import javax.enterprise.inject.spi.Producer; import javax.enterprise.inject.spi.configurator.BeanConfigurator; import javax.enterprise.util.TypeLiteral; import java.lang.annotation.Annotation; +import java.lang.reflect.ParameterizedType; import java.lang.reflect.Type; +import java.util.HashSet; import java.util.Set; import java.util.function.BiConsumer; import java.util.function.Function; +import org.apache.webbeans.component.OwbBean; +import org.apache.webbeans.component.WebBeansType; +import org.apache.webbeans.component.creation.BeanAttributesBuilder; +import org.apache.webbeans.config.WebBeansContext; +import org.apache.webbeans.exception.WebBeansConfigurationException; +import org.apache.webbeans.util.GenericsUtil; + +//X TODO finish. Impossible to implement right now as the spec is ambiguous +//X TODO producer part public class BeanConfiguratorImpl implements BeanConfigurator { + private final WebBeansContext webBeansContext; + + private Class beanClass = null; + private String passivationId = null; + private Class scope = Dependent.class; + private String name = null; + private boolean alternative; + + private Set typeClosures = new HashSet<>(); + private Set injectionPoints = new HashSet<>(); + private Set qualifiers = new HashSet<>(); + private Set> stereotypes = new HashSet<>(); + + private Function, ?> createWithCallback; + private BiConsumer> destroyWithCallback; + + private Function, ?> produceWithCallback; + private BiConsumer> disposeWithCallback; + + public BeanConfiguratorImpl(WebBeansContext webBeansContext) + { + this.webBeansContext = webBeansContext; + } @Override public BeanConfigurator beanClass(Class beanClass) { - throw new UnsupportedOperationException("TODO implement CDI 2.0"); + this.beanClass = beanClass; + return this; } @Override public BeanConfigurator addInjectionPoint(InjectionPoint injectionPoint) { - throw new UnsupportedOperationException("TODO implement CDI 2.0"); + this.injectionPoints.add(injectionPoint); + return this; } @Override public BeanConfigurator addInjectionPoints(InjectionPoint... injectionPoints) { - throw new UnsupportedOperationException("TODO implement CDI 2.0"); + for (InjectionPoint injectionPoint : injectionPoints) + { + this.injectionPoints.add(injectionPoint); + } + return this; } @Override public BeanConfigurator addInjectionPoints(Set injectionPoints) { - throw new UnsupportedOperationException("TODO implement CDI 2.0"); + this.injectionPoints.addAll(injectionPoints); + return this; } @Override public BeanConfigurator injectionPoints(InjectionPoint... injectionPoints) { - throw new UnsupportedOperationException("TODO implement CDI 2.0"); + this.injectionPoints.clear(); + addInjectionPoints(injectionPoints); + return this; } @Override public BeanConfigurator injectionPoints(Set injectionPoints) { - throw new UnsupportedOperationException("TODO implement CDI 2.0"); + this.injectionPoints.clear(); + addInjectionPoints(injectionPoints); + return this; } @Override public BeanConfigurator id(String id) { - throw new UnsupportedOperationException("TODO implement CDI 2.0"); + this.passivationId = id; + return this; } @Override public BeanConfigurator createWith(Function, U> callback) { - throw new UnsupportedOperationException("TODO implement CDI 2.0"); + this.createWithCallback = (Function) callback; + return (BeanConfigurator) this; } @Override public BeanConfigurator produceWith(Function, U> callback) { - throw new UnsupportedOperationException("TODO implement CDI 2.0"); + this.produceWithCallback = callback; + return (BeanConfigurator) this; } @Override public BeanConfigurator destroyWith(BiConsumer> callback) { - throw new UnsupportedOperationException("TODO implement CDI 2.0"); + this.destroyWithCallback = callback; + return this; } @Override public BeanConfigurator disposeWith(BiConsumer> callback) { - throw new UnsupportedOperationException("TODO implement CDI 2.0"); + this.disposeWithCallback = callback; + return this; } @Override public BeanConfigurator read(AnnotatedType type) { - throw new UnsupportedOperationException("TODO implement CDI 2.0"); + read(BeanAttributesBuilder.forContext(webBeansContext).newBeanAttibutes(type).build()); + return (BeanConfigurator) this; } @Override public BeanConfigurator read(BeanAttributes beanAttributes) { - throw new UnsupportedOperationException("TODO implement CDI 2.0"); + this.stereotypes.addAll(beanAttributes.getStereotypes()); + this.scope = beanAttributes.getScope(); + this.name = beanAttributes.getName(); + this.alternative = beanAttributes.isAlternative(); + types(beanAttributes.getTypes()); + qualifiers(beanAttributes.getQualifiers()); + stereotypes(beanAttributes.getStereotypes()); + + return this; } @Override public BeanConfigurator addType(Type type) { - throw new UnsupportedOperationException("TODO implement CDI 2.0"); + this.typeClosures.add(type); + return this; } @Override public BeanConfigurator addType(TypeLiteral typeLiteral) { - throw new UnsupportedOperationException("TODO implement CDI 2.0"); + this.typeClosures.add(typeLiteral.getType()); + return this; } @Override public BeanConfigurator addTypes(Type... types) { - throw new UnsupportedOperationException("TODO implement CDI 2.0"); + for (Type type : types) + { + addType(type); + } + return this; } @Override public BeanConfigurator addTypes(Set types) { - throw new UnsupportedOperationException("TODO implement CDI 2.0"); + for (Type type : types) + { + addType(type); + + } + return this; } @Override public BeanConfigurator addTransitiveTypeClosure(Type type) { - throw new UnsupportedOperationException("TODO implement CDI 2.0"); + Set typeClosure = GenericsUtil.getTypeClosure(type, type); + addTypes(typeClosure); + return this; } @Override public BeanConfigurator types(Type... types) { - throw new UnsupportedOperationException("TODO implement CDI 2.0"); + this.typeClosures.clear(); + addTypes(types); + return this; } @Override public BeanConfigurator types(Set types) { - throw new UnsupportedOperationException("TODO implement CDI 2.0"); + this.typeClosures.clear(); + addTypes(types); + return this; } @Override public BeanConfigurator scope(Class scope) { - throw new UnsupportedOperationException("TODO implement CDI 2.0"); + this.scope = scope; + return this; } @Override public BeanConfigurator addQualifier(Annotation qualifier) { - throw new UnsupportedOperationException("TODO implement CDI 2.0"); + this.qualifiers.add(qualifier); + return this; } @Override public BeanConfigurator addQualifiers(Annotation... qualifiers) { - throw new UnsupportedOperationException("TODO implement CDI 2.0"); + for (Annotation qualifier : qualifiers) + { + this.qualifiers.add(qualifier); + } + return this; } @Override public BeanConfigurator addQualifiers(Set qualifiers) { - throw new UnsupportedOperationException("TODO implement CDI 2.0"); + this.qualifiers.addAll(qualifiers); + return this; } @Override public BeanConfigurator qualifiers(Annotation... qualifiers) { - throw new UnsupportedOperationException("TODO implement CDI 2.0"); + this.qualifiers.clear(); + addQualifiers(qualifiers); + return this; } @Override public BeanConfigurator qualifiers(Set qualifiers) { - throw new UnsupportedOperationException("TODO implement CDI 2.0"); + this.qualifiers.clear(); + addQualifiers(qualifiers); + return this; } @Override public BeanConfigurator addStereotype(Class stereotype) { - throw new UnsupportedOperationException("TODO implement CDI 2.0"); + this.stereotypes.add(stereotype); + return this; } @Override public BeanConfigurator addStereotypes(Set> stereotypes) { - throw new UnsupportedOperationException("TODO implement CDI 2.0"); + for (Class stereotype : stereotypes) + { + this.stereotypes.add(stereotype); + } + return this; } @Override public BeanConfigurator stereotypes(Set> stereotypes) { - throw new UnsupportedOperationException("TODO implement CDI 2.0"); + this.stereotypes.clear(); + addStereotypes(stereotypes); + return this; } @Override public BeanConfigurator name(String name) { - throw new UnsupportedOperationException("TODO implement CDI 2.0"); + this.name = name; + return this; } @Override - public BeanConfigurator alternative(boolean value) + public BeanConfigurator alternative(boolean alternative) { - throw new UnsupportedOperationException("TODO implement CDI 2.0"); + this.alternative = alternative; + return this; + } + + public Bean getBean() + { + return new ConstructedBean(); + } + + /** + * 1:1 with the BeanConfigurator. + */ + public class ConstructedBean implements OwbBean, PassivationCapable + { + private final Class returnType; + private final boolean dependent; + private boolean specialized = false; + private boolean enabled = true; + + public ConstructedBean() + { + this.returnType = null; //X TODO calculate return type from the typeClosures + + dependent = !webBeansContext.getBeanManagerImpl().isNormalScope(scope); + + if (createWithCallback == null && produceWithCallback == null) + { + WebBeansConfigurationException e = new WebBeansConfigurationException("Either a createCallback or a produceCallback must be set " + toString()); + webBeansContext.getBeanManagerImpl().getErrorStack().pushError(e); + } + if (createWithCallback != null && produceWithCallback != null) + { + WebBeansConfigurationException e = new WebBeansConfigurationException("Only exactly one of createCallback and produceCallback must be set " + toString()); + webBeansContext.getBeanManagerImpl().getErrorStack().pushError(e); + } + } + + @Override + public Set getTypes() + { + return typeClosures; + } + + @Override + public Set getInjectionPoints() + { + return injectionPoints; + } + + @Override + public Set getQualifiers() + { + return qualifiers; + } + + @Override + public Producer getProducer() + { + //X TODO + return null; + } + + @Override + public Class getBeanClass() + { + return beanClass; + } + + @Override + public Class getScope() + { + return scope; + } + + @Override + public WebBeansType getWebBeansType() + { + return WebBeansType.CONFIGURED; + } + + @Override + public String getName() + { + return name; + } + + @Override + public Class getReturnType() + { + return (Class) beanClass; + } + + @Override + public T create(CreationalContext context) + { + return (T) createWithCallback.apply(context); + } + + @Override + public Set> getStereotypes() + { + return stereotypes; + } + + @Override + public void setSpecializedBean(boolean specialized) + { + this.specialized = specialized; + } + + @Override + public boolean isAlternative() + { + return alternative; + } + + @Override + public boolean isNullable() + { + return false; + } + + @Override + public void destroy(T instance, CreationalContext context) + { + destroyWithCallback.accept(instance, context); + } + + @Override + public boolean isSpecializedBean() + { + return specialized; + } + + @Override + public void setEnabled(boolean enabled) + { + this.enabled = enabled; + } + + @Override + public boolean isEnabled() + { + return enabled; + } + + @Override + public String getId() + { + return passivationId; + } + + @Override + public boolean isPassivationCapable() + { + return passivationId != null; + } + + @Override + public boolean isDependent() + { + return dependent; + } + + @Override + public WebBeansContext getWebBeansContext() + { + return webBeansContext; + } + + public String toString() + { + StringBuilder builder = new StringBuilder(); + final String simpleName = getReturnType().getSimpleName(); + builder.append(simpleName); + builder.append(", WebBeansType:").append(getWebBeansType()).append(", Name:").append(getName()); + builder.append(", API Types:["); + + int size = getTypes().size(); + int index = 1; + for(Type clazz : getTypes()) + { + if(clazz instanceof Class) + { + builder.append(((Class)clazz).getName()); + } + else + { + ParameterizedType parameterizedType = (ParameterizedType) clazz; + Class rawType = (Class) parameterizedType.getRawType(); + builder.append(rawType.getName()); + builder.append("<"); + Type[] actualTypeArguments = parameterizedType.getActualTypeArguments(); + if (actualTypeArguments.length > 0) + { + for (Type actualType : actualTypeArguments) + { + if (Class.class.isInstance(actualType)) + { + builder.append(Class.class.cast(actualType).getName().replace("java.lang.", "")); + } + else + { + builder.append(actualType); + } + builder.append(","); + } + } + builder.delete(builder.length() - 1, builder.length()); + builder.append(">"); + + } + + if(index < size) + { + builder.append(","); + } + + index++; + } + + builder.append("], "); + builder.append("Qualifiers:["); + + size = getQualifiers().size(); + index = 1; + for(Annotation ann : getQualifiers()) + { + builder.append(ann.annotationType().getName()); + + if(index < size) + { + builder.append(","); + } + + index++; + } + + builder.append("]"); + + return builder.toString(); + + } } } Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/events/discovery/AfterBeanDiscoveryImpl.java URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/events/discovery/AfterBeanDiscoveryImpl.java?rev=1798230&r1=1798229&r2=1798230&view=diff ============================================================================== --- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/events/discovery/AfterBeanDiscoveryImpl.java (original) +++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/events/discovery/AfterBeanDiscoveryImpl.java Fri Jun 9 14:47:27 2017 @@ -35,6 +35,7 @@ import javax.enterprise.inject.spi.confi import org.apache.webbeans.component.ManagedBean; import org.apache.webbeans.config.OWBLogConst; import org.apache.webbeans.config.WebBeansContext; +import org.apache.webbeans.configurator.BeanConfiguratorImpl; import org.apache.webbeans.container.BeanManagerImpl; import org.apache.webbeans.exception.WebBeansConfigurationException; import org.apache.webbeans.intercept.InterceptorsManager; @@ -44,6 +45,8 @@ import org.apache.webbeans.portable.even import org.apache.webbeans.portable.events.generics.GProcessSyntheticObserverMethod; import org.apache.webbeans.util.AnnotationUtil; +import java.util.HashSet; +import java.util.Set; import java.util.logging.Level; import java.util.logging.Logger; @@ -59,6 +62,7 @@ public class AfterBeanDiscoveryImpl exte private static final Logger logger = WebBeansLoggerFacade.getLogger(AfterBeanDiscoveryImpl.class); private final WebBeansContext webBeansContext; + private Set> beanConfigurators = new HashSet<>(); private Extension extension; @@ -232,12 +236,14 @@ public class AfterBeanDiscoveryImpl exte return beanManager.getAnnotatedTypes(type); } - //X TODO OWB-1182 CDI 2.0 @Override public BeanConfigurator addBean() { checkState(); - throw new UnsupportedOperationException("CDI 2.0 not yet imlemented"); + BeanConfiguratorImpl beanConfigurator = new BeanConfiguratorImpl<>(webBeansContext); + beanConfigurators.add(beanConfigurator); + + return beanConfigurator; } //X TODO OWB-1182 CDI 2.0 @@ -248,4 +254,8 @@ public class AfterBeanDiscoveryImpl exte throw new UnsupportedOperationException("CDI 2.0 not yet imlemented"); } + public void deployConfiguredBeans() + { + beanConfigurators.forEach(bc -> addBean(bc.getBean())); + } } Modified: openwebbeans/trunk/webbeans-tck/standalone-suite.xml URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-tck/standalone-suite.xml?rev=1798230&r1=1798229&r2=1798230&view=diff ============================================================================== --- openwebbeans/trunk/webbeans-tck/standalone-suite.xml (original) +++ openwebbeans/trunk/webbeans-tck/standalone-suite.xml Fri Jun 9 14:47:27 2017 @@ -121,6 +121,17 @@ + + + + + + + + + + +