felix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From clem...@apache.org
Subject svn commit: r1242270 - /felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/ComponentFactory.java
Date Thu, 09 Feb 2012 10:45:51 GMT
Author: clement
Date: Thu Feb  9 10:45:51 2012
New Revision: 1242270

URL: http://svn.apache.org/viewvc?rev=1242270&view=rev
Log:
Cosmetic changes.

Modified:
    felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/ComponentFactory.java

Modified: felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/ComponentFactory.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/ComponentFactory.java?rev=1242270&r1=1242269&r2=1242270&view=diff
==============================================================================
--- felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/ComponentFactory.java (original)
+++ felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/ComponentFactory.java Thu
Feb  9 10:45:51 2012
@@ -47,19 +47,20 @@ import org.osgi.framework.ServiceReferen
  * consists to create and manage component instances build with the current
  * component factory. This class could export Factory and ManagedServiceFactory
  * services.
+ *
+ * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
  * @see IPojoFactory
  * @see TrackerCustomizer
- * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
  */
 public class ComponentFactory extends IPojoFactory implements TrackerCustomizer {
 
-	/**
-	 * System property set to automatically attach primitive handlers to primitive
-	 * component types.
-	 * The value is a String parsed as a list (comma separated). Each element is
-	 * the fully qualified name of the handler <code>namespace:name</code>.
-	 */
-	public static final String HANDLER_AUTO_PRIMITIVE = "org.apache.felix.ipojo.handler.auto.primitive";
+    /**
+     * System property set to automatically attach primitive handlers to primitive
+     * component types.
+     * The value is a String parsed as a list (comma separated). Each element is
+     * the fully qualified name of the handler <code>namespace:name</code>.
+     */
+    public static final String HANDLER_AUTO_PRIMITIVE = "org.apache.felix.ipojo.handler.auto.primitive";
 
 
     /**
@@ -97,8 +98,9 @@ public class ComponentFactory extends IP
     /**
      * Creates a instance manager factory.
      * The class is given in parameter. The component type is not a composite.
+     *
      * @param context the bundle context
-     * @param clazz the component class
+     * @param clazz   the component class
      * @param element the metadata of the component
      * @throws ConfigurationException if the element describing the factory is malformed.
      */
@@ -109,6 +111,7 @@ public class ComponentFactory extends IP
 
     /**
      * Creates a instance manager factory.
+     *
      * @param context the bundle context
      * @param element the metadata of the component to create
      * @throws ConfigurationException if element describing the factory is malformed.
@@ -120,6 +123,7 @@ public class ComponentFactory extends IP
 
     /**
      * Gets the component type description of the current factory.
+     *
      * @return the description of the component type attached to this factory.
      * @see org.apache.felix.ipojo.IPojoFactory#getComponentTypeDescription()
      */
@@ -131,18 +135,22 @@ public class ComponentFactory extends IP
      * Allows a factory to check if the given element is well-formed.
      * A component factory metadata is correct if they contain the 'classname' attribute.
      * As this method is called from the (single-threaded) constructor, no synchronization
is needed.
+     *
      * @param element the metadata describing the component
      * @throws ConfigurationException if the element describing the factory is malformed.
      */
     public void check(Element element) throws ConfigurationException {
         m_classname = element.getAttribute("classname");
-        if (m_classname == null) { throw new ConfigurationException("A component needs a
class name : " + element); }
+        if (m_classname == null) {
+            throw new ConfigurationException("A component needs a class name : " + element);
+        }
         m_manipulation = new PojoMetadata(m_componentMetadata);
     }
 
     /**
      * Gets the class name.
      * No synchronization needed, the classname is immutable.
+     *
      * @return the class name.
      * @see org.apache.felix.ipojo.IPojoFactory#getClassName()
      */
@@ -153,11 +161,13 @@ public class ComponentFactory extends IP
     /**
      * Creates a primitive instance.
      * This method is called when holding the lock.
-     * @param config the instance configuration
-     * @param context the service context (null if the instance has to be created in the
global space).
+     *
+     * @param config   the instance configuration
+     * @param context  the service context (null if the instance has to be created in the
global space).
      * @param handlers the handlers to attach to the instance
      * @return the created instance
-     * @throws org.apache.felix.ipojo.ConfigurationException if the configuration process
failed.
+     * @throws org.apache.felix.ipojo.ConfigurationException
+     *          if the configuration process failed.
      * @see org.apache.felix.ipojo.IPojoFactory#createInstance(java.util.Dictionary, org.apache.felix.ipojo.IPojoContext,
org.apache.felix.ipojo.HandlerManager[])
      */
     public ComponentInstance createInstance(Dictionary config, IPojoContext context, HandlerManager[]
handlers) throws org.apache.felix.ipojo.ConfigurationException {
@@ -192,8 +202,9 @@ public class ComponentFactory extends IP
      * is created twice.
      * This method delegate the <code>define</code> method invocation to the
      * factory classloader.
-     * @param name the qualified name of the class
-     * @param clazz the byte array of the class
+     *
+     * @param name   the qualified name of the class
+     * @param clazz  the byte array of the class
      * @param domain the protection domain of the class
      * @return the defined class object
      */
@@ -208,6 +219,7 @@ public class ComponentFactory extends IP
      * Returns the URL of a resource.
      * This methods delegates the invocation to the
      * {@link Bundle#getResource(String)} method.
+     *
      * @param resName the resource name
      * @return the URL of the resource
      */
@@ -222,6 +234,7 @@ public class ComponentFactory extends IP
      * to load is the implementation class or not.
      * If it is, the factory classloader is used, else
      * the {@link Bundle#loadClass(String)} is called.
+     *
      * @param className the name of the class to load
      * @return the resulting Class object
      * @throws ClassNotFoundException if the class is not found
@@ -270,6 +283,7 @@ public class ComponentFactory extends IP
      * the 'name' and 'classname' attributes.
      * This method does not manipulate any non-immutable fields,
      * so does not need to be synchronized.
+     *
      * @return the factory name.
      */
     public String getFactoryName() {
@@ -287,6 +301,7 @@ public class ComponentFactory extends IP
      * so does not need to be synchronized.
      * This method checks the {@link ComponentFactory#HANDLER_AUTO_PRIMITIVE}
      * system property to add the listed handlers to the required handler set.
+     *
      * @return the required handler list.
      */
     public List getRequiredHandlerList() {
@@ -333,25 +348,25 @@ public class ComponentFactory extends IP
 
         // Manage auto attached handler.
         String v = System.getProperty(HANDLER_AUTO_PRIMITIVE);
-        if (v != null  && v.length() != 0) {
-        	String[] hs = ParseUtils.split(v, ",");
-        	for (int i = 0; i < hs.length; i++) {
-        		String h = hs[i].trim();
-        		String[] segments = ParseUtils.split(h, ":");
-        		RequiredHandler rq = null;
-        		if (segments.length == 2) { // External handler
-        			rq = new RequiredHandler(segments[1], segments[0]);
-        		} else if (segments.length == 1) { // Core handler
-        			rq = new RequiredHandler(segments[1], null);
-        		} // Others case are ignored.
-
-        		if (rq != null) {
-        			// Check it's not already contained
-        			if (! list.contains(rq)) {
-        				list.add(rq);
-        			}
-        		}
-        	}
+        if (v != null && v.length() != 0) {
+            String[] hs = ParseUtils.split(v, ",");
+            for (int i = 0; i < hs.length; i++) {
+                String h = hs[i].trim();
+                String[] segments = ParseUtils.split(h, ":");
+                RequiredHandler rq = null;
+                if (segments.length == 2) { // External handler
+                    rq = new RequiredHandler(segments[1], segments[0]);
+                } else if (segments.length == 1) { // Core handler
+                    rq = new RequiredHandler(segments[1], null);
+                } // Others case are ignored.
+
+                if (rq != null) {
+                    // Check it's not already contained
+                    if (!list.contains(rq)) {
+                        list.add(rq);
+                    }
+                }
+            }
         }
 
 
@@ -363,6 +378,7 @@ public class ComponentFactory extends IP
      * Test if the factory can be used or not.
      * This method need to be synchronized as it accesses to the content
      * of required handlers.
+     *
      * @param reference the new service reference.
      * @return <code>true</code> if the given factory reference matches with
a required handler.
      * @see org.apache.felix.ipojo.util.TrackerCustomizer#addingService(org.osgi.framework.ServiceReference)
@@ -388,6 +404,7 @@ public class ComponentFactory extends IP
      * This method is called when a matching service has been added to the tracker,
      * we can no compute the factory state. This method is synchronized to avoid
      * concurrent calls to method modifying the factory state.
+     *
      * @param reference the added service reference.
      * @see org.apache.felix.ipojo.util.TrackerCustomizer#addedService(org.osgi.framework.ServiceReference)
      */
@@ -401,8 +418,9 @@ public class ComponentFactory extends IP
      * This method is called when a used handler factory disappears.
      * This method is synchronized to avoid concurrent calls to method modifying
      * the factory state.
+     *
      * @param reference the leaving service reference.
-     * @param service  the handler factory object.
+     * @param service   the handler factory object.
      * @see org.apache.felix.ipojo.util.TrackerCustomizer#removedService(org.osgi.framework.ServiceReference,
java.lang.Object)
      */
     public synchronized void removedService(ServiceReference reference, Object service) {
@@ -421,8 +439,9 @@ public class ComponentFactory extends IP
      * This method is called when a used handler factory is modified.
      * However, handler factory modification is not possible, so this method
      * is never called.
+     *
      * @param reference the service reference
-     * @param service the Factory object (if already get)
+     * @param service   the Factory object (if already get)
      * @see org.apache.felix.ipojo.util.TrackerCustomizer#modifiedService(org.osgi.framework.ServiceReference,
java.lang.Object)
      */
     public void modifiedService(ServiceReference reference, Object service) {
@@ -431,6 +450,7 @@ public class ComponentFactory extends IP
 
     /**
      * Returns manipulation metadata of this component type.
+     *
      * @return manipulation metadata of this component type.
      */
     public PojoMetadata getPojoMetadata() {
@@ -439,6 +459,7 @@ public class ComponentFactory extends IP
 
     /**
      * Gets the version of the component type.
+     *
      * @return the version of <code>null</code> if not set.
      * @see org.apache.felix.ipojo.Factory#getVersion()
      */
@@ -454,8 +475,9 @@ public class ComponentFactory extends IP
      * this class defines the classloader attached to a factory.
      * This class loader is used to load the implementation (e.g. manipulated)
      * class.
-     * @see ClassLoader
+     *
      * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
+     * @see ClassLoader
      */
     private class FactoryClassloader extends ClassLoader {
 
@@ -466,13 +488,16 @@ public class ComponentFactory extends IP
 
         /**
          * The defineClass method.
-         * @param name name of the class
-         * @param clazz the byte array of the class
+         *
+         * @param name   name of the class
+         * @param clazz  the byte array of the class
          * @param domain the protection domain
          * @return the defined class.
          */
         public Class defineClass(String name, byte[] clazz, ProtectionDomain domain) {
-            if (m_definedClasses.containsKey(name)) { return (Class) m_definedClasses.get(name);
}
+            if (m_definedClasses.containsKey(name)) {
+                return (Class) m_definedClasses.get(name);
+            }
             Class clas = super.defineClass(name, clazz, 0, clazz.length, domain);
             m_definedClasses.put(name, clas);
             return clas;
@@ -480,6 +505,7 @@ public class ComponentFactory extends IP
 
         /**
          * Returns the URL of the required resource.
+         *
          * @param arg the name of the resource to find.
          * @return the URL of the resource.
          * @see java.lang.ClassLoader#getResource(java.lang.String)
@@ -490,11 +516,12 @@ public class ComponentFactory extends IP
 
         /**
          * Loads the given class.
-         * @see java.lang.ClassLoader#loadClass(java.lang.String, boolean)
-         * @param name the name of the class
+         *
+         * @param name    the name of the class
          * @param resolve should be the class resolve now ?
          * @return the loaded class object
          * @throws ClassNotFoundException if the class to load is not found
+         * @see java.lang.ClassLoader#loadClass(java.lang.String, boolean)
          * @see java.lang.ClassLoader#loadClass(String, boolean)
          */
         protected synchronized Class loadClass(String name, boolean resolve) throws ClassNotFoundException
{
@@ -506,44 +533,44 @@ public class ComponentFactory extends IP
      * This class defines the description of primitive (non-composite) component
      * types. An instance of this class will be returned when invoking the
      * {@link ComponentFactory#getComponentDescription()} method.
+     *
      * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
      */
     private final class PrimitiveTypeDescription extends ComponentTypeDescription {
 
-    	/*
-    	 * Set to keep component's all super-class class-names.
-    	 */
-    	private Set m_superClasses = new HashSet();
-    	
-    	/*
-    	 * Set to keep component's all interface class-names.
-    	 */
-    	private Set m_interfaces = new HashSet();
-    	
+        /*
+           * Set to keep component's all super-class class-names.
+           */
+        private Set m_superClasses = new HashSet();
+
+        /*
+           * Set to keep component's all interface class-names.
+           */
+        private Set m_interfaces = new HashSet();
+
         /**
          * Creates a PrimitiveTypeDescription object.
+         *
          * @param factory the factory attached to this component type description.
          */
         public PrimitiveTypeDescription(IPojoFactory factory) {
             super(factory);
-            
-            try 
-            {
-            	// Read inherited classes and interfaces into given Sets.
-				new InheritanceInspector(getPojoMetadata(), getBundleContext().getBundle()).
-						computeInterfacesAndSuperClasses(m_interfaces, m_superClasses);
-			} 
-            catch (ClassNotFoundException e) 
-			{
-				m_interfaces.clear();
-				m_superClasses.clear();				
-			}
-            
+
+            try {
+                // Read inherited classes and interfaces into given Sets.
+                new InheritanceInspector(getPojoMetadata(), getBundleContext().getBundle()).
+                        computeInterfacesAndSuperClasses(m_interfaces, m_superClasses);
+            } catch (ClassNotFoundException e) {
+                m_interfaces.clear();
+                m_superClasses.clear();
+            }
+
         }
 
         /**
          * Computes the properties to publish.
          * The <code>component.class</code> property contains the implementation
class name.
+         *
          * @return the dictionary of properties to publish
          * @see org.apache.felix.ipojo.architecture.ComponentTypeDescription#getPropertiesToPublish()
          */
@@ -557,62 +584,65 @@ public class ComponentFactory extends IP
 
         /**
          * Adds the "implementation-class" attribute to the type description.
+         *
          * @return the component type description.
          * @see org.apache.felix.ipojo.architecture.ComponentTypeDescription#getDescription()
          */
         public Element getDescription() {
             Element elem = super.getDescription();
             elem.addAttribute(new Attribute("Implementation-Class", m_classname));
-            
+
             /* Adding interfaces and super-classes of component into description */
             Element inheritance = new Element("Inherited", "");
-            
-            inheritance.addAttribute(new Attribute("Interfaces",m_interfaces.toString()));
-            inheritance.addAttribute(new Attribute("SuperClasses",m_superClasses.toString()));
+
+            inheritance.addAttribute(new Attribute("Interfaces", m_interfaces.toString()));
+            inheritance.addAttribute(new Attribute("SuperClasses", m_superClasses.toString()));
 
             elem.addElement(inheritance);
 
             return elem;
         }
-        
+
         /**
          * This class is used to collect interfaces and super-classes of given component
in specified Sets.
+         *
          * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
          */
-        private final class InheritanceInspector{
-        	/*
-        	 * PojoMetadata of target Component.
-        	 */
-        	private PojoMetadata m_pojoMetadata;        	
-        	
-        	/*
-        	 * Bundle exposing target component.
-        	 */
-        	private Bundle m_bundle;
-        	
-        	
-        	/**
-        	 * Creates a TypeCollector object
-        	 * @param pojoMetadata PojoMetadata describing Component.
-        	 * @param bundle Bundle which has been exposed the intended Component. 
-        	 */
-        	public InheritanceInspector(PojoMetadata pojoMetadata,Bundle bundle)
-        	{
-        		m_pojoMetadata = pojoMetadata;
-        		m_bundle = bundle;
-        	}
-        	
-        	/**
+        private final class InheritanceInspector {
+            /*
+                * PojoMetadata of target Component.
+                */
+            private PojoMetadata m_pojoMetadata;
+
+            /*
+                * Bundle exposing target component.
+                */
+            private Bundle m_bundle;
+
+
+            /**
+             * Creates a TypeCollector object
+             *
+             * @param pojoMetadata PojoMetadata describing Component.
+             * @param bundle       Bundle which has been exposed the intended Component.
+             */
+            public InheritanceInspector(PojoMetadata pojoMetadata, Bundle bundle) {
+                m_pojoMetadata = pojoMetadata;
+                m_bundle = bundle;
+            }
+
+            /**
              * Collect interfaces implemented by the POJO into given Sets.
+             *
              * @param interfaces : the set of implemented interfaces
-             * @param classes : the set of extended classes
+             * @param classes    : the set of extended classes
              * @throws ClassNotFoundException : occurs when an interface cannot be loaded.
              */
             public void computeInterfacesAndSuperClasses(Set interfaces, Set classes) throws
ClassNotFoundException {
-            	
-            	String[] immediateInterfaces = m_pojoMetadata.getInterfaces();
-            	String parentClass = m_pojoMetadata.getSuperClass();
-            	
+
+                String[] immediateInterfaces = m_pojoMetadata.getInterfaces();
+                String parentClass = m_pojoMetadata.getSuperClass();
+
                 // First iterate on found specification in manipulation metadata
                 for (int i = 0; i < immediateInterfaces.length; i++) {
                     interfaces.add(immediateInterfaces[i]);
@@ -628,15 +658,16 @@ public class ComponentFactory extends IP
                     classes.add(parentClass);
                     collectParentClassesFromClass(clazz, classes, m_bundle);
                 }
-                
+
                 // Removing Object Class from the inherited classes list.
                 classes.remove(Object.class.getName());
             }
 
             /**
              * Look for inherited interfaces.
-             * @param clazz : interface name to explore (class object)
-             * @param acc : set (accumulator)
+             *
+             * @param clazz  : interface name to explore (class object)
+             * @param acc    : set (accumulator)
              * @param bundle : bundle
              * @throws ClassNotFoundException : occurs when an interface cannot be loaded.
              */
@@ -651,8 +682,9 @@ public class ComponentFactory extends IP
             /**
              * Collect interfaces for the given class.
              * This method explores super class to.
-             * @param clazz : class object.
-             * @param acc : set of implemented interface (accumulator)
+             *
+             * @param clazz  : class object.
+             * @param acc    : set of implemented interface (accumulator)
              * @param bundle : bundle.
              * @throws ClassNotFoundException : occurs if an interface cannot be load.
              */
@@ -671,8 +703,9 @@ public class ComponentFactory extends IP
 
             /**
              * Collect parent classes for the given class.
-             * @param clazz : class object.
-             * @param acc : set of extended classes (accumulator)
+             *
+             * @param clazz  : class object.
+             * @param acc    : set of extended classes (accumulator)
              * @param bundle : bundle.
              * @throws ClassNotFoundException : occurs if an interface cannot be load.
              */



Mime
View raw message