myfaces-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gpetra...@apache.org
Subject svn commit: r1130681 - in /myfaces/extensions/cdi/trunk: ./ alternative-modules/ alternative-modules/alternative-configuration-modules/core-alternative-configuration-module/ alternative-modules/alternative-configuration-modules/core-alternative-configu...
Date Thu, 02 Jun 2011 17:41:02 GMT
Author: gpetracek
Date: Thu Jun  2 17:41:01 2011
New Revision: 1130681

URL: http://svn.apache.org/viewvc?rev=1130681&view=rev
Log:
EXTCDI-177 cleanup

Added:
    myfaces/extensions/cdi/trunk/alternative-modules/alternative-implementation-module/
      - copied from r1130646, myfaces/extensions/cdi/trunk/alternative-modules/alternative-spi-module/
    myfaces/extensions/cdi/trunk/alternative-modules/alternative-implementation-module/src/main/java/org/apache/myfaces/extensions/cdi/alternative/implementation/
    myfaces/extensions/cdi/trunk/alternative-modules/alternative-implementation-module/src/main/java/org/apache/myfaces/extensions/cdi/alternative/implementation/AlternativeImplementation.java
    myfaces/extensions/cdi/trunk/alternative-modules/alternative-implementation-module/src/main/java/org/apache/myfaces/extensions/cdi/alternative/implementation/AlternativeImplementationExtension.java
    myfaces/extensions/cdi/trunk/alternative-modules/alternative-implementation-module/src/main/java/org/apache/myfaces/extensions/cdi/alternative/implementation/ConfiguredClassAggregatable.java
    myfaces/extensions/cdi/trunk/alternative-modules/alternative-implementation-module/src/main/java/org/apache/myfaces/extensions/cdi/alternative/implementation/ConfiguredClassDescriptor.java
Removed:
    myfaces/extensions/cdi/trunk/alternative-modules/alternative-implementation-module/src/main/java/org/apache/myfaces/extensions/cdi/alternative/spi/
    myfaces/extensions/cdi/trunk/alternative-modules/alternative-spi-module/
Modified:
    myfaces/extensions/cdi/trunk/alternative-modules/alternative-configuration-modules/core-alternative-configuration-module/pom.xml
    myfaces/extensions/cdi/trunk/alternative-modules/alternative-configuration-modules/core-alternative-configuration-module/src/main/java/org/apache/myfaces/extensions/cdi/core/alternative/config/AlternativeCodiCoreConfig.java
    myfaces/extensions/cdi/trunk/alternative-modules/alternative-configuration-modules/core-alternative-configuration-module/src/main/java/org/apache/myfaces/extensions/cdi/core/alternative/scope/conversation/config/AlternativeConversationConfig.java
    myfaces/extensions/cdi/trunk/alternative-modules/alternative-configuration-modules/core-alternative-configuration-module/src/main/java/org/apache/myfaces/extensions/cdi/core/alternative/scope/conversation/config/AlternativeWindowContextConfig.java
    myfaces/extensions/cdi/trunk/alternative-modules/alternative-configuration-modules/jsf-alternative-configuration-module/pom.xml
    myfaces/extensions/cdi/trunk/alternative-modules/alternative-configuration-modules/jsf-alternative-configuration-module/src/main/java/org/apache/myfaces/extensions/cdi/jsf/alternative/config/AlternativeJsfModuleConfig.java
    myfaces/extensions/cdi/trunk/alternative-modules/alternative-implementation-module/pom.xml
    myfaces/extensions/cdi/trunk/alternative-modules/alternative-implementation-module/src/main/resources/META-INF/services/javax.enterprise.inject.spi.Extension
    myfaces/extensions/cdi/trunk/alternative-modules/pom.xml
    myfaces/extensions/cdi/trunk/pom.xml

Modified: myfaces/extensions/cdi/trunk/alternative-modules/alternative-configuration-modules/core-alternative-configuration-module/pom.xml
URL: http://svn.apache.org/viewvc/myfaces/extensions/cdi/trunk/alternative-modules/alternative-configuration-modules/core-alternative-configuration-module/pom.xml?rev=1130681&r1=1130680&r2=1130681&view=diff
==============================================================================
--- myfaces/extensions/cdi/trunk/alternative-modules/alternative-configuration-modules/core-alternative-configuration-module/pom.xml
(original)
+++ myfaces/extensions/cdi/trunk/alternative-modules/alternative-configuration-modules/core-alternative-configuration-module/pom.xml
Thu Jun  2 17:41:01 2011
@@ -40,7 +40,7 @@
 
         <dependency>
             <groupId>org.apache.myfaces.extensions.cdi.modules.alternative</groupId>
-            <artifactId>myfaces-extcdi-alternative-spi-module</artifactId>
+            <artifactId>myfaces-extcdi-alternative-implementation-module</artifactId>
         </dependency>
     </dependencies>
 

Modified: myfaces/extensions/cdi/trunk/alternative-modules/alternative-configuration-modules/core-alternative-configuration-module/src/main/java/org/apache/myfaces/extensions/cdi/core/alternative/config/AlternativeCodiCoreConfig.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/cdi/trunk/alternative-modules/alternative-configuration-modules/core-alternative-configuration-module/src/main/java/org/apache/myfaces/extensions/cdi/core/alternative/config/AlternativeCodiCoreConfig.java?rev=1130681&r1=1130680&r2=1130681&view=diff
==============================================================================
--- myfaces/extensions/cdi/trunk/alternative-modules/alternative-configuration-modules/core-alternative-configuration-module/src/main/java/org/apache/myfaces/extensions/cdi/core/alternative/config/AlternativeCodiCoreConfig.java
(original)
+++ myfaces/extensions/cdi/trunk/alternative-modules/alternative-configuration-modules/core-alternative-configuration-module/src/main/java/org/apache/myfaces/extensions/cdi/core/alternative/config/AlternativeCodiCoreConfig.java
Thu Jun  2 17:41:01 2011
@@ -18,7 +18,7 @@
  */
 package org.apache.myfaces.extensions.cdi.core.alternative.config;
 
-import org.apache.myfaces.extensions.cdi.alternative.spi.AlternativeImplementation;
+import org.apache.myfaces.extensions.cdi.alternative.implementation.AlternativeImplementation;
 import org.apache.myfaces.extensions.cdi.core.api.config.CodiCoreConfig;
 import org.apache.myfaces.extensions.cdi.core.api.util.ClassUtils;
 import org.apache.myfaces.extensions.cdi.core.impl.util.CodiUtils;

Modified: myfaces/extensions/cdi/trunk/alternative-modules/alternative-configuration-modules/core-alternative-configuration-module/src/main/java/org/apache/myfaces/extensions/cdi/core/alternative/scope/conversation/config/AlternativeConversationConfig.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/cdi/trunk/alternative-modules/alternative-configuration-modules/core-alternative-configuration-module/src/main/java/org/apache/myfaces/extensions/cdi/core/alternative/scope/conversation/config/AlternativeConversationConfig.java?rev=1130681&r1=1130680&r2=1130681&view=diff
==============================================================================
--- myfaces/extensions/cdi/trunk/alternative-modules/alternative-configuration-modules/core-alternative-configuration-module/src/main/java/org/apache/myfaces/extensions/cdi/core/alternative/scope/conversation/config/AlternativeConversationConfig.java
(original)
+++ myfaces/extensions/cdi/trunk/alternative-modules/alternative-configuration-modules/core-alternative-configuration-module/src/main/java/org/apache/myfaces/extensions/cdi/core/alternative/scope/conversation/config/AlternativeConversationConfig.java
Thu Jun  2 17:41:01 2011
@@ -18,7 +18,7 @@
  */
 package org.apache.myfaces.extensions.cdi.core.alternative.scope.conversation.config;
 
-import org.apache.myfaces.extensions.cdi.alternative.spi.AlternativeImplementation;
+import org.apache.myfaces.extensions.cdi.alternative.implementation.AlternativeImplementation;
 import org.apache.myfaces.extensions.cdi.core.api.scope.conversation.config.ConversationConfig;
 import org.apache.myfaces.extensions.cdi.core.api.util.ClassUtils;
 import org.apache.myfaces.extensions.cdi.core.impl.util.CodiUtils;

Modified: myfaces/extensions/cdi/trunk/alternative-modules/alternative-configuration-modules/core-alternative-configuration-module/src/main/java/org/apache/myfaces/extensions/cdi/core/alternative/scope/conversation/config/AlternativeWindowContextConfig.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/cdi/trunk/alternative-modules/alternative-configuration-modules/core-alternative-configuration-module/src/main/java/org/apache/myfaces/extensions/cdi/core/alternative/scope/conversation/config/AlternativeWindowContextConfig.java?rev=1130681&r1=1130680&r2=1130681&view=diff
==============================================================================
--- myfaces/extensions/cdi/trunk/alternative-modules/alternative-configuration-modules/core-alternative-configuration-module/src/main/java/org/apache/myfaces/extensions/cdi/core/alternative/scope/conversation/config/AlternativeWindowContextConfig.java
(original)
+++ myfaces/extensions/cdi/trunk/alternative-modules/alternative-configuration-modules/core-alternative-configuration-module/src/main/java/org/apache/myfaces/extensions/cdi/core/alternative/scope/conversation/config/AlternativeWindowContextConfig.java
Thu Jun  2 17:41:01 2011
@@ -18,7 +18,7 @@
  */
 package org.apache.myfaces.extensions.cdi.core.alternative.scope.conversation.config;
 
-import org.apache.myfaces.extensions.cdi.alternative.spi.AlternativeImplementation;
+import org.apache.myfaces.extensions.cdi.alternative.implementation.AlternativeImplementation;
 import org.apache.myfaces.extensions.cdi.core.api.scope.conversation.config.WindowContextConfig;
 import org.apache.myfaces.extensions.cdi.core.api.util.ClassUtils;
 import org.apache.myfaces.extensions.cdi.core.impl.util.CodiUtils;

Modified: myfaces/extensions/cdi/trunk/alternative-modules/alternative-configuration-modules/jsf-alternative-configuration-module/pom.xml
URL: http://svn.apache.org/viewvc/myfaces/extensions/cdi/trunk/alternative-modules/alternative-configuration-modules/jsf-alternative-configuration-module/pom.xml?rev=1130681&r1=1130680&r2=1130681&view=diff
==============================================================================
--- myfaces/extensions/cdi/trunk/alternative-modules/alternative-configuration-modules/jsf-alternative-configuration-module/pom.xml
(original)
+++ myfaces/extensions/cdi/trunk/alternative-modules/alternative-configuration-modules/jsf-alternative-configuration-module/pom.xml
Thu Jun  2 17:41:01 2011
@@ -44,7 +44,7 @@
 
         <dependency>
             <groupId>org.apache.myfaces.extensions.cdi.modules.alternative</groupId>
-            <artifactId>myfaces-extcdi-alternative-spi-module</artifactId>
+            <artifactId>myfaces-extcdi-alternative-implementation-module</artifactId>
         </dependency>
     </dependencies>
 

Modified: myfaces/extensions/cdi/trunk/alternative-modules/alternative-configuration-modules/jsf-alternative-configuration-module/src/main/java/org/apache/myfaces/extensions/cdi/jsf/alternative/config/AlternativeJsfModuleConfig.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/cdi/trunk/alternative-modules/alternative-configuration-modules/jsf-alternative-configuration-module/src/main/java/org/apache/myfaces/extensions/cdi/jsf/alternative/config/AlternativeJsfModuleConfig.java?rev=1130681&r1=1130680&r2=1130681&view=diff
==============================================================================
--- myfaces/extensions/cdi/trunk/alternative-modules/alternative-configuration-modules/jsf-alternative-configuration-module/src/main/java/org/apache/myfaces/extensions/cdi/jsf/alternative/config/AlternativeJsfModuleConfig.java
(original)
+++ myfaces/extensions/cdi/trunk/alternative-modules/alternative-configuration-modules/jsf-alternative-configuration-module/src/main/java/org/apache/myfaces/extensions/cdi/jsf/alternative/config/AlternativeJsfModuleConfig.java
Thu Jun  2 17:41:01 2011
@@ -18,7 +18,7 @@
  */
 package org.apache.myfaces.extensions.cdi.jsf.alternative.config;
 
-import org.apache.myfaces.extensions.cdi.alternative.spi.AlternativeImplementation;
+import org.apache.myfaces.extensions.cdi.alternative.implementation.AlternativeImplementation;
 import org.apache.myfaces.extensions.cdi.core.api.util.ClassUtils;
 import org.apache.myfaces.extensions.cdi.core.impl.util.CodiUtils;
 import org.apache.myfaces.extensions.cdi.jsf.api.config.JsfModuleConfig;

Modified: myfaces/extensions/cdi/trunk/alternative-modules/alternative-implementation-module/pom.xml
URL: http://svn.apache.org/viewvc/myfaces/extensions/cdi/trunk/alternative-modules/alternative-implementation-module/pom.xml?rev=1130681&r1=1130646&r2=1130681&view=diff
==============================================================================
--- myfaces/extensions/cdi/trunk/alternative-modules/alternative-implementation-module/pom.xml
(original)
+++ myfaces/extensions/cdi/trunk/alternative-modules/alternative-implementation-module/pom.xml
Thu Jun  2 17:41:01 2011
@@ -27,10 +27,10 @@
     </parent>
 
     <groupId>org.apache.myfaces.extensions.cdi.modules.alternative</groupId>
-    <artifactId>myfaces-extcdi-alternative-spi-module</artifactId>
+    <artifactId>myfaces-extcdi-alternative-implementation-module</artifactId>
     <version>1.0.0-SNAPSHOT</version>
 
-    <name>MyFaces Extensions-CDI Alternative-SPI Module</name>
+    <name>MyFaces Extensions-CDI Alternative-Implementation Module</name>
 
     <dependencies>
         <dependency>

Added: myfaces/extensions/cdi/trunk/alternative-modules/alternative-implementation-module/src/main/java/org/apache/myfaces/extensions/cdi/alternative/implementation/AlternativeImplementation.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/cdi/trunk/alternative-modules/alternative-implementation-module/src/main/java/org/apache/myfaces/extensions/cdi/alternative/implementation/AlternativeImplementation.java?rev=1130681&view=auto
==============================================================================
--- myfaces/extensions/cdi/trunk/alternative-modules/alternative-implementation-module/src/main/java/org/apache/myfaces/extensions/cdi/alternative/implementation/AlternativeImplementation.java
(added)
+++ myfaces/extensions/cdi/trunk/alternative-modules/alternative-implementation-module/src/main/java/org/apache/myfaces/extensions/cdi/alternative/implementation/AlternativeImplementation.java
Thu Jun  2 17:41:01 2011
@@ -0,0 +1,48 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.myfaces.extensions.cdi.alternative.implementation;
+
+import java.lang.annotation.Documented;
+import java.lang.annotation.Retention;
+import java.lang.annotation.Target;
+
+import static java.lang.annotation.ElementType.TYPE;
+import static java.lang.annotation.RetentionPolicy.RUNTIME;
+
+/**
+ * Only for the config and SPI of CODI!
+ *
+ * Annotate a bean which implements a SPI of CODI or extends a config class of CODI.
+ * In case of implementing a SPI it's required to register the custom class.
+ * So it will be checked by the {@link java.util.ServiceLoader}.
+ *
+ * In case of extending a config class of CODI, you have to do the same.
+ * However, since the config classes aren't abstract or have a special interface,
+ * it's required to register the custom class in a file called:
+ * MEtA-INF/services/org.apache.myfaces.extensions.cdi.core.api.config.CodiConfig
+ *
+ * @author Gerhard Petracek
+ */
+@Target({TYPE})
+@Retention(RUNTIME)
+@Documented
+
+public @interface AlternativeImplementation
+{
+}

Added: myfaces/extensions/cdi/trunk/alternative-modules/alternative-implementation-module/src/main/java/org/apache/myfaces/extensions/cdi/alternative/implementation/AlternativeImplementationExtension.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/cdi/trunk/alternative-modules/alternative-implementation-module/src/main/java/org/apache/myfaces/extensions/cdi/alternative/implementation/AlternativeImplementationExtension.java?rev=1130681&view=auto
==============================================================================
--- myfaces/extensions/cdi/trunk/alternative-modules/alternative-implementation-module/src/main/java/org/apache/myfaces/extensions/cdi/alternative/implementation/AlternativeImplementationExtension.java
(added)
+++ myfaces/extensions/cdi/trunk/alternative-modules/alternative-implementation-module/src/main/java/org/apache/myfaces/extensions/cdi/alternative/implementation/AlternativeImplementationExtension.java
Thu Jun  2 17:41:01 2011
@@ -0,0 +1,150 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.myfaces.extensions.cdi.alternative.implementation;
+
+import org.apache.myfaces.extensions.cdi.core.api.config.CodiConfig;
+import org.apache.myfaces.extensions.cdi.core.impl.config.ServiceLoaderResolver;
+import org.apache.myfaces.extensions.cdi.core.impl.util.CodiUtils;
+
+import javax.enterprise.event.Observes;
+import javax.enterprise.inject.Specializes;
+import javax.enterprise.inject.Typed;
+import javax.enterprise.inject.spi.Extension;
+import javax.enterprise.inject.spi.ProcessAnnotatedType;
+import java.io.Serializable;
+import java.lang.reflect.Modifier;
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * @author Gerhard Petracek
+ */
+public class AlternativeImplementationExtension implements Extension
+{
+    protected <T> void vetoDefaultImplementation(@Observes ProcessAnnotatedType<T>
processAnnotatedType)
+    {
+        Class<?> beanClass = processAnnotatedType.getAnnotatedType().getJavaClass();
+
+        //only filter default implementations of codi which are beans and don't filter a
+        //AlternativeImplementation provided by e.g. the codi alternative config module
+        if (!beanClass.getName().startsWith("org.apache.myfaces.extensions.cdi.") ||
+                beanClass.isAnnotationPresent(AlternativeImplementation.class) ||
+                beanClass.isAnnotationPresent(Specializes.class) ||
+                (beanClass.isAnnotationPresent(Typed.class) &&
+                        beanClass.getAnnotation(Typed.class).value().length == 0))
+        {
+            return;
+        }
+
+        if (beanClass.isInterface() || Modifier.isAbstract(beanClass.getModifiers()))
+        {
+            return;
+        }
+
+        final boolean configClassMode = CodiConfig.class.isAssignableFrom(beanClass);
+
+        List<Class> spiClassCandidates = findSpiClassCandidates(beanClass);
+
+        List customImplementations = new ArrayList();
+
+        Object customImplementation = null;
+
+        for (Class spiClass : spiClassCandidates)
+        {
+            if (Serializable.class.isAssignableFrom(beanClass))
+            {
+                if(!CodiConfig.class.getName().equals(spiClass.getName()))
+                {
+                    customImplementation = CodiUtils.lookupFromEnvironment(spiClass,
+                            new ConfiguredClassAggregatable(spiClass, customImplementations,
configClassMode));
+                }
+                else
+                {
+                    customImplementation = CodiUtils.lookupFromEnvironment(spiClass,
+                            new ConfiguredClassAggregatable(beanClass, customImplementations,
configClassMode));
+                }
+            }
+            else
+            {
+                //noinspection unchecked
+                customImplementation = tryToLoadCustomClassViaServiceLoader(spiClass);
+            }
+
+            if (customImplementation != null)
+            {
+                break;
+            }
+        }
+
+        if (customImplementation != null)
+        {
+            //veto default implementation of codi
+            processAnnotatedType.veto();
+        }
+    }
+
+    private Object tryToLoadCustomClassViaServiceLoader(Class spiClass)
+    {
+        List customImplementations = new ServiceLoaderResolver()
+                .resolveInstances(new ConfiguredClassDescriptor(spiClass));
+
+        if(customImplementations.isEmpty())
+        {
+            return null;
+        }
+
+        if (customImplementations.size() > 1)
+        {
+            //TODO
+            //here we have a spi which is used for other purposes
+            return null;
+        }
+
+        return customImplementations.iterator().next();
+    }
+
+    private <T> List<Class> findSpiClassCandidates(Class<T> beanClass)
+    {
+        List<Class> result = new ArrayList<Class>();
+
+        Class<?> currentClass = beanClass;
+        while (currentClass != null && !Object.class.getName().equals(currentClass.getName()))
+        {
+            //only codi spis are supported
+            if(currentClass.getName().startsWith("org.apache.myfaces.extensions.cdi."))
+            {
+                if ((Modifier.isAbstract(currentClass.getModifiers()) ||
+                        Modifier.isInterface(currentClass.getModifiers())))
+                {
+                    result.add(currentClass);
+                }
+            }
+
+            //scan interfaces
+            for (Class interfaceClass : currentClass.getInterfaces())
+            {
+                result.addAll(findSpiClassCandidates(interfaceClass));
+            }
+
+            currentClass = currentClass.getSuperclass();
+        }
+
+        return result;
+    }
+}

Added: myfaces/extensions/cdi/trunk/alternative-modules/alternative-implementation-module/src/main/java/org/apache/myfaces/extensions/cdi/alternative/implementation/ConfiguredClassAggregatable.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/cdi/trunk/alternative-modules/alternative-implementation-module/src/main/java/org/apache/myfaces/extensions/cdi/alternative/implementation/ConfiguredClassAggregatable.java?rev=1130681&view=auto
==============================================================================
--- myfaces/extensions/cdi/trunk/alternative-modules/alternative-implementation-module/src/main/java/org/apache/myfaces/extensions/cdi/alternative/implementation/ConfiguredClassAggregatable.java
(added)
+++ myfaces/extensions/cdi/trunk/alternative-modules/alternative-implementation-module/src/main/java/org/apache/myfaces/extensions/cdi/alternative/implementation/ConfiguredClassAggregatable.java
Thu Jun  2 17:41:01 2011
@@ -0,0 +1,96 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.myfaces.extensions.cdi.alternative.implementation;
+
+import org.apache.myfaces.extensions.cdi.core.api.Aggregatable;
+
+import javax.enterprise.inject.Typed;
+import java.util.List;
+
+/**
+ * @author Gerhard Petracek
+ */
+@Typed()
+class ConfiguredClassAggregatable<T> implements Aggregatable<T>
+{
+    private Class spiClass;
+    private List<T> customImplementations;
+    private boolean configClassMode;
+
+    ConfiguredClassAggregatable()
+    {
+    }
+
+    ConfiguredClassAggregatable(Class spiClass, List customImplementations, boolean configClassMode)
+    {
+        this.spiClass = spiClass;
+        this.customImplementations = customImplementations;
+        this.configClassMode = configClassMode;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public void add(T o)
+    {
+        if (o.getClass().isAnnotationPresent(AlternativeImplementation.class))
+        {
+            this.customImplementations.add(o);
+        }
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public T create()
+    {
+        if(!this.configClassMode)
+        {
+            if (this.customImplementations.size() > 1)
+            {
+                //TODO
+                //here we have a spi which is used for other purposes
+                return null;
+            }
+
+            if (this.customImplementations.size() == 1)
+            {
+                return this.customImplementations.iterator().next();
+            }
+        }
+        else if(!this.customImplementations.isEmpty())
+        {
+            return filterCustomCodiConfigImplementation();
+        }
+        return null;
+    }
+
+    private T filterCustomCodiConfigImplementation()
+    {
+        Class configClass = this.spiClass;
+        for(T customImplementation : this.customImplementations)
+        {
+            if(configClass.isAssignableFrom(customImplementation.getClass()))
+            {
+                return customImplementation;
+            }
+        }
+        return null;
+    }
+}

Added: myfaces/extensions/cdi/trunk/alternative-modules/alternative-implementation-module/src/main/java/org/apache/myfaces/extensions/cdi/alternative/implementation/ConfiguredClassDescriptor.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/cdi/trunk/alternative-modules/alternative-implementation-module/src/main/java/org/apache/myfaces/extensions/cdi/alternative/implementation/ConfiguredClassDescriptor.java?rev=1130681&view=auto
==============================================================================
--- myfaces/extensions/cdi/trunk/alternative-modules/alternative-implementation-module/src/main/java/org/apache/myfaces/extensions/cdi/alternative/implementation/ConfiguredClassDescriptor.java
(added)
+++ myfaces/extensions/cdi/trunk/alternative-modules/alternative-implementation-module/src/main/java/org/apache/myfaces/extensions/cdi/alternative/implementation/ConfiguredClassDescriptor.java
Thu Jun  2 17:41:01 2011
@@ -0,0 +1,57 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.myfaces.extensions.cdi.alternative.implementation;
+
+import org.apache.myfaces.extensions.cdi.core.api.config.ConfiguredValueDescriptor;
+
+import javax.enterprise.inject.Typed;
+
+/**
+ * @author Gerhard Petracek
+ */
+@Typed()
+class ConfiguredClassDescriptor implements ConfiguredValueDescriptor<Class, Object>
+{
+    private Class configuredClass;
+
+    ConfiguredClassDescriptor()
+    {
+    }
+
+    ConfiguredClassDescriptor(Class configuredClass)
+    {
+        this.configuredClass = configuredClass;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public Class getKey()
+    {
+        return this.configuredClass;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public Class<Object> getTargetType()
+    {
+        return this.configuredClass;
+    }
+}

Modified: myfaces/extensions/cdi/trunk/alternative-modules/alternative-implementation-module/src/main/resources/META-INF/services/javax.enterprise.inject.spi.Extension
URL: http://svn.apache.org/viewvc/myfaces/extensions/cdi/trunk/alternative-modules/alternative-implementation-module/src/main/resources/META-INF/services/javax.enterprise.inject.spi.Extension?rev=1130681&r1=1130646&r2=1130681&view=diff
==============================================================================
--- myfaces/extensions/cdi/trunk/alternative-modules/alternative-implementation-module/src/main/resources/META-INF/services/javax.enterprise.inject.spi.Extension
(original)
+++ myfaces/extensions/cdi/trunk/alternative-modules/alternative-implementation-module/src/main/resources/META-INF/services/javax.enterprise.inject.spi.Extension
Thu Jun  2 17:41:01 2011
@@ -17,4 +17,4 @@
 # under the License.
 #####################################################################################
 
-org.apache.myfaces.extensions.cdi.alternative.spi.AlternativeImplementationExtension
\ No newline at end of file
+org.apache.myfaces.extensions.cdi.alternative.implementation.AlternativeImplementationExtension
\ No newline at end of file

Modified: myfaces/extensions/cdi/trunk/alternative-modules/pom.xml
URL: http://svn.apache.org/viewvc/myfaces/extensions/cdi/trunk/alternative-modules/pom.xml?rev=1130681&r1=1130680&r2=1130681&view=diff
==============================================================================
--- myfaces/extensions/cdi/trunk/alternative-modules/pom.xml (original)
+++ myfaces/extensions/cdi/trunk/alternative-modules/pom.xml Thu Jun  2 17:41:01 2011
@@ -36,7 +36,7 @@
 
     <modules>
         <module>alternative-configuration-modules</module>
-        <module>alternative-spi-module</module>
+        <module>alternative-implementation-module</module>
     </modules>
 
 </project>

Modified: myfaces/extensions/cdi/trunk/pom.xml
URL: http://svn.apache.org/viewvc/myfaces/extensions/cdi/trunk/pom.xml?rev=1130681&r1=1130680&r2=1130681&view=diff
==============================================================================
--- myfaces/extensions/cdi/trunk/pom.xml (original)
+++ myfaces/extensions/cdi/trunk/pom.xml Thu Jun  2 17:41:01 2011
@@ -324,7 +324,7 @@
 
             <dependency>
                 <groupId>org.apache.myfaces.extensions.cdi.modules.alternative</groupId>
-                <artifactId>myfaces-extcdi-alternative-spi-module</artifactId>
+                <artifactId>myfaces-extcdi-alternative-implementation-module</artifactId>
                 <version>1.0.0-SNAPSHOT</version>
                 <scope>provided</scope>
             </dependency>



Mime
View raw message