openwebbeans-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From strub...@apache.org
Subject svn commit: r1798403 - in /openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans: configurator/ProducerConfiguratorImpl.java portable/events/ProcessProducerImpl.java
Date Sun, 11 Jun 2017 20:31:40 GMT
Author: struberg
Date: Sun Jun 11 20:31:40 2017
New Revision: 1798403

URL: http://svn.apache.org/viewvc?rev=1798403&view=rev
Log:
OWB-1187 implement ProducerConfigurator

Weird as it misses a way to configure the InjectionPoints for the Producer.
So this will never work properly per the current spec...

Modified:
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/configurator/ProducerConfiguratorImpl.java
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/events/ProcessProducerImpl.java

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/configurator/ProducerConfiguratorImpl.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/configurator/ProducerConfiguratorImpl.java?rev=1798403&r1=1798402&r2=1798403&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/configurator/ProducerConfiguratorImpl.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/configurator/ProducerConfiguratorImpl.java
Sun Jun 11 20:31:40 2017
@@ -18,21 +18,64 @@
  */
 package org.apache.webbeans.configurator;
 
+import javax.enterprise.context.spi.CreationalContext;
+import javax.enterprise.inject.spi.InjectionPoint;
+import javax.enterprise.inject.spi.Producer;
 import javax.enterprise.inject.spi.configurator.ProducerConfigurator;
+import java.util.HashSet;
+import java.util.Set;
 import java.util.function.Consumer;
 import java.util.function.Function;
 
-public class ProducerConfiguratorImpl implements ProducerConfigurator
+public class ProducerConfiguratorImpl<T> implements ProducerConfigurator<T>
 {
+    private Function produceWithCallback;
+    private Consumer disposeWithCallback;
+    private Set<InjectionPoint> injectionPoints = new HashSet<>();
+
     @Override
-    public ProducerConfigurator produceWith(Function callback)
+    public<U extends T> ProducerConfigurator<T> produceWith(Function<CreationalContext<U>,
U> callback)
     {
-        throw new UnsupportedOperationException("TODO implement CDI 2.0");
+        this.produceWithCallback = callback;
+        return this;
     }
 
     @Override
-    public ProducerConfigurator disposeWith(Consumer callback)
+    public ProducerConfigurator<T> disposeWith(Consumer<T> callback)
+    {
+        this.disposeWithCallback = callback;
+        return this;
+    }
+
+    public ProducerConfigurator<T> addInjectionPoint(InjectionPoint injectionPoint)
+    {
+        this.injectionPoints.add(injectionPoint);
+        return this;
+    }
+
+    public <T> Producer<T> getProducer()
+    {
+        return new ConfiguredProducer();
+    }
+
+    public class ConfiguredProducer<T> implements Producer<T>
     {
-        throw new UnsupportedOperationException("TODO implement CDI 2.0");
+        @Override
+        public T produce(CreationalContext<T> creationalContext)
+        {
+            return (T) produceWithCallback.apply(creationalContext);
+        }
+
+        @Override
+        public void dispose(T instance)
+        {
+            disposeWithCallback.accept(instance);
+        }
+
+        @Override
+        public Set<InjectionPoint> getInjectionPoints()
+        {
+            return injectionPoints;
+        }
     }
 }

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/events/ProcessProducerImpl.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/events/ProcessProducerImpl.java?rev=1798403&r1=1798402&r2=1798403&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/events/ProcessProducerImpl.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/events/ProcessProducerImpl.java
Sun Jun 11 20:31:40 2017
@@ -24,6 +24,7 @@ import javax.enterprise.inject.spi.Produ
 import javax.enterprise.inject.spi.configurator.ProducerConfigurator;
 
 import org.apache.webbeans.config.WebBeansContext;
+import org.apache.webbeans.configurator.ProducerConfiguratorImpl;
 
 /**
  * Implementation of {@link ProcessProducer}.
@@ -40,6 +41,8 @@ public class ProcessProducerImpl<X,T> ex
     
     /**Used by container to produce instance for producer method or field*/
     private Producer<T> producer = null;
+
+    private ProducerConfiguratorImpl<T> producerConfigurator = null;
     
     public ProcessProducerImpl(Producer<T> producer,AnnotatedMember<X> annotateMember)
     {
@@ -57,11 +60,13 @@ public class ProcessProducerImpl<X,T> ex
         WebBeansContext.getInstance().getBeanManagerImpl().getErrorStack().pushError(t);
     }
 
-    //X TODO OWB-1182 CDI 2.0
     @Override
     public ProducerConfigurator<T> configureProducer()
     {
-        throw new UnsupportedOperationException("CDI 2.0 not yet imlemented");
+        checkState();
+        this.producerConfigurator = new ProducerConfiguratorImpl<>();
+        this.producer = null;
+        return producerConfigurator;
     }
 
     /**
@@ -81,6 +86,10 @@ public class ProcessProducerImpl<X,T> ex
     public Producer<T> getProducer()
     {
         checkState();
+        if (producerConfigurator != null)
+        {
+            return producerConfigurator.getProducer();
+        }
         return producer;
     }
 
@@ -92,5 +101,6 @@ public class ProcessProducerImpl<X,T> ex
     {
         checkState();
         this.producer = producer;
+        this.producerConfigurator = null;
     }
 }



Mime
View raw message