openwebbeans-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From strub...@apache.org
Subject svn commit: r767580 - in /incubator/openwebbeans/trunk/webbeans-impl/src: main/java/org/apache/webbeans/container/ChildActivityManager.java main/java/org/apache/webbeans/container/ManagerImpl.java test/java/org/apache/webbeans/test/mock/MockManager.java
Date Wed, 22 Apr 2009 16:12:58 GMT
Author: struberg
Date: Wed Apr 22 16:12:58 2009
New Revision: 767580

URL: http://svn.apache.org/viewvc?rev=767580&view=rev
Log:
OWB-94 CreationanContext<?> instead of <T>
OWB-68 introduce new ChildActivityManager

Added:
    incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/container/ChildActivityManager.java
Modified:
    incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/container/ManagerImpl.java
    incubator/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/mock/MockManager.java

Added: incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/container/ChildActivityManager.java
URL: http://svn.apache.org/viewvc/incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/container/ChildActivityManager.java?rev=767580&view=auto
==============================================================================
--- incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/container/ChildActivityManager.java
(added)
+++ incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/container/ChildActivityManager.java
Wed Apr 22 16:12:58 2009
@@ -0,0 +1,285 @@
+/*
+ * 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.webbeans.container;
+
+import java.io.InputStream;
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Type;
+import java.util.List;
+import java.util.Set;
+
+import javax.context.Context;
+import javax.context.CreationalContext;
+import javax.event.Observer;
+import javax.inject.TypeLiteral;
+import javax.inject.manager.Bean;
+import javax.inject.manager.Decorator;
+import javax.inject.manager.InjectionPoint;
+import javax.inject.manager.InterceptionType;
+import javax.inject.manager.Interceptor;
+import javax.inject.manager.Manager;
+
+/**
+ * Each Manager can start a new child activity as defined by the JSR-299 spec chapter 11.6
+ * 
+ * A ChildActivityManager tries to handle the beans, contexts, ... itself 
+ * and delegates all other requests to it's parent Manager. 
+ *
+ */
+public class ChildActivityManager implements Manager
+{
+
+    /**
+     * The parent Manager this child is depending from.
+     */
+    private Manager parent;
+    
+    /**
+     * All beans added to this instance will be tracked by this very Manager
+     */
+    private Manager self;
+    
+    /**
+     * the ct will be called by {@code Manager#createActivity()}
+     * @param parent is the Manager calling this ct
+     */
+    public ChildActivityManager(Manager parent)
+    {
+        this.parent = parent;
+        this.self = new ManagerImpl();
+    }
+    
+    /** {@inheritDoc} */
+    public Manager addBean(Bean<?> bean)
+    {
+        //X TODO possibly add checks
+        return self.addBean(bean);
+    }
+
+    /** {@inheritDoc} */
+    public Manager addContext(Context context)
+    {
+        //X TODO possibly add checks
+        return self.addContext(context);
+    }
+
+    /** {@inheritDoc} */
+    public Manager addDecorator(Decorator decorator)
+    {
+        throw new UnsupportedOperationException("Decorators may not be registered with a
child activity.");
+    }
+
+    /** {@inheritDoc} */
+    public Manager addInterceptor(Interceptor interceptor)
+    {
+        throw new UnsupportedOperationException("Interceptors may not be registered with
a child activity.");
+    }
+
+    /** {@inheritDoc} */
+    public <T> Manager addObserver(Observer<T> observer, Class<T> eventType,
Annotation... bindings)
+    {
+        //X TODO possibly add checks
+        return self.addObserver(observer, eventType, bindings);
+    }
+
+    /** {@inheritDoc} */
+    public <T> Manager addObserver(Observer<T> observer, TypeLiteral<T>
eventType, Annotation... bindings)
+    {
+        //X TODO possibly add checks
+        return self.addObserver(observer, eventType, bindings);
+    }
+
+    /** {@inheritDoc} */
+    public Manager createActivity()
+    {
+        return new ChildActivityManager(this);
+    }
+
+    /** {@inheritDoc} */
+    public void fireEvent(Object event, Annotation... bindings)
+    {
+        // TODO Auto-generated method stub
+
+    }
+
+    /** {@inheritDoc} */
+    public Context getContext(Class<? extends Annotation> scopeType)
+    {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+    /** {@inheritDoc} */
+    public <T> T getInstance(Bean<T> bean)
+    {
+        //X TODO not 100% sure if this is ok. There is some 'double-definition' exception
case defined in the spec ...
+        T obj = self.getInstance(bean);
+        if (obj == null) 
+        {
+            obj = parent.getInstance(bean);
+        }
+        return obj;
+    }
+
+    /** {@inheritDoc} */
+    public Object getInstanceByName(String name)
+    {
+        //X TODO not 100% sure if this is ok. There is some 'double-definition' exception
case defined in the spec ...
+        Object obj = self.getInstanceByName(name);
+        if (obj == null) 
+        {
+            obj = parent.getInstanceByName(name);
+        }
+        return obj;
+    }
+
+    /** {@inheritDoc} */
+    public <T> T getInstanceByType(Class<T> type, Annotation... bindingTypes)
+    {
+        //X TODO not 100% sure if this is ok. There is some 'double-definition' exception
case defined in the spec ...
+        T obj = self.getInstanceByType(type, bindingTypes);
+        if (obj == null) 
+        {
+            obj = parent.getInstanceByType(type, bindingTypes);
+        }
+        return obj;
+    }
+
+    /** {@inheritDoc} */
+    public <T> T getInstanceByType(TypeLiteral<T> type, Annotation... bindingTypes)
+    {
+        //X TODO not 100% sure if this is ok. There is some 'double-definition' exception
case defined in the spec ...
+        T obj = self.getInstanceByType(type, bindingTypes);
+        if (obj == null) 
+        {
+            obj = parent.getInstanceByType(type, bindingTypes);
+        }
+        return obj;
+    }
+
+    /** {@inheritDoc} */
+    public <T> T getInstanceToInject(InjectionPoint injectionPoint, CreationalContext<?>
context)
+    {
+        //X TODO not 100% sure if this is ok. There is some 'double-definition' exception
case defined in the spec ...
+        T obj = self.<T>getInstanceToInject(injectionPoint, context); //X ugly <T>
due to javac bug 6302954
+        if (obj == null) 
+        {
+            obj = parent.<T>getInstanceToInject(injectionPoint, context); //X ugly
<T> due to javac bug 6302954
+        }
+        return obj;
+    }
+
+    /** {@inheritDoc} */
+    public <T> T getInstanceToInject(InjectionPoint injectionPoint)
+    {
+        //X TODO not 100% sure if this is ok. There is some 'double-definition' exception
case defined in the spec ...
+        T obj = self.<T>getInstanceToInject(injectionPoint); //X ugly <T> due
to javac bug 6302954
+        if (obj == null) 
+        {
+            obj = parent.<T>getInstanceToInject(injectionPoint); //X ugly <T>
due to javac bug 6302954
+        }
+        return obj;
+    }
+
+    /** {@inheritDoc} */
+    public Manager parse(InputStream xmlStream)
+    {
+        self.parse(xmlStream);
+        return this;
+    }
+
+    /** {@inheritDoc} */
+    public <T> Manager removeObserver(Observer<T> observer, Class<T> eventType,
Annotation... bindings)
+    {
+        //X TODO check if the user tries to remove an Observer from the parent -> Exception
+        self.removeObserver(observer, eventType, bindings);
+        return this;
+    }
+
+    /** {@inheritDoc} */
+    public <T> Manager removeObserver(Observer<T> observer, TypeLiteral<T>
eventType, Annotation... bindings)
+    {
+        //X TODO check if the user tries to remove an Observer from the parent -> Exception
+        self.removeObserver(observer, eventType, bindings);
+        return this;
+    }
+
+    /** {@inheritDoc} */
+    public Set<Bean<?>> resolveByName(String name)
+    {
+        //X TODO not 100% sure if this is ok. There is some 'double-definition' exception
case defined in the spec ...
+        Set<Bean<?>> set = self.resolveByName(name);
+        if (set == null || set.isEmpty()) 
+        {
+            set = parent.resolveByName(name);
+        }
+        return set;
+    }
+
+    /** {@inheritDoc} */
+    public <T> Set<Bean<T>> resolveByType(Class<T> type, Annotation...
bindings)
+    {
+        //X TODO not 100% sure if this is ok. There is some 'double-definition' exception
case defined in the spec ...
+        Set<Bean<T>> set = self.resolveByType(type, bindings);
+        if (set == null || set.isEmpty()) 
+        {
+            set = parent.resolveByType(type, bindings);
+        }
+        return set;
+    }
+
+    /** {@inheritDoc} */
+    public <T> Set<Bean<T>> resolveByType(TypeLiteral<T> apiType,
Annotation... bindingTypes)
+    {
+        //X TODO not 100% sure if this is ok. There is some 'double-definition' exception
case defined in the spec ...
+        Set<Bean<T>> set = self.resolveByType(apiType, bindingTypes);
+        if (set == null || set.isEmpty()) 
+        {
+            set = parent.resolveByType(apiType, bindingTypes);
+        }
+        return set;
+    }
+
+    /** {@inheritDoc} */
+    public List<Decorator> resolveDecorators(Set<Type> types, Annotation... bindingTypes)
+    {
+        throw new UnsupportedOperationException("Decorators may not be registered with a
child activity.");    
+    }
+
+    /** {@inheritDoc} */
+    public List<Interceptor> resolveInterceptors(InterceptionType type, Annotation...
interceptorBindings)
+    {
+        throw new UnsupportedOperationException("Interceptors may not be registered with
a child activity.");    
+    }
+
+    /** {@inheritDoc} */
+    public <T> Set<Observer<T>> resolveObservers(T event, Annotation...
bindings)
+    {
+        //X TODO not 100% sure if this is ok. There is some 'double-definition' exception
case defined in the spec ...
+        Set<Observer<T>> set = self.resolveObservers(event, bindings);
+        if (set == null || set.isEmpty()) 
+        {
+            set = parent.resolveObservers(event, bindings);
+        }
+        return set;
+    }
+
+    /** {@inheritDoc} */
+    public Manager setCurrent(Class<? extends Annotation> scopeType)
+    {
+        //X TODO what about parent? we must not set the current scope type for parents, but
what are the implications?
+        self.setCurrent(scopeType);
+        return this;
+    }
+}

Modified: incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/container/ManagerImpl.java
URL: http://svn.apache.org/viewvc/incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/container/ManagerImpl.java?rev=767580&r1=767579&r2=767580&view=diff
==============================================================================
--- incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/container/ManagerImpl.java
(original)
+++ incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/container/ManagerImpl.java
Wed Apr 22 16:12:58 2009
@@ -218,7 +218,7 @@
         return object;
     }
     
-    public <T> T getInstanceToInject(InjectionPoint injectionPoint, CreationalContext<T>
context)
+    public <T> T getInstanceToInject(InjectionPoint injectionPoint, CreationalContext<?>
context)
     {
         T instance = null;
         
@@ -464,7 +464,7 @@
         }
         else
         {
-            //Mark , this brokes the TCK tests!!!!
+//X TODO Mark , this brokes the TCK tests!!!!
 //            if (context.isActive() && containsActiveContext(contextList))
 //            {
 //                throw new IllegalStateException("There is already an active Context registered
for this scope! Context=" + context.getScopeType());
@@ -492,27 +492,12 @@
         return this;
     }
 
-//    /**
-//     * Check if the given contextList contains an active Context
-//     * @param contextList
-//     * @return <code>true</code> if the given contextList contains an active
Context, <code>false</code> otherwise
-//     */
-//    private boolean containsActiveContext(List<Context> contextList)
-//    {
-//        for (Context c : contextList)
-//        {
-//            if (c.isActive())
-//            {
-//                return true;
-//            }
-//        }
-//        return false;
-//    }
-    
+    /**
+     * Create a new ChildActivityManager.
+     */
     public Manager createActivity()
     {
-        // TODO Auto-generated method stub
-        return null;
+        return new ChildActivityManager(this);
     }
 
     public Manager setCurrent(Class<? extends Annotation> scopeType)

Modified: incubator/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/mock/MockManager.java
URL: http://svn.apache.org/viewvc/incubator/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/mock/MockManager.java?rev=767580&r1=767579&r2=767580&view=diff
==============================================================================
--- incubator/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/mock/MockManager.java
(original)
+++ incubator/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/mock/MockManager.java
Wed Apr 22 16:12:58 2009
@@ -120,9 +120,9 @@
         return manager.getContext(scopeType);
     }
 
-    public <T> T getInstanceToInject(InjectionPoint injectionPoint, CreationalContext<T>
context)
+    public <T> T getInstanceToInject(InjectionPoint injectionPoint, CreationalContext<?>
context)
     {
-        return manager.getInstanceToInject(injectionPoint, context);
+        return manager.<T>getInstanceToInject(injectionPoint, context); //X ugly <T>
due to javac bug 6302954
     }
     
     @SuppressWarnings("unchecked")



Mime
View raw message