felix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rickh...@apache.org
Subject svn commit: r414287 [3/6] - in /incubator/felix/trunk: org.apache.felix.ipojo.arch/ org.apache.felix.ipojo.arch/src/ org.apache.felix.ipojo.arch/src/main/ org.apache.felix.ipojo.arch/src/main/java/ org.apache.felix.ipojo.arch/src/main/java/org/ org.apa...
Date Wed, 14 Jun 2006 15:22:08 GMT
Added: incubator/felix/trunk/org.apache.felix.ipojo/src/main/java/org/apache/felix/ipojo/ComponentManager.java
URL: http://svn.apache.org/viewvc/incubator/felix/trunk/org.apache.felix.ipojo/src/main/java/org/apache/felix/ipojo/ComponentManager.java?rev=414287&view=auto
==============================================================================
--- incubator/felix/trunk/org.apache.felix.ipojo/src/main/java/org/apache/felix/ipojo/ComponentManager.java (added)
+++ incubator/felix/trunk/org.apache.felix.ipojo/src/main/java/org/apache/felix/ipojo/ComponentManager.java Wed Jun 14 08:22:03 2006
@@ -0,0 +1,502 @@
+/*
+ *   Copyright 2006 The Apache Software Foundation
+ *
+ *   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.apache.felix.ipojo;
+
+import java.lang.reflect.Constructor;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.util.logging.Level;
+
+import org.apache.felix.ipojo.metadata.Element;
+import org.osgi.framework.BundleContext;
+
+/**
+ * The component manager class manage one "version" of a component.
+ * It manages component lifecycle, component instance creation and handlers.
+ * @author Clement Escoffier
+ */
+public class ComponentManager {
+
+	// STATIC PART
+
+	/**
+     * Component State : INVALID.
+     * The component is invalid when it start or when a component dependency is unvalid.
+     */
+    public static final int INVALID = 1;
+
+    /**
+     * Component State : VALID.
+     * The component is resolved when it is running and all its component dependencies are valid.
+     */
+    public static final int VALID = 2;
+
+    // END STATIC PART
+
+	/**
+	 * Parent factory (ComponentManagerFactory).
+	 */
+	private ComponentManagerFactory m_factory;
+
+	/**
+	 * Attached metadata of the managed component.
+	 */
+	private ComponentMetadata m_metadata;
+
+	/**
+	 * The context of the component.
+	 */
+	private BundleContext m_context;
+
+	/**
+	 * Handler list.
+	 */
+	private Handler[] m_handlers = new Handler[0];
+
+	/**
+	 * Component state (STOPPED at the beginning).
+	 */
+	private int m_state = INVALID;
+
+	// Fields use for the manipulation, the loading of the class and for the instance creation
+
+	/**
+	 * Manipulatd clazz.
+	 */
+	private Class m_clazz;
+
+	/**
+	 * Instances of the components.
+	 */
+	private Object[] m_instances = new Object[0];
+
+    // Constructor
+    /**
+     * Construct a new Component Manager.
+     * @param factory : the factory managing the component manager
+     */
+    public ComponentManager(ComponentManagerFactory factory) {
+    	m_factory = factory;
+    	m_context = factory.getBundleContext();
+    	Activator.getLogger().log(Level.INFO, "[Bundle " + m_context.getBundle().getBundleId() + "] Create a component manager from the factory " + m_factory);
+    }
+
+	/**
+	 * Configure the component manager.
+	 * Stop the existings handler, clear the handler list, change the metadata, recreate the handlers
+	 * @param cm
+	 */
+	public void configure(Element cm) {
+		Activator.getLogger().log(Level.INFO, "[Bundle " + m_context.getBundle().getBundleId() + "] Configure the component manager " + cm.getAttribute("className"));
+
+		// Stop all previous registred handler
+		if (m_handlers.length != 0) { stop(); }
+
+		// Clear the handler list
+		m_handlers = new Handler[0];
+
+		// Change the metadata
+		m_metadata = new ComponentMetadata(cm);
+
+		// Create the standard handlers and add these handlers to the list
+		for (int i = 0; i < IPojoConfiguration.INTERNAL_HANDLERS.length; i++) {
+			// Create a new instance
+			try {
+				Handler h = (Handler)IPojoConfiguration.INTERNAL_HANDLERS[i].newInstance();
+				h.configure(this, cm);
+			} catch (InstantiationException e) {
+				Activator.getLogger().log(Level.SEVERE, "[" + m_metadata.getClassName() + "] Cannot instantiate the handler " + IPojoConfiguration.INTERNAL_HANDLERS[i] + " : " + e.getMessage());
+			} catch (IllegalAccessException e) {
+				Activator.getLogger().log(Level.SEVERE, "[" + m_metadata.getClassName() + "] Cannot instantiate the handler " + IPojoConfiguration.INTERNAL_HANDLERS[i] + " : " + e.getMessage());
+			}
+		}
+
+		// Look for namespaces
+		for (int i = 0; i < cm.getNamespaces().length; i++) {
+			if (!cm.getNamespaces()[i].equals("")) {
+				Activator.getLogger().log(Level.INFO, "[" + m_metadata.getClassName() + "] Look for class for the namespace : " + cm.getNamespaces()[i]);
+				// It is not an internal handler, try to load it
+				try {
+					Class c = m_context.getBundle().loadClass(cm.getNamespaces()[i]);
+					//Class c = Class.forName(cm.getNamespaces()[i]);
+					Handler h = (Handler) c.newInstance();
+					h.configure(this, cm);
+				} catch (ClassNotFoundException e) {
+					Activator.getLogger().log(Level.SEVERE, "[" + m_metadata.getClassName() + "] Cannot instantiate the handler " + cm.getNamespaces()[i] + " : " + e.getMessage());
+				} catch (InstantiationException e) {
+					Activator.getLogger().log(Level.SEVERE, "[" + m_metadata.getClassName() + "] Cannot instantiate the handler " + cm.getNamespaces()[i] + " : " + e.getMessage());
+				} catch (IllegalAccessException e) {
+					Activator.getLogger().log(Level.SEVERE, "[" + m_metadata.getClassName() + "] Cannot instantiate the handler " + cm.getNamespaces()[i] + " : " + e.getMessage());
+				}
+
+			}
+		}
+	}
+
+	/**
+	 * @return the component metadata.
+	 */
+	public ComponentMetadata getComponentMetatada() { return m_metadata; }
+
+	/**
+	 * @return the list of the registred handlers.
+	 */
+	public Handler[] getRegistredHandlers() { return m_handlers; }
+
+	/**
+	 * Return a specified handler.
+	 * @param name : class name of the handler to find
+	 * @return : the handler, or null if not found
+	 */
+	public Handler getHandler(String name) {
+		for (int i = 0; i < m_handlers.length; i++) {
+			if (m_handlers[i].getClass().getName().equalsIgnoreCase(name)) { return m_handlers[i]; }
+		}
+		return null;
+	}
+
+	// ===================== Lifecycle management =====================
+
+	/**
+	 * Start the component manager.
+	 */
+	public void start() {
+		// Start all the handlers
+		Activator.getLogger().log(Level.INFO, "[" + m_metadata.getClassName() + "] Start the component manager with " + m_handlers.length + " handlers");
+
+		// The new state of the component is UNRESOLVED
+		m_state = INVALID;
+
+		for (int i = 0; i < m_handlers.length; i++) {
+			m_handlers[i].start();
+		}
+
+		// Defines the state of the component :
+		check();
+	}
+
+	/**
+	 * Stop the component manager.
+	 */
+	public void stop() {
+		setState(INVALID);
+		// Stop all the handlers
+		for (int i = 0; i < m_handlers.length; i++) {
+			m_handlers[i].stop();
+		}
+		m_instances = new Object[0];
+	}
+
+	/**
+	 * Set the state of the component.
+	 * if the state changed call the stateChanged(int) method on the handlers
+	 */
+	public void setState(int state) {
+		if (m_state != state) {
+
+			// Log the state change
+			if (state == INVALID) { Activator.getLogger().log(Level.INFO, "[" + m_metadata.getClassName() + "] Component " + m_metadata.getClassName() + " State -> UNRESOLVED"); }
+			if (state == VALID) { Activator.getLogger().log(Level.INFO, "[" + m_metadata.getClassName() + "] Component " + m_metadata.getClassName() + " State -> VALID"); }
+
+			// The state changed call the handler stateChange method
+			m_state = state;
+			for (int i = 0; i < m_handlers.length; i++) {
+				m_handlers[i].stateChanged(state);
+			}
+		}
+	}
+
+	/**
+	 * @return the actual state of the component
+	 */
+	public int getState() {
+		return m_state;
+	}
+
+	// ===================== end Lifecycle management =====================
+
+	// ================== Class & Instance management ===================
+
+	/**
+	 * @return the factory of the component
+	 */
+	public ComponentManagerFactory getFactory() { return m_factory; }
+
+	/**
+	 * Load the manipulated class.
+	 */
+	private void load() {
+        try {
+        	m_clazz = m_factory.getBundleContext().getBundle().loadClass(m_metadata.getClassName());
+        } catch (Exception  e) {
+            Activator.getLogger().log(Level.SEVERE, "[" + m_metadata.getClassName() + "] Class not found during the loading phase : " + e.getMessage());
+            return;
+        }
+	}
+
+	/**
+	 * @return true if the class is loaded
+	 */
+	private boolean isLoaded() {
+		return (m_clazz != null);
+	}
+
+	private void addInstance(Object o) {
+        for (int i = 0; (m_instances != null) && (i < m_instances.length); i++) {
+            if (m_instances[i] == o) { return; }
+        }
+
+        if (m_instances.length > 0) {
+            Object[] newInstances = new Object[m_instances.length + 1];
+            System.arraycopy(m_instances, 0, newInstances, 0, m_instances.length);
+            newInstances[m_instances.length] = o;
+            m_instances = newInstances;
+        }
+        else {
+        	m_instances = new Object[] {o};
+        }
+	}
+
+	private void removeInstance(Object o) {
+		int idx = -1;
+        for (int i = 0; i < m_instances.length; i++) {
+            if (m_instances[i] == o) { idx = i; break; }
+        }
+
+        if (idx >= 0) {
+            if ((m_instances.length - 1) == 0) { m_instances = new Element[0]; }
+            else {
+                Object[] newInstances = new Object[m_instances.length - 1];
+                System.arraycopy(m_instances, 0, newInstances, 0, idx);
+                if (idx < newInstances.length) {
+                    System.arraycopy(m_instances, idx + 1, newInstances, idx, newInstances.length - idx); }
+                m_instances = newInstances;
+            }
+        }
+	}
+
+	/**
+	 * @return the created instance of the component.
+	 */
+	public Object[] getInstances() { return m_instances; }
+
+	/**
+	 * Delete the created instance (remove it from the list, to allow the garbage collector to eat the instance).
+	 * @param o : the instance to delete
+	 */
+	public void deleteInstance(Object o) { removeInstance(o); }
+
+	/**
+	 * Create an instance of the component.
+	 * This method need to be called one time only for singleton provided service
+	 * @return a new instance
+	 */
+	public Object createInstance() {
+		if (!isLoaded()) { load(); }
+		Object instance = null;
+		try {
+
+			Activator.getLogger().log(Level.INFO, "[" + m_metadata.getClassName() + "] createInstance -> call setComponentManager");
+			// Invoke the static method setComponentManager on the manipulated class
+			Method method = m_clazz.getMethod("setComponentManager", new Class[] {this.getClass()});
+			method.invoke(null, new Object[] {this});
+
+			Activator.getLogger().log(Level.INFO, "[" + m_metadata.getClassName() + "] createInstance -> Try to find the constructor");
+
+			// Try to find if there is a constructor with a bundle context as parameter :
+			try {
+				Constructor constructor = m_clazz.getConstructor(new Class[] {BundleContext.class});
+				constructor.setAccessible(true);
+				instance = constructor.newInstance(new Object[] {m_factory.getBundleContext()});
+			}
+			catch (NoSuchMethodException e) {
+				Activator.getLogger().log(Level.INFO, "[" + m_metadata.getClassName() + "] createInstance -> No constructor with a bundle context");
+			}
+
+			// Create an instance if no instance are already created with <init>()BundleContext
+			Activator.getLogger().log(Level.INFO, "[" + m_metadata.getClassName() + "] createInstance -> Try to create the object with an empty constructor");
+			if (instance == null) { instance = m_clazz.newInstance(); }
+
+		} catch (InstantiationException e) {
+			Activator.getLogger().log(Level.SEVERE, "[" + m_metadata.getClassName() + "] createInstance -> The Component Instance cannot be instancied : " + e.getMessage());
+			e.printStackTrace();
+		} catch (IllegalAccessException e) {
+			Activator.getLogger().log(Level.SEVERE, "[" + m_metadata.getClassName() + "] createInstance -> The Component Instance is not accessible : " + e.getMessage());
+			e.printStackTrace();
+		} catch (SecurityException e) {
+			Activator.getLogger().log(Level.SEVERE, "[" + m_metadata.getClassName() + "] createInstance -> The Component Instance is not accessible (security reason) : " + e.getMessage());
+			e.printStackTrace();
+		} catch (IllegalArgumentException e) {
+			Activator.getLogger().log(Level.SEVERE, "[" + m_metadata.getClassName() + "] createInstance -> Cannot invoke the setComponentManager method (illegal argument) : " + e.getMessage());
+			e.printStackTrace();
+		} catch (InvocationTargetException e) {
+			Activator.getLogger().log(Level.SEVERE, "[" + m_metadata.getClassName() + "] createInstance -> Cannot invoke the setComponentManager method (illegal target) : " + e.getMessage());
+			e.printStackTrace();
+		} catch (NoSuchMethodException e) {
+			Activator.getLogger().log(Level.SEVERE, "[" + m_metadata.getClassName() + "] createInstance -> Cannot invoke the setComponentManager method (method not found) : " + e.getMessage());
+			e.printStackTrace();
+		}
+
+		Activator.getLogger().log(Level.INFO, "[" + m_metadata.getClassName() + "] createInstance -> Return the instance " + instance);
+
+		// Register the new instance
+		addInstance(instance);
+		return instance;
+	}
+
+	/**
+	 * @return the instance of the component to use for singleton component
+	 */
+	public Object getInstance() {
+		if (m_instances.length == 0) { createInstance(); }
+		return m_instances[0];
+	}
+
+	/**
+	 * @return the manipulated class
+	 */
+	public Class getClazz() {
+		if (!isLoaded()) { load(); }
+		return m_clazz;
+	}
+
+	//	================== end Class & Instance management ================
+
+	//  ======================== Handlers Management ======================
+
+	/**
+     * Register the given handler to the current component manager.
+	 * @param h : the handler to register
+	 */
+	public void register(Handler h) {
+        for (int i = 0; (m_handlers != null) && (i < m_handlers.length); i++) {
+            if (m_handlers[i] == h) {
+                return;
+            }
+        }
+
+        if (m_handlers != null) {
+            Handler[] newList = new Handler[m_handlers.length + 1];
+            System.arraycopy(m_handlers, 0, newList, 0, m_handlers.length);
+            newList[m_handlers.length] = h;
+            m_handlers = newList;
+        }
+	}
+
+	/**
+     * Unregister the given handler.
+	 * @param h : the handler to unregiter
+	 */
+	public void unregister(Handler h) {
+        int idx = -1;
+        for (int i = 0; i < m_handlers.length; i++) {
+            if (m_handlers[i] == h) {
+                idx = i;
+                break;
+            }
+        }
+
+        if (idx >= 0) {
+            if ((m_handlers.length - 1) == 0) {
+                m_handlers = new Handler[0];
+            }
+            else {
+                Handler[] newList = new Handler[m_handlers.length - 1];
+                System.arraycopy(m_handlers, 0, newList, 0, idx);
+                if (idx < newList.length)             {
+                    System.arraycopy(
+                            m_handlers, idx + 1, newList, idx, newList.length - idx);
+                }
+                m_handlers = newList;
+            }
+        }
+	}
+
+	/**
+	 * This method is called by the manipulated class each time that a GETFIELD instruction is found.
+	 * The method ask to each handler which value need to be returned.
+	 * @param fieldName : the field name on which the GETFIELD instruction is called
+	 * @param initialValue : the value of the field in the code
+	 * @return the value decided by the last asked handler (throw a warining if two fields decide two different values)
+	 */
+	public Object getterCallback(String fieldName, Object initialValue) {
+		Activator.getLogger().log(Level.INFO, "[" + m_metadata.getClassName() + "] Call the getterCallbackMethod on " + fieldName +  " with " + initialValue);
+		Object result = null;
+		for (int i = 0; i < m_handlers.length; i++) {
+			Object handlerResult = m_handlers[i].getterCallback(fieldName, initialValue);
+			if (handlerResult != initialValue) { result = handlerResult; }
+		}
+
+		if (result != null) {
+			Activator.getLogger().log(Level.INFO, "[" + m_metadata.getClassName() + "] getterCallbackMethod return for " + fieldName +  " -> " + result);
+			return result;
+		} else {
+			Activator.getLogger().log(Level.INFO, "[" + m_metadata.getClassName() + "] getterCallbackMethod return for " + fieldName +  " -> " + initialValue);
+			return initialValue;
+		}
+	}
+
+	/**
+	 * This method is called by the manipulated class each time that a PUTFILED instruction is found.
+	 * the method send to each handler the new value.
+	 * @param fieldName : the field name on which the PUTFIELD instruction is called
+	 * @param objectValue : the value of the field
+	 */
+	public void setterCallback(String fieldName, Object objectValue) {
+		Activator.getLogger().log(Level.INFO, "[" + m_metadata.getClassName() + "] Call the setterCallbackMethod on " + fieldName +  " with " + objectValue);
+
+		for (int i = 0; i < m_handlers.length; i++) {
+			m_handlers[i].setterCallback(fieldName, objectValue);
+		}
+	}
+
+	/**
+	 * @return the context of the component.
+	 */
+	public BundleContext getContext() { return m_context; }
+
+	/**
+	 * Check the state of all handlers.
+	 */
+	public void check() {
+		Activator.getLogger().log(Level.INFO, "[" + m_metadata.getClassName() + "] Check the component state");
+		boolean isValid = true;
+		for (int i = 0; i < m_handlers.length; i++) {
+			boolean b = m_handlers[i].isValid();
+			Activator.getLogger().log(Level.INFO, "[" + m_metadata.getClassName() + "] Validity of the handler : " + m_handlers[i] + " = " + b);
+			isValid = isValid && b;
+		}
+
+		// Update the component state if necessary
+		if (!isValid && m_state == VALID) {
+			// Need to update the state to UNRESOLVED
+			setState(INVALID);
+			m_instances = new Object[0];
+			return;
+		}
+		if (isValid && m_state == INVALID) {
+			setState(VALID);
+			if (m_metadata.isImmediate() && m_instances.length == 0) { createInstance(); }
+		}
+
+		Activator.getLogger().log(Level.INFO, "[" + m_metadata.getClassName() + "] Component Manager : " + m_state);
+	}
+
+
+	// ======================= end Handlers Management =====================
+
+}

Propchange: incubator/felix/trunk/org.apache.felix.ipojo/src/main/java/org/apache/felix/ipojo/ComponentManager.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/felix/trunk/org.apache.felix.ipojo/src/main/java/org/apache/felix/ipojo/ComponentManagerFactory.java
URL: http://svn.apache.org/viewvc/incubator/felix/trunk/org.apache.felix.ipojo/src/main/java/org/apache/felix/ipojo/ComponentManagerFactory.java?rev=414287&view=auto
==============================================================================
--- incubator/felix/trunk/org.apache.felix.ipojo/src/main/java/org/apache/felix/ipojo/ComponentManagerFactory.java (added)
+++ incubator/felix/trunk/org.apache.felix.ipojo/src/main/java/org/apache/felix/ipojo/ComponentManagerFactory.java Wed Jun 14 08:22:03 2006
@@ -0,0 +1,159 @@
+/*
+ *   Copyright 2006 The Apache Software Foundation
+ *
+ *   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.apache.felix.ipojo;
+
+import java.util.logging.Level;
+
+import org.apache.felix.ipojo.metadata.Element;
+import org.osgi.framework.BundleContext;
+
+/**
+ * The component manager factory class manages component manager object.
+ * @author Clement Escoffier
+ */
+public class ComponentManagerFactory {
+
+	// Fields :
+	/**
+	 * List of the managed component manager.
+	 */
+	private ComponentManager[] m_componentManagers = new ComponentManager[0];
+
+	/**
+	 * The bundle context reference.
+	 */
+	private BundleContext m_bundleContext = null;
+
+	//End field
+
+	// Field accessors
+
+	 /**
+     * Add a component manager factory to the component manager list.
+     * @param cm : the new component metadata.
+     */
+    private void addComponent(ComponentManager cm) {
+
+    	// If the component manager array is not empty add the new factory at the end
+        if (m_componentManagers.length != 0) {
+        	ComponentManager[] newCM = new ComponentManager[m_componentManagers.length + 1];
+            System.arraycopy(m_componentManagers, 0, newCM, 0, m_componentManagers.length);
+            newCM[m_componentManagers.length] = cm;
+            m_componentManagers = newCM;
+        }
+        // Else create an array of size one with the new component manager
+        else {
+            m_componentManagers = new ComponentManager[] {cm};
+        }
+    }
+
+    /**
+     * Remove the component manager for m the list.
+     * @param cm : the component manager to remove
+     */
+    public void removeComponent(ComponentManager cm) {
+    	cm.stop();
+    	int idx = -1;
+
+    	for (int i = 0; i < m_componentManagers.length; i++) {
+    		if (m_componentManagers[i] == cm) { idx = i; }
+    	}
+
+        if (idx >= 0) {
+            if ((m_componentManagers.length - 1) == 0) { m_componentManagers = new ComponentManager[0]; }
+            else {
+            	ComponentManager[] newCMList = new ComponentManager[m_componentManagers.length - 1];
+                System.arraycopy(m_componentManagers, 0, newCMList, 0, idx);
+                if (idx < newCMList.length) {
+                    System.arraycopy(m_componentManagers, idx + 1, newCMList, idx, newCMList.length - idx); }
+                m_componentManagers = newCMList;
+            }
+            }
+       }
+
+    /**
+     * @return the iPOJO activator reference
+     */
+    public BundleContext getBundleContext() { return m_bundleContext; }
+
+	// End field accessors
+
+	/**
+	 * Constructor of a ComponentManagerFactory from a component metadata.
+	 * This contructor is use when the iPOJO Activator is used.
+	 * @param cm : Component Metadata for the component factory
+	 */
+	protected ComponentManagerFactory(Activator activator, Element cm) {
+		m_bundleContext = activator.getBundleContext();
+		createComponentManager(cm);
+	}
+
+	/**
+	 * Create a component manager factory and create a component manager with the given medatada.
+	 * @param bc : bundle context
+	 * @param cm : metadata of the component to create
+	 */
+	public ComponentManagerFactory(BundleContext bc, Element cm) {
+		m_bundleContext = bc;
+		createComponentManager(cm);
+	}
+
+	/**
+	 * Create a component manager factory, no component manager are created.
+	 * @param bc
+	 */
+	public ComponentManagerFactory(BundleContext bc) {
+		m_bundleContext = bc;
+	}
+
+	/**
+	 * Create a component manager form the component metadata.
+	 * @param cm : Component Metadata
+	 * @return a component manager configured with the metadata
+	 */
+	public ComponentManager createComponentManager(Element cm) {
+		ComponentManager component = new ComponentManager(this);
+		component.configure(cm);
+		addComponent(component);
+		return component;
+	}
+
+	// Factory lifecycle management
+
+	/**
+	 * Stop all the component managers.
+	 */
+	public void stop() {
+		Activator.getLogger().log(Level.INFO, "[Bundle " + m_bundleContext.getBundle().getBundleId() + "] Stop the component factory");
+		for (int i = 0; i < m_componentManagers.length; i++) {
+			ComponentManager cm = m_componentManagers[i];
+			cm.stop();
+		}
+	}
+
+	/**
+	 * Start all the component managers.
+	 */
+	public void start() {
+		Activator.getLogger().log(Level.INFO, "[Bundle " + m_bundleContext.getBundle().getBundleId() + "] Start the component factory");
+		for (int i = 0; i < m_componentManagers.length; i++) {
+			ComponentManager cm = m_componentManagers[i];
+			cm.start();
+		}
+	}
+
+}

Propchange: incubator/felix/trunk/org.apache.felix.ipojo/src/main/java/org/apache/felix/ipojo/ComponentManagerFactory.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/felix/trunk/org.apache.felix.ipojo/src/main/java/org/apache/felix/ipojo/ComponentMetadata.java
URL: http://svn.apache.org/viewvc/incubator/felix/trunk/org.apache.felix.ipojo/src/main/java/org/apache/felix/ipojo/ComponentMetadata.java?rev=414287&view=auto
==============================================================================
--- incubator/felix/trunk/org.apache.felix.ipojo/src/main/java/org/apache/felix/ipojo/ComponentMetadata.java (added)
+++ incubator/felix/trunk/org.apache.felix.ipojo/src/main/java/org/apache/felix/ipojo/ComponentMetadata.java Wed Jun 14 08:22:03 2006
@@ -0,0 +1,73 @@
+/*
+ *   Copyright 2006 The Apache Software Foundation
+ *
+ *   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.apache.felix.ipojo;
+
+import java.util.logging.Level;
+
+import org.apache.felix.ipojo.metadata.Element;
+
+/**
+ * Component Metadata.
+ * @author Clement Escoffier
+ */
+public class ComponentMetadata {
+
+	/**
+	 * Class name of the component.
+	 */
+	private String m_className;
+
+	/**
+	 * Is the component an immediate component ?
+	 */
+	private boolean m_isImmediate = false;
+
+    /**
+	 * Metadata of the component.
+	 */
+	private Element m_metadata;
+
+	/**
+     * Constructor.
+	 * @param metadata : metadata of the component
+	 */
+	public ComponentMetadata(Element metadata) {
+		m_metadata = metadata;
+		m_className = metadata.getAttribute("className");
+		if (m_className == null) {
+			Activator.getLogger().log(Level.SEVERE, "The class name of ths component cannot be setted, it does not exist in the metadata");
+		}
+		if (metadata.containsAttribute("immediate") && metadata.getAttribute("immediate").equals("true")) { m_isImmediate = true; }
+	}
+
+	// Getter
+	/**
+	 * @return the class name
+	 */
+	public String getClassName() { return m_className; }
+
+	/**
+	 * @return the component metadata
+	 */
+	public Element getMetadata() { return m_metadata; }
+
+	/**
+	 * @return true if its an immediate component
+	 */
+	public boolean isImmediate() { return m_isImmediate; }
+
+}

Propchange: incubator/felix/trunk/org.apache.felix.ipojo/src/main/java/org/apache/felix/ipojo/ComponentMetadata.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/felix/trunk/org.apache.felix.ipojo/src/main/java/org/apache/felix/ipojo/DummyActivator.java
URL: http://svn.apache.org/viewvc/incubator/felix/trunk/org.apache.felix.ipojo/src/main/java/org/apache/felix/ipojo/DummyActivator.java?rev=414287&view=auto
==============================================================================
--- incubator/felix/trunk/org.apache.felix.ipojo/src/main/java/org/apache/felix/ipojo/DummyActivator.java (added)
+++ incubator/felix/trunk/org.apache.felix.ipojo/src/main/java/org/apache/felix/ipojo/DummyActivator.java Wed Jun 14 08:22:03 2006
@@ -0,0 +1,43 @@
+/*
+ *   Copyright 2006 The Apache Software Foundation
+ *
+ *   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.apache.felix.ipojo;
+
+import org.osgi.framework.BundleActivator;
+import org.osgi.framework.BundleContext;
+
+/**
+ * This class is just if you start ipojo. It does nothing but avoid the launch of the Activator class on the iPOJO bundle
+ * @author escoffie
+ *
+ */
+public class DummyActivator implements BundleActivator {
+
+	/**
+	 * @see org.osgi.framework.BundleActivator#start(org.osgi.framework.BundleContext)
+	 */
+	public void start(BundleContext arg0) throws Exception {
+		System.out.println("iPOJO Started");
+	}
+
+	/**
+	 * @see org.osgi.framework.BundleActivator#stop(org.osgi.framework.BundleContext)
+	 */
+	public void stop(BundleContext arg0) throws Exception {
+		System.out.println("iPOJO Stopped");
+	}
+
+}

Propchange: incubator/felix/trunk/org.apache.felix.ipojo/src/main/java/org/apache/felix/ipojo/DummyActivator.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/felix/trunk/org.apache.felix.ipojo/src/main/java/org/apache/felix/ipojo/Handler.java
URL: http://svn.apache.org/viewvc/incubator/felix/trunk/org.apache.felix.ipojo/src/main/java/org/apache/felix/ipojo/Handler.java?rev=414287&view=auto
==============================================================================
--- incubator/felix/trunk/org.apache.felix.ipojo/src/main/java/org/apache/felix/ipojo/Handler.java (added)
+++ incubator/felix/trunk/org.apache.felix.ipojo/src/main/java/org/apache/felix/ipojo/Handler.java Wed Jun 14 08:22:03 2006
@@ -0,0 +1,72 @@
+/*
+ *   Copyright 2006 The Apache Software Foundation
+ *
+ *   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.apache.felix.ipojo;
+
+import org.apache.felix.ipojo.metadata.Element;
+
+/**
+ * Handler Interface.
+ * An handler need implements tese method to be notifed of lifecycle change, getfield operation and putfield operation
+ * @author Clement Escoffier
+ */
+public interface Handler {
+
+	/**
+	 * Configure the handler.
+	 * @param cm : the component manager
+	 * @param metadata : the metadata of the component
+	 */
+	void configure(ComponentManager cm, Element metadata);
+
+	/**
+	 * Stop the handler : stop the management.
+	 */
+	void stop();
+
+	/**
+	 * Start the handler : start the management.
+	 */
+	void start();
+
+	/**
+	 * This method is called when a PUTFIELD operation is detected.
+	 * @param fieldName : the field name
+	 * @param value : the value passed to the field
+	 */
+	void setterCallback(String fieldName, Object value);
+
+	/**
+	 * This method is called when a GETFIELD operation is detected.
+	 * @param fieldName : the field name
+	 * @param value : the value passed to the field (by the previous handler)
+	 * @return : the managed value of the field
+	 */
+	Object getterCallback(String fieldName, Object value);
+
+	/**
+	 * Is the actual state valid for this handler ?
+	 * @return true is the state seems valid for the handler
+	 */
+	boolean isValid();
+
+	/**
+	 * This method is called when the component state changed.
+	 * @param state : the new state
+	 */
+	void stateChanged(int state);
+
+}

Propchange: incubator/felix/trunk/org.apache.felix.ipojo/src/main/java/org/apache/felix/ipojo/Handler.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/felix/trunk/org.apache.felix.ipojo/src/main/java/org/apache/felix/ipojo/IPojoConfiguration.java
URL: http://svn.apache.org/viewvc/incubator/felix/trunk/org.apache.felix.ipojo/src/main/java/org/apache/felix/ipojo/IPojoConfiguration.java?rev=414287&view=auto
==============================================================================
--- incubator/felix/trunk/org.apache.felix.ipojo/src/main/java/org/apache/felix/ipojo/IPojoConfiguration.java (added)
+++ incubator/felix/trunk/org.apache.felix.ipojo/src/main/java/org/apache/felix/ipojo/IPojoConfiguration.java Wed Jun 14 08:22:03 2006
@@ -0,0 +1,51 @@
+/*
+ *   Copyright 2006 The Apache Software Foundation
+ *
+ *   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.apache.felix.ipojo;
+
+import java.util.logging.Level;
+
+import org.apache.felix.ipojo.handlers.architecture.ArchitectureHandler;
+import org.apache.felix.ipojo.handlers.configuration.ConfigurationHandler;
+import org.apache.felix.ipojo.handlers.dependency.DependencyHandler;
+import org.apache.felix.ipojo.handlers.lifecycle.callback.LifecycleCallbackHandler;
+import org.apache.felix.ipojo.handlers.providedService.ProvidedServiceHandler;
+
+/**
+ * Activator Basic Configuration.
+ * - Log Level
+ * - Available handlers
+ * @author Clement Escoffier
+ */
+public class IPojoConfiguration {
+
+	/**
+	 * iPOJO logger log level.
+	 */
+	public static final Level LOG_LEVEL = Level.WARNING;
+
+	/**
+	 * Available handlers in the iPOJO bundle.
+	 */
+	public static final Class[] INTERNAL_HANDLERS = new Class[] {
+		DependencyHandler.class,
+		ProvidedServiceHandler.class,
+		LifecycleCallbackHandler.class,
+		ConfigurationHandler.class,
+		ArchitectureHandler.class
+	};
+
+}

Propchange: incubator/felix/trunk/org.apache.felix.ipojo/src/main/java/org/apache/felix/ipojo/IPojoConfiguration.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/felix/trunk/org.apache.felix.ipojo/src/main/java/org/apache/felix/ipojo/Nullable.java
URL: http://svn.apache.org/viewvc/incubator/felix/trunk/org.apache.felix.ipojo/src/main/java/org/apache/felix/ipojo/Nullable.java?rev=414287&view=auto
==============================================================================
--- incubator/felix/trunk/org.apache.felix.ipojo/src/main/java/org/apache/felix/ipojo/Nullable.java (added)
+++ incubator/felix/trunk/org.apache.felix.ipojo/src/main/java/org/apache/felix/ipojo/Nullable.java Wed Jun 14 08:22:03 2006
@@ -0,0 +1,25 @@
+/*
+ *   Copyright 2006 The Apache Software Foundation
+ *
+ *   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.apache.felix.ipojo;
+
+/**
+ * A nullable object must implement this interface.
+ * @author Clement Escoffier
+ */
+public interface Nullable {
+    // Nothing
+}

Propchange: incubator/felix/trunk/org.apache.felix.ipojo/src/main/java/org/apache/felix/ipojo/Nullable.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/felix/trunk/org.apache.felix.ipojo/src/main/java/org/apache/felix/ipojo/architecture/Architecture.java
URL: http://svn.apache.org/viewvc/incubator/felix/trunk/org.apache.felix.ipojo/src/main/java/org/apache/felix/ipojo/architecture/Architecture.java?rev=414287&view=auto
==============================================================================
--- incubator/felix/trunk/org.apache.felix.ipojo/src/main/java/org/apache/felix/ipojo/architecture/Architecture.java (added)
+++ incubator/felix/trunk/org.apache.felix.ipojo/src/main/java/org/apache/felix/ipojo/architecture/Architecture.java Wed Jun 14 08:22:03 2006
@@ -0,0 +1,32 @@
+/*
+ *   Copyright 2006 The Apache Software Foundation
+ *
+ *   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.apache.felix.ipojo.architecture;
+
+/**
+ * Architecture service.
+ * Allows to have information of the service delivery about GenSD component.
+ * @author Clement Escoffier
+ */
+public interface Architecture {
+
+    /**
+     * Return the full architecture.
+     * @return : the current component description
+     */
+    ComponentDescription getComponentDescription();
+
+}

Propchange: incubator/felix/trunk/org.apache.felix.ipojo/src/main/java/org/apache/felix/ipojo/architecture/Architecture.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/felix/trunk/org.apache.felix.ipojo/src/main/java/org/apache/felix/ipojo/architecture/ComponentDescription.java
URL: http://svn.apache.org/viewvc/incubator/felix/trunk/org.apache.felix.ipojo/src/main/java/org/apache/felix/ipojo/architecture/ComponentDescription.java?rev=414287&view=auto
==============================================================================
--- incubator/felix/trunk/org.apache.felix.ipojo/src/main/java/org/apache/felix/ipojo/architecture/ComponentDescription.java (added)
+++ incubator/felix/trunk/org.apache.felix.ipojo/src/main/java/org/apache/felix/ipojo/architecture/ComponentDescription.java Wed Jun 14 08:22:03 2006
@@ -0,0 +1,150 @@
+/*
+ *   Copyright 2006 The Apache Software Foundation
+ *
+ *   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.apache.felix.ipojo.architecture;
+
+import java.util.HashMap;
+
+
+/**
+ * Component Description.
+ * @author Clement Escoffier
+ */
+public class ComponentDescription {
+
+    /**
+     * The Component class name.
+     * This String is the identifier of the component.
+     */
+    private String m_className;
+
+    /**
+     * List of provided service.
+     */
+    private ProvidedServiceDescription[] m_provideServices = new ProvidedServiceDescription[0];
+
+    /**
+     * List of dependencies.
+     */
+    private DependencyDescription[] m_dependencies = new DependencyDescription[0];
+
+    /**
+     * Hashmap [Instance reference, service reference] of the used service.
+     */
+    private HashMap m_usedServices = new HashMap();
+
+    /**
+     * Created Instances of the components.
+     */
+    private String[] m_instances = new String[0];
+
+    /**
+     * State of the component (VALID / UNRESOLVED).
+     */
+    private int m_state;
+
+    /**
+     * Constructor.
+     * @param name : the name of the component (the class name).
+     * @param state : the state of the component.
+     */
+    public ComponentDescription(String name, int state) {
+        m_className = name;
+        m_state = state;
+        m_usedServices.clear();
+        m_instances = new String[0];
+    }
+
+    /**
+     * @return the created instances
+     */
+    public String[] getInstances() { return m_instances; }
+
+    /**
+     * Set the instances array.
+     */
+    public void setInstances(String[] instances) { m_instances = instances; }
+
+    /**
+     * @return : the class name of the component
+     */
+    public String getClassName() { return m_className; }
+
+    /**
+     * @return the live dependency list
+     */
+    public DependencyDescription[] getDependencies() { return m_dependencies; }
+
+    /**
+     * @return the live provided service list
+     */
+    public ProvidedServiceDescription[] getProvideServices() { return m_provideServices; }
+
+    /**
+     * Add a dependency.
+     * @param dep : the dependency to add
+     */
+    public void addDependency(DependencyDescription dep) {
+        // Verify that the dependency description is not already in the array.
+        for (int i = 0; (i < m_dependencies.length); i++) {
+            if (m_dependencies[i] == dep) {
+                return; //NOTHING TO DO, the description is already in the array
+            }
+        }
+            // The component Description is not in the array, add it
+            DependencyDescription[] newDep = new DependencyDescription[m_dependencies.length + 1];
+            System.arraycopy(m_dependencies, 0, newDep, 0, m_dependencies.length);
+            newDep[m_dependencies.length] = dep;
+            m_dependencies = newDep;
+    }
+
+    /**
+     * Add a provided service.
+     * @param pds : the provided service to add
+     */
+    public void addProvidedService(ProvidedServiceDescription pds) {
+        //Verify that the provided service description is not already in the array.
+        for (int i = 0; (i < m_provideServices.length); i++) {
+            if (m_provideServices[i] == pds) {
+                return; //NOTHING DO DO, the description is already in the array
+            }
+        }
+
+            // The component Description is not in the array, add it
+            ProvidedServiceDescription[] newPSD = new ProvidedServiceDescription[m_provideServices.length + 1];
+            System.arraycopy(m_provideServices, 0, newPSD, 0, m_provideServices.length);
+            newPSD[m_provideServices.length] = pds;
+            m_provideServices = newPSD;
+
+    }
+
+    /**
+     * Set the state of the component.
+     * @param i : the state
+     */
+    public void setState(int i) {
+        m_state = i;
+    }
+
+    /**
+     * @return the state of the component.
+     */
+    public int getState() {
+        return m_state;
+    }
+
+
+}

Propchange: incubator/felix/trunk/org.apache.felix.ipojo/src/main/java/org/apache/felix/ipojo/architecture/ComponentDescription.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/felix/trunk/org.apache.felix.ipojo/src/main/java/org/apache/felix/ipojo/architecture/DependencyDescription.java
URL: http://svn.apache.org/viewvc/incubator/felix/trunk/org.apache.felix.ipojo/src/main/java/org/apache/felix/ipojo/architecture/DependencyDescription.java?rev=414287&view=auto
==============================================================================
--- incubator/felix/trunk/org.apache.felix.ipojo/src/main/java/org/apache/felix/ipojo/architecture/DependencyDescription.java (added)
+++ incubator/felix/trunk/org.apache.felix.ipojo/src/main/java/org/apache/felix/ipojo/architecture/DependencyDescription.java Wed Jun 14 08:22:03 2006
@@ -0,0 +1,169 @@
+/*
+ *   Copyright 2006 The Apache Software Foundation
+ *
+ *   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.apache.felix.ipojo.architecture;
+
+import java.util.HashMap;
+
+import org.osgi.framework.ServiceReference;
+
+/**
+ * Dependency Description.
+ * @author Clement Escoffier
+ */
+public class DependencyDescription {
+
+    /**
+     * Needed Service Interface.
+     */
+    private String m_interface;
+
+    /**
+     * Multiple ?
+     */
+    private boolean m_multiple;
+
+    /**
+     * Optional ?
+     */
+    private boolean m_optional;
+
+    /**
+     * State (VALID | INVALID).
+     */
+    private int m_state;
+
+    /**
+     * Filter.
+     */
+    private String m_filter;
+    /**
+     * Hashmap [Instance reference, service reference] of the used service.
+     */
+    private HashMap m_usedServices = new HashMap();
+
+
+    /**
+     * The list of service reference.
+     */
+    private ServiceReference[] m_serviceReferences;
+
+    /**
+     * Parent of the dependency either de ProvidedServiceDescription or a ComponentDescription.
+     */
+    private Object m_parent;
+
+
+    /**
+     * @return true if the dependency is a multiple dependency.
+     */
+    public boolean isMultiple() {
+        return m_multiple;
+    }
+
+    /**
+     * @return true if the dependency is an optional dependency.
+     */
+    public boolean isOptional() {
+        return m_optional;
+    }
+
+    /**
+     * @return the filter.
+     */
+    public String getFilter() {
+        return m_filter;
+    }
+
+    /**
+     * @return the needed interface.
+     */
+    public String getInterface() {
+        return m_interface;
+    }
+
+    /**
+     * @return the state of the dependency.
+     */
+    public int getState() {
+        return m_state;
+    }
+
+    /**
+     * Constructor.
+     * @param itf : the needed itf
+     * @param multiple : is the dependency a multiple dependency ?
+     * @param optional : is the depdendency optional ?
+     * @param filter : the filter
+     * @param state : the state
+     * @param parent : the description of the parent (either a ProvidedServiceDescription, either a ComponentDescription)
+     */
+    public DependencyDescription(String itf, boolean multiple, boolean optional, String filter, int state, Object parent) {
+        super();
+        m_interface = itf;
+        m_multiple = multiple;
+        m_optional = optional;
+        m_filter = filter;
+        m_state = state;
+        m_serviceReferences = new ServiceReference[0];
+        m_parent = parent;
+    }
+
+    /**
+     * @return the array of service reference (only if the cardinality could be n).
+     */
+    public ServiceReference[] getServiceReferences() {
+        return m_serviceReferences;
+    }
+
+    /**
+     * @return the ServiceReference (only if the cardinality could be 1).
+     */
+    public ServiceReference getServiceReference() {
+        return m_serviceReferences[0];
+    }
+
+    /**
+     * Set the service reference array.
+     * @param sr : the array of service reference
+     */
+    public void setServiceReferences(ServiceReference[] sr) {
+        m_serviceReferences = sr;
+    }
+
+    /**
+     * @return the parent of the dependency
+     */
+    public Object getParent() {
+        return m_parent;
+    }
+
+    /**
+     * @return the hashmap [object reference, service reference] containing the used services
+     */
+    public HashMap getUsedServices() { return m_usedServices; }
+
+    /**
+     * Set the usedServices.
+     * @param hm : the new usedService
+     */
+    public void setUsedServices(HashMap hm) {
+    	m_usedServices = hm;
+    }
+
+
+
+}

Propchange: incubator/felix/trunk/org.apache.felix.ipojo/src/main/java/org/apache/felix/ipojo/architecture/DependencyDescription.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/felix/trunk/org.apache.felix.ipojo/src/main/java/org/apache/felix/ipojo/architecture/ProvidedServiceDescription.java
URL: http://svn.apache.org/viewvc/incubator/felix/trunk/org.apache.felix.ipojo/src/main/java/org/apache/felix/ipojo/architecture/ProvidedServiceDescription.java?rev=414287&view=auto
==============================================================================
--- incubator/felix/trunk/org.apache.felix.ipojo/src/main/java/org/apache/felix/ipojo/architecture/ProvidedServiceDescription.java (added)
+++ incubator/felix/trunk/org.apache.felix.ipojo/src/main/java/org/apache/felix/ipojo/architecture/ProvidedServiceDescription.java Wed Jun 14 08:22:03 2006
@@ -0,0 +1,153 @@
+/*
+ *   Copyright 2006 The Apache Software Foundation
+ *
+ *   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.apache.felix.ipojo.architecture;
+
+import java.util.Properties;
+
+import org.osgi.framework.ServiceReference;
+
+/**
+ * Provided Service Description.
+ * @author Clement Escoffier
+ */
+public class ProvidedServiceDescription {
+
+    /**
+     * Provided Service Specification.
+     */
+    private String[] m_serviceSpecification;
+
+    /**
+     * Dependency of the service.
+     */
+    private DependencyDescription[] m_dependencies = new DependencyDescription[0];
+
+
+    /**
+     * State.
+     */
+    private int m_state;
+
+    /**
+     * The service reference.
+     */
+    private ServiceReference m_serviceReference;
+
+
+    /**
+     * Handler on the component description who contains this description.
+     */
+    private ComponentDescription m_parent;
+
+    /**
+     * Properties of the provided service.
+     */
+    private Properties m_properties = new Properties();
+
+
+    /**
+     * Constructor.
+     * @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, ComponentDescription parent) {
+        m_serviceSpecification = serviceSpecification;
+        m_state = state;
+        m_serviceReference = sr;
+        m_parent = parent;
+    }
+
+    /**
+     * @return the provided contract name.
+     */
+    public String[] getServiceSpecification() {
+        return m_serviceSpecification;
+    }
+
+    /**
+     * Add a dependency descriptino to this provided service description.
+     * @param dep : the dependency description to add
+     */
+    public void addDependency(DependencyDescription dep) {
+        // Verify that the dependency description is not already in the array.
+        for (int i = 0; (i < m_dependencies.length); i++) {
+            if (m_dependencies[i] == dep) {
+                return; //NOTHING DO DO, the description is already in the array
+            }
+        }
+            // The component Description is not in the array, add it
+            DependencyDescription[] newDep = new DependencyDescription[m_dependencies.length + 1];
+            System.arraycopy(m_dependencies, 0, newDep, 0, m_dependencies.length);
+            newDep[m_dependencies.length] = dep;
+            m_dependencies = newDep;
+    }
+
+    /**
+     * Add a property to the current provided service description.
+     * @param key : the key of the property
+     * @param value : the value of the property
+     */
+    public void addProperty(String key, String value) {
+        m_properties.put(key, value);
+    }
+
+    /**
+     * Set the set of properties. This function create a clone of the argument.
+     * @param props : the properties
+     */
+    public void setProperty(Properties props) {
+        m_properties = (Properties)props.clone();
+    }
+
+    /**
+     * @return the dependeny description list.
+     */
+    public DependencyDescription[] getDependencies() {
+        return m_dependencies;
+    }
+
+    /**
+     * @return the properties.
+     */
+    public Properties getProperties() {
+        return m_properties;
+    }
+
+    /**
+     * @return the state of the provided service (UNREGISTRED | REGISTRED).
+     */
+    public int getState() {
+        return m_state;
+    }
+
+    /**
+     * @return the service reference (null if the service is unregistred).
+     */
+    public ServiceReference getServiceReference() {
+        return m_serviceReference;
+    }
+
+    /**
+     * @return the parent description.
+     */
+    public ComponentDescription getComponentDescription() {
+        return m_parent;
+    }
+
+}

Propchange: incubator/felix/trunk/org.apache.felix.ipojo/src/main/java/org/apache/felix/ipojo/architecture/ProvidedServiceDescription.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/felix/trunk/org.apache.felix.ipojo/src/main/java/org/apache/felix/ipojo/architecture/State.java
URL: http://svn.apache.org/viewvc/incubator/felix/trunk/org.apache.felix.ipojo/src/main/java/org/apache/felix/ipojo/architecture/State.java?rev=414287&view=auto
==============================================================================
--- incubator/felix/trunk/org.apache.felix.ipojo/src/main/java/org/apache/felix/ipojo/architecture/State.java (added)
+++ incubator/felix/trunk/org.apache.felix.ipojo/src/main/java/org/apache/felix/ipojo/architecture/State.java Wed Jun 14 08:22:03 2006
@@ -0,0 +1,77 @@
+/*
+ *   Copyright 2006 The Apache Software Foundation
+ *
+ *   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.apache.felix.ipojo.architecture;
+
+/**
+ * @author Clement Escoffier
+ *
+ */
+public class State {
+
+    /**
+     * Return the String corresponding to a component state.
+     * @param state : the state in int
+     * @return : the string of the state (Stopped, Unresolved, Resolved) or "Unknow" if state is not revelant
+     */
+    public static String printComponentState(int state) {
+        switch(state) {
+        case(0) :
+            return "STOPPED";
+        case(1) :
+            return "INVALID";
+        case(2) :
+            return  "VALID";
+        default :
+            return "UNKNOW";
+        }
+    }
+
+    /**
+     * Return the String corresponding to a dependency state.
+     * @param state : the state in int
+     * @return : the string of the state (Stopped, Valid, Invalid) or "Unknow" if state is not revelant
+     */
+    public static String printDependencyState(int state) {
+        switch(state) {
+        case(0) :
+            return "STOPPED";
+        case(1) :
+            return "RESOLVED";
+        case(2) :
+            return  "UNRESOLVED";
+        default :
+            return "UNKNOW";
+        }
+    }
+
+    /**
+     * Return the String corresponding to a provided service state.
+     * @param state : the state in int
+     * @return : the string of the state (Unregistred, Registredu) or "Unknow" if state is not revelant
+     */
+    public static String printProvidedServiceState(int state) {
+        switch(state) {
+        case(0) :
+            return "UNREGISTRED";
+        case(1) :
+            return "REGISTRED";
+        default :
+            return "UNKNOW";
+        }
+    }
+
+}

Propchange: incubator/felix/trunk/org.apache.felix.ipojo/src/main/java/org/apache/felix/ipojo/architecture/State.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/felix/trunk/org.apache.felix.ipojo/src/main/java/org/apache/felix/ipojo/handlers/architecture/ArchitectureHandler.java
URL: http://svn.apache.org/viewvc/incubator/felix/trunk/org.apache.felix.ipojo/src/main/java/org/apache/felix/ipojo/handlers/architecture/ArchitectureHandler.java?rev=414287&view=auto
==============================================================================
--- incubator/felix/trunk/org.apache.felix.ipojo/src/main/java/org/apache/felix/ipojo/handlers/architecture/ArchitectureHandler.java (added)
+++ incubator/felix/trunk/org.apache.felix.ipojo/src/main/java/org/apache/felix/ipojo/handlers/architecture/ArchitectureHandler.java Wed Jun 14 08:22:03 2006
@@ -0,0 +1,177 @@
+/*
+ *   Copyright 2006 The Apache Software Foundation
+ *
+ *   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.apache.felix.ipojo.handlers.architecture;
+
+import java.util.Dictionary;
+import java.util.Properties;
+
+import org.apache.felix.ipojo.ComponentManager;
+import org.apache.felix.ipojo.Handler;
+import org.apache.felix.ipojo.architecture.Architecture;
+import org.apache.felix.ipojo.architecture.ComponentDescription;
+import org.apache.felix.ipojo.architecture.DependencyDescription;
+import org.apache.felix.ipojo.architecture.ProvidedServiceDescription;
+import org.apache.felix.ipojo.handlers.dependency.Dependency;
+import org.apache.felix.ipojo.handlers.dependency.DependencyHandler;
+import org.apache.felix.ipojo.handlers.dependency.DependencyMetadata;
+import org.apache.felix.ipojo.handlers.providedService.Property;
+import org.apache.felix.ipojo.handlers.providedService.PropertyMetadata;
+import org.apache.felix.ipojo.handlers.providedService.ProvidedService;
+import org.apache.felix.ipojo.handlers.providedService.ProvidedServiceHandler;
+import org.apache.felix.ipojo.handlers.providedService.ProvidedServiceMetadata;
+import org.apache.felix.ipojo.metadata.Element;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.Constants;
+import org.osgi.framework.ServiceRegistration;
+
+/**
+ * Achtiecture Handler : do reflection on your component.
+ * @author Clement Escoffier
+ */
+public class ArchitectureHandler implements Handler, Architecture {
+
+	/**
+	 * Component Manager.
+	 */
+	private ComponentManager m_manager;
+
+    /**
+     * Service Registration of the Architecture service provided by this handler.
+     */
+    private ServiceRegistration m_sr;
+
+    /**
+     * Unique name of the component : either the name of the component, either the classname if the name if not setted.
+     */
+    private String m_name;
+
+	/**
+	 * @see org.apache.felix.ipojo.Handler#configure(org.apache.felix.ipojo.ComponentManager, org.apache.felix.ipojo.metadata.Element)
+	 */
+	public void configure(ComponentManager cm, Element metadata) {
+		if (metadata.containsAttribute("architecture")) {
+			String isArchitectureEnabled = (metadata.getAttribute("architecture")).toLowerCase();
+			if (isArchitectureEnabled.equals("true")) { cm.register(this); }
+		}
+
+		if (metadata.containsAttribute("name")) { m_name = metadata.getAttribute("name"); }
+		else { m_name = metadata.getAttribute("className"); }
+
+		m_manager = cm;
+	}
+
+	/**
+	 * @see org.apache.felix.ipojo.Handler#stop()
+	 */
+	public void stop() {
+        try {
+            if (m_sr != null) { m_sr.unregister(); }
+        } catch (Exception e) { return; }
+	}
+
+	/**
+	 * @see org.apache.felix.ipojo.Handler#start()
+	 */
+	public void start() {
+		// Unregister the service if already registred
+		if (m_sr != null) { m_sr.unregister(); }
+
+		// Register the ManagedService
+		BundleContext bc = m_manager.getContext();
+		Dictionary properties = new Properties();
+		properties.put("Component Implementation Class", m_manager.getComponentMetatada().getClassName());
+		properties.put(Constants.SERVICE_PID, m_name);
+
+		m_sr = bc.registerService(Architecture.class.getName(), this, properties);
+
+	}
+
+	/**
+	 * @see org.apache.felix.ipojo.Handler#setterCallback(java.lang.String, java.lang.Object)
+	 */
+	public void setterCallback(String fieldName, Object value) { // Nothing to do
+	}
+
+	/**
+	 * @see org.apache.felix.ipojo.Handler#getterCallback(java.lang.String, java.lang.Object)
+	 */
+	public Object getterCallback(String fieldName, Object value) { return value; }
+
+	/**
+	 * @see org.apache.felix.ipojo.Handler#isValid()
+	 */
+	public boolean isValid() { return true; }
+
+	/**
+	 * @see org.apache.felix.ipojo.Handler#stateChanged(int)
+	 */
+	public void stateChanged(int state) {
+		// Nothing to do
+	}
+
+	/**
+	 * @see org.apache.felix.ipojo.architecture.Architecture#getComponentDescription()
+	 */
+	public ComponentDescription getComponentDescription() {
+		int componentState = m_manager.getState();
+		ComponentDescription componentDescription = new ComponentDescription(m_name, componentState);
+
+		String[] instances = new String[m_manager.getInstances().length];
+		for (int i = 0; i < m_manager.getInstances().length; i++) {
+			instances[i] = m_manager.getInstances()[i].toString();
+		}
+		componentDescription.setInstances(instances);
+
+		Handler[] handlers = m_manager.getRegistredHandlers();
+		for (int i = 0; i < handlers.length; i++) {
+			if (handlers[i] instanceof DependencyHandler) {
+				DependencyHandler dh = (DependencyHandler)handlers[i];
+				for (int j = 0; j < dh.getDependencies().length; j++) {
+					Dependency dep = dh.getDependencies()[j];
+					DependencyMetadata dm = dep.getMetadata();
+
+					// Create & add the dependency description
+					DependencyDescription dd = new DependencyDescription(dm.getServiceSpecification(), dm.isMultiple(), dm.isOptional(), dm.getFilter(), dep.getState(), componentDescription);
+					dd.setUsedServices(dep.getUsedServices());
+					componentDescription.addDependency(dd);
+				}
+			}
+			if (handlers[i] instanceof ProvidedServiceHandler) {
+				ProvidedServiceHandler psh = (ProvidedServiceHandler)handlers[i];
+				for (int j = 0; j < psh.getProvidedService().length; j++) {
+					ProvidedService ps = psh.getProvidedService()[j];
+					ProvidedServiceMetadata psm = ps.getMetadata();
+					ProvidedServiceDescription psd = new ProvidedServiceDescription(psm.getServiceSpecification(), ps.getState(), ps.getServiceReference(), componentDescription);
+
+					Properties props = new Properties();
+					for (int k = 0; k < ps.getProperties().length; k++) {
+						Property prop = ps.getProperties()[k];
+						PropertyMetadata pm = prop.getMetadata();
+						if (prop.getValue() != null) {
+							props.put(pm.getName(), prop.getValue().toString());
+						}
+					}
+					psd.setProperty(props);
+					componentDescription.addProvidedService(psd);
+				}
+			}
+
+		}
+		return componentDescription;
+	}
+
+}

Propchange: incubator/felix/trunk/org.apache.felix.ipojo/src/main/java/org/apache/felix/ipojo/handlers/architecture/ArchitectureHandler.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/felix/trunk/org.apache.felix.ipojo/src/main/java/org/apache/felix/ipojo/handlers/configuration/ConfigurableProperty.java
URL: http://svn.apache.org/viewvc/incubator/felix/trunk/org.apache.felix.ipojo/src/main/java/org/apache/felix/ipojo/handlers/configuration/ConfigurableProperty.java?rev=414287&view=auto
==============================================================================
--- incubator/felix/trunk/org.apache.felix.ipojo/src/main/java/org/apache/felix/ipojo/handlers/configuration/ConfigurableProperty.java (added)
+++ incubator/felix/trunk/org.apache.felix.ipojo/src/main/java/org/apache/felix/ipojo/handlers/configuration/ConfigurableProperty.java Wed Jun 14 08:22:03 2006
@@ -0,0 +1,157 @@
+/*
+ *   Copyright 2006 The Apache Software Foundation
+ *
+ *   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.apache.felix.ipojo.handlers.configuration;
+
+import java.lang.reflect.Constructor;
+import java.lang.reflect.InvocationTargetException;
+import java.util.logging.Level;
+
+import org.apache.felix.ipojo.Activator;
+import org.apache.felix.ipojo.metadata.Element;
+
+/**
+ * @author Clement Escoffier
+ * Configurable Property
+ */
+public class ConfigurableProperty {
+
+	/**
+	 * Name of the property (filed name if not set).
+	 */
+	private String m_name;
+
+	/**
+	 * Field of the property.
+	 */
+	private String m_field;
+
+	/**
+	 * Value of the property.
+	 */
+	private Object m_value;
+
+	/**
+	 * Configuration Handler managing this property.
+	 */
+	private ConfigurationHandler m_handler;
+
+	/**
+	 * Configurable Property Constructor.
+	 * @param name : name of the property (optional)
+	 * @param field : name of the field (mandatory)
+	 * @param value : initial value of the property (optional)
+	 * @param ch : configuration handler managing this configurable property
+	 */
+	public ConfigurableProperty(String name, String field, String value, ConfigurationHandler ch) {
+		m_handler = ch;
+		if (name != null) { m_name = name; }
+		else { m_name = field; }
+		m_field = field;
+
+		if (value != null) { setValue(m_field, value); }
+
+	}
+
+	/**
+     * Set the value of the property.
+     * @param strValue : value of the property (String)
+     */
+    private void setValue(String field, String strValue) {
+    	// Look for the type of the field
+    	Element manipulation = m_handler.getComponentManager().getComponentMetatada().getMetadata().getElements("Manipulation")[0];
+    	String type = null;
+    	for (int i = 0; i < manipulation.getElements("Field").length; i++) {
+    		if (field.equals(manipulation.getElements("Field")[i].getAttribute("name"))) {
+    			type = manipulation.getElements("Field")[i].getAttribute("type");
+    			break;
+    		}
+    	}
+
+    	if (type == null) { Activator.getLogger().log(Level.SEVERE, "[" + m_handler.getComponentManager().getComponentMetatada().getClassName() + "] The field " + field + " does not exist in the implementation"); return; }
+
+    	Activator.getLogger().log(Level.INFO, "[" + m_handler.getComponentManager().getComponentMetatada().getClassName() + "] Set the value of the configurable property " + field + " [" + type + "] " + " with the value : " + strValue);
+
+    	Object value = null;
+
+        if (type.equals("string") || type.equals("String")) { value = new String(strValue); }
+        if (type.equals("boolean")) { value = new Boolean(strValue); }
+        if (type.equals("byte")) { value = new Byte(strValue); }
+        if (type.equals("short")) { value = new Short(strValue); }
+        if (type.equals("int")) { value = new Integer(strValue); }
+        if (type.equals("long")) { value = new Long(strValue); }
+        if (type.equals("float")) { value = new Float(strValue); }
+        if (type.equals("double")) { value = new Double(strValue); }
+
+        if (value == null) {
+        	// Else it is a neither a primitive type neither a String -> create the object by calling a constructor with a string in argument.
+        	try {
+        		Class c = m_handler.getComponentManager().getContext().getBundle().loadClass(type);
+        		Constructor cst = c.getConstructor(new Class[] {String.class});
+        		value = cst.newInstance(new Object[] {strValue});
+        	} catch (ClassNotFoundException e) {
+        		System.err.println("Class not found exception in setValue on " + type);
+        		e.printStackTrace();
+        		return;
+        	} catch (SecurityException e) {
+        		e.printStackTrace();
+        		return;
+        	} catch (NoSuchMethodException e) {
+        		System.err.println("Constructor not found exeption in setValue on " + type);
+        		e.printStackTrace();
+        		return;
+        	} catch (IllegalArgumentException e) {
+        		System.err.println("Argument problem to call the constructor of the type " + type);
+        		e.printStackTrace();
+        		return;
+        	} catch (InstantiationException e) {
+        		System.err.println("Instantiation problem  " + type);
+        		e.printStackTrace();
+        		return;
+        	} catch (IllegalAccessException e) {
+        		e.printStackTrace();
+        	} catch (InvocationTargetException e) {
+        		System.err.println("Invocation problem " + type);
+        		e.printStackTrace();
+        		return;
+        	}
+        }
+
+        m_value = value;
+
+    }
+
+    /**
+     * @return the name of the property.
+     */
+    public String getName() { return m_name; }
+
+    /**
+     * @return the field of the property.
+     */
+    public String getField() { return m_field; }
+
+    /**
+     * @return the value of the property.
+     */
+    public Object getValue() { return m_value; }
+
+    /**
+     * Fix the value of the property.
+     * @param value : the new value.
+     */
+    public void setValue(Object value) { m_value = value; }
+}

Propchange: incubator/felix/trunk/org.apache.felix.ipojo/src/main/java/org/apache/felix/ipojo/handlers/configuration/ConfigurableProperty.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/felix/trunk/org.apache.felix.ipojo/src/main/java/org/apache/felix/ipojo/handlers/configuration/ConfigurationHandler.java
URL: http://svn.apache.org/viewvc/incubator/felix/trunk/org.apache.felix.ipojo/src/main/java/org/apache/felix/ipojo/handlers/configuration/ConfigurationHandler.java?rev=414287&view=auto
==============================================================================
--- incubator/felix/trunk/org.apache.felix.ipojo/src/main/java/org/apache/felix/ipojo/handlers/configuration/ConfigurationHandler.java (added)
+++ incubator/felix/trunk/org.apache.felix.ipojo/src/main/java/org/apache/felix/ipojo/handlers/configuration/ConfigurationHandler.java Wed Jun 14 08:22:03 2006
@@ -0,0 +1,231 @@
+/*
+ *   Copyright 2006 The Apache Software Foundation
+ *
+ *   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.apache.felix.ipojo.handlers.configuration;
+
+import java.util.Dictionary;
+import java.util.Enumeration;
+import java.util.Properties;
+import java.util.logging.Level;
+
+import org.apache.felix.ipojo.ComponentManager;
+import org.apache.felix.ipojo.Handler;
+import org.apache.felix.ipojo.Activator;
+import org.apache.felix.ipojo.metadata.Element;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.Constants;
+import org.osgi.framework.ServiceRegistration;
+import org.osgi.service.cm.ConfigurationException;
+import org.osgi.service.cm.ManagedService;
+
+/**
+ * Handler managing the Configuration Admin.
+ * @author Clement Escoffier
+ */
+public class ConfigurationHandler implements Handler, ManagedService {
+
+	/**
+	 * Reference on the component manager.
+	 */
+	private ComponentManager m_manager;
+
+	/**
+	 * List of the configurable fields.
+	 */
+	private ConfigurableProperty[] m_configurableProperties = new ConfigurableProperty[0];
+
+	/**
+	 * PID of the component.
+	 */
+	private String m_pid;
+
+	/**
+	 * Service registration of the ManagedService provided by this handler.
+	 */
+	private ServiceRegistration m_sr;
+
+	/**
+	 * @return component manager of this handler.
+	 */
+	protected ComponentManager getComponentManager() { return m_manager; }
+
+	/**
+	 * @see org.apache.felix.ipojo.Handler#configure(org.apache.felix.ipojo.ComponentManager, org.apache.felix.ipojo.metadata.Element)
+	 */
+	public void configure(ComponentManager cm, Element metadata) {
+		// Store the component manager
+		m_manager = cm;
+		m_configurableProperties = new ConfigurableProperty[0];
+
+		// Build the hashmap
+		Element[] configurables = metadata.getElements("ConfigurableProperty");
+
+		if (configurables.length > 0) { m_manager.register(this); }
+		else { return; }
+
+		for (int i = 0; i < configurables.length; i++) {
+			String fieldName = configurables[i].getAttribute("field");
+			String name = null;
+			if (configurables[i].containsAttribute("name")) { name = configurables[i].getAttribute("name"); }
+			else { name = fieldName; }
+			String value = null;
+			if (configurables[i].containsAttribute("value")) {
+				value = configurables[i].getAttribute("value");
+			}
+			ConfigurableProperty cp = new ConfigurableProperty(name, fieldName, value, this);
+			addProperty(cp);
+		}
+
+		// Get the PID :
+		if (metadata.containsAttribute("name")) { m_pid = metadata.getAttribute("name"); }
+		else { m_pid = metadata.getAttribute("className"); }
+	}
+
+	/**
+	 * @see org.apache.felix.ipojo.Handler#stop()
+	 */
+	public void stop() {
+		// Unregister the service
+		if (m_sr != null) {
+			Activator.getLogger().log(Level.INFO, "[" + m_manager.getComponentMetatada().getClassName() + "] Unregister Managed Service");
+			m_sr.unregister();
+			m_sr = null;
+		}
+
+	}
+
+	/**
+	 * @see org.apache.felix.ipojo.Handler#start()
+	 */
+	public void start() {
+		// Unregister the service if already registred (it should not happen )
+		if (m_sr != null) { m_sr.unregister(); }
+
+		// Register the ManagedService
+		BundleContext bc = m_manager.getContext();
+		Dictionary properties = new Properties();
+		properties.put(Constants.SERVICE_PID, m_pid);
+
+		Activator.getLogger().log(Level.INFO, "[" + m_manager.getComponentMetatada().getClassName() + "] Register Managed Service");
+		m_sr = bc.registerService(ManagedService.class.getName(), this, properties);
+	}
+
+	/**
+	 * @see org.apache.felix.ipojo.Handler#setterCallback(java.lang.String, java.lang.Object)
+	 */
+	public void setterCallback(String fieldName, Object value) {
+		// Nothing to do
+	}
+
+	/**
+	 * @see org.apache.felix.ipojo.Handler#getterCallback(java.lang.String, java.lang.Object)
+	 */
+	public Object getterCallback(String fieldName, Object value) {
+		// Check if the field is a configurable property
+		for (int i = 0; i < m_configurableProperties.length; i++) {
+			if (m_configurableProperties[i].getField().equals(fieldName)) {
+				return m_configurableProperties[i].getValue();
+			}
+		}
+		return value;
+	}
+
+	/**
+	 * @see org.apache.felix.ipojo.Handler#isValid()
+	 */
+	public boolean isValid() {
+		return true;
+	}
+
+	/**
+	 * @see org.apache.felix.ipojo.Handler#stateChanged(int)
+	 */
+	public void stateChanged(int state) {
+		if (state == ComponentManager.VALID) {
+			if (m_sr == null) { start(); }
+			return;
+		}
+		if (state == ComponentManager.INVALID) {
+			if (m_sr != null) { stop(); }
+			return;
+		}
+	}
+
+	/**
+	 * @see org.osgi.service.cm.ManagedService#updated(java.util.Dictionary)
+	 */
+	public void updated(Dictionary np) throws ConfigurationException {
+
+		if (np != null) {
+			Enumeration keysEnumeration = np.keys();
+			while (keysEnumeration.hasMoreElements()) {
+				String name = (String)keysEnumeration.nextElement();
+				Object value = np.get(name);
+				boolean find = false;
+				// Check if the field is a configurable property
+				for (int i = 0; !find && i < m_configurableProperties.length; i++) {
+					if (m_configurableProperties[i].getName().equals(name)) {
+						// Check if the value has change
+						if (m_configurableProperties[i].getValue() == null || !m_configurableProperties[i].getValue().equals(value)) {
+							m_configurableProperties[i].setValue(value); // Change the value
+							m_manager.setterCallback(m_configurableProperties[i].getField(), value); // says that the value has change
+						}
+						find = true;
+						// Else do nothing
+					}
+				}
+				if (!find) {
+					Activator.getLogger().log(Level.WARNING, "[" + m_manager.getComponentMetatada().getClassName() + "] The configuration is not valid, the property " + name + " is not a configurable property");
+					}
+				}
+			}
+		else { Activator.getLogger().log(Level.WARNING, "[" + m_manager.getComponentMetatada().getClassName() + "] The pushed configuration is null for " + m_pid); }
+
+	}
+
+	/**
+     * Add the given property metadata to the property metadata list.
+	 * @param p : property metdata to add
+	 */
+	protected void addProperty(ConfigurableProperty p) {
+        for (int i = 0; (m_configurableProperties != null) && (i < m_configurableProperties.length); i++) {
+            if (m_configurableProperties[i] == p) { return; }
+        }
+
+        if (m_configurableProperties.length > 0) {
+        	ConfigurableProperty[] newProp = new ConfigurableProperty[m_configurableProperties.length + 1];
+            System.arraycopy(m_configurableProperties, 0, newProp, 0, m_configurableProperties.length);
+            newProp[m_configurableProperties.length] = p;
+            m_configurableProperties = newProp;
+        }
+        else {
+        	m_configurableProperties = new ConfigurableProperty[] {p};
+        }
+	}
+
+	/**
+	 * Check if the liste contains the property.
+	 * @param name : name of the property
+	 * @return true if the property exist in the list
+	 */
+	protected boolean containsProperty(String name) {
+		for (int i = 0; (m_configurableProperties != null) && (i < m_configurableProperties.length); i++) {
+            if (m_configurableProperties[i].getName() == name) { return true; }
+        }
+		return false;
+	}
+
+}

Propchange: incubator/felix/trunk/org.apache.felix.ipojo/src/main/java/org/apache/felix/ipojo/handlers/configuration/ConfigurationHandler.java
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message