felix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rickh...@apache.org
Subject svn commit: r516458 [2/2] - in /incubator/felix/trunk/ipojo/src/main/java/org/apache/felix/ipojo: ./ architecture/ handlers/configuration/ handlers/dependency/ handlers/dependency/nullable/ handlers/lifecycle/callback/ handlers/providedservice/ parser/...
Date Fri, 09 Mar 2007 16:50:33 GMT
Modified: incubator/felix/trunk/ipojo/src/main/java/org/apache/felix/ipojo/handlers/lifecycle/callback/LifecycleCallback.java
URL: http://svn.apache.org/viewvc/incubator/felix/trunk/ipojo/src/main/java/org/apache/felix/ipojo/handlers/lifecycle/callback/LifecycleCallback.java?view=diff&rev=516458&r1=516457&r2=516458
==============================================================================
--- incubator/felix/trunk/ipojo/src/main/java/org/apache/felix/ipojo/handlers/lifecycle/callback/LifecycleCallback.java
(original)
+++ incubator/felix/trunk/ipojo/src/main/java/org/apache/felix/ipojo/handlers/lifecycle/callback/LifecycleCallback.java
Fri Mar  9 08:50:30 2007
@@ -52,7 +52,10 @@
     /**
      * LifecycleCallback constructor.
      * @param hh : the callback handler calling the callback
-     * @param hm : the callback metadata
+     * @param initialState : initial state of the callback
+     * @param finalState : finali state of the callback
+     * @param method : method to invoke
+     * @param isStatic : is the method static ?
      */
     public LifecycleCallback(LifecycleCallbackHandler hh, String initialState, String finalState,
String method, boolean isStatic) {
     	if (initialState.equals("VALID")) { m_initialState = InstanceManager.VALID; }

Modified: incubator/felix/trunk/ipojo/src/main/java/org/apache/felix/ipojo/handlers/lifecycle/callback/LifecycleCallbackHandler.java
URL: http://svn.apache.org/viewvc/incubator/felix/trunk/ipojo/src/main/java/org/apache/felix/ipojo/handlers/lifecycle/callback/LifecycleCallbackHandler.java?view=diff&rev=516458&r1=516457&r2=516458
==============================================================================
--- incubator/felix/trunk/ipojo/src/main/java/org/apache/felix/ipojo/handlers/lifecycle/callback/LifecycleCallbackHandler.java
(original)
+++ incubator/felix/trunk/ipojo/src/main/java/org/apache/felix/ipojo/handlers/lifecycle/callback/LifecycleCallbackHandler.java
Fri Mar  9 08:50:30 2007
@@ -49,7 +49,7 @@
     private InstanceManager m_manager;
 
 	/**
-	 * Does a POJO object be created at starting
+	 * Does a POJO object be created at starting.
 	 */
 	private boolean m_immediate = false;
 
@@ -67,8 +67,7 @@
             System.arraycopy(m_callbacks, 0, newHk, 0, m_callbacks.length);
             newHk[m_callbacks.length] = hk;
             m_callbacks = newHk;
-        }
-        else {
+        } else {
             m_callbacks = new LifecycleCallback[] {hk};
         }
 
@@ -121,7 +120,7 @@
      */
     public void stateChanged(int state) {
     	// Manage immediate component
-    	if(m_state == ComponentInstance.INVALID && state == ComponentInstance.VALID
&& m_manager.getPojoObjects().length == 0) {
+    	if (m_state == ComponentInstance.INVALID && state == ComponentInstance.VALID
&& m_manager.getPojoObjects().length == 0) {
     		m_manager.createPojoObject();
     	}
     	

Modified: incubator/felix/trunk/ipojo/src/main/java/org/apache/felix/ipojo/handlers/providedservice/Property.java
URL: http://svn.apache.org/viewvc/incubator/felix/trunk/ipojo/src/main/java/org/apache/felix/ipojo/handlers/providedservice/Property.java?view=diff&rev=516458&r1=516457&r2=516458
==============================================================================
--- incubator/felix/trunk/ipojo/src/main/java/org/apache/felix/ipojo/handlers/providedservice/Property.java
(original)
+++ incubator/felix/trunk/ipojo/src/main/java/org/apache/felix/ipojo/handlers/providedservice/Property.java
Fri Mar  9 08:50:30 2007
@@ -70,7 +70,11 @@
     /**
      * Property constructor.
      * @param ps : the provided service
-     * @param pm : metadata of the property
+     * @param name : name of the property
+     * @param field : name of the field (if a field is attached to the property)
+     * @param type : type of the property
+     * @param value : initial value of the property
+     * @param manipulation : manipulation metadata
      */
     public Property(ProvidedService ps, String name, String field, String type, String value,
Element manipulation) {
         m_providedService = ps;
@@ -85,15 +89,15 @@
         }
         
         // Check type if not already set
-        if(m_type == null) {
-        	if(field == null) { ps.getInstanceManager().getFactory().getLogger().log(Logger.ERROR,
"The property "+ m_name + " has neither type neither field."); return; }
-                for (int j = 0; j < manipulation.getElements("Field").length; j++) {
-                    if (field.equals(manipulation.getElements("Field")[j].getAttribute("name")))
{
-                        m_type = manipulation.getElements("Field")[j].getAttribute("type");
-                        break;
-                    }
+        if (m_type == null) {
+        	if (field == null) { ps.getInstanceManager().getFactory().getLogger().log(Logger.ERROR,
"The property " + m_name + " has neither type neither field."); return; }
+            for (int j = 0; j < manipulation.getElements("Field").length; j++) {
+                if (field.equals(manipulation.getElements("Field")[j].getAttribute("name")))
{
+                    m_type = manipulation.getElements("Field")[j].getAttribute("type");
+                    break;
                 }
-                if (m_type == null) { m_providedService.getInstanceManager().getFactory().getLogger().log(Logger.ERROR,
"[" + ps.getInstanceManager().getClassName() + "] A declared property was not found in the
class : " + m_field); }
+            }
+            if (m_type == null) { m_providedService.getInstanceManager().getFactory().getLogger().log(Logger.ERROR,
"[" + ps.getInstanceManager().getClassName() + "] A declared property was not found in the
class : " + m_field); }
         }
         
         if (m_initialValue != null) { setValue(m_initialValue); }
@@ -125,7 +129,6 @@
      */
     protected void set(String s) {
         setValue(s);
-        m_providedService.update();
     }
 
     /**
@@ -135,7 +138,6 @@
      */
     protected void set(Object o) {
         m_value = o;
-        m_providedService.update();
     }
 
     /**
@@ -238,12 +240,14 @@
             float[] fl = new float[values.length];
             for (int i = 0; i < values.length; i++) { fl[i] = new Float(values[i]).floatValue();
}
             m_value = fl;
-            return; }
+            return; 
+        }
         if (internalType.equals("double")) {
             double[] dl = new double[values.length];
             for (int i = 0; i < values.length; i++) { dl[i] = new Double(values[i]).doubleValue();
}
             m_value = dl;
-            return; }
+            return; 
+        }
 
         // Else it is a neither a primitive type neither a String -> create the object
by calling a constructor with a string in argument.
         try {

Modified: incubator/felix/trunk/ipojo/src/main/java/org/apache/felix/ipojo/handlers/providedservice/ProvidedService.java
URL: http://svn.apache.org/viewvc/incubator/felix/trunk/ipojo/src/main/java/org/apache/felix/ipojo/handlers/providedservice/ProvidedService.java?view=diff&rev=516458&r1=516457&r2=516458
==============================================================================
--- incubator/felix/trunk/ipojo/src/main/java/org/apache/felix/ipojo/handlers/providedservice/ProvidedService.java
(original)
+++ incubator/felix/trunk/ipojo/src/main/java/org/apache/felix/ipojo/handlers/providedservice/ProvidedService.java
Fri Mar  9 08:50:30 2007
@@ -88,7 +88,8 @@
     /**
      * Construct a provided service object.
      * @param handler : the provided service handler.
-     * @param psm : the provided service metadata.
+     * @param specification : specifications provided by this provided service
+     * @param factoryPolicy : service providing policy
      */
     public ProvidedService(ProvidedServiceHandler handler, String[] specification, int factoryPolicy)
{
         m_handler = handler;
@@ -107,7 +108,7 @@
      * @param props : the properties to attached to the service registration
      */
     protected void setProperties(Property[] props) { 
-    	for(int i = 0; i < props.length; i++) {
+    	for (int i = 0; i < props.length; i++) {
     		addProperty(props[i]);
     	}
     }
@@ -126,8 +127,9 @@
             System.arraycopy(m_properties, 0, newProp, 0, m_properties.length);
             newProp[m_properties.length] = p;
             m_properties = newProp;
+        } else { 
+        	m_properties = new Property[] {p}; 
         }
-        else { m_properties = new Property[] {p}; }
     }
 
     /**
@@ -141,12 +143,14 @@
         }
 
         if (idx >= 0) {
-            if ((m_properties.length - 1) == 0) { m_properties = new Property[0]; }
-            else {
+            if ((m_properties.length - 1) == 0) { 
+            	m_properties = new Property[0]; 
+            } else {
                 Property[] newPropertiesList = new Property[m_properties.length - 1];
                 System.arraycopy(m_properties, 0, newPropertiesList, 0, idx);
                 if (idx < newPropertiesList.length) {
-                    System.arraycopy(m_properties, idx + 1, newPropertiesList, idx, newPropertiesList.length
- idx); }
+                    System.arraycopy(m_properties, idx + 1, newPropertiesList, idx, newPropertiesList.length
- idx); 
+                }
                 m_properties = newPropertiesList;
             }
         }
@@ -156,8 +160,9 @@
      * @return the service reference of the provided service (null if the service is not
published).
      */
     public ServiceReference getServiceReference() {
-        if (m_serviceRegistration != null) { return m_serviceRegistration.getReference();
}
-        else { return null; }
+        if (m_serviceRegistration != null) { 
+        	return m_serviceRegistration.getReference(); 
+        } else { return null; }
     }
 
     /**
@@ -179,7 +184,7 @@
 
             default :
                 m_handler.getInstanceManager().getFactory().getLogger().log(Logger.ERROR,
"[" + m_handler.getInstanceManager().getClassName() + "] Unknown factory policy for " + m_serviceSpecification
+ " : " + m_factoryPolicy);
-            return null;
+                return null;
         }
 
     }
@@ -231,8 +236,11 @@
      * @return The state of the provided service.
      */
     public int getState() {
-    	if(m_serviceRegistration == null) { return UNREGISTERED; }
-    	else { return REGISTERED; }
+    	if (m_serviceRegistration == null) { 
+    		return UNREGISTERED; 
+    	} else { 
+    		return REGISTERED; 
+    	}
     }
 
     /**
@@ -273,14 +281,14 @@
         // Contruct the service properties list
         Properties serviceProperties = getServiceProperties();
         
-        if(serviceProperties == null) {
+        if (serviceProperties == null) {
         	m_handler.getInstanceManager().getFactory().getLogger().log(Logger.ERROR, "Cannot
get the properties of the provided service");
         }
 
         // Update the service registration
         if (m_serviceRegistration != null) {
-                m_serviceRegistration.setProperties(serviceProperties);
-            }
+            m_serviceRegistration.setProperties(serviceProperties);
+        }
     }
 
     /**
@@ -295,7 +303,6 @@
             Property prop = new Property(this, key, value);
             addProperty(prop);
         }
-        update();
     }
 
     /**
@@ -308,7 +315,6 @@
             String key = (String) keys.nextElement();
             removeProperty(key);
         }
-        update();
     }
 
 	/**

Modified: incubator/felix/trunk/ipojo/src/main/java/org/apache/felix/ipojo/handlers/providedservice/ProvidedServiceDescription.java
URL: http://svn.apache.org/viewvc/incubator/felix/trunk/ipojo/src/main/java/org/apache/felix/ipojo/handlers/providedservice/ProvidedServiceDescription.java?view=diff&rev=516458&r1=516457&r2=516458
==============================================================================
--- incubator/felix/trunk/ipojo/src/main/java/org/apache/felix/ipojo/handlers/providedservice/ProvidedServiceDescription.java
(original)
+++ incubator/felix/trunk/ipojo/src/main/java/org/apache/felix/ipojo/handlers/providedservice/ProvidedServiceDescription.java
Fri Mar  9 08:50:30 2007
@@ -30,12 +30,12 @@
 public class ProvidedServiceDescription {
 	
 	/**
-	 * State : the service is unregistered 
+	 * State : the service is unregistered.
 	 */
 	public static final int UNREGISTERED = 0;
 	
 	/**
-	 * State : the service is registered
+	 * State : the service is registered.
 	 */
 	public static final int REGISTERED = 1;
 
@@ -75,9 +75,8 @@
      * @param serviceSpecification : the provided contract
      * @param state : state (UNREGITRED | REGISTRED)
      * @param sr : Service Registration (to obtain the reference), or null if state is UNREGISTRED
-     * @param parent : the component description declaring this proided service
      */
-    public ProvidedServiceDescription(String[] serviceSpecification, int state, ServiceReference
sr/*, InstanceDescription parent*/) {
+    public ProvidedServiceDescription(String[] serviceSpecification, int state, ServiceReference
sr) {
         m_serviceSpecification = serviceSpecification;
         m_state = state;
         m_serviceReference = sr;

Modified: incubator/felix/trunk/ipojo/src/main/java/org/apache/felix/ipojo/handlers/providedservice/ProvidedServiceHandler.java
URL: http://svn.apache.org/viewvc/incubator/felix/trunk/ipojo/src/main/java/org/apache/felix/ipojo/handlers/providedservice/ProvidedServiceHandler.java?view=diff&rev=516458&r1=516457&r2=516458
==============================================================================
--- incubator/felix/trunk/ipojo/src/main/java/org/apache/felix/ipojo/handlers/providedservice/ProvidedServiceHandler.java
(original)
+++ incubator/felix/trunk/ipojo/src/main/java/org/apache/felix/ipojo/handlers/providedservice/ProvidedServiceHandler.java
Fri Mar  9 08:50:30 2007
@@ -62,8 +62,9 @@
             System.arraycopy(m_providedServices, 0, newPS, 0, m_providedServices.length);
             newPS[m_providedServices.length] = ps;
             m_providedServices = newPS;
+        } else { 
+        	m_providedServices = new ProvidedService[] {ps}; 
         }
-        else { m_providedServices = new ProvidedService[] {ps}; }
     }
 
     /**
@@ -125,8 +126,13 @@
                 String field = null;
                 if (props[j].containsAttribute("field")) { field = props[j].getAttribute("field");
}
 
-                if (name != null && configuration.get(name) != null && configuration.get(name)
instanceof String) { value = (String) configuration.get(name); }
-                else { if (field != null &&  configuration.get(field) != null &&
configuration.get(field) instanceof String) { value = (String) configuration.get(field); }
}
+                if (name != null && configuration.get(name) != null && configuration.get(name)
instanceof String) { 
+                	value = (String) configuration.get(name); 
+                } else { 
+                	if (field != null &&  configuration.get(field) != null &&
configuration.get(field) instanceof String) { 
+                		value = (String) configuration.get(field); 
+                	}
+                }
 
                 Property prop = new Property(ps, name, field, type, value, manipulation);
                 properties[j] = prop;
@@ -140,12 +146,11 @@
                 // Change ComponentInfo
                 for (int k = 0; k < ps.getServiceSpecification().length; k++) { cd.addProvidedServiceSpecification(ps.getServiceSpecification()[k]);
}
                 for (int k = 0; k < ps.getProperties().length; k++) { 
-                	if(!ps.getProperties()[k].getName().equals(Constants.SERVICE_PID) &&
!ps.getProperties()[k].getName().equals("factory.pid")) {
+                	if (!ps.getProperties()[k].getName().equals(Constants.SERVICE_PID) &&
!ps.getProperties()[k].getName().equals("factory.pid")) {
                 		cd.addProperty(new PropertyDescription(ps.getProperties()[k].getName(),
ps.getProperties()[k].getType(), ps.getProperties()[k].getInitialValue())); 
                 	}
                 }
-            }
-            else {
+            } else {
                 String itfs = "";
                 for (int j = 0; j < serviceSpecification.length; j++) {
                     itfs = itfs + " " + serviceSpecification[j];
@@ -164,9 +169,13 @@
                     Property prop = ps.getProperties()[j];
 
                     // Check if the instance configuration has a value for this property
-                    if (prop.getName() != null && configuration.get(prop.getName())
!= null && !(configuration.get(prop.getName()) instanceof String)) { prop.set(configuration.get(prop.getName()));
}
-                    else { if (prop.getField() != null && configuration.get(prop.getField())
!= null && !(configuration.get(prop.getField()) instanceof String)) { prop.set(configuration.get(prop.getField()));
} }
-
+                    if (prop.getName() != null && configuration.get(prop.getName())
!= null && !(configuration.get(prop.getName()) instanceof String)) { 
+                    	prop.set(configuration.get(prop.getName())); 
+                    } else { 
+                    	if (prop.getField() != null && configuration.get(prop.getField())
!= null && !(configuration.get(prop.getField()) instanceof String)) { 
+                    		prop.set(configuration.get(prop.getField())); 
+                    	}
+                    }
                     if (prop.getField() != null) {
                         String[] newFields = new String[fields.length + 1];
                         System.arraycopy(fields, 0, newFields, 0, fields.length);
@@ -176,7 +185,8 @@
                 }
             }
 
-            m_manager.register(this, fields); }
+            m_manager.register(this, fields); 
+        }
     }
 
     /**
@@ -193,7 +203,7 @@
                     b = true;
                 }
             }
-        	if(!b) { 
+        	if (!b) { 
         		m_manager.getFactory().getLogger().log(Logger.ERROR, "[" + m_manager.getClassName()
+ "] The service specification " + ps.getServiceSpecification()[i] + " is not implemented
by the component class");
         		return false; 
         	}
@@ -226,26 +236,16 @@
     }
 
     /**
-     * Stop the provided service handler : unregister all provided services.
+     * Stop the provided service handler.
      * @see org.apache.felix.ipojo.Handler#stop()
      */
-    public void stop() {
-        for (int i = 0; i < m_providedServices.length; i++) {
-            m_providedServices[i].unregisterService();
-        }
-    }
+    public void stop() { }
 
     /**
-     * Start the provided service handler : register the service if the component is resolved.
-     * Else do nothing and whait for a component state change event
+     * Start the provided service handler.
      * @see org.apache.felix.ipojo.Handler#start()
      */
-    public void start() {
-    	m_manager.getFactory().getLogger().log(Logger.INFO, "[" + m_manager.getClassName() +
"] Start the provided service handler");
-        for (int i = 0; (m_manager.getState() == InstanceManager.VALID) && i <
m_providedServices.length; i++) {
-            m_providedServices[i].registerService();
-        }
-    }
+    public void start() { }
 
     /**
      * @see org.apache.felix.ipojo.Handler#setterCallback(java.lang.String, java.lang.Object)
@@ -254,13 +254,16 @@
         // Verify that the field name coreespond to a dependency
         for (int i = 0; i < m_providedServices.length; i++) {
             ProvidedService ps = m_providedServices[i];
+            boolean update = false;
             for (int j = 0; j < ps.getProperties().length; j++) {
                 Property prop = ps.getProperties()[j];
                 if (fieldName.equals(prop.getField())) {
                     // it is the associated property
                     prop.set(value);
+                    update = true;
                 }
             }
+            if (update) { ps.update(); }
         }
         //Else do nothing
     }
@@ -291,13 +294,17 @@
     public void stateChanged(int state) {
         // If the new state is UNRESOLVED => unregister all the services
         if (state == InstanceManager.INVALID) {
-            stop();
+        	for (int i = 0; i < m_providedServices.length; i++) {
+                m_providedServices[i].unregisterService();
+            }
             return;
         }
 
         // If the new state is VALID => regiter all the services
         if (state == InstanceManager.VALID) {
-            start();
+        	for (int i = 0; i < m_providedServices.length; i++) {
+                m_providedServices[i].registerService();
+            }
             return;
         }
 
@@ -310,6 +317,7 @@
     public void addProperties(Dictionary dict) {
         for (int i = 0; i < m_providedServices.length; i++) {
             m_providedServices[i].addProperties(dict);
+            m_providedServices[i].update();
         }
     }
 
@@ -320,6 +328,7 @@
     public void removeProperties(Dictionary dict) {
         for (int i = 0; i < m_providedServices.length; i++) {
             m_providedServices[i].deleteProperties(dict);
+            m_providedServices[i].update();
         }
     }
 	
@@ -341,8 +350,27 @@
 			psd.setProperty(props);
 			pshd.addProvidedService(psd);
 		}
-		
 		return pshd;
+	}
+	
+	/**
+	 * @see org.apache.felix.ipojo.Handler#reconfigure(java.util.Dictionary)
+	 */
+	public void reconfigure(Dictionary dict) {
+		for (int j = 0; j < getProvidedService().length; j++) {
+			ProvidedService ps = getProvidedService()[j];
+			Property[] props = ps.getProperties();
+			boolean update = false;
+			for (int k = 0; k < props.length; k++) {
+				if (dict.get(props[k].getName()) != null) {
+					update = true;
+					if (dict.get(props[k].getName()) instanceof String) {
+						props[k].set((String) dict.get(props[k].getName()));
+					} else { props[k].set(dict.get(props[k].getName())); }
+				}
+			}
+			if (update) { ps.update(); }
+		}
 	}
 
 }

Modified: incubator/felix/trunk/ipojo/src/main/java/org/apache/felix/ipojo/parser/ManifestMetadataParser.java
URL: http://svn.apache.org/viewvc/incubator/felix/trunk/ipojo/src/main/java/org/apache/felix/ipojo/parser/ManifestMetadataParser.java?view=diff&rev=516458&r1=516457&r2=516458
==============================================================================
--- incubator/felix/trunk/ipojo/src/main/java/org/apache/felix/ipojo/parser/ManifestMetadataParser.java
(original)
+++ incubator/felix/trunk/ipojo/src/main/java/org/apache/felix/ipojo/parser/ManifestMetadataParser.java
Fri Mar  9 08:50:30 2007
@@ -62,32 +62,44 @@
         return dicts;
     }
     
+    /**
+     * Parse an Element to get a dictionary.
+     * @param instance : the Element describing an instance.
+     * @return : the resulting dictionary
+     * @throws ParseException
+     */
     private Dictionary parseInstance(Element instance) throws ParseException {
     	Dictionary dict = new Properties();
-    	if(!instance.containsAttribute("name")) { throw new ParseException("An instance does
not have the 'name' attribute"); }
-    	if(!instance.containsAttribute("component")) { throw new ParseException("An instance
does not have the 'component' attribute"); }
+    	if (!instance.containsAttribute("name")) { throw new ParseException("An instance does
not have the 'name' attribute"); }
+    	if (!instance.containsAttribute("component")) { throw new ParseException("An instance
does not have the 'component' attribute"); }
     	dict.put("name", instance.getAttribute("name"));
     	dict.put("component", instance.getAttribute("component"));
     	
-    	for(int i=0; i < instance.getElements("property").length; i++) {
+    	for (int i = 0; i < instance.getElements("property").length; i++) {
     		parseProperty(instance.getElements("property")[i], dict);
     	}
     	
     	return dict;
     }
     
+    /**
+     * @param prop
+     * @param dict
+     * @throws ParseException
+     */
     private void parseProperty(Element prop, Dictionary dict) throws ParseException {
     	// Check that the property has a name 
-    	if(!prop.containsAttribute("name")) { throw new ParseException("A property does not
have the 'name' attribute"); }
+    	if (!prop.containsAttribute("name")) { throw new ParseException("A property does not
have the 'name' attribute"); }
     	// Final case : the property element has a 'value' attribute
-    	if(prop.containsAttribute("value")) { dict.put(prop.getAttribute("name"), prop.getAttribute("value"));
}
-    	else {
+    	if (prop.containsAttribute("value")) { 
+    		dict.put(prop.getAttribute("name"), prop.getAttribute("value")); 
+    	} else {
     		// Recursive case
     		// Check if there is 'property' element
     		Element[] subProps = prop.getElements("property");
-    		if(subProps.length == 0) { throw new ParseException("A complex property must have at
least one 'property' sub-element"); }
+    		if (subProps.length == 0) { throw new ParseException("A complex property must have
at least one 'property' sub-element"); }
     		Dictionary dict2 = new Properties();
-    		for(int i = 0; i < subProps.length; i++) {
+    		for (int i = 0; i < subProps.length; i++) {
     			parseProperty(subProps[i], dict2);
     			dict.put(prop.getAttribute("name"), dict2);
     		}
@@ -104,8 +116,7 @@
             System.arraycopy(m_elements, 0, newElementsList, 0, m_elements.length);
             newElementsList[m_elements.length] = elem;
             m_elements = newElementsList;
-        }
-        else { m_elements = new Element[] {elem}; }
+        } else { m_elements = new Element[] {elem}; }
     }
 
     /**
@@ -120,8 +131,7 @@
             if ((m_elements.length - 1) == 0) {
                 // It is the last element of the list;
                 m_elements = new Element[0];
-            }
-            else {
+            } else {
                 // Remove the last element of the list :
                 Element[] newElementsList = new Element[m_elements.length - 1];
                 System.arraycopy(m_elements, 0, newElementsList, 0, idx);
@@ -169,8 +179,8 @@
             char c = string[i];
 
             switch(c) {
-
-                case '$' :
+            	// Beginning of an attribute.
+                case '$' : 
                     String attName = "";
                     String attValue = "";
                     String attNs = "";
@@ -199,41 +209,45 @@
                     m_elements[m_elements.length - 1].addAttribute(att);
                     break;
 
-                case '}' :
+                // End of an element    
+                case '}' : 
                     Element lastElement = removeLastElement();
                     if (m_elements.length != 0) {
                         Element newQueue = m_elements[m_elements.length - 1];
                         newQueue.addElement(lastElement);
-                    }
-                    else {
+                    } else {
                         addElement(lastElement);
                     }
                     break;
-                case ' ' : break; // do nothing;
+
+                // Space
+                case ' ' : 
+                	break; // do nothing;
+                
+                // Default case
                 default :
                     String name = "";
-                String ns = "";
-                c = string[i];
-                while (c != ' ') {
-                    if (c == ':') {
-                        ns = name;
-                        name = "";
-                        i++;
-                        c = string[i];
-                    }
-                    else {
-                        name = name + c;
-                        i++;
-                        c = string[i];
-                    }
-                }
-                // Skip spaces
-                while (string[i] == ' ') { i = i + 1; }
-                i = i + 1; // skip {
-                Element elem = new Element(name, ns);
-                addElement(elem);
-                break;
-            }
+                	String ns = "";
+                	c = string[i];
+                	while (c != ' ') {
+                		if (c == ':') {
+                			ns = name;
+                			name = "";
+                			i++;
+                			c = string[i];
+                		} else {
+                			name = name + c;
+                			i++;
+                			c = string[i];
+                		}
+                	}
+                	// Skip spaces
+                	while (string[i] == ' ') { i = i + 1; }
+                	i = i + 1; // skip {
+                	Element elem = new Element(name, ns);
+                	addElement(elem);
+                	break;
+           	}
         }
     }
 

Modified: incubator/felix/trunk/ipojo/src/main/java/org/apache/felix/ipojo/parser/ParseUtils.java
URL: http://svn.apache.org/viewvc/incubator/felix/trunk/ipojo/src/main/java/org/apache/felix/ipojo/parser/ParseUtils.java?view=diff&rev=516458&r1=516457&r2=516458
==============================================================================
--- incubator/felix/trunk/ipojo/src/main/java/org/apache/felix/ipojo/parser/ParseUtils.java
(original)
+++ incubator/felix/trunk/ipojo/src/main/java/org/apache/felix/ipojo/parser/ParseUtils.java
Fri Mar  9 08:50:30 2007
@@ -1,18 +1,40 @@
+/* 
+ * 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.felix.ipojo.parser;
 
+/**
+ * Parse Utils Methods.
+ * @author <a href="mailto:felix-dev@incubator.apache.org">Felix Project Team</a>
+ */
 public class ParseUtils {
 	
 	/**
-	 * Parse the string form of an array as {a, b, c}
+	 * Parse the string form of an array as {a, b, c}.
 	 * @param str : the string form
 	 * @return the resulting string array
 	 */
 	public static String[] parseArrays(String str) {
 		// Remove { and }
-		if(str.startsWith("{") && str.endsWith("}")) {
+		if (str.startsWith("{") && str.endsWith("}")) {
 			String m = str.substring(1, str.length() - 1);
 			String[] values = m.split(",");
-			for(int i = 0; i < values.length; i++) {
+			for (int i = 0; i < values.length; i++) {
 				values[i] = values[i].trim();
 			}
 			return values;

Modified: incubator/felix/trunk/ipojo/src/main/java/org/apache/felix/ipojo/util/Callback.java
URL: http://svn.apache.org/viewvc/incubator/felix/trunk/ipojo/src/main/java/org/apache/felix/ipojo/util/Callback.java?view=diff&rev=516458&r1=516457&r2=516458
==============================================================================
--- incubator/felix/trunk/ipojo/src/main/java/org/apache/felix/ipojo/util/Callback.java (original)
+++ incubator/felix/trunk/ipojo/src/main/java/org/apache/felix/ipojo/util/Callback.java Fri
Mar  9 08:50:30 2007
@@ -69,8 +69,9 @@
         Method method = m_manager.getClazz().getDeclaredMethod(m_method, new Class[] {});
         method.setAccessible(true);
 
-        if (m_isStatic) { method.invoke(null, new Object[]{}); }
-        else {
+        if (m_isStatic) { 
+        	method.invoke(null, new Object[]{}); 
+        } else {
             // Two cases :
             // - if instances already exists : call on each instances
             // - if no instance exists : create an instance
@@ -119,8 +120,9 @@
         Method method = m_manager.getClazz().getDeclaredMethod(m_method, classes);
         method.setAccessible(true);
 
-        if (m_isStatic) { method.invoke(null, arg); }
-        else {
+        if (m_isStatic) { 
+        	method.invoke(null, arg); 
+        } else {
             // Two cases :
             // - if instances already exists : call on each instances
             // - if no instance exists : create an instance

Modified: incubator/felix/trunk/ipojo/src/main/java/org/apache/felix/ipojo/util/Logger.java
URL: http://svn.apache.org/viewvc/incubator/felix/trunk/ipojo/src/main/java/org/apache/felix/ipojo/util/Logger.java?view=diff&rev=516458&r1=516457&r2=516458
==============================================================================
--- incubator/felix/trunk/ipojo/src/main/java/org/apache/felix/ipojo/util/Logger.java (original)
+++ incubator/felix/trunk/ipojo/src/main/java/org/apache/felix/ipojo/util/Logger.java Fri
Mar  9 08:50:30 2007
@@ -25,70 +25,131 @@
 import org.osgi.framework.ServiceReference;
 import org.osgi.service.log.LogService;
 
-public class Logger implements ServiceListener{
+/**
+ * iPOJO Logger.
+ * This logger send log message to a log service if presents. 
+ * @author <a href="mailto:felix-dev@incubator.apache.org">Felix Project Team</a>
+ */
+public class Logger implements ServiceListener {
 	
+	// TODO how to stop the logging (remove listener ...)
+	
+	/**
+	 * Log Level ERROR.
+	 */
 	public static final int ERROR = 1;
+    
+	/**
+     * Log Level WARNING. 
+     */
     public static final int WARNING = 2;
+    
+    /**
+     * Log Level INFO.
+     */
     public static final int INFO = 3;
+    
+    /**
+     * Log Level DEBUG. 
+     */
     public static final int DEBUG = 4;
     
+    /**
+     * Bundle Context.
+     */
     private BundleContext m_context;
+    
+    /**
+     * Service Reference of the log service is available. 
+     */
     private ServiceReference m_ref;
+    
+    /**
+     * Log service object. 
+     */
     private LogService m_log;
     
+    /**
+     * Name of the logger. 
+     */
     private String m_name;
+    
+    /**
+     * trace level of this logger. 
+     */
     private int m_level;
     
+    /**
+     * Constructor.
+     * @param bc : bundle context
+     * @param name : name of the logger
+     * @param level : trace level
+     */
     public Logger(BundleContext bc, String name, int level) { 
     	m_name = name;
     	m_level = level;
     	m_context = bc;
     	
     	m_ref = m_context.getServiceReference(LogService.class.getName());
-    	if(m_ref != null) { m_log = (LogService) m_context.getService(m_ref); }
+    	if (m_ref != null) { m_log = (LogService) m_context.getService(m_ref); }
     	
     	try {
-			m_context.addServiceListener(this, "(objectClass="+LogService.class.getName() + ")");
+			m_context.addServiceListener(this, "(objectClass=" + LogService.class.getName() + ")");
 		} catch (InvalidSyntaxException e) { e.printStackTrace(); }
     }
     
+    /**
+     * Log a message.
+     * @param level : level of the message
+     * @param msg : the message to log
+     */
     public void log(int level, String msg) {
-    	if(m_level >= level) {
-    		synchronized(this) { _log(level, msg, null); }
+    	if (m_level >= level) {
+    		synchronized (this) { _log(level, msg, null); }
     	}
     }
     
+    /**
+     * Log a message with an exception.
+     * @param level : level of the message
+     * @param msg : message to log
+     * @param ex : exception attached to the message
+     */
     public void log(int level, String msg, Throwable ex) {
-    	if(m_level >= level) { 
-    		synchronized(this) {_log(level, msg, ex); }
+    	if (m_level >= level) { 
+    		synchronized (this) { _log(level, msg, ex); }
     	}
     }
     
-    private void _log(int level, String msg, Throwable ex)
-    {
+    /**
+     * Internal log method.
+     * @param level : level of the message.
+     * @param msg : message to log
+     * @param ex : exception attached to the message
+     */
+    private void _log(int level, String msg, Throwable ex) {
         String s = msg;
         s = (ex == null) ? s : s + " (" + ex.getMessage() + ")";
         String message;
-        switch (level)
-        {
+        switch (level) {
             case DEBUG:
             	message = "[" + m_name + "] DEBUG: " + s;
-            	if(m_log != null) { m_log.log(LogService.LOG_DEBUG, message); }
+            	if (m_log != null) { m_log.log(LogService.LOG_DEBUG, message); }
                 System.err.println(message);
                 break;
             case ERROR:
             	message = "[" + m_name + "] ERROR: " + s;
-            	if(m_log != null) { m_log.log(LogService.LOG_ERROR, message); }
+            	if (m_log != null) { m_log.log(LogService.LOG_ERROR, message); }
                 System.err.println(message);
                 break;
             case INFO:
                 message = "[" + m_name + "] INFO: " + s;
-                if(m_log != null) { m_log.log(LogService.LOG_INFO, message); }
+                if (m_log != null) { m_log.log(LogService.LOG_INFO, message); }
             	System.err.println(message);
                 break;
             case WARNING:
             	message = "[" + m_name + "] WARNING: " + s;
-            	if(m_log != null) { m_log.log(LogService.LOG_WARNING, message); }
+            	if (m_log != null) { m_log.log(LogService.LOG_WARNING, message); }
                 System.err.println(message);
                 break;
             default:
@@ -97,16 +158,19 @@
         }
     }
 
+	/**
+	 * @see org.osgi.framework.ServiceListener#serviceChanged(org.osgi.framework.ServiceEvent)
+	 */
 	public void serviceChanged(ServiceEvent ev) {
-		if(ev.getType() == ServiceEvent.REGISTERED && m_ref == null) {
+		if (ev.getType() == ServiceEvent.REGISTERED && m_ref == null) {
 			m_ref = ev.getServiceReference();
 			m_log = (LogService) m_context.getService(m_ref);
 		}
-		if(ev.getType() == ServiceEvent.UNREGISTERING && m_ref == ev.getServiceReference())
{
+		if (ev.getType() == ServiceEvent.UNREGISTERING && m_ref == ev.getServiceReference())
{
 			m_context.ungetService(m_ref);
 			m_log = null;
 			m_ref = m_context.getServiceReference(LogService.class.getName());
-	    	if(m_ref != null) { m_log = (LogService) m_context.getService(m_ref); }
+	    	if (m_ref != null) { m_log = (LogService) m_context.getService(m_ref); }
 		}
 		
 	}



Mime
View raw message