Applied patch (FELIX-184) to restructure iPOJO and add some new
features.
git-svn-id: https://svn.apache.org/repos/asf/incubator/felix/trunk@487682 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/ipojo.arch/src/main/java/org/apache/felix/ipojo/arch/ArchCommandImpl.java b/ipojo.arch/src/main/java/org/apache/felix/ipojo/arch/ArchCommandImpl.java
index 396d697..ff0dce3 100644
--- a/ipojo.arch/src/main/java/org/apache/felix/ipojo/arch/ArchCommandImpl.java
+++ b/ipojo.arch/src/main/java/org/apache/felix/ipojo/arch/ArchCommandImpl.java
@@ -22,8 +22,8 @@
import java.io.PrintStream;
import org.apache.felix.ipojo.architecture.Architecture;
-import org.apache.felix.ipojo.architecture.ComponentDescription;
import org.apache.felix.ipojo.architecture.HandlerDescription;
+import org.apache.felix.ipojo.architecture.InstanceDescription;
import org.ungoverned.osgi.service.shell.Command;
@@ -65,7 +65,7 @@
* @param state : the state in int
* @return : the string of the state (Stopped, Unresolved, Resolved) or "Unknown" if state is not revelant
*/
- private String getComponentState(int state) {
+ private String getInstanceState(int state) {
switch(state) {
case(0) :
return "STOPPED";
@@ -84,10 +84,10 @@
public void execute(String line, PrintStream out, PrintStream err) {
synchronized(this) {
for(int i=0; i < archiService.length; i++) {
- ComponentDescription component = archiService[i].getComponentDescription();
- out.println("Component : " + component.getClassName() + " - " + getComponentState(component.getState()) + " from bundle " + component.getBundleId());
- for(int j = 0; j < component.getHandlers().length; j++) {
- HandlerDescription hd = component.getHandlers()[j];
+ InstanceDescription instance = archiService[i].getInstanceDescription();
+ out.println("Instance : " + instance.getClassName() + " - " + getInstanceState(instance.getState()) + " from bundle " + instance.getBundleId());
+ for(int j = 0; j < instance.getHandlers().length; j++) {
+ HandlerDescription hd = instance.getHandlers()[j];
String hn = hd.getHandlerName();
String hv = "valid";
if(!hd.isValid()) { hv = "invalid"; }
@@ -96,11 +96,10 @@
if(!hi.equals("")) { out.println(hi); }
}
- out.println("Created Instances of the POJO : ");
- for(int j=0; j < component.getInstances().length; j++) {
- out.println("\t" + component.getInstances()[j]);
+ out.println("Created POJO Objects : ");
+ for(int j=0; j < instance.getCreatedObjects().length; j++) {
+ out.println("\t" + instance.getCreatedObjects()[j]);
}
-
out.print("\n");
}
}
diff --git a/ipojo.plugin/pom.xml b/ipojo.plugin/pom.xml
index e5809a9..bdace6a 100644
--- a/ipojo.plugin/pom.xml
+++ b/ipojo.plugin/pom.xml
@@ -31,12 +31,7 @@
<version>2.0</version>
</dependency>
<dependency>
- <groupId>kxml2</groupId>
- <artifactId>kxml2</artifactId>
- <version>2.2.2</version>
- </dependency>
- <dependency>
- <groupId>asm</groupId>
+ <groupId>asm</groupId>
<artifactId>asm</artifactId>
<version>2.2.1</version>
</dependency>
diff --git a/ipojo.plugin/src/main/java/org/apache/felix/ipojo/manipulation/ClassChecker.java b/ipojo.plugin/src/main/java/org/apache/felix/ipojo/manipulation/ClassChecker.java
index 95e1b42..315b16b 100644
--- a/ipojo.plugin/src/main/java/org/apache/felix/ipojo/manipulation/ClassChecker.java
+++ b/ipojo.plugin/src/main/java/org/apache/felix/ipojo/manipulation/ClassChecker.java
@@ -50,7 +50,7 @@
*/
public FieldVisitor visitField(int access, String name, String desc, String signature, Object value) {
- if (access == ACC_PRIVATE && name.equals("_cm") && desc.equals("Lorg/apache/felix/ipojo/ComponentManagerImpl;")) {
+ if (access == ACC_PRIVATE && name.equals("_cm") && desc.equals("Lorg/apache/felix/ipojo/InstanceManager;")) {
isAlreadyManipulated = true;
}
diff --git a/ipojo.plugin/src/main/java/org/apache/felix/ipojo/manipulation/ConstructorCodeAdapter.java b/ipojo.plugin/src/main/java/org/apache/felix/ipojo/manipulation/ConstructorCodeAdapter.java
index a923c0c..3aba331 100644
--- a/ipojo.plugin/src/main/java/org/apache/felix/ipojo/manipulation/ConstructorCodeAdapter.java
+++ b/ipojo.plugin/src/main/java/org/apache/felix/ipojo/manipulation/ConstructorCodeAdapter.java
@@ -96,7 +96,7 @@
//mv.visitVarInsn(ALOAD, Type.getArgumentTypes(m_constructorDesc).length);
mv.visitVarInsn(ALOAD, 1); // CM is always the first argument
// 3) Initialize the field
- mv.visitMethodInsn(INVOKESPECIAL, m_owner, "_setComponentManager", "(Lorg/apache/felix/ipojo/ComponentManagerImpl;)V");
+ mv.visitMethodInsn(INVOKESPECIAL, m_owner, "_setComponentManager", "(Lorg/apache/felix/ipojo/InstanceManager;)V");
// insertion finished
}
else { mv.visitMethodInsn(opcode, owner, name, desc); }
@@ -118,9 +118,9 @@
public void visitLocalVariable(String name, String desc, String signature, Label start, Label end, int index) {
if(index == 0) {
mv.visitLocalVariable(name, desc, signature, start, end, index);
- mv.visitLocalVariable("_manager", "Lorg/apache/felix/ipojo/ComponentManagerImpl;", null, start, end, 1);
+ mv.visitLocalVariable("_manager", "Lorg/apache/felix/ipojo/InstanceManager;", null, start, end, 1);
IPojoPluginConfiguration.getLogger().log(Level.INFO, "Local Variable : " + name + " index = " + index + " desc = " + desc);
- IPojoPluginConfiguration.getLogger().log(Level.INFO, "Local Variable : " + "_manager" + " index = " + 1 + " desc = " + "Lorg/apache/felix/ipojo/ComponentManagerImpl;");
+ IPojoPluginConfiguration.getLogger().log(Level.INFO, "Local Variable : " + "_manager" + " index = " + 1 + " desc = " + "Lorg/apache/felix/ipojo/InstanceManager;");
}
mv.visitLocalVariable(name, desc, signature, start, end, index+1);
IPojoPluginConfiguration.getLogger().log(Level.INFO, "Local Variable : " + name + " index = " + index + " desc = " + desc);
diff --git a/ipojo.plugin/src/main/java/org/apache/felix/ipojo/manipulation/Manipulator.java b/ipojo.plugin/src/main/java/org/apache/felix/ipojo/manipulation/Manipulator.java
index 8e0770a..c277195 100644
--- a/ipojo.plugin/src/main/java/org/apache/felix/ipojo/manipulation/Manipulator.java
+++ b/ipojo.plugin/src/main/java/org/apache/felix/ipojo/manipulation/Manipulator.java
@@ -65,7 +65,6 @@
/**
* Manipulate the class.
- * @param bundle The component's m_bundle
* @param name The name of the class
* @param cm The component manager attached to this manipulation
* @throws Exception : throwed if the manipulation failed.
diff --git a/ipojo.plugin/src/main/java/org/apache/felix/ipojo/manipulation/PreprocessClassAdapter.java b/ipojo.plugin/src/main/java/org/apache/felix/ipojo/manipulation/PreprocessClassAdapter.java
index 982faa9..b0de844 100644
--- a/ipojo.plugin/src/main/java/org/apache/felix/ipojo/manipulation/PreprocessClassAdapter.java
+++ b/ipojo.plugin/src/main/java/org/apache/felix/ipojo/manipulation/PreprocessClassAdapter.java
@@ -79,7 +79,7 @@
m_owner = name;
// Insert _cm field
- FieldVisitor fv = super.visitField(ACC_PRIVATE, "_cm", "Lorg/apache/felix/ipojo/ComponentManagerImpl;", null, null);
+ FieldVisitor fv = super.visitField(ACC_PRIVATE, "_cm", "Lorg/apache/felix/ipojo/InstanceManager;", null, null);
fv.visitEnd();
// Create the _cmSetter(ComponentManager cm) method
@@ -108,7 +108,7 @@
if(name.equals("<init>")) {
// 1) change the constructor descriptor (add a component manager arg as first argument)
String new_desc = desc.substring(1);
- new_desc = "(Lorg/apache/felix/ipojo/ComponentManagerImpl;"+new_desc;
+ new_desc = "(Lorg/apache/felix/ipojo/InstanceManager;"+new_desc;
// Insert the new constructor
MethodVisitor mv = super.visitMethod(ACC_PUBLIC, "<init>", new_desc, null, null);
@@ -129,11 +129,11 @@
* Create the setter method for the _cm field.
*/
private void createComponentManagerSetter() {
- MethodVisitor mv = cv.visitMethod(ACC_PRIVATE, "_setComponentManager", "(Lorg/apache/felix/ipojo/ComponentManagerImpl;)V", null, null);
+ MethodVisitor mv = cv.visitMethod(ACC_PRIVATE, "_setComponentManager", "(Lorg/apache/felix/ipojo/InstanceManager;)V", null, null);
mv.visitVarInsn(ALOAD, 0);
mv.visitVarInsn(ALOAD, 1);
- mv.visitFieldInsn(PUTFIELD, m_owner, "_cm", "Lorg/apache/felix/ipojo/ComponentManagerImpl;");
+ mv.visitFieldInsn(PUTFIELD, m_owner, "_cm", "Lorg/apache/felix/ipojo/InstanceManager;");
mv.visitInsn(RETURN);
@@ -201,10 +201,10 @@
mv.visitFieldInsn(PUTFIELD, m_owner, name, internalType);
mv.visitVarInsn(ALOAD, 0);
- mv.visitFieldInsn(GETFIELD, m_owner, "_cm", "Lorg/apache/felix/ipojo/ComponentManagerImpl;");
+ mv.visitFieldInsn(GETFIELD, m_owner, "_cm", "Lorg/apache/felix/ipojo/InstanceManager;");
mv.visitLdcInsn(name);
mv.visitVarInsn(ALOAD, 1);
- mv.visitMethodInsn(INVOKEVIRTUAL, "org/apache/felix/ipojo/ComponentManagerImpl", "setterCallback", "(Ljava/lang/String;Ljava/lang/Object;)V");
+ mv.visitMethodInsn(INVOKEVIRTUAL, "org/apache/felix/ipojo/InstanceManager", "setterCallback", "(Ljava/lang/String;Ljava/lang/Object;)V");
mv.visitInsn(RETURN);
@@ -235,10 +235,10 @@
mv.visitVarInsn(ASTORE, 1);
mv.visitVarInsn(ALOAD, 0);
- mv.visitFieldInsn(GETFIELD, m_owner, "_cm", "Lorg/apache/felix/ipojo/ComponentManagerImpl;");
+ mv.visitFieldInsn(GETFIELD, m_owner, "_cm", "Lorg/apache/felix/ipojo/InstanceManager;");
mv.visitLdcInsn(name);
mv.visitVarInsn(ALOAD, 1);
- mv.visitMethodInsn(INVOKEVIRTUAL, "org/apache/felix/ipojo/ComponentManagerImpl", "getterCallback", "(Ljava/lang/String;Ljava/lang/Object;)Ljava/lang/Object;");
+ mv.visitMethodInsn(INVOKEVIRTUAL, "org/apache/felix/ipojo/InstanceManager", "getterCallback", "(Ljava/lang/String;Ljava/lang/Object;)Ljava/lang/Object;");
mv.visitVarInsn(ASTORE, 2);
mv.visitVarInsn(ALOAD, 2);
@@ -309,10 +309,10 @@
mv.visitVarInsn(ASTORE, 2);
mv.visitVarInsn(ALOAD, 0);
- mv.visitFieldInsn(GETFIELD, m_owner, "_cm", "Lorg/apache/felix/ipojo/ComponentManagerImpl;");
+ mv.visitFieldInsn(GETFIELD, m_owner, "_cm", "Lorg/apache/felix/ipojo/InstanceManager;");
mv.visitLdcInsn(name);
mv.visitVarInsn(ALOAD, 2);
- mv.visitMethodInsn(INVOKEVIRTUAL, "org/apache/felix/ipojo/ComponentManagerImpl", "getterCallback", "(Ljava/lang/String;Ljava/lang/Object;)Ljava/lang/Object;");
+ mv.visitMethodInsn(INVOKEVIRTUAL, "org/apache/felix/ipojo/InstanceManager", "getterCallback", "(Ljava/lang/String;Ljava/lang/Object;)Ljava/lang/Object;");
mv.visitVarInsn(ASTORE, 3);
mv.visitVarInsn(ALOAD, 3);
@@ -349,10 +349,10 @@
mv.visitVarInsn(ASTORE, 1);
mv.visitVarInsn(ALOAD, 0);
- mv.visitFieldInsn(GETFIELD, m_owner, "_cm", "Lorg/apache/felix/ipojo/ComponentManagerImpl;");
+ mv.visitFieldInsn(GETFIELD, m_owner, "_cm", "Lorg/apache/felix/ipojo/InstanceManager;");
mv.visitLdcInsn(name);
mv.visitVarInsn(ALOAD, 1);
- mv.visitMethodInsn(INVOKEVIRTUAL, "org/apache/felix/ipojo/ComponentManagerImpl", "getterCallback", "(Ljava/lang/String;Ljava/lang/Object;)Ljava/lang/Object;");
+ mv.visitMethodInsn(INVOKEVIRTUAL, "org/apache/felix/ipojo/InstanceManager", "getterCallback", "(Ljava/lang/String;Ljava/lang/Object;)Ljava/lang/Object;");
mv.visitVarInsn(ASTORE, 2);
mv.visitVarInsn(ALOAD, 2);
@@ -430,10 +430,10 @@
Label l2 = new Label();
mv.visitLabel(l2);
mv.visitVarInsn(ALOAD, 0);
- mv.visitFieldInsn(GETFIELD, m_owner, "_cm", "Lorg/apache/felix/ipojo/ComponentManagerImpl;");
+ mv.visitFieldInsn(GETFIELD, m_owner, "_cm", "Lorg/apache/felix/ipojo/InstanceManager;");
mv.visitLdcInsn(name);
mv.visitVarInsn(ALOAD, 2);
- mv.visitMethodInsn(INVOKEVIRTUAL, "org/apache/felix/ipojo/ComponentManagerImpl", "setterCallback", "(Ljava/lang/String;Ljava/lang/Object;)V");
+ mv.visitMethodInsn(INVOKEVIRTUAL, "org/apache/felix/ipojo/InstanceManager", "setterCallback", "(Ljava/lang/String;Ljava/lang/Object;)V");
Label l3 = new Label();
mv.visitLabel(l3);
@@ -446,10 +446,10 @@
mv.visitFieldInsn(PUTFIELD, m_owner, name, "L" + type.getInternalName() + ";");
mv.visitVarInsn(ALOAD, 0);
- mv.visitFieldInsn(GETFIELD, m_owner, "_cm", "Lorg/apache/felix/ipojo/ComponentManagerImpl;");
+ mv.visitFieldInsn(GETFIELD, m_owner, "_cm", "Lorg/apache/felix/ipojo/InstanceManager;");
mv.visitLdcInsn(name);
mv.visitVarInsn(ALOAD, 1);
- mv.visitMethodInsn(INVOKEVIRTUAL, "org/apache/felix/ipojo/ComponentManagerImpl", "setterCallback", "(Ljava/lang/String;Ljava/lang/Object;)V");
+ mv.visitMethodInsn(INVOKEVIRTUAL, "org/apache/felix/ipojo/InstanceManager", "setterCallback", "(Ljava/lang/String;Ljava/lang/Object;)V");
mv.visitInsn(RETURN);
break;
diff --git a/ipojo.plugin/src/main/java/org/apache/felix/ipojo/plugin/OsgiJarMojo.java b/ipojo.plugin/src/main/java/org/apache/felix/ipojo/plugin/OsgiJarMojo.java
index 6ccd1e8..1d364ee 100644
--- a/ipojo.plugin/src/main/java/org/apache/felix/ipojo/plugin/OsgiJarMojo.java
+++ b/ipojo.plugin/src/main/java/org/apache/felix/ipojo/plugin/OsgiJarMojo.java
@@ -481,6 +481,9 @@
}
}
+ // Add org.apache.felix.ipojo is not already in the set
+ referred.add("org.apache.felix.ipojo");
+
if (referred.isEmpty())
return;
@@ -1004,6 +1007,6 @@
}
private void setBundleActivator() throws MojoExecutionException {
- archiveConfig.addManifestEntry("Bundle-Activator", "org.apache.felix.ipojo.Activator");
+ archiveConfig.addManifestEntry("Bundle-Activator", "org.apache.felix.ipojo.Activator");
}
}
diff --git a/ipojo.plugin/src/main/resources/archetype-resources/pom.xml b/ipojo.plugin/src/main/resources/archetype-resources/pom.xml
index 84d4c29..8da7b7b 100644
--- a/ipojo.plugin/src/main/resources/archetype-resources/pom.xml
+++ b/ipojo.plugin/src/main/resources/archetype-resources/pom.xml
@@ -6,14 +6,6 @@
<version>${version}</version>
<name>$YOUR_PROJECT_NAME</name>
- <pluginRepositories>
- <pluginRepository>
- <id>iPOJO.repository</id>
- <name>iPOJO Repository</name>
- <url>http://www-adele.imag.fr/~escoffie/repository</url>
- </pluginRepository>
- </pluginRepositories>
-
<build>
<plugins>
<plugin>
diff --git a/ipojo/pom.xml b/ipojo/pom.xml
index 0b47da4..c6652ac 100644
--- a/ipojo/pom.xml
+++ b/ipojo/pom.xml
@@ -41,14 +41,17 @@
<bundleDescription> iPOJO </bundleDescription>
<importPackage>
org.osgi.framework; specification-version="1.3",
- org.osgi.service.cm; specification-version="1.2"
+ org.osgi.service.cm; specification-version="1.2",
+ org.osgi.service.log; specification-version="1.3"
</importPackage>
<exportPackage>
org.apache.felix.ipojo,
org.apache.felix.ipojo.metadata,
org.apache.felix.ipojo.architecture,
- org.apache.felix.ipojo.parser,
- org.osgi.service.cm; specification-version="1.2"
+ org.apache.felix.ipojo.parser,
+ org.apache.felix.ipojo.util,
+ org.osgi.service.cm; specification-version="1.2",
+ org.osgi.service.log; specification-version="1.3"
</exportPackage>
</osgiManifest>
</configuration>
diff --git a/ipojo/src/main/java/org/apache/felix/ipojo/Activator.java b/ipojo/src/main/java/org/apache/felix/ipojo/Activator.java
index 9eed6d1..b1c4950 100644
--- a/ipojo/src/main/java/org/apache/felix/ipojo/Activator.java
+++ b/ipojo/src/main/java/org/apache/felix/ipojo/Activator.java
@@ -20,8 +20,6 @@
import java.io.IOException;
import java.util.Dictionary;
-import java.util.logging.Level;
-import java.util.logging.Logger;
import org.apache.felix.ipojo.metadata.Element;
import org.apache.felix.ipojo.parser.ManifestMetadataParser;
@@ -31,25 +29,11 @@
/**
- * iPOJO generic activator.
+ * iPOJO generic activator.
+ * All iPOJO bundle (bundle containing iPOJO components) must used this activator to be able to start the component management.
* @author <a href="mailto:felix-dev@incubator.apache.org">Felix Project Team</a>
*/
public class Activator implements BundleActivator {
-
- // STATIC
- /**
- * The iPOJO static logger. This logger is used by each iPOJO instance.
- */
- private static Logger m_logger = Logger.getLogger("org.apache.felix.ipojo");
-
- /**
- * @return Returns the static ipojo logger : org.apache.felix.ipojo
- */
- public static Logger getLogger() { return Activator.m_logger; }
- // END STATIC
-
- // NON STATIC PART
-
/**
* The m_bundle context.
* m_bundleContext : BundleContext
@@ -57,93 +41,46 @@
private BundleContext m_bundleContext = null;
/**
- * The component manager for this activator.
- * m_handler : ComponentManagerFactory
+ * Component Factories managed by the current bundle.
+ * m_handler : ComponentFactory
*/
- private ComponentManagerFactory[] m_factories;
+ private ComponentFactory[] m_factories = new ComponentFactory[0];
+
+ /**
+ * The instance creator aims to manage instance from outside factory.
+ */
+ private InstanceCreator m_creator;
/**
- * The configuration to create.
- * m_configuration : Array of Dictionary
+ * The configurations to create.
+ * m_configuration : Array of Dictionary (each dictionary represents one configuration)
*/
private Dictionary[] m_configurations;
- // Field accessors :
-
/**
- * @return the m_bundle context
+ * @return the bundle context
*/
- public BundleContext getBundleContext() {
- return m_bundleContext;
- }
+ public BundleContext getBundleContext() { return m_bundleContext; }
/**
- * Add a component manager factory to the factory list.
+ * Add a component factory to the factory list.
* @param cm : the new component metadata.
*/
- public void addComponentFactory(Element cm) {
- // Create the factory :
- ComponentManagerFactory factory = new ComponentManagerFactory(m_bundleContext, cm);
+ private void addComponentFactory(Element cm) {
+ ComponentFactory factory = new ComponentFactory(m_bundleContext, cm);
// If the factory array is not empty add the new factory at the end
if (m_factories.length != 0) {
- ComponentManagerFactory[] newFactory = new ComponentManagerFactory[m_factories.length + 1];
+ ComponentFactory[] newFactory = new ComponentFactory[m_factories.length + 1];
System.arraycopy(m_factories, 0, newFactory, 0, m_factories.length);
newFactory[m_factories.length] = factory;
m_factories = newFactory;
}
// Else create an array of size one with the new Factory
- else { m_factories = new ComponentManagerFactory[] {factory}; }
+ else { m_factories = new ComponentFactory[] {factory}; }
}
/**
- * Remove a component manager factory to the factory list.
- * @param factory : the componet facotry to remove
- */
- public void removeComponentFactory(ComponentManagerFactory factory) {
-
- int idx = -1;
- for (int i = 0; i < m_factories.length; i++) {
- if (m_factories[i] == factory) {
- idx = i;
- break;
- }
- }
-
- if (idx >= 0) {
- // If this is the factory, then point to empty list.
- if ((m_factories.length - 1) == 0) {
- m_factories = new ComponentManagerFactory[0];
- }
- // Otherwise, we need to do some array copying.
- else {
- ComponentManagerFactory[] newFactories = new ComponentManagerFactory[m_factories.length - 1];
- System.arraycopy(m_factories, 0, newFactories, 0, idx);
- if (idx < newFactories.length) {
- System.arraycopy(m_factories, idx + 1, newFactories, idx, newFactories.length - idx);
- }
- m_factories = newFactories;
- }
- }
- }
-
- // End field accesors
-
- // Constructors :
-
- /**
- * Constructor used by Felix.
- */
- public Activator() {
- super();
- m_factories = new ComponentManagerFactory[0];
- }
-
- // End constuctors
-
- // Bundle Lifecycle CallBack
-
- /**
* Start method.
* @see org.osgi.framework.BundleActivator#start(org.osgi.framework.BundleContext)
* @param bc : the m_bundle context to use to manage the component.
@@ -151,15 +88,13 @@
*/
public void start(final BundleContext bc) throws Exception {
m_bundleContext = bc;
- Activator.getLogger().setLevel(IPojoConfiguration.LOG_LEVEL);
try {
parse();
} catch (Exception e) {
- Activator.getLogger().log(Level.SEVERE, "Parse error for the bundle " + m_bundleContext.getBundle().getBundleId() + " : " + e.getMessage());
+ System.err.println("Parse error for the bundle " + m_bundleContext.getBundle().getBundleId() + " : " + e.getMessage());
return;
}
- Activator.getLogger().log(Level.INFO, "[Bundle" + m_bundleContext.getBundle().getBundleId() + "] Called start after the parsing");
start(); // Call the internal start method
@@ -173,18 +108,15 @@
*/
public void stop(BundleContext arg0) throws Exception {
for (int i = 0; i < m_factories.length; i++) {
- ComponentManagerFactory factory = m_factories[i];
+ ComponentFactory factory = m_factories[i];
factory.stop();
}
+ m_creator.stop();
+ m_factories = new ComponentFactory[0]; // Release all factories
}
- // End Bundle Lifecycle CallBack
-
- // Parsing methods :
-
/**
- * Parse the file who is at the Metadata-Location place, manipulate the bytecode of the component implementation class
- * and set the manager.
+ * Parse the internal metadata (from the manifest (in the iPOJO-Components property)).
* @throws IOException : the manisfest could not be found
* @throws ParseException : the parsing process failed
*/
@@ -192,46 +124,48 @@
String componentClasses = (String) m_bundleContext.getBundle().getHeaders().get("iPOJO-Components");
if (componentClasses != null) {
- parseManifest(m_bundleContext.getBundle().getHeaders());
+ ManifestMetadataParser parser = new ManifestMetadataParser();
+ parser.parse(m_bundleContext.getBundle().getHeaders());
+
+ Element[] componentsMetadata = parser.getComponentsMetadata(); // Get the component type declaration
+ for (int i = 0; i < componentsMetadata.length; i++) { addComponentFactory(componentsMetadata[i]); }
+ m_configurations = parser.getInstances(); // Get the component instances declaration
} else {
- Activator.getLogger().log(Level.SEVERE, "[Bundle" + m_bundleContext.getBundle().getBundleId() + "] Components-Metadata are not in the manifest");
- throw new ParseException("[Bundle" + m_bundleContext.getBundle().getBundleId() + "] Component-Metadata are not in the manifest");
+ throw new ParseException("[Bundle" + m_bundleContext.getBundle().getBundleId() + "] iPOJO-Components are not in the manifest");
}
}
/**
- * Parse the manifest.
- * @param dict : Manifest Entries
- * @throws ParseException : throwed when the parsing failed
- */
- private void parseManifest(Dictionary dict) throws ParseException {
- ManifestMetadataParser parser = new ManifestMetadataParser();
- parser.parse(dict);
- // Create the components Factory according to the declared component
- Element[] componentsMetadata = parser.getComponentsMetadata();
- m_configurations = parser.getInstances();
- for (int i = 0; i < componentsMetadata.length; i++) {
- Activator.getLogger().log(Level.INFO, "[Bundle" + m_bundleContext.getBundle().getBundleId() + "] Create a component factory for " + componentsMetadata[i].getAttribute("classname"));
- addComponentFactory(componentsMetadata[i]);
- }
-
- }
-
- /**
- * Start the management : Manipulate the classes and start the component manager.
+ * Start the management factories and create instances.
*/
private void start() {
- for (int i = 0; i < m_factories.length; i++) {
- ComponentManagerFactory factory = m_factories[i];
- String componentClass = factory.getComponentClassName();
- for (int j = 0; j < m_configurations.length; j++) {
- Dictionary conf = m_configurations[j];
- if (conf.get("component") != null && conf.get("component").equals(componentClass)) {
- factory.createComponent(m_configurations[j]); // create a component
- }
- }
- factory.start(); // Start the factory exposition
- }
+ // Start the factories
+ for(int j = 0; j < m_factories.length; j++) { m_factories[j].start(); }
+
+ Dictionary[] outsiders = new Dictionary[0];
+ for(int i = 0; i < m_configurations.length; i++) {
+ Dictionary conf = m_configurations[i];
+ boolean created = false;
+ for(int j = 0; j < m_factories.length; j++) {
+ String componentClass = m_factories[j].getComponentClassName();
+ String factoryName = m_factories[j].getFactoryName();
+ if(conf.get("component") != null && (conf.get("component").equals(componentClass) || conf.get("component").equals(factoryName))) {
+ if(m_factories[j].isAcceptable(conf)) { m_factories[j].createComponentInstance(conf); created = true;}
+ }
+ }
+ if(!created && conf.get("component") != null) {
+ if (outsiders.length != 0) {
+ Dictionary[] newList = new Dictionary[outsiders.length + 1];
+ System.arraycopy(outsiders, 0, newList, 0, outsiders.length);
+ newList[outsiders.length] = conf;
+ outsiders = newList;
+ }
+ else { outsiders = new Dictionary[] {conf}; }
+ }
+ }
+
+ // Create the instance creator
+ m_creator = new InstanceCreator(m_bundleContext, outsiders);
}
}
diff --git a/ipojo/src/main/java/org/apache/felix/ipojo/ComponentManagerFactory.java b/ipojo/src/main/java/org/apache/felix/ipojo/ComponentFactory.java
similarity index 60%
rename from ipojo/src/main/java/org/apache/felix/ipojo/ComponentManagerFactory.java
rename to ipojo/src/main/java/org/apache/felix/ipojo/ComponentFactory.java
index e45d5f6..ff7ec92 100644
--- a/ipojo/src/main/java/org/apache/felix/ipojo/ComponentManagerFactory.java
+++ b/ipojo/src/main/java/org/apache/felix/ipojo/ComponentFactory.java
@@ -26,11 +26,12 @@
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Iterator;
-import java.util.List;
import java.util.Properties;
-import java.util.logging.Level;
+import org.apache.felix.ipojo.architecture.ComponentDescription;
+import org.apache.felix.ipojo.architecture.PropertyDescription;
import org.apache.felix.ipojo.metadata.Element;
+import org.apache.felix.ipojo.util.Logger;
import org.osgi.framework.BundleContext;
import org.osgi.framework.Constants;
import org.osgi.framework.ServiceRegistration;
@@ -38,62 +39,64 @@
import org.osgi.service.cm.ManagedServiceFactory;
/**
- * The component manager factory class manages component manager object.
+ * The component factory manages component instance objects.
+ * This management consist in creating and managing component instance build with the component factory.
* This class could export Factory and ManagedServiceFactory services.
* @author <a href="mailto:felix-dev@incubator.apache.org">Felix Project Team</a>
*/
-public class ComponentManagerFactory implements Factory, ManagedServiceFactory {
+public class ComponentFactory implements Factory, ManagedServiceFactory {
- // Fields :
/**
- * List of the managed component manager.
- * The key of tis hashmap is the name (pid) of the component created
+ * List of the managed instance managers.
+ * The key of this hashmap is the name (i.e. pid) of the created instance
*/
- private HashMap m_componentManagers = new HashMap();
+ private HashMap m_componentInstances = new HashMap();
/**
* The bundle context reference.
*/
- private BundleContext m_bundleContext = null;
+ private BundleContext m_context = null;
/**
- * Component class.
+ * Component Implementation class.
*/
private byte[] m_clazz = null;
/**
- * Component Class Name.
+ * Component Implementation Class Name.
*/
private String m_componentClassName = null;
/**
* Classloader to delegate loading.
*/
- private FactoryClassloader m_classLoader = null;
+ private FactoryClassloader m_classLoader = null; //TODO is this classloader really useful ?
/**
- * Component Type provided by this factory.
+ * Component Type provided by this factory. //TODO Should be keep this reference ?
*/
private Element m_componentMetadata;
/**
- * Factory Name / PID.
+ * Factory Name (i.e. Factory PID).
* Could be the component class name if the factory name is not set.
*/
private String m_factoryName;
/**
- * Service Registration of this factory (Facotry & ManagedServiceFactory).
+ * Service Registration of this factory (Factory & ManagedServiceFactory).
*/
private ServiceRegistration m_sr;
/**
- * Component-Type info exposed by the factory service.
+ * Component-Type description exposed by the factory service.
*/
- private ComponentInfo m_componentInfo;
+ private ComponentDescription m_componentDesc;
-
- //End field
+ /**
+ * Logger for the factory (and all component instance)
+ */
+ private Logger m_logger;
/**
* FactoryClassloader.
@@ -110,7 +113,7 @@
*/
protected synchronized Class loadClass(final String name,
final boolean resolve) throws ClassNotFoundException {
- return m_bundleContext.getBundle().loadClass(name);
+ return m_context.getBundle().loadClass(name);
}
@@ -121,7 +124,7 @@
* @see java.lang.ClassLoader#getResource(java.lang.String)
*/
public URL getResource(String arg) {
- return m_bundleContext.getBundle().getResource(arg);
+ return m_context.getBundle().getResource(arg);
}
/**
@@ -132,7 +135,7 @@
* @see java.lang.ClassLoader#getResources(java.lang.String)
*/
public Enumeration getRessources(String arg) throws IOException {
- return m_bundleContext.getBundle().getResources(arg);
+ return m_context.getBundle().getResources(arg);
}
/**
@@ -153,37 +156,43 @@
/**
* @return the Bundle Context
*/
- public BundleContext getBundleContext() { return m_bundleContext; }
+ protected BundleContext getBundleContext() { return m_context; }
/**
- * @return the class name of the component-type provided by this factory.
+ * @return the name of the component-type implementation class.
*/
protected String getComponentClassName() { return m_componentClassName; }
+
+ /**
+ * @return the factory logger.
+ */
+ public Logger getLogger() { return m_logger; }
/**
- * Create a component manager factory.
+ * Create a instance manager factory.
* @param bc : bundle context
* @param cm : metadata of the component to create
*/
- public ComponentManagerFactory(BundleContext bc, Element cm) {
- m_bundleContext = bc;
+ public ComponentFactory(BundleContext bc, Element cm) {
+ m_context = bc;
m_componentClassName = cm.getAttribute("className");
m_componentMetadata = cm;
// Get factory PID :
if (m_componentMetadata.containsAttribute("factory") && !m_componentMetadata.getAttribute("factory").equalsIgnoreCase("no")) { m_factoryName = m_componentMetadata.getAttribute("factory"); }
else { m_factoryName = m_componentMetadata.getAttribute("className"); }
-
+
+ m_logger = new Logger(m_context, m_factoryName, Logger.WARNING);
}
/**
- * Create a component manager factory. The class is given in parameter.
+ * Create a instance manager factory. The class is given in parameter.
* @param bc : bundle context
* @param clazz : the component class
* @param cm : metadata of the component
*/
- public ComponentManagerFactory(BundleContext bc, byte[] clazz, Element cm) {
- m_bundleContext = bc;
+ public ComponentFactory(BundleContext bc, byte[] clazz, Element cm) {
+ m_context = bc;
m_clazz = clazz;
m_componentClassName = cm.getAttribute("className");
m_componentMetadata = cm;
@@ -191,64 +200,58 @@
// Get factory PID :
if (m_componentMetadata.containsAttribute("factory") && !m_componentMetadata.getAttribute("factory").equalsIgnoreCase("no")) { m_factoryName = m_componentMetadata.getAttribute("factory"); }
else { m_factoryName = m_componentMetadata.getAttribute("className"); }
+
+ m_logger = new Logger(m_context, m_factoryName, Logger.WARNING);
}
/**
- * Create a component manager factory, no component manager are created.
- * @param bc
- */
- public ComponentManagerFactory(BundleContext bc) { m_bundleContext = bc; }
-
-
- // Factory lifecycle management
-
- /**
- * Stop all the component managers.
+ * Stop all the instance managers.
*/
public void stop() {
- Activator.getLogger().log(Level.INFO, "[Bundle " + m_bundleContext.getBundle().getBundleId() + "] Stop the component factory");
- Collection col = m_componentManagers.values();
+ Collection col = m_componentInstances.values();
Iterator it = col.iterator();
while (it.hasNext()) {
- ComponentManagerImpl cm = (ComponentManagerImpl) it.next();
+ InstanceManager cm = (InstanceManager) it.next();
cm.stop();
}
- m_componentManagers.clear();
+ m_componentInstances.clear();
if (m_sr != null) { m_sr.unregister(); }
m_sr = null;
}
/**
- * Start all the component managers.
+ * Start all the instance managers.
*/
- public void start() {
- Activator.getLogger().log(Level.INFO, "[Bundle " + m_bundleContext.getBundle().getBundleId() + "] Start the component factory");
+ public void start() {
+ Properties props = new Properties();
+
+ // create a ghost component
+ InstanceManager ghost = new InstanceManager(this, m_context);
+ Properties p = new Properties();
+ p.put("name", "ghost");
+ ghost.configure(m_componentMetadata, p);
+ m_componentDesc = ghost.getComponentDescription();
// Check if the factory should be exposed
if (m_componentMetadata.containsAttribute("factory") && m_componentMetadata.getAttribute("factory").equalsIgnoreCase("no")) { return; }
- Properties props = new Properties();
+
props.put("component.class", m_componentClassName);
-
- // create a ghost component
- ComponentManagerImpl ghost = new ComponentManagerImpl(this, m_bundleContext);
- ghost.configure(m_componentMetadata, new Properties());
- m_componentInfo = ghost.getComponentInfo();
-
- props.put("component.providedServiceSpecifications", m_componentInfo.getprovidedServiceSpecification());
- props.put("component.properties", m_componentInfo.getProperties());
- props.put("component.information", m_componentInfo.toString());
-
+ props.put("component.providedServiceSpecifications", m_componentDesc.getprovidedServiceSpecification());
+ props.put("component.properties", m_componentDesc.getProperties());
+ props.put("component.description", m_componentDesc);
+ props.put("component.desc", m_componentDesc.toString());
+
// Add Facotry PID to the component properties
props.put(Constants.SERVICE_PID, m_factoryName);
// Exposition of the factory service
- m_sr = m_bundleContext.registerService(new String[] {Factory.class.getName(), ManagedServiceFactory.class.getName()}, this, props);
+ m_sr = m_context.registerService(new String[] {Factory.class.getName(), ManagedServiceFactory.class.getName()}, this, props);
}
/**
* @see org.apache.felix.ipojo.Factory#getComponentInfo()
*/
- public ComponentInfo getComponentInfo() { return m_componentInfo; }
+ public ComponentDescription getComponentDescription() { return m_componentDesc; }
/**
* Load a class.
@@ -257,22 +260,18 @@
* @throws ClassNotFoundException : happen when the class is not found
*/
public Class loadClass(String className) throws ClassNotFoundException {
- Activator.getLogger().log(Level.INFO, "[Bundle " + m_bundleContext.getBundle().getBundleId() + "] In load for : " + className);
- if (m_clazz != null && className.equals(m_componentClassName)) {
+ getLogger().log(Logger.INFO, "[Bundle " + m_context.getBundle().getBundleId() + "] In load for : " + className);
+ if (m_clazz != null && className.equals(m_componentClassName)) { // Used the factory classloader to load the component implementation class
if (m_classLoader == null) {
- Activator.getLogger().log(Level.INFO, "[Bundle " + m_bundleContext.getBundle().getBundleId() + "] Create the FactoryClassLoader for : " + className);
m_classLoader = new FactoryClassloader();
}
try {
- Class c = m_classLoader.defineClass(m_componentClassName, m_clazz, null);
- Activator.getLogger().log(Level.INFO, "[Bundle " + m_bundleContext.getBundle().getBundleId() + "] Return " + c + " for " + className);
- return c;
+ return m_classLoader.defineClass(m_componentClassName, m_clazz, null);
} catch (Exception e) {
- Activator.getLogger().log(Level.SEVERE, "[Bundle " + m_bundleContext.getBundle().getBundleId() + "] Cannot define the class : " + className);
- return null;
+ throw new ClassNotFoundException("[Bundle " + m_context.getBundle().getBundleId() + "] Cannot define the class : " + className, e);
}
}
- return m_bundleContext.getBundle().loadClass(className);
+ return m_context.getBundle().loadClass(className);
}
/**
@@ -281,45 +280,54 @@
* @return the URL of the resource
*/
public URL getResource(String resName) {
- return m_bundleContext.getBundle().getResource(resName);
+ return m_context.getBundle().getResource(resName);
}
/**
- * @see org.apache.felix.ipojo.Factory#createComponent(java.util.Dictionary)
+ * @see org.apache.felix.ipojo.Factory#createComponentInstance(java.util.Dictionary)
*/
- public ComponentManager createComponent(Dictionary configuration) {
- Activator.getLogger().log(Level.INFO, "[Bundle " + m_bundleContext.getBundle().getBundleId() + "] Create a component and start it");
- IPojoContext context = new IPojoContext(m_bundleContext);
- ComponentManagerImpl component = new ComponentManagerImpl(this, context);
- context.setComponentInstance(component);
- component.configure(m_componentMetadata, configuration);
+ public ComponentInstance createComponentInstance(Dictionary configuration) {
+ if(!isAcceptable(configuration)) {
+ m_logger.log(Logger.ERROR, "The configuration is not acceptable");
+ return null;
+ }
+
+ IPojoContext context = new IPojoContext(m_context);
+ InstanceManager instance = new InstanceManager(this, context);
+ context.setComponentInstance(instance);
+ instance.configure(m_componentMetadata, configuration);
String pid = null;
if (configuration.get("name") != null) { pid = (String) configuration.get("name"); }
else { pid = m_componentMetadata.getAttribute("className"); }
- m_componentManagers.put(pid, component);
- component.start();
- return component;
+ m_componentInstances.put(pid, instance);
+ instance.start();
+ return instance;
}
/**
- * @see org.apache.felix.ipojo.Factory#createComponent(java.util.Dictionary)
+ * @see org.apache.felix.ipojo.Factory#createComponentInstance(java.util.Dictionary)
*/
- public ComponentManager createComponent(Dictionary configuration, ServiceContext serviceContext) {
- Activator.getLogger().log(Level.INFO, "[Bundle " + m_bundleContext.getBundle().getBundleId() + "] Create a component and start it");
- IPojoContext context = new IPojoContext(m_bundleContext, serviceContext);
- ComponentManagerImpl component = new ComponentManagerImpl(this, context);
- context.setComponentInstance(component);
- component.configure(m_componentMetadata, configuration);
+ public ComponentInstance createComponentInstance(Dictionary configuration, ServiceContext serviceContext) {
+ if(!isAcceptable(configuration)) {
+ //TODO : extend the message with infomation about the non acceptability
+ m_logger.log(Logger.ERROR, "The configuration is not acceptable");
+ return null;
+ }
+
+ IPojoContext context = new IPojoContext(m_context, serviceContext);
+ InstanceManager instance = new InstanceManager(this, context);
+ context.setComponentInstance(instance);
+ instance.configure(m_componentMetadata, configuration);
String pid = null;
if (configuration.get("name") != null) { pid = (String) configuration.get("name"); }
else { pid = m_componentMetadata.getAttribute("className"); }
- m_componentManagers.put(pid, component);
- component.start();
- return component;
+ m_componentInstances.put(pid, instance);
+ instance.start();
+ return instance;
}
@@ -328,7 +336,7 @@
* @see org.osgi.service.cm.ManagedServiceFactory#deleted(java.lang.String)
*/
public void deleted(String pid) {
- ComponentManagerImpl cm = (ComponentManagerImpl) m_componentManagers.remove(pid);
+ InstanceManager cm = (InstanceManager) m_componentInstances.remove(pid);
if (cm == null) { return; } // do nothing, the component does not exist !
else { cm.stop(); }
}
@@ -342,8 +350,8 @@
* @see org.osgi.service.cm.ManagedServiceFactory#updated(java.lang.String, java.util.Dictionary)
*/
public void updated(String pid, Dictionary properties) throws ConfigurationException {
- ComponentManagerImpl cm = (ComponentManagerImpl) m_componentManagers.get(pid);
- if (cm == null) { createComponent(properties); } // Create the component
+ InstanceManager cm = (InstanceManager) m_componentInstances.get(pid);
+ if (cm == null) { createComponentInstance(properties); } // Create the component
else {
cm.stop(); // Stop the component
cm.configure(m_componentMetadata, properties); // re-configure the component
@@ -360,16 +368,18 @@
* Check if the given configuration is acceptable as a component instance configuration.
* This checks that a name is given in the configuration and if all the configurable properties have a value.
* @param conf : the configuration to check
- * @return true when the configuration is acceptable
+ * @return true when the configuration seems to be acceptable
*/
public boolean isAcceptable(Dictionary conf) {
// First check that the configuration contains a name :
if(conf.get("name") == null) { return false; }
- List props = m_componentInfo.getProperties();
- for(int i = 0; i < props.size(); i++) {
- PropertyInfo pi = (PropertyInfo) props.get(i);
+ PropertyDescription[] props = m_componentDesc.getProperties();
+ for(int i = 0; i < props.length; i++) {
+ PropertyDescription pd = props[i];
// Failed if the props has no default value and the configuration does not push a value
- if(pi.getValue() == null && conf.get(pi.getName()) == null) { return false; }
+ if(pd.getValue() == null && conf.get(pd.getName()) == null) {
+ return false;
+ }
}
return true;
}
diff --git a/ipojo/src/main/java/org/apache/felix/ipojo/ComponentInfo.java b/ipojo/src/main/java/org/apache/felix/ipojo/ComponentInfo.java
deleted file mode 100644
index 7d10e41..0000000
--- a/ipojo/src/main/java/org/apache/felix/ipojo/ComponentInfo.java
+++ /dev/null
@@ -1,95 +0,0 @@
-/*
- * 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;
-
-import java.util.ArrayList;
-import java.util.List;
-/**
- * Component Type information.
- * @author <a href="mailto:felix-dev@incubator.apache.org">Felix Project Team</a>
- */
-public class ComponentInfo {
-
- /**
- * Provided service by the component type.
- */
- private ArrayList m_providedServiceSpecification = new ArrayList();
-
- /**
- * Component Type implementation class.
- */
- private String m_className;
-
- /**
- * Configuration Properties accepted by the component type.
- */
- private ArrayList m_properties = new ArrayList();
-
- /**
- * @see java.lang.Object#toString()
- */
- public String toString() {
- String res = "";
- res += "Component : " + m_className + "\n";
- for (int i = 0; i < m_providedServiceSpecification.size(); i++) {
- res += "\tProvides : " + (String) m_providedServiceSpecification.get(i) + "\n";
- }
- for (int i = 0; i < m_properties.size(); i++) {
- res += "\tProperty : " + (PropertyInfo) m_properties.get(i) + "\n";
- }
- return res;
- }
-
- /**
- * @return the component type implementation class name.
- */
- public String getClassName() { return m_className; }
-
- /**
- * Set the component type implementation class name.
- * @param name : the name of the implementation class
- */
- protected void setClassName(String name) { m_className = name; }
-
- /**
- * @return the list of configuration properties accepted by the component type.
- */
- public List getProperties() { return m_properties; }
-
- /**
- * Add a configuration properties to the component type.
- * @param pi : the property to add
- */
- public void addProperty(PropertyInfo pi) { this.m_properties.add(pi); }
-
- /**
- * @return the list of the provided service.
- */
- public List getprovidedServiceSpecification() { return m_providedServiceSpecification; }
-
- /**
- * add a provided service to the component type.
- * @param serviceSpecification : the provided service to add (interface name)
- */
- public void addProvidedServiceSpecification(String serviceSpecification) { m_providedServiceSpecification.add(serviceSpecification); }
-
-
-
-
-}
diff --git a/ipojo/src/main/java/org/apache/felix/ipojo/ComponentManager.java b/ipojo/src/main/java/org/apache/felix/ipojo/ComponentInstance.java
similarity index 69%
rename from ipojo/src/main/java/org/apache/felix/ipojo/ComponentManager.java
rename to ipojo/src/main/java/org/apache/felix/ipojo/ComponentInstance.java
index b580ed6..4e44aff 100644
--- a/ipojo/src/main/java/org/apache/felix/ipojo/ComponentManager.java
+++ b/ipojo/src/main/java/org/apache/felix/ipojo/ComponentInstance.java
@@ -18,65 +18,62 @@
*/
package org.apache.felix.ipojo;
+import org.apache.felix.ipojo.architecture.ComponentDescription;
import org.osgi.framework.BundleContext;
/**
- * The component manager class manages one instance of a component type.
+ * The component instance class manages one instance of a component type.
* @author <a href="mailto:felix-dev@incubator.apache.org">Felix Project Team</a>
*/
-public interface ComponentManager {
+public interface ComponentInstance {
/**
- * Component State : INVALID.
+ * Component Instance State : INVALID.
* The component is invalid when it start or when a component dependency is unvalid.
*/
int INVALID = 1;
/**
- * Component State : VALID.
+ * Component Instance State : VALID.
* The component is resolved when it is running and all its component dependencies are valid.
*/
int VALID = 2;
/**
- * Start the component manager.
+ * Start the component instance.
*/
void start();
/**
- * Stop the component manager.
+ * Stop the component instance.
*/
void stop();
/**
- * @return the actual state of the component.
+ * @return the actual state of the component instance.
*/
int getState();
/**
* @return the component type information.
+ * Each handler can participate to the component description.
*/
- ComponentInfo getComponentInfo();
+ ComponentDescription getComponentDescription();
/**
- * @return the component metadata.
+ * @return the factory of the component instance.
*/
- ComponentMetadata getComponentMetatada();
-
- /**
- * @return the factory of the component
- */
- ComponentManagerFactory getFactory();
+ ComponentFactory getFactory();
/**
- * @return the context of the component manager
+ * @return the context of the instance manager
*/
BundleContext getContext();
/**
* @return the name of the component instance
*/
- String getName();
+ String getInstanceName();
}
diff --git a/ipojo/src/main/java/org/apache/felix/ipojo/ComponentMetadata.java b/ipojo/src/main/java/org/apache/felix/ipojo/ComponentMetadata.java
deleted file mode 100644
index dc0c43f..0000000
--- a/ipojo/src/main/java/org/apache/felix/ipojo/ComponentMetadata.java
+++ /dev/null
@@ -1,75 +0,0 @@
-/*
- * 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;
-
-import java.util.logging.Level;
-
-import org.apache.felix.ipojo.metadata.Element;
-
-/**
- * Component Metadata.
- * @author <a href="mailto:felix-dev@incubator.apache.org">Felix Project Team</a>
- */
-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; }
-
-}
diff --git a/ipojo/src/main/java/org/apache/felix/ipojo/ServiceContextImpl.java b/ipojo/src/main/java/org/apache/felix/ipojo/DefaultServiceContext.java
similarity index 88%
rename from ipojo/src/main/java/org/apache/felix/ipojo/ServiceContextImpl.java
rename to ipojo/src/main/java/org/apache/felix/ipojo/DefaultServiceContext.java
index 55b3f58..4245db5 100644
--- a/ipojo/src/main/java/org/apache/felix/ipojo/ServiceContextImpl.java
+++ b/ipojo/src/main/java/org/apache/felix/ipojo/DefaultServiceContext.java
@@ -26,13 +26,13 @@
import org.osgi.framework.ServiceReference;
import org.osgi.framework.ServiceRegistration;
-public class ServiceContextImpl implements ServiceContext {
+public class DefaultServiceContext implements ServiceContext {
private BundleContext m_context;
- private ComponentManagerImpl m_instance;
+ private ComponentInstance m_instance;
- public ServiceContextImpl(BundleContext bc) { m_context = bc; }
+ public DefaultServiceContext(BundleContext bc) { m_context = bc; }
public void addServiceListener(ServiceListener listener, String filter)
throws InvalidSyntaxException {
@@ -80,10 +80,10 @@
return m_context.ungetService(reference);
}
- public ComponentManager getComponentInstance() {
+ public ComponentInstance getComponentInstance() {
return m_instance;
}
- public void setComponentInstance(ComponentManager cm) { m_instance = (ComponentManagerImpl) cm; }
+ public void setComponentInstance(ComponentInstance ci) { m_instance = ci; }
}
diff --git a/ipojo/src/main/java/org/apache/felix/ipojo/Factory.java b/ipojo/src/main/java/org/apache/felix/ipojo/Factory.java
index 9d8e8c5..66606ca 100644
--- a/ipojo/src/main/java/org/apache/felix/ipojo/Factory.java
+++ b/ipojo/src/main/java/org/apache/felix/ipojo/Factory.java
@@ -20,34 +20,36 @@
import java.util.Dictionary;
+import org.apache.felix.ipojo.architecture.ComponentDescription;
+
/**
* Component Type Factory Service.
- * This service is exposed by a component manager factory, and allows the dynamic creation of component instance.
+ * This service is exposed by a instance manager factory, and allows the dynamic creation of component instance.
* @author <a href="mailto:felix-dev@incubator.apache.org">Felix Project Team</a>
*/
public interface Factory {
/**
- * Create a component manager (i.e. component type instance).
+ * Create an instance manager (i.e. component type instance).
* @param configuration : the configuration properties for this component.
- * @return the created component manager.
+ * @return the created instance manager.
*/
- ComponentManager createComponent(Dictionary configuration);
+ ComponentInstance createComponentInstance(Dictionary configuration);
/**
- * Create a component manager (i.e. component type instance).
+ * Create an instance manager (i.e. component type instance).
* This has these service interaction in the scope given in argument.
* @param configuration : the configuration properties for this component.
* @param serviceContext : the service context of the component.
- * @return the created component manager.
+ * @return the created instance manager.
*/
- ComponentManager createComponent(Dictionary configuration, ServiceContext serviceContext);
+ ComponentInstance createComponentInstance(Dictionary configuration, ServiceContext serviceContext);
/**
* Get the component type information containing provided service, configuration properties ...
* @return the compionent type information.
*/
- ComponentInfo getComponentInfo();
+ ComponentDescription getComponentDescription();
/**
* Check if the given configuration is acceptable as a configuration of a component instance.
@@ -55,5 +57,10 @@
* @return true if the configuration is acceptable
*/
boolean isAcceptable(Dictionary conf);
+
+ /**
+ * @return the name of the factory.
+ */
+ String getName();
}
diff --git a/ipojo/src/main/java/org/apache/felix/ipojo/Handler.java b/ipojo/src/main/java/org/apache/felix/ipojo/Handler.java
index d52b488..bc4081d 100644
--- a/ipojo/src/main/java/org/apache/felix/ipojo/Handler.java
+++ b/ipojo/src/main/java/org/apache/felix/ipojo/Handler.java
@@ -31,10 +31,10 @@
/**
* Configure the handler.
- * @param cm : the component manager
+ * @param im : the instance manager
* @param metadata : the metadata of the component
*/
- public abstract void configure(ComponentManagerImpl cm, Element metadata, Dictionary configuration);
+ public abstract void configure(InstanceManager im, Element metadata, Dictionary configuration);
/**
* Stop the handler : stop the management.
diff --git a/ipojo/src/main/java/org/apache/felix/ipojo/IPojoConfiguration.java b/ipojo/src/main/java/org/apache/felix/ipojo/IPojoConfiguration.java
index 9aca014..2df12ee 100644
--- a/ipojo/src/main/java/org/apache/felix/ipojo/IPojoConfiguration.java
+++ b/ipojo/src/main/java/org/apache/felix/ipojo/IPojoConfiguration.java
@@ -18,13 +18,12 @@
*/
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;
+import org.apache.felix.ipojo.util.Logger;
/**
* Activator Basic Configuration.
@@ -37,7 +36,7 @@
/**
* iPOJO logger log level.
*/
- public static final Level LOG_LEVEL = Level.WARNING;
+ public static final int LOG_LEVEL = Logger.WARNING;
/**
* Available handlers in the iPOJO bundle.
diff --git a/ipojo/src/main/java/org/apache/felix/ipojo/IPojoContext.java b/ipojo/src/main/java/org/apache/felix/ipojo/IPojoContext.java
index 07c96fd..e5dffd3 100644
--- a/ipojo/src/main/java/org/apache/felix/ipojo/IPojoContext.java
+++ b/ipojo/src/main/java/org/apache/felix/ipojo/IPojoContext.java
@@ -56,7 +56,7 @@
*/
public IPojoContext(BundleContext bc) {
m_bundleContext = bc;
- m_serviceContext = new ServiceContextImpl(bc);
+ m_serviceContext = new DefaultServiceContext(bc);
}
/**
@@ -187,15 +187,15 @@
public boolean ungetService(ServiceReference reference) { return m_serviceContext.ungetService(reference); }
/**
- * Set the component manager to the service context.
+ * Set the instance manager to the service context.
* @param cm : the component manager
*/
- public void setComponentInstance(ComponentManager cm) {m_serviceContext.setComponentInstance(cm); }
+ public void setComponentInstance(ComponentInstance ci) {m_serviceContext.setComponentInstance(ci); }
/**
- * Get the component manager from the service context.
+ * Get the instance manager from the service context.
* @return the component manager of the service context
*/
- public ComponentManager getComponentInstance() { return m_serviceContext.getComponentInstance(); }
+ public ComponentInstance getComponentInstance() { return m_serviceContext.getComponentInstance(); }
}
diff --git a/ipojo/src/main/java/org/apache/felix/ipojo/InstanceCreator.java b/ipojo/src/main/java/org/apache/felix/ipojo/InstanceCreator.java
new file mode 100644
index 0000000..a9708a7
--- /dev/null
+++ b/ipojo/src/main/java/org/apache/felix/ipojo/InstanceCreator.java
@@ -0,0 +1,142 @@
+/*
+ * 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;
+
+import java.util.Dictionary;
+
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.InvalidSyntaxException;
+import org.osgi.framework.ServiceEvent;
+import org.osgi.framework.ServiceListener;
+import org.osgi.framework.ServiceReference;
+
+/**
+ * An instance creator aims to create instances and to track their factories.
+ * It's allow to create instance from outside factories.
+ * @author <a href="mailto:felix-dev@incubator.apache.org">Felix Project Team</a>
+ */
+public class InstanceCreator implements ServiceListener {
+
+ private BundleContext m_context;
+
+
+ /**
+ * This structure aims to manage a configuration.
+ * It stores all necessary information to create an instance and to track the factory.
+ */
+ private class ManagedConfiguration {
+ Dictionary configuration;
+ String factoryName;
+ ComponentInstance instance;
+
+ public ManagedConfiguration(Dictionary conf) { configuration = conf; }
+ }
+
+
+ /**
+ * Configurations to create and maintains.
+ */
+ private ManagedConfiguration[] m_configurations;
+
+
+
+ public InstanceCreator(BundleContext context, Dictionary[] configurations) {
+ m_context = context;
+ m_configurations = new ManagedConfiguration[configurations.length];
+ for(int i = 0; i < configurations.length; i++) {
+ ManagedConfiguration conf = new ManagedConfiguration(configurations[i]);
+ m_configurations[i] = conf;
+
+ // Get the component type name :
+ System.out.println("component = " + conf.configuration.get("component"));
+ String componentType = (String) conf.configuration.get("component");
+ Factory fact = null;
+
+ try {
+ String fil = "(|(" + org.osgi.framework.Constants.SERVICE_PID + "=" + componentType + ")(component.class=" + componentType + "))";
+ ServiceReference[] refs = context.getServiceReferences(org.apache.felix.ipojo.Factory.class.getName(), fil);
+ if(refs != null) {
+ fact = (Factory) m_context.getService(refs[0]);
+ createInstance(fact, conf);
+ }
+ else {
+ System.err.println("No factory available for the type : " + componentType);
+ }
+ } catch (InvalidSyntaxException e) { e.printStackTrace(); }
+
+ }
+
+ // Register a service listenner on Factory Service
+ try {
+ m_context.addServiceListener(this, "(objectClass="+Factory.class.getName() + ")");
+ } catch (InvalidSyntaxException e) { e.printStackTrace(); }
+ }
+
+ private void createInstance(Factory fact, ManagedConfiguration config) {
+ Dictionary conf = config.configuration;
+ if(fact.isAcceptable(conf)) {
+ config.instance = fact.createComponentInstance(conf);
+ config.factoryName = fact.getName();
+ }
+ else {
+ System.err.println("A factory is available for the configuration but the configuration is not acceptable");
+ }
+ }
+
+ public void serviceChanged(ServiceEvent ev) {
+ ServiceReference ref = ev.getServiceReference();
+ String factoryName = (String) ref.getProperty(org.osgi.framework.Constants.SERVICE_PID);
+ String componentClass = (String) ref.getProperty("component.class");
+
+ if(ev.getType() == ServiceEvent.REGISTERED) { //A new factory appears
+ for(int i = 0; i < m_configurations.length; i++) {
+ if(m_configurations[i].instance == null && (m_configurations[i].configuration.get("component").equals(factoryName) || m_configurations[i].configuration.get("component").equals(componentClass))) {
+ Factory fact = (Factory) m_context.getService(ref);
+ createInstance(fact, m_configurations[i]);
+ }
+ }
+ return;
+ }
+
+ if(ev.getType() == ServiceEvent.UNREGISTERING) {
+ for(int i = 0; i < m_configurations.length; i++) {
+ if(m_configurations[i].instance != null && m_configurations[i].factoryName.equals(factoryName)) {
+ m_configurations[i].instance = null;
+ m_configurations[i].factoryName = null;
+ m_context.ungetService(ref);
+ }
+ }
+ return;
+ }
+
+ //TODO manage modification ? normally a factory should not change its property.
+ }
+
+ /**
+ * Stop all created instances
+ */
+ public void stop() {
+ for(int i = 0; i < m_configurations.length; i++) {
+ if(m_configurations[i].instance != null) { m_configurations[i].instance.stop(); }
+ m_configurations[i].instance = null;
+ }
+ m_configurations = null;
+ }
+
+}
diff --git a/ipojo/src/main/java/org/apache/felix/ipojo/ComponentManagerImpl.java b/ipojo/src/main/java/org/apache/felix/ipojo/InstanceManager.java
similarity index 65%
rename from ipojo/src/main/java/org/apache/felix/ipojo/ComponentManagerImpl.java
rename to ipojo/src/main/java/org/apache/felix/ipojo/InstanceManager.java
index 542c95c..d7526e2 100644
--- a/ipojo/src/main/java/org/apache/felix/ipojo/ComponentManagerImpl.java
+++ b/ipojo/src/main/java/org/apache/felix/ipojo/InstanceManager.java
@@ -22,32 +22,38 @@
import java.lang.reflect.InvocationTargetException;
import java.util.Dictionary;
import java.util.HashMap;
-import java.util.logging.Level;
+import org.apache.felix.ipojo.architecture.ComponentDescription;
import org.apache.felix.ipojo.metadata.Element;
+import org.apache.felix.ipojo.util.Logger;
import org.osgi.framework.BundleContext;
/**
- * The component manager implementation class manages one instance of a component type.
+ * The instance manager class manages one instance of a component type.
* It manages component lifecycle, component instance creation and handlers.
* @author <a href="mailto:felix-dev@incubator.apache.org">Felix Project Team</a>
*/
-public class ComponentManagerImpl implements ComponentManager {
+public class InstanceManager implements ComponentInstance {
/**
- * Parent factory (ComponentManagerFactory).
+ * Parent factory (ComponentFactory).
*/
- private ComponentManagerFactory m_factory;
-
- /**
- * Attached metadata of the managed component.
- */
- private ComponentMetadata m_metadata;
+ private ComponentFactory m_factory;
/**
* Name of the component instance.
*/
private String m_name;
+
+ /**
+ * Name of the component type implementation class.
+ */
+ private String m_className;
+
+ /**
+ * Is the component an immediate component ?
+ */
+ private boolean m_isImmediate = false;
/**
* The context of the component.
@@ -69,8 +75,6 @@
*/
private int m_state = INVALID;
- // Fields use for the manipulation, the loading of the class and for the instance creation
-
/**
* Manipulatd clazz.
*/
@@ -79,44 +83,46 @@
/**
* Instances of the components.
*/
- private Object[] m_instances = new Object[0];
+ private Object[] m_pojoObjects = new Object[0];
/**
* Component type information.
*/
- private ComponentInfo m_componentInfo;
+ private ComponentDescription m_componentDesc;
// Constructor
/**
* Construct a new Component Manager.
- * @param factory : the factory managing the component manager
+ * @param factory : the factory managing the instance manager
*/
- public ComponentManagerImpl(ComponentManagerFactory factory, BundleContext bc) {
+ public InstanceManager(ComponentFactory factory, BundleContext bc) {
m_factory = factory;
m_context = bc;
- Activator.getLogger().log(Level.INFO, "[Bundle " + m_context.getBundle().getBundleId() + "] Create a component manager from the factory " + m_factory);
+ m_factory.getLogger().log(Logger.INFO, "[Bundle " + m_context.getBundle().getBundleId() + "] Create an instance manager from the factory " + m_factory);
}
/**
- * Configure the component manager.
+ * Configure the instance manager.
* Stop the existings handler, clear the handler list, change the metadata, recreate the handlers
* @param cm
*/
public void configure(Element cm, Dictionary configuration) {
- 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);
+ // Set the component-type metadata
+ m_className = cm.getAttribute("className");
+ if (m_className == null) {
+ m_factory.getLogger().log(Logger.ERROR, "The class name of the component cannot be setted, it does not exist in the metadata");
+ }
+ if (cm.containsAttribute("immediate") && cm.getAttribute("immediate").equalsIgnoreCase("true")) { m_isImmediate = true; }
// ComponentInfo initialization
- m_componentInfo = new ComponentInfo();
- m_componentInfo.setClassName(m_metadata.getClassName());
+ m_componentDesc = new ComponentDescription();
+ m_componentDesc.setClassName(m_className);
// Add the name
m_name = (String) configuration.get("name");
@@ -128,27 +134,26 @@
Handler h = (Handler) IPojoConfiguration.INTERNAL_HANDLERS[i].newInstance();
h.configure(this, cm, configuration);
} catch (InstantiationException e) {
- Activator.getLogger().log(Level.SEVERE, "[" + m_metadata.getClassName() + "] Cannot instantiate the handler " + IPojoConfiguration.INTERNAL_HANDLERS[i] + " : " + e.getMessage());
+ m_factory.getLogger().log(Logger.ERROR, "[" + m_className + "] 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());
+ m_factory.getLogger().log(Logger.ERROR, "[" + m_className + "] 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]);
Handler h = (Handler) c.newInstance();
h.configure(this, cm, configuration);
} catch (ClassNotFoundException e) {
- Activator.getLogger().log(Level.SEVERE, "[" + m_metadata.getClassName() + "] Cannot instantiate the handler " + cm.getNamespaces()[i] + " : " + e.getMessage());
+ m_factory.getLogger().log(Logger.ERROR, "[" + m_className + "] 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());
+ m_factory.getLogger().log(Logger.ERROR, "[" + m_className + "] 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());
+ m_factory.getLogger().log(Logger.ERROR, "[" + m_className + "] Cannot instantiate the handler " + cm.getNamespaces()[i] + " : " + e.getMessage());
}
}
@@ -159,12 +164,7 @@
/**
* @return the component type information.
*/
- public ComponentInfo getComponentInfo() { return m_componentInfo; }
-
- /**
- * @return the component metadata.
- */
- public ComponentMetadata getComponentMetatada() { return m_metadata; }
+ public ComponentDescription getComponentDescription() { return m_componentDesc; }
/**
* @return the list of the registred handlers.
@@ -187,15 +187,17 @@
* @return the component instance name.
*/
public String getComponentName() { return m_name; }
+
+ public String getClassName() { return m_className; }
// ===================== Lifecycle management =====================
/**
- * Start the component manager.
+ * Start the instance 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");
+ m_factory.getLogger().log(Logger.INFO, "[" + m_className + "] Start the instance manager with " + m_handlers.length + " handlers");
// The new state of the component is UNRESOLVED
m_state = INVALID;
@@ -205,11 +207,11 @@
}
// Defines the state of the component :
- checkComponentState();
+ checkInstanceState();
}
/**
- * Stop the component manager.
+ * Stop the instance manager.
*/
public void stop() {
setState(INVALID);
@@ -217,7 +219,7 @@
for (int i = m_handlers.length - 1; i > -1; i--) {
m_handlers[i].stop();
}
- m_instances = new Object[0];
+ m_pojoObjects = new Object[0];
}
/**
@@ -228,8 +230,8 @@
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"); }
+ if (state == INVALID) { m_factory.getLogger().log(Logger.INFO, "[" + m_className + "] State -> UNRESOLVED"); }
+ if (state == VALID) { m_factory.getLogger().log(Logger.INFO, "[" + m_className + "] State -> VALID"); }
// The state changed call the handler stateChange method
m_state = state;
@@ -253,16 +255,16 @@
/**
* @return the factory of the component
*/
- public ComponentManagerFactory getFactory() { return m_factory; }
+ public ComponentFactory getFactory() { return m_factory; }
/**
* Load the manipulated class.
*/
private void load() {
try {
- m_clazz = m_factory.loadClass(m_metadata.getClassName());
+ m_clazz = m_factory.loadClass(m_className);
} catch (ClassNotFoundException e) {
- Activator.getLogger().log(Level.SEVERE, "[" + m_metadata.getClassName() + "] Class not found during the loading phase : " + e.getMessage());
+ m_factory.getLogger().log(Logger.ERROR, "[" + m_className + "] Class not found during the loading phase : " + e.getMessage());
return;
}
}
@@ -279,18 +281,18 @@
* @param o : the instance to add
*/
private void addInstance(Object o) {
- for (int i = 0; (m_instances != null) && (i < m_instances.length); i++) {
- if (m_instances[i] == o) { return; }
+ for (int i = 0; (m_pojoObjects != null) && (i < m_pojoObjects.length); i++) {
+ if (m_pojoObjects[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;
+ if (m_pojoObjects.length > 0) {
+ Object[] newInstances = new Object[m_pojoObjects.length + 1];
+ System.arraycopy(m_pojoObjects, 0, newInstances, 0, m_pojoObjects.length);
+ newInstances[m_pojoObjects.length] = o;
+ m_pojoObjects = newInstances;
}
else {
- m_instances = new Object[] {o};
+ m_pojoObjects = new Object[] {o};
}
}
@@ -300,18 +302,18 @@
*/
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; }
+ for (int i = 0; i < m_pojoObjects.length; i++) {
+ if (m_pojoObjects[i] == o) { idx = i; break; }
}
if (idx >= 0) {
- if ((m_instances.length - 1) == 0) { m_instances = new Element[0]; }
+ if ((m_pojoObjects.length - 1) == 0) { m_pojoObjects = new Element[0]; }
else {
- Object[] newInstances = new Object[m_instances.length - 1];
- System.arraycopy(m_instances, 0, newInstances, 0, idx);
+ Object[] newInstances = new Object[m_pojoObjects.length - 1];
+ System.arraycopy(m_pojoObjects, 0, newInstances, 0, idx);
if (idx < newInstances.length) {
- System.arraycopy(m_instances, idx + 1, newInstances, idx, newInstances.length - idx); }
- m_instances = newInstances;
+ System.arraycopy(m_pojoObjects, idx + 1, newInstances, idx, newInstances.length - idx); }
+ m_pojoObjects = newInstances;
}
}
}
@@ -319,62 +321,59 @@
/**
* @return the created instance of the component.
*/
- public Object[] getInstances() { return m_instances; }
+ public Object[] getPojoObjects() { return m_pojoObjects; }
/**
* 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); }
+ public void deletePojoObject(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() {
+ public Object createPojoObject() {
if (!isLoaded()) { load(); }
Object instance = null;
try {
- Activator.getLogger().log(Level.INFO, "[" + m_metadata.getClassName() + "] createInstance -> Try to find the constructor");
+ m_factory.getLogger().log(Logger.INFO, "[" + m_className + "] 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[] {ComponentManagerImpl.class, BundleContext.class});
+ Constructor constructor = m_clazz.getConstructor(new Class[] {InstanceManager.class, BundleContext.class});
constructor.setAccessible(true);
instance = constructor.newInstance(new Object[] {this, m_context});
}
- catch (NoSuchMethodException e) {
- Activator.getLogger().log(Level.INFO, "[" + m_metadata.getClassName() + "] createInstance -> No constructor with a bundle context");
- }
+ catch (NoSuchMethodException e) { }
// 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) {
- Constructor constructor = m_clazz.getConstructor(new Class[] {ComponentManagerImpl.class});
+ Constructor constructor = m_clazz.getConstructor(new Class[] {InstanceManager.class});
constructor.setAccessible(true);
instance = constructor.newInstance(new Object[] {this});
}
} catch (InstantiationException e) {
- Activator.getLogger().log(Level.SEVERE, "[" + m_metadata.getClassName() + "] createInstance -> The Component Instance cannot be instancied : " + e.getMessage());
+ m_factory.getLogger().log(Logger.ERROR, "[" + m_className + "] 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());
+ m_factory.getLogger().log(Logger.ERROR, "[" + m_className + "] 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());
+ m_factory.getLogger().log(Logger.ERROR, "[" + m_className + "] createInstance -> The Component Instance is not accessible (security reason) : " + e.getMessage());
e.printStackTrace();
} catch (InvocationTargetException e) {
- Activator.getLogger().log(Level.SEVERE, "[" + m_metadata.getClassName() + "] createInstance -> Cannot invoke the constructor method (illegal target) : " + e.getMessage());
+ m_factory.getLogger().log(Logger.ERROR, "[" + m_className + "] createInstance -> Cannot invoke the constructor method (illegal target) : " + e.getMessage());
e.printStackTrace();
} catch (NoSuchMethodException e) {
- Activator.getLogger().log(Level.SEVERE, "[" + m_metadata.getClassName() + "] createInstance -> Cannot invoke the constructor (method not found) : " + e.getMessage());
+ m_factory.getLogger().log(Logger.ERROR, "[" + m_className + "] createInstance -> Cannot invoke the constructor (method not found) : " + e.getMessage());
e.printStackTrace();
}
- Activator.getLogger().log(Level.INFO, "[" + m_metadata.getClassName() + "] createInstance -> Return the instance " + instance);
+ m_factory.getLogger().log(Logger.INFO, "[" + m_className + "] createInstance -> Return the instance " + instance);
// Register the new instance
addInstance(instance);
@@ -386,9 +385,9 @@
/**
* @return the instance of the component to use for singleton component
*/
- public Object getInstance() {
- if (m_instances.length == 0) { createInstance(); }
- return m_instances[0];
+ public Object getPojoObject() {
+ if (m_pojoObjects.length == 0) { createPojoObject(); }
+ return m_pojoObjects[0];
}
/**
@@ -404,7 +403,7 @@
// ======================== Handlers Management ======================
/**
- * Register the given handler to the current component manager.
+ * Register the given handler to the current instance manager.
* @param h : the handler to register
*/
public void register(Handler h) {
@@ -436,7 +435,7 @@
}
else {
Handler[] list = (Handler[]) m_fieldRegistration.get(fields[i]);
- for (int j = 0; j < list.length; i++) { if (list[i] == h) { return; } }
+ for (int j = 0; j < list.length; j++) { if (list[j] == h) { return; } }
Handler[] newList = new Handler[list.length + 1];
System.arraycopy(list, 0, newList, 0, list.length);
newList[list.length] = h;
@@ -447,7 +446,7 @@
/**
* Unregister an handler for the field list.
- * The handler will not be notified of field access but is allways register on the component manager.
+ * The handler will not be notified of field access but is allways register on the instance manager.
* @param h : the handler to unregister.
* @param fields : the fields list
*/
@@ -520,7 +519,6 @@
* @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;
// Get the list of registered handlers
Handler[] list = (Handler[]) m_fieldRegistration.get(fieldName);
@@ -530,10 +528,8 @@
}
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;
}
}
@@ -545,7 +541,6 @@
* @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);
// Get the list of registered handlers
Handler[] list = (Handler[]) m_fieldRegistration.get(fieldName);
@@ -562,12 +557,11 @@
/**
* Check the state of all handlers.
*/
- public void checkComponentState() {
- Activator.getLogger().log(Level.INFO, "[" + m_metadata.getClassName() + "] Check the component state");
+ public void checkInstanceState() {
+ m_factory.getLogger().log(Logger.INFO, "[" + m_className + "] 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;
}
@@ -575,18 +569,18 @@
if (!isValid && m_state == VALID) {
// Need to update the state to UNRESOLVED
setState(INVALID);
- m_instances = new Object[0];
+ m_pojoObjects = new Object[0];
return;
}
if (isValid && m_state == INVALID) {
setState(VALID);
- if (m_metadata.isImmediate() && m_instances.length == 0) { createInstance(); }
+ if (m_isImmediate && m_pojoObjects.length == 0) { createPojoObject(); }
}
- Activator.getLogger().log(Level.INFO, "[" + m_metadata.getClassName() + "] Component Manager : " + m_state);
+ m_factory.getLogger().log(Logger.INFO, "[" + m_className + "] Component Manager : " + m_state);
}
- public String getName() { return m_name; }
+ public String getInstanceName() { return m_name; }
// ======================= end Handlers Management =====================
diff --git a/ipojo/src/main/java/org/apache/felix/ipojo/ServiceContext.java b/ipojo/src/main/java/org/apache/felix/ipojo/ServiceContext.java
index 34ed9b8..e384882 100644
--- a/ipojo/src/main/java/org/apache/felix/ipojo/ServiceContext.java
+++ b/ipojo/src/main/java/org/apache/felix/ipojo/ServiceContext.java
@@ -47,8 +47,8 @@
boolean ungetService(ServiceReference reference);
- ComponentManager getComponentInstance();
+ ComponentInstance getComponentInstance();
- void setComponentInstance(ComponentManager cm);
+ void setComponentInstance(ComponentInstance ci);
}
diff --git a/ipojo/src/main/java/org/apache/felix/ipojo/architecture/Architecture.java b/ipojo/src/main/java/org/apache/felix/ipojo/architecture/Architecture.java
index 6ef826d..774d5dd 100644
--- a/ipojo/src/main/java/org/apache/felix/ipojo/architecture/Architecture.java
+++ b/ipojo/src/main/java/org/apache/felix/ipojo/architecture/Architecture.java
@@ -26,9 +26,9 @@
public interface Architecture {
/**
- * Return the full architecture.
- * @return : the current component description
+ * Return the description of the instance.
+ * @return : the current component instance description
*/
- ComponentDescription getComponentDescription();
+ InstanceDescription getInstanceDescription();
}
diff --git a/ipojo/src/main/java/org/apache/felix/ipojo/architecture/InstanceDescription.java b/ipojo/src/main/java/org/apache/felix/ipojo/architecture/InstanceDescription.java
new file mode 100644
index 0000000..1604f17
--- /dev/null
+++ b/ipojo/src/main/java/org/apache/felix/ipojo/architecture/InstanceDescription.java
@@ -0,0 +1,132 @@
+/*
+ * 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.architecture;
+
+/**
+ * Instance Description.
+ * @author <a href="mailto:felix-dev@incubator.apache.org">Felix Project Team</a>
+ */
+public class InstanceDescription {
+
+ /**
+ * The Component class name.
+ * This String is the identifier of the component.
+ */
+ private String m_className;
+
+ /**
+ * The name of the component (instance).
+ */
+ private String m_name;
+
+ /**
+ * Handlers of the component instance.
+ */
+ private HandlerDescription[] m_handlers = new HandlerDescription[0];
+
+ /**
+ * Created Instances of the components.
+ */
+ private String[] m_createdObjects = new String[0];
+
+ /**
+ * State of the component (VALID / UNRESOLVED).
+ */
+ private int m_state;
+
+ /**
+ * BundleId of the component.
+ */
+ private long m_bundleId;
+
+ /**
+ * Constructor.
+ * @param name : the name of the component (the class name).
+ * @param state : the state of the component.
+ */
+ public InstanceDescription(String name, String className, int state, long bundleId) {
+ m_name = name;
+ m_className = className;
+ m_state = state;
+ m_createdObjects = new String[0];
+ m_handlers = new HandlerDescription[0];
+ m_bundleId = bundleId;
+ }
+
+ /**
+ * @return the name of the component.
+ */
+ public String getName() { return m_name; }
+
+ /**
+ * @return the created instances
+ */
+ public String[] getCreatedObjects() { return m_createdObjects; }
+
+ /**
+ * Set the instances array.
+ */
+ public void setCreatedObjects(String[] objects) { m_createdObjects = objects; }
+
+ /**
+ * @return : the class name of the component
+ */
+ public String getClassName() { return m_className; }
+
+ /**
+ * @return the live handler list
+ */
+ public HandlerDescription[] getHandlers() { return m_handlers; }
+
+ /**
+ * Add an handler description to the list.
+ * @param hd : the handler description to add
+ */
+ public void addHandler(HandlerDescription hd) {
+ // Verify that the dependency description is not already in the array.
+ for (int i = 0; (i < m_handlers.length); i++) {
+ if (m_handlers[i] == hd) {
+ return; //NOTHING TO DO, the description is already in the array
+ }
+ }
+ // The component Description is not in the array, add it
+ HandlerDescription[] newHd = new HandlerDescription[m_handlers.length + 1];
+ System.arraycopy(m_handlers, 0, newHd, 0, m_handlers.length);
+ newHd[m_handlers.length] = hd;
+ m_handlers = newHd;
+ }
+
+ /**
+ * 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; }
+
+ /**
+ * @return the bundle id owning the component implementation class.
+ */
+ public long getBundleId() { return m_bundleId; }
+
+
+}
diff --git a/ipojo/src/main/java/org/apache/felix/ipojo/PropertyInfo.java b/ipojo/src/main/java/org/apache/felix/ipojo/architecture/PropertyDescription.java
similarity index 85%
rename from ipojo/src/main/java/org/apache/felix/ipojo/PropertyInfo.java
rename to ipojo/src/main/java/org/apache/felix/ipojo/architecture/PropertyDescription.java
index ab16b0f..e49068c 100644
--- a/ipojo/src/main/java/org/apache/felix/ipojo/PropertyInfo.java
+++ b/ipojo/src/main/java/org/apache/felix/ipojo/architecture/PropertyDescription.java
@@ -16,13 +16,13 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.apache.felix.ipojo;
+package org.apache.felix.ipojo.architecture;
/**
* Property Information.
* @author <a href="mailto:felix-dev@incubator.apache.org">Felix Project Team</a>
*/
-public class PropertyInfo {
+public class PropertyDescription {
/**
* Name of the property.
@@ -38,6 +38,8 @@
* Default value of the property.
*/
private String m_value = null;
+
+ private boolean m_needed;
/**
* Constructor.
@@ -45,7 +47,7 @@
* @param type : type of the property
* @param value : default value of the property
*/
- public PropertyInfo(String name, String type, String value) {
+ public PropertyDescription(String name, String type, String value) {
m_name = name;
m_type = type;
m_value = value;
@@ -55,6 +57,11 @@
* @return the property name.
*/
public String getName() { return m_name; }
+
+ /**
+ * @return true is the property need to be configured.
+ */
+ public boolean isNeeded() { return m_needed; }
/**
* @return the property type.
diff --git a/ipojo/src/main/java/org/apache/felix/ipojo/architecture/ProvidedServiceDescription.java b/ipojo/src/main/java/org/apache/felix/ipojo/architecture/ProvidedServiceDescription.java
index 579147f..00c1ada 100644
--- a/ipojo/src/main/java/org/apache/felix/ipojo/architecture/ProvidedServiceDescription.java
+++ b/ipojo/src/main/java/org/apache/felix/ipojo/architecture/ProvidedServiceDescription.java
@@ -51,7 +51,7 @@
/**
* Handler on the component description who contains this description.
*/
- private ComponentDescription m_parent;
+ private InstanceDescription m_parent;
/**
* Properties of the provided service.
@@ -66,7 +66,7 @@
* @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) {
+ public ProvidedServiceDescription(String[] serviceSpecification, int state, ServiceReference sr, InstanceDescription parent) {
m_serviceSpecification = serviceSpecification;
m_state = state;
m_serviceReference = sr;
@@ -81,24 +81,6 @@
}
/**
- * 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
@@ -146,7 +128,7 @@
/**
* @return the parent description.
*/
- public ComponentDescription getComponentDescription() {
+ public InstanceDescription getInstanceDescription() {
return m_parent;
}
diff --git a/ipojo/src/main/java/org/apache/felix/ipojo/handlers/architecture/ArchitectureHandler.java b/ipojo/src/main/java/org/apache/felix/ipojo/handlers/architecture/ArchitectureHandler.java
index 971a498..6f7ff76 100644
--- a/ipojo/src/main/java/org/apache/felix/ipojo/handlers/architecture/ArchitectureHandler.java
+++ b/ipojo/src/main/java/org/apache/felix/ipojo/handlers/architecture/ArchitectureHandler.java
@@ -21,23 +21,21 @@
import java.util.Dictionary;
import java.util.Properties;
-import org.apache.felix.ipojo.ComponentManagerImpl;
import org.apache.felix.ipojo.Handler;
+import org.apache.felix.ipojo.InstanceManager;
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.DependencyHandlerDescription;
import org.apache.felix.ipojo.architecture.HandlerDescription;
+import org.apache.felix.ipojo.architecture.InstanceDescription;
import org.apache.felix.ipojo.architecture.ProvidedServiceDescription;
import org.apache.felix.ipojo.architecture.ProvidedServiceHandlerDescription;
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;
@@ -50,9 +48,9 @@
public class ArchitectureHandler extends Handler implements Architecture {
/**
- * Component Manager.
+ * Instance Manager.
*/
- private ComponentManagerImpl m_manager;
+ private InstanceManager m_manager;
/**
* Service Registration of the Architecture service provided by this handler.
@@ -70,19 +68,19 @@
private String m_className;
/**
- * @see org.apache.felix.ipojo.Handler#configure(org.apache.felix.ipojo.ComponentManagerImpl, org.apache.felix.ipojo.metadata.Element)
+ * @see org.apache.felix.ipojo.Handler#configure(org.apache.felix.ipojo.InstanceManager, org.apache.felix.ipojo.metadata.Element)
*/
- public void configure(ComponentManagerImpl cm, Element metadata, Dictionary configuration) {
+ public void configure(InstanceManager im, Element metadata, Dictionary configuration) {
if (metadata.containsAttribute("architecture")) {
String isArchitectureEnabled = (metadata.getAttribute("architecture")).toLowerCase();
- if (isArchitectureEnabled.equals("true")) { cm.register(this); }
+ if (isArchitectureEnabled.equalsIgnoreCase("true")) { im.register(this); }
}
m_className = metadata.getAttribute("className");
m_name = (String) configuration.get("name");
- m_manager = cm;
+ m_manager = im;
}
/**
@@ -104,7 +102,7 @@
// Register the ManagedService
BundleContext bc = m_manager.getContext();
Dictionary properties = new Properties();
- properties.put("Component Implementation Class", m_manager.getComponentMetatada().getClassName());
+ properties.put("Component.Implementation.Class", m_manager.getClassName());
properties.put(Constants.SERVICE_PID, m_name);
m_sr = bc.registerService(Architecture.class.getName(), this, properties);
@@ -114,15 +112,15 @@
/**
* @see org.apache.felix.ipojo.architecture.Architecture#getComponentDescription()
*/
- public ComponentDescription getComponentDescription() {
+ public InstanceDescription getInstanceDescription() {
int componentState = m_manager.getState();
- ComponentDescription componentDescription = new ComponentDescription(m_className, m_name, componentState, m_manager.getContext().getBundle().getBundleId());
+ InstanceDescription instanceDescription = new InstanceDescription(m_className, m_name, componentState, m_manager.getContext().getBundle().getBundleId());
- 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();
+ String[] objects = new String[m_manager.getPojoObjects().length];
+ for (int i = 0; i < m_manager.getPojoObjects().length; i++) {
+ objects[i] = m_manager.getPojoObjects()[i].toString();
}
- componentDescription.setInstances(instances);
+ instanceDescription.setCreatedObjects(objects);
Handler[] handlers = m_manager.getRegistredHandlers();
for (int i = 0; i < handlers.length; i++) {
@@ -134,11 +132,11 @@
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);
+ DependencyDescription dd = new DependencyDescription(dm.getServiceSpecification(), dm.isMultiple(), dm.isOptional(), dm.getFilter(), dep.getState(), instanceDescription);
dd.setUsedServices(dep.getUsedServices());
dhd.addDependency(dd);
}
- componentDescription.addHandler(dhd);
+ instanceDescription.addHandler(dhd);
break;
}
@@ -148,25 +146,23 @@
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);
+ ProvidedServiceDescription psd = new ProvidedServiceDescription(ps.getServiceSpecification(), ps.getState(), ps.getServiceReference(), instanceDescription);
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()); }
+ if (prop.getValue() != null) { props.put(prop.getName(), prop.getValue().toString()); }
}
psd.setProperty(props);
pshd.addProvidedService(psd);
}
- componentDescription.addHandler(pshd);
+ instanceDescription.addHandler(pshd);
break;
}
// Else add a generic handler to the description
- componentDescription.addHandler(new HandlerDescription(handlers[i].getClass().getName(), handlers[i].isValid()));
+ instanceDescription.addHandler(new HandlerDescription(handlers[i].getClass().getName(), handlers[i].isValid()));
}
- return componentDescription;
+ return instanceDescription;
}
}
diff --git a/ipojo/src/main/java/org/apache/felix/ipojo/handlers/configuration/ConfigurableProperty.java b/ipojo/src/main/java/org/apache/felix/ipojo/handlers/configuration/ConfigurableProperty.java
index 56fcb73..8430b88 100644
--- a/ipojo/src/main/java/org/apache/felix/ipojo/handlers/configuration/ConfigurableProperty.java
+++ b/ipojo/src/main/java/org/apache/felix/ipojo/handlers/configuration/ConfigurableProperty.java
@@ -21,10 +21,6 @@
import java.lang.reflect.Array;
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;
/**
* Configurable Property.
@@ -59,30 +55,13 @@
* @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) {
+ public ConfigurableProperty(String name, String field, String value, String type, 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); }
-
- }
-
- /**
- * @return the type of a configurable property.
- */
- public String getType() {
- Element manipulation = m_handler.getComponentManager().getComponentMetatada().getMetadata().getElements("Manipulation")[0];
- String type = null;
- for (int i = 0; i < manipulation.getElements("Field").length; i++) {
- if (m_field.equals(manipulation.getElements("Field")[i].getAttribute("name"))) {
- return manipulation.getElements("Field")[i].getAttribute("type");
- }
- }
-
- if (type == null) { Activator.getLogger().log(Level.SEVERE, "[" + m_handler.getComponentManager().getComponentMetatada().getClassName() + "] The field " + m_field + " does not exist in the implementation"); }
- return null;
+ if (value != null) { setValue(m_field, value, type); }
}
@@ -90,21 +69,7 @@
* 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);
-
+ private void setValue(String field, String strValue, String type) {
Object value = null;
if (type.equals("string") || type.equals("String")) { value = new String(strValue); }
@@ -127,7 +92,7 @@
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);
+ Class c = m_handler.getInstanceManager().getContext().getBundle().loadClass(type);
Constructor cst = c.getConstructor(new Class[] {String.class});
value = cst.newInstance(new Object[] {strValue});
} catch (ClassNotFoundException e) {
@@ -168,55 +133,60 @@
* @param values : new property value
*/
private void setArrayValue(String internalType, String[] values) {
- if (internalType.equals("string") || internalType.equals("String")) { m_value = values; return; }
+ if (internalType.equals("string") || internalType.equals("String")) {
+ String[] str = new String[values.length];
+ for (int i = 0; i < values.length; i++) { str[i] = new String(values[i].trim()); }
+ m_value = str;
+ return;
+ }
if (internalType.equals("boolean")) {
boolean[] bool = new boolean[values.length];
- for (int i = 0; i < values.length; i++) { bool[i] = new Boolean(values[i]).booleanValue(); }
+ for (int i = 0; i < values.length; i++) { bool[i] = new Boolean(values[i].trim()).booleanValue(); }
m_value = bool;
return;
}
if (internalType.equals("byte")) {
byte[] byt = new byte[values.length];
- for (int i = 0; i < values.length; i++) { byt[i] = new Byte(values[i]).byteValue(); }
+ for (int i = 0; i < values.length; i++) { byt[i] = new Byte(values[i].trim()).byteValue(); }
m_value = byt;
return;
}
if (internalType.equals("short")) {
short[] shor = new short[values.length];
- for (int i = 0; i < values.length; i++) { shor[i] = new Short(values[i]).shortValue(); }
+ for (int i = 0; i < values.length; i++) { shor[i] = new Short(values[i].trim()).shortValue(); }
m_value = shor;
return;
}
if (internalType.equals("int")) {
int[] in = new int[values.length];
- for (int i = 0; i < values.length; i++) { in[i] = new Integer(values[i]).intValue(); }
+ for (int i = 0; i < values.length; i++) { in[i] = new Integer(values[i].trim()).intValue(); }
m_value = in;
return;
}
if (internalType.equals("long")) {
long[] ll = new long[values.length];
- for (int i = 0; i < values.length; i++) { ll[i] = new Long(values[i]).longValue(); }
+ for (int i = 0; i < values.length; i++) { ll[i] = new Long(values[i].trim()).longValue(); }
m_value = ll;
return;
}
if (internalType.equals("float")) {
float[] fl = new float[values.length];
- for (int i = 0; i < values.length; i++) { fl[i] = new Float(values[i]).floatValue(); }
+ for (int i = 0; i < values.length; i++) { fl[i] = new Float(values[i].trim()).floatValue(); }
m_value = fl;
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(); }
+ for (int i = 0; i < values.length; i++) { dl[i] = new Double(values[i].trim()).doubleValue(); }
m_value = dl;
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 {
- Class c = m_handler.getComponentManager().getContext().getBundle().loadClass(internalType);
+ Class c = m_handler.getInstanceManager().getContext().getBundle().loadClass(internalType);
Constructor cst = c.getConstructor(new Class[] {String.class});
Object[] ob = (Object[]) Array.newInstance(c, values.length);
for (int i = 0; i < values.length; i++) {
- ob[i] = cst.newInstance(new Object[] {values[i]});
+ ob[i] = cst.newInstance(new Object[] {values[i].trim()});
}
m_value = ob;
return;
diff --git a/ipojo/src/main/java/org/apache/felix/ipojo/handlers/configuration/ConfigurationHandler.java b/ipojo/src/main/java/org/apache/felix/ipojo/handlers/configuration/ConfigurationHandler.java
index 7367cb2..72f8690 100644
--- a/ipojo/src/main/java/org/apache/felix/ipojo/handlers/configuration/ConfigurationHandler.java
+++ b/ipojo/src/main/java/org/apache/felix/ipojo/handlers/configuration/ConfigurationHandler.java
@@ -21,15 +21,14 @@
import java.util.Dictionary;
import java.util.Enumeration;
import java.util.Properties;
-import java.util.logging.Level;
-import org.apache.felix.ipojo.Activator;
-import org.apache.felix.ipojo.ComponentInfo;
-import org.apache.felix.ipojo.ComponentManagerImpl;
import org.apache.felix.ipojo.Handler;
-import org.apache.felix.ipojo.PropertyInfo;
+import org.apache.felix.ipojo.InstanceManager;
+import org.apache.felix.ipojo.architecture.ComponentDescription;
+import org.apache.felix.ipojo.architecture.PropertyDescription;
import org.apache.felix.ipojo.handlers.providedservice.ProvidedServiceHandler;
import org.apache.felix.ipojo.metadata.Element;
+import org.apache.felix.ipojo.util.Logger;
import org.osgi.framework.BundleContext;
import org.osgi.framework.Constants;
import org.osgi.framework.ServiceRegistration;
@@ -43,9 +42,9 @@
public class ConfigurationHandler extends Handler implements ManagedService {
/**
- * Reference on the component manager.
+ * Reference on the instance manager.
*/
- private ComponentManagerImpl m_manager;
+ private InstanceManager m_manager;
/**
* List of the configurable fields.
@@ -59,7 +58,7 @@
private ProvidedServiceHandler m_providedServiceHandler;
/**
- * Properties porpagated at the last "updated".
+ * Properties propagated at the last "updated".
*/
private Dictionary m_propagated = new Properties();
@@ -79,17 +78,17 @@
private ServiceRegistration m_sr;
/**
- * @return component manager of this handler.
+ * @return instance manager of this handler.
*/
- protected ComponentManagerImpl getComponentManager() { return m_manager; }
+ protected InstanceManager getInstanceManager() { return m_manager; }
/**
- * @see org.apache.felix.ipojo.Handler#configure(org.apache.felix.ipojo.ComponentManagerImpl, org.apache.felix.ipojo.metadata.Element)
+ * @see org.apache.felix.ipojo.Handler#configure(org.apache.felix.ipojo.InstanceManager, org.apache.felix.ipojo.metadata.Element)
*/
- public void configure(ComponentManagerImpl cm, Element metadata, Dictionary configuration) {
+ public void configure(InstanceManager im, Element metadata, Dictionary configuration) {
// Store the component manager
- m_manager = cm;
- ComponentInfo ci = cm.getComponentInfo();
+ m_manager = im;
+ ComponentDescription cd = im.getComponentDescription();
m_configurableProperties = new ConfigurableProperty[0];
// Build the hashmap
@@ -113,10 +112,20 @@
if (name != null && configuration.get(name) != null && configuration.get(name) instanceof String) { value = (String) configuration.get(name); }
else { if (fieldName != null && configuration.get(fieldName) != null && configuration.get(fieldName) instanceof String) { value = (String) configuration.get(fieldName); } }
- ConfigurableProperty cp = new ConfigurableProperty(name, fieldName, value, this);
-
- if (cp.getValue() != null) { ci.addProperty(new PropertyInfo(name, cp.getType(), cp.getValue().toString())); }
- else { ci.addProperty(new PropertyInfo(name, cp.getType(), "")); }
+ // Detect the type of the property
+ Element manipulation = metadata.getElements("Manipulation")[0];
+ String type = null;
+ for (int kk = 0; kk < manipulation.getElements("Field").length; kk++) {
+ if (fieldName.equals(manipulation.getElements("Field")[kk].getAttribute("name"))) {
+ type = manipulation.getElements("Field")[kk].getAttribute("type");
+ }
+ }
+ if (type == null) { m_manager.getFactory().getLogger().log(Logger.ERROR, "[" + m_manager.getClassName() + "] The field " + fieldName + " does not exist in the implementation"); return; }
+
+ ConfigurableProperty cp = new ConfigurableProperty(name, fieldName, value, type, this);
+
+ if (cp.getValue() != null) { cd.addProperty(new PropertyDescription(name, type, cp.getValue().toString())); }
+ else { cd.addProperty(new PropertyDescription(name, type, "")); }
addProperty(cp);
}
@@ -154,7 +163,7 @@
public void stop() {
// Unregister the service
if (m_isConfigurable && m_sr != null) {
- Activator.getLogger().log(Level.INFO, "[" + m_manager.getComponentMetatada().getClassName() + "] Unregister Managed Service");
+ m_manager.getFactory().getLogger().log(Logger.INFO, "[" + m_manager.getClassName() + "] Unregister Managed Service");
m_sr.unregister();
m_sr = null;
}
@@ -174,7 +183,7 @@
Dictionary properties = new Properties();
properties.put(Constants.SERVICE_PID, m_pid);
- Activator.getLogger().log(Level.INFO, "[" + m_manager.getComponentMetatada().getClassName() + "] Register Managed Service");
+ m_manager.getFactory().getLogger().log(Logger.INFO, "[" + m_manager.getClassName() + "] Register Managed Service");
m_sr = bc.registerService(ManagedService.class.getName(), this, properties);
}
}
@@ -186,8 +195,8 @@
// Verify that the field name correspond to a configurable property
for (int i = 0; i < m_configurableProperties.length; i++) {
ConfigurableProperty cp = m_configurableProperties[i];
- if (cp.getName().equals(fieldName)) {
- // Check if the value has change
+ if (cp.getField().equals(fieldName)) {
+ // Check if the value has changed
if (cp.getValue() == null || !cp.getValue().equals(value)) {
cp.setValue(value); // Change the value
}
@@ -213,11 +222,11 @@
* @see org.apache.felix.ipojo.Handler#stateChanged(int)
*/
public void stateChanged(int state) {
- if (state == ComponentManagerImpl.VALID) {
+ if (state == InstanceManager.VALID) {
if (m_sr == null) { start(); }
return;
}
- if (state == ComponentManagerImpl.INVALID) {
+ if (state == InstanceManager.INVALID) {
if (m_sr != null) { stop(); }
return;
}
@@ -239,7 +248,6 @@
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); // Useless, the setterCallback will call the setValue
m_manager.setterCallback(m_configurableProperties[i].getField(), value); // says that the value has change
}
find = true;
@@ -248,16 +256,16 @@
}
if (!find) {
//The property is not a configurable property
- Activator.getLogger().log(Level.INFO, "[" + m_manager.getComponentMetatada().getClassName() + "] The property " + name + " will be propagated to service registrations");
+ m_manager.getFactory().getLogger().log(Logger.INFO, "[" + m_manager.getClassName() + "] The property " + name + " will be propagated to service registrations");
toPropagate.put(name, value);
}
}
}
- else { Activator.getLogger().log(Level.WARNING, "[" + m_manager.getComponentMetatada().getClassName() + "] The pushed configuration is null for " + m_pid); }
+ else { m_manager.getFactory().getLogger().log(Logger.WARNING, "[" + m_manager.getClassName() + "] The pushed configuration is null for " + m_pid); }
// Propagation of the properties to service registrations :
if (m_providedServiceHandler != null && !toPropagate.isEmpty()) {
- Activator.getLogger().log(Level.INFO, "[" + m_manager.getComponentMetatada().getClassName() + "] Properties will be propagated");
+ m_manager.getFactory().getLogger().log(Logger.INFO, "[" + m_manager.getClassName() + "] Properties will be propagated");
m_providedServiceHandler.removeProperties(m_propagated);
m_providedServiceHandler.addProperties(toPropagate);
m_propagated = toPropagate;
diff --git a/ipojo/src/main/java/org/apache/felix/ipojo/handlers/dependency/Dependency.java b/ipojo/src/main/java/org/apache/felix/ipojo/handlers/dependency/Dependency.java
index e0426e1..e9662a4 100644
--- a/ipojo/src/main/java/org/apache/felix/ipojo/handlers/dependency/Dependency.java
+++ b/ipojo/src/main/java/org/apache/felix/ipojo/handlers/dependency/Dependency.java
@@ -21,10 +21,9 @@
import java.lang.reflect.Array;
import java.lang.reflect.InvocationTargetException;
import java.util.HashMap;
-import java.util.logging.Level;
-import org.apache.felix.ipojo.Activator;
-import org.apache.felix.ipojo.ComponentManagerImpl;
+import org.apache.felix.ipojo.InstanceManager;
+import org.apache.felix.ipojo.util.Logger;
import org.osgi.framework.Filter;
import org.osgi.framework.InvalidSyntaxException;
import org.osgi.framework.ServiceEvent;
@@ -148,8 +147,8 @@
* @return null or a service object or a list of service object according to the dependency.
*/
protected Object get() {
- Activator.getLogger().log(Level.INFO, "[" + m_handler.getComponentManager().getComponentMetatada().getClassName() + "] Call get for a dependency on : " + m_metadata.getServiceSpecification()
- + " Multiple : " + m_metadata.isMultiple() + " Optional : " + m_metadata.isOptional());
+ // m_handler.getInstanceManager().getFactory().getLogger().log(Logger.INFO, "[" + m_handler.getInstanceManager().getClassName() + "] Call get for a dependency on : " + m_metadata.getServiceSpecification()
+ // + " Multiple : " + m_metadata.isMultiple() + " Optional : " + m_metadata.isOptional());
try {
// 1 : Test if there is any change in the reference list :
@@ -164,15 +163,15 @@
}
// 2 : Else there is a change in the list -> recompute the m_services array
- Activator.getLogger().log(Level.INFO, "[" + m_handler.getComponentManager().getComponentMetatada().getClassName() + "] Create a service array of " + m_clazz.getName());
+ m_handler.getInstanceManager().getFactory().getLogger().log(Logger.INFO, "[" + m_handler.getInstanceManager().getClassName() + "] Create a service array of " + m_clazz.getName());
m_services = (Object[]) Array.newInstance(m_clazz, m_ref.length);
for (int i = 0; i < m_ref.length; i++) {
- m_services[i] = m_handler.getComponentManager().getContext().getService(m_ref[i]);
+ m_services[i] = m_handler.getInstanceManager().getContext().getService(m_ref[i]);
}
m_change = false;
- Activator.getLogger().log(Level.INFO, "[" + m_handler.getComponentManager().getComponentMetatada().getClassName() + "] Create an array with the size " + m_services.length);
+ // m_handler.getInstanceManager().getFactory().getLogger().log(Logger.INFO, "[" + m_handler.getInstanceManager().getClassName() + "] Create an array with the size " + m_services.length);
// 3 : The service object list is populated, I return either the first service object, either the array.
@@ -184,17 +183,17 @@
// Load the nullable class
String[] segment = m_metadata.getServiceSpecification().split("[.]");
String className = "org.apache.felix.ipojo." + segment[segment.length - 1] + "Nullable";
- Activator.getLogger().log(Level.INFO, "[" + m_handler.getComponentManager().getComponentMetatada().getClassName() + "] Try to load the nullable class for " + getMetadata().getServiceSpecification() + " -> " + className);
+ // m_handler.getInstanceManager().getFactory().getLogger().log(Logger.INFO, "[" + m_handler.getInstanceManager().getClassName() + "] Try to load the nullable class for " + getMetadata().getServiceSpecification() + " -> " + className);
Class nullableClazz = m_handler.getNullableClass(className);
if (nullableClazz == null) {
- Activator.getLogger().log(Level.INFO, "[" + m_handler.getComponentManager().getComponentMetatada().getClassName() + "] Cannot load the nullable class to return a dependency object for " + m_metadata.getField() + " -> " + m_metadata.getServiceSpecification());
+ m_handler.getInstanceManager().getFactory().getLogger().log(Logger.INFO, "[" + m_handler.getInstanceManager().getClassName() + "] Cannot load the nullable class to return a dependency object for " + m_metadata.getField() + " -> " + m_metadata.getServiceSpecification());
return null;
}
// The nullable class is loaded, create the object and return it
Object instance = nullableClazz.newInstance();
- Activator.getLogger().log(Level.INFO, "[" + m_handler.getComponentManager().getComponentMetatada().getClassName() + "] Nullable object created for " + getMetadata().getServiceSpecification() + " -> " + instance);
+ // m_handler.getInstanceManager().getFactory().getLogger().log(Logger.INFO, "[" + m_handler.getInstanceManager().getClassName() + "] Nullable object created for " + getMetadata().getServiceSpecification() + " -> " + instance);
return instance;
}
}
@@ -204,10 +203,10 @@
} catch (Exception e) {
// There is a problem in the dependency resolving (like in stopping method)
if (!m_metadata.isMultiple()) {
- Activator.getLogger().log(Level.SEVERE, "[" + m_handler.getComponentManager().getComponentMetatada().getClassName() + "] Return null, an exception was throwed in the get method -> " + e.getMessage());
+ m_handler.getInstanceManager().getFactory().getLogger().log(Logger.ERROR, "[" + m_handler.getInstanceManager().getClassName() + "] Return null, an exception was throwed in the get method", e);
return null; }
else {
- Activator.getLogger().log(Level.SEVERE, "[" + m_handler.getComponentManager().getComponentMetatada().getClassName() + "] Return an empty array, an exception was throwed in the get method" + e.getMessage());
+ m_handler.getInstanceManager().getFactory().getLogger().log(Logger.ERROR, "[" + m_handler.getInstanceManager().getClassName() + "] Return an empty array, an exception was throwed in the get method", e);
return Array.newInstance(m_clazz, 0); }
}
}
@@ -222,7 +221,7 @@
// If a service goes way.
if (event.getType() == ServiceEvent.UNREGISTERING) {
- Activator.getLogger().log(Level.INFO, "[" + m_handler.getComponentManager().getComponentMetatada().getClassName() + "] A service is gone -> " + event.getServiceReference().getBundle());
+ m_handler.getInstanceManager().getFactory().getLogger().log(Logger.INFO, "[" + m_handler.getInstanceManager().getClassName() + "] A service is gone -> " + event.getServiceReference().getBundle());
if (containsSR(event.getServiceReference())) { departureManagement(event.getServiceReference()); }
return;
}
@@ -236,11 +235,11 @@
// If a service is modified
if (event.getType() == ServiceEvent.MODIFIED) {
if (m_filter.match(event.getServiceReference())) {
- Activator.getLogger().log(Level.INFO, "[" + m_handler.getComponentManager().getComponentMetatada().getClassName() + "] A service with a filter matching is arrived -> " + event.getServiceReference().getBundle());
+ m_handler.getInstanceManager().getFactory().getLogger().log(Logger.INFO, "[" + m_handler.getInstanceManager().getClassName() + "] A service with a filter matching is arrived -> " + event.getServiceReference().getBundle());
if (!containsSR(event.getServiceReference())) { arrivalManagement(event.getServiceReference()); }
}
else {
- Activator.getLogger().log(Level.INFO, "[" + m_handler.getComponentManager().getComponentMetatada().getClassName() + "] A service with a filter matching has gone -> " + event.getServiceReference().getBundle());
+ m_handler.getInstanceManager().getFactory().getLogger().log(Logger.INFO, "[" + m_handler.getInstanceManager().getClassName() + "] A service with a filter matching has gone -> " + event.getServiceReference().getBundle());
if (containsSR(event.getServiceReference())) { departureManagement(event.getServiceReference()); }
}
return;
@@ -255,7 +254,7 @@
*/
private void arrivalManagement(ServiceReference ref) {
// Add the new service inside the ref list
- Activator.getLogger().log(Level.INFO, "[" + m_handler.getComponentManager().getComponentMetatada().getClassName() + "] Add a service for a dependency");
+ m_handler.getInstanceManager().getFactory().getLogger().log(Logger.INFO, "[" + m_handler.getInstanceManager().getClassName() + "] Add a service for a dependency");
addReference(ref);
if (isSatisfied()) {
m_state = RESOLVED;
@@ -274,7 +273,7 @@
if (m_metadata.isMultiple()) { callUnbindMethod(ref); }
// Unget the service reference
- m_handler.getComponentManager().getContext().ungetService(ref);
+ m_handler.getInstanceManager().getContext().ungetService(ref);
int index = removeReference(ref);
// Is the state valid or invalid
@@ -301,7 +300,7 @@
* @param ref : reference to send (if accepted) to the method
*/
private void callUnbindMethod(ServiceReference ref) {
- if (m_handler.getComponentManager().getState() == ComponentManagerImpl.VALID) {
+ if (m_handler.getInstanceManager().getState() == InstanceManager.VALID) {
for (int i = 0; i < m_metadata.getCallbacks().length; i++) {
if (m_metadata.getCallbacks()[i].getMethodType() == DependencyCallback.UNBIND) {
// Try to call the bind method with a service reference inside
@@ -314,30 +313,30 @@
} catch (NoSuchMethodException e1) {
// The method was not found : try with the service object
try {
- m_metadata.getCallbacks()[i].call(new Object[] {m_handler.getComponentManager().getContext().getService(ref)});
+ m_metadata.getCallbacks()[i].call(new Object[] {m_handler.getInstanceManager().getContext().getService(ref)});
} catch (NoSuchMethodException e2) {
- Activator.getLogger().log(Level.SEVERE, "[" + m_handler.getComponentManager().getComponentMetatada().getClassName() + "] Dependency Callback Error : Unbind method not found : " + e1.getMessage());
+ m_handler.getInstanceManager().getFactory().getLogger().log(Logger.ERROR, "[" + m_handler.getInstanceManager().getClassName() + "] Dependency Callback Error : Unbind method not found", e2);
return;
} catch (IllegalAccessException e2) {
- Activator.getLogger().log(Level.SEVERE, "[" + m_handler.getComponentManager().getComponentMetatada().getClassName() + "] Dependency Callback Error : Illegal access on unbind method : " + e2.getMessage());
+ m_handler.getInstanceManager().getFactory().getLogger().log(Logger.ERROR, "[" + m_handler.getInstanceManager().getClassName() + "] Dependency Callback Error : Illegal access on unbind method", e2);
return;
} catch (InvocationTargetException e2) {
- Activator.getLogger().log(Level.SEVERE, "[" + m_handler.getComponentManager().getComponentMetatada().getClassName() + "] Dependency Callback Error : Invocation Target Exception in the unbind method " + e2.getMessage());
+ m_handler.getInstanceManager().getFactory().getLogger().log(Logger.ERROR, "[" + m_handler.getInstanceManager().getClassName() + "] Dependency Callback Error : Invocation Target Exception in the unbind method", e2);
return;
}
} catch (IllegalAccessException e1) {
- Activator.getLogger().log(Level.SEVERE, "[" + m_handler.getComponentManager().getComponentMetatada().getClassName() + "] Dependency Callback Error : Illegal access on unbind method : " + e1.getMessage());
+ m_handler.getInstanceManager().getFactory().getLogger().log(Logger.ERROR, "[" + m_handler.getInstanceManager().getClassName() + "] Dependency Callback Error : Illegal access on unbind method", e1);
return;
} catch (InvocationTargetException e1) {
- Activator.getLogger().log(Level.SEVERE, "[" + m_handler.getComponentManager().getComponentMetatada().getClassName() + "] Dependency Callback Error : Invocation Target Exception in the unbind method " + e1.getMessage());
+ m_handler.getInstanceManager().getFactory().getLogger().log(Logger.ERROR, "[" + m_handler.getInstanceManager().getClassName() + "] Dependency Callback Error : Invocation Target Exception in the unbind method", e1);
return;
}
} catch (IllegalAccessException e) {
- Activator.getLogger().log(Level.SEVERE, "[" + m_handler.getComponentManager().getComponentMetatada().getClassName() + "] Dependency Callback Error : Illegal access on bind method : " + e.getMessage());
+ m_handler.getInstanceManager().getFactory().getLogger().log(Logger.ERROR, "[" + m_handler.getInstanceManager().getClassName() + "] Dependency Callback Error : Illegal access on bind method", e);
return;
} catch (InvocationTargetException e) {
- Activator.getLogger().log(Level.SEVERE, "[" + m_handler.getComponentManager().getComponentMetatada().getClassName() + "] Dependency Callback Error : Invocation Target Exception in the bind method " + e.getMessage());
+ m_handler.getInstanceManager().getFactory().getLogger().log(Logger.ERROR, "[" + m_handler.getInstanceManager().getClassName() + "] Dependency Callback Error : Invocation Target Exception in the bind method", e);
return;
}
}
@@ -368,29 +367,29 @@
} catch (NoSuchMethodException e1) {
// The method was not found : try with the service object
try {
- m_metadata.getCallbacks()[j].call(instance, new Object[] {m_handler.getComponentManager().getContext().getService(m_ref[i])});
+ m_metadata.getCallbacks()[j].call(instance, new Object[] {m_handler.getInstanceManager().getContext().getService(m_ref[i])});
} catch (NoSuchMethodException e2) {
- Activator.getLogger().log(Level.SEVERE, "[" + m_handler.getComponentManager().getComponentMetatada().getClassName() + "] Dependency Callback Error : Bind method not found : " + e1.getMessage());
+ m_handler.getInstanceManager().getFactory().getLogger().log(Logger.ERROR, "[" + m_handler.getInstanceManager().getClassName() + "] Dependency Callback Error : Bind method not found", e2);
return;
} catch (IllegalAccessException e2) {
- Activator.getLogger().log(Level.SEVERE, "[" + m_handler.getComponentManager().getComponentMetatada().getClassName() + "] Dependency Callback Error : Illegal access on bind method : " + e2.getMessage());
+ m_handler.getInstanceManager().getFactory().getLogger().log(Logger.ERROR, "[" + m_handler.getInstanceManager().getClassName() + "] Dependency Callback Error : Illegal access on bind method", e2);
return;
} catch (InvocationTargetException e2) {
- Activator.getLogger().log(Level.SEVERE, "[" + m_handler.getComponentManager().getComponentMetatada().getClassName() + "] Dependency Callback Error : Invocation Target Exception in the bind method " + e2.getMessage());
+ m_handler.getInstanceManager().getFactory().getLogger().log(Logger.ERROR, "[" + m_handler.getInstanceManager().getClassName() + "] Dependency Callback Error : Invocation Target Exception in the bind method", e2);
return;
}
} catch (IllegalAccessException e1) {
- Activator.getLogger().log(Level.SEVERE, "[" + m_handler.getComponentManager().getComponentMetatada().getClassName() + "] Dependency Callback Error : Illegal access on bind method : " + e1.getMessage());
+ m_handler.getInstanceManager().getFactory().getLogger().log(Logger.ERROR, "[" + m_handler.getInstanceManager().getClassName() + "] Dependency Callback Error : Illegal access on bind method", e1);
return;
} catch (InvocationTargetException e1) {
- Activator.getLogger().log(Level.SEVERE, "[" + m_handler.getComponentManager().getComponentMetatada().getClassName() + "] Dependency Callback Error : Invocation Target Exception in the bind method " + e1.getMessage());
+ m_handler.getInstanceManager().getFactory().getLogger().log(Logger.ERROR, "[" + m_handler.getInstanceManager().getClassName() + "] Dependency Callback Error : Invocation Target Exception in the bind method", e1);
return;
}
} catch (IllegalAccessException e) {
- Activator.getLogger().log(Level.SEVERE, "[" + m_handler.getComponentManager().getComponentMetatada().getClassName() + "] Dependency Callback Error : Illegal access on bind method : " + e.getMessage());
+ m_handler.getInstanceManager().getFactory().getLogger().log(Logger.ERROR, "[" + m_handler.getInstanceManager().getClassName() + "] Dependency Callback Error : Illegal access on bind method", e);
return;
} catch (InvocationTargetException e) {
- Activator.getLogger().log(Level.SEVERE, "[" + m_handler.getComponentManager().getComponentMetatada().getClassName() + "] Dependency Callback Error : Invocation Target Exception in the bind method " + e.getMessage());
+ m_handler.getInstanceManager().getFactory().getLogger().log(Logger.ERROR, "[" + m_handler.getInstanceManager().getClassName() + "] Dependency Callback Error : Invocation Target Exception in the bind method" + e);
return;
}
}
@@ -405,35 +404,34 @@
} catch (NoSuchMethodException e) {
// The method was not found : try without service reference
try {
- Activator.getLogger().log(Level.WARNING, "[" + m_handler.getComponentManager().getComponentMetatada().getClassName() + "] Dependency Callback Call the Bind method");
m_metadata.getCallbacks()[j].call(instance);
} catch (NoSuchMethodException e1) {
// The method was not found : try with the service object
try {
- m_metadata.getCallbacks()[j].call(new Object[] {m_handler.getComponentManager().getContext().getService(m_ref[0])});
+ m_metadata.getCallbacks()[j].call(new Object[] {m_handler.getInstanceManager().getContext().getService(m_ref[0])});
} catch (NoSuchMethodException e2) {
- Activator.getLogger().log(Level.SEVERE, "[" + m_handler.getComponentManager().getComponentMetatada().getClassName() + "] Dependency Callback Error : Bind method not found : " + e1.getMessage());
+ m_handler.getInstanceManager().getFactory().getLogger().log(Logger.ERROR, "[" + m_handler.getInstanceManager().getClassName() + "] Dependency Callback Error : Bind method not found", e2);
return;
} catch (IllegalAccessException e2) {
- Activator.getLogger().log(Level.SEVERE, "[" + m_handler.getComponentManager().getComponentMetatada().getClassName() + "] Dependency Callback Error : Illegal access on bind method : " + e2.getMessage());
+ m_handler.getInstanceManager().getFactory().getLogger().log(Logger.ERROR, "[" + m_handler.getInstanceManager().getClassName() + "] Dependency Callback Error : Illegal access on bind method", e2);
return;
} catch (InvocationTargetException e2) {
- Activator.getLogger().log(Level.SEVERE, "[" + m_handler.getComponentManager().getComponentMetatada().getClassName() + "] Dependency Callback Error : Invocation Target Exception in the bind method " + e2.getMessage());
+ m_handler.getInstanceManager().getFactory().getLogger().log(Logger.ERROR, "[" + m_handler.getInstanceManager().getClassName() + "] Dependency Callback Error : Invocation Target Exception in the bind method", e2);
return;
}
} catch (IllegalAccessException e1) {
- Activator.getLogger().log(Level.SEVERE, "[" + m_handler.getComponentManager().getComponentMetatada().getClassName() + "] Dependency Callback Error : Illegal access on bind method : " + e1.getMessage());
+ m_handler.getInstanceManager().getFactory().getLogger().log(Logger.ERROR, "[" + m_handler.getInstanceManager().getClassName() + "] Dependency Callback Error : Illegal access on bind method", e1);
return;
} catch (InvocationTargetException e1) {
- Activator.getLogger().log(Level.SEVERE, "[" + m_handler.getComponentManager().getComponentMetatada().getClassName() + "] Dependency Callback Error : Invocation Target Exception in the bind method " + e1.getMessage());
+ m_handler.getInstanceManager().getFactory().getLogger().log(Logger.ERROR, "[" + m_handler.getInstanceManager().getClassName() + "] Dependency Callback Error : Invocation Target Exception in the bind method", e1);
return;
}
} catch (IllegalAccessException e) {
- Activator.getLogger().log(Level.SEVERE, "[" + m_handler.getComponentManager().getComponentMetatada().getClassName() + "] Dependency Callback Error : Illegal access on bind method : " + e.getMessage());
+ m_handler.getInstanceManager().getFactory().getLogger().log(Logger.ERROR, "[" + m_handler.getInstanceManager().getClassName() + "] Dependency Callback Error : Illegal access on bind method", e);
return;
} catch (InvocationTargetException e) {
- Activator.getLogger().log(Level.SEVERE, "[" + m_handler.getComponentManager().getComponentMetatada().getClassName() + "] Dependency Callback Error : Invocation Target Exception in the bind method " + e.getMessage());
+ m_handler.getInstanceManager().getFactory().getLogger().log(Logger.ERROR, "[" + m_handler.getInstanceManager().getClassName() + "] Dependency Callback Error : Invocation Target Exception in the bind method", e);
return;
}
}
@@ -447,7 +445,7 @@
*/
private void callBindMethod(ServiceReference ref) {
// call bind method :
- if (m_handler.getComponentManager().getState() == ComponentManagerImpl.VALID) {
+ if (m_handler.getInstanceManager().getState() == InstanceManager.VALID) {
for (int i = 0; i < m_metadata.getCallbacks().length; i++) {
if (m_metadata.getCallbacks()[i].getMethodType() == DependencyCallback.BIND) {
// Try to call the bind method with a service reference inside
@@ -456,35 +454,35 @@
} catch (NoSuchMethodException e) {
// The method was not found : try without service reference
try {
- Activator.getLogger().log(Level.INFO, "[" + m_handler.getComponentManager().getComponentMetatada().getClassName() + "] Dependency Callback Call the Bind method");
+ m_handler.getInstanceManager().getFactory().getLogger().log(Logger.INFO, "[" + m_handler.getInstanceManager().getClassName() + "] Dependency Callback Call the Bind method");
m_metadata.getCallbacks()[i].call();
} catch (NoSuchMethodException e1) {
// The method was not found : try with the service object
try {
- m_metadata.getCallbacks()[i].call(new Object[] {m_handler.getComponentManager().getContext().getService(ref)});
+ m_metadata.getCallbacks()[i].call(new Object[] {m_handler.getInstanceManager().getContext().getService(ref)});
} catch (NoSuchMethodException e2) {
- Activator.getLogger().log(Level.SEVERE, "[" + m_handler.getComponentManager().getComponentMetatada().getClassName() + "] Dependency Callback Error : Bind method not found : " + e1.getMessage());
+ m_handler.getInstanceManager().getFactory().getLogger().log(Logger.ERROR, "[" + m_handler.getInstanceManager().getClassName() + "] Dependency Callback Error : Bind method not found", e2);
return;
} catch (IllegalAccessException e2) {
- Activator.getLogger().log(Level.SEVERE, "[" + m_handler.getComponentManager().getComponentMetatada().getClassName() + "] Dependency Callback Error : Illegal access on bind method : " + e2.getMessage());
+ m_handler.getInstanceManager().getFactory().getLogger().log(Logger.ERROR, "[" + m_handler.getInstanceManager().getClassName() + "] Dependency Callback Error : Illegal access on bind method", e2);
return;
} catch (InvocationTargetException e2) {
- Activator.getLogger().log(Level.SEVERE, "[" + m_handler.getComponentManager().getComponentMetatada().getClassName() + "] Dependency Callback Error : Invocation Target Exception in the bind method " + e2.getMessage());
+ m_handler.getInstanceManager().getFactory().getLogger().log(Logger.ERROR, "[" + m_handler.getInstanceManager().getClassName() + "] Dependency Callback Error : Invocation Target Exception in the bind method", e2);
return;
}
} catch (IllegalAccessException e1) {
- Activator.getLogger().log(Level.SEVERE, "[" + m_handler.getComponentManager().getComponentMetatada().getClassName() + "] Dependency Callback Error : Illegal access on bind method : " + e1.getMessage());
+ m_handler.getInstanceManager().getFactory().getLogger().log(Logger.ERROR, "[" + m_handler.getInstanceManager().getClassName() + "] Dependency Callback Error : Illegal access on bind method", e1);
return;
} catch (InvocationTargetException e1) {
- Activator.getLogger().log(Level.SEVERE, "[" + m_handler.getComponentManager().getComponentMetatada().getClassName() + "] Dependency Callback Error : Invocation Target Exception in the bind method " + e1.getMessage());
+ m_handler.getInstanceManager().getFactory().getLogger().log(Logger.ERROR, "[" + m_handler.getInstanceManager().getClassName() + "] Dependency Callback Error : Invocation Target Exception in the bind method", e1);
return;
}
} catch (IllegalAccessException e) {
- Activator.getLogger().log(Level.SEVERE, "[" + m_handler.getComponentManager().getComponentMetatada().getClassName() + "] Dependency Callback Error : Illegal access on bind method : " + e.getMessage());
+ m_handler.getInstanceManager().getFactory().getLogger().log(Logger.ERROR, "[" + m_handler.getInstanceManager().getClassName() + "] Dependency Callback Error : Illegal access on bind method", e);
return;
} catch (InvocationTargetException e) {
- Activator.getLogger().log(Level.SEVERE, "[" + m_handler.getComponentManager().getComponentMetatada().getClassName() + "] Dependency Callback Error : Invocation Target Exception in the bind method " + e.getMessage());
+ m_handler.getInstanceManager().getFactory().getLogger().log(Logger.ERROR, "[" + m_handler.getInstanceManager().getClassName() + "] Dependency Callback Error : Invocation Target Exception in the bind method", e);
return;
}
}
@@ -506,11 +504,11 @@
filter = classnamefilter;
}
- Activator.getLogger().log(Level.INFO, "[" + m_handler.getComponentManager().getComponentMetatada().getClassName() + "] Start a dependency on : " + m_metadata.getServiceSpecification() + " with " + m_metadata.getFilter());
+ m_handler.getInstanceManager().getFactory().getLogger().log(Logger.INFO, "[" + m_handler.getInstanceManager().getClassName() + "] Start a dependency on : " + m_metadata.getServiceSpecification() + " with " + m_metadata.getFilter());
m_state = UNRESOLVED;
try {
- m_clazz = m_handler.getComponentManager().getContext().getBundle().loadClass(m_metadata.getServiceSpecification());
+ m_clazz = m_handler.getInstanceManager().getContext().getBundle().loadClass(m_metadata.getServiceSpecification());
} catch (ClassNotFoundException e) {
System.err.println("Cannot load the interface class for the dependency " + m_metadata.getField() + " [" + m_metadata.getServiceSpecification() + "]");
e.printStackTrace();
@@ -518,20 +516,20 @@
try {
// Look if the service is already present :
- ServiceReference[] sr = m_handler.getComponentManager().getContext().getServiceReferences(
+ ServiceReference[] sr = m_handler.getInstanceManager().getContext().getServiceReferences(
m_metadata.getServiceSpecification(), filter);
if (sr != null) {
for (int i = 0; i < sr.length; i++) { addReference(sr[i]); }
m_state = RESOLVED;
}
// Register a listener :
- m_handler.getComponentManager().getContext().addServiceListener(this);
- m_filter = m_handler.getComponentManager().getContext().createFilter(filter); // Store the filter
- Activator.getLogger().log(Level.INFO, "[" + m_handler.getComponentManager().getComponentMetatada().getClassName() + "] Create a filter from : " + filter);
+ m_handler.getInstanceManager().getContext().addServiceListener(this);
+ m_filter = m_handler.getInstanceManager().getContext().createFilter(filter); // Store the filter
+ m_handler.getInstanceManager().getFactory().getLogger().log(Logger.INFO, "[" + m_handler.getInstanceManager().getClassName() + "] Create a filter from : " + filter);
m_change = true;
}
catch (InvalidSyntaxException e1) {
- Activator.getLogger().log(Level.SEVERE, "[" + m_handler.getComponentManager().getComponentMetatada().getClassName() + "] A filter is malformed : " + filter);
+ m_handler.getInstanceManager().getFactory().getLogger().log(Logger.ERROR, "[" + m_handler.getInstanceManager().getClassName() + "] A filter is malformed : " + filter);
e1.printStackTrace();
}
}
@@ -540,16 +538,16 @@
* Stop the dependency.
*/
public void stop() {
- Activator.getLogger().log(Level.INFO, "[" + m_handler.getComponentManager().getComponentMetatada().getClassName() + "] Stop a dependency on : " + m_metadata.getServiceSpecification() + " with " + m_metadata.getFilter());
+ m_handler.getInstanceManager().getFactory().getLogger().log(Logger.INFO, "[" + m_handler.getInstanceManager().getClassName() + "] Stop a dependency on : " + m_metadata.getServiceSpecification() + " with " + m_metadata.getFilter());
m_state = UNRESOLVED;
// Unget all services references
for (int i = 0; i < m_ref.length; i++) {
- m_handler.getComponentManager().getContext().ungetService(m_ref[i]);
+ m_handler.getInstanceManager().getContext().ungetService(m_ref[i]);
}
m_ref = new ServiceReference[0];
- m_handler.getComponentManager().getContext().removeServiceListener(this);
+ m_handler.getInstanceManager().getContext().removeServiceListener(this);
m_clazz = null;
m_services = null;
}
diff --git a/ipojo/src/main/java/org/apache/felix/ipojo/handlers/dependency/DependencyCallback.java b/ipojo/src/main/java/org/apache/felix/ipojo/handlers/dependency/DependencyCallback.java
index ebd35f4..7700ffc 100644
--- a/ipojo/src/main/java/org/apache/felix/ipojo/handlers/dependency/DependencyCallback.java
+++ b/ipojo/src/main/java/org/apache/felix/ipojo/handlers/dependency/DependencyCallback.java
@@ -20,7 +20,7 @@
import java.lang.reflect.InvocationTargetException;
-import org.apache.felix.ipojo.Callback;
+import org.apache.felix.ipojo.util.Callback;
/**
@@ -59,7 +59,7 @@
*/
public DependencyCallback(Dependency dep, String method, int methodType, boolean isStatic) {
m_methodType = methodType;
- m_callback = new Callback(method, isStatic, dep.getDependencyHandler().getComponentManager());
+ m_callback = new Callback(method, isStatic, dep.getDependencyHandler().getInstanceManager());
}
/**
diff --git a/ipojo/src/main/java/org/apache/felix/ipojo/handlers/dependency/DependencyHandler.java b/ipojo/src/main/java/org/apache/felix/ipojo/handlers/dependency/DependencyHandler.java
index 3bedc45..925c397 100644
--- a/ipojo/src/main/java/org/apache/felix/ipojo/handlers/dependency/DependencyHandler.java
+++ b/ipojo/src/main/java/org/apache/felix/ipojo/handlers/dependency/DependencyHandler.java
@@ -21,13 +21,12 @@
import java.io.IOException;
import java.net.URL;
import java.util.Dictionary;
-import java.util.logging.Level;
-import org.apache.felix.ipojo.Activator;
-import org.apache.felix.ipojo.ComponentManagerImpl;
import org.apache.felix.ipojo.Handler;
+import org.apache.felix.ipojo.InstanceManager;
import org.apache.felix.ipojo.handlers.dependency.nullable.NullableObjectWriter;
import org.apache.felix.ipojo.metadata.Element;
+import org.apache.felix.ipojo.util.Logger;
/**
* The dependency handler manages a list of dependencies.
@@ -36,9 +35,9 @@
public class DependencyHandler extends Handler {
/**
- * The component manager using this handler.
+ * The instance manager using this handler.
*/
- private ComponentManagerImpl m_componentManager;
+ private InstanceManager m_manager;
/**
* List of depednencies of the component.
@@ -110,9 +109,9 @@
public Dependency[] getDependencies() { return m_dependencies; }
/**
- * @return the component manager
+ * @return the instance manager
*/
- protected ComponentManagerImpl getComponentManager() { return m_componentManager; }
+ protected InstanceManager getInstanceManager() { return m_manager; }
// ===================== Handler implementation =====================
@@ -123,7 +122,7 @@
synchronized (this) {
- Activator.getLogger().log(Level.INFO, "[DependencyHandler on " + m_componentManager.getComponentMetatada().getClassName() + "] Check Context ...");
+ m_manager.getFactory().getLogger().log(Logger.INFO, "[DependencyHandler on " + m_manager.getClassName() + "] Check Context ...");
// Store the initial state
int initialState = m_state;
@@ -131,19 +130,19 @@
// Check the component dependencies
if (!validateComponentDependencies()) {
// The dependencies are not valid
- if (initialState == ComponentManagerImpl.VALID) {
+ if (initialState == InstanceManager.VALID) {
//There is a state change
- m_state = ComponentManagerImpl.INVALID;
- m_componentManager.checkComponentState();
+ m_state = InstanceManager.INVALID;
+ m_manager.checkInstanceState();
}
// Else do nothing, the component state stay UNRESOLVED
}
else {
// The dependencies are valid
- if (initialState == ComponentManagerImpl.INVALID) {
+ if (initialState == InstanceManager.INVALID) {
//There is a state change
- m_state = ComponentManagerImpl.VALID;
- m_componentManager.checkComponentState();
+ m_state = InstanceManager.VALID;
+ m_manager.checkInstanceState();
}
// Else do nothing, the component state stay VALID
}
@@ -156,11 +155,10 @@
* @param dep : the dependency to check
* @return true if the dependency is valid
*/
- private boolean checkDependency(Dependency dep) {
+ private boolean checkDependency(Dependency dep, Element manipulation) {
// Check the internal type of dependency
String field = dep.getMetadata().getField();
- Element manipulation = m_componentManager.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"))) {
@@ -170,7 +168,7 @@
}
if (type == null) {
- Activator.getLogger().log(Level.SEVERE, "[DependencyHandler on " + m_componentManager.getComponentMetatada().getClassName() + "] A declared dependency was not found in the class : " + dep.getMetadata().getField());
+ m_manager.getFactory().getLogger().log(Logger.ERROR, "[DependencyHandler on " + m_manager.getClassName() + "] A declared dependency was not found in the class : " + dep.getMetadata().getField());
return false;
}
@@ -184,23 +182,22 @@
if (dep.getMetadata().getServiceSpecification() == null) { dep.getMetadata().setServiceSpecification(type); }
if (!dep.getMetadata().getServiceSpecification().equals(type)) {
- Activator.getLogger().log(Level.WARNING, "[DependencyHandler on " + m_componentManager.getComponentMetatada().getClassName() + "] The field type [" + type + "] and the needed service interface [" + dep.getMetadata().getServiceSpecification() + "] are not the same");
+ m_manager.getFactory().getLogger().log(Logger.WARNING, "[DependencyHandler on " + m_manager.getClassName() + "] The field type [" + type + "] and the needed service interface [" + dep.getMetadata().getServiceSpecification() + "] are not the same");
dep.getMetadata().setServiceSpecification(type);
}
}
else {
- Activator.getLogger().log(Level.WARNING, "[DependencyHandler on " + m_componentManager.getComponentMetatada().getClassName() + "] The declared dependency " + dep.getMetadata().getField() + " does not exist in the code");
+ m_manager.getFactory().getLogger().log(Logger.WARNING, "[DependencyHandler on " + m_manager.getClassName() + "] The declared dependency " + dep.getMetadata().getField() + " does not exist in the code");
}
return true;
}
/**
- * @see org.apache.felix.ipojo.Handler#configure(org.apache.felix.ipojo.ComponentManagerImpl, org.apache.felix.ipojo.metadata.Element)
+ * @see org.apache.felix.ipojo.Handler#configure(org.apache.felix.ipojo.InstanceManager, org.apache.felix.ipojo.metadata.Element)
*/
- public void configure(ComponentManagerImpl cm, Element componentMetadata, Dictionary configuration) {
- // Fix the component manager
- m_componentManager = cm;
+ public void configure(InstanceManager im, Element componentMetadata, Dictionary configuration) {
+ m_manager = im;
m_dependencies = new Dependency[0];
m_nullableClasses = new Class[0];
@@ -220,8 +217,9 @@
Dependency dep = new Dependency(this, dm);
// Check the dependency :
- if (checkDependency(dep)) { addDependency(dep); }
- else { Activator.getLogger().log(Level.SEVERE, "[DependencyHandler on " + m_componentManager.getComponentMetatada().getClassName() + "] The dependency on " + dep.getMetadata().getField() + " is not valid"); }
+ Element manipulation = componentMetadata.getElements("Manipulation")[0];
+ if (checkDependency(dep, manipulation)) { addDependency(dep); }
+ else { m_manager.getFactory().getLogger().log(Logger.ERROR, "[DependencyHandler on " + m_manager.getClassName() + "] The dependency on " + dep.getMetadata().getField() + " is not valid"); }
// Look for dependency callback :
for (int j = 0; j < (deps[i].getElements("Callback", "")).length; j++) {
@@ -242,10 +240,11 @@
for (int k = 0; k < m_dependencies.length; k++) {
fields[k] = m_dependencies[k].getMetadata().getField();
}
- m_componentManager.register(this, fields);
+ m_manager.register(this, fields);
// Create the nullable classloader
- m_classloader = new NullableClassloader(m_componentManager.getContext().getBundle());
+ // TODO why do not use the factory class loader ?
+ m_classloader = new NullableClassloader(m_manager.getContext().getBundle());
}
}
@@ -255,13 +254,13 @@
* @param dep : the dependency
*/
private void createNullableClass(Dependency dep) {
- Activator.getLogger().log(Level.INFO, "[DependencyHandler on " + m_componentManager.getComponentMetatada().getClassName() + "] Try to load the nullable class for " + dep.getMetadata().getServiceSpecification());
+ m_manager.getFactory().getLogger().log(Logger.INFO, "[DependencyHandler on " + m_manager.getClassName() + "] Try to load the nullable class for " + dep.getMetadata().getServiceSpecification());
// Try to load the nullable object :
String[] segment = dep.getMetadata().getServiceSpecification().split("[.]");
String className = "org/apache/felix/ipojo/" + segment[segment.length - 1] + "Nullable";
String resource = dep.getMetadata().getServiceSpecification().replace('.', '/') + ".class";
- URL url = m_componentManager.getContext().getBundle().getResource(resource);
+ URL url = m_manager.getContext().getBundle().getResource(resource);
try {
byte[] b = NullableObjectWriter.dump(url, dep.getMetadata().getServiceSpecification());
@@ -279,12 +278,12 @@
// }
addNullableClass(m_classloader.defineClass(className.replace('/', '.'), b, null));
- Activator.getLogger().log(Level.INFO, "[DependencyHandler on " + m_componentManager.getComponentMetatada().getClassName() + "] Nullable class created for " + dep.getMetadata().getServiceSpecification());
+ m_manager.getFactory().getLogger().log(Logger.INFO, "[DependencyHandler on " + m_manager.getClassName() + "] Nullable class created for " + dep.getMetadata().getServiceSpecification());
} catch (IOException e1) {
- Activator.getLogger().log(Level.SEVERE, "[DependencyHandler on " + m_componentManager.getComponentMetatada().getClassName() + "] Cannot open a stream of an interface to generate the nullable class for " + dep.getMetadata().getServiceSpecification() + " -> " + e1.getMessage());
+ m_manager.getFactory().getLogger().log(Logger.ERROR, "[DependencyHandler on " + m_manager.getClassName() + "] Cannot open a stream of an interface to generate the nullable class for " + dep.getMetadata().getServiceSpecification(), e1);
} catch (Exception e2) {
- Activator.getLogger().log(Level.SEVERE, "[DependencyHandler on " + m_componentManager.getComponentMetatada().getClassName() + "] Cannot load the nullable class for " + dep.getMetadata().getServiceSpecification() + " -> " + e2.getMessage());
+ m_manager.getFactory().getLogger().log(Logger.ERROR, "[DependencyHandler on " + m_manager.getClassName() + "] Cannot load the nullable class for " + dep.getMetadata().getServiceSpecification(), e2);
}
}
@@ -307,7 +306,7 @@
* @see org.apache.felix.ipojo.Handler#getterCallback(java.lang.String, java.lang.Object)
*/
public Object getterCallback(String fieldName, Object value) {
- //TODO : non performant
+ //TODO : non effiecent
for (int i = 0; i < m_dependencies.length; i++) {
Dependency dep = m_dependencies[i];
if (dep.getMetadata().getField().equals(fieldName)) {
@@ -323,14 +322,14 @@
* @see org.apache.felix.ipojo.Handler#isValid()
*/
public boolean isValid() {
- return (m_state == ComponentManagerImpl.VALID);
+ return (m_state == InstanceManager.VALID);
}
/**
* @see org.apache.felix.ipojo.Handler#start()
*/
public void start() {
- Activator.getLogger().log(Level.INFO, "[DependencyHandler on " + m_componentManager.getComponentMetatada().getClassName() + "] Start the dependency handler");
+ m_manager.getFactory().getLogger().log(Logger.INFO, "[DependencyHandler on " + m_manager.getClassName() + "] Start the dependency handler");
// Start the dependencies, for optional dependencies create Nullable class
for (int i = 0; i < m_dependencies.length; i++) {
@@ -339,7 +338,7 @@
dep.start();
}
// Check the state
- m_state = m_componentManager.getState();
+ m_state = m_manager.getState();
checkContext();
}
@@ -373,11 +372,11 @@
Dependency dep = m_dependencies[i];
valide = valide & dep.isSatisfied();
if (!valide) {
- Activator.getLogger().log(Level.INFO, "[DependencyHandler on " + m_componentManager.getComponentMetatada().getClassName() + "] Component Dependencies are not valid : " + dep.getMetadata().getServiceSpecification());
+ m_manager.getFactory().getLogger().log(Logger.INFO, "[DependencyHandler on " + m_manager.getClassName() + "] Component Dependencies are not valid : " + dep.getMetadata().getServiceSpecification());
return false;
}
}
- Activator.getLogger().log(Level.INFO, "[DependencyHandler on " + m_componentManager.getComponentMetatada().getClassName() + "] Component Dependencies are valid");
+ m_manager.getFactory().getLogger().log(Logger.INFO, "[DependencyHandler on " + m_manager.getClassName() + "] Component Dependencies are valid");
return valide;
}
diff --git a/ipojo/src/main/java/org/apache/felix/ipojo/handlers/dependency/nullable/NullableObjectWriter.java b/ipojo/src/main/java/org/apache/felix/ipojo/handlers/dependency/nullable/NullableObjectWriter.java
index 9665692..a4d4f29 100644
--- a/ipojo/src/main/java/org/apache/felix/ipojo/handlers/dependency/nullable/NullableObjectWriter.java
+++ b/ipojo/src/main/java/org/apache/felix/ipojo/handlers/dependency/nullable/NullableObjectWriter.java
@@ -84,7 +84,7 @@
MethodVisitor mv = cw.visitMethod(ACC_PUBLIC, name, desc, sign, exc);
Type returnType = Type.getReturnType(desc);
- // TODO : manage the other type primitive
+ // TODO : manage the other type primitive for Nullable
// Primitive type :
switch (returnType.getSort()) {
case Type.BOOLEAN:
diff --git a/ipojo/src/main/java/org/apache/felix/ipojo/handlers/lifecycle/callback/LifecycleCallback.java b/ipojo/src/main/java/org/apache/felix/ipojo/handlers/lifecycle/callback/LifecycleCallback.java
index d023558..6e03efb 100644
--- a/ipojo/src/main/java/org/apache/felix/ipojo/handlers/lifecycle/callback/LifecycleCallback.java
+++ b/ipojo/src/main/java/org/apache/felix/ipojo/handlers/lifecycle/callback/LifecycleCallback.java
@@ -19,40 +19,49 @@
package org.apache.felix.ipojo.handlers.lifecycle.callback;
import java.lang.reflect.InvocationTargetException;
-import org.apache.felix.ipojo.Callback;
+
+import org.apache.felix.ipojo.InstanceManager;
+import org.apache.felix.ipojo.util.Callback;
/**
* This class is the implementation of callback on lifecycle transition.
* @author <a href="mailto:felix-dev@incubator.apache.org">Felix Project Team</a>
*/
public class LifecycleCallback {
-
+
+ /**
+ * Initial state of the transition.
+ */
+ private int m_initialState;
/**
- * Metadata of the callback.
+ * Final state of the transition.
*/
- private LifecycleCallbackMetadata m_metadata;
+ private int m_finalState;
/**
* Callback object.
*/
private Callback m_callback;
+
+ /**
+ * Method called by the callback.
+ */
+ private String m_method;
/**
* LifecycleCallback constructor.
* @param hh : the callback handler calling the callback
* @param hm : the callback metadata
*/
- public LifecycleCallback(LifecycleCallbackHandler hh, LifecycleCallbackMetadata hm) {
- m_metadata = hm;
- m_callback = new Callback(hm.getMethod(), hm.isStatic(), hh.getComponentManager());
- }
-
- /**
- * @return : the metadata of the hook
- */
- public LifecycleCallbackMetadata getMetadata() {
- return m_metadata;
+ public LifecycleCallback(LifecycleCallbackHandler hh, String initialState, String finalState, String method, boolean isStatic) {
+ if (initialState.equals("VALID")) { m_initialState = InstanceManager.VALID; }
+ if (initialState.equals("INVALID")) { m_initialState = InstanceManager.INVALID; }
+ if (finalState.equals("VALID")) { m_finalState = InstanceManager.VALID; }
+ if (finalState.equals("INVALID")) { m_finalState = InstanceManager.INVALID; }
+
+ m_method = method;
+ m_callback = new Callback(method, isStatic, hh.getInstanceManager());
}
/**
@@ -64,5 +73,24 @@
protected void call() throws NoSuchMethodException, IllegalAccessException, InvocationTargetException {
m_callback.call();
}
+
+ /**
+ * @return Returns the m_finalState.
+ */
+ public int getFinalState() {
+ return m_finalState;
+ }
+
+ /**
+ * @return Returns the m_initialState.
+ */
+ public int getInitialState() {
+ return m_initialState;
+ }
+
+ /**
+ * @return the method called by this callback.
+ */
+ public String getMethod() { return m_method; }
}
diff --git a/ipojo/src/main/java/org/apache/felix/ipojo/handlers/lifecycle/callback/LifecycleCallbackHandler.java b/ipojo/src/main/java/org/apache/felix/ipojo/handlers/lifecycle/callback/LifecycleCallbackHandler.java
index f04c2b2..e071081 100644
--- a/ipojo/src/main/java/org/apache/felix/ipojo/handlers/lifecycle/callback/LifecycleCallbackHandler.java
+++ b/ipojo/src/main/java/org/apache/felix/ipojo/handlers/lifecycle/callback/LifecycleCallbackHandler.java
@@ -20,12 +20,11 @@
import java.lang.reflect.InvocationTargetException;
import java.util.Dictionary;
-import java.util.logging.Level;
-import org.apache.felix.ipojo.Activator;
-import org.apache.felix.ipojo.ComponentManagerImpl;
import org.apache.felix.ipojo.Handler;
+import org.apache.felix.ipojo.InstanceManager;
import org.apache.felix.ipojo.metadata.Element;
+import org.apache.felix.ipojo.util.Logger;
/**
* Lifecycle callback handler.
@@ -39,14 +38,14 @@
private LifecycleCallback[] m_callbacks = new LifecycleCallback[0];
/**
- * State of the component manager (unresolved at the beginning).
+ * State of the instance manager (unresolved at the beginning).
*/
- private int m_state = ComponentManagerImpl.INVALID;
+ private int m_state = InstanceManager.INVALID;
/**
- * The component manager.
+ * The instance manager.
*/
- private ComponentManagerImpl m_componentManager;
+ private InstanceManager m_manager;
/**
* Add the given Hook to the hook list.
@@ -70,10 +69,10 @@
}
/**
- * @see org.apache.felix.ipojo.Handler#configure(org.apache.felix.ipojo.ComponentManagerImpl, org.apache.felix.ipojo.metadata.Element)
+ * @see org.apache.felix.ipojo.Handler#configure(org.apache.felix.ipojo.InstanceManager, org.apache.felix.ipojo.metadata.Element)
*/
- public void configure(ComponentManagerImpl cm, Element metadata, Dictionary configuration) {
- m_componentManager = cm;
+ public void configure(InstanceManager cm, Element metadata, Dictionary configuration) {
+ m_manager = cm;
m_callbacks = new LifecycleCallback[0];
Element[] hooksMetadata = metadata.getElements("callback");
@@ -85,12 +84,10 @@
boolean isStatic = false;
if (hooksMetadata[i].containsAttribute("isStatic") && hooksMetadata[i].getAttribute("isStatic").equals("true")) { isStatic = true; }
- LifecycleCallbackMetadata hm = new LifecycleCallbackMetadata(initialState, finalState, method, isStatic);
-
- LifecycleCallback hk = new LifecycleCallback(this, hm);
+ LifecycleCallback hk = new LifecycleCallback(this, initialState, finalState, method, isStatic);
addCallback(hk);
}
- if (m_callbacks.length > 0) { m_componentManager.register(this); }
+ if (m_callbacks.length > 0) { m_manager.register(this); }
}
/**
@@ -102,31 +99,29 @@
* @see org.apache.felix.ipojo.Handler#stop()
*/
public void stop() {
- m_state = ComponentManagerImpl.INVALID;
+ m_state = InstanceManager.INVALID;
}
/**
- * @return the component manager
+ * @return the instance manager
*/
- protected ComponentManagerImpl getComponentManager() { return m_componentManager; }
+ protected InstanceManager getInstanceManager() { return m_manager; }
/**
* When the state change call the associated hooks.
* @see org.apache.felix.ipojo.Handler#stateChanged(int)
*/
public void stateChanged(int state) {
- Activator.getLogger().log(Level.INFO, "[" + m_componentManager.getComponentMetatada().getClassName() + "] State changed in callback handler, check " + m_callbacks.length + " callbacks. Transition : " + m_state + " -> " + state);
for (int i = 0; i < m_callbacks.length; i++) {
- if (m_callbacks[i].getMetadata().getInitialState() == m_state && m_callbacks[i].getMetadata().getFinalState() == state) {
+ if (m_callbacks[i].getInitialState() == m_state && m_callbacks[i].getFinalState() == state) {
try {
- Activator.getLogger().log(Level.INFO, "[" + m_componentManager.getComponentMetatada().getClassName() + "] Call the callback : " + m_callbacks[i].getMetadata().getMethod());
m_callbacks[i].call();
} catch (NoSuchMethodException e) {
- Activator.getLogger().log(Level.SEVERE, "[" + m_componentManager.getComponentMetatada().getClassName() + "] The callback method " + m_callbacks[i].getMetadata().getMethod() + " is not found : " + e.getMessage());
+ m_manager.getFactory().getLogger().log(Logger.ERROR, "[" + m_manager.getClassName() + "] The callback method " + m_callbacks[i].getMethod() + " is not found", e);
} catch (IllegalAccessException e) {
- Activator.getLogger().log(Level.SEVERE, "[" + m_componentManager.getComponentMetatada().getClassName() + "] The callback method " + m_callbacks[i].getMetadata().getMethod() + " is not accessible : " + e.getMessage());
+ m_manager.getFactory().getLogger().log(Logger.ERROR, "[" + m_manager.getClassName() + "] The callback method " + m_callbacks[i].getMethod() + " is not accessible", e);
} catch (InvocationTargetException e) {
- Activator.getLogger().log(Level.SEVERE, "[" + m_componentManager.getComponentMetatada().getClassName() + "] The callback method " + m_callbacks[i].getMetadata().getMethod() + " has throws an exception : " + e.getMessage() + " -> " + e.getCause());
+ m_manager.getFactory().getLogger().log(Logger.ERROR, "[" + m_manager.getClassName() + "] The callback method " + m_callbacks[i].getMethod() + " has throws an exception : " + e.getMessage() + " -> " + e.getCause());
}
}
}
diff --git a/ipojo/src/main/java/org/apache/felix/ipojo/handlers/lifecycle/callback/LifecycleCallbackMetadata.java b/ipojo/src/main/java/org/apache/felix/ipojo/handlers/lifecycle/callback/LifecycleCallbackMetadata.java
deleted file mode 100644
index 63c333f..0000000
--- a/ipojo/src/main/java/org/apache/felix/ipojo/handlers/lifecycle/callback/LifecycleCallbackMetadata.java
+++ /dev/null
@@ -1,98 +0,0 @@
-/*
- * 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.handlers.lifecycle.callback;
-
-import org.apache.felix.ipojo.ComponentManagerImpl;
-
-/**
- * Lifecycle callback metadata.
- * @author <a href="mailto:felix-dev@incubator.apache.org">Felix Project Team</a>
- */
-public class LifecycleCallbackMetadata {
-
- /**
- * Initial state of the transition.
- */
- private int m_initialState;
-
- /**
- * Final state of the transition.
- */
- private int m_finalState;
-
- /**
- * Method to call.
- */
- private String m_method;
-
- /**
- * is the method a static method ?
- */
- private boolean m_isStatic;
-
- // Constructor
-
- /**
- * Constructor.
- * @param initialState : initial state
- * @param finalState : final state
- * @param method : method name
- * @param isStatic : is the method a static method ?
- */
- public LifecycleCallbackMetadata(String initialState, String finalState, String method, boolean isStatic) {
- if (initialState.equals("VALID")) { m_initialState = ComponentManagerImpl.VALID; }
- if (initialState.equals("INVALID")) { m_initialState = ComponentManagerImpl.INVALID; }
- if (finalState.equals("VALID")) { m_finalState = ComponentManagerImpl.VALID; }
- if (finalState.equals("INVALID")) { m_finalState = ComponentManagerImpl.INVALID; }
-
- m_method = method;
- m_isStatic = isStatic;
- }
-
- // Getters
-
- /**
- * @return Returns the m_finalState.
- */
- public int getFinalState() {
- return m_finalState;
- }
-
- /**
- * @return Returns the m_initialState.
- */
- public int getInitialState() {
- return m_initialState;
- }
-
- /**
- * @return Returns the m_isStatic.
- */
- public boolean isStatic() {
- return m_isStatic;
- }
-
- /**
- * @return Returns the m_method.
- */
- public String getMethod() {
- return m_method;
- }
-
-}
diff --git a/ipojo/src/main/java/org/apache/felix/ipojo/handlers/providedservice/Property.java b/ipojo/src/main/java/org/apache/felix/ipojo/handlers/providedservice/Property.java
index 1b7451e..89b06e6 100644
--- a/ipojo/src/main/java/org/apache/felix/ipojo/handlers/providedservice/Property.java
+++ b/ipojo/src/main/java/org/apache/felix/ipojo/handlers/providedservice/Property.java
@@ -21,10 +21,9 @@
import java.lang.reflect.Array;
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;
+import org.apache.felix.ipojo.util.Logger;
/**
* Represent a property i.e. a set : [name, type, value].
@@ -46,37 +45,57 @@
* Value of the property (before we know the type).
*/
private Object m_value;
+
+ /**
+ * Field of the property.
+ */
+ private String m_field;
/**
- * Metadata of the property.
+ * Name of the property.
*/
- private PropertyMetadata m_metadata;
+ private String m_name;
+
+ /**
+ * Type of the property.
+ */
+ private String m_type;
+
+ /**
+ * String value of the property (initial value).
+ */
+ private String m_initialValue;
/**
* Property constructor.
* @param ps : the provided service
* @param pm : metadata of the property
*/
- public Property(ProvidedService ps, PropertyMetadata pm) {
+ public Property(ProvidedService ps, String name, String field, String type, String value, Element manipulation) {
m_providedService = ps;
- m_metadata = pm;
+ m_name = name;
+ m_field = field;
+ m_type = type;
+ m_initialValue = value;
- // Fix the type of the property if null
- if (pm.getType() == null) {
- // If the type is not found, it is a dynamic property
- Element manipulation = m_providedService.getComponentManager().getComponentMetatada().getMetadata().getElements("Manipulation")[0];
- String type = null;
- String field = m_metadata.getField();
- 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;
- }
- }
- pm.setType(type);
+ // Dynamic property case :
+ if (m_field != null) {
+ if (m_name == null) { m_name = m_field; }
}
-
- if (pm.getValue() != null) { setValue(pm.getValue()); }
+
+ // 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) { 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); }
}
/**
@@ -88,27 +107,15 @@
*/
public Property(ProvidedService ps, String name, Object value) {
m_providedService = ps;
- m_metadata = new PropertyMetadata(name, null, value.getClass().getName(), null);
+ m_name = name;
+ m_type = value.getClass().getName();
m_value = value;
}
/**
* @return the Object value of the property
*/
- protected Object get() {
- if (m_value == null) {
- Activator.getLogger().log(Level.INFO, "[" + m_providedService.getComponentManager().getComponentMetatada().getClassName() + "] A property " + m_metadata.getName() + " can not be returned : no value assigned");
- }
- return m_value;
- }
-
-
- /**
- * @return the property metadata.
- */
- public PropertyMetadata getMetadata() {
- return m_metadata;
- }
+ protected Object get() { return m_value; }
/**
* This method is automaticaly called when the value of the property is changed.
@@ -143,13 +150,10 @@
* @param value : value of the property (String)
*/
private void setValue(String value) {
- String type = m_metadata.getType();
-
- Activator.getLogger().log(Level.INFO, "[" + m_providedService.getComponentManager().getComponentMetatada().getClassName() + "] Set the value of the property " + m_metadata.getName() + " [" + m_metadata.getType() + "] " + " with the value : " + value);
// Array :
- if (type.endsWith("[]")) {
- String internalType = type.substring(0, type.length() - 2);
+ if (m_type.endsWith("[]")) {
+ String internalType = m_type.substring(0, m_type.length() - 2);
value = value.substring(1, value.length() - 1);
String[] values = value.split(",");
setArrayValue(internalType, values);
@@ -157,40 +161,39 @@
}
// Simple :
-
- if (type.equals("string") || type.equals("String")) { m_value = new String(value); return; }
- if (type.equals("boolean")) { m_value = new Boolean(value); return; }
- if (type.equals("byte")) { m_value = new Byte(value); return; }
- if (type.equals("short")) { m_value = new Short(value); return; }
- if (type.equals("int")) { m_value = new Integer(value); return; }
- if (type.equals("long")) { m_value = new Long(value); return; }
- if (type.equals("float")) { m_value = new Float(value); return; }
- if (type.equals("double")) { m_value = new Double(value); return; }
+ if (m_type.equals("string") || m_type.equals("String")) { m_value = new String(value); return; }
+ if (m_type.equals("boolean")) { m_value = new Boolean(value); return; }
+ if (m_type.equals("byte")) { m_value = new Byte(value); return; }
+ if (m_type.equals("short")) { m_value = new Short(value); return; }
+ if (m_type.equals("int")) { m_value = new Integer(value); return; }
+ if (m_type.equals("long")) { m_value = new Long(value); return; }
+ if (m_type.equals("float")) { m_value = new Float(value); return; }
+ if (m_type.equals("double")) { m_value = new Double(value); 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 {
- Class c = m_providedService.getComponentManager().getContext().getBundle().loadClass(type);
+ Class c = m_providedService.getInstanceManager().getContext().getBundle().loadClass(m_type);
//Class string = m_providedService.getComponentManager().getContext().getBundle().loadClass("java.lang.String");
Constructor cst = c.getConstructor(new Class[] {String.class});
m_value = cst.newInstance(new Object[] {value});
} catch (ClassNotFoundException e) {
- System.err.println("Class not found exception in setValue on " + type);
+ System.err.println("Class not found exception in setValue on " + m_type);
e.printStackTrace();
} catch (SecurityException e) {
e.printStackTrace();
} catch (NoSuchMethodException e) {
- System.err.println("Constructor not found exeption in setValue on " + type);
+ System.err.println("Constructor not found exeption in setValue on " + m_type);
e.printStackTrace();
} catch (IllegalArgumentException e) {
- System.err.println("Argument problem to call the constructor of the type " + type);
+ System.err.println("Argument problem to call the constructor of the type " + m_type);
e.printStackTrace();
} catch (InstantiationException e) {
- System.err.println("Instantiation problem " + type);
+ System.err.println("Instantiation problem " + m_type);
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (InvocationTargetException e) {
- System.err.println("Invocation problem " + type);
+ System.err.println("Invocation problem " + m_type);
e.printStackTrace();
}
}
@@ -245,7 +248,7 @@
// 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_providedService.getComponentManager().getContext().getBundle().loadClass(internalType);
+ Class c = m_providedService.getInstanceManager().getContext().getBundle().loadClass(internalType);
Constructor cst = c.getConstructor(new Class[] {String.class});
Object[] ob = (Object[]) Array.newInstance(c, values.length);
for (int i = 0; i < values.length; i++) {
@@ -279,4 +282,31 @@
* @return the value of the property.
*/
public Object getValue() { return m_value; }
+
+ /**
+ * @return the name of the property
+ */
+ public String getName() { return m_name; }
+
+ /**
+ * @return the field name of the property (null if the property has no field).
+ */
+ protected String getField() { return m_field; }
+
+ /**
+ * Set the type of the property.
+ * @param type : the type to attached to the property
+ */
+ public void setType(String type) { m_type = type; }
+
+ /**
+ * @return the type of the property.
+ */
+ public String getType() { return m_type; }
+
+ /**
+ * @return the initial value of the property.
+ */
+ public String getInitialValue() { return m_initialValue; }
+
}
diff --git a/ipojo/src/main/java/org/apache/felix/ipojo/handlers/providedservice/PropertyMetadata.java b/ipojo/src/main/java/org/apache/felix/ipojo/handlers/providedservice/PropertyMetadata.java
deleted file mode 100644
index 3b3b42f..0000000
--- a/ipojo/src/main/java/org/apache/felix/ipojo/handlers/providedservice/PropertyMetadata.java
+++ /dev/null
@@ -1,95 +0,0 @@
-/*
- * 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.handlers.providedservice;
-
-/**
- * Property metadata : either static either dynamic.
- * @author <a href="mailto:felix-dev@incubator.apache.org">Felix Project Team</a>
- */
-public class PropertyMetadata {
-
- /**
- * Field of the property.
- */
- private String m_field;
-
- /**
- * Name of the property.
- */
- private String m_name;
-
- /**
- * Type of the property.
- */
- private String m_type;
-
- /**
- * String value of the property (initial value).
- */
- private String m_value;
-
- //Constructor
-
- /**
- * Constructor.
- * @param name : name of the property
- * @param field : field of the property
- * @param type : type of the property
- * @param value : initial value of the property
- */
- public PropertyMetadata(String name, String field, String type, String value) {
- m_name = name;
- m_field = field;
- m_type = type;
- m_value = value;
-
- // Dynamic property case :
- if (m_field != null) {
- if (m_name == null) { m_name = m_field; }
- }
- }
-
- /**
- * @return the field name.
- */
- public String getField() { return m_field; };
-
- /**
- * @return the property name.
- */
- public String getName() { return m_name; };
-
- /**
- * @return the type of the property.
- */
- public String getType() { return m_type; };
-
- /**
- * @return the initial value.
- */
- public String getValue() { return m_value; }
-
- /**
- * Set the type of the property (dynamic property only).
- * @param type : the type of the property.
- */
- public void setType(String type) { m_type = type; }
-
-
-}
diff --git a/ipojo/src/main/java/org/apache/felix/ipojo/handlers/providedservice/ProvidedService.java b/ipojo/src/main/java/org/apache/felix/ipojo/handlers/providedservice/ProvidedService.java
index b0be97f..7136732 100644
--- a/ipojo/src/main/java/org/apache/felix/ipojo/handlers/providedservice/ProvidedService.java
+++ b/ipojo/src/main/java/org/apache/felix/ipojo/handlers/providedservice/ProvidedService.java
@@ -21,10 +21,9 @@
import java.util.Dictionary;
import java.util.Enumeration;
import java.util.Properties;
-import java.util.logging.Level;
-import org.apache.felix.ipojo.ComponentManagerImpl;
-import org.apache.felix.ipojo.Activator;
+import org.apache.felix.ipojo.InstanceManager;
+import org.apache.felix.ipojo.util.Logger;
import org.osgi.framework.Bundle;
import org.osgi.framework.ServiceFactory;
import org.osgi.framework.ServiceReference;
@@ -58,6 +57,16 @@
public static final int SERVICE_FACTORY = 1;
/**
+ * At this time, it is only the java interface full name.
+ */
+ private String[] m_serviceSpecification = new String[0];
+
+ /**
+ * Factory policy.
+ */
+ private int m_factoryPolicy = SINGLETON_FACTORY;
+
+ /**
* The service registration.
* is null when the service is not registred.
* m_serviceRegistration : ServiceRegistration
@@ -65,17 +74,12 @@
private ServiceRegistration m_serviceRegistration;
/**
- * Link to the component manager.
- * m_handler : ComponentManager
+ * Link to the owner handler.
+ * m_handler : Provided Service Handler
*/
private ProvidedServiceHandler m_handler;
/**
- * Provided service metadata.
- */
- private ProvidedServiceMetadata m_metadata;
-
- /**
* State of the provided service.
*/
private int m_state;
@@ -91,19 +95,26 @@
* @param handler : the provided service handler.
* @param psm : the provided service metadata.
*/
- public ProvidedService(ProvidedServiceHandler handler, ProvidedServiceMetadata psm) {
+ public ProvidedService(ProvidedServiceHandler handler, String[] specification, int factoryPolicy) {
m_handler = handler;
- m_metadata = psm;
- for (int i = 0; i < psm.getProperties().length; i++) {
- Property prop = new Property(this, ((PropertyMetadata) psm.getProperties()[i]));
- addProperty(prop);
- }
+
+ m_serviceSpecification = specification;
+ m_factoryPolicy = factoryPolicy;
+
//Add service pid and factory pid
- //TODO : test this
- PropertyMetadata pid_meta = new PropertyMetadata(org.osgi.framework.Constants.SERVICE_PID, null, "java.lang.String", handler.getComponentManager().getComponentName());
- PropertyMetadata factory_meta = new PropertyMetadata("factory.pid", null, "java.lang.String", handler.getComponentManager().getFactory().getFactoryName());
- addProperty(new Property(this, pid_meta));
- addProperty(new Property(this, factory_meta));
+ addProperty(new Property(this, org.osgi.framework.Constants.SERVICE_PID, handler.getInstanceManager().getInstanceName()));
+ addProperty(new Property(this, "factory.pid", handler.getInstanceManager().getFactory().getFactoryName()));
+ }
+
+ //TODO check if we need to erase previous props or add to the previous props.
+ /**
+ * Add properties to the provided service.
+ * @param props : the properties to attached to the service registration
+ */
+ protected void setProperties(Property[] props) {
+ for(int i = 0; i < props.length; i++) {
+ addProperty(props[i]);
+ }
}
/**
@@ -131,7 +142,7 @@
private synchronized void removeProperty(String name) {
int idx = -1;
for (int i = 0; i < m_properties.length; i++) {
- if (m_properties[i].getMetadata().getName() == name) { idx = i; break; }
+ if (m_properties[i].getName() == name) { idx = i; break; }
}
if (idx >= 0) {
@@ -163,16 +174,16 @@
*/
public Object getService(Bundle bundle, ServiceRegistration registration) {
- switch(m_metadata.getFactoryPolicy()) {
+ switch(m_factoryPolicy) {
case SINGLETON_FACTORY :
- return m_handler.getComponentManager().getInstance();
+ return m_handler.getInstanceManager().getPojoObject();
case SERVICE_FACTORY :
- return m_handler.getComponentManager().createInstance();
+ return m_handler.getInstanceManager().createPojoObject();
default :
- Activator.getLogger().log(Level.SEVERE, "[" + m_handler.getComponentManager().getComponentMetatada().getClassName() + "] Unknown factory policy for " + m_metadata.getServiceSpecification() + " : " + m_metadata.getFactoryPolicy());
+ m_handler.getInstanceManager().getFactory().getLogger().log(Logger.ERROR, "[" + m_handler.getInstanceManager().getClassName() + "] Unknown factory policy for " + m_serviceSpecification + " : " + m_factoryPolicy);
return null;
}
@@ -189,24 +200,6 @@
//Nothing to do
}
-// /**
-// * Validate the service dependencies of the current provided service.
-// * @return true if the service dependencies are valid
-// */
-// public boolean validate() {
-// boolean valide = true;
-// for (int i = 0; i < m_dependencies.length; i++) {
-// Dependency dep = m_dependencies[i];
-// valide = valide & dep.isSatisfied();
-// if (!valide) {
-// ComponentManager.getLogger().log(Level.INFO, "Service Dependency for " + m_interface + " not valid : " + dep.getInterface());
-// return false;
-// }
-// }
-// ComponentManager.getLogger().log(Level.INFO, "Service dependencies for " + m_interface + " are valid");
-// return valide;
-// }
-
/**
* Register the service.
* The service object must be able to serve this service.
@@ -215,18 +208,17 @@
protected void registerService() {
if (m_state != REGISTERED) {
String spec = "";
- for (int i = 0; i < m_metadata.getServiceSpecification().length; i++) {
- spec = spec + m_metadata.getServiceSpecification()[i] + ", ";
+ for (int i = 0; i < m_serviceSpecification.length; i++) {
+ spec = spec + m_serviceSpecification[i] + ", ";
}
- Activator.getLogger().log(Level.INFO, "[" + m_handler.getComponentManager().getComponentMetatada().getClassName() + "] Register the service : " + spec);
// Contruct the service properties list
Properties serviceProperties = getServiceProperties();
m_state = REGISTERED;
synchronized (this) {
m_serviceRegistration =
- m_handler.getComponentManager().getContext().registerService(
- m_metadata.getServiceSpecification(), this, serviceProperties);
+ m_handler.getInstanceManager().getContext().registerService(
+ m_serviceSpecification, this, serviceProperties);
}
}
}
@@ -252,10 +244,10 @@
}
/**
- * @return the component manager.
+ * @return the instance manager.
*/
- protected ComponentManagerImpl getComponentManager() {
- return m_handler.getComponentManager();
+ protected InstanceManager getInstanceManager() {
+ return m_handler.getInstanceManager();
}
/**
@@ -268,7 +260,7 @@
Properties serviceProperties = new Properties();
for (int i = 0; i < m_properties.length; i++) {
if (m_properties[i].get() != null) {
- serviceProperties.put(m_properties[i].getMetadata().getName(), m_properties[i].get().toString());
+ serviceProperties.put(m_properties[i].getName(), m_properties[i].get());
}
}
return serviceProperties;
@@ -299,13 +291,6 @@
}
/**
- * @return the propvided service metadata.
- */
- public ProvidedServiceMetadata getMetadata() {
- return m_metadata;
- }
-
- /**
* Add properties to the list.
* @param props : properties to add
*/
@@ -333,4 +318,9 @@
update();
}
+ /**
+ * @return the list of provided service specifications (i.e. java interface).
+ */
+ public String[] getServiceSpecification() { return m_serviceSpecification; }
+
}
diff --git a/ipojo/src/main/java/org/apache/felix/ipojo/handlers/providedservice/ProvidedServiceHandler.java b/ipojo/src/main/java/org/apache/felix/ipojo/handlers/providedservice/ProvidedServiceHandler.java
index 3deda1c..15517f8 100644
--- a/ipojo/src/main/java/org/apache/felix/ipojo/handlers/providedservice/ProvidedServiceHandler.java
+++ b/ipojo/src/main/java/org/apache/felix/ipojo/handlers/providedservice/ProvidedServiceHandler.java
@@ -19,14 +19,14 @@
package org.apache.felix.ipojo.handlers.providedservice;
import java.util.Dictionary;
-import java.util.logging.Level;
-import org.apache.felix.ipojo.Activator;
-import org.apache.felix.ipojo.ComponentInfo;
-import org.apache.felix.ipojo.ComponentManagerImpl;
import org.apache.felix.ipojo.Handler;
-import org.apache.felix.ipojo.PropertyInfo;
+import org.apache.felix.ipojo.InstanceManager;
+import org.apache.felix.ipojo.architecture.ComponentDescription;
+import org.apache.felix.ipojo.architecture.PropertyDescription;
import org.apache.felix.ipojo.metadata.Element;
+import org.apache.felix.ipojo.util.Logger;
+import org.osgi.framework.Constants;
/**
* @author <a href="mailto:felix-dev@incubator.apache.org">Felix Project Team</a>
@@ -40,9 +40,9 @@
private ProvidedService[] m_providedServices = new ProvidedService[0];
/**
- * The component manager.
+ * The instance manager.
*/
- private ComponentManagerImpl m_componentManager;
+ private InstanceManager m_manager;
/**
* Add a provided service to the list .
@@ -64,9 +64,9 @@
}
/**
- * @return the component manager.
+ * @return the instance manager.
*/
- public ComponentManagerImpl getComponentManager() { return m_componentManager; }
+ public InstanceManager getInstanceManager() { return m_manager; }
/**
* @return the list of the provided service.
@@ -74,17 +74,18 @@
public ProvidedService[] getProvidedService() { return m_providedServices; }
/**
- * @see org.apache.felix.ipojo.Handler#configure(org.apache.felix.ipojo.ComponentManagerImpl, org.apache.felix.ipojo.metadata.Element)
+ * @see org.apache.felix.ipojo.Handler#configure(org.apache.felix.ipojo.InstanceManager, org.apache.felix.ipojo.metadata.Element)
*/
- public void configure(ComponentManagerImpl cm, Element componentMetadata, Dictionary configuration) {
- // Fix the component manager & clean the provided service list
- m_componentManager = cm;
+ public void configure(InstanceManager im, Element componentMetadata, Dictionary configuration) {
+ // Fix the instance manager & clean the provided service list
+ m_manager = im;
- ComponentInfo ci = cm.getComponentInfo();
+ ComponentDescription cd = im.getComponentDescription();
m_providedServices = new ProvidedService[0];
// Create the dependency according to the component metadata
Element[] providedServices = componentMetadata.getElements("Provides");
+ Element manipulation = componentMetadata.getElements("Manipulation")[0];
for (int i = 0; i < providedServices.length; i++) {
// Create a ProvidedServiceMetadata object
@@ -97,7 +98,6 @@
serviceSpecification = new String[spec.length];
for (int j = 0; j < spec.length; j++) { serviceSpecification[j] = spec[j].trim(); }
} else {
- Element manipulation = m_componentManager.getComponentMetatada().getMetadata().getElements("Manipulation")[0];
serviceSpecification = new String[manipulation.getElements("Interface").length];
for (int j = 0; j < manipulation.getElements("Interface").length; j++) {
serviceSpecification[j] = manipulation.getElements("Interface")[j].getAttribute("name");
@@ -105,13 +105,14 @@
}
// Get the factory policy
- int factory = ProvidedServiceMetadata.SINGLETON_FACTORY;
+ int factory = ProvidedService.SINGLETON_FACTORY;
if (providedServices[i].containsAttribute("factory") && providedServices[i].getAttribute("factory").equals("service")) { factory = ProvidedService.SERVICE_FACTORY; }
- // Then create the provided service metadata
- ProvidedServiceMetadata psm = new ProvidedServiceMetadata(serviceSpecification, factory);
+ // Then create the provided service
+ ProvidedService ps = new ProvidedService(this, serviceSpecification, factory);
Element[] props = providedServices[i].getElements("Property");
+ Property[] properties = new Property[props.length];
for (int j = 0; j < props.length; j++) {
String name = null;
if (props[j].containsAttribute("name")) { name = props[j].getAttribute("name"); }
@@ -125,24 +126,29 @@
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); } }
- PropertyMetadata pm = new PropertyMetadata(name, field, type, value);
- psm.addProperty(pm);
+ Property prop = new Property(ps, name, field, type, value, manipulation);
+ properties[j] = prop;
}
- // Create the provided service object
- ProvidedService ps = new ProvidedService(this, psm);
- if (checkProvidedService(ps)) {
+ // Attached to properties to the provided service
+ ps.setProperties(properties);
+
+ if (checkProvidedService(ps, manipulation)) {
addProvidedService(ps);
// Change ComponentInfo
- for (int k = 0; k < ps.getMetadata().getServiceSpecification().length; k++) { ci.addProvidedServiceSpecification(ps.getMetadata().getServiceSpecification()[k]); }
- for (int k = 0; k < ps.getMetadata().getProperties().length; k++) { ci.addProperty(new PropertyInfo(ps.getMetadata().getProperties()[k].getName(), ps.getMetadata().getProperties()[k].getType(), ps.getMetadata().getProperties()[k].getValue())); }
+ 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")) {
+ cd.addProperty(new PropertyDescription(ps.getProperties()[k].getName(), ps.getProperties()[k].getType(), ps.getProperties()[k].getInitialValue()));
+ }
+ }
}
else {
String itfs = "";
for (int j = 0; j < serviceSpecification.length; j++) {
itfs = itfs + " " + serviceSpecification[j];
}
- Activator.getLogger().log(Level.SEVERE, "[" + m_componentManager.getComponentMetatada().getClassName() + "] The provided service" + itfs + " is not valid, it will be removed");
+ m_manager.getFactory().getLogger().log(Logger.ERROR, "[" + m_manager.getClassName() + "] The provided service" + itfs + " is not valid, it will be removed");
ps = null;
}
@@ -156,34 +162,19 @@
Property prop = ps.getProperties()[j];
// Check if the instance configuration has a value for this property
- if (prop.getMetadata().getName() != null && configuration.get(prop.getMetadata().getName()) != null && !(configuration.get(prop.getMetadata().getName()) instanceof String)) { prop.set(configuration.get(prop.getMetadata().getName())); }
- else { if (prop.getMetadata().getField() != null && configuration.get(prop.getMetadata().getField()) != null && !(configuration.get(prop.getMetadata().getField()) instanceof String)) { prop.set(configuration.get(prop.getMetadata().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.getMetadata().getField() != null) {
+ if (prop.getField() != null) {
String[] newFields = new String[fields.length + 1];
System.arraycopy(fields, 0, newFields, 0, fields.length);
- newFields[fields.length] = prop.getMetadata().getField();
+ newFields[fields.length] = prop.getField();
fields = newFields;
}
}
}
- m_componentManager.register(this, fields); }
- }
-
- /**
- * Is the specicifaction s in the list ?
- * @param s : the specitication to search
- * @return true if s is in the list
- */
- private boolean containsInterface(String s) {
- Element manipulation = m_componentManager.getComponentMetatada().getMetadata().getElements("Manipulation")[0];
- for (int i = 0; i < manipulation.getElements("Interface").length; i++) {
- if (manipulation.getElements("Interface")[i].getAttribute("name").equals(s)) {
- return true;
- }
- }
- return false;
+ m_manager.register(this, fields); }
}
/**
@@ -191,25 +182,30 @@
* @param ps : the provided service to check
* @return true if the provided service is correct
*/
- private boolean checkProvidedService(ProvidedService ps) {
+ private boolean checkProvidedService(ProvidedService ps, Element manipulation) {
- for (int i = 0; i < ps.getMetadata().getServiceSpecification().length; i++) {
- if (!containsInterface(ps.getMetadata().getServiceSpecification()[i])) {
- Activator.getLogger().log(Level.SEVERE, "[" + m_componentManager.getComponentMetatada().getClassName() + "] The service specification " + ps.getMetadata().getServiceSpecification()[i] + " is not implemented by the component class");
- return false;
+ for (int i = 0; i < ps.getServiceSpecification().length; i++) {
+ boolean b = false;
+ for (int ii = 0; ii < manipulation.getElements("Interface").length; ii++) {
+ if (manipulation.getElements("Interface")[ii].getAttribute("name").equals(ps.getServiceSpecification()[i])) {
+ b = true;
+ }
}
+ 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;
+ }
+
}
// Fix internal property type
for (int i = 0; i < ps.getProperties().length; i++) {
Property prop = ps.getProperties()[i];
- String field = prop.getMetadata().getField();
+ String field = prop.getField();
if (field == null) {
- // Static dependency -> Nothing to check
- return true;
+ return true; // Static dependency -> Nothing to check
} else {
- Element manipulation = getComponentManager().getComponentMetatada().getMetadata().getElements("Manipulation")[0];
String type = null;
for (int j = 0; j < manipulation.getElements("Field").length; j++) {
if (field.equals(manipulation.getElements("Field")[j].getAttribute("name"))) {
@@ -218,26 +214,10 @@
}
}
if (type == null) {
- Activator.getLogger().log(Level.SEVERE, "[" + m_componentManager.getComponentMetatada().getClassName() + "] A declared property was not found in the class : " + prop.getMetadata().getField());
+ m_manager.getFactory().getLogger().log(Logger.ERROR, "[" + m_manager.getClassName() + "] A declared property was not found in the class : " + prop.getField());
return false;
}
-
- if (type != null) {
-// if (type.endsWith("[]")) {
-// Activator.getLogger().log(Level.SEVERE, "[" + m_componentManager.getComponentMetatada().getClassName() + "] An array property was found in the class [Not implemented yet] : " + prop.getMetadata().getField());
-// return false;
-// }
-
- if (prop.getMetadata().getType() == null) { prop.getMetadata().setType(type); }
-
- if (!prop.getMetadata().getType().equals(type)) {
- Activator.getLogger().log(Level.WARNING, "[" + m_componentManager.getComponentMetatada().getClassName() + "] The field type [" + type + "] and the declared type [" + prop.getMetadata().getType() + "] are not the same for " + prop.getMetadata().getField());
- prop.getMetadata().setType(type);
- }
- }
- else {
- Activator.getLogger().log(Level.WARNING, "[" + m_componentManager.getComponentMetatada().getClassName() + "] The declared property " + prop.getMetadata().getField() + " does not exist in the code");
- }
+ prop.setType(type); //Set the type
}
}
return true;
@@ -259,8 +239,8 @@
* @see org.apache.felix.ipojo.Handler#start()
*/
public void start() {
- Activator.getLogger().log(Level.INFO, "[" + m_componentManager.getComponentMetatada().getClassName() + "] Start the provided service handler");
- for (int i = 0; (m_componentManager.getState() == ComponentManagerImpl.VALID) && i < m_providedServices.length; i++) {
+ 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();
}
}
@@ -274,7 +254,7 @@
ProvidedService ps = m_providedServices[i];
for (int j = 0; j < ps.getProperties().length; j++) {
Property prop = ps.getProperties()[j];
- if (fieldName.equals(prop.getMetadata().getField())) {
+ if (fieldName.equals(prop.getField())) {
// it is the associated property
prop.set(value);
}
@@ -291,7 +271,7 @@
ProvidedService ps = m_providedServices[i];
for (int j = 0; j < ps.getProperties().length; j++) {
Property prop = ps.getProperties()[j];
- if (fieldName.equals(prop.getMetadata().getField())) {
+ if (fieldName.equals(prop.getField())) {
// it is the associated property
return prop.get();
}
@@ -308,13 +288,13 @@
*/
public void stateChanged(int state) {
// If the new state is UNRESOLVED => unregister all the services
- if (state == ComponentManagerImpl.INVALID) {
+ if (state == InstanceManager.INVALID) {
stop();
return;
}
// If the new state is VALID => regiter all the services
- if (state == ComponentManagerImpl.VALID) {
+ if (state == InstanceManager.VALID) {
start();
return;
}
diff --git a/ipojo/src/main/java/org/apache/felix/ipojo/handlers/providedservice/ProvidedServiceMetadata.java b/ipojo/src/main/java/org/apache/felix/ipojo/handlers/providedservice/ProvidedServiceMetadata.java
deleted file mode 100644
index b16f299..0000000
--- a/ipojo/src/main/java/org/apache/felix/ipojo/handlers/providedservice/ProvidedServiceMetadata.java
+++ /dev/null
@@ -1,102 +0,0 @@
-/*
- * 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.handlers.providedservice;
-
-
-/**
- * Provided Service Metadata.
- * @author <a href="mailto:felix-dev@incubator.apache.org">Felix Project Team</a>
- */
-public class ProvidedServiceMetadata {
-
- /**
- * Factory Policy : SINGLETON_FACTORY.
- */
- public static final int SINGLETON_FACTORY = 0;
-
- /**
- * Factory policy : SERVICE_FACTORY.
- */
- public static final int SERVICE_FACTORY = 1;
-
- /**
- * At this time, it is only the java interface full name.
- */
- private String[] m_serviceSpecification = new String[0];
-
- /**
- * List of proeprty metadata.
- */
- private PropertyMetadata[] m_properties = new PropertyMetadata[0];
-
- /**
- * Foactory policy.
- */
- private int m_factoryPolicy = SINGLETON_FACTORY;
-
- //CONSTRUCTOR :
-
- /**
- * Constructor.
- * @param specification : service specification (i.e. the interface)
- * @param factoryPolicy : the facotry policy.
- */
- public ProvidedServiceMetadata(String[] specification, int factoryPolicy) {
- m_serviceSpecification = specification;
- m_factoryPolicy = factoryPolicy;
- }
-
- // GETTERS :
-
-
- /**
- * @return the service specification (i.e. the interface)
- */
- public String[] getServiceSpecification() { return m_serviceSpecification; }
-
- /**
- * @return the property metadata list.
- */
- public PropertyMetadata[] getProperties() { return m_properties; }
-
- /**
- * @return the factory policy.
- */
- public int getFactoryPolicy() { return m_factoryPolicy; }
-
- // SETTERS :
-
- /**
- * Add the given property metadata to the property metadata list.
- * @param p : property metdata to add
- */
- protected void addProperty(PropertyMetadata p) {
- for (int i = 0; (m_properties != null) && (i < m_properties.length); i++) {
- if (m_properties[i] == p) { return; }
- }
-
- if (m_properties.length > 0) {
- PropertyMetadata[] newProp = new PropertyMetadata[m_properties.length + 1];
- System.arraycopy(m_properties, 0, newProp, 0, m_properties.length);
- newProp[m_properties.length] = p;
- m_properties = newProp;
- }
- else { m_properties = new PropertyMetadata[] {p}; }
- }
-}
diff --git a/ipojo/src/main/java/org/apache/felix/ipojo/parser/ManifestMetadataParser.java b/ipojo/src/main/java/org/apache/felix/ipojo/parser/ManifestMetadataParser.java
index e484be6..17451fd 100644
--- a/ipojo/src/main/java/org/apache/felix/ipojo/parser/ManifestMetadataParser.java
+++ b/ipojo/src/main/java/org/apache/felix/ipojo/parser/ManifestMetadataParser.java
@@ -113,7 +113,7 @@
}
/**
- * Parse the given dictionnary and create the components manager.
+ * Parse the given dictionnary and create the instance managers.
* @param dict : the given headers of the manifest file
* @throws ParseException : if any error occurs
*/
diff --git a/ipojo/src/main/java/org/apache/felix/ipojo/Callback.java b/ipojo/src/main/java/org/apache/felix/ipojo/util/Callback.java
similarity index 74%
rename from ipojo/src/main/java/org/apache/felix/ipojo/Callback.java
rename to ipojo/src/main/java/org/apache/felix/ipojo/util/Callback.java
index d410547..2136329 100644
--- a/ipojo/src/main/java/org/apache/felix/ipojo/Callback.java
+++ b/ipojo/src/main/java/org/apache/felix/ipojo/util/Callback.java
@@ -16,11 +16,12 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.apache.felix.ipojo;
+package org.apache.felix.ipojo.util;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
-import java.util.logging.Level;
+
+import org.apache.felix.ipojo.InstanceManager;
@@ -41,20 +42,20 @@
private boolean m_isStatic;
/**
- * Reference on the component manager.
+ * Reference on the instance manager.
*/
- private ComponentManagerImpl m_manager;
+ private InstanceManager m_manager;
/**
* LifecycleCallback constructor.
* @param method : the name of the method to call
* @param isStatic : is the method a static method
- * @param cm : the component manager of the component containing the method
+ * @param im : the instance manager of the component containing the method
*/
- public Callback(String method, boolean isStatic, ComponentManagerImpl cm) {
+ public Callback(String method, boolean isStatic, InstanceManager im) {
m_method = method;
m_isStatic = isStatic;
- m_manager = cm;
+ m_manager = im;
}
/**
@@ -64,7 +65,7 @@
* @throws IllegalAccessException : The method can not be invoked
*/
public void call() throws NoSuchMethodException, IllegalAccessException, InvocationTargetException {
- Activator.getLogger().log(Level.INFO, "[" + m_manager.getComponentMetatada().getClassName() + "] Call an callback method : " + m_method);
+ m_manager.getFactory().getLogger().log(Logger.INFO, "[" + m_manager.getClassName() + "] Call an callback method : " + m_method);
Method method = m_manager.getClazz().getMethod(m_method, new Class[] {});
method.setAccessible(true);
@@ -73,13 +74,13 @@
// Two cases :
// - if instances already exists : call on each instances
// - if no instance exists : create an instance
- if (m_manager.getInstances().length == 0) {
- Activator.getLogger().log(Level.INFO, "[" + m_manager.getComponentMetatada().getClassName() + "] Create the first instance " + m_manager.getInstance());
- method.invoke(m_manager.getInstance(), new Object[]{});
+ if (m_manager.getPojoObjects().length == 0) {
+ m_manager.getFactory().getLogger().log(Logger.INFO, "[" + m_manager.getClassName() + "] Create the first instance " + m_manager.getPojoObject());
+ method.invoke(m_manager.getPojoObject(), new Object[]{});
} else {
- for (int i = 0; i < m_manager.getInstances().length; i++) {
- Activator.getLogger().log(Level.INFO, "[" + m_manager.getComponentMetatada().getClassName() + "] Call the callback on the instance " + m_manager.getInstances()[i]);
- method.invoke(m_manager.getInstances()[i], new Object[]{});
+ for (int i = 0; i < m_manager.getPojoObjects().length; i++) {
+ m_manager.getFactory().getLogger().log(Logger.INFO, "[" + m_manager.getClassName() + "] Call the callback on the instance " + m_manager.getPojoObjects()[i]);
+ method.invoke(m_manager.getPojoObjects()[i], new Object[]{});
}
}
}
@@ -107,7 +108,7 @@
* @throws InvocationTargetException : an error occurs inside the called method
*/
public void call(Object[] arg) throws NoSuchMethodException, IllegalAccessException, InvocationTargetException {
- Activator.getLogger().log(Level.INFO, "[" + m_manager.getComponentMetatada().getClassName() + "] Call an callback method : " + m_method);
+ m_manager.getFactory().getLogger().log(Logger.INFO, "[" + m_manager.getClassName() + "] Call an callback method : " + m_method);
// Build an array of call for arg :
Class[] classes = new Class[arg.length];
@@ -122,12 +123,12 @@
// Two cases :
// - if instances already exists : call on each instances
// - if no instance exists : create an instance
- if (m_manager.getInstances().length == 0) {
- Activator.getLogger().log(Level.INFO, "[" + m_manager.getComponentMetatada().getClassName() + "] Create the first instance " + m_manager.getInstance());
- method.invoke(m_manager.getInstance(), new Object[]{});
+ if (m_manager.getPojoObjects().length == 0) {
+ m_manager.getFactory().getLogger().log(Logger.INFO, "[" + m_manager.getClassName() + "] Create the first instance " + m_manager.getPojoObject());
+ method.invoke(m_manager.getPojoObject(), new Object[]{});
} else {
- for (int i = 0; i < m_manager.getInstances().length; i++) {
- method.invoke(m_manager.getInstances()[i], arg);
+ for (int i = 0; i < m_manager.getPojoObjects().length; i++) {
+ method.invoke(m_manager.getPojoObjects()[i], arg);
}
}
}
diff --git a/ipojo/src/main/java/org/apache/felix/ipojo/util/Logger.java b/ipojo/src/main/java/org/apache/felix/ipojo/util/Logger.java
new file mode 100644
index 0000000..69efa5b
--- /dev/null
+++ b/ipojo/src/main/java/org/apache/felix/ipojo/util/Logger.java
@@ -0,0 +1,112 @@
+/*
+ * 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.util;
+
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.InvalidSyntaxException;
+import org.osgi.framework.ServiceEvent;
+import org.osgi.framework.ServiceListener;
+import org.osgi.framework.ServiceReference;
+import org.osgi.service.log.LogService;
+
+public class Logger implements ServiceListener{
+
+ public static final int ERROR = 1;
+ public static final int WARNING = 2;
+ public static final int INFO = 3;
+ public static final int DEBUG = 4;
+
+ private BundleContext m_context;
+ private ServiceReference m_ref;
+ private LogService m_log;
+
+ private String m_name;
+ private int m_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); }
+
+ try {
+ m_context.addServiceListener(this, "(objectClass="+LogService.class.getName() + ")");
+ } catch (InvalidSyntaxException e) { e.printStackTrace(); }
+ }
+
+ public void log(int level, String msg) {
+ if(m_level >= level) {
+ synchronized(this) { _log(level, msg, null); }
+ }
+ }
+
+ public void log(int level, String msg, Throwable ex) {
+ if(m_level >= level) {
+ synchronized(this) {_log(level, msg, ex); }
+ }
+ }
+
+ private void _log(int level, String msg, Throwable ex)
+ {
+ String s = msg;
+ s = (ex == null) ? s : s + " (" + ex.getMessage() + ")";
+ String message;
+ switch (level)
+ {
+ case DEBUG:
+ message = "[" + m_name + "] DEBUG: " + s;
+ 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); }
+ System.err.println(message);
+ break;
+ case INFO:
+ message = "[" + m_name + "] INFO: " + s;
+ 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); }
+ System.err.println(message);
+ break;
+ default:
+ System.err.println("[" + m_name + "] UNKNOWN[" + level + "]: " + s);
+ }
+ }
+
+ public void serviceChanged(ServiceEvent ev) {
+ 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()) {
+ 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); }
+ }
+
+ }
+}
diff --git a/ipojo/src/main/java/org/osgi/service/log/LogEntry.java b/ipojo/src/main/java/org/osgi/service/log/LogEntry.java
new file mode 100644
index 0000000..12e6c8d
--- /dev/null
+++ b/ipojo/src/main/java/org/osgi/service/log/LogEntry.java
@@ -0,0 +1,109 @@
+/*
+ * $Header: /cvshome/build/org.osgi.service.log/src/org/osgi/service/log/LogEntry.java,v 1.9 2006/06/16 16:31:49 hargrave Exp $
+ *
+ * Copyright (c) OSGi Alliance (2000, 2006). All Rights Reserved.
+ *
+ * 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.osgi.service.log;
+
+import org.osgi.framework.Bundle;
+import org.osgi.framework.ServiceReference;
+
+/**
+ * Provides methods to access the information contained in an individual Log
+ * Service log entry.
+ *
+ * <p>
+ * A <code>LogEntry</code> object may be acquired from the
+ * <code>LogReaderService.getLog</code> method or by registering a
+ * <code>LogListener</code> object.
+ *
+ * @version $Revision: 1.9 $
+ * @see LogReaderService#getLog
+ * @see LogListener
+ */
+public interface LogEntry {
+ /**
+ * Returns the bundle that created this <code>LogEntry</code> object.
+ *
+ * @return The bundle that created this <code>LogEntry</code> object;
+ * <code>null</code> if no bundle is associated with this
+ * <code>LogEntry</code> object.
+ */
+ public Bundle getBundle();
+
+ /**
+ * Returns the <code>ServiceReference</code> object for the service associated
+ * with this <code>LogEntry</code> object.
+ *
+ * @return <code>ServiceReference</code> object for the service associated
+ * with this <code>LogEntry</code> object; <code>null</code> if no
+ * <code>ServiceReference</code> object was provided.
+ */
+ public ServiceReference getServiceReference();
+
+ /**
+ * Returns the severity level of this <code>LogEntry</code> object.
+ *
+ * <p>
+ * This is one of the severity levels defined by the <code>LogService</code>
+ * interface.
+ *
+ * @return Severity level of this <code>LogEntry</code> object.
+ *
+ * @see LogService#LOG_ERROR
+ * @see LogService#LOG_WARNING
+ * @see LogService#LOG_INFO
+ * @see LogService#LOG_DEBUG
+ */
+ public int getLevel();
+
+ /**
+ * Returns the human readable message associated with this <code>LogEntry</code>
+ * object.
+ *
+ * @return <code>String</code> containing the message associated with this
+ * <code>LogEntry</code> object.
+ */
+ public String getMessage();
+
+ /**
+ * Returns the exception object associated with this <code>LogEntry</code>
+ * object.
+ *
+ * <p>
+ * In some implementations, the returned exception may not be the original
+ * exception. To avoid references to a bundle defined exception class, thus
+ * preventing an uninstalled bundle from being garbage collected, the Log
+ * Service may return an exception object of an implementation defined
+ * Throwable subclass. The returned object will attempt to provide as much
+ * information as possible from the original exception object such as the
+ * message and stack trace.
+ *
+ * @return <code>Throwable</code> object of the exception associated with this
+ * <code>LogEntry</code>;<code>null</code> if no exception is
+ * associated with this <code>LogEntry</code> object.
+ */
+ public Throwable getException();
+
+ /**
+ * Returns the value of <code>currentTimeMillis()</code> at the time this
+ * <code>LogEntry</code> object was created.
+ *
+ * @return The system time in milliseconds when this <code>LogEntry</code>
+ * object was created.
+ * @see "System.currentTimeMillis()"
+ */
+ public long getTime();
+}
diff --git a/ipojo/src/main/java/org/osgi/service/log/LogListener.java b/ipojo/src/main/java/org/osgi/service/log/LogListener.java
new file mode 100644
index 0000000..3731c28
--- /dev/null
+++ b/ipojo/src/main/java/org/osgi/service/log/LogListener.java
@@ -0,0 +1,51 @@
+/*
+ * $Header: /cvshome/build/org.osgi.service.log/src/org/osgi/service/log/LogListener.java,v 1.9 2006/06/16 16:31:49 hargrave Exp $
+ *
+ * Copyright (c) OSGi Alliance (2000, 2006). All Rights Reserved.
+ *
+ * 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.osgi.service.log;
+
+import java.util.EventListener;
+
+/**
+ * Subscribes to <code>LogEntry</code> objects from the <code>LogReaderService</code>.
+ *
+ * <p>
+ * A <code>LogListener</code> object may be registered with the Log Reader Service
+ * using the <code>LogReaderService.addLogListener</code> method. After the
+ * listener is registered, the <code>logged</code> method will be called for each
+ * <code>LogEntry</code> object created. The <code>LogListener</code> object may be
+ * unregistered by calling the <code>LogReaderService.removeLogListener</code>
+ * method.
+ *
+ * @version $Revision: 1.9 $
+ * @see LogReaderService
+ * @see LogEntry
+ * @see LogReaderService#addLogListener(LogListener)
+ * @see LogReaderService#removeLogListener(LogListener)
+ */
+public interface LogListener extends EventListener {
+ /**
+ * Listener method called for each LogEntry object created.
+ *
+ * <p>
+ * As with all event listeners, this method should return to its caller as
+ * soon as possible.
+ *
+ * @param entry A <code>LogEntry</code> object containing log information.
+ * @see LogEntry
+ */
+ public void logged(LogEntry entry);
+}
diff --git a/ipojo/src/main/java/org/osgi/service/log/LogReaderService.java b/ipojo/src/main/java/org/osgi/service/log/LogReaderService.java
new file mode 100644
index 0000000..4176ebc
--- /dev/null
+++ b/ipojo/src/main/java/org/osgi/service/log/LogReaderService.java
@@ -0,0 +1,98 @@
+/*
+ * $Header: /cvshome/build/org.osgi.service.log/src/org/osgi/service/log/LogReaderService.java,v 1.10 2006/06/16 16:31:49 hargrave Exp $
+ *
+ * Copyright (c) OSGi Alliance (2000, 2006). All Rights Reserved.
+ *
+ * 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.osgi.service.log;
+
+import java.util.Enumeration;
+
+/**
+ * Provides methods to retrieve <code>LogEntry</code> objects from the log.
+ * <p>
+ * There are two ways to retrieve <code>LogEntry</code> objects:
+ * <ul>
+ * <li>The primary way to retrieve <code>LogEntry</code> objects is to register a
+ * <code>LogListener</code> object whose <code>LogListener.logged</code> method will
+ * be called for each entry added to the log.
+ * <li>To retrieve past <code>LogEntry</code> objects, the <code>getLog</code>
+ * method can be called which will return an <code>Enumeration</code> of all
+ * <code>LogEntry</code> objects in the log.
+ *
+ * @version $Revision: 1.10 $
+ * @see LogEntry
+ * @see LogListener
+ * @see LogListener#logged(LogEntry)
+ */
+public interface LogReaderService {
+ /**
+ * Subscribes to <code>LogEntry</code> objects.
+ *
+ * <p>
+ * This method registers a <code>LogListener</code> object with the Log Reader
+ * Service. The <code>LogListener.logged(LogEntry)</code> method will be
+ * called for each <code>LogEntry</code> object placed into the log.
+ *
+ * <p>
+ * When a bundle which registers a <code>LogListener</code> object is stopped
+ * or otherwise releases the Log Reader Service, the Log Reader Service must
+ * remove all of the bundle's listeners.
+ *
+ * <p>
+ * If this Log Reader Service's list of listeners already contains a
+ * listener <code>l</code> such that <code>(l==listener)</code>, this method
+ * does nothing.
+ *
+ * @param listener A <code>LogListener</code> object to register; the
+ * <code>LogListener</code> object is used to receive <code>LogEntry</code>
+ * objects.
+ * @see LogListener
+ * @see LogEntry
+ * @see LogListener#logged(LogEntry)
+ */
+ public void addLogListener(LogListener listener);
+
+ /**
+ * Unsubscribes to <code>LogEntry</code> objects.
+ *
+ * <p>
+ * This method unregisters a <code>LogListener</code> object from the Log
+ * Reader Service.
+ *
+ * <p>
+ * If <code>listener</code> is not contained in this Log Reader Service's list
+ * of listeners, this method does nothing.
+ *
+ * @param listener A <code>LogListener</code> object to unregister.
+ * @see LogListener
+ */
+ public void removeLogListener(LogListener listener);
+
+ /**
+ * Returns an <code>Enumeration</code> of all <code>LogEntry</code> objects in
+ * the log.
+ *
+ * <p>
+ * Each element of the enumeration is a <code>LogEntry</code> object, ordered
+ * with the most recent entry first. Whether the enumeration is of all
+ * <code>LogEntry</code> objects since the Log Service was started or some
+ * recent past is implementation-specific. Also implementation-specific is
+ * whether informational and debug <code>LogEntry</code> objects are included
+ * in the enumeration.
+ * @return An <code>Enumeration</code> of all <code>LogEntry</code> objects in
+ * the log.
+ */
+ public Enumeration getLog();
+}
diff --git a/ipojo/src/main/java/org/osgi/service/log/LogService.java b/ipojo/src/main/java/org/osgi/service/log/LogService.java
new file mode 100644
index 0000000..4858c58
--- /dev/null
+++ b/ipojo/src/main/java/org/osgi/service/log/LogService.java
@@ -0,0 +1,156 @@
+/*
+ * $Header: /cvshome/build/org.osgi.service.log/src/org/osgi/service/log/LogService.java,v 1.9 2006/06/16 16:31:49 hargrave Exp $
+ *
+ * Copyright (c) OSGi Alliance (2000, 2006). All Rights Reserved.
+ *
+ * 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.osgi.service.log;
+
+import org.osgi.framework.ServiceReference;
+
+/**
+ * Provides methods for bundles to write messages to the log.
+ *
+ * <p>
+ * <code>LogService</code> methods are provided to log messages; optionally with a
+ * <code>ServiceReference</code> object or an exception.
+ *
+ * <p>
+ * Bundles must log messages in the OSGi environment with a severity level
+ * according to the following hierarchy:
+ * <ol>
+ * <li>{@link #LOG_ERROR}
+ * <li>{@link #LOG_WARNING}
+ * <li>{@link #LOG_INFO}
+ * <li>{@link #LOG_DEBUG}
+ * </ol>
+ *
+ * @version $Revision: 1.9 $
+ */
+public interface LogService {
+ /**
+ * An error message (Value 1).
+ *
+ * <p>
+ * This log entry indicates the bundle or service may not be functional.
+ */
+ public static final int LOG_ERROR = 1;
+ /**
+ * A warning message (Value 2).
+ *
+ * <p>
+ * This log entry indicates a bundle or service is still functioning but may
+ * experience problems in the future because of the warning condition.
+ */
+ public static final int LOG_WARNING = 2;
+ /**
+ * An informational message (Value 3).
+ *
+ * <p>
+ * This log entry may be the result of any change in the bundle or service
+ * and does not indicate a problem.
+ */
+ public static final int LOG_INFO = 3;
+ /**
+ * A debugging message (Value 4).
+ *
+ * <p>
+ * This log entry is used for problem determination and may be irrelevant to
+ * anyone but the bundle developer.
+ */
+ public static final int LOG_DEBUG = 4;
+
+ /**
+ * Logs a message.
+ *
+ * <p>
+ * The <code>ServiceReference</code> field and the <code>Throwable</code> field
+ * of the <code>LogEntry</code> object will be set to <code>null</code>.
+ *
+ * @param level The severity of the message. This should be one of the
+ * defined log levels but may be any integer that is interpreted in a
+ * user defined way.
+ * @param message Human readable string describing the condition or
+ * <code>null</code>.
+ * @see #LOG_ERROR
+ * @see #LOG_WARNING
+ * @see #LOG_INFO
+ * @see #LOG_DEBUG
+ */
+ public void log(int level, String message);
+
+ /**
+ * Logs a message with an exception.
+ *
+ * <p>
+ * The <code>ServiceReference</code> field of the <code>LogEntry</code> object
+ * will be set to <code>null</code>.
+ *
+ * @param level The severity of the message. This should be one of the
+ * defined log levels but may be any integer that is interpreted in a
+ * user defined way.
+ * @param message The human readable string describing the condition or
+ * <code>null</code>.
+ * @param exception The exception that reflects the condition or
+ * <code>null</code>.
+ * @see #LOG_ERROR
+ * @see #LOG_WARNING
+ * @see #LOG_INFO
+ * @see #LOG_DEBUG
+ */
+ public void log(int level, String message, Throwable exception);
+
+ /**
+ * Logs a message associated with a specific <code>ServiceReference</code>
+ * object.
+ *
+ * <p>
+ * The <code>Throwable</code> field of the <code>LogEntry</code> will be set to
+ * <code>null</code>.
+ *
+ * @param sr The <code>ServiceReference</code> object of the service that this
+ * message is associated with or <code>null</code>.
+ * @param level The severity of the message. This should be one of the
+ * defined log levels but may be any integer that is interpreted in a
+ * user defined way.
+ * @param message Human readable string describing the condition or
+ * <code>null</code>.
+ * @see #LOG_ERROR
+ * @see #LOG_WARNING
+ * @see #LOG_INFO
+ * @see #LOG_DEBUG
+ */
+ public void log(ServiceReference sr, int level, String message);
+
+ /**
+ * Logs a message with an exception associated and a
+ * <code>ServiceReference</code> object.
+ *
+ * @param sr The <code>ServiceReference</code> object of the service that this
+ * message is associated with.
+ * @param level The severity of the message. This should be one of the
+ * defined log levels but may be any integer that is interpreted in a
+ * user defined way.
+ * @param message Human readable string describing the condition or
+ * <code>null</code>.
+ * @param exception The exception that reflects the condition or
+ * <code>null</code>.
+ * @see #LOG_ERROR
+ * @see #LOG_WARNING
+ * @see #LOG_INFO
+ * @see #LOG_DEBUG
+ */
+ public void log(ServiceReference sr, int level, String message,
+ Throwable exception);
+}