[webbeans-commits] Webbeans SVN: r468 - in ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans: event and 1 other directory.

webbeans-commits at lists.jboss.org webbeans-commits at lists.jboss.org
Mon Dec 8 05:01:58 EST 2008


Author: nickarls
Date: 2008-12-08 05:01:58 -0500 (Mon, 08 Dec 2008)
New Revision: 468

Modified:
   ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/CurrentManager.java
   ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/FacadeImpl.java
   ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/InstanceImpl.java
   ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/event/EventImpl.java
Log:
docs + merging of similar code in FacadeImpl

Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/CurrentManager.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/CurrentManager.java	2008-12-08 08:44:08 UTC (rev 467)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/CurrentManager.java	2008-12-08 10:01:58 UTC (rev 468)
@@ -1,3 +1,20 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * Licensed 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.jboss.webbeans;
 
 import org.jboss.webbeans.contexts.ApplicationContext;
@@ -4,16 +21,31 @@
 import org.jboss.webbeans.contexts.RequestContext;
 import org.jboss.webbeans.contexts.SessionContext;
 
+/**
+ * Access point for getting/setting current Managager 
+ * 
+ * @author Gavin King
+ */
 public class CurrentManager 
 {
-
+   // The root manager instance
    protected static ManagerImpl rootManager;
 
+   /**
+    * Gets the root manager
+    * 
+    * @return The root manager
+    */
    public static ManagerImpl rootManager()
    {
       return rootManager;
    }
    
+   /**
+    * Sets the root manager
+    * 
+    * @param rootManager The root manager
+    */
    public static void setRootManager(ManagerImpl rootManager) 
    {
       CurrentManager.rootManager = rootManager;

Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/FacadeImpl.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/FacadeImpl.java	2008-12-08 08:44:08 UTC (rev 467)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/FacadeImpl.java	2008-12-08 10:01:58 UTC (rev 468)
@@ -1,3 +1,20 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * Licensed 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.jboss.webbeans;
 
 import java.lang.annotation.Annotation;
@@ -5,75 +22,87 @@
 import java.util.Set;
 
 import javax.webbeans.DuplicateBindingTypeException;
-import javax.webbeans.Observable;
 
 import org.jboss.webbeans.util.Reflections;
 
-public class FacadeImpl<T> {
-
+/**
+ * Common implementation for binding-type-based helpers
+ * 
+ * @author Gavin King
+ * 
+ * @param <T>
+ */
+public abstract class FacadeImpl<T>
+{
+   // The binding types the helper operates on
    protected final Set<? extends Annotation> bindingTypes;
+   // The Web Beans manager
    protected final ManagerImpl manager;
+   // The type of the operation
    protected final Class<T> type;
 
    /**
-    * Validates the binding types
+    * Constructor
     * 
-    * Removes @Observable from the list
-    * 
-    * @param annotations The annotations to validate
-    * @return A set of binding type annotations (minus @Observable, if it was
-    *         present)
+    * @param manager The Web Beans manager
+    * @param eventType The event type
+    * @param bindingTypes The binding types
     */
-   protected static Set<Annotation> getBindingTypes(Annotation... annotations) {
-      Set<Annotation> result = new HashSet<Annotation>();
-      for (Annotation annotation : annotations)
-      {
-         if (!Reflections.isBindingType(annotation))
-         {
-            throw new IllegalArgumentException(annotation + " is not a binding type");
-         }
-         if (!annotation.annotationType().equals(Observable.class))
-         {
-            result.add(annotation);
-         }
-      }
-      return result;
-   }
-
-   protected FacadeImpl(ManagerImpl manager, Class<T> eventType, Annotation... bindingTypes) {
+   protected FacadeImpl(ManagerImpl manager, Class<T> eventType, Annotation... bindingTypes)
+   {
       this.manager = manager;
       this.type = eventType;
-      this.bindingTypes = getBindingTypes(bindingTypes);
-    }
+      this.bindingTypes = mergeBindingTypes(new HashSet<Annotation>(), bindingTypes);
+   }
 
    /**
-    * Validates the binding types and checks for duplicates among the annotations.
+    * Merges and validates the current and new bindings
     * 
-    * @param annotations The annotations to validate
-    * @return A set of unique binding type annotations
+    * Checkes with an abstract method for annotations to exclude
+    * 
+    * @param currentBindings Existing bindings
+    * @param newBindings New bindings
+    * @return The union of the bindings
     */
-   protected Set<Annotation> checkBindingTypes(Annotation... annotations) {
+   protected Set<Annotation> mergeBindingTypes(Set<? extends Annotation> currentBindings, Annotation... newBindings)
+   {
       Set<Annotation> result = new HashSet<Annotation>();
-      for (Annotation annotation : annotations)
+      result.addAll(currentBindings);
+      for (Annotation newAnnotation : newBindings)
       {
-         if (!Reflections.isBindingType(annotation))
+         if (!Reflections.isBindingType(newAnnotation))
          {
-            throw new IllegalArgumentException(annotation + " is not a binding type for " + this);
+            throw new IllegalArgumentException(newAnnotation + " is not a binding type for " + this);
          }
-         if (result.contains(annotation) || this.bindingTypes.contains(annotation))
+         if (result.contains(newAnnotation))
          {
-            throw new DuplicateBindingTypeException(annotation + " is already present in the bindings list for " + this);
+            throw new DuplicateBindingTypeException(newAnnotation + " is already present in the bindings list for " + this);
          }
-         result.add(annotation);
+         if (!getFilteredAnnotations().contains(newAnnotation.annotationType()))
+         {
+            result.add(newAnnotation);
+         }
       }
       return result;
    }
 
-   protected Annotation[] mergeBindings(Annotation... bindingTypes) {
-      Set<Annotation> bindingParameters = checkBindingTypes(bindingTypes);
-      bindingParameters.addAll(this.bindingTypes);
-      Annotation[] bindings = bindingParameters.toArray(new Annotation[0]);
-      return bindings;
+   /**
+    * Gets a set of annotation classes to ignore
+    * 
+    * @return A set of annotation classes to ignore
+    */
+   protected abstract Set<Class<? extends Annotation>> getFilteredAnnotations();
+
+   /**
+    * Merges the binding this helper operates upon with the parameters
+    * 
+    * @param bindingTypes The bindings to merge
+    * 
+    * @return The union of the binding types
+    */
+   protected Annotation[] mergeBindings(Annotation... newBindingTypes)
+   {
+      return mergeBindingTypes(bindingTypes, newBindingTypes).toArray(new Annotation[0]);
    }
 
 }
\ No newline at end of file

Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/InstanceImpl.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/InstanceImpl.java	2008-12-08 08:44:08 UTC (rev 467)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/InstanceImpl.java	2008-12-08 10:01:58 UTC (rev 468)
@@ -18,6 +18,8 @@
 package org.jboss.webbeans;
 
 import java.lang.annotation.Annotation;
+import java.util.Collections;
+import java.util.Set;
 
 import javax.webbeans.Instance;
 
@@ -57,4 +59,10 @@
       return buffer.toString();
    }
 
+   @Override
+   protected Set<Class<? extends Annotation>> getFilteredAnnotations()
+   {
+      return Collections.emptySet();
+   }
+
 }

Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/event/EventImpl.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/event/EventImpl.java	2008-12-08 08:44:08 UTC (rev 467)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/event/EventImpl.java	2008-12-08 10:01:58 UTC (rev 468)
@@ -18,8 +18,12 @@
 package org.jboss.webbeans.event;
 
 import java.lang.annotation.Annotation;
+import java.util.Arrays;
+import java.util.HashSet;
+import java.util.Set;
 
 import javax.webbeans.Event;
+import javax.webbeans.Observable;
 import javax.webbeans.Observer;
 
 import org.jboss.webbeans.FacadeImpl;
@@ -36,6 +40,9 @@
  */
 public class EventImpl<T> extends FacadeImpl<T> implements Event<T>
 {
+   @SuppressWarnings("unchecked")
+   private static final Set<Class<? extends Annotation>> FILTERED_ANNOTATIONS = new HashSet<Class<? extends Annotation>>(Arrays.asList(Observable.class));
+   
    /**
     * Constructor
     * 
@@ -78,4 +85,10 @@
       return buffer.toString();
    }
 
+   @Override
+   protected Set<Class<? extends Annotation>> getFilteredAnnotations()
+   {
+      return FILTERED_ANNOTATIONS;
+   }
+
 }




More information about the weld-commits mailing list