You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tuscany.apache.org by mc...@apache.org on 2008/04/10 21:50:46 UTC

svn commit: r646939 - /incubator/tuscany/java/sca/modules/core-spi/src/main/java/org/apache/tuscany/sca/context/DefaultContextFactoryExtensionPoint.java

Author: mcombellack
Date: Thu Apr 10 12:50:44 2008
New Revision: 646939

URL: http://svn.apache.org/viewvc?rev=646939&view=rev
Log:
TUSCANY-2216 - Added checks for null parameters and throw IllegalArgumentException. Also updated the JavaDoc to reflect this change

Modified:
    incubator/tuscany/java/sca/modules/core-spi/src/main/java/org/apache/tuscany/sca/context/DefaultContextFactoryExtensionPoint.java

Modified: incubator/tuscany/java/sca/modules/core-spi/src/main/java/org/apache/tuscany/sca/context/DefaultContextFactoryExtensionPoint.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/core-spi/src/main/java/org/apache/tuscany/sca/context/DefaultContextFactoryExtensionPoint.java?rev=646939&r1=646938&r2=646939&view=diff
==============================================================================
--- incubator/tuscany/java/sca/modules/core-spi/src/main/java/org/apache/tuscany/sca/context/DefaultContextFactoryExtensionPoint.java (original)
+++ incubator/tuscany/java/sca/modules/core-spi/src/main/java/org/apache/tuscany/sca/context/DefaultContextFactoryExtensionPoint.java Thu Apr 10 12:50:44 2008
@@ -27,16 +27,24 @@
  * @version $Rev$ $Date$
  */
 public class DefaultContextFactoryExtensionPoint implements ContextFactoryExtensionPoint {
-    
+
+    /**
+     * The Map of Factories that have been registered.
+     */
     private HashMap<Class<?>, Object> factories = new HashMap<Class<?>, Object>();
 
     /**
      * Add a model factory extension.
-     * 
-     * @param factory The factory to add
+     *
+     * @param factory The factory to add.
+     * @throws IllegalArgumentException if factory is null
      */
-    public void addFactory(Object factory) {
-        Class[] interfaces = factory.getClass().getInterfaces();
+    public void addFactory(Object factory) throws IllegalArgumentException {
+        if (factory == null) {
+            throw new IllegalArgumentException("Cannot add null as a factory");
+        }
+
+        Class<?>[] interfaces = factory.getClass().getInterfaces();
         for (int i = 0; i<interfaces.length; i++) {
             factories.put(interfaces[i], factory);
         }
@@ -44,24 +52,33 @@
 
     /**
      * Remove a model factory extension.
-     *  
+     *
      * @param factory The factory to remove
+     * @throws IllegalArgumentException if factory is null
      */
-    public void removeFactory(Object factory) {
-        Class[] interfaces = factory.getClass().getInterfaces();
+    public void removeFactory(Object factory) throws IllegalArgumentException {
+        if (factory == null) {
+            throw new IllegalArgumentException("Cannot remove null as a factory");
+        }
+
+        Class<?>[] interfaces = factory.getClass().getInterfaces();
         for (int i = 0; i<interfaces.length; i++) {
             factories.remove(interfaces[i]);
         }
     }
-    
+
     /**
      * Get a factory implementing the given interface.
+     *
      * @param factoryInterface The lookup key (factory interface)
      * @return The factory
-     */    
-    public <T> T getFactory(Class<T> factoryInterface) {
+     */
+    public <T> T getFactory(Class<T> factoryInterface) throws IllegalArgumentException {
+        if (factoryInterface == null) {
+            throw new IllegalArgumentException("Cannot get null as a factory");
+        }
+
         Object factory = factories.get(factoryInterface);
         return factoryInterface.cast(factory);
     }
-
 }



---------------------------------------------------------------------
To unsubscribe, e-mail: tuscany-commits-unsubscribe@ws.apache.org
For additional commands, e-mail: tuscany-commits-help@ws.apache.org