You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commons-dev@ws.apache.org by ve...@apache.org on 2010/05/17 23:42:57 UTC

svn commit: r945402 - in /webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom: injection/ om/OMAbstractFactory.java osgi/ osgi/FactoryInjectionComponent.java

Author: veithen
Date: Mon May 17 21:42:57 2010
New Revision: 945402

URL: http://svn.apache.org/viewvc?rev=945402&view=rev
Log:
WSCOMMONS-432: Finalized the OSGi support with some minor changes to David's initial design:

* Reversed the control flow between OMAbstractFactory and FactoryInjectionComponent, i.e. let FactoryInjectionComponent invoke OMAbstractFactory. Reason: adding a setMetaFactory method to OMAbstractFactory may also be useful in other scenarios where configuring the meta factory using a system property is not an option (e.g. bundling Axiom in a WAR and let Spring initialize the meta factory).
* Renamed org.apache.axiom.injection to org.apache.axiom.osgi. We don't need to hide the fact that we support OSGi. Also, it is unlikely that FactoryInjectionComponent could be used for something else than OSGi.

Also added some more Javadoc to these classes.

Added:
    webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/osgi/
      - copied from r944797, webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/injection/
Removed:
    webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/injection/
Modified:
    webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/OMAbstractFactory.java
    webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/osgi/FactoryInjectionComponent.java

Modified: webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/OMAbstractFactory.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/OMAbstractFactory.java?rev=945402&r1=945401&r2=945402&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/OMAbstractFactory.java (original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/OMAbstractFactory.java Mon May 17 21:42:57 2010
@@ -19,16 +19,14 @@
 
 package org.apache.axiom.om;
 
-import org.apache.axiom.injection.FactoryInjectionComponent;
 import org.apache.axiom.soap.SOAPFactory;
 
 /**
  * Provides default instances for object model and meta factories.
  * <p>
  * The {@link #getMetaFactory()} method returns the default {@link OMMetaFactory} instance.
- * The implementation class is determined by the <code>org.apache.axiom.om.OMMetaFactory</code>
- * system property. If this property is not set, the meta factory for the LLOM implementation
- * is used.
+ * See the Javadoc of the {@link #getMetaFactory()} method for details about how this
+ * instance is determined.
  * <p>
  * The {@link #getOMFactory()}, {@link #getSOAP11Factory()} and {@link #getSOAP12Factory()}
  * methods return default instances for plain XML, SOAP 1.1 and SOAP 1.2 object model factories.
@@ -46,28 +44,75 @@ public class OMAbstractFactory {
     private static final String DEFAULT_META_FACTORY_CLASS_NAME =
             "org.apache.axiom.om.impl.llom.factory.OMLinkedListMetaFactory";
 
+    /**
+     * The default {@link OMMetaFactory} instance determined by the system
+     * property {@link #META_FACTORY_NAME_PROPERTY}, or if no such system
+     * property is set, by the value of the
+     * {@link #DEFAULT_META_FACTORY_CLASS_NAME} constant.
+     */
     private static OMMetaFactory defaultMetaFactory;
+    
+    /**
+     * The {@link OMMetaFactory} set through
+     * {@link #setMetaFactory(OMMetaFactory)}. If this is <code>null</code>,
+     * then {@link #defaultMetaFactory} will be returned by
+     * {@link #getMetaFactory()}.
+     */
+    private static OMMetaFactory metaFactory;
 
     private OMAbstractFactory() {}
 
     /**
-     * Get the default meta factory instance. The implementation class is determined by the
-     * <code>org.apache.axiom.om.OMMetaFactory</code> system property. If this property is not
-     * set, the meta factory for the LLOM implementation is returned.
+     * Explicitly set a meta factory instance. The new instance will be returned
+     * by all subsequent calls to {@link #getMetaFactory()}. Note that this is
+     * an application wide setting. More precisely, the configured meta factory
+     * will be used by all classes loaded from the class loader where Axiom is
+     * deployed and all its child class loaders. Therefore this method should be
+     * used with care and only be invoked during the initialization of the
+     * application.
      * <p>
-     * This method uses {@link System#getProperty(String)} to determine the value of
-     * the <code>org.apache.axiom.om.OMMetaFactory</code> system property. A
-     * {@link SecurityException} thrown by this method is simply ignored
-     * and the default factory implementation is used.
-     *
+     * When Axiom is deployed as a bundle in an OSGi environment, this method
+     * will be used to inject the meta factory instance from the implementation
+     * bundle.
+     * 
+     * @param newMetaFactory
+     *            the new meta factory instance, or <code>null</code> to revert
+     *            to the default meta factory instance determined by the
+     *            <code>org.apache.axiom.om.OMMetaFactory</code> system property
+     */
+    public static void setMetaFactory(OMMetaFactory newMetaFactory) {
+        metaFactory = newMetaFactory;
+    }
+    
+    /**
+     * Get the default meta factory instance. The default instance is determined
+     * using the following algorithm:
+     * <ol>
+     * <li>If an instance has been set using
+     * {@link #setMetaFactory(OMMetaFactory)}, then that instance is returned.
+     * Note that this will be the case in an OSGi runtime, where
+     * {@link #setMetaFactory(OMMetaFactory)} is invoked by a helper component
+     * that is part of Axiom.
+     * <li>If no instance has been set using
+     * {@link #setMetaFactory(OMMetaFactory)}, then the implementation class is
+     * determined by the <code>org.apache.axiom.om.OMMetaFactory</code> system
+     * property.
+     * <li>If the <code>org.apache.axiom.om.OMMetaFactory</code> system property
+     * is not set, the meta factory for the LLOM implementation is returned.
+     * </ol>
+     * This method uses {@link System#getProperty(String)} to determine the
+     * value of the <code>org.apache.axiom.om.OMMetaFactory</code> system
+     * property. A {@link SecurityException} thrown by this method is simply
+     * ignored and the default factory implementation is used.
+     * 
      * @return the default OM factory instance
-     * @throws OMException if the factory's implementation class can't be found
-     *                     or if the class can't be instantiated
+     * @throws OMException
+     *             if the factory's implementation class can't be found or if
+     *             the class can't be instantiated
      */
     public static OMMetaFactory getMetaFactory() {
-        OMMetaFactory of = FactoryInjectionComponent.getMetaFactory();
-        if(of!=null){
-            return of;
+        if (metaFactory != null) {
+            return metaFactory;
         }
         
         if (defaultMetaFactory != null) {

Modified: webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/osgi/FactoryInjectionComponent.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/osgi/FactoryInjectionComponent.java?rev=945402&r1=944797&r2=945402&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/osgi/FactoryInjectionComponent.java (original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/osgi/FactoryInjectionComponent.java Mon May 17 21:42:57 2010
@@ -16,16 +16,23 @@
  * specific language governing permissions and limitations
  * under the License.
  */
-package org.apache.axiom.injection;
+package org.apache.axiom.osgi;
 
 import java.util.ArrayList;
 import java.util.List;
 
+import org.apache.axiom.om.OMAbstractFactory;
 import org.apache.axiom.om.OMMetaFactory;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 
 /**
+ * Internal component required for OSGi support. This component is
+ * responsible for injecting the {@link OMMetaFactory} instance loaded
+ * from the implementation bundle into {@link OMAbstractFactory} (using
+ * {@link OMAbstractFactory#setMetaFactory(OMMetaFactory)}). This class
+ * is for internal use only and MUST NOT be used for other purposes.
+ * 
  * @scr.component name="factoryinjection.component" immediate="true"
  * @scr.reference name="metafactory" interface="org.apache.axiom.om.OMMetaFactory" cardinality="0..n" policy="dynamic" bind="setMetaFactory" unbind="unsetMetaFactory"
  */
@@ -41,7 +48,6 @@ public class FactoryInjectionComponent {
 	}
 
 	private static List metaFactories = null;
-	private static OMMetaFactory currentMetaFactory = null;
 	
 	protected void setMetaFactory(OMMetaFactory metafactory) {
 		synchronized (FactoryInjectionComponent.class) {
@@ -54,7 +60,7 @@ public class FactoryInjectionComponent {
 			} else {
 				metaFactories.add(metafactory);
 			}
-			currentMetaFactory = (OMMetaFactory) metaFactories.get(0);
+			OMAbstractFactory.setMetaFactory((OMMetaFactory) metaFactories.get(0));
 		}
 	}
 
@@ -66,12 +72,8 @@ public class FactoryInjectionComponent {
 			if (metaFactories.size() == 0) {
 			    metaFactories = null;
 			} else {
-				currentMetaFactory = (OMMetaFactory) metaFactories.get(0);
+			    OMAbstractFactory.setMetaFactory((OMMetaFactory) metaFactories.get(0));
 			}
 		}
 	}
-
-	public static OMMetaFactory getMetaFactory() {
-		return currentMetaFactory;
-	}
 }