Applied patch (FELIX-270) to add the composite component "provider"
handler for dynamically providing a service from a composite component
description. Also improves the architecture infrastructure and moves
iPOJO to the new Maven Bundle Plugin.
git-svn-id: https://svn.apache.org/repos/asf/incubator/felix/trunk@529623 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/ipojo.arch/pom.xml b/ipojo.arch/pom.xml
index a6ca99d..4f1e91b 100644
--- a/ipojo.arch/pom.xml
+++ b/ipojo.arch/pom.xml
@@ -7,7 +7,7 @@
<modelVersion>4.0.0</modelVersion>
<packaging>ipojo-bundle</packaging>
<name>Apache Felix iPOJO Arch Command</name>
- <version>0.7.0-incubator-SNAPSHOT</version>
+ <version>0.7.1-incubator-SNAPSHOT</version>
<artifactId>org.apache.felix.ipojo.arch</artifactId>
<dependencies>
<dependency>
@@ -18,6 +18,12 @@
</dependency>
<dependency>
<groupId>${pom.groupId}</groupId>
+ <artifactId>org.apache.felix.ipojo.metadata</artifactId>
+ <version>${pom.version}</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>${pom.groupId}</groupId>
<artifactId>org.apache.felix.shell</artifactId>
<version>0.9.0-incubator-SNAPSHOT</version>
<scope>provided</scope>
@@ -32,7 +38,7 @@
<configuration>
<osgiManifest>
<bundleName>iPOJO Arch Command</bundleName>
- <bundleVersion>0.7.0.incubator-SNAPSHOT</bundleVersion>
+ <bundleVersion>0.7.1.incubator-SNAPSHOT</bundleVersion>
<bundleSymbolicName>${pom.artifactId}</bundleSymbolicName>
<bundleDescription>Architecture Shell Command (arch)</bundleDescription>
<iPOJOMetadata>metadata.xml</iPOJOMetadata>
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 b32123c..830b6bc 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
@@ -21,8 +21,8 @@
import java.io.PrintStream;
+import org.apache.felix.ipojo.ComponentInstance;
import org.apache.felix.ipojo.architecture.Architecture;
-import org.apache.felix.ipojo.architecture.HandlerDescription;
import org.apache.felix.ipojo.architecture.InstanceDescription;
import org.ungoverned.osgi.service.shell.Command;
@@ -49,7 +49,7 @@
* @see org.ungoverned.osgi.service.shell.Command#getUsage()
*/
public String getUsage() {
- return "arch -> Dispaly architecture information";
+ return "arch [instance name]";
}
/**
@@ -58,49 +58,32 @@
public String getShortDescription() {
return "Architecture command : display the architecture";
}
-
-
- /**
- * Return the String corresponding to a component state.
- * @param state : the state in int
- * @return : the string of the state (Stopped, Unresolved, Resolved) or "Unknown" if state is not revelant
- */
- private String getInstanceState(int state) {
- switch(state) {
- case(0) :
- return "STOPPED";
- case(1) :
- return "INVALID";
- case(2) :
- return "VALID";
- default :
- return "UNKNOWN";
- }
- }
/**
* @see org.ungoverned.osgi.service.shell.Command#execute(java.lang.String, java.io.PrintStream, java.io.PrintStream)
*/
public void execute(String line, PrintStream out, PrintStream err) {
synchronized(this) {
- for(int i=0; i < archiService.length; i++) {
- InstanceDescription instance = archiService[i].getInstanceDescription();
- out.println("Instance : " + instance.getName() + " (" + instance.getComponentDescription().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"; }
- String hi = hd.getHandlerInfo();
- out.println("Handler : " + hn + " : " + hv);
- if(!hi.equals("")) { out.println(hi); }
+ if(line.substring("arch".length()).trim().length() == 0) {
+ for(int i=0; i < archiService.length; i++) {
+ InstanceDescription instance = archiService[i].getInstanceDescription();
+ if(instance.getState() == ComponentInstance.VALID) {
+ out.println("Instance " + instance.getName() + " -> valid");
+ }
+ if(instance.getState() == ComponentInstance.INVALID) {
+ out.println("Instance " + instance.getName() + " -> invalid");
+ }
+ if(instance.getState() == ComponentInstance.STOPPED) {
+ out.println("Instance " + instance.getName() + " -> stopped");
+ }
}
-
- out.println("Created POJO Objects : ");
- for(int j=0; j < instance.getCreatedObjects().length; j++) {
- out.println("\t" + instance.getCreatedObjects()[j]);
+ } else {
+ String line2 = line.substring("arch".length()).trim();
+ for(int i=0; i < archiService.length; i++) {
+ InstanceDescription instance = archiService[i].getInstanceDescription();
+ if(instance.getName().equalsIgnoreCase(line2)) { out.println(instance.getDescription()); return;}
}
- out.print("\n");
+ err.println("Instance " + line2 + " not found");
}
}
diff --git a/ipojo.metadata/pom.xml b/ipojo.metadata/pom.xml
index 9f1fe50..5cea035 100644
--- a/ipojo.metadata/pom.xml
+++ b/ipojo.metadata/pom.xml
@@ -7,6 +7,6 @@
<modelVersion>4.0.0</modelVersion>
<artifactId>org.apache.felix.ipojo.metadata</artifactId>
<packaging>jar</packaging>
- <version>0.7.0-incubator-SNAPSHOT</version>
+ <version>0.7.1-incubator-SNAPSHOT</version>
<name>Apache Felix iPOJO Metadata</name>
</project>
diff --git a/ipojo.metadata/src/main/java/org/apache/felix/ipojo/metadata/Element.java b/ipojo.metadata/src/main/java/org/apache/felix/ipojo/metadata/Element.java
index 4a821f8..cd00a72 100644
--- a/ipojo.metadata/src/main/java/org/apache/felix/ipojo/metadata/Element.java
+++ b/ipojo.metadata/src/main/java/org/apache/felix/ipojo/metadata/Element.java
@@ -309,5 +309,81 @@
return ns;
}
+
+ public String toXMLString() {
+ return toXMLString(0);
+ }
+
+ private String toXMLString(int indent) {
+ String xml = "";
+
+ String tabs = "";
+ for(int j = 0; j < indent; j++) {
+ tabs += "\t";
+ }
+
+ if(m_nameSpace.equals("")) {
+ xml = tabs + "<" + m_name;
+ } else {
+ xml = tabs + "<" + m_nameSpace+":"+m_name;
+ }
+
+ for(int i = 0; i < m_attributes.length; i++) {
+ Attribute current = m_attributes[i];
+ if(current.getNameSpace().equals("")) {
+ xml += " " + current.getName() + "=\"" + current.getValue() + "\"";
+ } else {
+ xml += " " + current.getNameSpace() + ":" + current.getName() + "=\"" + current.getValue()+ "\"";
+ }
+ }
+
+ if(m_elements.length == 0) { xml += "/>"; return xml; }
+ else {
+ xml+=">";
+ for(int i = 0; i < m_elements.length; i++) {
+ xml += "\n";
+ xml += m_elements[i].toXMLString(indent+1);
+ }
+ xml+="\n" + tabs + "</"+m_name+">";
+ return xml;
+ }
+ }
+
+ public String toString() {
+ return toString(0);
+ }
+
+ private String toString(int indent) {
+ String xml = "";
+
+ String tabs = "";
+ for(int j = 0; j < indent; j++) {
+ tabs += "\t";
+ }
+
+ if(m_nameSpace.equals("")) {
+ xml = tabs + m_name;
+ } else {
+ xml = tabs + m_nameSpace+":"+m_name;
+ }
+
+ for(int i = 0; i < m_attributes.length; i++) {
+ Attribute current = m_attributes[i];
+ if(current.getNameSpace().equals("")) {
+ xml += " " + current.getName() + "=\"" + current.getValue() + "\"";
+ } else {
+ xml += " " + current.getNameSpace() + ":" + current.getName() + "=\"" + current.getValue()+ "\"";
+ }
+ }
+
+ if(m_elements.length == 0) { return xml; }
+ else {
+ for(int i = 0; i < m_elements.length; i++) {
+ xml += "\n";
+ xml += m_elements[i].toString(indent+1);
+ }
+ return xml;
+ }
+ }
}
diff --git a/ipojo.plugin/pom.xml b/ipojo.plugin/pom.xml
index b422357..3888168 100644
--- a/ipojo.plugin/pom.xml
+++ b/ipojo.plugin/pom.xml
@@ -6,7 +6,7 @@
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>org.apache.felix.ipojo.plugin</artifactId>
- <version>0.7.0-incubator-SNAPSHOT</version>
+ <version>0.7.1-incubator-SNAPSHOT</version>
<name>Apache Felix iPOJO Maven Plugin</name>
<packaging>maven-plugin</packaging>
<dependencies>
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 c61f91a..1367c13 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
@@ -152,7 +152,7 @@
private OsgiManifest osgiManifest;
private String[][] namespaces;
- private List referedPackages;
+ private List referredPackages;
/**
* Execute this Mojo
@@ -484,8 +484,8 @@
}
// Add refered imports form the metadata
- for(int i = 0; i < referedPackages.size(); i++) {
- String pack = (String) referedPackages.get(i);
+ for(int i = 0; i < referredPackages.size(); i++) {
+ String pack = (String) referredPackages.get(i);
referred.add(pack);
}
@@ -879,7 +879,7 @@
parser.parse(is);
meta = handler.getMetadata();
- referedPackages = handler.getReferredPackages();
+ referredPackages = handler.getReferredPackages();
} catch (MalformedURLException e) {
getLog().error("Malformed URL for " + outputDirectory+path+ "("+e.getMessage()+")");
diff --git a/ipojo/pom.xml b/ipojo/pom.xml
index eb1ea8d..9cc366f 100644
--- a/ipojo/pom.xml
+++ b/ipojo/pom.xml
@@ -5,10 +5,10 @@
<version>0.9.0-incubator-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
- <packaging>osgi-bundle</packaging>
+ <packaging>bundle</packaging>
<name>Apache Felix iPOJO</name>
<artifactId>org.apache.felix.ipojo</artifactId>
- <version>0.7.0-incubator-SNAPSHOT</version>
+ <version>0.7.1-incubator-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>${pom.groupId}</groupId>
@@ -24,39 +24,47 @@
<dependency>
<groupId>${pom.groupId}</groupId>
<artifactId>org.apache.felix.ipojo.metadata</artifactId>
- <version>0.7.0-incubator-SNAPSHOT</version>
+ <version>0.7.1-incubator-SNAPSHOT</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
- <groupId>org.apache.felix.plugins</groupId>
- <artifactId>maven-osgi-plugin</artifactId>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>maven-bundle-plugin</artifactId>
<extensions>true</extensions>
<configuration>
- <osgiManifest>
- <bundleName>iPOJO</bundleName>
- <bundleSymbolicName>${pom.artifactId}</bundleSymbolicName>
- <bundleVendor>Clement ESCOFFIER</bundleVendor>
- <bundleDescription> iPOJO </bundleDescription>
- <importPackage>
- org.osgi.framework; specification-version="1.3",
- 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.apache.felix.ipojo.util,
- org.apache.felix.ipojo.handlers.dependency,
- org.apache.felix.ipojo.handlers.providedservice,
- org.apache.felix.ipojo.composite,
- org.osgi.service.cm; specification-version="1.2",
- org.osgi.service.log; specification-version="1.3"
- </exportPackage>
- </osgiManifest>
+ <instructions>
+ <Bundle-Name>iPOJO</Bundle-Name>
+ <Bundle-Vendor>Clement ESCOFFIER</Bundle-Vendor>
+ <Bundle-Description> iPOJO </Bundle-Description>
+ <Import-Package>
+ org.osgi.framework; version="1.3",
+ org.osgi.service.cm; version="1.2",
+ org.osgi.service.log; version="1.3"
+ </Import-Package>
+ <Private-Package>
+ org.apache.felix.ipojo.composite.architecture,
+ org.apache.felix.ipojo.composite.service*,
+ org.apache.felix.ipojo.handlers.architecture,
+ org.apache.felix.ipojo.handlers.configuration,
+ org.apache.felix.ipojo.handlers.dependency.nullable,
+ org.apache.felix.ipojo.handlers.lifecycle.callback,
+ org.objectweb.asm*
+ </Private-Package>
+ <Export-Package>
+ org.apache.felix.ipojo; version="0.7.1",
+ org.apache.felix.ipojo.metadata; version="0.7.1",
+ org.apache.felix.ipojo.architecture; version="0.7.1",
+ org.apache.felix.ipojo.parser; version="0.7.1",
+ org.apache.felix.ipojo.util; version="0.7.1",
+ org.apache.felix.ipojo.handlers.dependency; version="0.7.1",
+ org.apache.felix.ipojo.handlers.providedservice; version="0.7.1",
+ org.apache.felix.ipojo.composite; version="0.7.1",
+ org.osgi.service.cm; version="1.2",
+ org.osgi.service.log; version="1.3"
+ </Export-Package>
+ </instructions>
</configuration>
</plugin>
</plugins>
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 0c41a8f..d243539 100644
--- a/ipojo/src/main/java/org/apache/felix/ipojo/Activator.java
+++ b/ipojo/src/main/java/org/apache/felix/ipojo/Activator.java
@@ -58,9 +58,10 @@
private Dictionary[] m_configurations;
/**
- * @return the bundle context
+ * Return the bundle context.
+ * @return the bundle context.
*/
- public BundleContext getBundleContext() { return m_bundleContext; }
+ BundleContext getBundleContext() { return m_bundleContext; }
/**
* Add a component factory to the factory list.
@@ -89,9 +90,11 @@
try {
parse();
- } catch (Exception e) {
- System.err.println("Parse error for the bundle " + m_bundleContext.getBundle().getBundleId() + " : " + e.getMessage());
+ } catch (IOException e) {
+ System.err.println("IO error for the bundle " + m_bundleContext.getBundle().getBundleId() + " : " + e.getMessage());
return;
+ } catch (ParseException e) {
+ System.err.println("Parse error for the bundle " + m_bundleContext.getBundle().getBundleId() + " : " + e.getMessage());
}
start(); // Call the internal start method
@@ -137,38 +140,42 @@
* Start the management factories and create instances.
*/
private void start() {
- // 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))) {
- try {
- m_factories[j].createComponentInstance(conf);
- created = true;
- } catch (UnacceptableConfiguration e) {
- System.err.println("Cannot create the instance " + conf.get("name") + " : " + e.getMessage());
- }
- }
- }
- 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);
+ // 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].getName();
+ if (conf.get("component") != null && (conf.get("component").equals(componentClass) || conf.get("component").equals(factoryName))) {
+ try {
+ m_factories[j].createComponentInstance(conf);
+ created = true;
+ } catch (UnacceptableConfiguration e) {
+ System.err.println("Cannot create the instance " + conf.get("name") + " : " + e.getMessage());
+ }
+ }
+ }
+ 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/ComponentFactory.java b/ipojo/src/main/java/org/apache/felix/ipojo/ComponentFactory.java
index 2d66c3d..99d20d7 100644
--- a/ipojo/src/main/java/org/apache/felix/ipojo/ComponentFactory.java
+++ b/ipojo/src/main/java/org/apache/felix/ipojo/ComponentFactory.java
@@ -39,21 +39,22 @@
import org.osgi.service.cm.ManagedServiceFactory;
/**
- * 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.
+ * 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 ComponentFactory implements Factory, ManagedServiceFactory {
/**
- * List of the managed instance managers.
- * The key of this hashmap is the name (i.e. pid) of the created instance
+ * List of the managed instance managers. The key of this hashmap is the
+ * name (i.e. pid) of the created instance
*/
private HashMap m_componentInstances = new HashMap();
-
+
/**
- * Ture if the component is a composition.
+ * Ture if the component is a composition.
*/
private boolean m_isComposite = false;
@@ -71,25 +72,29 @@
* Component Implementation Class Name.
*/
private String m_componentClassName = null;
-
+
/**
- * Composition Name.
+ * Composition Name.
*/
private String m_compositeName = null;
/**
* Classloader to delegate loading.
*/
- private FactoryClassloader m_classLoader = null; //TODO is this classloader really useful ?
+ private FactoryClassloader m_classLoader = null; // TODO is this
+
+ // classloader really
+ // useful ?
/**
- * Component Type provided by this factory. //TODO Should be keep this reference ?
+ * Component Type provided by this factory. //TODO Should be keep this
+ * reference ?
*/
private Element m_componentMetadata;
-
+
/**
- * Factory Name (i.e. Factory PID).
- * Could be the component class name if the factory name is not set.
+ * Factory Name (i.e. Factory PID). Could be the component class name if the
+ * factory name is not set.
*/
private String m_factoryName;
@@ -102,12 +107,12 @@
* Component-Type description exposed by the factory service.
*/
private ComponentDescription m_componentDesc;
-
+
/**
* Logger for the factory (and all component instance).
*/
private Logger m_logger;
-
+
/**
* True when the factory is active (non stopping and non starting).
*/
@@ -116,29 +121,29 @@
/**
* FactoryClassloader.
*/
- private class FactoryClassloader extends ClassLoader {
-
- /**
- * Map of defined classes [Name, Class Object].
- */
- private HashMap m_definedClasses = new HashMap();
+ private class FactoryClassloader extends ClassLoader {
+
+ /**
+ * Map of defined classes [Name, Class Object].
+ */
+ private HashMap m_definedClasses = new HashMap();
/**
* load the class.
+ *
* @see java.lang.ClassLoader#loadClass(java.lang.String, boolean)
* @param name : the name of the class
* @param resolve : should be the class resolve now ?
* @return : the loaded class
* @throws ClassNotFoundException : the class to load is not found
*/
- protected synchronized Class loadClass(final String name,
- final boolean resolve) throws ClassNotFoundException {
+ protected synchronized Class loadClass(final String name, final boolean resolve) throws ClassNotFoundException {
return m_context.getBundle().loadClass(name);
}
-
/**
* Return the URL of the asked ressource.
+ *
* @param arg : the name of the resource to find.
* @return the URL of the resource.
* @see java.lang.ClassLoader#getResource(java.lang.String)
@@ -149,6 +154,7 @@
/**
* .
+ *
* @param arg : resource to find
* @return : the enumeration found
* @throws IOException : if the lookup failed.
@@ -160,39 +166,53 @@
/**
* The defineClass method.
+ *
* @param name : name of the class
* @param b : the byte array of the class
* @param domain : the protection domain
* @return : the defined class.
* @throws Exception : if a problem is detected during the loading
*/
- public Class defineClass(String name, byte[] b,
- ProtectionDomain domain) throws Exception {
- if (m_definedClasses.containsKey(name)) { return (Class) m_definedClasses.get(name); }
+ public Class defineClass(String name, byte[] b, ProtectionDomain domain) throws Exception {
+ if (m_definedClasses.containsKey(name)) {
+ return (Class) m_definedClasses.get(name);
+ }
Class c = super.defineClass(name, b, 0, b.length, domain);
m_definedClasses.put(name, c);
return c;
}
}
-
/**
- * @return the Bundle Context
+ * Return the bundle context.
+ *
+ * @return the Bundle Context.
*/
- protected BundleContext getBundleContext() { return m_context; }
+ protected BundleContext getBundleContext() {
+ return m_context;
+ }
/**
+ * Get the implementation class of the component type.
+ *
* @return the name of the component-type implementation class.
*/
- protected String getComponentClassName() { return m_componentClassName; }
-
+ protected String getComponentClassName() {
+ return m_componentClassName;
+ }
+
/**
+ * Get the logger used by instances of he current factory.
+ *
* @return the factory logger.
*/
- public Logger getLogger() { return m_logger; }
+ public Logger getLogger() {
+ return m_logger;
+ }
/**
* Create a instance manager factory.
+ *
* @param bc : bundle context
* @param cm : metadata of the component to create
*/
@@ -200,57 +220,66 @@
m_context = bc;
m_componentMetadata = cm;
if (cm.getName().equalsIgnoreCase("composite")) {
- m_componentClassName = null;
- m_isComposite = true;
- // Get the name
- if (cm.containsAttribute("name")) {
- m_compositeName = cm.getAttribute("name");
- } else {
- System.err.println("A composite needs a name"); return;
- }
- // Compute factory name
- if (m_componentMetadata.containsAttribute("factory") && !m_componentMetadata.getAttribute("factory").equalsIgnoreCase("no")) {
- m_factoryName = m_componentMetadata.getAttribute("factory");
- } else { m_factoryName = m_compositeName; }
- } else {
- if (cm.containsAttribute("className")) {
- m_componentClassName = cm.getAttribute("className");
- } else {
- System.err.println("A component needs a class name"); return;
- }
- 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_componentClassName = null;
+ m_isComposite = true;
+ // Get the name
+ if (cm.containsAttribute("name")) {
+ m_compositeName = cm.getAttribute("name");
+ } else {
+ System.err.println("A composite needs a name");
+ return;
+ }
+ // Compute factory name
+ if (m_componentMetadata.containsAttribute("factory") && !m_componentMetadata.getAttribute("factory").equalsIgnoreCase("no")) {
+ m_factoryName = m_componentMetadata.getAttribute("factory");
+ } else {
+ m_factoryName = m_compositeName;
+ }
+ } else {
+ if (cm.containsAttribute("className")) {
+ m_componentClassName = cm.getAttribute("className");
+ } else {
+ System.err.println("A component needs a class name");
+ return;
+ }
+ if (m_componentMetadata.containsAttribute("factory") && !m_componentMetadata.getAttribute("factory").equalsIgnoreCase("no")) {
+ m_factoryName = m_componentMetadata.getAttribute("factory");
+ } else {
+ m_factoryName = m_componentMetadata.getAttribute("className");
+ }
}
if (m_factoryName != null) {
- m_logger = new Logger(m_context, m_factoryName, Logger.WARNING);
+ m_logger = new Logger(m_context, m_factoryName, Logger.WARNING);
} else {
- if (m_isComposite) {
- m_logger = new Logger(m_context, m_compositeName, Logger.WARNING);
- } else {
- m_logger = new Logger(m_context, m_componentClassName, Logger.WARNING);
- }
+ if (m_isComposite) {
+ m_logger = new Logger(m_context, m_compositeName, Logger.WARNING);
+ } else {
+ m_logger = new Logger(m_context, m_componentClassName, Logger.WARNING);
+ }
}
}
/**
- * Create a instance manager factory. The class is given in parameter.
- * The component type is not a composite.
+ * Create a instance manager factory. The class is given in parameter. The
+ * component type is not a composite.
+ *
* @param bc : bundle context
* @param clazz : the component class
* @param cm : metadata of the component
*/
public ComponentFactory(BundleContext bc, byte[] clazz, Element cm) {
- m_context = bc;
+ m_context = bc;
m_clazz = clazz;
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"); }
-
+ 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);
}
@@ -258,87 +287,101 @@
* Stop all the instance managers.
*/
public synchronized void stop() {
- m_active = false;
+ m_active = false;
Collection col = m_componentInstances.values();
Iterator it = col.iterator();
while (it.hasNext()) {
ComponentInstance ci = (ComponentInstance) it.next();
if (ci.isStarted()) {
- ci.stop();
+ ci.dispose();
}
}
m_componentInstances.clear();
- if (m_sr != null) { m_sr.unregister(); }
+ if (m_sr != null) {
+ m_sr.unregister();
+ }
m_sr = null;
}
/**
* Start all the instance managers.
*/
- public synchronized void start() {
+ public synchronized void start() {
+ if (m_active) {
+ return;
+ } // Already started
+
Properties props = new Properties();
// create a ghost component
if (!m_isComposite) {
- InstanceManager ghost = new InstanceManager(this, m_context);
- Properties p = new Properties();
- p.put("name", "ghost");
- ghost.configure(m_componentMetadata, p);
- m_componentDesc = ghost.getComponentDescription();
+ InstanceManager ghost = new InstanceManager(this, m_context);
+ Properties p = new Properties();
+ p.put("name", "ghost");
+ ghost.configure(m_componentMetadata, p);
+ m_componentDesc = ghost.getComponentDescription();
} else {
- CompositeManager ghost = new CompositeManager(this, m_context);
- Properties p = new Properties();
- p.put("name", "ghost");
- ghost.configure(m_componentMetadata, p);
- m_componentDesc = ghost.getComponentDescription();
+ CompositeManager ghost = new CompositeManager(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; }
-
- if (!m_isComposite) {
- props.put("component.class", m_componentClassName);
- } else {
- props.put("component.class", "no implementation class");
+ if (m_componentMetadata.containsAttribute("factory") && m_componentMetadata.getAttribute("factory").equalsIgnoreCase("no")) {
+ return;
+ }
+
+ if (!m_isComposite) {
+ props.put("component.class", m_componentClassName);
+ } else {
+ props.put("component.class", "no implementation class");
}
props.put("factory.name", m_factoryName);
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
+
+ // Add Factory PID to the component properties
props.put(Constants.SERVICE_PID, m_factoryName);
// Exposition of the factory service
m_active = true;
- m_sr = m_context.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);
}
-
+
/**
* Callback called by instance when stopped.
+ *
* @param ci : the instance stopping
*/
protected synchronized void stopped(ComponentInstance ci) {
- if (m_active) {
- m_componentInstances.remove(ci.getInstanceName());
- }
+ if (m_active) {
+ m_componentInstances.remove(ci.getInstanceName());
+ }
}
/**
- * @see org.apache.felix.ipojo.Factory#getComponentInfo()
+ * Get the component type description attached to this factory.
+ * @return : the component type description
+ * @see org.apache.felix.ipojo.Factory#getComponentDescription()
*/
- public ComponentDescription getComponentDescription() { return m_componentDesc; }
+ public ComponentDescription getComponentDescription() {
+ return m_componentDesc;
+ }
/**
* Load a class.
+ *
* @param className : name of the class to load
* @return the resulting Class object
* @throws ClassNotFoundException : happen when the class is not found
*/
public Class loadClass(String className) throws ClassNotFoundException {
- 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_clazz != null && className.equals(m_componentClassName)) {
+ // Used the factory classloader to load the component implementation class
if (m_classLoader == null) {
m_classLoader = new FactoryClassloader();
}
@@ -350,9 +393,10 @@
}
return m_context.getBundle().loadClass(className);
}
-
+
/**
* Define a class.
+ *
* @param name : qualified name of the class
* @param b : byte array of the class
* @param domain : protection domain of the class
@@ -360,12 +404,15 @@
* @throws Exception : an exception occur during the definition
*/
public Class defineClass(String name, byte[] b, ProtectionDomain domain) throws Exception {
- if (m_classLoader == null) { m_classLoader = new FactoryClassloader(); }
- return m_classLoader.defineClass(name, b, domain);
+ if (m_classLoader == null) {
+ m_classLoader = new FactoryClassloader();
+ }
+ return m_classLoader.defineClass(name, b, domain);
}
/**
* Return the URL of a resource.
+ *
* @param resName : resource name
* @return the URL of the resource
*/
@@ -374,188 +421,222 @@
}
/**
+ * Create an instance.
+ * The given configuration needs to contain the 'name' property.
+ * @param configuration : configuration of the created instance.
+ * @return the created component instance.
+ * @throws UnacceptableConfiguration : occurs if the given configuration is not consistent with the component type of this factory.
* @see org.apache.felix.ipojo.Factory#createComponentInstance(java.util.Dictionary)
*/
- public ComponentInstance createComponentInstance(Dictionary configuration) throws UnacceptableConfiguration {
- try {
- _isAcceptable(configuration);
- } catch (UnacceptableConfiguration e) {
- m_logger.log(Logger.ERROR, "The configuration is not acceptable : " + e.getMessage());
- throw new UnacceptableConfiguration("The configuration " + configuration + " is not acceptable for " + m_factoryName + ": " + e.getMessage());
- }
-
- IPojoContext context = new IPojoContext(m_context);
- ComponentInstance instance = null;
- if (!m_isComposite) {
- InstanceManager inst = new InstanceManager(this, context);
- //context.setComponentInstance(inst);
- inst.configure(m_componentMetadata, configuration);
- instance = inst;
- } else {
- CompositeManager inst = new CompositeManager(this, context);
- //context.setComponentInstance(inst);
- inst.configure(m_componentMetadata, configuration);
- instance = inst;
+ public ComponentInstance createComponentInstance(Dictionary configuration) throws UnacceptableConfiguration {
+ try {
+ checkAcceptability(configuration);
+ } catch (UnacceptableConfiguration e) {
+ m_logger.log(Logger.ERROR, "The configuration is not acceptable : " + e.getMessage());
+ throw new UnacceptableConfiguration("The configuration " + configuration + " is not acceptable for " + m_factoryName + ": " + e.getMessage());
}
String pid = null;
- if (configuration.get("name") != null) {
- pid = (String) configuration.get("name");
+ if (configuration.get("name") != null) {
+ pid = (String) configuration.get("name");
} else {
- throw new UnacceptableConfiguration("The name attribute is missing");
+ throw new UnacceptableConfiguration("The name attribute is missing");
}
-
+
if (m_componentInstances.containsKey(pid)) {
- throw new UnacceptableConfiguration("Name already used : " + pid);
+ throw new UnacceptableConfiguration("Name already used : " + pid);
}
-
+
+ IPojoContext context = new IPojoContext(m_context);
+ ComponentInstance instance = null;
+ if (!m_isComposite) {
+ InstanceManager inst = new InstanceManager(this, context);
+ // context.setComponentInstance(inst);
+ inst.configure(m_componentMetadata, configuration);
+ instance = inst;
+ } else {
+ CompositeManager inst = new CompositeManager(this, context);
+ // context.setComponentInstance(inst);
+ inst.configure(m_componentMetadata, configuration);
+ instance = inst;
+ }
+
m_componentInstances.put(pid, instance);
instance.start();
return instance;
}
-
+
/**
+ * Create an instance.
+ * The given configuration needs to contain the 'name' property.
+ * @param configuration : configuration of the created instance.
+ * @param serviceContext : the service context to push for this instance.
+ * @return the created component instance.
+ * @throws UnacceptableConfiguration : occurs if the given configuration is not consistent with the component type of this factory.
* @see org.apache.felix.ipojo.Factory#createComponentInstance(java.util.Dictionary)
*/
public ComponentInstance createComponentInstance(Dictionary configuration, ServiceContext serviceContext) throws UnacceptableConfiguration {
- try {
- _isAcceptable(configuration);
- } catch (UnacceptableConfiguration e) {
- m_logger.log(Logger.ERROR, "The configuration is not acceptable : " + e.getMessage());
- throw new UnacceptableConfiguration("The configuration " + configuration + " is not acceptable for " + m_factoryName + ": " + e.getMessage());
- }
-
- IPojoContext context = new IPojoContext(m_context, serviceContext);
- ComponentInstance instance = null;
- if (!m_isComposite) {
- InstanceManager inst = new InstanceManager(this, context);
- //context.setComponentInstance(inst);
- inst.configure(m_componentMetadata, configuration);
- instance = inst;
- } else {
- CompositeManager inst = new CompositeManager(this, context);
- //context.setComponentInstance(inst);
- inst.configure(m_componentMetadata, configuration);
- instance = inst;
+ try {
+ checkAcceptability(configuration);
+ } catch (UnacceptableConfiguration e) {
+ m_logger.log(Logger.ERROR, "The configuration is not acceptable : " + e.getMessage());
+ throw new UnacceptableConfiguration("The configuration " + configuration + " is not acceptable for " + m_factoryName + ": " + e.getMessage());
}
- String pid = null;
- if (configuration.get("name") != null) {
- pid = (String) configuration.get("name");
+ String pid = null;
+ if (configuration.get("name") != null) {
+ pid = (String) configuration.get("name");
} else {
- throw new UnacceptableConfiguration("The name attribute is missing");
+ throw new UnacceptableConfiguration("The name attribute is missing");
}
-
+
if (m_componentInstances.containsKey(pid)) {
- throw new UnacceptableConfiguration("Name already used : " + pid);
+ throw new UnacceptableConfiguration("Name already used : " + pid);
+ }
+
+ IPojoContext context = new IPojoContext(m_context, serviceContext);
+ ComponentInstance instance = null;
+ if (!m_isComposite) {
+ InstanceManager inst = new InstanceManager(this, context);
+ // context.setComponentInstance(inst);
+ inst.configure(m_componentMetadata, configuration);
+ instance = inst;
+ } else {
+ CompositeManager inst = new CompositeManager(this, context);
+ // context.setComponentInstance(inst);
+ inst.configure(m_componentMetadata, configuration);
+ instance = inst;
}
m_componentInstances.put(pid, instance);
instance.start();
return instance;
}
-
-
/**
+ * Delete an instance.
+ * @param pid : name of the instance to delete
* @see org.osgi.service.cm.ManagedServiceFactory#deleted(java.lang.String)
*/
public void deleted(String pid) {
InstanceManager cm = (InstanceManager) m_componentInstances.remove(pid);
- if (cm == null) {
- return; // do nothing, the component does not exist !
- } else { cm.stop(); }
+ if (cm == null) {
+ return; // do nothing, the component does not exist !
+ } else {
+ cm.dispose();
+ }
}
/**
- * @see org.osgi.service.cm.ManagedServiceFactory#getName()
+ * Get the name of this factory.
+ * @return the name of this factory
+ * @see org.apache.felix.ipojo.Factory#getName()
*/
- public String getName() { return getFactoryName(); }
+ public String getName() {
+ return m_factoryName;
+ }
/**
+ * Create of update an instance.
+ * @param pid : name of the instance
+ * @param properties : configuration of the instance
+ * @throws ConfigurationException : if the configuration is not consistent for this component type
* @see org.osgi.service.cm.ManagedServiceFactory#updated(java.lang.String, java.util.Dictionary)
*/
public void updated(String pid, Dictionary properties) throws ConfigurationException {
InstanceManager cm = (InstanceManager) m_componentInstances.get(pid);
if (cm == null) {
- try {
- properties.put("name", pid); // Add the name in the configuration
- createComponentInstance(properties);
- } catch (UnacceptableConfiguration e) {
- m_logger.log(Logger.ERROR, "The configuration is not acceptable : " + e.getMessage());
- throw new ConfigurationException(properties.toString(), e.getMessage());
- }
- } else {
try {
- properties.put("name", pid); // Add the name in the configuration
- _isAcceptable(properties); // Test if the configuration is acceptable
- } catch (UnacceptableConfiguration e) {
- m_logger.log(Logger.ERROR, "The configuration is not acceptable : " + e.getMessage());
- throw new ConfigurationException(properties.toString(), e.getMessage());
- }
+ properties.put("name", pid); // Add the name in the
+ // configuration
+ createComponentInstance(properties);
+ } catch (UnacceptableConfiguration e) {
+ m_logger.log(Logger.ERROR, "The configuration is not acceptable : " + e.getMessage());
+ throw new ConfigurationException(properties.toString(), e.getMessage());
+ }
+ } else {
+ try {
+ properties.put("name", pid); // Add the name in the
+ // configuration
+ checkAcceptability(properties); // Test if the configuration is
+ // acceptable
+ } catch (UnacceptableConfiguration e) {
+ m_logger.log(Logger.ERROR, "The configuration is not acceptable : " + e.getMessage());
+ throw new ConfigurationException(properties.toString(), e.getMessage());
+ }
cm.reconfigure(properties); // re-configure the component
}
}
-
+
/**
- * @return the factory name
- */
- public String getFactoryName() { return m_factoryName; }
-
- /**
- * 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.
+ * 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 seems to be acceptable
*/
public boolean isAcceptable(Dictionary conf) {
- // First check that the configuration contains a name :
- if (conf.get("name") == null) { return false; }
- 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 (pd.getValue() == null && conf.get(pd.getName()) == null) {
- return false;
- }
- }
- return true;
+ // First check that the configuration contains a name :
+ if (conf.get("name") == null) {
+ return false;
+ }
+ 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 (pd.getValue() == null && conf.get(pd.getName()) == null) {
+ return false;
+ }
+ }
+ return true;
}
-
+
/**
* Test is a configuration is acceptable for the factory.
+ *
* @param conf : the configuration to test.
* @throws UnacceptableConfiguration : the configuration is not acceptable.
*/
- private void _isAcceptable(Dictionary conf) throws UnacceptableConfiguration {
- if (conf == null || conf.get("name") == null) { throw new UnacceptableConfiguration("The configuration does not contains the \"name\" property"); }
- 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 (pd.getValue() == null && conf.get(pd.getName()) == null) {
- throw new UnacceptableConfiguration("The configuration does not contains the \"" + pd.getName() + "\" property");
- }
- }
+ private void checkAcceptability(Dictionary conf) throws UnacceptableConfiguration {
+ if (conf == null || conf.get("name") == null) {
+ throw new UnacceptableConfiguration("The configuration does not contains the \"name\" property");
+ }
+ 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 (pd.getValue() == null && conf.get(pd.getName()) == null) {
+ throw new UnacceptableConfiguration("The configuration does not contains the \"" + pd.getName() + "\" property");
+ }
+ }
}
- /**
- * @see org.apache.felix.ipojo.Factory#reconfigure(java.util.Dictionary)
- */
- public void reconfigure(Dictionary properties) throws UnacceptableConfiguration {
- if (properties == null || properties.get("name") == null) { throw new UnacceptableConfiguration("The configuration does not contains the \"name\" property"); }
- String name = (String) properties.get("name");
- ComponentInstance cm = null;
- if (m_isComposite) {
- cm = (CompositeManager) m_componentInstances.get(name);
- } else {
- cm = (InstanceManager) m_componentInstances.get(name);
- }
- if (cm == null) {
- return; // The instance does not exist.
+ /**
+ * Reconfigure an existing instance.
+ * @param properties : the new configuration to push.
+ * @throws UnacceptableConfiguration : occurs if the new configuration is not consistent with the component type.
+ * @see org.apache.felix.ipojo.Factory#reconfigure(java.util.Dictionary)
+ */
+ public void reconfigure(Dictionary properties) throws UnacceptableConfiguration {
+ if (properties == null || properties.get("name") == null) {
+ throw new UnacceptableConfiguration("The configuration does not contains the \"name\" property");
+ }
+ String name = (String) properties.get("name");
+ ComponentInstance cm = null;
+ if (m_isComposite) {
+ cm = (CompositeManager) m_componentInstances.get(name);
} else {
- _isAcceptable(properties); // Test if the configuration is acceptable
- }
+ cm = (InstanceManager) m_componentInstances.get(name);
+ }
+ if (cm == null) {
+ return; // The instance does not exist.
+ } else {
+ checkAcceptability(properties); // Test if the configuration is
+ // acceptable
+ }
cm.reconfigure(properties); // re-configure the component
- }
+ }
}
diff --git a/ipojo/src/main/java/org/apache/felix/ipojo/ComponentInstance.java b/ipojo/src/main/java/org/apache/felix/ipojo/ComponentInstance.java
index 9578dda..3dd5abe 100644
--- a/ipojo/src/main/java/org/apache/felix/ipojo/ComponentInstance.java
+++ b/ipojo/src/main/java/org/apache/felix/ipojo/ComponentInstance.java
@@ -26,25 +26,26 @@
/**
* 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 ComponentInstance {
/**
- * Component Instance State : STOPPED.
- * The component instance is not started.
+ * Component Instance State : STOPPED. The component instance is not
+ * started.
*/
int STOPPED = 0;
-
- /**
- * Component Instance State : INVALID.
- * The component is invalid when it start or when a component dependency is unvalid.
+
+ /**
+ * Component Instance State : INVALID. The component is invalid when it
+ * start or when a component dependency is unvalid.
*/
int INVALID = 1;
/**
- * Component Instance State : VALID.
- * The component is resolved when it is running and all its component dependencies are valid.
+ * Component Instance State : VALID. The component is resolved when it is
+ * running and all its component dependencies are valid.
*/
int VALID = 2;
@@ -55,51 +56,65 @@
/**
* Stop the component instance.
+ * A stopped instance can be re-started.
*/
void stop();
+
+ /**
+ * Dispose the component instance.
+ * A disposed instance cannot be re-started.
+ */
+ void dispose();
/**
+ * Return the actual state of the instance.
* @return the actual state of the component instance.
*/
int getState();
/**
- * @return the component type information.
- * Each handler can participate to the component description.
+ * Return component-type description of this instance.
+ * @return the component type information. Each handler can participate to
+ * the component description.
*/
ComponentDescription getComponentDescription();
-
+
/**
+ * Return the instance description.
* @return the instance description of the current instance
*/
InstanceDescription getInstanceDescription();
/**
+ * Return the factory which create this instance.
* @return the factory of the component instance.
*/
ComponentFactory getFactory();
-
+
/**
+ * Return the bundle context of this instance.
* @return the context of the component instance
*/
BundleContext getContext();
-
+
/**
+ * Return the name of the instance.
* @return the name of the component instance
*/
String getInstanceName();
-
+
/**
+ * Check if the instance is started.
* @return true if getState returns INVALID or VALID.
*/
boolean isStarted();
-
+
/**
- * Re-configurare an instance.
- * Do nothing if the instance does not support dynamic reconfiguration.
- * The reconfiguration does not stop the instance.
+ * Re-configurare an instance. Do nothing if the instance does not support
+ * dynamic reconfiguration. The reconfiguration does not stop the instance.
+ *
* @param configuration : the new configuration.
*/
void reconfigure(Dictionary configuration);
-
+
}
diff --git a/ipojo/src/main/java/org/apache/felix/ipojo/CompositeHandler.java b/ipojo/src/main/java/org/apache/felix/ipojo/CompositeHandler.java
index 8dab9a6..ea675c6 100644
--- a/ipojo/src/main/java/org/apache/felix/ipojo/CompositeHandler.java
+++ b/ipojo/src/main/java/org/apache/felix/ipojo/CompositeHandler.java
@@ -24,14 +24,16 @@
import org.apache.felix.ipojo.metadata.Element;
/**
- * Composite Handler Abstract Class.
- * An composite handler need implements these method to be notifed of lifecycle change...
+ * Composite Handler Abstract Class. An composite handler need implements these
+ * method to be notifed of lifecycle change...
+ *
* @author <a href="mailto:felix-dev@incubator.apache.org">Felix Project Team</a>
*/
public abstract class CompositeHandler {
-
- /**
+
+ /**
* Configure the handler.
+ *
* @param im : the instance manager
* @param metadata : the metadata of the component
* @param configuration : the instance configuration
@@ -50,25 +52,35 @@
/**
* Is the actual state valid for this handler ?
+ *
* @return true is the state seems valid for the handler
*/
- public boolean isValid() { return true; }
+ public boolean isValid() {
+ return true;
+ }
/**
* This method is called when the component state changed.
+ *
* @param state : the new state
*/
- public void stateChanged(int state) { }
+ public void stateChanged(int state) {
+ }
/**
- * @return the description of the handler..
+ * Return the description of the handler.
+ * @return the description of the handler.
*/
- public HandlerDescription getDescription() { return new HandlerDescription(this.getClass().getName(), isValid()); }
+ public HandlerDescription getDescription() {
+ return new HandlerDescription(this.getClass().getName(), isValid());
+ }
- /**
- * The instance is reconfiguring.
- * @param configuration : New instance configuration.
- */
- public void reconfigure(Dictionary configuration) { }
+ /**
+ * The instance is reconfiguring.
+ *
+ * @param configuration : New instance configuration.
+ */
+ public void reconfigure(Dictionary configuration) {
+ }
}
diff --git a/ipojo/src/main/java/org/apache/felix/ipojo/CompositeManager.java b/ipojo/src/main/java/org/apache/felix/ipojo/CompositeManager.java
index d17f45d..19b461a 100644
--- a/ipojo/src/main/java/org/apache/felix/ipojo/CompositeManager.java
+++ b/ipojo/src/main/java/org/apache/felix/ipojo/CompositeManager.java
@@ -31,18 +31,19 @@
import org.osgi.framework.ServiceReference;
/**
- * iPOJO Composite manager.
- * The composite manager class manages one instance of a component type which is a composition.
- * It manages component lifecycle, and handlers...
+ * iPOJO Composite manager. The composite manager class manages one instance of
+ * a component type which is a composition. It manages component lifecycle, and
+ * handlers...
+ *
* @author <a href="mailto:felix-dev@incubator.apache.org">Felix Project Team</a>
*/
public class CompositeManager implements ComponentInstance {
-
- /**
+
+ /**
* Parent factory (ComponentFactory).
*/
private ComponentFactory m_factory;
-
+
/**
* Name of the component instance.
*/
@@ -67,16 +68,16 @@
* Component type information.
*/
private ComponentDescription m_componentDesc;
-
+
/**
* Internal service context of the composition.
*/
private CompositeServiceContext m_internalContext;
-
// Constructor
/**
* Construct a new Component Manager.
+ *
* @param factory : the factory managing the instance manager
* @param bc : the bundle context to give to the instance
*/
@@ -89,21 +90,24 @@
}
/**
- * Configure the instance manager.
- * Stop the existings handler, clear the handler list, change the metadata, recreate the handlers
+ * Configure the instance manager. Stop the existings handler, clear the
+ * handler list, change the metadata, recreate the handler
+ *
* @param cm : the component type metadata
* @param configuration : the configuration of the instance
*/
public void configure(Element cm, Dictionary configuration) {
// Stop all previous registred handler
- if (m_handlers.length != 0) { stop(); }
+ if (m_handlers.length != 0) {
+ stop();
+ }
// Clear the handler list
m_handlers = new CompositeHandler[0];
// ComponentInfo initialization
m_componentDesc = new ComponentDescription(m_factory.getName());
-
+
// Add the name
m_name = (String) configuration.get("name");
@@ -111,12 +115,14 @@
for (int i = 0; i < IPojoConfiguration.INTERNAL_COMPOSITE_HANDLERS.length; i++) {
// Create a new instance
try {
- CompositeHandler h = (CompositeHandler) IPojoConfiguration.INTERNAL_COMPOSITE_HANDLERS[i].newInstance();
+ CompositeHandler h = (CompositeHandler) IPojoConfiguration.INTERNAL_COMPOSITE_HANDLERS[i].newInstance();
h.configure(this, cm, configuration);
} catch (InstantiationException e) {
- m_factory.getLogger().log(Logger.ERROR, "[" + m_name + "] Cannot instantiate the handler " + IPojoConfiguration.INTERNAL_HANDLERS[i] + " : " + e.getMessage());
+ m_factory.getLogger().log(Logger.ERROR,
+ "[" + m_name + "] Cannot instantiate the handler " + IPojoConfiguration.INTERNAL_HANDLERS[i] + " : " + e.getMessage());
} catch (IllegalAccessException e) {
- m_factory.getLogger().log(Logger.ERROR, "[" + m_name + "] Cannot instantiate the handler " + IPojoConfiguration.INTERNAL_HANDLERS[i] + " : " + e.getMessage());
+ m_factory.getLogger().log(Logger.ERROR,
+ "[" + m_name + "] Cannot instantiate the handler " + IPojoConfiguration.INTERNAL_HANDLERS[i] + " : " + e.getMessage());
}
}
@@ -129,62 +135,77 @@
CompositeHandler h = (CompositeHandler) c.newInstance();
h.configure(this, cm, configuration);
} catch (ClassNotFoundException e) {
- m_factory.getLogger().log(Logger.ERROR, "[" + m_name + "] Cannot instantiate the handler " + cm.getNamespaces()[i] + " : " + e.getMessage());
+ m_factory.getLogger()
+ .log(Logger.ERROR, "[" + m_name + "] Cannot instantiate the handler " + cm.getNamespaces()[i] + " : " + e.getMessage());
} catch (InstantiationException e) {
- m_factory.getLogger().log(Logger.ERROR, "[" + m_name + "] Cannot instantiate the handler " + cm.getNamespaces()[i] + " : " + e.getMessage());
+ m_factory.getLogger()
+ .log(Logger.ERROR, "[" + m_name + "] Cannot instantiate the handler " + cm.getNamespaces()[i] + " : " + e.getMessage());
} catch (IllegalAccessException e) {
- m_factory.getLogger().log(Logger.ERROR, "[" + m_name + "] Cannot instantiate the handler " + cm.getNamespaces()[i] + " : " + e.getMessage());
+ m_factory.getLogger()
+ .log(Logger.ERROR, "[" + m_name + "] Cannot instantiate the handler " + cm.getNamespaces()[i] + " : " + e.getMessage());
}
}
}
}
/**
+ * Return the component type description of this instance.
* @return the component type information.
+ * @see org.apache.felix.ipojo.ComponentInstance#getComponentDescription()
*/
- public ComponentDescription getComponentDescription() { return m_componentDesc; }
-
+ public ComponentDescription getComponentDescription() {
+ return m_componentDesc;
+ }
+
/**
+ * Return the instance description of this instance.
* @return the instance description.
+ * @see org.apache.felix.ipojo.ComponentInstance#getInstanceDescription()
*/
public synchronized InstanceDescription getInstanceDescription() {
- int componentState = getState();
+ int componentState = getState();
InstanceDescription instanceDescription = new InstanceDescription(m_name, componentState, getContext().getBundle().getBundleId(), m_componentDesc);
CompositeHandler[] handlers = getRegistredCompositeHandlers();
for (int i = 0; i < handlers.length; i++) {
- instanceDescription.addHandler(handlers[i].getDescription());
+ instanceDescription.addHandler(handlers[i].getDescription());
}
-
+
// Get instances description of internal instance
ServiceReference[] refs;
- try {
- refs = m_internalContext.getServiceReferences(Architecture.class.getName(), null);
- if (refs != null) {
- for (int i = 0; i < refs.length; i++) {
- Architecture arch = (Architecture) m_internalContext.getService(refs[i]);
- instanceDescription.addInstance(arch.getInstanceDescription());
- m_internalContext.ungetService(refs[i]);
- }
- }
- } catch (InvalidSyntaxException e) {
- e.printStackTrace(); // Should not happen
- }
+ try {
+ refs = m_internalContext.getServiceReferences(Architecture.class.getName(), null);
+ if (refs != null) {
+ for (int i = 0; i < refs.length; i++) {
+ Architecture arch = (Architecture) m_internalContext.getService(refs[i]);
+ instanceDescription.addInstance(arch.getInstanceDescription());
+ m_internalContext.ungetService(refs[i]);
+ }
+ }
+ } catch (InvalidSyntaxException e) {
+ e.printStackTrace(); // Should not happen
+ }
return instanceDescription;
}
/**
+ * REturn the list of handlers plugged on this instace.
* @return the list of the registred handlers.
*/
- public CompositeHandler[] getRegistredCompositeHandlers() { return m_handlers; }
+ public CompositeHandler[] getRegistredCompositeHandlers() {
+ return m_handlers;
+ }
/**
* Return a specified handler.
+ *
* @param name : class name of the handler to find
* @return : the handler, or null if not found
*/
public CompositeHandler getCompositeHandler(String name) {
for (int i = 0; i < m_handlers.length; i++) {
- if (m_handlers[i].getClass().getName().equalsIgnoreCase(name)) { return m_handlers[i]; }
+ if (m_handlers[i].getClass().getName().equalsIgnoreCase(name)) {
+ return m_handlers[i];
+ }
}
return null;
}
@@ -195,14 +216,16 @@
* Start the instance manager.
*/
public void start() {
- if (m_state != STOPPED) { return; } // Instance already started
-
+ if (m_state != STOPPED) {
+ return;
+ } // Instance already started
+
// Start all the handlers
m_factory.getLogger().log(Logger.INFO, "[" + m_name + "] Start the instance manager with " + m_handlers.length + " handlers");
// The new state of the component is UNRESOLVED
m_state = INVALID;
-
+
m_internalContext.start(); // Turn on the factory tracking
for (int i = 0; i < m_handlers.length; i++) {
@@ -217,29 +240,54 @@
* Stop the instance manager.
*/
public void stop() {
- if (m_state == STOPPED) { return; } // Instance already stopped
-
+ if (m_state == STOPPED) {
+ return;
+ } // Instance already stopped
+
setState(INVALID);
// Stop all the handlers
for (int i = m_handlers.length - 1; i > -1; i--) {
m_handlers[i].stop();
}
-
+
m_internalContext.stop(); // Turn off the factory tracking
m_state = STOPPED;
+ }
+
+ /**
+ * Dispose the instance.
+ * @see org.apache.felix.ipojo.ComponentInstance#dispose()
+ */
+ public void dispose() {
+ if (m_state != STOPPED) {
+ stop();
+ }
+
m_factory.stopped(this);
+
+ // Cleaning
+ m_factory = null;
+ m_name = null;
+ m_context = null;
+ m_handlers = null;
+ m_componentDesc = null;
}
/**
- * Set the state of the component.
- * if the state changed call the stateChanged(int) method on the handlers
+ * Set the state of the component.
+ * Ff the state changed call the stateChanged(int) method on the handlers.
+ * @param state : new state
*/
public void setState(int state) {
if (m_state != state) {
// Log the state change
- if (state == INVALID) { m_factory.getLogger().log(Logger.INFO, "[" + m_name + "] State -> INVALID"); }
- if (state == VALID) { m_factory.getLogger().log(Logger.INFO, "[" + m_name + "] State -> VALID"); }
+ if (state == INVALID) {
+ m_factory.getLogger().log(Logger.INFO, "[" + m_name + "] State -> INVALID");
+ }
+ if (state == VALID) {
+ m_factory.getLogger().log(Logger.INFO, "[" + m_name + "] State -> VALID");
+ }
// The state changed call the handler stateChange method
m_state = state;
@@ -250,28 +298,41 @@
}
/**
- * @return the actual state of the component.
+ * Get the actual state of the instance.
+ * @return the actual state of the instance
+ * @see org.apache.felix.ipojo.ComponentInstance#getState()
*/
- public int getState() { return m_state; }
-
+ public int getState() {
+ return m_state;
+ }
+
/**
+ * Check if the instance is started.
+ * @return true if the instance is started.
* @see org.apache.felix.ipojo.ComponentInstance#isStarted()
*/
- public boolean isStarted() { return m_state != STOPPED; }
+ public boolean isStarted() {
+ return m_state != STOPPED;
+ }
// ===================== end Lifecycle management =====================
// ================== Class & Instance management ===================
/**
+ * Get the factory which create this instance.
* @return the factory of the component
+ * @see org.apache.felix.ipojo.ComponentInstance#getFactory()
*/
- public ComponentFactory getFactory() { return m_factory; }
+ public ComponentFactory getFactory() {
+ return m_factory;
+ }
- // ======================== Handlers Management ======================
+ // ======================== Handlers Management ======================
/**
* Register the given handler to the current instance manager.
+ *
* @param h : the handler to register
*/
public void register(CompositeHandler h) {
@@ -282,7 +343,7 @@
}
if (m_handlers != null) {
- CompositeHandler[] newList = new CompositeHandler[m_handlers.length + 1];
+ CompositeHandler[] newList = new CompositeHandler[m_handlers.length + 1];
System.arraycopy(m_handlers, 0, newList, 0, m_handlers.length);
newList[m_handlers.length] = h;
m_handlers = newList;
@@ -291,6 +352,7 @@
/**
* Unregister the given handler.
+ *
* @param h : the handler to unregiter
*/
public void unregister(CompositeHandler h) {
@@ -306,22 +368,24 @@
if ((m_handlers.length - 1) == 0) {
m_handlers = new CompositeHandler[0];
} else {
- CompositeHandler[] newList = new CompositeHandler[m_handlers.length - 1];
+ CompositeHandler[] newList = new CompositeHandler[m_handlers.length - 1];
System.arraycopy(m_handlers, 0, newList, 0, idx);
- if (idx < newList.length) {
- System.arraycopy(
- m_handlers, idx + 1, newList, idx, newList.length - idx);
+ if (idx < newList.length) {
+ System.arraycopy(m_handlers, idx + 1, newList, idx, newList.length - idx);
}
m_handlers = newList;
}
}
}
-
/**
+ * Get the bundle context used by this instance.
* @return the parent context of the instance.
+ * @see org.apache.felix.ipojo.ComponentInstance#getContext()
*/
- public BundleContext getContext() { return m_context; }
+ public BundleContext getContext() {
+ return m_context;
+ }
/**
* Check the state of all handlers.
@@ -340,25 +404,36 @@
setState(INVALID);
return;
}
- if (isValid && m_state == INVALID) { setState(VALID); }
+ if (isValid && m_state == INVALID) {
+ setState(VALID);
+ }
}
- /**
- * @see org.apache.felix.ipojo.ComponentInstance#getInstanceName()
- */
- public String getInstanceName() { return m_name; }
+ /**
+ * Get the instance name.
+ * @return the instance name
+ * @see org.apache.felix.ipojo.ComponentInstance#getInstanceName()
+ */
+ public String getInstanceName() {
+ return m_name;
+ }
- /**
- * @see org.apache.felix.ipojo.ComponentInstance#reconfigure(java.util.Dictionary)
- */
- public void reconfigure(Dictionary configuration) {
- for (int i = 0; i < m_handlers.length; i++) {
- m_handlers[i].reconfigure(configuration);
- }
- }
-
- /**
- * @return the internal service context.
- */
- public ServiceContext getServiceContext() { return m_internalContext; }
+ /**
+ * Reconfigure the current instance.
+ * @param configuration : the new instance ocnfiguration.
+ * @see org.apache.felix.ipojo.ComponentInstance#reconfigure(java.util.Dictionary)
+ */
+ public void reconfigure(Dictionary configuration) {
+ for (int i = 0; i < m_handlers.length; i++) {
+ m_handlers[i].reconfigure(configuration);
+ }
+ }
+
+ /**
+ * Get the internal service context of this instance.
+ * @return the internal service context.
+ */
+ public ServiceContext getServiceContext() {
+ return m_internalContext;
+ }
}
diff --git a/ipojo/src/main/java/org/apache/felix/ipojo/DefaultServiceContext.java b/ipojo/src/main/java/org/apache/felix/ipojo/DefaultServiceContext.java
index 114c500..06f2694 100644
--- a/ipojo/src/main/java/org/apache/felix/ipojo/DefaultServiceContext.java
+++ b/ipojo/src/main/java/org/apache/felix/ipojo/DefaultServiceContext.java
@@ -27,116 +27,134 @@
import org.osgi.framework.ServiceRegistration;
/**
- * Default iPOJO Service Context.
- * this service context delegate all calls on the bundle context.
+ * Default iPOJO Service Context. this service context delegate all calls on the
+ * bundle context.
+ *
* @author <a href="mailto:felix-dev@incubator.apache.org">Felix Project Team</a>
*/
-/**
- * @author Clement
- *
- */
public class DefaultServiceContext implements ServiceContext {
-
- /**
- * The bundle context on which delegate.
- */
- private BundleContext m_context;
-
- /**
- * Instance attached to this service context.
- */
- private ComponentInstance m_instance;
-
- /**
- * Constructor.
- * @param bc : the bundle context on which delegate.
- */
- public DefaultServiceContext(BundleContext bc) { m_context = bc; }
- /**
- * @see org.apache.felix.ipojo.ServiceContext#addServiceListener(org.osgi.framework.ServiceListener, java.lang.String)
- */
- public void addServiceListener(ServiceListener listener, String filter) throws InvalidSyntaxException {
- m_context.addServiceListener(listener, filter);
- }
-
- /**
- * @see org.apache.felix.ipojo.ServiceContext#addServiceListener(org.osgi.framework.ServiceListener)
- */
- public void addServiceListener(ServiceListener listener) {
- m_context.addServiceListener(listener);
- }
+ /**
+ * The bundle context on which delegate.
+ */
+ private BundleContext m_context;
- /**
- * @see org.apache.felix.ipojo.ServiceContext#getAllServiceReferences(java.lang.String, java.lang.String)
- */
- public ServiceReference[] getAllServiceReferences(String clazz,
- String filter) throws InvalidSyntaxException {
- return m_context.getAllServiceReferences(clazz, filter);
- }
+ /**
+ * Constructor.
+ *
+ * @param bc : the bundle context on which delegate.
+ */
+ public DefaultServiceContext(BundleContext bc) {
+ m_context = bc;
+ }
- /**
- * @see org.apache.felix.ipojo.ServiceContext#getService(org.osgi.framework.ServiceReference)
- */
- public Object getService(ServiceReference reference) {
- return m_context.getService(reference);
- }
+ /**
+ * Add a service listener.
+ * @param listener : the service lsitener to add.
+ * @param filter : the LDAP filter
+ * @throws InvalidSyntaxException : occurs when the LDAP filter is malformed
+ * @see org.apache.felix.ipojo.ServiceContext#addServiceListener(org.osgi.framework.ServiceListener, java.lang.String)
+ */
+ public void addServiceListener(ServiceListener listener, String filter) throws InvalidSyntaxException {
+ m_context.addServiceListener(listener, filter);
+ }
- /**
- * @see org.apache.felix.ipojo.ServiceContext#getServiceReference(java.lang.String)
- */
- public ServiceReference getServiceReference(String clazz) {
- return m_context.getServiceReference(clazz);
- }
+ /**
+ * Add a service listener.
+ * @param listener : the service listener to add.
+ * @see org.apache.felix.ipojo.ServiceContext#addServiceListener(org.osgi.framework.ServiceListener)
+ */
+ public void addServiceListener(ServiceListener listener) {
+ m_context.addServiceListener(listener);
+ }
- /**
- * @see org.apache.felix.ipojo.ServiceContext#getServiceReferences(java.lang.String, java.lang.String)
- */
- public ServiceReference[] getServiceReferences(String clazz, String filter) throws InvalidSyntaxException {
- return m_context.getServiceReferences(clazz, filter);
- }
+ /**
+ * Get the service references matching with the given query.
+ * @param clazz : Required interface
+ * @param filter : LDAP filter
+ * @return the array of available service reference
+ * @throws InvalidSyntaxException : occurs if the LDAP filter is malformed
+ * @see org.apache.felix.ipojo.ServiceContext#getAllServiceReferences(java.lang.String, java.lang.String)
+ */
+ public ServiceReference[] getAllServiceReferences(String clazz, String filter) throws InvalidSyntaxException {
+ return m_context.getAllServiceReferences(clazz, filter);
+ }
- /**
- * @see org.apache.felix.ipojo.ServiceContext#registerService(java.lang.String[], java.lang.Object, java.util.Dictionary)
- */
- public ServiceRegistration registerService(String[] clazzes,
- Object service, Dictionary properties) {
- return m_context.registerService(clazzes, service, properties);
- }
+ /**
+ * Get a service object.
+ * @param reference : the required service reference
+ * @return the service object or null if the service reference is no more valid or if the service object is not accessible
+ * @see org.apache.felix.ipojo.ServiceContext#getService(org.osgi.framework.ServiceReference)
+ */
+ public Object getService(ServiceReference reference) {
+ return m_context.getService(reference);
+ }
- /**
- * @see org.apache.felix.ipojo.ServiceContext#registerService(java.lang.String, java.lang.Object, java.util.Dictionary)
- */
- public ServiceRegistration registerService(String clazz, Object service,
- Dictionary properties) {
- return m_context.registerService(clazz, service, properties);
- }
+ /**
+ * Get a service reference for the given interface.
+ * @param clazz : the required interface name
+ * @return a service reference on a available provider or null if no provider available
+ * @see org.apache.felix.ipojo.ServiceContext#getServiceReference(java.lang.String)
+ */
+ public ServiceReference getServiceReference(String clazz) {
+ return m_context.getServiceReference(clazz);
+ }
- /**
- * @see org.apache.felix.ipojo.ServiceContext#removeServiceListener(org.osgi.framework.ServiceListener)
- */
- public void removeServiceListener(ServiceListener listener) {
- m_context.removeServiceListener(listener);
+ /**
+ * Get service reference list for the given query.
+ * @param clazz : the name of the requried service interface
+ * @param filter : LDAP filter to apply on service provider
+ * @return : the array of consistent service reference or null if no available provider
+ * @throws InvalidSyntaxException : occrus if the LDAP filter is malformed
+ * @see org.apache.felix.ipojo.ServiceContext#getServiceReferences(java.lang.String, java.lang.String)
+ */
+ public ServiceReference[] getServiceReferences(String clazz, String filter) throws InvalidSyntaxException {
+ return m_context.getServiceReferences(clazz, filter);
+ }
- }
+ /**
+ * Register a service.
+ * @param clazzes : interfaces provided by the service.
+ * @param service : the service object.
+ * @param properties : service properties.
+ * @return the service registration for this service publication.
+ * @see org.apache.felix.ipojo.ServiceContext#registerService(java.lang.String[], java.lang.Object, java.util.Dictionary)
+ */
+ public ServiceRegistration registerService(String[] clazzes, Object service, Dictionary properties) {
+ return m_context.registerService(clazzes, service, properties);
+ }
- /**
- * @see org.apache.felix.ipojo.ServiceContext#ungetService(org.osgi.framework.ServiceReference)
- */
- public boolean ungetService(ServiceReference reference) {
- return m_context.ungetService(reference);
- }
+ /**
+ * Register a service.
+ * @param clazz : interface provided by the service.
+ * @param service : the service object.
+ * @param properties : service properties.
+ * @return the service registration for this service publication.
+ * @see org.apache.felix.ipojo.ServiceContext#registerService(java.lang.String, java.lang.Object, java.util.Dictionary)
+ */
+ public ServiceRegistration registerService(String clazz, Object service, Dictionary properties) {
+ return m_context.registerService(clazz, service, properties);
+ }
- /**
- * @see org.apache.felix.ipojo.ServiceContext#getComponentInstance()
- */
- public ComponentInstance getComponentInstance() {
- return m_instance;
- }
-
- /**
- * @see org.apache.felix.ipojo.ServiceContext#setComponentInstance(org.apache.felix.ipojo.ComponentInstance)
- */
- public void setComponentInstance(ComponentInstance ci) { m_instance = ci; }
+
+ /**
+ * Remove a service listener.
+ * @param listener : the service listner to remove
+ * @see org.apache.felix.ipojo.ServiceContext#removeServiceListener(org.osgi.framework.ServiceListener)
+ */
+ public void removeServiceListener(ServiceListener listener) {
+ m_context.removeServiceListener(listener);
+
+ }
+
+ /**
+ * Unget the service reference.
+ * @param reference : the reference to unget
+ * @return true if you are the last user of the reference
+ * @see org.apache.felix.ipojo.ServiceContext#ungetService(org.osgi.framework.ServiceReference)
+ */
+ public boolean ungetService(ServiceReference reference) {
+ return m_context.ungetService(reference);
+ }
}
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 141a608..9715747 100644
--- a/ipojo/src/main/java/org/apache/felix/ipojo/Factory.java
+++ b/ipojo/src/main/java/org/apache/felix/ipojo/Factory.java
@@ -23,52 +23,63 @@
import org.apache.felix.ipojo.architecture.ComponentDescription;
/**
- * Component Type Factory Service.
- * This service is exposed by a instance manager factory, and allows the dynamic creation of component instance.
+ * Component Type Factory Service. 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 an instance manager (i.e. component type instance).
+ *
* @param configuration : the configuration properties for this component.
* @return the created instance manager.
+ * @throws UnacceptableConfiguration : when a given configuration is not valid.
*/
ComponentInstance createComponentInstance(Dictionary configuration) throws UnacceptableConfiguration;
-
+
/**
- * Create an instance manager (i.e. component type instance).
- * This has these service interaction in the scope given in argument.
+ * 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 instance manager.
+ * @throws UnacceptableConfiguration : when the given configuration isnot valid.
*/
ComponentInstance createComponentInstance(Dictionary configuration, ServiceContext serviceContext) throws UnacceptableConfiguration;
/**
- * Get the component type information containing provided service, configuration properties ...
- * @return the compionent type information.
+ * Get the component type information containing provided service,
+ * configuration properties ...
+ *
+ * @return the component type information.
*/
ComponentDescription getComponentDescription();
-
+
/**
- * Check if the given configuration is acceptable as a configuration of a component instance.
+ * Check if the given configuration is acceptable as a configuration of a
+ * component instance.
+ *
* @param conf : the configuration to test
* @return true if the configuration is acceptable
*/
boolean isAcceptable(Dictionary conf);
-
+
/**
+ * Return the factory name.
* @return the name of the factory.
*/
String getName();
-
-
+
/**
- * Reconfigure an instance already created.
- * This configuration need to have the name property to identify the instance.
+ * Reconfigure an instance already created. This configuration need to have
+ * the name property to identify the instance.
+ *
* @param conf : the configuration to reconfigure the instance.
- * @throws UnacceptableConfiguration : if the given configuration is not consistent for the tragetted instance.
+ * @throws UnacceptableConfiguration : if the given configuration is not
+ * consistent for the tragetted instance.
*/
void reconfigure(Dictionary conf) throws UnacceptableConfiguration;
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 54b46b2..0c474bc 100644
--- a/ipojo/src/main/java/org/apache/felix/ipojo/Handler.java
+++ b/ipojo/src/main/java/org/apache/felix/ipojo/Handler.java
@@ -24,14 +24,16 @@
import org.apache.felix.ipojo.metadata.Element;
/**
- * Handler Abstract Class.
- * An handler need implements tese method to be notifed of lifecycle change, getfield operation and putfield operation
+ * Handler Abstract Class. An handler need implements tese method to be notifed
+ * of lifecycle change, getfield operation and putfield operation
+ *
* @author <a href="mailto:felix-dev@incubator.apache.org">Felix Project Team</a>
*/
public abstract class Handler {
/**
* Configure the handler.
+ *
* @param im : the instance manager
* @param metadata : the metadata of the component
* @param configuration : the instance configuration
@@ -50,45 +52,64 @@
/**
* This method is called when a PUTFIELD operation is detected.
+ *
* @param fieldName : the field name
* @param value : the value passed to the field
*/
- public void setterCallback(String fieldName, Object value) { }
+ public void setterCallback(String fieldName, Object value) {
+ }
/**
* This method is called when a GETFIELD operation is detected.
+ *
* @param fieldName : the field name
* @param value : the value passed to the field (by the previous handler)
* @return : the managed value of the field
*/
- public Object getterCallback(String fieldName, Object value) { return value; }
+ public Object getterCallback(String fieldName, Object value) {
+ return value;
+ }
/**
* Is the actual state valid for this handler ?
+ *
* @return true is the state seems valid for the handler
*/
- public boolean isValid() { return true; }
+ public boolean isValid() {
+ return true;
+ }
/**
* This method is called when the component state changed.
+ *
* @param state : the new state
*/
- public void stateChanged(int state) { }
+ public void stateChanged(int state) {
+ }
/**
- * This method is called when an instance of the component is created, but before someone can use it.
+ * This method is called when an instance of the component is created, but
+ * before someone can use it.
+ *
* @param instance : the created instance
*/
- public void createInstance(Object instance) { }
-
+ public void createInstance(Object instance) {
+ }
+
/**
+ * Return the current handler description.
+ * Thesimplest description contains only the name and the validity of the handler.
* @return the description of the handler..
*/
- public HandlerDescription getDescription() { return new HandlerDescription(this.getClass().getName(), isValid()); }
+ public HandlerDescription getDescription() {
+ return new HandlerDescription(this.getClass().getName(), isValid());
+ }
- /**
- * The instance is reconfiguring.
- * @param configuration : New instance configuration.
- */
- public void reconfigure(Dictionary configuration) { }
+ /**
+ * The instance is reconfiguring.
+ *
+ * @param configuration : New instance configuration.
+ */
+ public void reconfigure(Dictionary configuration) {
+ }
}
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 e431196..706a767 100644
--- a/ipojo/src/main/java/org/apache/felix/ipojo/IPojoConfiguration.java
+++ b/ipojo/src/main/java/org/apache/felix/ipojo/IPojoConfiguration.java
@@ -28,9 +28,8 @@
import org.apache.felix.ipojo.util.Logger;
/**
- * Activator Basic Configuration.
- * - Log Level
- * - Available handlers
+ * Activator Basic Configuration. - Log Level - Available handlers
+ *
* @author <a href="mailto:felix-dev@incubator.apache.org">Felix Project Team</a>
*/
public class IPojoConfiguration {
@@ -43,21 +42,22 @@
/**
* Available handlers in the iPOJO bundle.
*/
- public static final Class[] INTERNAL_HANDLERS = new Class[] {
- DependencyHandler.class,
- ProvidedServiceHandler.class,
+ public static final Class[] INTERNAL_HANDLERS = new Class[] {
+ DependencyHandler.class,
+ ProvidedServiceHandler.class,
ConfigurationHandler.class,
- LifecycleCallbackHandler.class,
- ArchitectureHandler.class
+ LifecycleCallbackHandler.class,
+ ArchitectureHandler.class
};
- /**
- * Available composite handlers in the iPOJO bundle.
- */
- public static final Class[] INTERNAL_COMPOSITE_HANDLERS = new Class[] {
- ServiceInstantiatorHandler.class,
- ImportExportHandler.class,
- org.apache.felix.ipojo.composite.architecture.ArchitectureHandler.class
- };
+ /**
+ * Available composite handlers in the iPOJO bundle.
+ */
+ public static final Class[] INTERNAL_COMPOSITE_HANDLERS = new Class[] {
+ ServiceInstantiatorHandler.class,
+ ImportExportHandler.class,
+ org.apache.felix.ipojo.composite.service.provides.ProvidedServiceHandler.class,
+ org.apache.felix.ipojo.composite.architecture.ArchitectureHandler.class
+ };
}
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 85166b7..9d119e5 100644
--- a/ipojo/src/main/java/org/apache/felix/ipojo/IPojoContext.java
+++ b/ipojo/src/main/java/org/apache/felix/ipojo/IPojoContext.java
@@ -34,174 +34,272 @@
import org.osgi.framework.ServiceRegistration;
/**
- * The iPOJO Context is a BundleContext implementation allowing the separation between Bundle context and Service (Bundle) Context.
+ * The iPOJO Context is a BundleContext implementation allowing the separation
+ * between Bundle context and Service (Bundle) Context.
+ *
* @author <a href="mailto:felix-dev@incubator.apache.org">Felix Project Team</a>
*/
public class IPojoContext implements BundleContext {
-
- /**
- * BundleContext used to access bundle method.
- */
- private BundleContext m_bundleContext;
-
- /**
- * Service Context used to access service interaction.
- */
- private ServiceContext m_serviceContext;
-
- /**
- * Constructor.
- * Used when the service context = the bundle context
- * @param bc : bundle context
- */
- public IPojoContext(BundleContext bc) {
- m_bundleContext = bc;
- m_serviceContext = new DefaultServiceContext(bc);
- }
-
- /**
- * Constructor.
- * Used when the service context and the bundle context are different
- * @param bc : bundle context
- * @param sc : service context
- */
- public IPojoContext(BundleContext bc, ServiceContext sc) {
- m_bundleContext = bc;
- m_serviceContext = sc;
- }
- /**
- * @see org.osgi.framework.BundleContext#addBundleListener(org.osgi.framework.BundleListener)
- */
- public void addBundleListener(BundleListener listener) { m_bundleContext.addBundleListener(listener); }
+ /**
+ * BundleContext used to access bundle method.
+ */
+ private BundleContext m_bundleContext;
- /**
- * @see org.osgi.framework.BundleContext#addFrameworkListener(org.osgi.framework.FrameworkListener)
- */
- public void addFrameworkListener(FrameworkListener listener) { m_bundleContext.addFrameworkListener(listener); }
+ /**
+ * Service Context used to access service interaction.
+ */
+ private ServiceContext m_serviceContext;
- /**
- * @see org.osgi.framework.BundleContext#addServiceListener(org.osgi.framework.ServiceListener, java.lang.String)
- */
- public void addServiceListener(ServiceListener listener, String filter) throws InvalidSyntaxException {
- m_serviceContext.addServiceListener(listener, filter);
- }
+ /**
+ * Constructor. Used when the service context = the bundle context
+ *
+ * @param bc : bundle context
+ */
+ public IPojoContext(BundleContext bc) {
+ m_bundleContext = bc;
+ m_serviceContext = new DefaultServiceContext(bc);
+ }
- /**
- * @see org.osgi.framework.BundleContext#addServiceListener(org.osgi.framework.ServiceListener)
- */
- public void addServiceListener(ServiceListener listener) { m_serviceContext.addServiceListener(listener); }
+ /**
+ * Constructor. Used when the service context and the bundle context are
+ * different
+ *
+ * @param bc : bundle context
+ * @param sc : service context
+ */
+ public IPojoContext(BundleContext bc, ServiceContext sc) {
+ m_bundleContext = bc;
+ m_serviceContext = sc;
+ }
- /**
- * @see org.osgi.framework.BundleContext#createFilter(java.lang.String)
- */
- public Filter createFilter(String filter) throws InvalidSyntaxException {
- return m_bundleContext.createFilter(filter);
- }
+
+ /**
+ * Add a bundle listener.
+ * @param listener : the listener to add
+ * @see org.osgi.framework.BundleContext#addBundleListener(org.osgi.framework.BundleListener)
+ */
+ public void addBundleListener(BundleListener listener) {
+ m_bundleContext.addBundleListener(listener);
+ }
- /**
- * @see org.osgi.framework.BundleContext#getAllServiceReferences(java.lang.String, java.lang.String)
- */
- public ServiceReference[] getAllServiceReferences(String clazz, String filter) throws InvalidSyntaxException {
- return m_serviceContext.getAllServiceReferences(clazz, filter);
- }
+ /**
+ * Add a framework listener.
+ * @param listener : the listener object to add
+ * @see org.osgi.framework.BundleContext#addFrameworkListener(org.osgi.framework.FrameworkListener)
+ */
+ public void addFrameworkListener(FrameworkListener listener) {
+ m_bundleContext.addFrameworkListener(listener);
+ }
- /**
- * @see org.osgi.framework.BundleContext#getBundle()
- */
- public Bundle getBundle() { return m_bundleContext.getBundle(); }
+ /**
+ * Add a service listener.
+ * @param listener : the service lsitener to add.
+ * @param filter : the LDAP filter
+ * @throws InvalidSyntaxException : occurs when the LDAP filter is malformed
+ * @see org.osgi.framework.BundleContext#addServiceListener(org.osgi.framework.ServiceListener, java.lang.String)
+ */
+ public void addServiceListener(ServiceListener listener, String filter) throws InvalidSyntaxException {
+ m_serviceContext.addServiceListener(listener, filter);
+ }
- /**
- * @see org.osgi.framework.BundleContext#getBundle(long)
- */
- public Bundle getBundle(long id) { return m_bundleContext.getBundle(id); }
+ /**
+ * Add a service listener.
+ * @param listener : the service listener to add.
+ * @see org.osgi.framework.BundleContext#addServiceListener(org.osgi.framework.ServiceListener)
+ */
+ public void addServiceListener(ServiceListener listener) {
+ m_serviceContext.addServiceListener(listener);
+ }
- /**
- * @see org.osgi.framework.BundleContext#getBundles()
- */
- public Bundle[] getBundles() { return m_bundleContext.getBundles(); }
- /**
- * @see org.osgi.framework.BundleContext#getDataFile(java.lang.String)
- */
- public File getDataFile(String filename) { return m_bundleContext.getDataFile(filename); }
+ /**
+ * Create a Filter object.
+ * @param filter : the string form of the LDAP filter to create
+ * @return the Filter object.
+ * @throws InvalidSyntaxException : occurs when the given filter is malformed
+ * @see org.osgi.framework.BundleContext#createFilter(java.lang.String)
+ */
+ public Filter createFilter(String filter) throws InvalidSyntaxException {
+ return m_bundleContext.createFilter(filter);
+ }
- /**
- * @see org.osgi.framework.BundleContext#getProperty(java.lang.String)
- */
- public String getProperty(String key) { return m_bundleContext.getProperty(key); }
+ /**
+ * Get the service references matching with the given query.
+ * @param clazz : Required interface
+ * @param filter : LDAP filter
+ * @return the array of available service reference
+ * @throws InvalidSyntaxException : occurs if the LDAP filter is malformed
+ * @see org.osgi.framework.BundleContext#getAllServiceReferences(java.lang.String, java.lang.String)
+ */
+ public ServiceReference[] getAllServiceReferences(String clazz, String filter) throws InvalidSyntaxException {
+ return m_serviceContext.getAllServiceReferences(clazz, filter);
+ }
- /**
- * @see org.osgi.framework.BundleContext#getService(org.osgi.framework.ServiceReference)
- */
- public Object getService(ServiceReference reference) { return m_serviceContext.getService(reference); }
+ /**
+ * Get the current bundle.
+ * @return the current bundle
+ * @see org.osgi.framework.BundleContext#getBundle()
+ */
+ public Bundle getBundle() {
+ return m_bundleContext.getBundle();
+ }
- /**
- * @see org.osgi.framework.BundleContext#getServiceReference(java.lang.String)
- */
- public ServiceReference getServiceReference(String clazz) { return m_serviceContext.getServiceReference(clazz); }
+ /**
+ * Get the bundle object with the given id.
+ * @param id : bundle id
+ * @return the bundle object
+ * @see org.osgi.framework.BundleContext#getBundle(long)
+ */
+ public Bundle getBundle(long id) {
+ return m_bundleContext.getBundle(id);
+ }
- /**
- * @see org.osgi.framework.BundleContext#getServiceReferences(java.lang.String, java.lang.String)
- */
- public ServiceReference[] getServiceReferences(String clazz, String filter) throws InvalidSyntaxException {
- return m_serviceContext.getServiceReferences(clazz, filter);
- }
+ /**
+ * Get installed bundles.
+ * @return the list of installed bundles
+ * @see org.osgi.framework.BundleContext#getBundles()
+ */
+ public Bundle[] getBundles() {
+ return m_bundleContext.getBundles();
+ }
- /**
- * @see org.osgi.framework.BundleContext#installBundle(java.lang.String)
- */
- public Bundle installBundle(String location) throws BundleException { return m_bundleContext.installBundle(location); }
- /**
- * @see org.osgi.framework.BundleContext#installBundle(java.lang.String, java.io.InputStream)
- */
- public Bundle installBundle(String location, InputStream input) throws BundleException {
- return m_bundleContext.installBundle(location, input);
- }
+ /**
+ * Get a data file.
+ * @param filename : File name.
+ * @return the File object
+ * @see org.osgi.framework.BundleContext#getDataFile(java.lang.String)
+ */
+ public File getDataFile(String filename) {
+ return m_bundleContext.getDataFile(filename);
+ }
- /**
- * @see org.osgi.framework.BundleContext#registerService(java.lang.String[], java.lang.Object, java.util.Dictionary)
- */
- public ServiceRegistration registerService(String[] clazzes,
- Object service, Dictionary properties) { return m_serviceContext.registerService(clazzes, service, properties); }
+ /**
+ * Get a property value.
+ * @param key : key of the asked property
+ * @return the property value (object) or null if no property are associated with the given key
+ * @see org.osgi.framework.BundleContext#getProperty(java.lang.String)
+ */
+ public String getProperty(String key) {
+ return m_bundleContext.getProperty(key);
+ }
- /**
- * @see org.osgi.framework.BundleContext#registerService(java.lang.String, java.lang.Object, java.util.Dictionary)
- */
- public ServiceRegistration registerService(String clazz, Object service,
- Dictionary properties) { return m_serviceContext.registerService(clazz, service, properties); }
+ /**
+ * Get a service object.
+ * @param reference : the required service reference
+ * @return the service object or null if the service reference is no more valid or if the service object is not accessible
+ * @see org.osgi.framework.BundleContext#getService(org.osgi.framework.ServiceReference)
+ */
+ public Object getService(ServiceReference reference) {
+ return m_serviceContext.getService(reference);
+ }
- /**
- * @see org.osgi.framework.BundleContext#removeBundleListener(org.osgi.framework.BundleListener)
- */
- public void removeBundleListener(BundleListener listener) { m_bundleContext.removeBundleListener(listener); }
+ /**
+ * Get a service reference for the given interface.
+ * @param clazz : the required interface name
+ * @return a service reference on a available provider or null if no provider available
+ * @see org.osgi.framework.BundleContext#getServiceReference(java.lang.String)
+ */
+ public ServiceReference getServiceReference(String clazz) {
+ return m_serviceContext.getServiceReference(clazz);
+ }
- /**
- * @see org.osgi.framework.BundleContext#removeFrameworkListener(org.osgi.framework.FrameworkListener)
- */
- public void removeFrameworkListener(FrameworkListener listener) { m_bundleContext.removeFrameworkListener(listener); }
+ /**
+ * Get service reference list for the given query.
+ * @param clazz : the name of the requried service interface
+ * @param filter : LDAP filter to apply on service provider
+ * @return : the array of consistent service reference or null if no available provider
+ * @throws InvalidSyntaxException : occrus if the LDAP filter is malformed
+ * @see org.osgi.framework.BundleContext#getServiceReferences(java.lang.String, java.lang.String)
+ */
+ public ServiceReference[] getServiceReferences(String clazz, String filter) throws InvalidSyntaxException {
+ return m_serviceContext.getServiceReferences(clazz, filter);
+ }
- /**
- * @see org.osgi.framework.BundleContext#removeServiceListener(org.osgi.framework.ServiceListener)
- */
- public void removeServiceListener(ServiceListener listener) { m_serviceContext.removeServiceListener(listener); }
+ /**
+ * Install a bundle.
+ * @param location : URL of the bundle to install
+ * @return the installed bundle
+ * @throws BundleException : if the bundle cannot be installed correctly
+ * @see org.osgi.framework.BundleContext#installBundle(java.lang.String)
+ */
+ public Bundle installBundle(String location) throws BundleException {
+ return m_bundleContext.installBundle(location);
+ }
- /**
- * @see org.osgi.framework.BundleContext#ungetService(org.osgi.framework.ServiceReference)
- */
- public boolean ungetService(ServiceReference reference) { return m_serviceContext.ungetService(reference); }
-
- /**
- * Set the instance to the service context.
- * @param ci : the component instance
- */
- //public void setComponentInstance(ComponentInstance ci) { m_serviceContext.setComponentInstance(ci); }
-
- /**
- * Get the instance manager from the service context.
- * @return the component manager of the service context
- */
- //public ComponentInstance getComponentInstance() { return m_serviceContext.getComponentInstance(); }
+ /**
+ * Install a bundle.
+ * @param location : URL of the bundle to install
+ * @param input :
+ * @return the installed bundle
+ * @throws BundleException : if the bundle cannot be installed correctly
+ * @see org.osgi.framework.BundleContext#installBundle(java.lang.String, java.io.InputStream)
+ */
+ public Bundle installBundle(String location, InputStream input) throws BundleException {
+ return m_bundleContext.installBundle(location, input);
+ }
+
+ /**
+ * Register a service.
+ * @param clazzes : interfaces provided by the service.
+ * @param service : the service object.
+ * @param properties : service properties.
+ * @return the service registration for this service publication.
+ * @see org.apache.felix.ipojo.ServiceContext#registerService(java.lang.String[], java.lang.Object, java.util.Dictionary)
+ */
+ public ServiceRegistration registerService(String[] clazzes, Object service, Dictionary properties) {
+ return m_serviceContext.registerService(clazzes, service, properties);
+ }
+
+ /**
+ * Register a service.
+ * @param clazz : interface provided by the service.
+ * @param service : the service object.
+ * @param properties : service properties.
+ * @return the service registration for this service publication.
+ * @see org.osgi.framework.BundleContext#registerService(java.lang.String, java.lang.Object, java.util.Dictionary)
+ */
+ public ServiceRegistration registerService(String clazz, Object service, Dictionary properties) {
+ return m_serviceContext.registerService(clazz, service, properties);
+ }
+
+ /**
+ * Remove a bundle listener.
+ * @param listener : the listener to remove
+ * @see org.osgi.framework.BundleContext#removeBundleListener(org.osgi.framework.BundleListener)
+ */
+ public void removeBundleListener(BundleListener listener) {
+ m_bundleContext.removeBundleListener(listener);
+ }
+
+ /**
+ * Remove a framework listener.
+ * @param listener : the listener to remove
+ * @see org.osgi.framework.BundleContext#removeFrameworkListener(org.osgi.framework.FrameworkListener)
+ */
+ public void removeFrameworkListener(FrameworkListener listener) {
+ m_bundleContext.removeFrameworkListener(listener);
+ }
+
+ /**
+ * Remove a service listener.
+ * @param listener : the service listner to remove
+ * @see org.apache.felix.ipojo.ServiceContext#removeServiceListener(org.osgi.framework.ServiceListener)
+ * @see org.osgi.framework.BundleContext#removeServiceListener(org.osgi.framework.ServiceListener)
+ */
+ public void removeServiceListener(ServiceListener listener) {
+ m_serviceContext.removeServiceListener(listener);
+ }
+
+ /**
+ * Unget the service reference.
+ * @param reference : the reference to unget
+ * @return true if you are the last user of the reference
+ * @see org.osgi.framework.BundleContext#ungetService(org.osgi.framework.ServiceReference)
+ */
+ public boolean ungetService(ServiceReference reference) {
+ return m_serviceContext.ungetService(reference);
+ }
}
diff --git a/ipojo/src/main/java/org/apache/felix/ipojo/InstanceCreator.java b/ipojo/src/main/java/org/apache/felix/ipojo/InstanceCreator.java
index 6fa3be8..2254a1a 100644
--- a/ipojo/src/main/java/org/apache/felix/ipojo/InstanceCreator.java
+++ b/ipojo/src/main/java/org/apache/felix/ipojo/InstanceCreator.java
@@ -28,172 +28,202 @@
import org.osgi.framework.ServiceReference;
/**
- * An instance creator aims to create instances and to track their factories.
+ * 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 {
-
- /**
- * Bundle Context.
- */
- private BundleContext m_context;
-
- /**
- * Logger to log messages if error occurs.
- */
- private Logger m_logger;
-
- /**
- * This structure aims to manage a configuration.
- * It stores all necessary information to create an instance and to track the factory.
- */
- private class ManagedConfiguration {
- /**
- * Configuration of the instance to create.
- */
- private Dictionary m_configuration;
-
- /**
- * Factory name.
- */
- private String m_factoryName;
-
- /**
- * Created instance.
- */
- private ComponentInstance m_instance;
-
- /**
- * Constructor.
- * @param conf : the configuration to create.
- */
- ManagedConfiguration(Dictionary conf) { m_configuration = conf; }
-
- /**
- * @return the configuration.
- */
- Dictionary getConfiguration() { return m_configuration; }
-
- /**
- * @return the factory
- */
- String getFactory() { return m_factoryName; }
-
- /**
- * @return the instance (or null if no instance are created).
- */
- ComponentInstance getInstance() { return m_instance; }
-
- /**
- * Set the factory name.
- * @param name : the factory name.
- */
- void setFactory(String name) { m_factoryName = name; }
-
- /**
- * Set the instance object.
- * @param instance : the instance
- */
- void setInstance(ComponentInstance instance) { m_instance = instance; }
- }
-
-
- /**
- * Configurations to create and maintains.
- */
- private ManagedConfiguration[] m_configurations;
-
- /**
- * Constructor.
- * @param context : the bundle context.
- * @param configurations : configuration set to create and maintain.
- */
- public InstanceCreator(BundleContext context, Dictionary[] configurations) {
- m_context = context;
- m_logger = new Logger(context, "InstanceCreator" + context.getBundle().getBundleId(), Logger.WARNING);
- 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 :
- String componentType = (String) conf.getConfiguration().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 {
- m_logger.log(Logger.WARNING, "No factory available for the type : " + componentType);
- }
- } catch (InvalidSyntaxException e) { m_logger.log(Logger.ERROR, "Invalid syntax filter for the type : " + componentType, e); }
- }
-
- // Register a service listenner on Factory Service
- try {
- m_context.addServiceListener(this, "(objectClass=" + Factory.class.getName() + ")");
- } catch (InvalidSyntaxException e) { m_logger.log(Logger.ERROR, "Invalid syntax filter when registering a listener on Factory Service", e); }
- }
-
- /**
- * Create an instance using the given factory and the given configuration.
- * @param fact : the facotry name to used.
- * @param config : the configuration.
- */
- private void createInstance(Factory fact, ManagedConfiguration config) {
- Dictionary conf = config.getConfiguration();
- try {
- config.setInstance(fact.createComponentInstance(conf));
- config.setFactory(fact.getName());
- } catch (UnacceptableConfiguration e) {
- m_logger.log(Logger.ERROR, "A factory is available for the configuration but the configuration is not acceptable", e);
- }
- }
+ /**
+ * Bundle Context.
+ */
+ private BundleContext m_context;
- /**
- * @see org.osgi.framework.ServiceListener#serviceChanged(org.osgi.framework.ServiceEvent)
- */
- 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].getInstance() == null && (m_configurations[i].getConfiguration().get("component").equals(factoryName) || m_configurations[i].getConfiguration().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].getInstance() != null && m_configurations[i].getFactory().equals(factoryName)) {
- m_configurations[i].setInstance(null);
- m_configurations[i].setFactory(null);
- m_context.ungetService(ref);
- }
- }
- return;
- }
- }
-
- /**
- * Stop all created instances.
- */
- public void stop() {
- for (int i = 0; i < m_configurations.length; i++) {
- if (m_configurations[i].getInstance() != null) { m_configurations[i].getInstance().stop(); }
- m_configurations[i].setInstance(null);
- m_configurations[i].setFactory(null);
- }
- m_configurations = null;
- }
+ /**
+ * Logger to log messages if error occurs.
+ */
+ private Logger m_logger;
+
+ /**
+ * This structure aims to manage a configuration. It stores all necessary
+ * information to create an instance and to track the factory.
+ */
+ private class ManagedConfiguration {
+ /**
+ * Configuration of the instance to create.
+ */
+ private Dictionary m_configuration;
+
+ /**
+ * Factory name.
+ */
+ private String m_factoryName;
+
+ /**
+ * Created instance.
+ */
+ private ComponentInstance m_instance;
+
+ /**
+ * Constructor.
+ *
+ * @param conf : the configuration to create.
+ */
+ ManagedConfiguration(Dictionary conf) {
+ m_configuration = conf;
+ }
+
+ /**
+ * Return the managed configuration.
+ * @return the configuration.
+ */
+ Dictionary getConfiguration() {
+ return m_configuration;
+ }
+
+ /**
+ * Return the used factory name.
+ * @return the factory
+ */
+ String getFactory() {
+ return m_factoryName;
+ }
+
+ /**
+ * Return the created instance.
+ * @return the instance (or null if no instance are created).
+ */
+ ComponentInstance getInstance() {
+ return m_instance;
+ }
+
+ /**
+ * Set the factory name.
+ *
+ * @param name : the factory name.
+ */
+ void setFactory(String name) {
+ m_factoryName = name;
+ }
+
+ /**
+ * Set the instance object.
+ *
+ * @param instance : the instance
+ */
+ void setInstance(ComponentInstance instance) {
+ m_instance = instance;
+ }
+ }
+
+ /**
+ * Configurations to create and maintains.
+ */
+ private ManagedConfiguration[] m_configurations = new ManagedConfiguration[0];
+
+ /**
+ * Constructor.
+ *
+ * @param context : the bundle context.
+ * @param configurations : configuration set to create and maintain.
+ */
+ public InstanceCreator(BundleContext context, Dictionary[] configurations) {
+ m_context = context;
+ m_logger = new Logger(context, "InstanceCreator" + context.getBundle().getBundleId(), Logger.WARNING);
+ 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 :
+ String componentType = (String) conf.getConfiguration().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 {
+ m_logger.log(Logger.WARNING, "No factory available for the type : " + componentType);
+ }
+ } catch (InvalidSyntaxException e) {
+ m_logger.log(Logger.ERROR, "Invalid syntax filter for the type : " + componentType, e);
+ }
+ }
+
+ // Register a service listenner on Factory Service
+ try {
+ m_context.addServiceListener(this, "(objectClass=" + Factory.class.getName() + ")");
+ } catch (InvalidSyntaxException e) {
+ m_logger.log(Logger.ERROR, "Invalid syntax filter when registering a listener on Factory Service", e);
+ }
+ }
+
+ /**
+ * Create an instance using the given factory and the given configuration.
+ *
+ * @param fact : the facotry name to used.
+ * @param config : the configuration.
+ */
+ private void createInstance(Factory fact, ManagedConfiguration config) {
+ Dictionary conf = config.getConfiguration();
+ try {
+ config.setInstance(fact.createComponentInstance(conf));
+ config.setFactory(fact.getName());
+ } catch (UnacceptableConfiguration e) {
+ m_logger.log(Logger.ERROR, "A factory is available for the configuration but the configuration is not acceptable", e);
+ }
+ }
+
+ /**
+ * Service Listener implementation.
+ * @param ev : the service event
+ * @see org.osgi.framework.ServiceListener#serviceChanged(org.osgi.framework.ServiceEvent)
+ */
+ 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].getInstance() == null
+ && (m_configurations[i].getConfiguration().get("component").equals(factoryName) || m_configurations[i].getConfiguration().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].getInstance() != null && m_configurations[i].getFactory().equals(factoryName)) {
+ m_configurations[i].setInstance(null);
+ m_configurations[i].setFactory(null);
+ m_context.ungetService(ref);
+ }
+ }
+ return;
+ }
+ }
+
+ /**
+ * Stop all created instances.
+ */
+ public synchronized void stop() {
+ m_context.removeServiceListener(this);
+ for (int i = 0; i < m_configurations.length; i++) {
+ if (m_configurations[i].getInstance() != null) {
+ m_configurations[i].getInstance().stop();
+ }
+ m_configurations[i].setInstance(null);
+ m_configurations[i].setFactory(null);
+ }
+ m_configurations = null;
+ }
}
diff --git a/ipojo/src/main/java/org/apache/felix/ipojo/InstanceManager.java b/ipojo/src/main/java/org/apache/felix/ipojo/InstanceManager.java
index 5f9cda3..134d5f3 100644
--- a/ipojo/src/main/java/org/apache/felix/ipojo/InstanceManager.java
+++ b/ipojo/src/main/java/org/apache/felix/ipojo/InstanceManager.java
@@ -30,8 +30,9 @@
import org.osgi.framework.BundleContext;
/**
- * The instance manager class manages one instance of a component type.
- * It manages component lifecycle, component instance creation and handlers.
+ * 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 InstanceManager implements ComponentInstance {
@@ -40,12 +41,12 @@
* Parent factory (ComponentFactory).
*/
private ComponentFactory m_factory;
-
+
/**
* Name of the component instance.
*/
private String m_name;
-
+
/**
* Name of the component type implementation class.
*/
@@ -72,7 +73,7 @@
private int m_state = STOPPED;
/**
- * Manipulatd clazz.
+ * Manipulated clazz.
*/
private Class m_clazz;
@@ -89,6 +90,7 @@
// Constructor
/**
* Construct a new Component Manager.
+ *
* @param factory : the factory managing the instance manager
* @param bc : the bundle context to give to the instance
*/
@@ -99,14 +101,17 @@
}
/**
- * Configure the instance manager.
- * Stop the existings handler, clear the handler list, change the metadata, recreate the handlers
+ * Configure the instance manager. Stop the existings handler, clear the
+ * handler list, change the metadata, recreate the handlers
+ *
* @param cm : the component type metadata
* @param configuration : the configuration of the instance
*/
public void configure(Element cm, Dictionary configuration) {
// Stop all previous registred handler
- if (m_handlers.length != 0) { stop(); }
+ if (m_handlers.length != 0) {
+ stop();
+ }
// Clear the handler list
m_handlers = new Handler[0];
@@ -119,7 +124,7 @@
// ComponentInfo initialization
m_componentDesc = new ComponentDescription(m_factory.getName(), m_className);
-
+
// Add the name
m_name = (String) configuration.get("name");
@@ -130,9 +135,11 @@
Handler h = (Handler) IPojoConfiguration.INTERNAL_HANDLERS[i].newInstance();
h.configure(this, cm, configuration);
} catch (InstantiationException e) {
- m_factory.getLogger().log(Logger.ERROR, "[" + m_name + "] Cannot instantiate the handler " + IPojoConfiguration.INTERNAL_HANDLERS[i] + " : " + e.getMessage());
+ m_factory.getLogger().log(Logger.ERROR,
+ "[" + m_name + "] Cannot instantiate the handler " + IPojoConfiguration.INTERNAL_HANDLERS[i] + " : " + e.getMessage());
} catch (IllegalAccessException e) {
- m_factory.getLogger().log(Logger.ERROR, "[" + m_name + "] Cannot instantiate the handler " + IPojoConfiguration.INTERNAL_HANDLERS[i] + " : " + e.getMessage());
+ m_factory.getLogger().log(Logger.ERROR,
+ "[" + m_name + "] Cannot instantiate the handler " + IPojoConfiguration.INTERNAL_HANDLERS[i] + " : " + e.getMessage());
}
}
@@ -145,67 +152,72 @@
Handler h = (Handler) c.newInstance();
h.configure(this, cm, configuration);
} catch (ClassNotFoundException e) {
- m_factory.getLogger().log(Logger.ERROR, "[" + m_name + "] Cannot instantiate the handler " + cm.getNamespaces()[i] + " : " + e.getMessage());
+ m_factory.getLogger()
+ .log(Logger.ERROR, "[" + m_name + "] Cannot instantiate the handler " + cm.getNamespaces()[i] + " : " + e.getMessage());
} catch (InstantiationException e) {
- m_factory.getLogger().log(Logger.ERROR, "[" + m_name + "] Cannot instantiate the handler " + cm.getNamespaces()[i] + " : " + e.getMessage());
+ m_factory.getLogger()
+ .log(Logger.ERROR, "[" + m_name + "] Cannot instantiate the handler " + cm.getNamespaces()[i] + " : " + e.getMessage());
} catch (IllegalAccessException e) {
- m_factory.getLogger().log(Logger.ERROR, "[" + m_name + "] Cannot instantiate the handler " + cm.getNamespaces()[i] + " : " + e.getMessage());
+ m_factory.getLogger()
+ .log(Logger.ERROR, "[" + m_name + "] Cannot instantiate the handler " + cm.getNamespaces()[i] + " : " + e.getMessage());
}
}
}
}
/**
+ * Get the compoenent-type description of the current instance.
* @return the component type information.
+ * @see org.apache.felix.ipojo.ComponentInstance#getComponentDescription()
*/
- public ComponentDescription getComponentDescription() { return m_componentDesc; }
-
+ public ComponentDescription getComponentDescription() {
+ return m_componentDesc;
+ }
+
/**
+ * Get the description of the current instance.
* @return the instance description.
+ * @see org.apache.felix.ipojo.ComponentInstance#getInstanceDescription()
*/
public InstanceDescription getInstanceDescription() {
- int componentState = getState();
+ int componentState = getState();
InstanceDescription instanceDescription = new InstanceDescription(m_name, componentState, getContext().getBundle().getBundleId(), m_componentDesc);
String[] objects = new String[getPojoObjects().length];
for (int i = 0; i < getPojoObjects().length; i++) {
- objects[i] = getPojoObjects()[i].toString();
+ objects[i] = getPojoObjects()[i].toString();
}
instanceDescription.setCreatedObjects(objects);
Handler[] handlers = getRegistredHandlers();
for (int i = 0; i < handlers.length; i++) {
- instanceDescription.addHandler(handlers[i].getDescription());
+ instanceDescription.addHandler(handlers[i].getDescription());
}
return instanceDescription;
}
/**
- * @return the list of the registred handlers.
+ * Get the list of handlers plugged on the instance.
+ * @return the handler array of plugged handlers.
*/
- public Handler[] getRegistredHandlers() { return m_handlers; }
+ public Handler[] getRegistredHandlers() {
+ return m_handlers;
+ }
/**
* Return a specified handler.
+ *
* @param name : class name of the handler to find
* @return : the handler, or null if not found
*/
public Handler getHandler(String name) {
for (int i = 0; i < m_handlers.length; i++) {
- if (m_handlers[i].getClass().getName().equalsIgnoreCase(name)) { return m_handlers[i]; }
+ if (m_handlers[i].getClass().getName().equalsIgnoreCase(name)) {
+ return m_handlers[i];
+ }
}
return null;
}
-
- /**
- * @return the component instance name.
- */
- public String getComponentName() { return m_name; }
-
- /**
- * @return the implementation class name of the instance.
- */
- public String getClassName() { return m_className; }
// ===================== Lifecycle management =====================
@@ -213,8 +225,10 @@
* Start the instance manager.
*/
public void start() {
- if (m_state != STOPPED) { return; } // Instance already started
-
+ if (m_state != STOPPED) {
+ return;
+ } // Instance already started
+
// Start all the handlers
m_factory.getLogger().log(Logger.INFO, "[" + m_name + "] Start the instance manager with " + m_handlers.length + " handlers");
@@ -233,30 +247,58 @@
* Stop the instance manager.
*/
public void stop() {
- if (m_state == STOPPED) { return; } // Instance already stopped
-
+ if (m_state == STOPPED) {
+ return;
+ } // Instance already stopped
+
setState(INVALID);
// Stop all the handlers
for (int i = m_handlers.length - 1; i > -1; i--) {
m_handlers[i].stop();
}
m_pojoObjects = new Object[0];
-
+
m_state = STOPPED;
+ }
+
+ /**
+ * Dispose the instance.
+ * @see org.apache.felix.ipojo.ComponentInstance#dispose()
+ */
+ public void dispose() {
+ if (m_state != STOPPED) {
+ stop();
+ }
m_factory.stopped(this);
+
+ // Cleaning
+ m_factory = null;
+ m_name = null;
+ m_className = null;
+ m_context = null;
+ m_handlers = null;
+ m_fieldRegistration = null;
+ m_clazz = null;
+ m_pojoObjects = null;
+ m_componentDesc = null;
}
/**
- * Set the state of the component.
- * if the state changed call the stateChanged(int) method on the handlers
+ * Set the state of the component instance.
+ * Ff the state changed call the stateChanged(int) method on the handlers.
+ * @param state : the new state
*/
public void setState(int state) {
if (m_state != state) {
// Log the state change
- if (state == INVALID) { m_factory.getLogger().log(Logger.INFO, "[" + m_name + "] State -> INVALID"); }
- if (state == VALID) { m_factory.getLogger().log(Logger.INFO, "[" + m_name + "] State -> VALID"); }
+ if (state == INVALID) {
+ m_factory.getLogger().log(Logger.INFO, "[" + m_name + "] State -> INVALID");
+ }
+ if (state == VALID) {
+ m_factory.getLogger().log(Logger.INFO, "[" + m_name + "] State -> VALID");
+ }
// The state changed call the handler stateChange method
m_state = state;
@@ -267,23 +309,35 @@
}
/**
- * @return the actual state of the component.
+ * Get the actual state of the instance.
+ * @return the actual state of the component instance.
+ * @see org.apache.felix.ipojo.ComponentInstance#getState()
*/
- public int getState() { return m_state; }
-
+ public int getState() {
+ return m_state;
+ }
+
/**
+ * Check if the instance if started.
+ * @return true if the instance is started.
* @see org.apache.felix.ipojo.ComponentInstance#isStarted()
*/
- public boolean isStarted() { return m_state != STOPPED; }
+ public boolean isStarted() {
+ return m_state != STOPPED;
+ }
// ===================== end Lifecycle management =====================
// ================== Class & Instance management ===================
/**
+ * Get the factory which create the current instance.
* @return the factory of the component
+ * @see org.apache.felix.ipojo.ComponentInstance#getFactory()
*/
- public ComponentFactory getFactory() { return m_factory; }
+ public ComponentFactory getFactory() {
+ return m_factory;
+ }
/**
* Load the manipulated class.
@@ -291,17 +345,18 @@
private void load() {
try {
m_clazz = m_factory.loadClass(m_className);
- } catch (ClassNotFoundException e) {
+ } catch (ClassNotFoundException e) {
m_factory.getLogger().log(Logger.ERROR, "[" + m_name + "] Class not found during the loading phase : " + e.getMessage());
return;
}
}
/**
+ * Is the implementation class loaded?
* @return true if the class is loaded
*/
private boolean isLoaded() {
- return (m_clazz != null);
+ return m_clazz != null;
}
/**
@@ -310,7 +365,9 @@
*/
private void addInstance(Object o) {
for (int i = 0; (m_pojoObjects != null) && (i < m_pojoObjects.length); i++) {
- if (m_pojoObjects[i] == o) { return; }
+ if (m_pojoObjects[i] == o) {
+ return;
+ }
}
if (m_pojoObjects.length > 0) {
@@ -319,28 +376,33 @@
newInstances[m_pojoObjects.length] = o;
m_pojoObjects = newInstances;
} else {
- m_pojoObjects = new Object[] {o};
+ m_pojoObjects = new Object[] { o };
}
}
/**
- * Remove an instance from the created instance list. The instance will be eated by the garbage collector.
+ * Remove an instance from the created instance list.
+ * The instance will be eated by the garbage collector.
+ *
* @param o : the instance to remove
*/
private void removeInstance(Object o) {
int idx = -1;
for (int i = 0; i < m_pojoObjects.length; i++) {
- if (m_pojoObjects[i] == o) { idx = i; break; }
+ if (m_pojoObjects[i] == o) {
+ idx = i;
+ break;
+ }
}
if (idx >= 0) {
- if ((m_pojoObjects.length - 1) == 0) {
- m_pojoObjects = new Element[0];
+ if ((m_pojoObjects.length - 1) == 0) {
+ m_pojoObjects = new Element[0];
} else {
Object[] newInstances = new Object[m_pojoObjects.length - 1];
System.arraycopy(m_pojoObjects, 0, newInstances, 0, idx);
if (idx < newInstances.length) {
- System.arraycopy(m_pojoObjects, idx + 1, newInstances, idx, newInstances.length - idx);
+ System.arraycopy(m_pojoObjects, idx + 1, newInstances, idx, newInstances.length - idx);
}
m_pojoObjects = newInstances;
}
@@ -348,39 +410,53 @@
}
/**
- * @return the created instance of the component.
+ * Get the array of object created by the instance.
+ * @return the created instance of the component instance.
*/
- public Object[] getPojoObjects() { return m_pojoObjects; }
+ public Object[] getPojoObjects() {
+ return m_pojoObjects;
+ }
/**
- * Delete the created instance (remove it from the list, to allow the garbage collector to eat the instance).
+ * 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 deletePojoObject(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
+ * 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 createPojoObject() {
- if (!isLoaded()) { load(); }
+ if (!isLoaded()) {
+ load();
+ }
Object instance = null;
try {
- // Try to find if there is a constructor with a bundle context as parameter :
+ // Try to find if there is a constructor with a bundle context as
+ // parameter :
try {
- Constructor constructor = m_clazz.getConstructor(new Class[] {InstanceManager.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) { instance = null; }
+ instance = constructor.newInstance(new Object[] { this, m_context });
+ } catch (NoSuchMethodException e) {
+ instance = null;
+ }
- // Create an instance if no instance are already created with <init>()BundleContext
+ // Create an instance if no instance are already created with
+ // <init>()BundleContext
if (instance == null) {
- Constructor constructor = m_clazz.getConstructor(new Class[] {InstanceManager.class});
+ Constructor constructor = m_clazz.getConstructor(new Class[] { InstanceManager.class });
constructor.setAccessible(true);
- instance = constructor.newInstance(new Object[] {this});
+ instance = constructor.newInstance(new Object[] { this });
}
} catch (InstantiationException e) {
@@ -390,10 +466,12 @@
m_factory.getLogger().log(Logger.ERROR, "[" + m_name + "] createInstance -> The Component Instance is not accessible : " + e.getMessage());
e.printStackTrace();
} catch (SecurityException e) {
- m_factory.getLogger().log(Logger.ERROR, "[" + m_name + "] createInstance -> The Component Instance is not accessible (security reason) : " + e.getMessage());
+ m_factory.getLogger().log(Logger.ERROR,
+ "[" + m_name + "] createInstance -> The Component Instance is not accessible (security reason) : " + e.getMessage());
e.printStackTrace();
} catch (InvocationTargetException e) {
- m_factory.getLogger().log(Logger.ERROR, "[" + m_name + "] createInstance -> Cannot invoke the constructor method (illegal target) : " + e.getMessage());
+ m_factory.getLogger().log(Logger.ERROR,
+ "[" + m_name + "] createInstance -> Cannot invoke the constructor method (illegal target) : " + e.getMessage());
e.printStackTrace();
} catch (NoSuchMethodException e) {
m_factory.getLogger().log(Logger.ERROR, "[" + m_name + "] createInstance -> Cannot invoke the constructor (method not found) : " + e.getMessage());
@@ -405,32 +483,42 @@
// Register the new instance
addInstance(instance);
// Call createInstance on Handlers :
- for (int i = 0; i < m_handlers.length; i++) { m_handlers[i].createInstance(instance); }
+ for (int i = 0; i < m_handlers.length; i++) {
+ m_handlers[i].createInstance(instance);
+ }
return instance;
}
/**
- * @return the instance of the component to use for singleton component
+ * Get the first object created by the instance.
+ * If no object created, create and return one object.
+ * @return the instance of the component instance to use for singleton component
*/
public Object getPojoObject() {
- if (m_pojoObjects.length == 0) { createPojoObject(); }
+ if (m_pojoObjects.length == 0) {
+ createPojoObject();
+ }
return m_pojoObjects[0];
}
/**
+ * Get the manipulated class.
* @return the manipulated class
*/
public Class getClazz() {
- if (!isLoaded()) { load(); }
+ if (!isLoaded()) {
+ load();
+ }
return m_clazz;
}
- // ================== end Class & Instance management ================
+ // ================== end Class & Instance management ================
- // ======================== Handlers Management ======================
+ // ======================== Handlers Management ======================
/**
* Register the given handler to the current instance manager.
+ *
* @param h : the handler to register
*/
public void register(Handler h) {
@@ -449,8 +537,9 @@
}
/**
- * Register an handler.
- * The handler will be notified of event on each field given in the list.
+ * Register an handler. The handler will be notified of event on each field
+ * given in the list.
+ *
* @param h : the handler to register
* @param fields : the fields list
*/
@@ -458,13 +547,13 @@
register(h);
for (int i = 0; i < fields.length; i++) {
if (m_fieldRegistration.get(fields[i]) == null) {
- m_fieldRegistration.put(fields[i], new Handler[] {h});
+ m_fieldRegistration.put(fields[i], new Handler[] { h });
} else {
Handler[] list = (Handler[]) m_fieldRegistration.get(fields[i]);
- for (int j = 0; j < list.length; j++) {
- if (list[j] == 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);
@@ -475,15 +564,16 @@
}
/**
- * Unregister an handler for the field list.
- * The handler will not be notified of field access but is allways register on the instance manager.
+ * Unregister an handler for the field list. 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
*/
public void unregister(Handler h, String[] fields) {
for (int i = 0; i < fields.length; i++) {
- if (m_fieldRegistration.get(fields[i]) == null) {
- break;
+ if (m_fieldRegistration.get(fields[i]) == null) {
+ break;
} else {
Handler[] list = (Handler[]) m_fieldRegistration.get(fields[i]);
int idx = -1;
@@ -500,9 +590,8 @@
} else {
Handler[] newList = new Handler[list.length - 1];
System.arraycopy(list, 0, newList, 0, idx);
- if (idx < newList.length) {
- System.arraycopy(
- list, idx + 1, newList, idx, newList.length - idx);
+ if (idx < newList.length) {
+ System.arraycopy(list, idx + 1, newList, idx, newList.length - idx);
}
list = newList;
}
@@ -514,6 +603,7 @@
/**
* Unregister the given handler.
+ *
* @param h : the handler to unregiter
*/
public void unregister(Handler h) {
@@ -531,9 +621,8 @@
} else {
Handler[] newList = new Handler[m_handlers.length - 1];
System.arraycopy(m_handlers, 0, newList, 0, idx);
- if (idx < newList.length) {
- System.arraycopy(
- m_handlers, idx + 1, newList, idx, newList.length - idx);
+ if (idx < newList.length) {
+ System.arraycopy(m_handlers, idx + 1, newList, idx, newList.length - idx);
}
m_handlers = newList;
}
@@ -541,11 +630,15 @@
}
/**
- * This method is called by the manipulated class each time that a GETFIELD instruction is found.
- * The method ask to each handler which value need to be returned.
- * @param fieldName : the field name on which the GETFIELD instruction is called
+ * This method is called by the manipulated class each time that a GETFIELD
+ * instruction is found. The method ask to each handler which value need to
+ * be returned.
+ *
+ * @param fieldName : the field name on which the GETFIELD instruction is
+ * called
* @param initialValue : the value of the field in the code
- * @return the value decided by the last asked handler (throw a warining if two fields decide two different values)
+ * @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) {
Object result = null;
@@ -553,7 +646,9 @@
Handler[] list = (Handler[]) m_fieldRegistration.get(fieldName);
for (int i = 0; list != null && i < list.length; i++) {
Object handlerResult = list[i].getterCallback(fieldName, initialValue);
- if (handlerResult != initialValue) { result = handlerResult; }
+ if (handlerResult != initialValue) {
+ result = handlerResult;
+ }
}
if (result != null) {
@@ -564,9 +659,11 @@
}
/**
- * This method is called by the manipulated class each time that a PUTFILED instruction is found.
- * the method send to each handler the new value.
- * @param fieldName : the field name on which the PUTFIELD instruction is called
+ * This method is called by the manipulated class each time that a PUTFILED
+ * instruction is found. the method send to each handler the new value.
+ *
+ * @param fieldName : the field name on which the PUTFIELD instruction is
+ * called
* @param objectValue : the value of the field
*/
public void setterCallback(String fieldName, Object objectValue) {
@@ -579,9 +676,13 @@
}
/**
+ * Get the bundle context used by this component instance.
* @return the context of the component.
+ * @see org.apache.felix.ipojo.ComponentInstance#getContext()
*/
- public BundleContext getContext() { return m_context; }
+ public BundleContext getContext() {
+ return m_context;
+ }
/**
* Check the state of all handlers.
@@ -601,23 +702,38 @@
m_pojoObjects = new Object[0];
return;
}
- if (isValid && m_state == INVALID) { setState(VALID); }
+ if (isValid && m_state == INVALID) {
+ setState(VALID);
+ }
}
- /**
- * @see org.apache.felix.ipojo.ComponentInstance#getInstanceName()
- */
- public String getInstanceName() { return m_name; }
+ /**
+ * Get the instance name.
+ * @return the instance name.
+ * @see org.apache.felix.ipojo.ComponentInstance#getInstanceName()
+ */
+ public String getInstanceName() {
+ return m_name;
+ }
- /**
- * @see org.apache.felix.ipojo.ComponentInstance#reconfigure(java.util.Dictionary)
- */
- public void reconfigure(Dictionary configuration) {
- for (int i = 0; i < m_handlers.length; i++) {
- m_handlers[i].reconfigure(configuration);
- }
- }
+ /**
+ * Reconfigure the current instance.
+ * @param configuration : the new configuration to push
+ * @see org.apache.felix.ipojo.ComponentInstance#reconfigure(java.util.Dictionary)
+ */
+ public void reconfigure(Dictionary configuration) {
+ for (int i = 0; i < m_handlers.length; i++) {
+ m_handlers[i].reconfigure(configuration);
+ }
+ }
+ /**
+ * Get the implementation class of the component type.
+ * @return the class name of the component type.
+ */
+ public String getClassName() {
+ return m_className;
+ }
// ======================= end Handlers Management =====================
diff --git a/ipojo/src/main/java/org/apache/felix/ipojo/Nullable.java b/ipojo/src/main/java/org/apache/felix/ipojo/Nullable.java
index 1026d3f..e3e32ac 100644
--- a/ipojo/src/main/java/org/apache/felix/ipojo/Nullable.java
+++ b/ipojo/src/main/java/org/apache/felix/ipojo/Nullable.java
@@ -20,6 +20,7 @@
/**
* A nullable object must implement this interface.
+ *
* @author <a href="mailto:felix-dev@incubator.apache.org">Felix Project Team</a>
*/
public interface Nullable {
diff --git a/ipojo/src/main/java/org/apache/felix/ipojo/Pojo.java b/ipojo/src/main/java/org/apache/felix/ipojo/Pojo.java
index bf5d5d8..fb755aa 100644
--- a/ipojo/src/main/java/org/apache/felix/ipojo/Pojo.java
+++ b/ipojo/src/main/java/org/apache/felix/ipojo/Pojo.java
@@ -21,13 +21,15 @@
/**
* Interface implemented by each object created through an manipulated class.
* This interface allow to get the component instance from the object.
+ *
* @author <a href="mailto:felix-dev@incubator.apache.org">Felix Project Team</a>
*/
public interface Pojo {
-
- /**
- * @return the component instance who create this object.
- */
- ComponentInstance getComponentInstance();
+
+ /**
+ * Get the instance container which create the current object.
+ * @return the component instance who create this object.
+ */
+ ComponentInstance getComponentInstance();
}
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 24a4176..0f7acf2 100644
--- a/ipojo/src/main/java/org/apache/felix/ipojo/ServiceContext.java
+++ b/ipojo/src/main/java/org/apache/felix/ipojo/ServiceContext.java
@@ -26,88 +26,99 @@
import org.osgi.framework.ServiceRegistration;
/**
- * A service context give the access the a service registry.
- * All service interaction should use this service context.
+ * A service context give the access the a service registry. All service
+ * interaction should use this service context.
+ *
* @author <a href="mailto:felix-dev@incubator.apache.org">Felix Project Team</a>
*/
public interface ServiceContext {
-
- /**
- * @param listener
- * @param filter
- * @throws InvalidSyntaxException
- */
- void addServiceListener(ServiceListener listener, String filter) throws InvalidSyntaxException;
-
- /**
- * @param listener
- */
- void addServiceListener(ServiceListener listener);
-
- /**
- * @param clazz
- * @param filter
- * @return
- * @throws InvalidSyntaxException
- */
- ServiceReference[] getAllServiceReferences(String clazz, String filter) throws InvalidSyntaxException;
-
- /**
- * @param reference
- * @return
- */
- Object getService(ServiceReference reference);
-
- /**
- * @param clazz
- * @return
- */
- ServiceReference getServiceReference(String clazz);
-
- /**
- * @param clazz
- * @param filter
- * @return
- * @throws InvalidSyntaxException
- */
- ServiceReference[] getServiceReferences(String clazz, String filter) throws InvalidSyntaxException;
-
- /**
- * @param clazzes
- * @param service
- * @param properties
- * @return
- */
- ServiceRegistration registerService(String[] clazzes, Object service, Dictionary properties);
-
- /**
- * @param clazz
- * @param service
- * @param properties
- * @return
- */
- ServiceRegistration registerService(String clazz, Object service, Dictionary properties);
-
- /**
- * @param listener
- */
- void removeServiceListener(ServiceListener listener);
-
- /**
- * @param reference
- * @return
- */
- boolean ungetService(ServiceReference reference);
-
- /**
- * @return the component instance who use this service context.
- */
- ComponentInstance getComponentInstance();
-
- /**
- * Set the component instance using the service context.
- * @param ci
- */
- //void setComponentInstance(ComponentInstance ci);
+
+ /**
+ * Add a service listener.
+ * @param listener : the service lsitener to add.
+ * @param filter : the LDAP filter
+ * @throws InvalidSyntaxException : occurs when the LDAP filter is malformed
+ * @see org.osgi.framework.BundleContext#addServiceListener(org.osgi.framework.ServiceListener, java.lang.String)
+ */
+ void addServiceListener(ServiceListener listener, String filter) throws InvalidSyntaxException;
+
+ /**
+ * Add a service listener.
+ * @param listener : the service listener to add.
+ * @see org.osgi.framework.BundleContext#addServiceListener(org.osgi.framework.ServiceListener)
+ */
+ void addServiceListener(ServiceListener listener);
+
+ /**
+ * Get the service references matching with the given query.
+ * @param clazz : Required interface
+ * @param filter : LDAP filter
+ * @return the array of available service reference
+ * @throws InvalidSyntaxException : occurs if the LDAP filter is malformed
+ * @see org.osgi.framework.BundleContext#getAllServiceReferences(java.lang.String, java.lang.String)
+ */
+ ServiceReference[] getAllServiceReferences(String clazz, String filter) throws InvalidSyntaxException;
+
+ /**
+ * Get a service object.
+ * @param reference : the required service reference
+ * @return the service object or null if the service reference is no more valid or if the service object is not accessible
+ * @see org.osgi.framework.BundleContext#getService(org.osgi.framework.ServiceReference)
+ */
+ Object getService(ServiceReference reference);
+
+ /**
+ * Get a service reference for the given interface.
+ * @param clazz : the required interface name
+ * @return a service reference on a available provider or null if no provider available
+ * @see org.osgi.framework.BundleContext#getServiceReference(java.lang.String)
+ */
+ ServiceReference getServiceReference(String clazz);
+
+ /**
+ * Get service reference list for the given query.
+ * @param clazz : the name of the requried service interface
+ * @param filter : LDAP filter to apply on service provider
+ * @return : the array of consistent service reference or null if no available provider
+ * @throws InvalidSyntaxException : occrus if the LDAP filter is malformed
+ * @see org.osgi.framework.BundleContext#getServiceReferences(java.lang.String, java.lang.String)
+ */
+ ServiceReference[] getServiceReferences(String clazz, String filter) throws InvalidSyntaxException;
+
+ /**
+ * Register a service.
+ * @param clazzes : interfaces provided by the service.
+ * @param service : the service object.
+ * @param properties : service properties.
+ * @return the service registration for this service publication.
+ * @see org.apache.felix.ipojo.ServiceContext#registerService(java.lang.String[], java.lang.Object, java.util.Dictionary)
+ */
+ ServiceRegistration registerService(String[] clazzes, Object service, Dictionary properties);
+
+ /**
+ * Register a service.
+ * @param clazz : interface provided by the service.
+ * @param service : the service object.
+ * @param properties : service properties.
+ * @return the service registration for this service publication.
+ * @see org.osgi.framework.BundleContext#registerService(java.lang.String, java.lang.Object, java.util.Dictionary)
+ */
+ ServiceRegistration registerService(String clazz, Object service, Dictionary properties);
+
+ /**
+ * Remove a service listener.
+ * @param listener : the listener to remove
+ * @see org.osgi.framework.BundleContext#removeServiceListener(org.osgi.framework.ServiceListener)
+ */
+ void removeServiceListener(ServiceListener listener);
+
+ /**
+ * Unget the service reference.
+ * @param reference : the reference to unget
+ * @return true if you are the last user of the reference
+ * @see org.osgi.framework.BundleContext#ungetService(org.osgi.framework.ServiceReference)
+ */
+ boolean ungetService(ServiceReference reference);
+
}
diff --git a/ipojo/src/main/java/org/apache/felix/ipojo/UnacceptableConfiguration.java b/ipojo/src/main/java/org/apache/felix/ipojo/UnacceptableConfiguration.java
index 1084b8f..8ace316 100644
--- a/ipojo/src/main/java/org/apache/felix/ipojo/UnacceptableConfiguration.java
+++ b/ipojo/src/main/java/org/apache/felix/ipojo/UnacceptableConfiguration.java
@@ -1,19 +1,42 @@
+/*
+ * 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;
/**
- * UnacceptableConfiguration is throwed when a factory refuses to create an instance.
+ * UnacceptableConfiguration is throwed when a factory refuses to create an
+ * instance.
+ *
* @author <a href="mailto:felix-dev@incubator.apache.org">Felix Project Team</a>
*/
public class UnacceptableConfiguration extends Exception {
- /**
- *
- */
- private static final long serialVersionUID = 2998931848886223965L;
-
- /**
- * @param message : message indicating the error.
- */
- public UnacceptableConfiguration(String message) { super(message); }
+ /**
+ * Exception UID.
+ */
+ private static final long serialVersionUID = 2998931848886223965L;
+
+ /**
+ * Constructor.
+ * @param message : message indicating the error.
+ */
+ public UnacceptableConfiguration(String message) {
+ super(message);
+ }
}
diff --git a/ipojo/src/main/java/org/apache/felix/ipojo/architecture/ComponentDescription.java b/ipojo/src/main/java/org/apache/felix/ipojo/architecture/ComponentDescription.java
index a55db2c..6826c70 100644
--- a/ipojo/src/main/java/org/apache/felix/ipojo/architecture/ComponentDescription.java
+++ b/ipojo/src/main/java/org/apache/felix/ipojo/architecture/ComponentDescription.java
@@ -20,6 +20,7 @@
/**
* Component Type information.
+ *
* @author <a href="mailto:felix-dev@incubator.apache.org">Felix Project Team</a>
*/
public class ComponentDescription {
@@ -43,34 +44,38 @@
* Get the name of this component type.
*/
private String m_name;
-
+
/**
* Constructor.
- * @param name : name of the component type (factory name).
+ *
+ * @param name : name of the component type (factory name).
* @param className : implementation class.
*/
public ComponentDescription(String name, String className) {
- m_name = name;
- m_className = className;
+ m_name = name;
+ m_className = className;
}
-
+
/**
* Constructor for composite.
- * @param name : name of the component type (factory name).
+ *
+ * @param name : name of the component type (factory name).
*/
public ComponentDescription(String name) {
- m_name = name;
+ m_name = name;
}
-
+
/**
+ * Get a displayable form of the current component type description.
+ * @return displayable form of the component type description
* @see java.lang.Object#toString()
*/
public String toString() {
String res = "";
if (m_className == null) {
- res += "Component Type : " + m_name + " (Composition) \n";
+ res += "Component Type : " + m_name + " (Composition) \n";
} else {
- res += "Component Type : " + m_name + " (" + m_className + ") \n";
+ res += "Component Type : " + m_name + " (" + m_className + ") \n";
}
for (int i = 0; i < m_providedServiceSpecification.length; i++) {
res += "\tProvides : " + m_providedServiceSpecification[i] + "\n";
@@ -82,54 +87,66 @@
}
/**
+ * Get the implementation class of this component type.
* @return the component type implementation class name.
*/
- public String getClassName() { return m_className; }
+ public String getClassName() {
+ return m_className;
+ }
/**
- * @return the list of configuration properties accepted by the component type.
+ * Get component-type properties.
+ * @return the list of configuration properties accepted by the component type
+ * type.
*/
- public PropertyDescription[] getProperties() { return m_properties; }
+ public PropertyDescription[] getProperties() {
+ return m_properties;
+ }
/**
* Add a configuration properties to the component type.
+ *
* @param pd : the property to add
*/
- public void addProperty(PropertyDescription pd) {
- for (int i = 0; i < m_properties.length; i++) {
- if (m_properties[i].getName().equals(pd.getName())) { return; }
- }
-
- PropertyDescription[] newProps = new PropertyDescription[m_properties.length + 1];
+ public void addProperty(PropertyDescription pd) {
+ for (int i = 0; i < m_properties.length; i++) {
+ if (m_properties[i].getName().equals(pd.getName())) {
+ return;
+ }
+ }
+
+ PropertyDescription[] newProps = new PropertyDescription[m_properties.length + 1];
System.arraycopy(m_properties, 0, newProps, 0, m_properties.length);
newProps[m_properties.length] = pd;
m_properties = newProps;
}
/**
+ * Get the list of provided service offered by instances of this type.
* @return the list of the provided service.
*/
- public String[] getprovidedServiceSpecification() { return m_providedServiceSpecification; }
+ public String[] getprovidedServiceSpecification() {
+ return m_providedServiceSpecification;
+ }
/**
- * add a provided service to the component type.
- * @param serviceSpecification : the provided service to add (interface name)
+ * Add a provided service to the component type.
+ * @param serviceSpecification : the provided service to add (interface
+ * name)
*/
- public void addProvidedServiceSpecification(String serviceSpecification) {
+ public void addProvidedServiceSpecification(String serviceSpecification) {
String[] newSs = new String[m_providedServiceSpecification.length + 1];
System.arraycopy(m_providedServiceSpecification, 0, newSs, 0, m_providedServiceSpecification.length);
newSs[m_providedServiceSpecification.length] = serviceSpecification;
m_providedServiceSpecification = newSs;
}
-
+
/**
+ * Return the component-type name.
* @return the name of this component type
*/
- public String getName() { return m_name; }
-
-
-
-
-
+ public String getName() {
+ return m_name;
+ }
}
diff --git a/ipojo/src/main/java/org/apache/felix/ipojo/architecture/HandlerDescription.java b/ipojo/src/main/java/org/apache/felix/ipojo/architecture/HandlerDescription.java
index 6997099..093e528 100644
--- a/ipojo/src/main/java/org/apache/felix/ipojo/architecture/HandlerDescription.java
+++ b/ipojo/src/main/java/org/apache/felix/ipojo/architecture/HandlerDescription.java
@@ -18,14 +18,16 @@
*/
package org.apache.felix.ipojo.architecture;
+import org.apache.felix.ipojo.metadata.Attribute;
+import org.apache.felix.ipojo.metadata.Element;
/**
* Handler Description.
+ *
* @author <a href="mailto:felix-dev@incubator.apache.org">Felix Project Team</a>
*/
public class HandlerDescription {
-
/**
* Handler Class Name (i.e namespace).
*/
@@ -36,9 +38,9 @@
*/
private boolean m_isValid;
-
/**
* Constructor.
+ *
* @param name : handler name
* @param isValid : is the handler valid
*/
@@ -48,18 +50,34 @@
}
/**
+ * Check if the handler is valid.
* @return true if the handler is valid.
*/
- public boolean isValid() { return m_isValid; }
+ public boolean isValid() {
+ return m_isValid;
+ }
/**
+ * Get the handler name.
* @return the handler name (i.e. namespace).
*/
- public String getHandlerName() { return m_handlerName; }
+ public String getHandlerName() {
+ return m_handlerName;
+ }
/**
+ * Get handler information.
* @return the handler information.
*/
- public String getHandlerInfo() { return ""; };
+ public Element getHandlerInfo() {
+ Element elem = new Element("Handler", "");
+ elem.addAttribute(new Attribute("name", m_handlerName));
+ if (m_isValid) {
+ elem.addAttribute(new Attribute("state", "valid"));
+ } else {
+ elem.addAttribute(new Attribute("state", "invalid"));
+ }
+ return elem;
+ }
}
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
index 39b7b6b..2e6c55d 100644
--- a/ipojo/src/main/java/org/apache/felix/ipojo/architecture/InstanceDescription.java
+++ b/ipojo/src/main/java/org/apache/felix/ipojo/architecture/InstanceDescription.java
@@ -18,8 +18,13 @@
*/
package org.apache.felix.ipojo.architecture;
+import org.apache.felix.ipojo.ComponentInstance;
+import org.apache.felix.ipojo.metadata.Attribute;
+import org.apache.felix.ipojo.metadata.Element;
+
/**
* Instance Description.
+ *
* @author <a href="mailto:felix-dev@incubator.apache.org">Felix Project Team</a>
*/
public class InstanceDescription {
@@ -48,12 +53,12 @@
* BundleId who create the instance.
*/
private long m_bundleId;
-
+
/**
* Component Type of the instance.
*/
private ComponentDescription m_type;
-
+
/**
* COntained instance list.
*/
@@ -61,6 +66,7 @@
/**
* Constructor.
+ *
* @param name : the name of the component instance.
* @param state : the state of the instance.
* @param bundleId : bundle id owning this instance.
@@ -77,29 +83,44 @@
}
/**
- * @return the name of the component.
+ * Get the instance name.
+ * @return the name of the instance.
*/
- public String getName() { return m_name; }
+ public String getName() {
+ return m_name;
+ }
/**
+ * Get the list of object created by the described instance.
* @return the created instances
*/
- public String[] getCreatedObjects() { return m_createdObjects; }
+ public String[] getCreatedObjects() {
+ return m_createdObjects;
+ }
/**
- * Set the instances array.
+ * Set the array of objects created by the described instance.
+ * @param objects : the list of create objects.
*/
- public void setCreatedObjects(String[] objects) { m_createdObjects = objects; }
+ public void setCreatedObjects(String[] objects) {
+ m_createdObjects = objects;
+ }
/**
+ * Get the component type description of the described instance.
* @return : the component type description of this instance.
*/
- public ComponentDescription getComponentDescription() { return m_type; }
+ public ComponentDescription getComponentDescription() {
+ return m_type;
+ }
/**
+ * Get the plugged handler list.
* @return the live handler list
*/
- public HandlerDescription[] getHandlers() { return m_handlers; }
+ public HandlerDescription[] getHandlers() {
+ return m_handlers;
+ }
/**
* Add an handler description to the list.
@@ -107,27 +128,30 @@
*/
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++) {
+ 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
+ return; // NOTHING TO DO, the description is already in the
+ // array
}
}
- // The component Description is not in the array, add it
+ // 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;
}
-
+
/**
* Add an instance description to the contained instance list.
+ *
* @param inst : the handler description to add
*/
public void addInstance(InstanceDescription inst) {
// Verify that the dependency description is not already in the array.
- for (int i = 0; (i < m_containedInstances.length); i++) {
+ for (int i = 0; i < m_containedInstances.length; i++) {
if (m_containedInstances[i] == inst) {
- return; //NOTHING TO DO, the description is already in the array
+ return; // NOTHING TO DO, the description is already in the
+ // array
}
}
// The component Description is not in the array, add it
@@ -139,24 +163,79 @@
/**
* Set the state of the component.
+ *
* @param i : the state
*/
- public void setState(int i) { m_state = i; }
+ public void setState(int i) {
+ m_state = i;
+ }
/**
- * @return the state of the component.
+ * Get the state of the described instance.
+ * @return the state of the instance.
*/
- public int getState() { return m_state; }
+ public int getState() {
+ return m_state;
+ }
/**
+ * Get the bundle id of the bundle containing the described instance.
* @return the bundle id owning the component implementation class.
*/
- public long getBundleId() { return m_bundleId; }
-
+ public long getBundleId() {
+ return m_bundleId;
+ }
+
/**
+ * Get the list of contained instance in the describe instance.
+ * This list contains only instances who exposed their architecture.
* @return the list of contained instances.
*/
- public InstanceDescription[] getContainedInstances() { return m_containedInstances; }
+ public InstanceDescription[] getContainedInstances() {
+ return m_containedInstances;
+ }
+ /**
+ * Get the instance description.
+ * @return the instance description
+ */
+ public Element getDescription() {
+ Element instance = new Element("Instance", "");
+ instance.addAttribute(new Attribute("name", getName())); // Name
+ // State
+ if (m_state == ComponentInstance.STOPPED) {
+ instance.addAttribute(new Attribute("state", "stopped"));
+ }
+ if (m_state == ComponentInstance.VALID) {
+ instance.addAttribute(new Attribute("state", "valid"));
+ }
+ if (m_state == ComponentInstance.INVALID) {
+ instance.addAttribute(new Attribute("state", "invalid"));
+ }
+ // Bundle
+ instance.addAttribute(new Attribute("bundle", "" + m_bundleId));
+
+ // Component Type
+ instance.addAttribute(new Attribute("component.type", m_type.getName()));
+
+ // Handlers
+ for (int i = 0; i < m_handlers.length; i++) {
+ instance.addElement(m_handlers[i].getHandlerInfo());
+ }
+ // Created Object (empty is composite)
+ for (int i = 0; i < m_createdObjects.length; i++) {
+ Element obj = new Element("Object", "");
+ obj.addAttribute(new Attribute("name", ((Object) m_createdObjects[i]).toString()));
+ instance.addElement(obj);
+ }
+ // Contained instance (exposing architecture) (empty if primitive)
+ for (int i = 0; i < m_containedInstances.length; i++) {
+ Element inst = new Element("ContainedInstances", "");
+ inst.addElement(m_containedInstances[i].getDescription());
+ instance.addElement(inst);
+ }
+ return instance;
+
+ }
}
diff --git a/ipojo/src/main/java/org/apache/felix/ipojo/architecture/PropertyDescription.java b/ipojo/src/main/java/org/apache/felix/ipojo/architecture/PropertyDescription.java
index bb52d9a..dfdc3c5 100644
--- a/ipojo/src/main/java/org/apache/felix/ipojo/architecture/PropertyDescription.java
+++ b/ipojo/src/main/java/org/apache/felix/ipojo/architecture/PropertyDescription.java
@@ -20,6 +20,7 @@
/**
* Property Information.
+ *
* @author <a href="mailto:felix-dev@incubator.apache.org">Felix Project Team</a>
*/
public class PropertyDescription {
@@ -41,6 +42,7 @@
/**
* Constructor.
+ *
* @param name : name of the property
* @param type : type of the property
* @param value : default value of the property
@@ -52,28 +54,39 @@
}
/**
+ * Get the current property name.
* @return the property name.
*/
- public String getName() { return m_name; }
-
+ public String getName() {
+ return m_name;
+ }
+
/**
+ * Get the current property type.
* @return the property type.
*/
- public String getType() { return m_type; }
+ public String getType() {
+ return m_type;
+ }
/**
+ * Get the current property value.
* @return the default value for the property.
*/
- public String getValue() { return m_value; }
+ public String getValue() {
+ return m_value;
+ }
/**
+ * Get a displayed form of the current property.
+ * @return : a String representing this property.
* @see java.lang.Object#toString()
*/
public String toString() {
- if (m_value != null) {
- return getName() + " - " + getType() + " - " + getValue();
- } else {
- return getName() + " - " + getType() + " - REQUIRED";
+ if (m_value != null) {
+ return getName() + " - " + getType() + " - " + getValue();
+ } else {
+ return getName() + " - " + getType() + " - REQUIRED";
}
}
diff --git a/ipojo/src/main/java/org/apache/felix/ipojo/composite/CompositeServiceContext.java b/ipojo/src/main/java/org/apache/felix/ipojo/composite/CompositeServiceContext.java
index 5f4bb40..1eec9bf 100644
--- a/ipojo/src/main/java/org/apache/felix/ipojo/composite/CompositeServiceContext.java
+++ b/ipojo/src/main/java/org/apache/felix/ipojo/composite/CompositeServiceContext.java
@@ -35,233 +35,293 @@
import org.osgi.framework.ServiceRegistration;
/**
- * CompositeServiceContext Class.
- * This class provides an implementation of the service context for composite.
+ * CompositeServiceContext Class. This class provides an implementation of the
+ * service context for composite.
+ *
* @author <a href="mailto:felix-dev@incubator.apache.org">Felix Project Team</a>
*/
public class CompositeServiceContext implements ServiceContext, ServiceListener {
-
- private class Record {
- private ServiceReference m_ref;
- private ServiceRegistration m_reg;
- private FactoryProxy m_fact;
- }
-
- private List m_factories = new ArrayList();
-
- private BundleContext m_parent;
-
- /**
- * Internal service registry.
- */
- private ServiceRegistry m_registry;
-
- /**
- * Component Instance who creates this registry.
- */
- private ComponentInstance m_instance;
-
- /**
- * Constructor.
- * This constructor instantiate a service registry with the given bundle context.
- * @param bc : the bundle context
- */
- public CompositeServiceContext(BundleContext bc) {
- m_registry = new ServiceRegistry(bc);
- m_parent = bc;
- }
-
- /**
- * Constructor.
- * @param bc : the bundle context
- * @param ci : the component instance owning this context
- */
- public CompositeServiceContext(BundleContext bc, ComponentInstance ci) {
- this(bc);
- m_parent = bc;
- m_instance = ci;
- }
- /**
- * @see org.apache.felix.ipojo.ServiceContext#addServiceListener(org.osgi.framework.ServiceListener)
- */
- public void addServiceListener(ServiceListener arg0) {
- m_registry.addServiceListener(arg0);
- }
+ /**
+ * Structure stoing the referense, the factory and the registration.
+ */
+ private class Record {
+ /**
+ * Reference of the proxed factory from the external context.
+ */
+ private ServiceReference m_ref;
+ /**
+ * Registration of the factory in the internal context.
+ */
+ private ServiceRegistration m_reg;
+ /**
+ * Proxed Factory.
+ */
+ private FactoryProxy m_fact;
+ }
- /**
- * @see org.apache.felix.ipojo.ServiceContext#addServiceListener(org.osgi.framework.ServiceListener, java.lang.String)
- */
- public void addServiceListener(ServiceListener arg0, String arg1) throws InvalidSyntaxException {
- m_registry.addServiceListener(arg0, arg1);
- }
+ /**
+ * List of imported factories.
+ */
+ private List m_factories = new ArrayList();
- /**
- * @see org.apache.felix.ipojo.ServiceContext#getAllServiceReferences(java.lang.String, java.lang.String)
- */
- public ServiceReference[] getAllServiceReferences(String arg0, String arg1) throws InvalidSyntaxException {
- return m_registry.getAllServiceReferences(arg0, arg1);
- }
+ /**
+ * External context.
+ */
+ private BundleContext m_parent;
- /**
- * @see org.apache.felix.ipojo.ServiceContext#getComponentInstance()
- */
- public ComponentInstance getComponentInstance() {
- return m_instance;
- }
+ /**
+ * Internal service registry.
+ */
+ private ServiceRegistry m_registry;
- /**
- * @see org.apache.felix.ipojo.ServiceContext#getService(org.osgi.framework.ServiceReference)
- */
- public Object getService(ServiceReference arg0) {
- return m_registry.getService(m_instance, arg0);
- }
+ /**
+ * Component Instance who creates this registry.
+ */
+ private ComponentInstance m_instance;
- /**
- * @see org.apache.felix.ipojo.ServiceContext#getServiceReference(java.lang.String)
- */
- public ServiceReference getServiceReference(String arg0) {
- return m_registry.getServiceReference(arg0);
- }
+ /**
+ * Constructor. This constructor instantiate a service registry with the
+ * given bundle context.
+ *
+ * @param bc : the bundle context
+ */
+ public CompositeServiceContext(BundleContext bc) {
+ m_registry = new ServiceRegistry(bc);
+ m_parent = bc;
+ }
- /**
- * @see org.apache.felix.ipojo.ServiceContext#getServiceReferences(java.lang.String, java.lang.String)
- */
- public ServiceReference[] getServiceReferences(String clazz, String filter) throws InvalidSyntaxException {
- return m_registry.getServiceReferences(clazz, filter);
- }
+ /**
+ * Constructor.
+ *
+ * @param bc : the bundle context
+ * @param ci : the component instance owning this context
+ */
+ public CompositeServiceContext(BundleContext bc, ComponentInstance ci) {
+ this(bc);
+ m_parent = bc;
+ m_instance = ci;
+ }
- /**
- * @see org.apache.felix.ipojo.ServiceContext#registerService(java.lang.String[], java.lang.Object, java.util.Dictionary)
- */
- public ServiceRegistration registerService(String[] arg0, Object arg1, Dictionary arg2) {
- return m_registry.registerService(m_instance, arg0, arg1, arg2);
- }
+ /**
+ * Add a service listener.
+ * @param arg0 : The service listener to add
+ * @see org.apache.felix.ipojo.ServiceContext#addServiceListener(org.osgi.framework.ServiceListener)
+ */
+ public void addServiceListener(ServiceListener arg0) {
+ m_registry.addServiceListener(arg0);
+ }
- /**
- * @see org.apache.felix.ipojo.ServiceContext#registerService(java.lang.String, java.lang.Object, java.util.Dictionary)
- */
- public ServiceRegistration registerService(String arg0, Object arg1, Dictionary arg2) {
- return m_registry.registerService(m_instance, arg0, arg1, arg2);
- }
+ /**
+ * Add a filtered service listener.
+ * @param arg0 : the service listner object to add
+ * @param arg1 : the LDAP filter for this listener
+ * @throws InvalidSyntaxException : throwed if the LDAP filter is malformed
+ * @see org.apache.felix.ipojo.ServiceContext#addServiceListener(org.osgi.framework.ServiceListener,
+ * java.lang.String)
+ */
+ public void addServiceListener(ServiceListener arg0, String arg1) throws InvalidSyntaxException {
+ m_registry.addServiceListener(arg0, arg1);
+ }
- /**
- * @see org.apache.felix.ipojo.ServiceContext#removeServiceListener(org.osgi.framework.ServiceListener)
- */
- public void removeServiceListener(ServiceListener arg0) {
- m_registry.removeServiceListener(arg0);
- }
+ /**
+ * Get all service references.
+ * @param arg0 : The requried service interface.
+ * @param arg1 : LDAP filter
+ * @return the list of all service reference matching with the query
+ * @throws InvalidSyntaxException : occurs when the given filter is malformed
+ * @see org.apache.felix.ipojo.ServiceContext#getAllServiceReferences(java.lang.String,
+ * java.lang.String)
+ */
+ public ServiceReference[] getAllServiceReferences(String arg0, String arg1) throws InvalidSyntaxException {
+ return m_registry.getAllServiceReferences(arg0, arg1);
+ }
- /**
- * @see org.apache.felix.ipojo.ServiceContext#ungetService(org.osgi.framework.ServiceReference)
- */
- public boolean ungetService(ServiceReference arg0) {
- return m_registry.ungetService(m_instance, arg0);
- }
-
- /**
- * Initiate the factory list.
- */
- private void importFactories() {
- try {
- ServiceReference[] refs = m_parent.getServiceReferences(Factory.class.getName(), null);
- if (refs != null) {
- for (int i = 0; i < refs.length; i++) {
- importFactory(refs[i]);
- }
- }
- } catch (InvalidSyntaxException e) {
- e.printStackTrace(); // Should not happen
- }
- }
-
- /**
- * Import a factory form the parent to the internal registry.
- * @param ref : the reference of the factory to import.
- */
- private void importFactory(ServiceReference ref) {
- //System.out.println("Add a new factory in the scope : " + ref.getProperty(Constants.SERVICE_PID));
- Record rec = new Record();
- m_factories.add(rec);
- Dictionary dict = new Properties();
- for (int j = 0; j < ref.getPropertyKeys().length; j++) {
- dict.put(ref.getPropertyKeys()[j], ref.getProperty(ref.getPropertyKeys()[j]));
- }
- rec.m_fact = new FactoryProxy((Factory) m_parent.getService(ref), this);
- rec.m_reg = registerService(Factory.class.getName(), rec.m_fact, dict);
- rec.m_ref = ref;
- }
-
- /**
- * Remove a factory of the available factory list.
- * @param ref : the reference on the factory to remove.
- */
- private void removeFactory(ServiceReference ref) {
- //System.out.println("Remove a factory from the scope : " + ref.getProperty(Constants.SERVICE_PID));
- for (int i = 0; i < m_factories.size(); i++) {
- Record rec = (Record) m_factories.get(i);
- if (rec.m_ref == ref) {
- rec.m_reg.unregister();
- rec.m_fact = null;
- m_parent.ungetService(rec.m_ref);
- m_factories.remove(rec);
- return;
- }
- }
- }
-
- /**
- * Start the registry management.
- */
- public void start() {
- importFactories();
- try {
- m_parent.addServiceListener(this, "(" + Constants.OBJECTCLASS + "=" + Factory.class.getName() + ")");
- } catch (InvalidSyntaxException e) {
- // Should not happen
- e.printStackTrace();
- }
- }
+ /**
+ * Get a service object for the given service reference.
+ * @param arg0 : the service reference
+ * @return the service object or null if the reference is no more valid or if the object is not accessible
+ * @see org.apache.felix.ipojo.ServiceContext#getService(org.osgi.framework.ServiceReference)
+ */
+ public Object getService(ServiceReference arg0) {
+ return m_registry.getService(m_instance, arg0);
+ }
- /**
- * Stop the registry management.
- */
- public synchronized void stop() {
- m_parent.removeServiceListener(this);
- m_registry.reset();
- for (int i = 0; i < m_factories.size(); i++) {
- Record rec = (Record) m_factories.get(i);
- removeFactory(rec.m_ref);
- }
- }
-
- /**
- * @see org.osgi.framework.ServiceListener#serviceChanged(org.osgi.framework.ServiceEvent)
- */
- public void serviceChanged(ServiceEvent event) {
- if (event.getType() == ServiceEvent.REGISTERED) {
- if (!containsRef(event.getServiceReference())) {
- importFactory(event.getServiceReference());
- }
- return;
- }
- if (event.getType() == ServiceEvent.UNREGISTERING) {
- if (containsRef(event.getServiceReference())) {
- removeFactory(event.getServiceReference());
- }
- }
- }
-
- /**
- * Check if the factory list contain the given reference.
- * @param ref : the reference to find.
- * @return true if the list contains the given reference.
- */
- private boolean containsRef(ServiceReference ref) {
- for (int i = 0; i < m_factories.size(); i++) {
- Record rec = (Record) m_factories.get(i);
- if (rec.m_ref == ref) { return true; }
- }
- return false;
- }
+
+ /**
+ * Get a service reference for the required interface.
+ * @param arg0 : the requried interface name
+ * @return the service reference or null if no available provider
+ * @see org.apache.felix.ipojo.ServiceContext#getServiceReference(java.lang.String)
+ */
+ public ServiceReference getServiceReference(String arg0) {
+ return m_registry.getServiceReference(arg0);
+ }
+
+ /**
+ * Get all accessible service reference for the given query.
+ * @param clazz : required interface
+ * @param filter : LDAP filter
+ * @return the list (array) of service reference matching with the query.
+ * @throws InvalidSyntaxException : occurs when the LDAP filter is malformed
+ * @see org.apache.felix.ipojo.ServiceContext#getServiceReferences(java.lang.String, java.lang.String)
+ */
+ public ServiceReference[] getServiceReferences(String clazz, String filter) throws InvalidSyntaxException {
+ return m_registry.getServiceReferences(clazz, filter);
+ }
+
+
+ /**
+ * Register a service inside the composite context.
+ * @param arg0 : list of interfaces to register.
+ * @param arg1 : service object
+ * @param arg2 : properties list
+ * @return the service registration
+ * @see org.apache.felix.ipojo.ServiceContext#registerService(java.lang.String[], java.lang.Object, java.util.Dictionary)
+ */
+ public ServiceRegistration registerService(String[] arg0, Object arg1, Dictionary arg2) {
+ return m_registry.registerService(m_instance, arg0, arg1, arg2);
+ }
+
+ /**
+ * Register a service inside the composite context.
+ * @param arg0 : interface to register.
+ * @param arg1 : service object
+ * @param arg2 : properties list
+ * @return the service registration
+ * @see org.apache.felix.ipojo.ServiceContext#registerService(java.lang.String, java.lang.Object, java.util.Dictionary)
+ */
+ public ServiceRegistration registerService(String arg0, Object arg1, Dictionary arg2) {
+ return m_registry.registerService(m_instance, arg0, arg1, arg2);
+ }
+
+ /**
+ * Remove a service listener.
+ * @param arg0 : the service listener to remove
+ * @see org.apache.felix.ipojo.ServiceContext#removeServiceListener(org.osgi.framework.ServiceListener)
+ */
+ public void removeServiceListener(ServiceListener arg0) {
+ m_registry.removeServiceListener(arg0);
+ }
+
+ /**
+ * Unget a service.
+ * @param arg0 the service reference to unget
+ * @return true
+ * @see org.apache.felix.ipojo.ServiceContext#ungetService(org.osgi.framework.ServiceReference)
+ */
+ public boolean ungetService(ServiceReference arg0) {
+ return m_registry.ungetService(m_instance, arg0);
+ }
+
+ /**
+ * Initiate the factory list.
+ */
+ private void importFactories() {
+ try {
+ ServiceReference[] refs = m_parent.getServiceReferences(Factory.class.getName(), null);
+ if (refs != null) {
+ for (int i = 0; i < refs.length; i++) {
+ importFactory(refs[i]);
+ }
+ }
+ } catch (InvalidSyntaxException e) {
+ e.printStackTrace(); // Should not happen
+ }
+ }
+
+ /**
+ * Import a factory form the parent to the internal registry.
+ *
+ * @param ref : the reference of the factory to import.
+ */
+ private void importFactory(ServiceReference ref) {
+ Record rec = new Record();
+ m_factories.add(rec);
+ Dictionary dict = new Properties();
+ for (int j = 0; j < ref.getPropertyKeys().length; j++) {
+ dict.put(ref.getPropertyKeys()[j], ref.getProperty(ref.getPropertyKeys()[j]));
+ }
+ rec.m_fact = new FactoryProxy((Factory) m_parent.getService(ref), this);
+ rec.m_reg = registerService(Factory.class.getName(), rec.m_fact, dict);
+ rec.m_ref = ref;
+ }
+
+ /**
+ * Remove a factory of the available factory list.
+ *
+ * @param ref : the reference on the factory to remove.
+ */
+ private void removeFactory(ServiceReference ref) {
+ for (int i = 0; i < m_factories.size(); i++) {
+ Record rec = (Record) m_factories.get(i);
+ if (rec.m_ref == ref) {
+ rec.m_reg.unregister();
+ rec.m_fact = null;
+ m_parent.ungetService(rec.m_ref);
+ m_factories.remove(rec);
+ return;
+ }
+ }
+ }
+
+ /**
+ * Start the registry management.
+ */
+ public void start() {
+ importFactories();
+ try {
+ m_parent.addServiceListener(this, "(" + Constants.OBJECTCLASS + "=" + Factory.class.getName() + ")");
+ } catch (InvalidSyntaxException e) {
+ // Should not happen
+ e.printStackTrace();
+ }
+ }
+
+ /**
+ * Stop the registry management.
+ */
+ public synchronized void stop() {
+ m_parent.removeServiceListener(this);
+ m_registry.reset();
+ for (int i = 0; i < m_factories.size(); i++) {
+ Record rec = (Record) m_factories.get(i);
+ removeFactory(rec.m_ref);
+ }
+ }
+
+ /**
+ * Service Listener implementation.
+ * @param event : the service event
+ * @see org.osgi.framework.ServiceListener#serviceChanged(org.osgi.framework.ServiceEvent)
+ */
+ public void serviceChanged(ServiceEvent event) {
+ if (event.getType() == ServiceEvent.REGISTERED) {
+ if (!containsRef(event.getServiceReference())) {
+ importFactory(event.getServiceReference());
+ }
+ return;
+ }
+ if (event.getType() == ServiceEvent.UNREGISTERING) {
+ if (containsRef(event.getServiceReference())) {
+ removeFactory(event.getServiceReference());
+ }
+ }
+ }
+
+ /**
+ * Check if the factory list contain the given reference.
+ *
+ * @param ref : the reference to find.
+ * @return true if the list contains the given reference.
+ */
+ private boolean containsRef(ServiceReference ref) {
+ for (int i = 0; i < m_factories.size(); i++) {
+ Record rec = (Record) m_factories.get(i);
+ if (rec.m_ref == ref) {
+ return true;
+ }
+ }
+ return false;
+ }
}
diff --git a/ipojo/src/main/java/org/apache/felix/ipojo/composite/FactoryProxy.java b/ipojo/src/main/java/org/apache/felix/ipojo/composite/FactoryProxy.java
index 0244ae9..ffc5c14 100644
--- a/ipojo/src/main/java/org/apache/felix/ipojo/composite/FactoryProxy.java
+++ b/ipojo/src/main/java/org/apache/felix/ipojo/composite/FactoryProxy.java
@@ -28,55 +28,102 @@
/**
* Bridge representing a Factory inside a composition.
+ *
* @author <a href="mailto:felix-dev@incubator.apache.org">Felix Project Team</a>
*/
public class FactoryProxy implements Factory {
-
- private Factory m_delegate;
- private ServiceContext m_context;
-
- /**
- * Constructor.
- * @param fact : the targetted factory.
- * @param s : the service context to target.
- */
- public FactoryProxy(Factory fact, ServiceContext s) {
- m_delegate = fact;
- m_context = s;
- }
- /**
- * @see org.apache.felix.ipojo.Factory#createComponentInstance(java.util.Dictionary)
- */
- public ComponentInstance createComponentInstance(Dictionary configuration) throws UnacceptableConfiguration {
- return m_delegate.createComponentInstance(configuration, m_context);
- }
+ /**
+ * Delegated factory.
+ */
+ private Factory m_delegate;
- /**
- * @see org.apache.felix.ipojo.Factory#createComponentInstance(java.util.Dictionary, org.apache.felix.ipojo.ServiceContext)
- */
- public ComponentInstance createComponentInstance(Dictionary configuration, ServiceContext serviceContext) throws UnacceptableConfiguration {
- return m_delegate.createComponentInstance(configuration, serviceContext);
- }
+ /**
+ * Destination context.
+ */
+ private ServiceContext m_context;
- /**
- * @see org.apache.felix.ipojo.Factory#getComponentDescription()
- */
- public ComponentDescription getComponentDescription() { return m_delegate.getComponentDescription(); }
+ /**
+ * Constructor.
+ *
+ * @param fact : the targetted factory.
+ * @param s : the service context to target.
+ */
+ public FactoryProxy(Factory fact, ServiceContext s) {
+ m_delegate = fact;
+ m_context = s;
+ }
- /**
- * @see org.apache.felix.ipojo.Factory#getName()
- */
- public String getName() { return m_delegate.getName(); }
+ /**
+ * Create an instance manager (i.e. component type instance).
+ *
+ * @param configuration : the configuration properties for this component.
+ * @return the created instance manager.
+ * @throws UnacceptableConfiguration : when a given configuration is not valid.
+ * @see org.apache.felix.ipojo.Factory#createComponentInstance(java.util.Dictionary)
+ */
+ public ComponentInstance createComponentInstance(Dictionary configuration) throws UnacceptableConfiguration {
+ return m_delegate.createComponentInstance(configuration, m_context);
+ }
- /**
- * @see org.apache.felix.ipojo.Factory#isAcceptable(java.util.Dictionary)
- */
- public boolean isAcceptable(Dictionary conf) { return m_delegate.isAcceptable(conf); }
+ /**
+ * 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 instance manager.
+ * @throws UnacceptableConfiguration : when the given configuration isnot valid.
+ * @see org.apache.felix.ipojo.Factory#createComponentInstance(java.util.Dictionary,
+ * org.apache.felix.ipojo.ServiceContext)
+ */
+ public ComponentInstance createComponentInstance(Dictionary configuration, ServiceContext serviceContext) throws UnacceptableConfiguration {
+ return m_delegate.createComponentInstance(configuration, serviceContext);
+ }
- /**
- * @see org.apache.felix.ipojo.Factory#reconfigure(java.util.Dictionary)
- */
- public void reconfigure(Dictionary conf) throws UnacceptableConfiguration { m_delegate.reconfigure(conf); }
+ /**
+ * Get the component type information containing provided service,
+ * configuration properties ...
+ *
+ * @return the component type information.
+ * @see org.apache.felix.ipojo.Factory#getComponentDescription()
+ */
+ public ComponentDescription getComponentDescription() {
+ return m_delegate.getComponentDescription();
+ }
+
+ /**
+ * Return the factory name.
+ * @return the name of the factory.
+ * @see org.apache.felix.ipojo.Factory#getName()
+ */
+ public String getName() {
+ return m_delegate.getName();
+ }
+
+ /**
+ * Check if the given configuration is acceptable as a configuration of a
+ * component instance.
+ *
+ * @param conf : the configuration to test
+ * @return true if the configuration is acceptable
+ * @see org.apache.felix.ipojo.Factory#isAcceptable(java.util.Dictionary)
+ */
+ public boolean isAcceptable(Dictionary conf) {
+ return m_delegate.isAcceptable(conf);
+ }
+
+ /**
+ * Reconfigure an instance already created. This configuration need to have
+ * the name property to identify the instance.
+ *
+ * @param conf : the configuration to reconfigure the instance.
+ * @throws UnacceptableConfiguration : if the given configuration is not
+ * consistent for the tragetted instance.
+ * @see org.apache.felix.ipojo.Factory#reconfigure(java.util.Dictionary)
+ */
+ public void reconfigure(Dictionary conf) throws UnacceptableConfiguration {
+ m_delegate.reconfigure(conf);
+ }
}
diff --git a/ipojo/src/main/java/org/apache/felix/ipojo/composite/ServiceReferenceImpl.java b/ipojo/src/main/java/org/apache/felix/ipojo/composite/ServiceReferenceImpl.java
index ae2f1aa..9238292 100644
--- a/ipojo/src/main/java/org/apache/felix/ipojo/composite/ServiceReferenceImpl.java
+++ b/ipojo/src/main/java/org/apache/felix/ipojo/composite/ServiceReferenceImpl.java
@@ -18,70 +18,89 @@
*/
package org.apache.felix.ipojo.composite;
-
import org.apache.felix.ipojo.ComponentInstance;
import org.osgi.framework.Bundle;
import org.osgi.framework.ServiceReference;
/**
- * Internal service reference implemenation.
- * This class is used for in the composition.
+ * Internal service reference implemenation. This class is used for in the
+ * composition.
+ *
* @author <a href="mailto:felix-dev@incubator.apache.org">Felix Project Team</a>
*/
public class ServiceReferenceImpl implements ServiceReference {
-
- /**
- * Service Registration attached to the service reference.
- */
- private ServiceRegistrationImpl m_registration = null;
-
- /**
- * Constructor.
- * @param cm : component instance publishing the service.
- * @param sr : registration attached to this service reference.
- */
- public ServiceReferenceImpl(ComponentInstance cm, ServiceRegistrationImpl sr) { m_registration = sr; }
- /**
- * Not supported in composite.
- * @see org.osgi.framework.ServiceReference#getBundle()
- */
- public Bundle getBundle() {
- throw new UnsupportedOperationException("getUsingBundles is not supported in scope");
- }
-
- /**
- * @return the service registration for this service reference.
- */
- public ServiceRegistrationImpl getServiceRegistration() { return m_registration; }
+ /**
+ * Service Registration attached to the service reference.
+ */
+ private ServiceRegistrationImpl m_registration = null;
- /**
- * @see org.osgi.framework.ServiceReference#getProperty(java.lang.String)
- */
- public Object getProperty(String s) {
- return m_registration.getProperty(s);
- }
+ /**
+ * Constructor.
+ *
+ * @param cm : component instance publishing the service.
+ * @param sr : registration attached to this service reference.
+ */
+ public ServiceReferenceImpl(ComponentInstance cm, ServiceRegistrationImpl sr) {
+ m_registration = sr;
+ }
- /**
- * @see org.osgi.framework.ServiceReference#getPropertyKeys()
- */
- public String[] getPropertyKeys() {
- return m_registration.getPropertyKeys();
- }
+ /**
+ * Not supported in composite.
+ * @return null
+ * @see org.osgi.framework.ServiceReference#getBundle()
+ */
+ public Bundle getBundle() {
+ throw new UnsupportedOperationException("getUsingBundles is not supported in scope");
+ }
- /**
- * Not supported in composite.
- * @see org.osgi.framework.ServiceReference#getUsingBundles()
- */
- public Bundle[] getUsingBundles() {
- throw new UnsupportedOperationException("getUsingBundles is not supported in scope");
- }
+ /**
+ * Get the service registration for this reference.
+ * @return the service registration for this service reference.
+ */
+ public ServiceRegistrationImpl getServiceRegistration() {
+ return m_registration;
+ }
- /**
- * @see org.osgi.framework.ServiceReference#isAssignableTo(org.osgi.framework.Bundle, java.lang.String)
- */
- public boolean isAssignableTo(Bundle arg0, String arg1) {
- return true;
- }
+
+ /**
+ * Get a property value.
+ * @param s : the key of the required property.
+ * @return the property value or null if no property for the given key.
+ * @see org.osgi.framework.ServiceReference#getProperty(java.lang.String)
+ */
+ public Object getProperty(String s) {
+ return m_registration.getProperty(s);
+ }
+
+ /**
+ * Get the String arrays of service property keys.
+ * @return : the list of property keys.
+ * @see org.osgi.framework.ServiceReference#getPropertyKeys()
+ */
+ public String[] getPropertyKeys() {
+ return m_registration.getPropertyKeys();
+ }
+
+
+ /**
+ * Unsupported Operation inside composite.
+ * @return bundles using this reference.
+ * @see org.osgi.framework.ServiceReference#getUsingBundles()
+ */
+ public Bundle[] getUsingBundles() {
+ throw new UnsupportedOperationException("getUsingBundles is not supported in scope");
+ }
+
+ /**
+ * Check if the current service reference is assignable to the given bundle.
+ * @param arg0 : the bundle to check
+ * @param arg1 : the class name to check.
+ * @return true in the case of composite
+ * @see org.osgi.framework.ServiceReference#isAssignableTo(org.osgi.framework.Bundle, java.lang.String)
+ */
+ public boolean isAssignableTo(Bundle arg0, String arg1) {
+ return true;
+ }
}
diff --git a/ipojo/src/main/java/org/apache/felix/ipojo/composite/ServiceRegistrationImpl.java b/ipojo/src/main/java/org/apache/felix/ipojo/composite/ServiceRegistrationImpl.java
index 4734c86..abdb3ba 100644
--- a/ipojo/src/main/java/org/apache/felix/ipojo/composite/ServiceRegistrationImpl.java
+++ b/ipojo/src/main/java/org/apache/felix/ipojo/composite/ServiceRegistrationImpl.java
@@ -32,39 +32,40 @@
import org.osgi.framework.ServiceRegistration;
/**
- * Internal service registration implemenation.
- * This class is used for in the composition.
+ * Internal service registration implemenation. This class is used for in the
+ * composition.
+ *
* @author <a href="mailto:felix-dev@incubator.apache.org">Felix Project Team</a>
*/
public class ServiceRegistrationImpl implements ServiceRegistration {
/**
- * Service Registry.
+ * Service Registry.
*/
private ServiceRegistry m_registry = null;
-
+
/**
* Interfaces associated with the service object.
*/
private String[] m_classes = null;
-
+
/**
- * Service Id associated with the service object.
+ * Service Id associated with the service object.
*/
private Long m_serviceId = null;
-
+
/**
* Service object.
*/
private Object m_svcObj = null;
-
+
/**
* Service factory interface.
*/
private ServiceFactory m_factory = null;
-
+
/**
- * Associated property dictionary.
+ * Associated property dictionary.
*/
private Map m_propMap = null;
@@ -75,10 +76,11 @@
/**
* Constructor.
+ *
* @param registry : the service registry
* @param cm : component instance
* @param classes : published interfaces array
- * @param serviceId : the unique service id
+ * @param serviceId : the unique service id
* @param svcObj : the service object or the service factory object
* @param dict : service properties
*/
@@ -87,33 +89,44 @@
m_classes = classes;
m_serviceId = serviceId;
m_svcObj = svcObj;
- m_factory = (m_svcObj instanceof ServiceFactory)
- ? (ServiceFactory) m_svcObj : null;
-
+ if (m_svcObj instanceof ServiceFactory) { m_factory = (ServiceFactory) m_svcObj; }
initializeProperties(dict);
- // This reference is the "standard" reference for this service and will always be returned by getReference().
- // Since all reference to this service are supposed to be equal, we use the hashcode of this reference for
+ // This reference is the "standard" reference for this service and will
+ // always be returned by getReference().
+ // Since all reference to this service are supposed to be equal, we use
+ // the hashcode of this reference for
// a references to this service in ServiceReference.
m_ref = new ServiceReferenceImpl(cm, this);
}
/**
+ * Check if the service registration still valid.
* @return true if the service registration is valid.
*/
- protected boolean isValid() { return (m_svcObj != null); }
+ protected boolean isValid() {
+ return m_svcObj != null;
+ }
/**
+ * Get the service reference attached with this service registration.
+ * @return the service reference
* @see org.osgi.framework.ServiceRegistration#getReference()
*/
- public ServiceReference getReference() { return m_ref; }
+ public ServiceReference getReference() {
+ return m_ref;
+ }
/**
+ * Add properties to a service registration.
+ * @param dict : the properties to add
* @see org.osgi.framework.ServiceRegistration#setProperties(java.util.Dictionary)
*/
public void setProperties(Dictionary dict) {
// Make sure registration is valid.
- if (!isValid()) { throw new IllegalStateException("The service registration is no longer valid."); }
+ if (!isValid()) {
+ throw new IllegalStateException("The service registration is no longer valid.");
+ }
// Set the properties.
initializeProperties(dict);
// Tell registry about it.
@@ -121,6 +134,7 @@
}
/**
+ * Unregister the service.
* @see org.osgi.framework.ServiceRegistration#unregister()
*/
public void unregister() {
@@ -128,15 +142,17 @@
m_registry.unregisterService(this);
m_svcObj = null;
m_factory = null;
- } else {
- throw new IllegalStateException("Service already unregistered.");
+ } else {
+ throw new IllegalStateException("Service already unregistered.");
}
}
/**
- * Look for a property in the service properties.
+ * Look for a property in the service properties.
+ *
* @param key : property key
- * @return the object associated with the key or null if the key is not present.
+ * @return the object associated with the key or null if the key is not
+ * present.
*/
protected Object getProperty(String key) {
return m_propMap.get(key);
@@ -148,6 +164,7 @@
private transient ArrayList m_list = new ArrayList();
/**
+ * Get the property keys.
* @return the property keys list.
*/
protected String[] getPropertyKeys() {
@@ -163,26 +180,30 @@
}
/**
+ * Get the service object.
* @return the service object. Call the service factory if needed.
*/
protected Object getService() {
// If the service object is a service factory, then
// let it create the service object.
if (m_factory != null) {
- return getFactoryUnchecked();
- } else { return m_svcObj; }
+ return getFactoryUnchecked();
+ } else {
+ return m_svcObj;
+ }
}
/**
* Initialize properties.
+ *
* @param dict : serivce properties to publish.
*/
private void initializeProperties(Dictionary dict) {
// Create a case insensitive map.
- if (m_propMap == null) {
- m_propMap = new StringMap(false);
- } else {
- m_propMap.clear();
+ if (m_propMap == null) {
+ m_propMap = new StringMap(false);
+ } else {
+ m_propMap.clear();
}
if (dict != null) {
@@ -198,6 +219,7 @@
}
/**
+ * Get a service object via a service factory.
* @return the service object via the service factory invocation.
*/
private Object getFactoryUnchecked() {
@@ -205,28 +227,30 @@
}
/**
- * Unget a service.
- * (Internal Method)
+ * Unget a service. (Internal Method)
+ *
* @param cm : component instance using the service.
* @param svcObj : the unget service object.
*/
private void ungetFactoryUnchecked(ComponentInstance cm, Object svcObj) {
- if (cm instanceof InstanceManager) {
- m_factory.ungetService(((InstanceManager) cm).getContext().getBundle(), this, svcObj);
- }
-
+ if (cm instanceof InstanceManager) {
+ m_factory.ungetService(((InstanceManager) cm).getContext().getBundle(), this, svcObj);
+ }
+
}
- /**
- * Unget a service.
+ /**
+ * Unget a service.
+ *
* @param cm : component instance using the service.
* @param srvObj : the unget service object.
- */
- public void ungetService(ComponentInstance cm, Object srvObj) {
- // If the service object is a service factory, then let is release the service object.
+ */
+ public void ungetService(ComponentInstance cm, Object srvObj) {
+ // If the service object is a service factory, then let is release the
+ // service object.
if (m_factory != null) {
ungetFactoryUnchecked(cm, srvObj);
}
- }
+ }
}
diff --git a/ipojo/src/main/java/org/apache/felix/ipojo/composite/ServiceRegistry.java b/ipojo/src/main/java/org/apache/felix/ipojo/composite/ServiceRegistry.java
index 381b16b..857e123 100644
--- a/ipojo/src/main/java/org/apache/felix/ipojo/composite/ServiceRegistry.java
+++ b/ipojo/src/main/java/org/apache/felix/ipojo/composite/ServiceRegistry.java
@@ -32,275 +32,308 @@
import org.osgi.framework.ServiceRegistration;
/**
- * Internal Service Registry.
- * This class is used for in the composition.
+ * Internal Service Registry. This class is used for in the composition.
+ *
* @author <a href="mailto:felix-dev@incubator.apache.org">Felix Project Team</a>
*/
public class ServiceRegistry {
-
- /**
- * Service Id index.
- */
- private long m_serviceId = 1L;
-
- /**
- * List of service listeners.
- */
- private ArrayList m_listeners = new ArrayList(); // ListenerInfo List
-
- /**
- * List of service registration.
- */
- private ArrayList m_regs = new ArrayList();
-
- /**
- * A "real" bundle context to create LDAP filter.
- */
- private BundleContext m_bc; //BundleContext to create Filter
-
- /**
- * Listener info structure.
- */
- private class ListenerInfo {
- private ServiceListener m_listener;
- private Filter m_filter;
- }
-
- /**
- * Constructor.
- * @param bc : bundle context.
- */
- public ServiceRegistry(BundleContext bc) {
- m_bc = bc;
- }
- /**
- * Add a given service listener with no filter.
- * @param arg0 : the service listener to add
- */
- public void addServiceListener(ServiceListener arg0) {
- ListenerInfo li = new ListenerInfo();
- li.m_listener = arg0;
- li.m_filter = null;
- m_listeners.add(li);
- }
+ /**
+ * Service Id index.
+ */
+ private long m_serviceId = 1L;
- /**
- * Unget a service.
- * @param cm : instance releasing the service.
- * @param ref : released reference.
- * @return true if the unget success
- */
- public boolean ungetService(ComponentInstance cm, ServiceReference ref) {
-
- ServiceRegistrationImpl reg = ((ServiceReferenceImpl) ref).getServiceRegistration();
- if (!reg.isValid()) {
- return false;
- } else {
- reg.ungetService(cm, reg.getService());
- return true;
- }
- }
+ /**
+ * List of service listeners.
+ */
+ private ArrayList m_listeners = new ArrayList(); // ListenerInfo List
- /**
- * Unregister a service listener.
- * @param arg0 : the service listenenr to remove
- */
- public void removeServiceListener(ServiceListener arg0) {
- m_listeners.remove(arg0);
- }
+ /**
+ * List of service registration.
+ */
+ private ArrayList m_regs = new ArrayList();
- /**
- * Register a service.
- * @param cm : provider instance.
- * @param clazz : provided interface.
- * @param svcObj : service object of service factory object.
- * @param dict : service properties.
- * @return the created service registration.
- */
- public ServiceRegistration registerService(ComponentInstance cm, String clazz, Object svcObj, Dictionary dict) {
- synchronized (m_regs) {
- ServiceRegistrationImpl reg = new ServiceRegistrationImpl(this, cm, new String[] {clazz}, new Long(m_serviceId++), svcObj, dict);
- m_regs.add(reg);
- fireServiceChanged(new ServiceEvent(ServiceEvent.REGISTERED, reg.getReference()));
- return reg;
- }
- }
+ /**
+ * A "real" bundle context to create LDAP filter.
+ */
+ private BundleContext m_bc; // BundleContext to create Filter
- /**
- * Register a service.
- * @param cm : provider instance.
- * @param clazzes : provided interfaces.
- * @param svcObj : service object of service factory object.
- * @param dict : service properties.
- * @return the created service registration.
- */
- public ServiceRegistration registerService(ComponentInstance cm, String[] clazzes, Object svcObj, Dictionary dict) {
- synchronized (m_regs) {
- ServiceRegistrationImpl reg = new ServiceRegistrationImpl(this, cm, clazzes, new Long(m_serviceId++), svcObj, dict);
- m_regs.add(reg);
- fireServiceChanged(new ServiceEvent(ServiceEvent.REGISTERED, reg.getReference()));
- return reg;
- }
- }
-
- /**
- * Dispatch a service event.
- * @param event : the service to dispatch
- */
- private void fireServiceChanged(ServiceEvent event) {
- synchronized (this) {
- // Iterate on the service listenner list to notify service listener
- for (int i = 0; i < m_listeners.size(); i++) {
- ListenerInfo li = (ListenerInfo) m_listeners.get(i);
- ServiceReference sr = event.getServiceReference();
- if (li.m_filter == null) { li.m_listener.serviceChanged(event); }
- if (li.m_filter != null && li.m_filter.match(sr)) { li.m_listener.serviceChanged(event); }
- }
- }
- }
+ /**
+ * Listener info structure.
+ */
+ private class ListenerInfo {
+ /**
+ * Listener object.
+ */
+ private ServiceListener m_listener;
+ /**
+ * Filter associated with the filter.
+ */
+ private Filter m_filter;
+ }
- /**
- * Get available (and accessible) service references.
- * @param className : required interface
- * @param expr : LDAP filter
- * @return : the list of available service references.
- * @throws InvalidSyntaxException occurs when the LDAP filter is malformed.
- */
- public ServiceReference[] getServiceReferences(String className, String expr) throws InvalidSyntaxException {
- synchronized (this) {
- // Define filter if expression is not null.
- Filter filter = null;
- if (expr != null) { filter = m_bc.createFilter(expr); }
-
- ArrayList refs = new ArrayList();
-
- for (int i = 0; i < m_regs.size(); i++) {
- ServiceRegistrationImpl reg = (ServiceRegistrationImpl) m_regs.get(i);
- // Determine if the registered services matches the search criteria.
- boolean matched = false;
+ /**
+ * Constructor.
+ *
+ * @param bc : bundle context.
+ */
+ public ServiceRegistry(BundleContext bc) {
+ m_bc = bc;
+ }
- // If className is null, then look at filter only.
- if ((className == null) && ((filter == null) || filter.match(reg.getReference()))) {
- matched = true;
- } else if (className != null) {
- // If className is not null, then first match the
- // objectClass property before looking at the
- // filter.
- String[] objectClass = (String[]) ((ServiceRegistrationImpl) reg).getProperty(Constants.OBJECTCLASS);
- for (int classIdx = 0; classIdx < objectClass.length; classIdx++) {
- if (objectClass[classIdx].equals(className) && ((filter == null) || filter.match(reg.getReference()))) {
- matched = true;
- break;
- }
- }
- }
+ /**
+ * Add a given service listener with no filter.
+ *
+ * @param arg0 : the service listener to add
+ */
+ public void addServiceListener(ServiceListener arg0) {
+ ListenerInfo li = new ListenerInfo();
+ li.m_listener = arg0;
+ li.m_filter = null;
+ m_listeners.add(li);
+ }
- // Add reference if it was a match.
- if (matched) { refs.add(reg.getReference()); }
- }
-
- if (refs.size() > 0) { return (ServiceReference[]) refs.toArray(new ServiceReference[refs.size()]); }
- return null;
- }
- }
+ /**
+ * Unget a service.
+ *
+ * @param cm : instance releasing the service.
+ * @param ref : released reference.
+ * @return true if the unget success
+ */
+ public boolean ungetService(ComponentInstance cm, ServiceReference ref) {
- /**
- * Look for a service reference.
- * @param clazz : required interface.
- * @return the first available provider or null if none available.
- */
- public ServiceReference getServiceReference(String clazz) {
- synchronized (this) {
- try {
- ServiceReference[] refs = getServiceReferences(clazz, null);
- if (refs != null) { return refs[0]; } // If the refs != null we are sure that it exist one references or more.
- } catch (InvalidSyntaxException ex) { System.err.println("Scope Service Registry : Problem when look for service reference" + ex.getMessage()); }
- return null;
- }
- }
+ ServiceRegistrationImpl reg = ((ServiceReferenceImpl) ref).getServiceRegistration();
+ if (!reg.isValid()) {
+ return false;
+ } else {
+ reg.ungetService(cm, reg.getService());
+ return true;
+ }
+ }
- /**
- * Get a service object.
- * @param cm : component instance requiring the service.
- * @param ref : the required reference.
- * @return the service object.
- */
- public Object getService(ComponentInstance cm, ServiceReference ref) {
- synchronized (this) {
- // Look for the service registration for this ref
- ServiceRegistrationImpl reg = ((ServiceReferenceImpl) ref).getServiceRegistration();
- if (reg.isValid()) {
- // Delegate the service providing to the service registration
- return reg.getService();
- } else {
- return null;
- }
- }
- }
+ /**
+ * Unregister a service listener.
+ *
+ * @param arg0 : the service listenenr to remove
+ */
+ public void removeServiceListener(ServiceListener arg0) {
+ m_listeners.remove(arg0);
+ }
- /**
- * Get all service references consistent with the given interface and filter.
- * @param clazz : the required interface.
- * @param filter : the LDAP filter.
- * @return the list of all service reference or null if none available.
- * @throws InvalidSyntaxException
- */
- public ServiceReference[] getAllServiceReferences(String clazz, String filter) throws InvalidSyntaxException {
- synchronized (this) {
- // Can delegate on getServiceReference, indeed their is no test on the "modularity" conflict.
- return getServiceReferences(clazz, filter);
- }
- }
+ /**
+ * Register a service.
+ *
+ * @param cm : provider instance.
+ * @param clazz : provided interface.
+ * @param svcObj : service object of service factory object.
+ * @param dict : service properties.
+ * @return the created service registration.
+ */
+ public ServiceRegistration registerService(ComponentInstance cm, String clazz, Object svcObj, Dictionary dict) {
+ synchronized (m_regs) {
+ ServiceRegistrationImpl reg = new ServiceRegistrationImpl(this, cm, new String[] { clazz }, new Long(m_serviceId++), svcObj, dict);
+ m_regs.add(reg);
+ fireServiceChanged(new ServiceEvent(ServiceEvent.REGISTERED, reg.getReference()));
+ return reg;
+ }
+ }
- /**
- * Add a service listener with a filter.
- * @param listener : the service listener to add
- * @param filter : LDAP filter
- */
- public void addServiceListener(ServiceListener listener, String filter) {
- synchronized (this) {
- ListenerInfo li = new ListenerInfo();
- li.m_listener = listener;
- try {
- li.m_filter = m_bc.createFilter(filter);
- } catch (InvalidSyntaxException ex) { System.err.println("Scope Service Registry : Problem when creatin a service listener " + ex.getMessage()); }
- m_listeners.add(li);
- }
- }
+ /**
+ * Register a service.
+ *
+ * @param cm : provider instance.
+ * @param clazzes : provided interfaces.
+ * @param svcObj : service object of service factory object.
+ * @param dict : service properties.
+ * @return the created service registration.
+ */
+ public ServiceRegistration registerService(ComponentInstance cm, String[] clazzes, Object svcObj, Dictionary dict) {
+ synchronized (m_regs) {
+ ServiceRegistrationImpl reg = new ServiceRegistrationImpl(this, cm, clazzes, new Long(m_serviceId++), svcObj, dict);
+ m_regs.add(reg);
+ fireServiceChanged(new ServiceEvent(ServiceEvent.REGISTERED, reg.getReference()));
+ return reg;
+ }
+ }
- /**
- * Dispatch a service properties modified event.
- * @param reg : the implicated service registration.
- */
- public void servicePropertiesModified(ServiceRegistrationImpl reg) {
- fireServiceChanged(new ServiceEvent(ServiceEvent.MODIFIED, reg.getReference()));
- }
+ /**
+ * Dispatch a service event.
+ *
+ * @param event : the service to dispatch
+ */
+ private void fireServiceChanged(ServiceEvent event) {
+ synchronized (this) {
+ // Iterate on the service listenner list to notify service listener
+ for (int i = 0; i < m_listeners.size(); i++) {
+ ListenerInfo li = (ListenerInfo) m_listeners.get(i);
+ ServiceReference sr = event.getServiceReference();
+ if (li.m_filter == null) {
+ li.m_listener.serviceChanged(event);
+ }
+ if (li.m_filter != null && li.m_filter.match(sr)) {
+ li.m_listener.serviceChanged(event);
+ }
+ }
+ }
+ }
- /**
- * Unregister a service.
- * @param reg : the service registration to unregister
- */
- public void unregisterService(ServiceRegistrationImpl reg) {
- synchronized (this) {
- m_regs.remove(reg);
- fireServiceChanged(new ServiceEvent(ServiceEvent.UNREGISTERING, reg.getReference()));
- }
- }
-
- /**
- * @return the size of the service registry.
- */
- protected int getSize() {
- return m_regs.size();
- }
-
- /**
- * Reset the service registry.
- */
- protected void reset() {
- m_serviceId = 1L;
- m_listeners = new ArrayList();
- m_regs = new ArrayList();
- }
+ /**
+ * Get available (and accessible) service references.
+ *
+ * @param className : required interface
+ * @param expr : LDAP filter
+ * @return : the list of available service references.
+ * @throws InvalidSyntaxException occurs when the LDAP filter is malformed.
+ */
+ public ServiceReference[] getServiceReferences(String className, String expr) throws InvalidSyntaxException {
+ synchronized (this) {
+ // Define filter if expression is not null.
+ Filter filter = null;
+ if (expr != null) {
+ filter = m_bc.createFilter(expr);
+ }
+
+ ArrayList refs = new ArrayList();
+
+ for (int i = 0; i < m_regs.size(); i++) {
+ ServiceRegistrationImpl reg = (ServiceRegistrationImpl) m_regs.get(i);
+ // Determine if the registered services matches the search
+ // criteria.
+ boolean matched = false;
+
+ // If className is null, then look at filter only.
+ if ((className == null) && ((filter == null) || filter.match(reg.getReference()))) {
+ matched = true;
+ } else if (className != null) {
+ // If className is not null, then first match the
+ // objectClass property before looking at the
+ // filter.
+ String[] objectClass = (String[]) ((ServiceRegistrationImpl) reg).getProperty(Constants.OBJECTCLASS);
+ for (int classIdx = 0; classIdx < objectClass.length; classIdx++) {
+ if (objectClass[classIdx].equals(className) && ((filter == null) || filter.match(reg.getReference()))) {
+ matched = true;
+ break;
+ }
+ }
+ }
+
+ // Add reference if it was a match.
+ if (matched) {
+ refs.add(reg.getReference());
+ }
+ }
+
+ if (refs.size() > 0) {
+ return (ServiceReference[]) refs.toArray(new ServiceReference[refs.size()]);
+ }
+ return null;
+ }
+ }
+
+ /**
+ * Look for a service reference.
+ *
+ * @param clazz : required interface.
+ * @return the first available provider or null if none available.
+ */
+ public ServiceReference getServiceReference(String clazz) {
+ synchronized (this) {
+ try {
+ ServiceReference[] refs = getServiceReferences(clazz, null);
+ if (refs != null) {
+ return refs[0];
+ } // If the refs != null we are sure that it exist one
+ // references or more.
+ } catch (InvalidSyntaxException ex) {
+ System.err.println("Scope Service Registry : Problem when look for service reference" + ex.getMessage());
+ }
+ return null;
+ }
+ }
+
+ /**
+ * Get a service object.
+ *
+ * @param cm : component instance requiring the service.
+ * @param ref : the required reference.
+ * @return the service object.
+ */
+ public Object getService(ComponentInstance cm, ServiceReference ref) {
+ synchronized (this) {
+ // Look for the service registration for this ref
+ ServiceRegistrationImpl reg = ((ServiceReferenceImpl) ref).getServiceRegistration();
+ if (reg.isValid()) {
+ // Delegate the service providing to the service registration
+ return reg.getService();
+ } else {
+ return null;
+ }
+ }
+ }
+
+ /**
+ * Get all service references consistent with the given interface and
+ * filter.
+ *
+ * @param clazz : the required interface.
+ * @param filter : the LDAP filter.
+ * @return the list of all service reference or null if none available.
+ * @throws InvalidSyntaxException occurs when the LDAP filter is malformed.
+ */
+ public ServiceReference[] getAllServiceReferences(String clazz, String filter) throws InvalidSyntaxException {
+ synchronized (this) {
+ // Can delegate on getServiceReference, indeed their is no test on
+ // the "modularity" conflict.
+ return getServiceReferences(clazz, filter);
+ }
+ }
+
+ /**
+ * Add a service listener with a filter.
+ *
+ * @param listener : the service listener to add
+ * @param filter : LDAP filter
+ */
+ public void addServiceListener(ServiceListener listener, String filter) {
+ synchronized (this) {
+ ListenerInfo li = new ListenerInfo();
+ li.m_listener = listener;
+ try {
+ li.m_filter = m_bc.createFilter(filter);
+ } catch (InvalidSyntaxException ex) {
+ System.err.println("Scope Service Registry : Problem when creatin a service listener " + ex.getMessage());
+ }
+ m_listeners.add(li);
+ }
+ }
+
+ /**
+ * Dispatch a service properties modified event.
+ *
+ * @param reg : the implicated service registration.
+ */
+ public void servicePropertiesModified(ServiceRegistrationImpl reg) {
+ fireServiceChanged(new ServiceEvent(ServiceEvent.MODIFIED, reg.getReference()));
+ }
+
+ /**
+ * Unregister a service.
+ *
+ * @param reg : the service registration to unregister
+ */
+ public void unregisterService(ServiceRegistrationImpl reg) {
+ synchronized (this) {
+ m_regs.remove(reg);
+ fireServiceChanged(new ServiceEvent(ServiceEvent.UNREGISTERING, reg.getReference()));
+ }
+ }
+
+ /**
+ * Reset the service registry.
+ */
+ protected void reset() {
+ m_serviceId = 1L;
+ m_listeners = new ArrayList();
+ m_regs = new ArrayList();
+ }
}
diff --git a/ipojo/src/main/java/org/apache/felix/ipojo/composite/StringMap.java b/ipojo/src/main/java/org/apache/felix/ipojo/composite/StringMap.java
index 5800a02..86f5d46 100644
--- a/ipojo/src/main/java/org/apache/felix/ipojo/composite/StringMap.java
+++ b/ipojo/src/main/java/org/apache/felix/ipojo/composite/StringMap.java
@@ -23,37 +23,39 @@
import java.util.TreeMap;
/**
- * Simple utility class that creates a map for string-based keys by
- * extending <tt>TreeMap</tt>. This map can be set to use case-sensitive
- * or case-insensitive comparison when searching for the key.
- * Any keys put into this map will be converted to
- * a <tt>String</tt> using the <tt>toString()</tt> method,
- * since it is only intended to compare strings.
-**/
+ * Simple utility class that creates a map for string-based keys by extending
+ * <tt>TreeMap</tt>. This map can be set to use case-sensitive or
+ * case-insensitive comparison when searching for the key. Any keys put into
+ * this map will be converted to a <tt>String</tt> using the
+ * <tt>toString()</tt> method, since it is only intended to compare strings.
+ * @author <a href="mailto:felix-dev@incubator.apache.org">Felix Project Team</a>
+ */
public class StringMap extends TreeMap {
-
- /**
- * serialVersionUID.
- */
- private static final long serialVersionUID = 6948801857034259744L;
- /**
+ /**
+ * serialVersionUID.
+ */
+ private static final long serialVersionUID = 6948801857034259744L;
+
+ /**
* Constructor.
*/
public StringMap() {
this(true);
}
-
+
/**
* Constructor.
+ *
* @param caseSensitive : fix if the map if case sensitive or not.
*/
public StringMap(boolean caseSensitive) {
super(new StringComparator(caseSensitive));
}
-
+
/**
* Constructor.
+ *
* @param map : initial properties.
* @param caseSensitive : fix if the map if case sensitive or not.
*/
@@ -61,15 +63,20 @@
this(caseSensitive);
putAll(map);
}
-
+
/**
+ * Put a record in the map.
+ * @param key : key
+ * @param value : value
+ * @return an object.
* @see java.util.TreeMap#put(K, V)
*/
public Object put(Object key, Object value) {
return super.put(key.toString(), value);
}
-
+
/**
+ * Check if the map is case-sensitive.
* @return true if the map is case sensitive.
*/
public boolean isCaseSensitive() {
@@ -78,6 +85,7 @@
/**
* Set the case sensitivity.
+ *
* @param b : the new case sensitivity.
*/
public void setCaseSensitive(boolean b) {
@@ -85,10 +93,14 @@
}
private static class StringComparator implements Comparator {
+ /**
+ * Is the map case sensitive?
+ */
private boolean m_isCaseSensitive = true;
/**
* Constructor.
+ *
* @param b : true to enable the case sensitivity.
*/
public StringComparator(boolean b) {
@@ -96,6 +108,10 @@
}
/**
+ * Compare to object.
+ * @param o1 : first object to compare
+ * @param o2 : second object to compare
+ * @return the comparison result
* @see java.util.Comparator#compare(T, T)
*/
public int compare(Object o1, Object o2) {
@@ -107,6 +123,7 @@
}
/**
+ * Check if the comparator is case sensitive.
* @return true if the map is case sensitive.
*/
public boolean isCaseSensitive() {
@@ -115,17 +132,20 @@
/**
* Set the case sensitivity.
+ *
* @param b : true to enable the case sensitivity
*/
public void setCaseSensitive(boolean b) {
m_isCaseSensitive = b;
}
-
+
/**
+ * Does not support cloning.
+ * @return The current map
* @see java.lang.Object#clone()
*/
public Object clone() {
- return this;
+ return this;
}
}
}
diff --git a/ipojo/src/main/java/org/apache/felix/ipojo/composite/architecture/ArchitectureHandler.java b/ipojo/src/main/java/org/apache/felix/ipojo/composite/architecture/ArchitectureHandler.java
index 697decb..8053008 100644
--- a/ipojo/src/main/java/org/apache/felix/ipojo/composite/architecture/ArchitectureHandler.java
+++ b/ipojo/src/main/java/org/apache/felix/ipojo/composite/architecture/ArchitectureHandler.java
@@ -32,17 +32,19 @@
/**
* Composite Architecture Handler.
+ *
* @author <a href="mailto:felix-dev@incubator.apache.org">Felix Project Team</a>
*/
public class ArchitectureHandler extends CompositeHandler implements Architecture {
- /**
+ /**
* Composite Manager.
*/
private CompositeManager m_manager;
/**
- * Service Registration of the Architecture service provided by this handler.
+ * Service Registration of the Architecture service provided by this
+ * handler.
*/
private ServiceRegistration m_sr;
@@ -52,12 +54,20 @@
private String m_name;
/**
- * @see org.apache.felix.ipojo.CompositeHandler#configure(org.apache.felix.ipojo.CompositeManager, org.apache.felix.ipojo.metadata.Element, java.util.Dictionary)
+ * Configure the handler.
+ *
+ * @param im : the instance manager
+ * @param metadata : the metadata of the component
+ * @param configuration : the instance configuration
+ * @see org.apache.felix.ipojo.CompositeHandler#configure(org.apache.felix.ipojo.CompositeManager,
+ * org.apache.felix.ipojo.metadata.Element, java.util.Dictionary)
*/
public void configure(CompositeManager im, Element metadata, Dictionary configuration) {
if (metadata.containsAttribute("architecture")) {
String isArchitectureEnabled = (metadata.getAttribute("architecture")).toLowerCase();
- if (isArchitectureEnabled.equalsIgnoreCase("true")) { im.register(this); }
+ if (isArchitectureEnabled.equalsIgnoreCase("true")) {
+ im.register(this);
+ }
}
m_name = (String) configuration.get("name");
@@ -66,20 +76,27 @@
}
/**
+ * Stop the handler.
+ * Unregister the service.
* @see org.apache.felix.ipojo.Handler#stop()
*/
public void stop() {
- try {
- if (m_sr != null) { m_sr.unregister(); m_sr = null; }
- } catch (Exception e) { return; }
+ if (m_sr != null) {
+ m_sr.unregister();
+ m_sr = null;
+ }
}
/**
+ * Start the handler.
+ * Register the service.
* @see org.apache.felix.ipojo.Handler#start()
*/
public void start() {
// Unregister the service if already registred
- if (m_sr != null) { m_sr.unregister(); }
+ if (m_sr != null) {
+ m_sr.unregister();
+ }
// Register the ManagedService
BundleContext bc = m_manager.getContext();
@@ -91,6 +108,8 @@
}
/**
+ * Get the instance description.
+ * @return the instance description
* @see org.apache.felix.ipojo.architecture.Architecture#getComponentDescription()
*/
public InstanceDescription getInstanceDescription() {
diff --git a/ipojo/src/main/java/org/apache/felix/ipojo/composite/service/importer/ImportExportDescription.java b/ipojo/src/main/java/org/apache/felix/ipojo/composite/service/importer/ImportExportDescription.java
index df213dc..1a2768b 100644
--- a/ipojo/src/main/java/org/apache/felix/ipojo/composite/service/importer/ImportExportDescription.java
+++ b/ipojo/src/main/java/org/apache/felix/ipojo/composite/service/importer/ImportExportDescription.java
@@ -21,57 +21,77 @@
import java.util.List;
import org.apache.felix.ipojo.architecture.HandlerDescription;
+import org.apache.felix.ipojo.metadata.Attribute;
+import org.apache.felix.ipojo.metadata.Element;
/**
+ * Description of the Import Export Handler.
* @author <a href="mailto:felix-dev@incubator.apache.org">Felix Project Team</a>
*/
public class ImportExportDescription extends HandlerDescription {
-
- private List m_imports;
- private List m_exports;
- /**
- * Constructor.
- * @param name
- * @param isValid
- * @param importers
- * @param exporters
- */
- public ImportExportDescription(String name, boolean isValid, List importers, List exporters) {
- super(name, isValid);
- m_imports = importers;
- m_exports = exporters;
- }
-
- /**
- * @see org.apache.felix.ipojo.architecture.HandlerDescription#getHandlerInfo()
- */
- public String getHandlerInfo() {
- String s = "";
- for (int i = 0; i < m_imports.size(); i++) {
- ServiceImporter imp = (ServiceImporter) m_imports.get(i);
- if (imp.isSatisfied()) {
- s += "\t Specification " + imp.getSpecification() + " provided by \n \t";
- for (int j = 0; j < imp.getProviders().size(); j++) {
- String prov = (String) imp.getProviders().get(j);
- s += prov + " ";
- }
- } else {
- s += "\t Specification " + imp.getSpecification() + " is not statisfied \n";
- }
- }
- for (int i = 0; i < m_exports.size(); i++) {
- ServiceExporter exp = (ServiceExporter) m_exports.get(i);
- if (exp.isSatisfied()) {
- s += "\t Specification " + exp.getSpecification() + " is exported or optional";
- } else {
- s += "\t Specification " + exp.getSpecification() + " is not exported";
- }
- }
- return s;
-
- }
-
-
+ /**
+ * List of imports.
+ */
+ private List m_imports;
+
+ /**
+ * List of exports.
+ */
+ private List m_exports;
+
+ /**
+ * Constructor.
+ *
+ * @param name : name of the handler
+ * @param isValid : handler validity
+ * @param importers : list of managed imports
+ * @param exporters : list of managed exports
+ */
+ public ImportExportDescription(String name, boolean isValid, List importers, List exporters) {
+ super(name, isValid);
+ m_imports = importers;
+ m_exports = exporters;
+ }
+
+ /**
+ * Build the ImportExport handler description.
+ * @return the handler description
+ * @see org.apache.felix.ipojo.architecture.HandlerDescription#getHandlerInfo()
+ */
+ public Element getHandlerInfo() {
+ Element handler = super.getHandlerInfo();
+ for (int i = 0; i < m_imports.size(); i++) {
+ ServiceImporter imp = (ServiceImporter) m_imports.get(i);
+ Element impo = new Element("Import", "");
+ impo.addAttribute(new Attribute("Specification", imp.getSpecification()));
+ if (imp.getFilter() != null) { impo.addAttribute(new Attribute("Filter", imp.getFilter())); }
+ if (imp.isSatisfied()) {
+ impo.addAttribute(new Attribute("State", "resolved"));
+ for (int j = 0; j < imp.getProviders().size(); j++) {
+ Element pr = new Element("Provider", "");
+ pr.addAttribute(new Attribute("name", (String) imp.getProviders().get(j)));
+ impo.addElement(pr);
+ }
+ } else {
+ impo.addAttribute(new Attribute("State", "unresolved"));
+ }
+ handler.addElement(impo);
+ }
+ for (int i = 0; i < m_exports.size(); i++) {
+ ServiceExporter exp = (ServiceExporter) m_exports.get(i);
+ Element expo = new Element("Export", "");
+ expo.addAttribute(new Attribute("Specification", exp.getSpecification()));
+ expo.addAttribute(new Attribute("Filter", exp.getFilter()));
+ if (exp.isSatisfied()) {
+ expo.addAttribute(new Attribute("State", "resolved"));
+ } else {
+ expo.addAttribute(new Attribute("State", "unresolved"));
+ }
+ handler.addElement(expo);
+ }
+ return handler;
+
+ }
}
diff --git a/ipojo/src/main/java/org/apache/felix/ipojo/composite/service/importer/ImportExportHandler.java b/ipojo/src/main/java/org/apache/felix/ipojo/composite/service/importer/ImportExportHandler.java
index cf55240..b0b9bd9 100644
--- a/ipojo/src/main/java/org/apache/felix/ipojo/composite/service/importer/ImportExportHandler.java
+++ b/ipojo/src/main/java/org/apache/felix/ipojo/composite/service/importer/ImportExportHandler.java
@@ -31,211 +31,259 @@
import org.osgi.framework.BundleContext;
/**
- * This handler manages the importation and the exportation of services from / to the parent context.
+ * This handler manages the importation and the exportation of services from /
+ * to the parent context.
+ *
* @author <a href="mailto:felix-dev@incubator.apache.org">Felix Project Team</a>
*/
public class ImportExportHandler extends CompositeHandler {
-
- /**
- * Composite Manager.
- */
- private CompositeManager m_manager;
-
- /**
- * Service Scope.
- */
- private ServiceContext m_scope;
-
- /**
- * Parent context.
- */
- private BundleContext m_context;
-
- /**
- * List of importers.
- */
- private List m_importers = new ArrayList();
-
- /**
- * List of exporters.
- */
- private List m_exporters = new ArrayList();
-
- /**
- * Is the handler valid ?
- */
- private boolean m_valid;
- /**
- * @see org.apache.felix.ipojo.CompositeHandler#configure(org.apache.felix.ipojo.CompositeManager, org.apache.felix.ipojo.metadata.Element, java.util.Dictionary)
- */
- public void configure(CompositeManager im, Element metadata, Dictionary conf) {
- m_manager = im;
- m_context = im.getContext();
- m_scope = m_manager.getServiceContext();
-
- Element[] imp = metadata.getElements("import");
- Element[] exp = metadata.getElements("export");
-
- for (int i = 0; i < imp.length; i++) {
- boolean optional = false;
- boolean aggregate = false;
- String specification = null;
-
- if (!imp[i].containsAttribute("specification")) { // Malformed import
- im.getFactory().getLogger().log(Logger.ERROR, "Malformed import : the specification attribute is mandatory");
- } else {
- specification = imp[i].getAttribute("specification");
- String filter = "(&(objectClass=" + specification + ")(!(service.pid=" + m_manager.getInstanceName() + ")))"; // Cannot import yourself
- if (imp[i].containsAttribute("optional") && imp[i].getAttribute("optional").equalsIgnoreCase("true")) { optional = true; }
- if (imp[i].containsAttribute("aggregate") && imp[i].getAttribute("aggregate").equalsIgnoreCase("true")) { aggregate = true; }
- if (imp[i].containsAttribute("filter")) {
- String classnamefilter = "(objectClass=" + specification + ")";
- filter = "";
- if (!imp[i].getAttribute("filter").equals("")) {
- filter = "(&" + classnamefilter + imp[i].getAttribute("filter") + ")";
- } else {
- filter = classnamefilter;
- }
- }
- ServiceImporter si = new ServiceImporter(specification, filter, aggregate, optional, this);
- m_importers.add(si);
- }
- }
-
- for (int i = 0; i < exp.length; i++) {
- boolean optional = false;
- boolean aggregate = false;
- String specification = null;
-
- if (!exp[i].containsAttribute("specification")) { // Malformed exports
- im.getFactory().getLogger().log(Logger.ERROR, "Malformed exports : the specification attribute is mandatory");
- } else {
- specification = exp[i].getAttribute("specification");
- String filter = "(objectClass=" + specification + ")";
- if (exp[i].containsAttribute("optional") && exp[i].getAttribute("optional").equalsIgnoreCase("true")) { optional = true; }
- if (exp[i].containsAttribute("aggregate") && exp[i].getAttribute("aggregate").equalsIgnoreCase("true")) { aggregate = true; }
- if (exp[i].containsAttribute("filter")) {
- String classnamefilter = "(objectClass=" + specification + ")";
- filter = "";
- if (!imp[i].getAttribute("filter").equals("")) {
- filter = "(&" + classnamefilter + exp[i].getAttribute("filter") + ")";
- } else {
- filter = classnamefilter;
- }
- }
- ServiceExporter si = new ServiceExporter(specification, filter, aggregate, optional, this);
- // Update the componenet type description
-
- m_manager.getComponentDescription().addProvidedServiceSpecification(specification);
- m_exporters.add(si);
- }
- }
-
- if (m_importers.size() > 0 || m_exporters.size() > 0) {
- im.register(this);
- }
- }
+ /**
+ * Composite Manager.
+ */
+ private CompositeManager m_manager;
- /**
- * @see org.apache.felix.ipojo.CompositeHandler#start()
- */
- public void start() {
- for (int i = 0; i < m_importers.size(); i++) {
- ServiceImporter si = (ServiceImporter) m_importers.get(i);
- si.configure(m_context, m_scope);
- si.start();
- }
-
- for (int i = 0; i < m_exporters.size(); i++) {
- ServiceExporter se = (ServiceExporter) m_exporters.get(i);
- se.configure(m_scope, m_context);
- se.start();
- }
-
- }
+ /**
+ * Service Scope.
+ */
+ private ServiceContext m_scope;
- /**
- * @see org.apache.felix.ipojo.CompositeHandler#stop()
- */
- public void stop() {
- for (int i = 0; i < m_importers.size(); i++) {
- ServiceImporter si = (ServiceImporter) m_importers.get(i);
- si.stop();
- }
-
- for (int i = 0; i < m_exporters.size(); i++) {
- ServiceExporter se = (ServiceExporter) m_exporters.get(i);
- se.stop();
- }
- }
-
- /**
- * @see org.apache.felix.ipojo.CompositeHandler#isValid()
- */
- public boolean isValid() {
- for (int i = 0; i < m_importers.size(); i++) {
- ServiceImporter si = (ServiceImporter) m_importers.get(i);
- if (!si.isSatisfied()) { m_valid = false; return false; }
- }
-
- for (int i = 0; i < m_exporters.size(); i++) {
- ServiceExporter se = (ServiceExporter) m_exporters.get(i);
- if (!se.isSatisfied()) { m_valid = false; return false; }
- }
-
- m_valid = true;
- return true;
- }
+ /**
+ * Parent context.
+ */
+ private BundleContext m_context;
- /**
- * Notify the handler that an importer is no more valid.
- * @param importer : the implicated importer.
- */
- protected void invalidating(ServiceImporter importer) {
- // An import is no more valid
- if (m_valid) { m_manager.checkInstanceState(); }
-
- }
+ /**
+ * List of importers.
+ */
+ private List m_importers = new ArrayList();
- /**
- * Notify the handler that an importer becomes valid.
- * @param importer : the implicated importer.
- */
- protected void validating(ServiceImporter importer) {
- // An import becomes valid
- if (!m_valid && isValid()) { m_manager.checkInstanceState(); }
-
- }
+ /**
+ * List of exporters.
+ */
+ private List m_exporters = new ArrayList();
- /**
- * Notify the handler that an exporter becomes invalid.
- * @param exporter : the impcated exporter.
- */
- protected void invalidating(ServiceExporter exporter) {
- // An import is no more valid
- if (m_valid) { m_manager.checkInstanceState(); }
-
- }
+ /**
+ * Is the handler valid ?
+ */
+ private boolean m_valid;
- /**
- * Notify the handler that an exporter becomes valid.
- * @param exporter : the impcated exporter.
- */
- protected void validating(ServiceExporter exporter) {
- // An import becomes valid
- if (!m_valid && isValid()) { m_manager.checkInstanceState(); }
-
- }
-
- /**
- * @return the attached composite manager.
- */
- protected CompositeManager getManager() { return m_manager; }
-
-
- /**
- * @see org.apache.felix.ipojo.CompositeHandler#getDescription()
- */
- public HandlerDescription getDescription() { return new ImportExportDescription(this.getClass().getName(), isValid(), m_importers, m_exporters); }
+ /**
+ * Configure the handler.
+ *
+ * @param im : the instance manager
+ * @param metadata : the metadata of the component
+ * @param conf : the instance configuration
+ * @see org.apache.felix.ipojo.CompositeHandler#configure(org.apache.felix.ipojo.CompositeManager,
+ * org.apache.felix.ipojo.metadata.Element, java.util.Dictionary)
+ */
+ public void configure(CompositeManager im, Element metadata, Dictionary conf) {
+ m_manager = im;
+ m_context = im.getContext();
+ m_scope = m_manager.getServiceContext();
+
+ Element[] imp = metadata.getElements("import");
+ Element[] exp = metadata.getElements("export");
+
+ for (int i = 0; i < imp.length; i++) {
+ boolean optional = false;
+ boolean aggregate = false;
+ String specification = null;
+
+ if (!imp[i].containsAttribute("specification")) { // Malformed
+ // import
+ im.getFactory().getLogger().log(Logger.ERROR, "Malformed import : the specification attribute is mandatory");
+ } else {
+ specification = imp[i].getAttribute("specification");
+ String filter = "(&(objectClass=" + specification + ")(!(service.pid=" + m_manager.getInstanceName() + ")))"; // Cannot
+ // import
+ // yourself
+ if (imp[i].containsAttribute("optional") && imp[i].getAttribute("optional").equalsIgnoreCase("true")) {
+ optional = true;
+ }
+ if (imp[i].containsAttribute("aggregate") && imp[i].getAttribute("aggregate").equalsIgnoreCase("true")) {
+ aggregate = true;
+ }
+ if (imp[i].containsAttribute("filter")) {
+ String classnamefilter = "(objectClass=" + specification + ")";
+ filter = "";
+ if (!imp[i].getAttribute("filter").equals("")) {
+ filter = "(&" + classnamefilter + imp[i].getAttribute("filter") + ")";
+ } else {
+ filter = classnamefilter;
+ }
+ }
+ ServiceImporter si = new ServiceImporter(specification, filter, aggregate, optional, m_context, m_scope, this);
+ m_importers.add(si);
+ }
+ }
+
+ for (int i = 0; i < exp.length; i++) {
+ boolean optional = false;
+ boolean aggregate = false;
+ String specification = null;
+
+ if (!exp[i].containsAttribute("specification")) { // Malformed
+ // exports
+ im.getFactory().getLogger().log(Logger.ERROR, "Malformed exports : the specification attribute is mandatory");
+ } else {
+ specification = exp[i].getAttribute("specification");
+ String filter = "(objectClass=" + specification + ")";
+ if (exp[i].containsAttribute("optional") && exp[i].getAttribute("optional").equalsIgnoreCase("true")) {
+ optional = true;
+ }
+ if (exp[i].containsAttribute("aggregate") && exp[i].getAttribute("aggregate").equalsIgnoreCase("true")) {
+ aggregate = true;
+ }
+ if (exp[i].containsAttribute("filter")) {
+ String classnamefilter = "(objectClass=" + specification + ")";
+ filter = "";
+ if (!imp[i].getAttribute("filter").equals("")) {
+ filter = "(&" + classnamefilter + exp[i].getAttribute("filter") + ")";
+ } else {
+ filter = classnamefilter;
+ }
+ }
+ ServiceExporter si = new ServiceExporter(specification, filter, aggregate, optional, m_scope, m_context, this);
+ // Update the componenet type description
+
+ m_manager.getComponentDescription().addProvidedServiceSpecification(specification);
+ m_exporters.add(si);
+ }
+ }
+
+ if (m_importers.size() > 0 || m_exporters.size() > 0) {
+ im.register(this);
+ }
+ }
+
+ /**
+ * Start the handler.
+ * Start importers and exporters.
+ * @see org.apache.felix.ipojo.CompositeHandler#start()
+ */
+ public void start() {
+ for (int i = 0; i < m_importers.size(); i++) {
+ ServiceImporter si = (ServiceImporter) m_importers.get(i);
+ si.start();
+ }
+
+ for (int i = 0; i < m_exporters.size(); i++) {
+ ServiceExporter se = (ServiceExporter) m_exporters.get(i);
+ se.start();
+ }
+
+ }
+
+ /**
+ * Stop the handler.
+ * Stop all importers and exporters.
+ * @see org.apache.felix.ipojo.CompositeHandler#stop()
+ */
+ public void stop() {
+ for (int i = 0; i < m_importers.size(); i++) {
+ ServiceImporter si = (ServiceImporter) m_importers.get(i);
+ si.stop();
+ }
+
+ for (int i = 0; i < m_exporters.size(); i++) {
+ ServiceExporter se = (ServiceExporter) m_exporters.get(i);
+ se.stop();
+ }
+ }
+
+ /**
+ * Check the handler validity.
+ * @return true if all importers and exporters are valid
+ * @see org.apache.felix.ipojo.CompositeHandler#isValid()
+ */
+ public boolean isValid() {
+ for (int i = 0; i < m_importers.size(); i++) {
+ ServiceImporter si = (ServiceImporter) m_importers.get(i);
+ if (!si.isSatisfied()) {
+ m_valid = false;
+ return false;
+ }
+ }
+
+ for (int i = 0; i < m_exporters.size(); i++) {
+ ServiceExporter se = (ServiceExporter) m_exporters.get(i);
+ if (!se.isSatisfied()) {
+ m_valid = false;
+ return false;
+ }
+ }
+
+ m_valid = true;
+ return true;
+ }
+
+ /**
+ * Notify the handler that an importer is no more valid.
+ *
+ * @param importer : the implicated importer.
+ */
+ protected void invalidating(ServiceImporter importer) {
+ // An import is no more valid
+ if (m_valid) {
+ m_manager.checkInstanceState();
+ }
+
+ }
+
+ /**
+ * Notify the handler that an importer becomes valid.
+ *
+ * @param importer : the implicated importer.
+ */
+ protected void validating(ServiceImporter importer) {
+ // An import becomes valid
+ if (!m_valid && isValid()) {
+ m_manager.checkInstanceState();
+ }
+
+ }
+
+ /**
+ * Notify the handler that an exporter becomes invalid.
+ *
+ * @param exporter : the impcated exporter.
+ */
+ protected void invalidating(ServiceExporter exporter) {
+ // An import is no more valid
+ if (m_valid) {
+ m_manager.checkInstanceState();
+ }
+
+ }
+
+ /**
+ * Notify the handler that an exporter becomes valid.
+ *
+ * @param exporter : the impcated exporter.
+ */
+ protected void validating(ServiceExporter exporter) {
+ // An import becomes valid
+ if (!m_valid && isValid()) {
+ m_manager.checkInstanceState();
+ }
+
+ }
+
+ /**
+ * Get the composite maanger.
+ * @return the attached composite manager.
+ */
+ protected CompositeManager getManager() {
+ return m_manager;
+ }
+
+ /**
+ * Get the import / export handler description.
+ * @return the handler description
+ * @see org.apache.felix.ipojo.CompositeHandler#getDescription()
+ */
+ public HandlerDescription getDescription() {
+ return new ImportExportDescription(this.getClass().getName(), isValid(), m_importers, m_exporters);
+ }
}
diff --git a/ipojo/src/main/java/org/apache/felix/ipojo/composite/service/importer/ServiceExporter.java b/ipojo/src/main/java/org/apache/felix/ipojo/composite/service/importer/ServiceExporter.java
index 0b8b570..5f54f6c 100644
--- a/ipojo/src/main/java/org/apache/felix/ipojo/composite/service/importer/ServiceExporter.java
+++ b/ipojo/src/main/java/org/apache/felix/ipojo/composite/service/importer/ServiceExporter.java
@@ -35,267 +35,324 @@
/**
* Export an service from the scope to the parent context.
+ *
* @author <a href="mailto:felix-dev@incubator.apache.org">Felix Project Team</a>
*/
public class ServiceExporter implements ServiceListener {
-
- private BundleContext m_destination;
- private ServiceContext m_origin;
-
- private String m_specification;
- private Filter m_filter;
- private String m_filterStr;
-
- private boolean m_aggregate = false;
- private boolean m_optional = false;
-
- private ImportExportHandler m_handler;
-
- private boolean m_isValid;
-
- private class Record {
- private ServiceReference m_ref;
- private ServiceRegistration m_reg;
- private Object m_svcObject;
- }
-
- private List/*<Record>*/ m_records = new ArrayList()/*<Record>*/;
-
- /**
- * Constructor.
- * @param specification
- * @param filter
- * @param multiple
- * @param optional
- * @param from
- * @param to
- * @param exp
- */
- public ServiceExporter(String specification, String filter, boolean multiple, boolean optional, ServiceContext from, BundleContext to, ImportExportHandler exp) {
- this.m_destination = to;
- this.m_origin = from;
- this.m_handler = exp;
- try {
- this.m_filter = to.createFilter(filter);
- } catch (InvalidSyntaxException e) { e.printStackTrace(); return; }
- this.m_aggregate = multiple;
- this.m_specification = specification;
- this.m_optional = optional;
- }
-
- /**
- * @param specification
- * @param filter
- * @param multiple
- * @param optional
- * @param exp
- */
- public ServiceExporter(String specification, String filter, boolean multiple, boolean optional, ImportExportHandler exp) {
- this.m_handler = exp;
- this.m_filterStr = filter;
- this.m_aggregate = multiple;
- this.m_specification = specification;
- this.m_optional = optional;
- }
-
- /**
- * @param from
- * @param to
- */
- public void configure(ServiceContext from, BundleContext to) {
- this.m_destination = to;
- this.m_origin = from;
- try {
- this.m_filter = to.createFilter(m_filterStr);
- } catch (InvalidSyntaxException e) { e.printStackTrace(); return; }
- }
-
- /**
- *
- */
- public void start() {
- try {
- ServiceReference[] refs = m_origin.getServiceReferences(m_specification, null);
- if (refs != null) {
- for (int i = 0; i < refs.length; i++) {
- if (m_filter.match(refs[i])) {
- Record rec = new Record();
- rec.m_ref = refs[i];
- m_records.add(rec);
- }
- }
- }
- } catch (InvalidSyntaxException e) { e.printStackTrace(); }
-
- // Publish available services
- if (m_records.size() > 0) {
- if (m_aggregate) {
- for (int i = 0; i < m_records.size(); i++) {
- Record rec = (Record) m_records.get(i);
- rec.m_svcObject = m_origin.getService(rec.m_ref);
- rec.m_reg = m_destination.registerService(m_specification, rec.m_svcObject, getProps(rec.m_ref));
- }
- } else {
- Record rec = (Record) m_records.get(0);
- rec.m_svcObject = m_origin.getService(rec.m_ref);
- rec.m_reg = m_destination.registerService(m_specification, rec.m_svcObject, getProps(rec.m_ref));
- }
- }
-
- // Register service listener
- try {
- m_origin.addServiceListener(this, "(" + Constants.OBJECTCLASS + "=" + m_specification + ")");
- } catch (InvalidSyntaxException e) { e.printStackTrace(); }
-
- m_isValid = isSatisfied();
- }
-
- /**
- * @param ref
- * @return
- */
- private Dictionary getProps(ServiceReference ref) {
- Properties prop = new Properties();
- String[] keys = ref.getPropertyKeys();
- for (int i = 0; i < keys.length; i++) {
- prop.put(keys[i], ref.getProperty(keys[i]));
- }
-
- prop.put(Constants.SERVICE_PID, m_handler.getManager().getInstanceName());
- prop.put("factory.pid", m_handler.getManager().getFactory().getFactoryName());
- return prop;
- }
-
- /**
- *
- */
- public void stop() {
- m_origin.removeServiceListener(this);
-
- for (int i = 0; i < m_records.size(); i++) {
- Record rec = (Record) m_records.get(i);
- rec.m_svcObject = null;
- if (rec.m_reg != null) {
- rec.m_reg.unregister();
- m_origin.ungetService(rec.m_ref);
- rec.m_ref = null;
- }
- }
-
- m_records.clear();
-
- }
-
- /**
- * @return
- */
- public boolean isSatisfied() {
- return m_optional || m_records.size() > 0;
- }
-
- /**
- * @param ref
- * @return
- */
- private List/*<Record>*/ getRecordsByRef(ServiceReference ref) {
- List l = new ArrayList();
- for (int i = 0; i < m_records.size(); i++) {
- Record rec = (Record) m_records.get(i);
- if (rec.m_ref == ref) { l.add(rec); }
- }
- return l;
- }
-
- /**
- * @see org.osgi.framework.ServiceListener#serviceChanged(org.osgi.framework.ServiceEvent)
- */
- public void serviceChanged(ServiceEvent ev) {
- if (ev.getType() == ServiceEvent.REGISTERED) { arrivalManagement(ev.getServiceReference()); }
- if (ev.getType() == ServiceEvent.UNREGISTERING) { departureManagement(ev.getServiceReference()); }
-
- if (ev.getType() == ServiceEvent.MODIFIED) {
- if (m_filter.match(ev.getServiceReference())) {
- // Test if the ref is always matching with the filter
- List l = getRecordsByRef(ev.getServiceReference());
- if (l.size() > 0) { // The ref is already contained => update the properties
- for (int i = 0; i < l.size(); i++) { // Stop the implied record
- Record rec = (Record) l.get(i);
- if (rec.m_reg != null) { rec.m_reg.setProperties(getProps(rec.m_ref)); }
- }
- } else { // it is a new mathcing service => add it
- arrivalManagement(ev.getServiceReference());
- }
- } else {
- List l = getRecordsByRef(ev.getServiceReference());
- if (l.size() > 0) { // The ref is already contained => the service does no more match
- departureManagement(ev.getServiceReference());
- }
- }
- }
- }
-
- /**
- * @param ref
- */
- private void arrivalManagement(ServiceReference ref) {
- // Check if the new service match
- if (m_filter.match(ref)) {
- // Add it to the record list
- Record rec = new Record();
- rec.m_ref = ref;
- m_records.add(rec);
- // Publishing ?
- if (m_records.size() == 1 || m_aggregate) { // If the service is the first one, or if it is a multiple imports
- rec.m_svcObject = m_origin.getService(rec.m_ref);
- rec.m_reg = m_destination.registerService(m_specification, rec.m_svcObject, getProps(rec.m_ref));
- }
- // Compute the new state
- if (!m_isValid && isSatisfied()) {
- m_isValid = true;
- m_handler.validating(this);
- }
- }
- }
-
- /**
- * @param ref
- */
- private void departureManagement(ServiceReference ref) {
- List l = getRecordsByRef(ref);
- for (int i = 0; i < l.size(); i++) { // Stop the implied record
- Record rec = (Record) l.get(i);
- if (rec.m_reg != null) {
- rec.m_svcObject = null;
- rec.m_reg.unregister();
- rec.m_reg = null;
- m_origin.ungetService(rec.m_ref);
- }
- }
- m_records.removeAll(l);
-
- // Check the validity & if we need to reimport the service
- if (m_records.size() > 0) {
- // There is other available services
- if (!m_aggregate) { // Import the next one
- Record rec = (Record) m_records.get(0);
- if (rec.m_svcObject == null) { // It is the first service who disappears - create the next one
- rec.m_svcObject = m_origin.getService(rec.m_ref);
- rec.m_reg = m_destination.registerService(m_specification, rec.m_svcObject, getProps(rec.m_ref));
- }
- }
- } else {
- if (!m_optional) {
- m_isValid = false;
- m_handler.invalidating(this);
- }
- }
- }
-
- /**
- * @return the exported specification.
- */
- protected String getSpecification() {
- return m_specification;
- }
+ /**
+ * Destination context.
+ */
+ private BundleContext m_destination;
+
+ /**
+ * Origin context.
+ */
+ private ServiceContext m_origin;
+
+ /**
+ * Exported specification.
+ */
+ private String m_specification;
+
+ /**
+ * LDAP filter filtering internal provider.
+ */
+ private Filter m_filter;
+
+ /**
+ * String form of the LDAP filter.
+ */
+ private String m_filterStr;
+
+ /**
+ * Should be exported several providers.
+ */
+ private boolean m_aggregate = false;
+
+ /**
+ * Is this exports optional?
+ */
+ private boolean m_optional = false;
+
+ /**
+ * Reference of the handler.
+ */
+ private ImportExportHandler m_handler;
+
+ /**
+ * Is the exporter valid?
+ */
+ private boolean m_isValid;
+
+ /**
+ * Structure Reference, Registration, Service Object.
+ */
+ private class Record {
+ /**
+ * Internal Reference.
+ */
+ private ServiceReference m_ref;
+ /**
+ * External Registration.
+ */
+ private ServiceRegistration m_reg;
+ /**
+ * Exposed object.
+ */
+ private Object m_svcObject;
+ }
+
+ /**
+ * List of managed records.
+ */
+ private List/*<Record>*/m_records = new ArrayList()/* <Record> */;
+
+ /**
+ * Constructor.
+ *
+ * @param specification : exported service specification.
+ * @param filter : LDAP filter
+ * @param multiple : is the export an aggregate export?
+ * @param optional : is the export optional?
+ * @param from : internal service context
+ * @param to : external bundle context
+ * @param exp : handler
+ */
+ public ServiceExporter(String specification, String filter, boolean multiple, boolean optional, ServiceContext from, BundleContext to,
+ ImportExportHandler exp) {
+ this.m_destination = to;
+ this.m_origin = from;
+ this.m_handler = exp;
+ try {
+ this.m_filter = to.createFilter(filter);
+ } catch (InvalidSyntaxException e) {
+ e.printStackTrace();
+ return;
+ }
+ this.m_aggregate = multiple;
+ this.m_specification = specification;
+ this.m_optional = optional;
+ }
+
+ /**
+ * Start method.
+ * Start the provider traking and the publication.
+ */
+ public void start() {
+ try {
+ ServiceReference[] refs = m_origin.getServiceReferences(m_specification, null);
+ if (refs != null) {
+ for (int i = 0; i < refs.length; i++) {
+ if (m_filter.match(refs[i])) {
+ Record rec = new Record();
+ rec.m_ref = refs[i];
+ m_records.add(rec);
+ }
+ }
+ }
+ } catch (InvalidSyntaxException e) {
+ e.printStackTrace();
+ }
+
+ // Publish available services
+ if (m_records.size() > 0) {
+ if (m_aggregate) {
+ for (int i = 0; i < m_records.size(); i++) {
+ Record rec = (Record) m_records.get(i);
+ rec.m_svcObject = m_origin.getService(rec.m_ref);
+ rec.m_reg = m_destination.registerService(m_specification, rec.m_svcObject, getProps(rec.m_ref));
+ }
+ } else {
+ Record rec = (Record) m_records.get(0);
+ rec.m_svcObject = m_origin.getService(rec.m_ref);
+ rec.m_reg = m_destination.registerService(m_specification, rec.m_svcObject, getProps(rec.m_ref));
+ }
+ }
+
+ // Register service listener
+ try {
+ m_origin.addServiceListener(this, "(" + Constants.OBJECTCLASS + "=" + m_specification + ")");
+ } catch (InvalidSyntaxException e) {
+ e.printStackTrace();
+ }
+
+ m_isValid = isSatisfied();
+ }
+
+ /**
+ * Transform service reference property in a dictionary.
+ * Service.PID and Factory.PID are injected too.
+ * @param ref : the service reference.
+ * @return the dictionary containing all property of the given service reference.
+ */
+ private Dictionary getProps(ServiceReference ref) {
+ Properties prop = new Properties();
+ String[] keys = ref.getPropertyKeys();
+ for (int i = 0; i < keys.length; i++) {
+ prop.put(keys[i], ref.getProperty(keys[i]));
+ }
+
+ prop.put(Constants.SERVICE_PID, m_handler.getManager().getInstanceName());
+ prop.put("factory.pid", m_handler.getManager().getFactory().getName());
+
+ return prop;
+ }
+
+ /**
+ * Stop an exporter.
+ * Remove the service listener
+ * Unregister all exported services.
+ */
+ public void stop() {
+ m_origin.removeServiceListener(this);
+
+ for (int i = 0; i < m_records.size(); i++) {
+ Record rec = (Record) m_records.get(i);
+ rec.m_svcObject = null;
+ if (rec.m_reg != null) {
+ rec.m_reg.unregister();
+ m_origin.ungetService(rec.m_ref);
+ rec.m_ref = null;
+ }
+ }
+
+ m_records.clear();
+
+ }
+
+ /**
+ * Check the exporter validity.
+ * @return true if optional or 'valid'
+ */
+ public boolean isSatisfied() {
+ return m_optional || m_records.size() > 0;
+ }
+
+ /**
+ * Get the list of records using the given reference.
+ * @param ref : the service reference
+ * @return the list of records using the given reference, empty if no record used this reference
+ */
+ private List/* <Record> */getRecordsByRef(ServiceReference ref) {
+ List l = new ArrayList();
+ for (int i = 0; i < m_records.size(); i++) {
+ Record rec = (Record) m_records.get(i);
+ if (rec.m_ref == ref) {
+ l.add(rec);
+ }
+ }
+ return l;
+ }
+
+ /**
+ * Service Listener Implementation.
+ * @param ev : the service event
+ * @see org.osgi.framework.ServiceListener#serviceChanged(org.osgi.framework.ServiceEvent)
+ */
+ public void serviceChanged(ServiceEvent ev) {
+ if (ev.getType() == ServiceEvent.REGISTERED) {
+ arrivalManagement(ev.getServiceReference());
+ }
+ if (ev.getType() == ServiceEvent.UNREGISTERING) {
+ departureManagement(ev.getServiceReference());
+ }
+
+ if (ev.getType() == ServiceEvent.MODIFIED) {
+ if (m_filter.match(ev.getServiceReference())) {
+ // Test if the ref is always matching with the filter
+ List l = getRecordsByRef(ev.getServiceReference());
+ if (l.size() > 0) { // The ref is already contained => update
+ // the properties
+ for (int i = 0; i < l.size(); i++) { // Stop the implied
+ // record
+ Record rec = (Record) l.get(i);
+ if (rec.m_reg != null) {
+ rec.m_reg.setProperties(getProps(rec.m_ref));
+ }
+ }
+ } else { // it is a new mathcing service => add it
+ arrivalManagement(ev.getServiceReference());
+ }
+ } else {
+ List l = getRecordsByRef(ev.getServiceReference());
+ if (l.size() > 0) { // The ref is already contained => the
+ // service does no more match
+ departureManagement(ev.getServiceReference());
+ }
+ }
+ }
+ }
+
+ /**
+ * Manage the arrival of a service.
+ * @param ref : the new service reference.
+ */
+ private void arrivalManagement(ServiceReference ref) {
+ // Check if the new service match
+ if (m_filter.match(ref)) {
+ // Add it to the record list
+ Record rec = new Record();
+ rec.m_ref = ref;
+ m_records.add(rec);
+ // Publishing ?
+ if (m_records.size() == 1 || m_aggregate) { // If the service is the
+ // first one, or if it
+ // is a multiple imports
+ rec.m_svcObject = m_origin.getService(rec.m_ref);
+ rec.m_reg = m_destination.registerService(m_specification, rec.m_svcObject, getProps(rec.m_ref));
+ }
+ // Compute the new state
+ if (!m_isValid && isSatisfied()) {
+ m_isValid = true;
+ m_handler.validating(this);
+ }
+ }
+ }
+
+ /**
+ * Manage the departure of a service.
+ * @param ref : the new service reference.
+ */
+ private void departureManagement(ServiceReference ref) {
+ List l = getRecordsByRef(ref);
+ for (int i = 0; i < l.size(); i++) { // Stop the implied record
+ Record rec = (Record) l.get(i);
+ if (rec.m_reg != null) {
+ rec.m_svcObject = null;
+ rec.m_reg.unregister();
+ rec.m_reg = null;
+ m_origin.ungetService(rec.m_ref);
+ }
+ }
+ m_records.removeAll(l);
+
+ // Check the validity & if we need to reimport the service
+ if (m_records.size() > 0) {
+ // There is other available services
+ if (!m_aggregate) { // Import the next one
+ Record rec = (Record) m_records.get(0);
+ if (rec.m_svcObject == null) { // It is the first service who
+ // disappears - create the next
+ // one
+ rec.m_svcObject = m_origin.getService(rec.m_ref);
+ rec.m_reg = m_destination.registerService(m_specification, rec.m_svcObject, getProps(rec.m_ref));
+ }
+ }
+ } else {
+ if (!m_optional) {
+ m_isValid = false;
+ m_handler.invalidating(this);
+ }
+ }
+ }
+
+
+ protected String getSpecification() {
+ return m_specification;
+ }
+
+ public String getFilter() {
+ return m_filterStr;
+ }
}
diff --git a/ipojo/src/main/java/org/apache/felix/ipojo/composite/service/importer/ServiceImporter.java b/ipojo/src/main/java/org/apache/felix/ipojo/composite/service/importer/ServiceImporter.java
index 79ef6f7..98a2eff 100644
--- a/ipojo/src/main/java/org/apache/felix/ipojo/composite/service/importer/ServiceImporter.java
+++ b/ipojo/src/main/java/org/apache/felix/ipojo/composite/service/importer/ServiceImporter.java
@@ -34,283 +34,332 @@
import org.osgi.framework.ServiceRegistration;
/**
- * Import a service form the parent to the internal service registry.
+ * Import a service form the parent to the internal service registry.
+ *
* @author <a href="mailto:felix-dev@incubator.apache.org">Felix Project Team</a>
*/
public class ServiceImporter implements ServiceListener {
-
- private ServiceContext m_destination;
- private BundleContext m_origine;
-
- private String m_specification;
- private Filter m_filter;
- private String m_filterStr;
-
- private boolean m_aggregate = false;
- private boolean m_optional = false;
-
- private boolean m_isValid;
-
- private ImportExportHandler m_handler;
-
- private class Record {
- private ServiceReference m_ref;
- private ServiceRegistration m_reg;
- private Object m_svcObject;
- }
-
- private List/*<Record>*/ m_records = new ArrayList()/*<Record>*/;
-
- /**
- * Constructor.
- * @param specification : targetted specification
- * @param filter : LDAP filter
- * @param multiple : should the importer imports several services ?
- * @param optional : is the import optional ?
- * @param from : parent context
- * @param to : internal context
- * @param in : handler
- */
- public ServiceImporter(String specification, String filter, boolean multiple, boolean optional, BundleContext from, ServiceContext to, ImportExportHandler in) {
- this.m_destination = to;
- this.m_origine = from;
- try {
- this.m_filter = from.createFilter(filter);
- } catch (InvalidSyntaxException e) { e.printStackTrace(); return; }
- this.m_aggregate = multiple;
- this.m_specification = specification;
- this.m_optional = optional;
- this.m_handler = in;
- }
-
- /**
- * Constructor.
- * @param specification : targetted specification
- * @param filter : LDAP filter
- * @param multiple : should the importer imports several services ?
- * @param optional : is the import optional ?
- * @param in : handler
- */
- public ServiceImporter(String specification, String filter, boolean multiple, boolean optional, ImportExportHandler in) {
- this.m_filterStr = filter;
- this.m_aggregate = multiple;
- this.m_filterStr = filter;
- this.m_specification = specification;
- this.m_optional = optional;
- this.m_handler = in;
- }
-
- /**
- * Configure the origin and the destination of the import.
- * @param from : origine (parent)
- * @param to : destination (internal scope)
- */
- public void configure(BundleContext from, ServiceContext to) {
- this.m_destination = to;
- this.m_origine = from;
- try {
- this.m_filter = from.createFilter(m_filterStr);
- } catch (InvalidSyntaxException e) { e.printStackTrace(); return; }
- }
-
- /**
- * Start method to begin the import.
- */
- public void start() {
- try {
- ServiceReference[] refs = m_origine.getServiceReferences(m_specification, null);
- if (refs != null) {
- for (int i = 0; i < refs.length; i++) {
- if (m_filter.match(refs[i])) {
- Record rec = new Record();
- rec.m_ref = refs[i];
- m_records.add(rec);
- }
- }
- }
- } catch (InvalidSyntaxException e) { e.printStackTrace(); }
-
- // Publish available services
- if (m_records.size() > 0) {
- if (m_aggregate) {
- for (int i = 0; i < m_records.size(); i++) {
- Record rec = (Record) m_records.get(i);
- rec.m_svcObject = m_origine.getService(rec.m_ref);
- rec.m_reg = m_destination.registerService(m_specification, rec.m_svcObject, getProps(rec.m_ref));
- }
- } else {
- Record rec = (Record) m_records.get(0);
- rec.m_svcObject = m_origine.getService(rec.m_ref);
- rec.m_reg = m_destination.registerService(m_specification, rec.m_svcObject, getProps(rec.m_ref));
- }
- }
-
- // Register service listener
- try {
- m_origine.addServiceListener(this, "(" + Constants.OBJECTCLASS + "=" + m_specification + ")");
- } catch (InvalidSyntaxException e) { e.printStackTrace(); }
-
- m_isValid = isSatisfied();
- }
-
- /**
- * Get the properties for the exposed service from the given reference.
- * @param ref : the reference.
- * @return the property dictionary
- */
- private Dictionary getProps(ServiceReference ref) {
- Properties prop = new Properties();
- String[] keys = ref.getPropertyKeys();
- for (int i = 0; i < keys.length; i++) {
- prop.put(keys[i], ref.getProperty(keys[i]));
- }
- return prop;
- }
-
- /**
- * Stop the management of the import.
- */
- public void stop() {
-
- m_origine.removeServiceListener(this);
-
- for (int i = 0; i < m_records.size(); i++) {
- Record rec = (Record) m_records.get(i);
- rec.m_svcObject = null;
- if (rec.m_reg != null) {
- rec.m_reg.unregister();
- m_origine.ungetService(rec.m_ref);
- rec.m_ref = null;
- }
- }
-
- m_records.clear();
-
- }
-
- /**
- * @return true if the import is satisfied.
- */
- public boolean isSatisfied() {
- return m_optional || m_records.size() > 0;
- }
-
- /**
- * Get the record list using the given reference.
- * @param ref : the reference
- * @return the list containing all record using the given reference
- */
- private List/*<Record>*/ getRecordsByRef(ServiceReference ref) {
- List l = new ArrayList();
- for (int i = 0; i < m_records.size(); i++) {
- Record rec = (Record) m_records.get(i);
- if (rec.m_ref == ref) { l.add(rec); }
- }
- return l;
- }
-
- /**
- * @see org.osgi.framework.ServiceListener#serviceChanged(org.osgi.framework.ServiceEvent)
- */
- public void serviceChanged(ServiceEvent ev) {
- if (ev.getType() == ServiceEvent.REGISTERED) { arrivalManagement(ev.getServiceReference()); }
- if (ev.getType() == ServiceEvent.UNREGISTERING) { departureManagement(ev.getServiceReference()); }
-
- if (ev.getType() == ServiceEvent.MODIFIED) {
- if (m_filter.match(ev.getServiceReference())) {
- // Test if the ref is always matching with the filter
- List l = getRecordsByRef(ev.getServiceReference());
- if (l.size() > 0) { // The ref is already contained => update the properties
- for (int i = 0; i < l.size(); i++) { // Stop the implied record
- Record rec = (Record) l.get(i);
- if (rec.m_reg != null) { rec.m_reg.setProperties(getProps(rec.m_ref)); }
- }
- } else { // it is a new mathcing service => add it
- arrivalManagement(ev.getServiceReference());
- }
- } else {
- List l = getRecordsByRef(ev.getServiceReference());
- if (l.size() > 0) { // The ref is already contained => the service does no more match
- departureManagement(ev.getServiceReference());
- }
- }
- }
- }
-
- /**
- * Manage the arrival of a consitent service.
- * @param ref : the arrival service reference
- */
- private void arrivalManagement(ServiceReference ref) {
- // Check if the new service match
- if (m_filter.match(ref)) {
- // Add it to the record list
- Record rec = new Record();
- rec.m_ref = ref;
- m_records.add(rec);
- // Publishing ?
- if (m_records.size() == 1 || m_aggregate) { // If the service is the first one, or if it is a multiple imports
- rec.m_svcObject = m_origine.getService(rec.m_ref);
- rec.m_reg = m_destination.registerService(m_specification, rec.m_svcObject, getProps(rec.m_ref));
- }
- // Compute the new state
- if (!m_isValid && isSatisfied()) {
- m_isValid = true;
- m_handler.validating(this);
- }
- }
- }
-
- /**
- * Manage the departure of a used reference.
- * @param ref : the leaving reference
- */
- private void departureManagement(ServiceReference ref) {
- List l = getRecordsByRef(ref);
- for (int i = 0; i < l.size(); i++) { // Stop the implied record
- Record rec = (Record) l.get(i);
- if (rec.m_reg != null) {
- rec.m_svcObject = null;
- rec.m_reg.unregister();
- rec.m_reg = null;
- m_origine.ungetService(rec.m_ref);
- }
- }
- m_records.removeAll(l);
-
- // Check the validity & if we need to reimport the service
- if (m_records.size() > 0) {
- // There is other available services
- if (!m_aggregate) { // Import the next one
- Record rec = (Record) m_records.get(0);
- if (rec.m_svcObject == null) { // It is the first service who disappears - create the next one
- rec.m_svcObject = m_origine.getService(rec.m_ref);
- rec.m_reg = m_destination.registerService(m_specification, rec.m_svcObject, getProps(rec.m_ref));
- }
- }
- } else {
- if (!m_optional) {
- m_isValid = false;
- m_handler.invalidating(this);
- }
- }
- }
-
- /**
- * @return the targetted specification.
- */
- public String getSpecification() { return m_specification; }
-
- /**
- * @return the list of all imported services.
- */
- protected List getProviders() {
- List l = new ArrayList();
- for (int i = 0; i < m_records.size(); i++) {
- l.add((((Record) m_records.get(i)).m_ref).getProperty(Constants.SERVICE_PID));
- }
- return l;
-
- }
+
+ /**
+ * Destination context.
+ */
+ private ServiceContext m_destination;
+
+ /**
+ * Origine Context.
+ */
+ private BundleContext m_origine;
+
+ /**
+ * Imported Specification.
+ */
+ private String m_specification;
+
+ /**
+ * LDAP filter filtering external providers.
+ */
+ private Filter m_filter;
+
+ /**
+ * String form of the LDAP filter.
+ */
+ private String m_filterStr;
+
+ /**
+ * Should we importer several providers?
+ */
+ private boolean m_aggregate = false;
+
+ /**
+ * Is the import optional?
+ */
+ private boolean m_optional = false;
+
+ /**
+ * Is the importer valid?
+ */
+ private boolean m_isValid;
+
+ /**
+ * Reference on the handler.
+ */
+ private ImportExportHandler m_handler;
+
+ private class Record {
+ /**
+ * External Reference.
+ */
+ private ServiceReference m_ref;
+ /**
+ * Internal Registration.
+ */
+ private ServiceRegistration m_reg;
+ /**
+ * Exposed Object.
+ */
+ private Object m_svcObject;
+ }
+
+ /**
+ * List of managed records.
+ */
+ private List/*<Record>*/m_records = new ArrayList()/* <Record> */;
+
+ /**
+ * Constructor.
+ *
+ * @param specification : targetted specification
+ * @param filter : LDAP filter
+ * @param multiple : should the importer imports several services ?
+ * @param optional : is the import optional ?
+ * @param from : parent context
+ * @param to : internal context
+ * @param in : handler
+ */
+ public ServiceImporter(String specification, String filter, boolean multiple, boolean optional, BundleContext from, ServiceContext to,
+ ImportExportHandler in) {
+ this.m_destination = to;
+ this.m_origine = from;
+ try {
+ this.m_filter = from.createFilter(filter);
+ } catch (InvalidSyntaxException e) {
+ e.printStackTrace();
+ return;
+ }
+ this.m_aggregate = multiple;
+ this.m_specification = specification;
+ this.m_optional = optional;
+ this.m_handler = in;
+ }
+
+ /**
+ * Start method to begin the import.
+ */
+ public void start() {
+ try {
+ ServiceReference[] refs = m_origine.getServiceReferences(m_specification, null);
+ if (refs != null) {
+ for (int i = 0; i < refs.length; i++) {
+ if (m_filter.match(refs[i])) {
+ Record rec = new Record();
+ rec.m_ref = refs[i];
+ m_records.add(rec);
+ }
+ }
+ }
+ } catch (InvalidSyntaxException e) {
+ e.printStackTrace();
+ }
+
+ // Publish available services
+ if (m_records.size() > 0) {
+ if (m_aggregate) {
+ for (int i = 0; i < m_records.size(); i++) {
+ Record rec = (Record) m_records.get(i);
+ rec.m_svcObject = m_origine.getService(rec.m_ref);
+ rec.m_reg = m_destination.registerService(m_specification, rec.m_svcObject, getProps(rec.m_ref));
+ }
+ } else {
+ Record rec = (Record) m_records.get(0);
+ rec.m_svcObject = m_origine.getService(rec.m_ref);
+ rec.m_reg = m_destination.registerService(m_specification, rec.m_svcObject, getProps(rec.m_ref));
+ }
+ }
+
+ // Register service listener
+ try {
+ m_origine.addServiceListener(this, "(" + Constants.OBJECTCLASS + "=" + m_specification + ")");
+ } catch (InvalidSyntaxException e) {
+ e.printStackTrace();
+ }
+
+ m_isValid = isSatisfied();
+ }
+
+ /**
+ * Get the properties for the exposed service from the given reference.
+ *
+ * @param ref : the reference.
+ * @return the property dictionary
+ */
+ private Dictionary getProps(ServiceReference ref) {
+ Properties prop = new Properties();
+ String[] keys = ref.getPropertyKeys();
+ for (int i = 0; i < keys.length; i++) {
+ prop.put(keys[i], ref.getProperty(keys[i]));
+ }
+ return prop;
+ }
+
+ /**
+ * Stop the management of the import.
+ */
+ public void stop() {
+
+ m_origine.removeServiceListener(this);
+
+ for (int i = 0; i < m_records.size(); i++) {
+ Record rec = (Record) m_records.get(i);
+ rec.m_svcObject = null;
+ if (rec.m_reg != null) {
+ rec.m_reg.unregister();
+ m_origine.ungetService(rec.m_ref);
+ rec.m_ref = null;
+ }
+ }
+
+ m_records.clear();
+
+ }
+
+ /**
+ * Check if the import is statisfied.
+ * @return true if the import is optional or at least one provider is imported
+ */
+ public boolean isSatisfied() {
+ return m_optional || m_records.size() > 0;
+ }
+
+ /**
+ * Get the record list using the given reference.
+ *
+ * @param ref : the reference
+ * @return the list containing all record using the given reference
+ */
+ private List/* <Record> */getRecordsByRef(ServiceReference ref) {
+ List l = new ArrayList();
+ for (int i = 0; i < m_records.size(); i++) {
+ Record rec = (Record) m_records.get(i);
+ if (rec.m_ref == ref) {
+ l.add(rec);
+ }
+ }
+ return l;
+ }
+
+ /**
+ * Service Listener Implementation.
+ * @param ev : the service event
+ * @see org.osgi.framework.ServiceListener#serviceChanged(org.osgi.framework.ServiceEvent)
+ */
+ public void serviceChanged(ServiceEvent ev) {
+ if (ev.getType() == ServiceEvent.REGISTERED) {
+ arrivalManagement(ev.getServiceReference());
+ }
+ if (ev.getType() == ServiceEvent.UNREGISTERING) {
+ departureManagement(ev.getServiceReference());
+ }
+
+ if (ev.getType() == ServiceEvent.MODIFIED) {
+ if (m_filter.match(ev.getServiceReference())) {
+ // Test if the ref is always matching with the filter
+ List l = getRecordsByRef(ev.getServiceReference());
+ if (l.size() > 0) { // The ref is already contained => update
+ // the properties
+ for (int i = 0; i < l.size(); i++) { // Stop the implied
+ // record
+ Record rec = (Record) l.get(i);
+ if (rec.m_reg != null) {
+ rec.m_reg.setProperties(getProps(rec.m_ref));
+ }
+ }
+ } else { // it is a new mathcing service => add it
+ arrivalManagement(ev.getServiceReference());
+ }
+ } else {
+ List l = getRecordsByRef(ev.getServiceReference());
+ if (l.size() > 0) { // The ref is already contained => the
+ // service does no more match
+ departureManagement(ev.getServiceReference());
+ }
+ }
+ }
+ }
+
+ /**
+ * Manage the arrival of a consitent service.
+ *
+ * @param ref : the arrival service reference
+ */
+ private void arrivalManagement(ServiceReference ref) {
+ // Check if the new service match
+ if (m_filter.match(ref)) {
+ // Add it to the record list
+ Record rec = new Record();
+ rec.m_ref = ref;
+ m_records.add(rec);
+ // Publishing ?
+ if (m_records.size() == 1 || m_aggregate) { // If the service is the
+ // first one, or if it
+ // is a multiple imports
+ rec.m_svcObject = m_origine.getService(rec.m_ref);
+ rec.m_reg = m_destination.registerService(m_specification, rec.m_svcObject, getProps(rec.m_ref));
+ }
+ // Compute the new state
+ if (!m_isValid && isSatisfied()) {
+ m_isValid = true;
+ m_handler.validating(this);
+ }
+ }
+ }
+
+ /**
+ * Manage the departure of a used reference.
+ *
+ * @param ref : the leaving reference
+ */
+ private void departureManagement(ServiceReference ref) {
+ List l = getRecordsByRef(ref);
+ for (int i = 0; i < l.size(); i++) { // Stop the implied record
+ Record rec = (Record) l.get(i);
+ if (rec.m_reg != null) {
+ rec.m_svcObject = null;
+ rec.m_reg.unregister();
+ rec.m_reg = null;
+ m_origine.ungetService(rec.m_ref);
+ }
+ }
+ m_records.removeAll(l);
+
+ // Check the validity & if we need to reimport the service
+ if (m_records.size() > 0) {
+ // There is other available services
+ if (!m_aggregate) { // Import the next one
+ Record rec = (Record) m_records.get(0);
+ if (rec.m_svcObject == null) { // It is the first service who
+ // disappears - create the next
+ // one
+ rec.m_svcObject = m_origine.getService(rec.m_ref);
+ rec.m_reg = m_destination.registerService(m_specification, rec.m_svcObject, getProps(rec.m_ref));
+ }
+ }
+ } else {
+ if (!m_optional) {
+ m_isValid = false;
+ m_handler.invalidating(this);
+ }
+ }
+ }
+
+ public String getSpecification() {
+ return m_specification;
+ }
+
+ /**
+ * Build the list of imported service provider.
+ * @return the list of all imported services.
+ */
+ protected List getProviders() {
+ List l = new ArrayList();
+ for (int i = 0; i < m_records.size(); i++) {
+ l.add((((Record) m_records.get(i)).m_ref).getProperty(Constants.SERVICE_PID));
+ }
+ return l;
+
+ }
+
+ public String getFilter() {
+ return m_filterStr;
+ }
}
diff --git a/ipojo/src/main/java/org/apache/felix/ipojo/composite/service/instantiator/ServiceInstantiatorDescription.java b/ipojo/src/main/java/org/apache/felix/ipojo/composite/service/instantiator/ServiceInstantiatorDescription.java
index 598faa3..883e508 100644
--- a/ipojo/src/main/java/org/apache/felix/ipojo/composite/service/instantiator/ServiceInstantiatorDescription.java
+++ b/ipojo/src/main/java/org/apache/felix/ipojo/composite/service/instantiator/ServiceInstantiatorDescription.java
@@ -25,49 +25,65 @@
import org.apache.felix.ipojo.ComponentInstance;
import org.apache.felix.ipojo.architecture.HandlerDescription;
+import org.apache.felix.ipojo.metadata.Attribute;
+import org.apache.felix.ipojo.metadata.Element;
import org.osgi.framework.ServiceReference;
/**
* Description of the Service Instantiator Handler.
+ *
* @author <a href="mailto:felix-dev@incubator.apache.org">Felix Project Team</a>
*/
public class ServiceInstantiatorDescription extends HandlerDescription {
-
- /**
- * List of managed service instances.
- */
- private List m_instances;
- /**
- * Constructor.
- * @param arg0 : name of the handler
- * @param arg1 : validity of the handler
- * @param insts : list of service instance
- */
- public ServiceInstantiatorDescription(String arg0, boolean arg1, List insts) {
- super(arg0, arg1);
- m_instances = insts;
- }
-
- /**
- * @see org.apache.felix.ipojo.architecture.HandlerDescription#getHandlerInfo()
- */
- public String getHandlerInfo() {
- String r = "";
- for (int i = 0; i < m_instances.size(); i++) {
- SvcInstance inst = (SvcInstance) m_instances.get(i);
- HashMap map = inst.getUsedReferences();
- Set keys = map.keySet();
- Iterator it = keys.iterator();
- while (it.hasNext()) {
- ServiceReference ref = (ServiceReference) it.next();
- Object o = map.get(ref);
- if (o != null && o instanceof ComponentInstance) {
- r += "\t Specification " + inst.getSpecification() + " instantiated from " + ((ComponentInstance) o).getComponentDescription().getName() + " \n";
- }
- }
- }
- return r;
- }
+ /**
+ * List of managed service instances.
+ */
+ private List m_instances;
+
+ /**
+ * Constructor.
+ *
+ * @param arg0 : name of the handler
+ * @param arg1 : validity of the handler
+ * @param insts : list of service instance
+ */
+ public ServiceInstantiatorDescription(String arg0, boolean arg1, List insts) {
+ super(arg0, arg1);
+ m_instances = insts;
+ }
+
+ /**
+ * Build service instantiator handler description.
+ * @return the handler description
+ * @see org.apache.felix.ipojo.architecture.HandlerDescription#getHandlerInfo()
+ */
+ public Element getHandlerInfo() {
+ Element services = super.getHandlerInfo();
+ for (int i = 0; i < m_instances.size(); i++) {
+ SvcInstance inst = (SvcInstance) m_instances.get(i);
+ Element service = new Element("Service", "");
+ service.addAttribute(new Attribute("Specification", inst.getSpecification()));
+ String state = "unresolved";
+ if (inst.isSatisfied()) {
+ state = "resolved";
+ }
+ service.addAttribute(new Attribute("State", state));
+ HashMap map = inst.getUsedReferences();
+ Set keys = map.keySet();
+ Iterator it = keys.iterator();
+ while (it.hasNext()) {
+ ServiceReference ref = (ServiceReference) it.next();
+ Object o = map.get(ref);
+ if (o != null) {
+ Element fact = new Element("Factory", "");
+ fact.addAttribute(new Attribute("Name", ((ComponentInstance) o).getComponentDescription().getName()));
+ service.addElement(fact);
+ }
+ }
+ services.addElement(service);
+ }
+ return services;
+ }
}
diff --git a/ipojo/src/main/java/org/apache/felix/ipojo/composite/service/instantiator/ServiceInstantiatorHandler.java b/ipojo/src/main/java/org/apache/felix/ipojo/composite/service/instantiator/ServiceInstantiatorHandler.java
index 1810c5f..d641cb0 100644
--- a/ipojo/src/main/java/org/apache/felix/ipojo/composite/service/instantiator/ServiceInstantiatorHandler.java
+++ b/ipojo/src/main/java/org/apache/felix/ipojo/composite/service/instantiator/ServiceInstantiatorHandler.java
@@ -30,129 +30,155 @@
import org.apache.felix.ipojo.metadata.Element;
/**
- * Service Instantiator Class.
- * This handler allows to instantiate service instance inside the composition.
+ * Service Instantiator Class. This handler allows to instantiate service
+ * instance inside the composition.
+ *
* @author <a href="mailto:felix-dev@incubator.apache.org">Felix Project Team</a>
*/
public class ServiceInstantiatorHandler extends CompositeHandler {
-
- /**
- * Composite Manager.
- */
- private CompositeManager m_manager;
-
- /**
- * Is the handler valid ?
- */
- private boolean m_isValid = false;
-
- /**
- * List of instances to manage.
- */
- private List/*<SvcInstance>*/ m_instances = new ArrayList();
- /**
- * @see org.apache.felix.ipojo.CompositeHandler#configure(org.apache.felix.ipojo.CompositeManager, org.apache.felix.ipojo.metadata.Element, java.util.Dictionary)
- */
- public void configure(CompositeManager im, Element metadata, Dictionary conf) {
- m_manager = im;
- Element[] services = metadata.getElements("service");
- for (int i = 0; i < services.length; i++) {
- String spec = services[i].getAttribute("specification");
- String filter = "(objectClass=" + Factory.class.getName() + ")";
- if (services[i].containsAttribute("filter")) {
- String classnamefilter = "(&(objectClass=" + Factory.class.getName() + ")(!(service.pid=" + m_manager.getInstanceName() + ")))"; // Cannot instantaite yourself
- filter = "";
- if (!services[i].getAttribute("filter").equals("")) {
- filter = "(&" + classnamefilter + services[i].getAttribute("filter") + ")";
- } else {
- filter = classnamefilter;
- }
- }
- Properties prop = new Properties();
- for (int k = 0; k < services[i].getElements("property").length; k++) {
- String key = services[i].getElements("property")[k].getAttribute("name");
- String value = services[i].getElements("property")[k].getAttribute("value");
- prop.put(key, value);
- }
- boolean agg = false;
- if (services[i].containsAttribute("aggregate") && services[i].getAttribute("aggregate").equalsIgnoreCase("true")) { agg = true; }
- boolean opt = false;
- if (services[i].containsAttribute("optional") && services[i].getAttribute("optional").equalsIgnoreCase("true")) { opt = true; }
- SvcInstance inst = new SvcInstance(this, spec, prop, agg, opt, filter);
- m_instances.add(inst);
- }
- if (m_instances.size() > 0) {
- m_manager.register(this);
- }
- }
+ /**
+ * Composite Manager.
+ */
+ private CompositeManager m_manager;
- /**
- * @see org.apache.felix.ipojo.CompositeHandler#start()
- */
- public void start() {
- // Init
- for (int i = 0; i < m_instances.size(); i++) {
- SvcInstance inst = (SvcInstance) m_instances.get(i);
- inst.start();
- }
-
- m_isValid = isValid();
- }
-
- /**
- * @see org.apache.felix.ipojo.CompositeHandler#isValid()
- */
- public boolean isValid() {
- for (int i = 0; i < m_instances.size(); i++) {
- SvcInstance inst = (SvcInstance) m_instances.get(i);
- if (!inst.isSatisfied()) {
- return false;
- }
- }
- return true;
- }
+ /**
+ * Is the handler valid ?
+ */
+ private boolean m_isValid = false;
- /**
- * @see org.apache.felix.ipojo.CompositeHandler#stop()
- */
- public void stop() {
- for (int i = 0; i < m_instances.size(); i++) {
- SvcInstance inst = (SvcInstance) m_instances.get(i);
- inst.stop();
- }
- m_instances.clear();
- }
-
- /**
- * An service instance becomes valid.
- */
- public void validate() {
- if (!m_isValid) {
- if (isValid()) { m_manager.checkInstanceState(); }
- m_isValid = true;
- }
- }
-
- /**
- * A service instance becomes invalid.
- */
- public void invalidate() {
- if (m_isValid) {
- if (!isValid()) { m_manager.checkInstanceState(); }
- m_isValid = false;
- }
- }
-
- /**
- * @see org.apache.felix.ipojo.CompositeHandler#getDescription()
- */
- public HandlerDescription getDescription() {
- return new ServiceInstantiatorDescription(this.getClass().getName(), isValid(), m_instances);
- }
-
- /**
- * @return the composite manager.
- */
- protected CompositeManager getManager() { return m_manager; }
+ /**
+ * List of instances to manage.
+ */
+ private List/* <SvcInstance> */m_instances = new ArrayList();
+
+ /**
+ * Configure the handler.
+ *
+ * @param im : the instance manager
+ * @param metadata : the metadata of the component
+ * @param conf : the instance configuration
+ * @see org.apache.felix.ipojo.CompositeHandler#configure(org.apache.felix.ipojo.CompositeManager,
+ * org.apache.felix.ipojo.metadata.Element, java.util.Dictionary)
+ */
+ public void configure(CompositeManager im, Element metadata, Dictionary conf) {
+ m_manager = im;
+ Element[] services = metadata.getElements("service");
+ for (int i = 0; i < services.length; i++) {
+ String spec = services[i].getAttribute("specification");
+ String filter = "(&(objectClass=" + Factory.class.getName() + ")(!(service.pid=" + m_manager.getComponentDescription().getName() + ")))"; // Cannot reinstantiate yourself
+ if (services[i].containsAttribute("filter")) {
+ String classnamefilter = "(&(objectClass=" + Factory.class.getName() + ")(!(service.pid=" + m_manager.getComponentDescription().getName() + ")))"; // Cannot reinstantiate yourself
+ filter = "";
+ if (!services[i].getAttribute("filter").equals("")) {
+ filter = "(&" + classnamefilter + services[i].getAttribute("filter") + ")";
+ } else {
+ filter = classnamefilter;
+ }
+ }
+ Properties prop = new Properties();
+ for (int k = 0; k < services[i].getElements("property").length; k++) {
+ String key = services[i].getElements("property")[k].getAttribute("name");
+ String value = services[i].getElements("property")[k].getAttribute("value");
+ prop.put(key, value);
+ }
+ boolean agg = false;
+ if (services[i].containsAttribute("aggregate") && services[i].getAttribute("aggregate").equalsIgnoreCase("true")) {
+ agg = true;
+ }
+ boolean opt = false;
+ if (services[i].containsAttribute("optional") && services[i].getAttribute("optional").equalsIgnoreCase("true")) {
+ opt = true;
+ }
+ SvcInstance inst = new SvcInstance(this, spec, prop, agg, opt, filter);
+ m_instances.add(inst);
+ }
+ if (m_instances.size() > 0) {
+ m_manager.register(this);
+ }
+ }
+
+ /**
+ * Start the service instantiator handler.
+ * Start all created service instance.
+ * @see org.apache.felix.ipojo.CompositeHandler#start()
+ */
+ public void start() {
+ // Init
+ for (int i = 0; i < m_instances.size(); i++) {
+ SvcInstance inst = (SvcInstance) m_instances.get(i);
+ inst.start();
+ }
+
+ m_isValid = isValid();
+ }
+
+ /**
+ * Check the handler validity.
+ * @return true if oall created service isntance are valid
+ * @see org.apache.felix.ipojo.CompositeHandler#isValid()
+ */
+ public boolean isValid() {
+ for (int i = 0; i < m_instances.size(); i++) {
+ SvcInstance inst = (SvcInstance) m_instances.get(i);
+ if (!inst.isSatisfied()) {
+ return false;
+ }
+ }
+ return true;
+ }
+
+ /**
+ * Handler stop method.
+ * Stop all created service instance.
+ * @see org.apache.felix.ipojo.CompositeHandler#stop()
+ */
+ public void stop() {
+ for (int i = 0; i < m_instances.size(); i++) {
+ SvcInstance inst = (SvcInstance) m_instances.get(i);
+ inst.stop();
+ }
+ m_instances.clear();
+ }
+
+ /**
+ * An service instance becomes valid.
+ */
+ public void validate() {
+ if (!m_isValid) {
+ if (isValid()) {
+ m_manager.checkInstanceState();
+ }
+ m_isValid = true;
+ }
+ }
+
+ /**
+ * A service instance becomes invalid.
+ */
+ public void invalidate() {
+ if (m_isValid) {
+ if (!isValid()) {
+ m_manager.checkInstanceState();
+ }
+ m_isValid = false;
+ }
+ }
+
+ /**
+ * Get the service instantiator handler description.
+ * @return the description
+ * @see org.apache.felix.ipojo.CompositeHandler#getDescription()
+ */
+ public HandlerDescription getDescription() {
+ return new ServiceInstantiatorDescription(this.getClass().getName(), isValid(), m_instances);
+ }
+
+ /**
+ * Get the composite manager.
+ * @return the composite manager.
+ */
+ protected CompositeManager getManager() {
+ return m_manager;
+ }
}
diff --git a/ipojo/src/main/java/org/apache/felix/ipojo/composite/service/instantiator/SvcInstance.java b/ipojo/src/main/java/org/apache/felix/ipojo/composite/service/instantiator/SvcInstance.java
index 848d73f..b73f2e9 100644
--- a/ipojo/src/main/java/org/apache/felix/ipojo/composite/service/instantiator/SvcInstance.java
+++ b/ipojo/src/main/java/org/apache/felix/ipojo/composite/service/instantiator/SvcInstance.java
@@ -22,6 +22,7 @@
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Iterator;
+import java.util.Properties;
import java.util.Set;
import org.apache.felix.ipojo.ComponentInstance;
@@ -29,319 +30,391 @@
import org.apache.felix.ipojo.ServiceContext;
import org.apache.felix.ipojo.UnacceptableConfiguration;
import org.apache.felix.ipojo.architecture.PropertyDescription;
+import org.apache.felix.ipojo.util.Logger;
import org.osgi.framework.InvalidSyntaxException;
import org.osgi.framework.ServiceEvent;
import org.osgi.framework.ServiceListener;
import org.osgi.framework.ServiceReference;
/**
- * Manage a service instantiation.
- * This service create componenet instance providing the required service specification.
+ * Manage a service instantiation. This service create componenet instance
+ * providing the required service specification.
+ *
* @author <a href="mailto:felix-dev@incubator.apache.org">Felix Project Team</a>
*/
public class SvcInstance implements ServiceListener {
-
- /**
- * Required specification.
- */
- private String m_specification;
-
- /**
- * Configuration to push to the instance.
- */
- private Dictionary m_configuration;
-
- /**
- * Map of factory references => instance or NO_INSTANCE.
- */
- private HashMap /*ServiceReference*/ m_usedRef = new HashMap();
-
- /**
- * Does we instantiate several provider ?
- */
- private boolean m_isAggregate = false;
-
- /**
- * Is the service optional ?
- */
- private boolean m_isOptional = false;
-
- /**
- * Handler creating the service instance.
- */
- private ServiceInstantiatorHandler m_handler;
-
- /**
- * Service Context (internal scope).
- */
- private ServiceContext m_context;
-
- /**
- * Parent context.
- */
- //private BundleContext m_parent;
-
- /**
- * True if the service instantiation is valid.
- */
- private boolean m_isValid = false;
-
- /**
- * String form of the factory filter.
- */
- private String m_filterStr;
-
- /**
- * Name of the last create instance.
- */
- private long m_index = 0;
-
- /**
- * Constructor.
- * @param h : the handler.
- * @param spec : required specification.
- * @param conf : instance configuration.
- * @param isAgg : is the svc instance an aggregate service ?
- * @param isOpt : is the svc instance optional ?
- */
- public SvcInstance(ServiceInstantiatorHandler h, String spec, Dictionary conf, boolean isAgg, boolean isOpt, String filt) {
- m_handler = h;
- m_context = h.getManager().getServiceContext();
- //m_parent = h.getManager().getContext();
- m_specification = spec;
- m_configuration = conf;
- m_isAggregate = isAgg;
- m_isOptional = isOpt;
- m_filterStr = filt;
- }
-
- /**
- * Start the service instance.
- * @param sc
- */
- public void start() {
- initFactoryList();
- // Register factory listener
- try {
- m_context.addServiceListener(this, m_filterStr);
- } catch (InvalidSyntaxException e) {
- e.printStackTrace(); // Should not happens
- }
- // Init the instances
- if (m_usedRef.size() > 0) {
- Set keys = m_usedRef.keySet();
- Iterator it = keys.iterator();
- if (m_isAggregate) {
- while (it.hasNext()) {
- ServiceReference ref = (ServiceReference) it.next();
- createInstance(ref);
- }
- } else {
- ServiceReference ref = (ServiceReference) it.next();
- createInstance(ref);
- }
- }
- m_isValid = isSatisfied();
- }
-
- /**
- * Stop the service instance.
- */
- public void stop() {
- m_context.removeServiceListener(this);
- Set keys = m_usedRef.keySet();
- Iterator it = keys.iterator();
- while (it.hasNext()) {
- ServiceReference ref = (ServiceReference) it.next();
- Object o = m_usedRef.get(ref);
- if (o != null) {
- ((ComponentInstance) o).stop();
- }
- }
- m_usedRef.clear();
- m_isValid = false;
- }
-
- /**
- * @return true if at least one instance is created.
- */
- private boolean isAnInstanceCreated() {
- Set keys = m_usedRef.keySet();
- Iterator it = keys.iterator();
- ServiceReference ref = (ServiceReference) it.next();
- Object o = m_usedRef.get(ref);
- return o != null;
- }
-
- /**
- * Create an instance for the given reference.
- */
- private void createInstance(ServiceReference ref) {
- try {
- Factory factory = (Factory) m_context.getService(ref);
- ComponentInstance instance = factory.createComponentInstance(m_configuration);
- m_usedRef.put(ref, instance);
- m_context.ungetService(ref);
- } catch (UnacceptableConfiguration e) {
- System.err.println("A matching factory (" + ref.getProperty("service.pid") + ") seems to refuse the given configuration : " + e.getMessage());
- }
- }
-
- /**
- * Create an instance for the next available factory.
- */
- private void createNextInstance() {
- Set keys = m_usedRef.keySet();
- Iterator it = keys.iterator();
- ServiceReference ref = (ServiceReference) it.next();
- try {
- Factory factory = (Factory) m_context.getService(ref);
- ComponentInstance instance = factory.createComponentInstance(m_configuration);
- m_usedRef.put(ref, instance);
- m_context.ungetService(ref);
- } catch (UnacceptableConfiguration e) {
- System.err.println("A matching factory seems to refuse the given configuration : " + e.getMessage());
- }
- }
-
- /**
- * Kill an instance (if exist).
- */
- private void stopInstance(ServiceReference ref) {
- Object o = m_usedRef.get(ref);
- if (o != null) {
- ((ComponentInstance) o).stop();
- }
- }
+ /**
+ * Required specification.
+ */
+ private String m_specification;
+ /**
+ * Configuration to push to the instance.
+ */
+ private Dictionary m_configuration;
- /**
- * Init the list of available factory.
- */
- public void initFactoryList() {
- // Init factory list
- try {
- ServiceReference[] refs = m_context.getServiceReferences(Factory.class.getName(), m_filterStr);
- if (refs == null) { return; }
- for (int i = 0; i < refs.length; i++) {
- ServiceReference ref = refs[i];
- Factory fact = (Factory) m_context.getService(ref);
- // Check provided spec & conf
- if (match(fact)) {
- m_usedRef.put(ref, null);
- }
- fact = null;
- m_context.ungetService(ref);
- }
- } catch (InvalidSyntaxException e) {
- e.printStackTrace(); // Should not happen
- }
- }
-
- /**
- * @return true if the service instance if satisfied.
- */
- public boolean isSatisfied() {
- return m_isOptional || m_usedRef.size() > 0;
- }
-
- /**
- * Does the service instance match with the given factory.
- * @param fact : the factory to test.
- * @return true if the factory match, false otherwise.
- */
- private boolean match(Factory fact) {
- // Check if the factory can provide the spec
- for (int i = 0; i < fact.getComponentDescription().getprovidedServiceSpecification().length; i++) {
- if (fact.getComponentDescription().getprovidedServiceSpecification()[i].equals(m_specification)) {
-
- // Check that the factory needs every properties contained in the configuration
- Enumeration e = m_configuration.keys();
- while (e.hasMoreElements()) {
- String k = (String) e.nextElement();
- if (!containsProperty(k, fact)) {
- return false;
- }
- }
-
- // Add an unique name if not specified.
- if (m_configuration.get("name") == null) {
- m_configuration.put("name", this.toString() + "-" + m_index);
- m_index++;
- }
-
- // Check the acceptability.
- return (fact.isAcceptable(m_configuration));
- }
- }
- return false;
- }
-
- /**
- * Does the factory support the given property ?
- * @param name : name of the property
- * @param factory : factory to test
- * @return true if the factory support this property
- */
- private boolean containsProperty(String name, Factory factory) {
- PropertyDescription[] props = factory.getComponentDescription().getProperties();
- for (int i = 0; i < props.length; i++) {
- if (props[i].getName().equalsIgnoreCase(name)) { return true; }
- }
- if (name.equalsIgnoreCase("name")) { return true; } // Skip the name property
- return false;
- }
+ /**
+ * Map of factory references => instance or NO_INSTANCE.
+ */
+ private HashMap /* ServiceReference */m_usedRef = new HashMap();
- /**
- * @see org.osgi.framework.ServiceListener#serviceChanged(org.osgi.framework.ServiceEvent)
- */
- public void serviceChanged(ServiceEvent ev) {
- if (ev.getType() == ServiceEvent.REGISTERED) {
- // Check the matching
- Factory fact = (Factory) m_context.getService(ev.getServiceReference());
- if (match(fact)) {
- m_usedRef.put(ev.getServiceReference(), null);
- if (m_isAggregate) { // Create an instance for the new factory
- createInstance(ev.getServiceReference());
- if (!m_isValid) { m_isValid = true; m_handler.validate(); }
- } else {
- if (!isAnInstanceCreated()) { createInstance(ev.getServiceReference()); }
- if (!m_isValid) { m_isValid = true; m_handler.validate(); }
- }
- }
- fact = null;
- m_context.ungetService(ev.getServiceReference());
- return;
- }
- if (ev.getType() == ServiceEvent.UNREGISTERING) {
- // Remove the ref is contained
- Object o = m_usedRef.remove(ev.getServiceReference());
- if (o != null) {
- stopInstance(ev.getServiceReference());
- if (m_usedRef.size() > 0) {
- if (!m_isAggregate) {
- createNextInstance(); // Create an instance with another factory
- }
- } else { // No more candidate
- if (!m_isOptional) { m_isValid = false; m_handler.invalidate(); }
- }
- }
- }
- }
+ /**
+ * Does we instantiate several provider ?
+ */
+ private boolean m_isAggregate = false;
- /**
- * @return the required specification.
- */
- public String getSpecification() {
- return m_specification;
- }
-
- /**
- * @return the map of used references.
- */
- protected HashMap getUsedReferences() {
- return m_usedRef;
- }
+ /**
+ * Is the service optional ?
+ */
+ private boolean m_isOptional = false;
+
+ /**
+ * Handler creating the service instance.
+ */
+ private ServiceInstantiatorHandler m_handler;
+
+ /**
+ * Service Context (internal scope).
+ */
+ private ServiceContext m_context;
+
+ /**
+ * True if the service instantiation is valid.
+ */
+ private boolean m_isValid = false;
+
+ /**
+ * String form of the factory filter.
+ */
+ private String m_filterStr;
+
+ /**
+ * Name of the last create instance.
+ */
+ private static Long m_index = new Long(0);
+
+ /**
+ * Constructor.
+ *
+ * @param h : the handler.
+ * @param spec : required specification.
+ * @param conf : instance configuration.
+ * @param isAgg : is the svc instance an aggregate service ?
+ * @param isOpt : is the svc instance optional ?
+ * @param filt : LDAP filter
+ */
+ public SvcInstance(ServiceInstantiatorHandler h, String spec, Dictionary conf, boolean isAgg, boolean isOpt, String filt) {
+ m_handler = h;
+ m_context = h.getManager().getServiceContext();
+ m_specification = spec;
+ m_configuration = conf;
+ m_isAggregate = isAgg;
+ m_isOptional = isOpt;
+ m_filterStr = filt;
+ }
+
+ /**
+ * Start the service instance.
+ *
+ * @param sc
+ */
+ public void start() {
+ initFactoryList();
+ // Register factory listener
+ try {
+ m_context.addServiceListener(this, m_filterStr);
+ } catch (InvalidSyntaxException e) {
+ e.printStackTrace(); // Should not happens
+ }
+
+ // Init the instances
+ if (m_usedRef.size() > 0) {
+ Set keys = m_usedRef.keySet();
+ Iterator it = keys.iterator();
+ if (m_isAggregate) {
+ while (it.hasNext()) {
+ ServiceReference ref = (ServiceReference) it.next();
+ createInstance(ref);
+ }
+ } else {
+ ServiceReference ref = (ServiceReference) it.next();
+ createInstance(ref);
+ }
+ }
+ m_isValid = isSatisfied();
+ }
+
+ /**
+ * Stop the service instance.
+ */
+ public void stop() {
+ m_context.removeServiceListener(this);
+ Set keys = m_usedRef.keySet();
+ Iterator it = keys.iterator();
+ while (it.hasNext()) {
+ ServiceReference ref = (ServiceReference) it.next();
+ Object o = m_usedRef.get(ref);
+ if (o != null) {
+ ((ComponentInstance) o).dispose();
+ }
+ }
+ m_usedRef.clear();
+ m_isValid = false;
+ }
+
+ /**
+ * Check if an instance is already created.
+ * @return true if at least one instance is created.
+ */
+ private boolean isAnInstanceCreated() {
+ Set keys = m_usedRef.keySet();
+ Iterator it = keys.iterator();
+ ServiceReference ref = (ServiceReference) it.next();
+ Object o = m_usedRef.get(ref);
+ return o != null;
+ }
+
+ /**
+ * Create an instance for the given reference.
+ * @param ref : the service reference to used to create the instance.
+ */
+ private void createInstance(ServiceReference ref) {
+ try {
+ Factory factory = (Factory) m_context.getService(ref);
+
+ // Add an unique name if not specified.
+ Properties p = new Properties();
+ Enumeration kk = m_configuration.keys();
+ while (kk.hasMoreElements()) {
+ String k = (String) kk.nextElement();
+ p.put(k, m_configuration.get(k));
+ }
+
+ if (p.get("name") == null) {
+ synchronized (m_index) {
+ p.put("name", this.toString() + "-" + m_index.longValue());
+ m_index = new Long(m_index.longValue() + 1);
+ }
+ }
+
+ ComponentInstance instance = factory.createComponentInstance(p);
+ m_usedRef.put(ref, instance);
+ m_context.ungetService(ref);
+ } catch (UnacceptableConfiguration e) {
+ m_handler.getManager().getFactory().getLogger().log(Logger.ERROR,
+ "A matching factory (" + ref.getProperty("service.pid") + ") seems to refuse the given configuration : " + e.getMessage());
+ }
+ }
+
+ /**
+ * Create an instance for the next available factory.
+ */
+ private void createNextInstance() {
+ Set keys = m_usedRef.keySet();
+ Iterator it = keys.iterator();
+ ServiceReference ref = (ServiceReference) it.next();
+ try {
+ Factory factory = (Factory) m_context.getService(ref);
+
+ // Add an unique name if not specified.
+ Properties p = new Properties();
+ Enumeration kk = m_configuration.keys();
+ while (kk.hasMoreElements()) {
+ String k = (String) kk.nextElement();
+ p.put(k, m_configuration.get(k));
+ }
+
+ if (p.get("name") == null) {
+ synchronized (m_index) {
+ p.put("name", this.toString() + "-" + m_index.longValue());
+ m_index = new Long(m_index.longValue() + 1);
+ }
+ }
+
+ ComponentInstance instance = factory.createComponentInstance(p);
+ m_usedRef.put(ref, instance);
+ m_context.ungetService(ref);
+ } catch (UnacceptableConfiguration e) {
+ m_handler.getManager().getFactory().getLogger().log(Logger.ERROR,
+ "A matching factory (" + ref.getProperty("service.pid") + ") seems to refuse the given configuration : " + e.getMessage());
+ }
+ }
+
+ /**
+ * Kill an instance (if exist).
+ * If an instance if created by using the given reference, this reference is disposed.
+ * @param ref : the leaving reference.
+ */
+ private void stopInstance(ServiceReference ref) {
+ Object o = m_usedRef.get(ref);
+ if (o != null) {
+ ((ComponentInstance) o).dispose();
+ }
+ }
+
+ /**
+ * Init the list of available factory.
+ */
+ public void initFactoryList() {
+ // Init factory list
+ try {
+ ServiceReference[] refs = m_context.getServiceReferences(Factory.class.getName(), m_filterStr);
+ if (refs == null) {
+ return;
+ }
+ for (int i = 0; i < refs.length; i++) {
+ ServiceReference ref = refs[i];
+ Factory fact = (Factory) m_context.getService(ref);
+ // Check provided spec & conf
+ if (match(fact)) {
+ m_usedRef.put(ref, null);
+ }
+ fact = null;
+ m_context.ungetService(ref);
+ }
+ } catch (InvalidSyntaxException e) {
+ e.printStackTrace(); // Should not happen
+ }
+ }
+
+ /**
+ * Check if the service isntance is statisfed.
+ * @return true if the service instance if satisfied.
+ */
+ public boolean isSatisfied() {
+ return m_isOptional || m_usedRef.size() > 0;
+ }
+
+ /**
+ * Does the service instance match with the given factory.
+ *
+ * @param fact : the factory to test.
+ * @return true if the factory match, false otherwise.
+ */
+ private boolean match(Factory fact) {
+ // Check if the factory can provide the spec
+ for (int i = 0; i < fact.getComponentDescription().getprovidedServiceSpecification().length; i++) {
+ if (fact.getComponentDescription().getprovidedServiceSpecification()[i].equals(m_specification)) {
+
+ // Check that the factory needs every properties contained in
+ // the configuration
+ Enumeration e = m_configuration.keys();
+ while (e.hasMoreElements()) {
+ String k = (String) e.nextElement();
+ if (!containsProperty(k, fact)) {
+ return false;
+ }
+ }
+
+ // Add an unique name if not specified.
+ Properties p = new Properties();
+ Enumeration keys = m_configuration.keys();
+ while (keys.hasMoreElements()) {
+ String k = (String) keys.nextElement();
+ p.put(k, m_configuration.get(k));
+ }
+
+ if (p.get("name") == null) {
+ synchronized (m_index) {
+ p.put("name", this.toString() + "-" + m_index.longValue());
+ m_index = new Long(m_index.longValue() + 1);
+ }
+ }
+
+ // Check the acceptability.
+ return fact.isAcceptable(p);
+ }
+ }
+ return false;
+ }
+
+ /**
+ * Does the factory support the given property ?
+ *
+ * @param name : name of the property
+ * @param factory : factory to test
+ * @return true if the factory support this property
+ */
+ private boolean containsProperty(String name, Factory factory) {
+ PropertyDescription[] props = factory.getComponentDescription().getProperties();
+ for (int i = 0; i < props.length; i++) {
+ if (props[i].getName().equalsIgnoreCase(name)) {
+ return true;
+ }
+ }
+ if (name.equalsIgnoreCase("name")) {
+ return true;
+ } // Skip the name property
+ return false;
+ }
+
+ /**
+ * Service Listener Implementation.
+ * @param ev : the service event
+ * @see org.osgi.framework.ServiceListener#serviceChanged(org.osgi.framework.ServiceEvent)
+ */
+ public void serviceChanged(ServiceEvent ev) {
+ if (ev.getType() == ServiceEvent.REGISTERED) {
+ // Check the matching
+ Factory fact = (Factory) m_context.getService(ev.getServiceReference());
+ if (match(fact)) {
+ m_usedRef.put(ev.getServiceReference(), null);
+ if (m_isAggregate) { // Create an instance for the new
+ // factory
+ createInstance(ev.getServiceReference());
+ if (!m_isValid) {
+ m_isValid = true;
+ m_handler.validate();
+ }
+ } else {
+ if (!isAnInstanceCreated()) {
+ createInstance(ev.getServiceReference());
+ }
+ if (!m_isValid) {
+ m_isValid = true;
+ m_handler.validate();
+ }
+ }
+ }
+ fact = null;
+ m_context.ungetService(ev.getServiceReference());
+ return;
+ }
+ if (ev.getType() == ServiceEvent.UNREGISTERING) {
+ // Remove the ref is contained
+ Object o = m_usedRef.remove(ev.getServiceReference());
+ if (o != null) {
+ stopInstance(ev.getServiceReference());
+ if (m_usedRef.size() > 0) {
+ if (!m_isAggregate) {
+ createNextInstance(); // Create an instance with
+ // another factory
+ }
+ } else { // No more candidate
+ if (!m_isOptional) {
+ m_isValid = false;
+ m_handler.invalidate();
+ }
+ }
+ }
+ }
+ }
+
+ /**
+ * Get the required specification.
+ * @return the required specification.
+ */
+ public String getSpecification() {
+ return m_specification;
+ }
+
+ /**
+ * Get the map of used references [ref, component instance].
+ * @return the map of used references.
+ */
+ protected HashMap getUsedReferences() {
+ return m_usedRef;
+ }
}
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 684d258..f85a83d 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
@@ -32,6 +32,7 @@
/**
* Achtiecture Handler : do reflection on your component.
+ *
* @author <a href="mailto:felix-dev@incubator.apache.org">Felix Project Team</a>
*/
public class ArchitectureHandler extends Handler implements Architecture {
@@ -42,7 +43,8 @@
private InstanceManager m_manager;
/**
- * Service Registration of the Architecture service provided by this handler.
+ * Service Registration of the Architecture service provided by this
+ * handler.
*/
private ServiceRegistration m_sr;
@@ -52,12 +54,20 @@
private String m_name;
/**
- * @see org.apache.felix.ipojo.Handler#configure(org.apache.felix.ipojo.InstanceManager, org.apache.felix.ipojo.metadata.Element)
+ * Configure the handler.
+ *
+ * @param im : the instance manager
+ * @param metadata : the metadata of the component
+ * @param configuration : the instance configuration
+ * @see org.apache.felix.ipojo.Handler#configure(org.apache.felix.ipojo.InstanceManager,
+ * org.apache.felix.ipojo.metadata.Element)
*/
public void configure(InstanceManager im, Element metadata, Dictionary configuration) {
if (metadata.containsAttribute("architecture")) {
String isArchitectureEnabled = (metadata.getAttribute("architecture")).toLowerCase();
- if (isArchitectureEnabled.equalsIgnoreCase("true")) { im.register(this); }
+ if (isArchitectureEnabled.equalsIgnoreCase("true")) {
+ im.register(this);
+ }
}
m_name = (String) configuration.get("name");
@@ -66,20 +76,27 @@
}
/**
+ * Stop method.
+ * Unregister the service if published.
* @see org.apache.felix.ipojo.Handler#stop()
*/
public void stop() {
- try {
- if (m_sr != null) { m_sr.unregister(); m_sr = null; }
- } catch (Exception e) { return; }
+ if (m_sr != null) {
+ m_sr.unregister();
+ m_sr = null;
+ }
}
/**
+ * Start method.
+ * Register the service.
* @see org.apache.felix.ipojo.Handler#start()
*/
public void start() {
// Unregister the service if already registred
- if (m_sr != null) { m_sr.unregister(); }
+ if (m_sr != null) {
+ m_sr.unregister();
+ }
// Register the ManagedService
BundleContext bc = m_manager.getContext();
@@ -92,6 +109,8 @@
}
/**
+ * Get the instance description.
+ * @return the instance description
* @see org.apache.felix.ipojo.architecture.Architecture#getComponentDescription()
*/
public InstanceDescription getInstanceDescription() {
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 68fc08f..5a184b4 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
@@ -23,9 +23,11 @@
import java.lang.reflect.InvocationTargetException;
import org.apache.felix.ipojo.parser.ParseUtils;
+import org.apache.felix.ipojo.util.Logger;
/**
* Configurable Property.
+ *
* @author <a href="mailto:felix-dev@incubator.apache.org">Felix Project Team</a>
*/
public class ConfigurableProperty {
@@ -52,38 +54,61 @@
/**
* Configurable Property Constructor.
+ *
* @param name : name of the property (optional)
* @param field : name of the field (mandatory)
* @param value : initial value of the property (optional)
+ * @param type : the type of the property
* @param ch : configuration handler managing this configurable property
*/
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;
+ if (name != null) {
+ m_name = name;
+ } else {
+ m_name = field;
}
m_field = field;
- if (value != null) { setValue(m_field, value, type); }
+ if (value != null) {
+ setValue(m_field, value, type);
+ }
}
/**
* Set the value of the property.
+ *
+ * @param field : name of the field attached to the property
* @param strValue : value of the property (String)
+ * @param type : type of the property
*/
private void setValue(String field, String strValue, String type) {
Object value = null;
- if (type.equals("string") || type.equals("String")) { value = new String(strValue); }
- if (type.equals("boolean")) { value = new Boolean(strValue); }
- if (type.equals("byte")) { value = new Byte(strValue); }
- if (type.equals("short")) { value = new Short(strValue); }
- if (type.equals("int")) { value = new Integer(strValue); }
- if (type.equals("long")) { value = new Long(strValue); }
- if (type.equals("float")) { value = new Float(strValue); }
- if (type.equals("double")) { value = new Double(strValue); }
+ if (type.equals("string") || type.equals("String")) {
+ value = new String(strValue);
+ }
+ if (type.equals("boolean")) {
+ value = new Boolean(strValue);
+ }
+ if (type.equals("byte")) {
+ value = new Byte(strValue);
+ }
+ if (type.equals("short")) {
+ value = new Short(strValue);
+ }
+ if (type.equals("int")) {
+ value = new Integer(strValue);
+ }
+ if (type.equals("long")) {
+ value = new Long(strValue);
+ }
+ if (type.equals("float")) {
+ value = new Float(strValue);
+ }
+ if (type.equals("double")) {
+ value = new Double(strValue);
+ }
// Array :
if (type.endsWith("[]")) {
String internalType = type.substring(0, type.length() - 2);
@@ -92,35 +117,34 @@
}
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.
+ // 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.getInstanceManager().getContext().getBundle().loadClass(type);
- Constructor cst = c.getConstructor(new Class[] {String.class});
- value = cst.newInstance(new Object[] {strValue});
+ Constructor cst = c.getConstructor(new Class[] { String.class });
+ value = cst.newInstance(new Object[] { strValue });
} catch (ClassNotFoundException e) {
- System.err.println("Class not found exception in setValue on " + type);
- e.printStackTrace();
+ m_handler.getInstanceManager().getFactory().getLogger().log(Logger.ERROR,
+ "Class not found exception in setValue on " + type + " : " + e.getMessage());
return;
} catch (SecurityException e) {
- e.printStackTrace();
+ m_handler.getInstanceManager().getFactory().getLogger().log(Logger.ERROR, "Security excption in setValue on " + type + " : " + e.getMessage());
return;
} catch (NoSuchMethodException e) {
- System.err.println("Constructor not found exeption in setValue on " + type);
- e.printStackTrace();
+ m_handler.getInstanceManager().getFactory().getLogger().log(Logger.ERROR,
+ "Constructor not found exeption in setValue on " + type + " : " + e.getMessage());
return;
} catch (IllegalArgumentException e) {
- System.err.println("Argument problem to call the constructor of the type " + type);
- e.printStackTrace();
+ m_handler.getInstanceManager().getFactory().getLogger().log(Logger.ERROR, "Argument problem to call the constructor of the type " + type);
return;
} catch (InstantiationException e) {
- System.err.println("Instantiation problem " + type);
- e.printStackTrace();
+ m_handler.getInstanceManager().getFactory().getLogger().log(Logger.ERROR, "Instantiation problem " + type);
return;
} catch (IllegalAccessException e) {
- e.printStackTrace();
+ m_handler.getInstanceManager().getFactory().getLogger().log(Logger.ERROR, "Illegal Access " + type);
+ return;
} catch (InvocationTargetException e) {
- System.err.println("Invocation problem " + type);
- e.printStackTrace();
+ m_handler.getInstanceManager().getFactory().getLogger().log(Logger.ERROR, "Invocation problem " + type);
return;
}
}
@@ -131,109 +155,123 @@
/**
* Set array value to the current property.
+ *
* @param internalType : type of the property
* @param values : new property value
*/
private void setArrayValue(String internalType, String[] values) {
- 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]); }
- m_value = str;
- 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]);
+ }
+ 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]).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]).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]).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]).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]).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]).floatValue();
+ }
m_value = fl;
- return;
+ return;
}
if (internalType.equals("double")) {
double[] dl = new double[values.length];
- for (int i = 0; i < values.length; i++) { dl[i] = new Double(values[i]).doubleValue(); }
+ for (int i = 0; i < values.length; i++) {
+ dl[i] = new Double(values[i]).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.
+ // 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.getInstanceManager().getContext().getBundle().loadClass(internalType);
- Constructor cst = c.getConstructor(new Class[] {String.class});
+ 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].trim()});
+ ob[i] = cst.newInstance(new Object[] { values[i].trim() });
}
m_value = ob;
return;
} catch (ClassNotFoundException e) {
- System.err.println("Class not found exception in setValue on " + internalType);
- e.printStackTrace();
+ m_handler.getInstanceManager().getFactory().getLogger().log(Logger.ERROR, "Class not found exception in setValue on " + internalType);
} catch (SecurityException e) {
- e.printStackTrace();
+ m_handler.getInstanceManager().getFactory().getLogger().log(Logger.ERROR, "Secutiry Exception in setValue on " + internalType);
} catch (NoSuchMethodException e) {
- System.err.println("Constructor not found exeption in setValue on " + internalType);
- e.printStackTrace();
+ m_handler.getInstanceManager().getFactory().getLogger().log(Logger.ERROR, "Constructor not found exception in setValue on " + internalType);
} catch (IllegalArgumentException e) {
- System.err.println("Argument problem to call the constructor of the type " + internalType);
- e.printStackTrace();
+ m_handler.getInstanceManager().getFactory().getLogger().log(Logger.ERROR, "Argument problem to call the constructor of the type " + internalType);
} catch (InstantiationException e) {
- System.err.println("Instantiation problem " + internalType);
- e.printStackTrace();
+ m_handler.getInstanceManager().getFactory().getLogger().log(Logger.ERROR, "Instantiation problem " + internalType);
} catch (IllegalAccessException e) {
- e.printStackTrace();
+ m_handler.getInstanceManager().getFactory().getLogger().log(Logger.ERROR, "Illegal Access Exception in " + internalType);
} catch (InvocationTargetException e) {
- System.err.println("Invocation problem " + internalType);
- e.printStackTrace();
+ m_handler.getInstanceManager().getFactory().getLogger().log(Logger.ERROR, "Invocation problem " + internalType);
}
}
- /**
- * @return the name of the property.
- */
- public String getName() { return m_name; }
+ public String getName() {
+ return m_name;
+ }
- /**
- * @return the field of the property.
- */
- public String getField() { return m_field; }
+ public String getField() {
+ return m_field;
+ }
- /**
- * @return the value of the property.
- */
- public Object getValue() { return m_value; }
+
+ public Object getValue() {
+ return m_value;
+ }
/**
* Fix the value of the property.
+ *
* @param value : the new value.
*/
- public void setValue(Object value) { m_value = value; }
+ public void setValue(Object value) {
+ m_value = value;
+ }
}
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 a66472a..53a1904 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
@@ -33,6 +33,7 @@
/**
* Handler managing the Configuration Admin.
+ *
* @author <a href="mailto:felix-dev@incubator.apache.org">Felix Project Team</a>
*/
public class ConfigurationHandler extends Handler {
@@ -48,8 +49,8 @@
private ConfigurableProperty[] m_configurableProperties = new ConfigurableProperty[0];
/**
- * ProvidedServiceHandler of the component.
- * It is useful to priopagate properties to service registrations.
+ * ProvidedServiceHandler of the component. It is useful to priopagate
+ * properties to service registrations.
*/
private ProvidedServiceHandler m_providedServiceHandler;
@@ -57,8 +58,7 @@
* Properties propagated at the last "updated".
*/
private Dictionary m_propagated = new Properties();
-
-
+
/**
* Properties to propage.
*/
@@ -75,12 +75,21 @@
private ServiceRegistration m_sr;
/**
+ * Get the instance manager.
* @return instance manager of this handler.
*/
- protected InstanceManager getInstanceManager() { return m_manager; }
+ protected InstanceManager getInstanceManager() {
+ return m_manager;
+ }
/**
- * @see org.apache.felix.ipojo.Handler#configure(org.apache.felix.ipojo.InstanceManager, org.apache.felix.ipojo.metadata.Element)
+ * Configure the handler.
+ *
+ * @param im : the instance manager
+ * @param metadata : the metadata of the component
+ * @param configuration : the instance configuration
+ * @see org.apache.felix.ipojo.Handler#configure(org.apache.felix.ipojo.InstanceManager,
+ * org.apache.felix.ipojo.metadata.Element)
*/
public void configure(InstanceManager im, Element metadata, Dictionary configuration) {
// Store the component manager
@@ -90,34 +99,41 @@
// Build the hashmap
Element[] confs = metadata.getElements("Properties", "");
- if (confs.length == 0) { return; }
+ if (confs.length == 0) {
+ return;
+ }
// Check if the component is dynamically configurable
m_isConfigurable = false;
- if (confs[0].containsAttribute("configurable") && confs[0].getAttribute("configurable").equalsIgnoreCase("true")) { m_isConfigurable = true; m_toPropagate = configuration; }
+ if (confs[0].containsAttribute("configurable") && confs[0].getAttribute("configurable").equalsIgnoreCase("true")) {
+ m_isConfigurable = true;
+ m_toPropagate = configuration;
+ }
Element[] configurables = confs[0].getElements("Property");
for (int i = 0; i < configurables.length; i++) {
String fieldName = configurables[i].getAttribute("field");
String name = null;
- if (configurables[i].containsAttribute("name")) {
- name = configurables[i].getAttribute("name");
- } else {
- name = fieldName;
+ if (configurables[i].containsAttribute("name")) {
+ name = configurables[i].getAttribute("name");
+ } else {
+ name = fieldName;
}
String value = null;
- if (configurables[i].containsAttribute("value")) { value = configurables[i].getAttribute("value"); }
-
- 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);
- }
+ if (configurables[i].containsAttribute("value")) {
+ value = configurables[i].getAttribute("value");
}
- // Detect the type of the property
+ 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);
+ }
+ }
+
+ // 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++) {
@@ -125,14 +141,18 @@
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; }
-
+ 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, null));
+
+ if (cp.getValue() != null) {
+ cd.addProperty(new PropertyDescription(name, type, cp.getValue().toString()));
+ } else {
+ cd.addProperty(new PropertyDescription(name, type, null));
}
addProperty(cp);
@@ -143,15 +163,16 @@
for (int k = 0; k < m_configurableProperties.length; k++) {
fields[k] = m_configurableProperties[k].getField();
- // Check if the instance configuration contains value for the current property :
+ // Check if the instance configuration contains value for the
+ // current property :
String name = m_configurableProperties[k].getName();
String fieldName = m_configurableProperties[k].getField();
- if (name != null && configuration.get(name) != null && !(configuration.get(name) instanceof String)) {
- m_configurableProperties[k].setValue(configuration.get(name));
- } else {
- if (fieldName != null && configuration.get(fieldName) != null && !(configuration.get(fieldName) instanceof String)) {
- m_configurableProperties[k].setValue(configuration.get(fieldName));
- }
+ if (name != null && configuration.get(name) != null && !(configuration.get(name) instanceof String)) {
+ m_configurableProperties[k].setValue(configuration.get(name));
+ } else {
+ if (fieldName != null && configuration.get(fieldName) != null && !(configuration.get(fieldName) instanceof String)) {
+ m_configurableProperties[k].setValue(configuration.get(fieldName));
+ }
}
}
m_manager.register(this, fields);
@@ -159,11 +180,16 @@
}
/**
+ * Stop method.
+ * Do nothing.
* @see org.apache.felix.ipojo.Handler#stop()
*/
- public void stop() { }
+ public void stop() {
+ }
/**
+ * Start method.
+ * Propagate properties if the propagation is activated.
* @see org.apache.felix.ipojo.Handler#start()
*/
public void start() {
@@ -172,14 +198,19 @@
// Propagation
if (m_isConfigurable) {
- for (int i = 0; i < m_configurableProperties.length; i++) {
- m_toPropagate.put(m_configurableProperties[i].getName(), m_configurableProperties[i].getValue());
- }
- reconfigure(m_toPropagate);
+ for (int i = 0; i < m_configurableProperties.length; i++) {
+ m_toPropagate.put(m_configurableProperties[i].getName(), m_configurableProperties[i].getValue());
+ }
+ reconfigure(m_toPropagate);
}
}
+
/**
+ * Setter Callback Method.
+ * Check if the modified field is a configurable property to update the value.
+ * @param fieldName : field name
+ * @param value : new value
* @see org.apache.felix.ipojo.Handler#setterCallback(java.lang.String, java.lang.Object)
*/
public void setterCallback(String fieldName, Object value) {
@@ -193,11 +224,17 @@
}
}
}
- //Else do nothing
+ // Else do nothing
}
/**
- * @see org.apache.felix.ipojo.Handler#getterCallback(java.lang.String, java.lang.Object)
+ * Getter Callback Method.
+ * Check if the field is a configurable property to push the stored value.
+ * @param fieldName : field name
+ * @param value : value pushed by the previous handler
+ * @return the stored value or the previous value.
+ * @see org.apache.felix.ipojo.Handler#getterCallback(java.lang.String,
+ * java.lang.Object)
*/
public Object getterCallback(String fieldName, Object value) {
// Check if the field is a configurable property
@@ -210,26 +247,35 @@
}
/**
- * @see org.apache.felix.ipojo.Handler#stateChanged(int)
+ * Handler state changed.
+ * @param state : the new instance state.
+ * @see org.apache.felix.ipojo.CompositeHandler#stateChanged(int)
*/
public void stateChanged(int state) {
if (state == InstanceManager.VALID) {
- if (m_sr == null) { start(); }
+ if (m_sr == null) {
+ start();
+ }
return;
}
if (state == InstanceManager.INVALID) {
- if (m_sr != null) { stop(); }
+ if (m_sr != null) {
+ stop();
+ }
return;
}
}
/**
* Add the given property metadata to the property metadata list.
+ *
* @param p : property metdata to add
*/
protected void addProperty(ConfigurableProperty p) {
for (int i = 0; (m_configurableProperties != null) && (i < m_configurableProperties.length); i++) {
- if (m_configurableProperties[i].getName().equals(p.getName())) { return; }
+ if (m_configurableProperties[i].getName().equals(p.getName())) {
+ return;
+ }
}
if (m_configurableProperties.length > 0) {
@@ -238,27 +284,33 @@
newProp[m_configurableProperties.length] = p;
m_configurableProperties = newProp;
} else {
- m_configurableProperties = new ConfigurableProperty[] {p};
+ m_configurableProperties = new ConfigurableProperty[] { p };
}
}
/**
* Check if the liste contains the property.
+ *
* @param name : name of the property
* @return true if the property exist in the list
*/
protected boolean containsProperty(String name) {
for (int i = 0; (m_configurableProperties != null) && (i < m_configurableProperties.length); i++) {
- if (m_configurableProperties[i].getName().equals(name)) { return true; }
+ if (m_configurableProperties[i].getName().equals(name)) {
+ return true;
+ }
}
return false;
}
-
+
/**
+ * Reconfigure the component instance.
+ * Check if the new configuration modify the current configuration.
+ * @param np : the new configuration
* @see org.apache.felix.ipojo.Handler#reconfigure(java.util.Dictionary)
*/
public void reconfigure(Dictionary np) {
- Properties toPropagate = new Properties();
+ Properties toPropagate = new Properties();
Enumeration keysEnumeration = np.keys();
while (keysEnumeration.hasMoreElements()) {
String name = (String) keysEnumeration.nextElement();
@@ -269,14 +321,19 @@
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_manager.setterCallback(m_configurableProperties[i].getField(), value); // says that the value has changed
+ m_manager.setterCallback(m_configurableProperties[i].getField(), value); // says
+ // that
+ // the
+ // value
+ // has
+ // changed
}
find = true;
// Else do nothing
}
}
if (!find) {
- //The property is not a configurable property
+ // The property is not a configurable property
toPropagate.put(name, value);
}
}
@@ -284,10 +341,10 @@
// Propagation of the properties to service registrations :
if (m_providedServiceHandler != null && !toPropagate.isEmpty()) {
m_providedServiceHandler.removeProperties(m_propagated);
-
+
// Remove to name props
toPropagate.remove("name");
-
+
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 64bc089..78059fd 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
@@ -32,6 +32,7 @@
/**
* Represent a service dependency of the component instance.
+ *
* @author <a href="mailto:felix-dev@incubator.apache.org">Felix Project Team</a>
*/
public class Dependency implements ServiceListener {
@@ -50,67 +51,64 @@
* Reference on the Dependency Handler.
*/
private DependencyHandler m_handler;
-
+
/**
* Field of the dependency.
*/
private String m_field;
-
+
/**
- * List of dependency callback.
+ * List of dependency callback.
*/
private DependencyCallback[] m_callbacks = new DependencyCallback[0];
-
+
/**
* Service Specification required by the dependency.
*/
private String m_specification;
-
+
/**
* Is the dependency a multiple dependency ?
*/
private boolean m_isMultiple = false;
-
+
/**
* Is the Dependency an optional dependency ?
*/
private boolean m_isOptional = false;
-
+
/**
* LDAP Filter of the Dependency (String form).
*/
private String m_strFilter;
-
/**
- * Array of Service Objects.
- * When cardinality = 1 : just the first element is returned
- * When cardinality = ?..n : all the array is returned
+ * Array of Service Objects. When cardinality = 1 : just the first element
+ * is returned When cardinality = ?..n : all the array is returned
* m_services : Array
*/
private Object[] m_services = new Object[0];
/**
- * Array of service references.
- * m_ref : Array
+ * Array of service references. m_ref : Array
*/
private ServiceReference[] m_ref = new ServiceReference[0];
/**
- * State of the dependency.
- * 0 : stopped, 1 : valid, 2 : invalid.
- * m_state : int
+ * State of the dependency. 0 : stopped, 1 : valid, 2 : invalid. m_state :
+ * int
*/
private int m_state;
/**
- * True if the reference list change after the creation of a service object array.
+ * True if the reference list change after the creation of a service object
+ * array.
*/
private boolean m_change;
/**
- * Class of the dependency.
- * Usefull to create in the case of multiple dependency
+ * Class of the dependency. Usefull to create in the case of multiple
+ * dependency
*/
private Class m_clazz;
@@ -119,9 +117,9 @@
*/
private Filter m_filter;
-
/**
* Dependency contructor. After the creation the dependency is not started.
+ *
* @param dh : the dependency handler managing this dependency
* @param field : field of the dependency
* @param spec : required specification
@@ -136,39 +134,44 @@
m_strFilter = filter;
}
- /**
- * @return the field attached to the dependency.
- */
- public String getField() { return m_field; }
-
- /**
- * @return the specification tracked by the dependency.
- */
- public String getSpecification() { return m_specification; }
-
- /**
- * @return true is the dependency is optional.
- */
- public boolean isOptional() { return m_isOptional; }
-
- /**
- * @return true if the dependency is multiple.
- */
- public boolean isMultiple() { return m_isMultiple; }
-
+ public String getField() {
+ return m_field;
+ }
+
+
+ public String getSpecification() {
+ return m_specification;
+ }
+
+
+ public boolean isOptional() {
+ return m_isOptional;
+ }
+
+
+ public boolean isMultiple() {
+ return m_isMultiple;
+ }
+
/**
* Set the dependency to multiple.
*/
- protected void setMultiple() { m_isMultiple = true; }
-
+ protected void setMultiple() {
+ m_isMultiple = true;
+ }
+
/**
* Set the tracked specification for this dependency.
+ *
* @param spec : the tracked specification (interface name)
*/
- protected void setSpecification(String spec) { m_specification = spec; }
-
+ protected void setSpecification(String spec) {
+ m_specification = spec;
+ }
+
/**
* Add a callback to the dependency.
+ *
* @param cb : callback to add
*/
protected void addDependencyCallback(DependencyCallback cb) {
@@ -178,37 +181,43 @@
newCallbacks[m_callbacks.length] = cb;
m_callbacks = newCallbacks;
} else {
- m_callbacks = new DependencyCallback[] {cb};
+ m_callbacks = new DependencyCallback[] { cb };
}
}
-
- /**
- * @return the filter attached to the dependency.
- */
- public String getFilter() { return m_strFilter; }
+
+
+ public String getFilter() {
+ return m_strFilter;
+ }
+
+
+ public DependencyHandler getDependencyHandler() {
+ return m_handler;
+ }
/**
- * @return the dependency handler of this dependency.
- */
- public DependencyHandler getDependencyHandler() { return m_handler; }
-
- /**
+ * Build the map [service object, service reference] of used services.
* @return the used service.
*/
public HashMap getUsedServices() {
HashMap hm = new HashMap();
if (m_isMultiple) {
for (int i = 0; i < m_ref.length; i++) {
- if (i < m_services.length) { hm.put(((Object) m_services[i]).toString(), m_ref[i]); }
+ if (i < m_services.length) {
+ hm.put(((Object) m_services[i]).toString(), m_ref[i]);
+ }
}
} else {
- if (m_ref.length != 0 && m_services.length != 0) { hm.put((m_services[0]).toString(), m_ref[0]); }
+ if (m_ref.length != 0 && m_services.length != 0) {
+ hm.put((m_services[0]).toString(), m_ref[0]);
+ }
}
return hm;
}
/**
* A dependency is satisfied if it is optional of ref.length != 0.
+ *
* @return true is the dependency is satified
*/
protected boolean isSatisfied() {
@@ -216,28 +225,35 @@
}
/**
- * This method is called by the replaced code in the component implementation class.
- * Construct the service object list is necessary.
- * @return null or a service object or a list of service object according to the dependency.
+ * This method is called by the replaced code in the component
+ * implementation class. Construct the service object list is necessary.
+ *
+ * @return null or a service object or a list of service object according to
+ * the dependency.
*/
protected Object get() {
- // 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());
+ // 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 :
if (!m_change) {
if (!m_isMultiple) {
if (m_services.length > 0) {
- return m_services[0];
+ return m_services[0];
}
} else {
return m_services;
}
}
- // 2 : Else there is a change in the list -> recompute the m_services array
- m_handler.getInstanceManager().getFactory().getLogger().log(Logger.INFO, "[" + m_handler.getInstanceManager().getClassName() + "] Create a service array of " + m_clazz.getName());
+ // 2 : Else there is a change in the list -> recompute the
+ // m_services array
+ 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++) {
@@ -245,49 +261,69 @@
}
m_change = false;
- // m_handler.getInstanceManager().getFactory().getLogger().log(Logger.INFO, "[" + m_handler.getInstanceManager().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.
+ // 3 : The service object list is populated, I return either the
+ // first service object, either the array.
// Return null or an empty array if no service are found.
if (!m_isMultiple) {
if (m_services.length > 0) {
return m_services[0];
} else {
// Load the nullable class
- //String[] segment = m_metadata.getServiceSpecification().split("[.]");
- //String className = "org.apache.felix.ipojo." + segment[segment.length - 1] + "Nullable";
- String className = m_specification + "Nullable";
- // m_handler.getInstanceManager().getFactory().getLogger().log(Logger.INFO, "[" + m_handler.getInstanceManager().getClassName() + "] Try to load the nullable class for " + getMetadata().getServiceSpecification() + " -> " + className);
+ // String[] segment =
+ // m_metadata.getServiceSpecification().split("[.]");
+ // String className = "org.apache.felix.ipojo." +
+ // segment[segment.length - 1] + "Nullable";
+ String className = m_specification + "Nullable";
+ // 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) {
- m_handler.getInstanceManager().getFactory().getLogger().log(Logger.INFO, "[" + m_handler.getInstanceManager().getClassName() + "] Cannot load the nullable class to return a dependency object for " + m_field + " -> " + m_specification);
+ m_handler.getInstanceManager().getFactory().getLogger().log(
+ Logger.INFO,
+ "[" + m_handler.getInstanceManager().getClassName() + "] Cannot load the nullable class to return a dependency object for "
+ + m_field + " -> " + m_specification);
return null;
}
- // The nullable class is loaded, create the object and return it
+ // The nullable class is loaded, create the object and
+ // return it
Object instance = nullableClazz.newInstance();
- // m_handler.getInstanceManager().getFactory().getLogger().log(Logger.INFO, "[" + m_handler.getInstanceManager().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;
}
} else { // Multiple dependency
return m_services;
}
} catch (Exception e) {
- // There is a problem in the dependency resolving (like in stopping method)
+ // There is a problem in the dependency resolving (like in stopping
+ // method)
if (!m_isMultiple) {
- 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;
+ 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 {
- 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);
+ 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);
}
}
}
/**
* Method calld when a service event is throwed.
+ *
* @see org.osgi.framework.ServiceListener#serviceChanged(org.osgi.framework.ServiceEvent)
* @param event : the received service event
*/
@@ -296,26 +332,28 @@
// If a service goes way.
if (event.getType() == ServiceEvent.UNREGISTERING) {
- if (containsSR(event.getServiceReference())) { departureManagement(event.getServiceReference()); }
+ if (containsSR(event.getServiceReference())) {
+ departureManagement(event.getServiceReference());
+ }
return;
}
// If a service arrives
if (event.getType() == ServiceEvent.REGISTERED) {
- if (m_filter.match(event.getServiceReference())) {
- arrivalManagement(event.getServiceReference());
+ if (m_filter.match(event.getServiceReference())) {
+ arrivalManagement(event.getServiceReference());
}
return;
}
// If a service is modified
if (event.getType() == ServiceEvent.MODIFIED) {
if (m_filter.match(event.getServiceReference())) {
- if (!containsSR(event.getServiceReference())) {
- arrivalManagement(event.getServiceReference());
+ if (!containsSR(event.getServiceReference())) {
+ arrivalManagement(event.getServiceReference());
}
} else {
- if (containsSR(event.getServiceReference())) {
- departureManagement(event.getServiceReference());
+ if (containsSR(event.getServiceReference())) {
+ departureManagement(event.getServiceReference());
}
}
return;
@@ -326,27 +364,34 @@
/**
* Method called when a service arrives.
+ *
* @param ref : the arriving service reference
*/
private void arrivalManagement(ServiceReference ref) {
- // Add the new service inside the ref list
- 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;
- if (m_isMultiple || m_ref.length == 1) { m_change = true; callBindMethod(ref); }
+ if (m_isMultiple || m_ref.length == 1) {
+ m_change = true;
+ callBindMethod(ref);
+ }
}
m_handler.checkContext();
}
/**
* Method called when a service goes away.
+ *
* @param ref : the leaving service reference
*/
private void departureManagement(ServiceReference ref) {
// Call unbind method
- if (!m_isMultiple && ref == m_ref[0]) { callUnbindMethod(ref); }
- if (m_isMultiple) { callUnbindMethod(ref); }
+ if (!m_isMultiple && ref == m_ref[0]) {
+ callUnbindMethod(ref);
+ }
+ if (m_isMultiple) {
+ callUnbindMethod(ref);
+ }
// Unget the service reference
m_handler.getInstanceManager().getContext().ungetService(ref);
@@ -362,10 +407,16 @@
// Is there any change ?
if (!m_isMultiple && index == 0) {
m_change = true;
- if (m_ref.length != 0) { callBindMethod(m_ref[0]); }
+ if (m_ref.length != 0) {
+ callBindMethod(m_ref[0]);
+ }
}
- if (!m_isMultiple && index != 0) { m_change = false; }
- if (m_isMultiple) { m_change = true; }
+ if (!m_isMultiple && index != 0) {
+ m_change = false;
+ }
+ if (m_isMultiple) {
+ m_change = true;
+ }
m_handler.checkContext();
return;
@@ -373,46 +424,64 @@
/**
* Call unbind callback method.
+ *
* @param ref : reference to send (if accepted) to the method
*/
private void callUnbindMethod(ServiceReference ref) {
if (m_handler.getInstanceManager().getState() == InstanceManager.VALID) {
for (int i = 0; i < m_callbacks.length; i++) {
if (m_callbacks[i].getMethodType() == DependencyCallback.UNBIND) {
- // Try to call the bind method with a service reference inside
+ // Try to call the bind method with a service reference
+ // inside
try {
m_callbacks[i].call(ref);
} catch (NoSuchMethodException e) {
- // The method was not found : try without service reference
+ // The method was not found : try without service
+ // reference
try {
m_callbacks[i].call();
} catch (NoSuchMethodException e1) {
- // The method was not found : try with the service object
+ // The method was not found : try with the service
+ // object
try {
m_callbacks[i].call(m_handler.getInstanceManager().getContext().getService(ref));
} catch (NoSuchMethodException e2) {
- m_handler.getInstanceManager().getFactory().getLogger().log(Logger.ERROR, "[" + m_handler.getInstanceManager().getClassName() + "] Dependency Callback Error : Unbind method not found", e2);
+ m_handler.getInstanceManager().getFactory().getLogger().log(Logger.ERROR,
+ "[" + m_handler.getInstanceManager().getClassName() + "] Dependency Callback Error : Unbind method not found", e2);
return;
} catch (IllegalAccessException e2) {
- m_handler.getInstanceManager().getFactory().getLogger().log(Logger.ERROR, "[" + m_handler.getInstanceManager().getClassName() + "] Dependency Callback Error : Illegal access on unbind method", e2);
+ 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) {
- m_handler.getInstanceManager().getFactory().getLogger().log(Logger.ERROR, "[" + m_handler.getInstanceManager().getClassName() + "] Dependency Callback Error : Invocation Target Exception in the unbind method", e2);
+ 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) {
- m_handler.getInstanceManager().getFactory().getLogger().log(Logger.ERROR, "[" + m_handler.getInstanceManager().getClassName() + "] Dependency Callback Error : Illegal access on unbind method", e1);
+ 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) {
- m_handler.getInstanceManager().getFactory().getLogger().log(Logger.ERROR, "[" + m_handler.getInstanceManager().getClassName() + "] Dependency Callback Error : Invocation Target Exception in the unbind method", e1);
+ 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) {
- m_handler.getInstanceManager().getFactory().getLogger().log(Logger.ERROR, "[" + m_handler.getInstanceManager().getClassName() + "] Dependency Callback Error : Illegal access on bind method", e);
+ 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) {
- m_handler.getInstanceManager().getFactory().getLogger().log(Logger.ERROR, "[" + m_handler.getInstanceManager().getClassName() + "] Dependency Callback Error : Invocation Target Exception in the bind method", e);
+ m_handler.getInstanceManager().getFactory().getLogger().log(
+ Logger.ERROR,
+ "[" + m_handler.getInstanceManager().getClassName()
+ + "] Dependency Callback Error : Invocation Target Exception in the bind method", e);
return;
}
}
@@ -422,50 +491,75 @@
/**
* Call the bind method.
+ *
* @param instance : instance on which calling the bind method.
*/
protected void callBindMethod(Object instance) {
- // Check optional case : nullable object case : do not call bind on nullable object
- if (m_isOptional && m_ref.length == 0) { return; }
-
+ // Check optional case : nullable object case : do not call bind on
+ // nullable object
+ if (m_isOptional && m_ref.length == 0) {
+ return;
+ }
if (m_isMultiple) {
for (int i = 0; i < m_ref.length; i++) {
for (int j = 0; j < m_callbacks.length; j++) {
if (m_callbacks[j].getMethodType() == DependencyCallback.BIND) {
- // Try to call the bind method with a service reference inside
+ // Try to call the bind method with a service reference
+ // inside
try {
m_callbacks[j].callOnInstance(instance, m_ref[i]);
} catch (NoSuchMethodException e) {
- // The method was not found : try without service reference
+ // The method was not found : try without service
+ // reference
try {
m_callbacks[j].callOnInstance(instance);
} catch (NoSuchMethodException e1) {
- // The method was not found : try with the service object
+ // The method was not found : try with the
+ // service object
try {
m_callbacks[j].callOnInstance(instance, m_handler.getInstanceManager().getContext().getService(m_ref[i]));
} catch (NoSuchMethodException e2) {
- m_handler.getInstanceManager().getFactory().getLogger().log(Logger.ERROR, "[" + m_handler.getInstanceManager().getClassName() + "] Dependency Callback Error : Bind method not found", e2);
+ m_handler.getInstanceManager().getFactory().getLogger().log(Logger.ERROR,
+ "[" + m_handler.getInstanceManager().getClassName() + "] Dependency Callback Error : Bind method not found", e2);
return;
} catch (IllegalAccessException e2) {
- m_handler.getInstanceManager().getFactory().getLogger().log(Logger.ERROR, "[" + m_handler.getInstanceManager().getClassName() + "] Dependency Callback Error : Illegal access on bind method", e2);
+ 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) {
- m_handler.getInstanceManager().getFactory().getLogger().log(Logger.ERROR, "[" + m_handler.getInstanceManager().getClassName() + "] Dependency Callback Error : Invocation Target Exception in the bind method", e2);
+ 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) {
- m_handler.getInstanceManager().getFactory().getLogger().log(Logger.ERROR, "[" + m_handler.getInstanceManager().getClassName() + "] Dependency Callback Error : Illegal access on bind method", e1);
+ 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) {
- m_handler.getInstanceManager().getFactory().getLogger().log(Logger.ERROR, "[" + m_handler.getInstanceManager().getClassName() + "] Dependency Callback Error : Invocation Target Exception in the bind method", e1);
+ 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) {
- m_handler.getInstanceManager().getFactory().getLogger().log(Logger.ERROR, "[" + m_handler.getInstanceManager().getClassName() + "] Dependency Callback Error : Illegal access on bind method", e);
+ 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) {
- m_handler.getInstanceManager().getFactory().getLogger().log(Logger.ERROR, "[" + m_handler.getInstanceManager().getClassName() + "] Dependency Callback Error : Invocation Target Exception in the bind method" + e);
+ m_handler.getInstanceManager().getFactory().getLogger().log(
+ Logger.ERROR,
+ "[" + m_handler.getInstanceManager().getClassName()
+ + "] Dependency Callback Error : Invocation Target Exception in the bind method" + e);
return;
}
}
@@ -474,40 +568,59 @@
} else {
for (int j = 0; j < m_callbacks.length; j++) {
if (m_callbacks[j].getMethodType() == DependencyCallback.BIND) {
- // Try to call the bind method with a service reference inside
+ // Try to call the bind method with a service reference
+ // inside
try {
m_callbacks[j].callOnInstance(instance, m_ref[0]);
} catch (NoSuchMethodException e) {
- // The method was not found : try without service reference
+ // The method was not found : try without service
+ // reference
try {
m_callbacks[j].callOnInstance(instance);
} catch (NoSuchMethodException e1) {
- // The method was not found : try with the service object
+ // The method was not found : try with the service
+ // object
try {
m_callbacks[j].callOnInstance(instance, m_handler.getInstanceManager().getContext().getService(m_ref[0]));
} catch (NoSuchMethodException e2) {
- m_handler.getInstanceManager().getFactory().getLogger().log(Logger.ERROR, "[" + m_handler.getInstanceManager().getClassName() + "] Dependency Callback Error : Bind method not found", e2);
+ m_handler.getInstanceManager().getFactory().getLogger().log(Logger.ERROR,
+ "[" + m_handler.getInstanceManager().getClassName() + "] Dependency Callback Error : Bind method not found", e2);
return;
} catch (IllegalAccessException e2) {
- m_handler.getInstanceManager().getFactory().getLogger().log(Logger.ERROR, "[" + m_handler.getInstanceManager().getClassName() + "] Dependency Callback Error : Illegal access on bind method", e2);
+ 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) {
- m_handler.getInstanceManager().getFactory().getLogger().log(Logger.ERROR, "[" + m_handler.getInstanceManager().getClassName() + "] Dependency Callback Error : Invocation Target Exception in the bind method", e2);
+ 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) {
- m_handler.getInstanceManager().getFactory().getLogger().log(Logger.ERROR, "[" + m_handler.getInstanceManager().getClassName() + "] Dependency Callback Error : Illegal access on bind method", e1);
+ 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) {
- m_handler.getInstanceManager().getFactory().getLogger().log(Logger.ERROR, "[" + m_handler.getInstanceManager().getClassName() + "] Dependency Callback Error : Invocation Target Exception in the bind method", e1);
+ 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) {
- m_handler.getInstanceManager().getFactory().getLogger().log(Logger.ERROR, "[" + m_handler.getInstanceManager().getClassName() + "] Dependency Callback Error : Illegal access on bind method", e);
+ 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) {
- m_handler.getInstanceManager().getFactory().getLogger().log(Logger.ERROR, "[" + m_handler.getInstanceManager().getClassName() + "] Dependency Callback Error : Invocation Target Exception in the bind method", e);
+ m_handler.getInstanceManager().getFactory().getLogger().log(
+ Logger.ERROR,
+ "[" + m_handler.getInstanceManager().getClassName()
+ + "] Dependency Callback Error : Invocation Target Exception in the bind method", e);
return;
}
}
@@ -517,6 +630,7 @@
/**
* Call bind method with the service reference in parameter (if accepted).
+ *
* @param ref : the service reference of the new service
*/
private void callBindMethod(ServiceReference ref) {
@@ -524,41 +638,61 @@
if (m_handler.getInstanceManager().getState() == InstanceManager.VALID) {
for (int i = 0; i < m_callbacks.length; i++) {
if (m_callbacks[i].getMethodType() == DependencyCallback.BIND) {
- // Try to call the bind method with a service reference inside
+ // Try to call the bind method with a service reference
+ // inside
try {
m_callbacks[i].call(ref);
} catch (NoSuchMethodException e) {
- // The method was not found : try without service reference
+ // The method was not found : try without service
+ // reference
try {
- m_handler.getInstanceManager().getFactory().getLogger().log(Logger.INFO, "[" + m_handler.getInstanceManager().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_callbacks[i].call();
} catch (NoSuchMethodException e1) {
- // The method was not found : try with the service object
+ // The method was not found : try with the service
+ // object
try {
m_callbacks[i].call(m_handler.getInstanceManager().getContext().getService(ref));
} catch (NoSuchMethodException e2) {
- m_handler.getInstanceManager().getFactory().getLogger().log(Logger.ERROR, "[" + m_handler.getInstanceManager().getClassName() + "] Dependency Callback Error : Bind method not found", e2);
+ m_handler.getInstanceManager().getFactory().getLogger().log(Logger.ERROR,
+ "[" + m_handler.getInstanceManager().getClassName() + "] Dependency Callback Error : Bind method not found", e2);
return;
} catch (IllegalAccessException e2) {
- m_handler.getInstanceManager().getFactory().getLogger().log(Logger.ERROR, "[" + m_handler.getInstanceManager().getClassName() + "] Dependency Callback Error : Illegal access on bind method", e2);
+ 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) {
- m_handler.getInstanceManager().getFactory().getLogger().log(Logger.ERROR, "[" + m_handler.getInstanceManager().getClassName() + "] Dependency Callback Error : Invocation Target Exception in the bind method", e2);
+ 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) {
- m_handler.getInstanceManager().getFactory().getLogger().log(Logger.ERROR, "[" + m_handler.getInstanceManager().getClassName() + "] Dependency Callback Error : Illegal access on bind method", e1);
+ 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) {
- m_handler.getInstanceManager().getFactory().getLogger().log(Logger.ERROR, "[" + m_handler.getInstanceManager().getClassName() + "] Dependency Callback Error : Invocation Target Exception in the bind method", e1);
+ 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) {
- m_handler.getInstanceManager().getFactory().getLogger().log(Logger.ERROR, "[" + m_handler.getInstanceManager().getClassName() + "] Dependency Callback Error : Illegal access on bind method", e);
+ 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) {
- m_handler.getInstanceManager().getFactory().getLogger().log(Logger.ERROR, "[" + m_handler.getInstanceManager().getClassName() + "] Dependency Callback Error : Invocation Target Exception in the bind method", e);
+ m_handler.getInstanceManager().getFactory().getLogger().log(
+ Logger.ERROR,
+ "[" + m_handler.getInstanceManager().getClassName()
+ + "] Dependency Callback Error : Invocation Target Exception in the bind method", e);
return;
}
}
@@ -579,30 +713,37 @@
filter = classnamefilter;
}
- m_handler.getInstanceManager().getFactory().getLogger().log(Logger.INFO, "[" + m_handler.getInstanceManager().getClassName() + "] Start a dependency on : " + m_specification + " with " + m_strFilter);
+ m_handler.getInstanceManager().getFactory().getLogger().log(Logger.INFO,
+ "[" + m_handler.getInstanceManager().getClassName() + "] Start a dependency on : " + m_specification + " with " + m_strFilter);
m_state = UNRESOLVED;
try {
m_clazz = m_handler.getInstanceManager().getContext().getBundle().loadClass(m_specification);
} catch (ClassNotFoundException e) {
- System.err.println("Cannot load the interface class for the dependency " + m_field + " [" + m_specification + "]");
- e.printStackTrace();
+ m_handler.getInstanceManager().getFactory().getLogger().log(Logger.ERROR,
+ "Cannot load the interface class for the dependency " + m_field + " [" + m_specification + "]");
}
try {
// Look if the service is already present :
ServiceReference[] sr = m_handler.getInstanceManager().getContext().getServiceReferences(m_specification, filter);
if (sr != null) {
- for (int i = 0; i < sr.length; i++) { addReference(sr[i]); }
+ for (int i = 0; i < sr.length; i++) {
+ addReference(sr[i]);
+ }
m_state = RESOLVED;
}
// Register a listener :
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_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) {
- m_handler.getInstanceManager().getFactory().getLogger().log(Logger.ERROR, "[" + m_handler.getInstanceManager().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();
}
}
@@ -611,7 +752,8 @@
* Stop the dependency.
*/
public void stop() {
- m_handler.getInstanceManager().getFactory().getLogger().log(Logger.INFO, "[" + m_handler.getInstanceManager().getClassName() + "] Stop a dependency on : " + m_specification + " with " + m_strFilter);
+ m_handler.getInstanceManager().getFactory().getLogger().log(Logger.INFO,
+ "[" + m_handler.getInstanceManager().getClassName() + "] Stop a dependency on : " + m_specification + " with " + m_strFilter);
m_state = UNRESOLVED;
// Unget all services references
@@ -627,14 +769,20 @@
/**
* Return the state of the dependency.
+ *
* @return the state of the dependency (1 : valid, 2 : invalid)
*/
public int getState() {
- return (m_isOptional) ? 1 : m_state;
+ if (m_isOptional) {
+ return 1;
+ } else {
+ return m_state;
+ }
}
/**
* Return the list of service reference.
+ *
* @return the service reference list.
*/
public ServiceReference[] getServiceReferences() {
@@ -643,6 +791,7 @@
/**
* Add a service reference in the current list.
+ *
* @param r : the new service reference to add
*/
private void addReference(ServiceReference r) {
@@ -658,12 +807,13 @@
newSR[m_ref.length] = r;
m_ref = newSR;
} else {
- m_ref = new ServiceReference[] {r};
+ m_ref = new ServiceReference[] { r };
}
}
/**
* Find if a service registration il already registred.
+ *
* @param sr : the service registration to find.
* @return true if the service registration is already in the array
*/
@@ -678,8 +828,10 @@
/**
* Remove a service reference in the current list.
+ *
* @param r : the new service reference to remove
- * @return the index of the founded element, or -1 if the element is not found
+ * @return the index of the founded element, or -1 if the element is not
+ * found
*/
private int removeReference(ServiceReference r) {
if (m_ref == null) {
@@ -701,9 +853,8 @@
} else { // Otherwise, we need to do some array copying.
ServiceReference[] newSR = new ServiceReference[m_ref.length - 1];
System.arraycopy(m_ref, 0, newSR, 0, idx);
- if (idx < newSR.length) {
- System.arraycopy(
- m_ref, idx + 1, newSR, idx, newSR.length - idx);
+ if (idx < newSR.length) {
+ System.arraycopy(m_ref, idx + 1, newSR, idx, newSR.length - idx);
}
m_ref = newSR;
}
@@ -711,5 +862,4 @@
return idx;
}
-
}
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 d197cb6..33a8fa6 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
@@ -25,9 +25,10 @@
import org.apache.felix.ipojo.util.Logger;
import org.osgi.framework.ServiceReference;
-
/**
- * This class allwos the creation of callback when service dependency arrives or disappear.
+ * This class allwos the creation of callback when service dependency arrives or
+ * disappear.
+ *
* @author <a href="mailto:felix-dev@incubator.apache.org">Felix Project Team</a>
*/
public class DependencyCallback {
@@ -51,12 +52,12 @@
* Callback method name.
*/
private String m_callback;
-
+
/**
* Is the callback a static callback.
*/
private boolean m_isStatic;
-
+
/**
* The instance manager.
*/
@@ -64,9 +65,11 @@
/**
* Constructor.
+ *
* @param dep : the dependency attached to this depednency callback
* @param method : the method to call
- * @param methodType : is the method to call a bind method or an unbind method
+ * @param methodType : is the method to call a bind method or an unbind
+ * method
* @param isStatic : is the method to call static ?
*/
public DependencyCallback(Dependency dep, String method, int methodType, boolean isStatic) {
@@ -76,31 +79,33 @@
m_manager = dep.getDependencyHandler().getInstanceManager();
}
- /**
- * @return the method type.
- */
- public int getMethodType() { return m_methodType; }
+
+ public int getMethodType() {
+ return m_methodType;
+ }
/**
* Call the callback method.
+ *
* @throws NoSuchMethodException : Method is not found in the class
* @throws InvocationTargetException : The method is not static
* @throws IllegalAccessException : The method can not be invoked
*/
protected void call() throws NoSuchMethodException, IllegalAccessException, InvocationTargetException {
- // Get the method object
- Method method = m_manager.getClazz().getDeclaredMethod(m_callback, new Class[] {});
- method.setAccessible(true);
-
- if (m_isStatic) {
- method.invoke(null, new Object[] {});
+ // Get the method object
+ Method method = m_manager.getClazz().getDeclaredMethod(m_callback, new Class[] {});
+ method.setAccessible(true);
+
+ if (m_isStatic) {
+ method.invoke(null, new Object[] {});
} else {
// Two cases :
// - if instances already exists : call on each instances
// - if no instance exists : create an instance
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[]{});
+ 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.getPojoObjects().length; i++) {
method.invoke(m_manager.getPojoObjects()[i], new Object[] {});
@@ -111,28 +116,30 @@
/**
* Call the callback method with a service reference.
+ *
* @param ref : the service reference to send to the method
* @throws NoSuchMethodException : Method is not found in the class
* @throws InvocationTargetException : The method is not static
* @throws IllegalAccessException : The method can not be invoked
*/
protected void call(ServiceReference ref) throws NoSuchMethodException, IllegalAccessException, InvocationTargetException {
- // Get the method object
- Method method = m_manager.getClazz().getDeclaredMethod(m_callback, new Class[] {ServiceReference.class});
- method.setAccessible(true);
-
- if (m_isStatic) {
- method.invoke(null, new Object[] {ref});
+ // Get the method object
+ Method method = m_manager.getClazz().getDeclaredMethod(m_callback, new Class[] { ServiceReference.class });
+ method.setAccessible(true);
+
+ if (m_isStatic) {
+ method.invoke(null, new Object[] { ref });
} else {
// Two cases :
// - if instances already exists : call on each instances
// - if no instance exists : create an instance
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[]{ref});
+ m_manager.getFactory().getLogger()
+ .log(Logger.INFO, "[" + m_manager.getClassName() + "] Create the first instance " + m_manager.getPojoObject());
+ method.invoke(m_manager.getPojoObject(), new Object[] { ref });
} else {
for (int i = 0; i < m_manager.getPojoObjects().length; i++) {
- method.invoke(m_manager.getPojoObjects()[i], new Object[] {ref});
+ method.invoke(m_manager.getPojoObjects()[i], new Object[] { ref });
}
}
}
@@ -140,28 +147,30 @@
/**
* Call the callback method with an object.
+ *
* @param o : the object to send to the method
* @throws NoSuchMethodException : Method is not found in the class
* @throws InvocationTargetException : The method is not static
* @throws IllegalAccessException : The method can not be invoked
*/
protected void call(Object o) throws NoSuchMethodException, IllegalAccessException, InvocationTargetException {
- // Get the method object
- Method method = m_manager.getClazz().getDeclaredMethod(m_callback, new Class[] {Object.class});
- method.setAccessible(true);
-
- if (m_isStatic) {
- method.invoke(null, new Object[] {o});
+ // Get the method object
+ Method method = m_manager.getClazz().getDeclaredMethod(m_callback, new Class[] { Object.class });
+ method.setAccessible(true);
+
+ if (m_isStatic) {
+ method.invoke(null, new Object[] { o });
} else {
// Two cases :
// - if instances already exists : call on each instances
// - if no instance exists : create an instance
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[]{o});
+ m_manager.getFactory().getLogger()
+ .log(Logger.INFO, "[" + m_manager.getClassName() + "] Create the first instance " + m_manager.getPojoObject());
+ method.invoke(m_manager.getPojoObject(), new Object[] { o });
} else {
for (int i = 0; i < m_manager.getPojoObjects().length; i++) {
- method.invoke(m_manager.getPojoObjects()[i], new Object[] {o});
+ method.invoke(m_manager.getPojoObjects()[i], new Object[] { o });
}
}
}
@@ -169,19 +178,21 @@
/**
* Call the callback on the given instance with no parameters.
+ *
* @param instance : the instance on which call the callback
* @throws NoSuchMethodException : the method is not found
* @throws IllegalAccessException : the method could not be called
* @throws InvocationTargetException : an error happens in the called method
*/
- protected void callOnInstance(Object instance) throws NoSuchMethodException, IllegalAccessException, InvocationTargetException {
- Method method = instance.getClass().getDeclaredMethod(m_callback, new Class[] {});
- method.setAccessible(true);
- method.invoke(instance, new Object[] {});
- }
+ protected void callOnInstance(Object instance) throws NoSuchMethodException, IllegalAccessException, InvocationTargetException {
+ Method method = instance.getClass().getDeclaredMethod(m_callback, new Class[] {});
+ method.setAccessible(true);
+ method.invoke(instance, new Object[] {});
+ }
/**
* Call the callback on the given instance with the given argument.
+ *
* @param instance : the instance on which call the callback
* @param ref : the service reference to send to the callback
* @throws NoSuchMethodException : the method is not found
@@ -190,13 +201,14 @@
* @throws InvocationTargetException
*/
protected void callOnInstance(Object instance, ServiceReference ref) throws NoSuchMethodException, IllegalAccessException, InvocationTargetException {
- Method method = instance.getClass().getDeclaredMethod(m_callback, new Class[] {ServiceReference.class});
- method.setAccessible(true);
- method.invoke(instance, new Object[] {ref});
+ Method method = instance.getClass().getDeclaredMethod(m_callback, new Class[] { ServiceReference.class });
+ method.setAccessible(true);
+ method.invoke(instance, new Object[] { ref });
}
-
+
/**
* Call the callback on the given instance with the given argument.
+ *
* @param instance : the instance on which call the callback
* @param o : the service object to send to the callback
* @throws NoSuchMethodException : the method is not found
@@ -205,8 +217,8 @@
* @throws InvocationTargetException
*/
protected void callOnInstance(Object instance, Object o) throws NoSuchMethodException, IllegalAccessException, InvocationTargetException {
- Method method = instance.getClass().getDeclaredMethod(m_callback, new Class[] {Object.class});
- method.setAccessible(true);
- method.invoke(instance, new Object[] {o});
+ Method method = instance.getClass().getDeclaredMethod(m_callback, new Class[] { Object.class });
+ method.setAccessible(true);
+ method.invoke(instance, new Object[] { o });
}
}
diff --git a/ipojo/src/main/java/org/apache/felix/ipojo/handlers/dependency/DependencyDescription.java b/ipojo/src/main/java/org/apache/felix/ipojo/handlers/dependency/DependencyDescription.java
index 6919911..8da733c 100644
--- a/ipojo/src/main/java/org/apache/felix/ipojo/handlers/dependency/DependencyDescription.java
+++ b/ipojo/src/main/java/org/apache/felix/ipojo/handlers/dependency/DependencyDescription.java
@@ -63,29 +63,14 @@
*/
private ServiceReference[] m_serviceReferences;
- /**
- * @return true if the dependency is a multiple dependency.
- */
public boolean isMultiple() { return m_multiple; }
- /**
- * @return true if the dependency is an optional dependency.
- */
public boolean isOptional() { return m_optional; }
- /**
- * @return the filter.
- */
public String getFilter() { return m_filter; }
- /**
- * @return the needed interface.
- */
public String getInterface() { return m_interface; }
- /**
- * @return the state of the dependency.
- */
public int getState() { return m_state; }
/**
@@ -107,11 +92,13 @@
}
/**
+ * Get the service refrence array.
* @return the array of service reference (only if the cardinality could be n).
*/
public ServiceReference[] getServiceReferences() { return m_serviceReferences; }
/**
+ * Get the service reference if only 1 used.
* @return the ServiceReference (only if the cardinality could be 1).
*/
public ServiceReference getServiceReference() { return m_serviceReferences[0]; }
@@ -123,6 +110,7 @@
public void setServiceReferences(ServiceReference[] sr) { m_serviceReferences = sr; }
/**
+ * Get the used service map.
* @return the hashmap [object reference, service reference] containing the used services
*/
public HashMap getUsedServices() { return m_usedServices; }
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 210f0e5..93cecdd 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
@@ -30,6 +30,7 @@
/**
* The dependency handler manages a list of dependencies.
+ *
* @author <a href="mailto:felix-dev@incubator.apache.org">Felix Project Team</a>
*/
public class DependencyHandler extends Handler {
@@ -54,10 +55,11 @@
*/
private int m_state;
-// ===================== Fields getters & setters =====================
+ // ===================== Fields getters & setters =====================
/**
* Add a dependency.
+ *
* @param dep : the dependency to add
*/
private void addDependency(Dependency dep) {
@@ -72,12 +74,13 @@
newDep[m_dependencies.length] = dep;
m_dependencies = newDep;
} else {
- m_dependencies = new Dependency[] {dep};
+ m_dependencies = new Dependency[] { dep };
}
}
/**
* Add a nullable class.
+ *
* @param clazz : the class to add
*/
private void addNullableClass(Class clazz) {
@@ -92,21 +95,27 @@
newClass[m_nullableClasses.length] = clazz;
m_nullableClasses = newClass;
} else {
- m_nullableClasses = new Class[] {clazz};
+ m_nullableClasses = new Class[] { clazz };
}
}
/**
+ * Get the list of managed dependency.
* @return the dependency list
*/
- public Dependency[] getDependencies() { return m_dependencies; }
+ public Dependency[] getDependencies() {
+ return m_dependencies;
+ }
/**
+ * Get the instance manager.
* @return the instance manager
*/
- protected InstanceManager getInstanceManager() { return m_manager; }
+ protected InstanceManager getInstanceManager() {
+ return m_manager;
+ }
-// ===================== Handler implementation =====================
+ // ===================== Handler implementation =====================
/**
* Check the validity of the dependencies.
@@ -124,7 +133,7 @@
if (validateComponentDependencies()) {
// The dependencies are valid
if (initialState == InstanceManager.INVALID) {
- //There is a state change
+ // There is a state change
m_state = InstanceManager.VALID;
m_manager.checkInstanceState();
}
@@ -132,7 +141,7 @@
} else {
// The dependencies are not valid
if (initialState == InstanceManager.VALID) {
- //There is a state change
+ // There is a state change
m_state = InstanceManager.INVALID;
m_manager.checkInstanceState();
}
@@ -143,8 +152,11 @@
}
/**
- * Check if the dependency given is valid in the sense that metadata are consistent.
+ * Check if the dependency given is valid in the sense that metadata are
+ * consistent.
+ *
* @param dep : the dependency to check
+ * @param manipulation : the component-type manipulation metadata
* @return true if the dependency is valid
*/
private boolean checkDependency(Dependency dep, Element manipulation) {
@@ -160,7 +172,8 @@
}
if (type == null) {
- m_manager.getFactory().getLogger().log(Logger.ERROR, "[DependencyHandler on " + m_manager.getClassName() + "] A declared dependency was not found in the class : " + dep.getField());
+ m_manager.getFactory().getLogger().log(Logger.ERROR,
+ "[DependencyHandler on " + m_manager.getClassName() + "] A declared dependency was not found in the class : " + dep.getField());
return false;
}
@@ -171,21 +184,30 @@
type = type.substring(0, type.length() - 2);
}
- if (dep.getSpecification() == null) { dep.setSpecification(type); }
+ if (dep.getSpecification() == null) {
+ dep.setSpecification(type);
+ }
if (!dep.getSpecification().equals(type)) {
- m_manager.getFactory().getLogger().log(Logger.WARNING, "[DependencyHandler on " + m_manager.getClassName() + "] The field type [" + type + "] and the needed service interface [" + dep.getSpecification() + "] 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.getSpecification() + "] are not the same");
dep.setSpecification(type);
}
} else {
- m_manager.getFactory().getLogger().log(Logger.WARNING, "[DependencyHandler on " + m_manager.getClassName() + "] The declared dependency " + dep.getField() + " does not exist in the code");
+ m_manager.getFactory().getLogger().log(Logger.WARNING,
+ "[DependencyHandler on " + m_manager.getClassName() + "] The declared dependency " + dep.getField() + " does not exist in the code");
}
return true;
}
-
/**
- * @see org.apache.felix.ipojo.Handler#configure(org.apache.felix.ipojo.InstanceManager, org.apache.felix.ipojo.metadata.Element)
+ * Configure the handler.
+ * @param im : the instance manager
+ * @param componentMetadata : the component type metadata
+ * @param configuration : the instance configuration
+ * @see org.apache.felix.ipojo.Handler#configure(org.apache.felix.ipojo.InstanceManager, org.apache.felix.ipojo.metadata.Element, java.util.Dictionary)
*/
public void configure(InstanceManager im, Element componentMetadata, Dictionary configuration) {
m_manager = im;
@@ -198,19 +220,26 @@
// Create the dependency metadata
String field = deps[i].getAttribute("field");
String serviceSpecification = null;
- if (deps[i].containsAttribute("interface")) { serviceSpecification = deps[i].getAttribute("interface"); }
+ if (deps[i].containsAttribute("interface")) {
+ serviceSpecification = deps[i].getAttribute("interface");
+ }
String filter = "";
- if (deps[i].containsAttribute("filter")) { filter = deps[i].getAttribute("filter"); }
+ if (deps[i].containsAttribute("filter")) {
+ filter = deps[i].getAttribute("filter");
+ }
boolean optional = false;
- if (deps[i].containsAttribute("optional") && deps[i].getAttribute("optional").equals("true")) { optional = true; }
+ if (deps[i].containsAttribute("optional") && deps[i].getAttribute("optional").equals("true")) {
+ optional = true;
+ }
Dependency dep = new Dependency(this, field, serviceSpecification, filter, optional);
// Check the dependency :
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.getField() + " is not valid");
+ if (checkDependency(dep, manipulation)) {
+ addDependency(dep);
+ } else {
+ m_manager.getFactory().getLogger().log(Logger.ERROR,
+ "[DependencyHandler on " + m_manager.getClassName() + "] The dependency on " + dep.getField() + " is not valid");
}
// Look for dependency callback :
@@ -218,13 +247,16 @@
String method = deps[i].getElements("Callback", "")[j].getAttribute("method");
String type = deps[i].getElements("Callback", "")[j].getAttribute("type");
int methodType = 0;
- if (type.equals("bind")) {
- methodType = DependencyCallback.BIND;
- } else {
- methodType = DependencyCallback.UNBIND;
+ if (type.equals("bind")) {
+ methodType = DependencyCallback.BIND;
+ } else {
+ methodType = DependencyCallback.UNBIND;
}
boolean isStatic = false;
- if (deps[i].getElements("Callback", "")[j].containsAttribute("isStatic") && deps[i].getElements("Callback", "")[j].getAttribute("isStatic").equals("true")) { isStatic = true; }
+ if (deps[i].getElements("Callback", "")[j].containsAttribute("isStatic")
+ && deps[i].getElements("Callback", "")[j].getAttribute("isStatic").equals("true")) {
+ isStatic = true;
+ }
DependencyCallback dc = new DependencyCallback(dep, method, methodType, isStatic);
dep.addDependencyCallback(dc);
}
@@ -241,36 +273,45 @@
/**
* Create a nullable class for the given dependency.
+ *
* @param dep : the dependency
*/
private void createNullableClass(Dependency dep) {
- m_manager.getFactory().getLogger().log(Logger.INFO, "[DependencyHandler on " + m_manager.getClassName() + "] Try to load the nullable class for " + dep.getSpecification());
-
- //String[] segment = dep.getMetadata().getServiceSpecification().split("[.]");
- //String className = "org/apache/felix/ipojo/" + segment[segment.length - 1] + "Nullable";
- String className = dep.getSpecification() + "Nullable";
+ m_manager.getFactory().getLogger().log(Logger.INFO,
+ "[DependencyHandler on " + m_manager.getClassName() + "] Try to load the nullable class for " + dep.getSpecification());
+
+ // String[] segment =
+ // dep.getMetadata().getServiceSpecification().split("[.]");
+ // String className = "org/apache/felix/ipojo/" + segment[segment.length
+ // - 1] + "Nullable";
+ String className = dep.getSpecification() + "Nullable";
String resource = dep.getSpecification().replace('.', '/') + ".class";
- URL url = m_manager.getContext().getBundle().getResource(resource);
+ URL url = m_manager.getContext().getBundle().getResource(resource);
try {
- byte[] b = NullableObjectWriter.dump(url, dep.getSpecification());
+ byte[] b = NullableObjectWriter.dump(url, dep.getSpecification());
Class c = null;
try {
- c = m_manager.getFactory().defineClass(className, b, null);
- } catch (Exception e) {
- System.err.println("Cannot define !!!");
+ c = m_manager.getFactory().defineClass(className, b, null);
+ } catch (Exception e) {
+ m_manager.getFactory().getLogger().log(Logger.ERROR, "Cannot define the nullable class : " + e.getMessage());
+ return;
}
- addNullableClass(c);
- m_manager.getFactory().getLogger().log(Logger.INFO, "[DependencyHandler on " + m_manager.getClassName() + "] Nullable class created for " + dep.getSpecification());
+ addNullableClass(c);
+ m_manager.getFactory().getLogger().log(Logger.INFO,
+ "[DependencyHandler on " + m_manager.getClassName() + "] Nullable class created for " + dep.getSpecification());
} catch (Exception e2) {
- m_manager.getFactory().getLogger().log(Logger.ERROR, "[DependencyHandler on " + m_manager.getClassName() + "] Cannot load the nullable class for " + dep.getSpecification(), e2);
+ m_manager.getFactory().getLogger().log(Logger.ERROR,
+ "[DependencyHandler on " + m_manager.getClassName() + "] Cannot load the nullable class for " + dep.getSpecification(), e2);
}
}
/**
* Return the nullable class corresponding to the given name.
+ *
* @param name the needed type
- * @return the class correspondig to the name, or null if the class does not exist.
+ * @return the class correspondig to the name, or null if the class does not
+ * exist.
*/
protected Class getNullableClass(String name) {
for (int i = 0; i < m_nullableClasses.length; i++) {
@@ -283,10 +324,13 @@
}
/**
+ * GetterCallback Method.
+ * @param fieldName : the field name.
+ * @param value : the value passed to the field (by the previous handler).
+ * @return the object that the dependency handler want to push.
* @see org.apache.felix.ipojo.Handler#getterCallback(java.lang.String, java.lang.Object)
*/
public Object getterCallback(String fieldName, Object value) {
- //TODO : non effiecent
for (int i = 0; i < m_dependencies.length; i++) {
Dependency dep = m_dependencies[i];
if (dep.getField().equals(fieldName)) {
@@ -299,22 +343,28 @@
}
/**
+ * Check the handler validity.
+ * @return true if all mandatory dependencies are resolved.
* @see org.apache.felix.ipojo.Handler#isValid()
*/
public boolean isValid() {
- return (m_state == InstanceManager.VALID);
+ return m_state == InstanceManager.VALID;
}
/**
+ * Handler start method.
* @see org.apache.felix.ipojo.Handler#start()
*/
public void start() {
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
+ // Start the dependencies, for optional dependencies create Nullable
+ // class
for (int i = 0; i < m_dependencies.length; i++) {
Dependency dep = m_dependencies[i];
- if (dep.isOptional() && !dep.isMultiple()) { createNullableClass(dep); }
+ if (dep.isOptional() && !dep.isMultiple()) {
+ createNullableClass(dep);
+ }
dep.start();
}
// Check the state
@@ -323,19 +373,29 @@
}
/**
+ * Handler stateChanged method.
+ * @param state : new instance state
* @see org.apache.felix.ipojo.Handler#stateChanged(int)
*/
- public void stateChanged(int state) { m_state = state; }
+ public void stateChanged(int state) {
+ m_state = state;
+ }
/**
+ * Handler stop method.
* @see org.apache.felix.ipojo.Handler#stop()
*/
public void stop() {
- for (int i = 0; i < m_dependencies.length; i++) { m_dependencies[i].stop(); }
+ for (int i = 0; i < m_dependencies.length; i++) {
+ m_dependencies[i].stop();
+ }
m_nullableClasses = new Class[0];
}
/**
+ * Handler createInstance method.
+ * This method is overided to allow delayed callback invocation.
+ * @param instance : the created object
* @see org.apache.felix.ipojo.Handler#createInstance(java.lang.Object)
*/
public void createInstance(Object instance) {
@@ -345,6 +405,7 @@
}
/**
+ * Check if dependencies are resolved.
* @return true if all dependencies are resolved.
*/
private boolean validateComponentDependencies() {
@@ -353,15 +414,18 @@
Dependency dep = m_dependencies[i];
valide = valide & dep.isSatisfied();
if (!valide) {
- m_manager.getFactory().getLogger().log(Logger.INFO, "[DependencyHandler on " + m_manager.getClassName() + "] Component Dependencies are not valid : " + dep.getSpecification());
+ m_manager.getFactory().getLogger().log(Logger.INFO,
+ "[DependencyHandler on " + m_manager.getClassName() + "] Component Dependencies are not valid : " + dep.getSpecification());
return false;
}
}
m_manager.getFactory().getLogger().log(Logger.INFO, "[DependencyHandler on " + m_manager.getClassName() + "] Component Dependencies are valid");
return valide;
}
-
+
/**
+ * Get the dependency handler description.
+ * @return the dependency handler description.
* @see org.apache.felix.ipojo.Handler#getDescription()
*/
public HandlerDescription getDescription() {
diff --git a/ipojo/src/main/java/org/apache/felix/ipojo/handlers/dependency/DependencyHandlerDescription.java b/ipojo/src/main/java/org/apache/felix/ipojo/handlers/dependency/DependencyHandlerDescription.java
index a67109d..10a6344 100644
--- a/ipojo/src/main/java/org/apache/felix/ipojo/handlers/dependency/DependencyHandlerDescription.java
+++ b/ipojo/src/main/java/org/apache/felix/ipojo/handlers/dependency/DependencyHandlerDescription.java
@@ -21,14 +21,16 @@
import java.util.Iterator;
import org.apache.felix.ipojo.architecture.HandlerDescription;
+import org.apache.felix.ipojo.metadata.Attribute;
+import org.apache.felix.ipojo.metadata.Element;
/**
* Dependency Handler Description.
+ *
* @author <a href="mailto:felix-dev@incubator.apache.org">Felix Project Team</a>
*/
public class DependencyHandlerDescription extends HandlerDescription {
-
/**
* Dependencies managed by the dependency handler.
*/
@@ -36,6 +38,7 @@
/**
* Constructor.
+ *
* @param isValid : the validity of the dependency handler.
*/
public DependencyHandlerDescription(boolean isValid) {
@@ -43,19 +46,24 @@
}
/**
+ * Get dependencies description.
* @return the dependencies list.
*/
- public DependencyDescription[] getDependencies() { return m_dependencies; }
+ public DependencyDescription[] getDependencies() {
+ return m_dependencies;
+ }
/**
* Add a dependency.
+ *
* @param dep : the dependency to add
*/
public void addDependency(DependencyDescription dep) {
// Verify that the dependency description is not already in the array.
- for (int i = 0; (i < m_dependencies.length); i++) {
+ for (int i = 0; i < m_dependencies.length; i++) {
if (m_dependencies[i] == dep) {
- return; //NOTHING TO DO, the description is already in the array
+ return; // NOTHING TO DO, the description is already in the
+ // array
}
}
// The component Description is not in the array, add it
@@ -66,21 +74,31 @@
}
/**
+ * Build Dependency Handler description.
+ * @return the handler description.
* @see org.apache.felix.ipojo.architecture.HandlerDescription#getHandlerInfo()
*/
- public String getHandlerInfo() {
- String info = "";
+ public Element getHandlerInfo() {
+ Element deps = super.getHandlerInfo();
for (int i = 0; i < m_dependencies.length; i++) {
String state = "resolved";
- if (m_dependencies[i].getState() == 2) { state = "unresolved"; }
- info += "\t Dependency on " + m_dependencies[i].getInterface() + "[" + m_dependencies[i].getFilter() + "] is " + state;
+ if (m_dependencies[i].getState() == 2) {
+ state = "unresolved";
+ }
+ Element dep = new Element("Dependency", "");
+ dep.addAttribute(new Attribute("Specification", m_dependencies[i].getInterface()));
+ dep.addAttribute(new Attribute("Filter", m_dependencies[i].getFilter()));
+ dep.addAttribute(new Attribute("State", state));
+ Element usages = new Element("Usages", "");
Iterator it = m_dependencies[i].getUsedServices().keySet().iterator();
while (it.hasNext()) {
- info += "\n \t\t Uses : " + it.next();
+ Element use = new Element("Use", "");
+ use.addAttribute(new Attribute("object", it.next().toString()));
+ usages.addElement(use);
}
- info += "\n";
+ deps.addElement(dep);
}
- return info;
+ return deps;
}
}
diff --git a/ipojo/src/main/java/org/apache/felix/ipojo/handlers/dependency/nullable/MethodSignature.java b/ipojo/src/main/java/org/apache/felix/ipojo/handlers/dependency/nullable/MethodSignature.java
index 93d1530..7dd02f0 100644
--- a/ipojo/src/main/java/org/apache/felix/ipojo/handlers/dependency/nullable/MethodSignature.java
+++ b/ipojo/src/main/java/org/apache/felix/ipojo/handlers/dependency/nullable/MethodSignature.java
@@ -43,7 +43,7 @@
/**
* Exception thored by the method.
*/
- private String[] m_exception;
+ private String[] m_exception = new String[0];
/**
* MethodSignature constructor.
@@ -57,10 +57,11 @@
m_name = name;
m_desc = desc;
m_signature = sign;
- m_exception = exc;
+ if (exc != null) { m_exception = exc; }
}
/**
+ * Get the method description.
* @return the description of the method.
*/
public String getDesc() {
@@ -68,6 +69,7 @@
}
/**
+ * Get the list of declared exception.
* @return the String array of exception throwed by the method.
*/
public String[] getException() {
@@ -75,6 +77,7 @@
}
/**
+ * Get the method name.
* @return the name of the method.
*/
public String getName() {
@@ -82,6 +85,7 @@
}
/**
+ * Get the method signature.
* @return the signature of the method.
*/
public String getSignature() {
diff --git a/ipojo/src/main/java/org/apache/felix/ipojo/handlers/dependency/nullable/MethodSignatureVisitor.java b/ipojo/src/main/java/org/apache/felix/ipojo/handlers/dependency/nullable/MethodSignatureVisitor.java
index a5d9799..a1f64b9 100644
--- a/ipojo/src/main/java/org/apache/felix/ipojo/handlers/dependency/nullable/MethodSignatureVisitor.java
+++ b/ipojo/src/main/java/org/apache/felix/ipojo/handlers/dependency/nullable/MethodSignatureVisitor.java
@@ -60,7 +60,8 @@
}
/**
- * @return the mthod signature array.
+ * Get the method signatures list.
+ * @return the method signature array.
*/
public MethodSignature[] getMethods() {
return m_methods;
@@ -86,6 +87,7 @@
}
/**
+ * Visit a method.
* @see org.objectweb.asm.ClassVisitor#visit(int, int, java.lang.String, java.lang.String, java.lang.String, java.lang.String[])
* @param arg0 : version
* @param arg1 : access
@@ -97,6 +99,7 @@
public void visit(int arg0, int arg1, String arg2, String arg3, String arg4, String[] arg5) { }
/**
+ * Visit sources.
* @see org.objectweb.asm.ClassVisitor#visitSource(java.lang.String, java.lang.String)
* @param arg0 : source
* @param arg1 : debug
@@ -104,6 +107,7 @@
public void visitSource(String arg0, String arg1) { }
/**
+ * Visit an outer class.
* @see org.objectweb.asm.ClassVisitor#visitOuterClass(java.lang.String, java.lang.String, java.lang.String)
* @param arg0 : owner
* @param arg1 : name
@@ -112,6 +116,7 @@
public void visitOuterClass(String arg0, String arg1, String arg2) { }
/**
+ * Visit an annotation.
* @see org.objectweb.asm.ClassVisitor#visitAnnotation(java.lang.String, boolean)
* @param arg0 : desc
* @param arg1 : visible
@@ -120,12 +125,14 @@
public AnnotationVisitor visitAnnotation(String arg0, boolean arg1) { return null; }
/**
+ * Visit an attribute.
* @see org.objectweb.asm.ClassVisitor#visitAttribute(org.objectweb.asm.Attribute)
* @param arg0 : Attribute
*/
public void visitAttribute(Attribute arg0) { }
/**
+ * Visit an inner class.
* @see org.objectweb.asm.ClassVisitor#visitInnerClass(java.lang.String, java.lang.String, java.lang.String, int)
* @param arg0 : name
* @param arg1 : outerclass
@@ -135,6 +142,7 @@
public void visitInnerClass(String arg0, String arg1, String arg2, int arg3) { }
/**
+ * Visit a field.
* @see org.objectweb.asm.ClassVisitor#visitField(int, java.lang.String, java.lang.String, java.lang.String, java.lang.Object)
* @param arg0 : access
* @param arg1 : name
@@ -146,6 +154,7 @@
public FieldVisitor visitField(int arg0, String arg1, String arg2, String arg3, Object arg4) { return null; }
/**
+ * End of the visit.
* @see org.objectweb.asm.ClassVisitor#visitEnd()
*/
public void visitEnd() { }
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 0228e10..132f56e 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
@@ -18,7 +18,6 @@
*/
package org.apache.felix.ipojo.handlers.dependency.nullable;
-
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
@@ -29,19 +28,22 @@
import org.objectweb.asm.Opcodes;
import org.objectweb.asm.Type;
-/** Create the proxy class.
+/**
+ * Create the proxy class.
+ *
* @author <a href="mailto:felix-dev@incubator.apache.org">Felix Project Team</a>
*/
public class NullableObjectWriter implements Opcodes {
- /** Return the proxy classname for the contract contractname
- * on the service object soc.
+ /**
+ * Return the proxy classname for the contract contractname on the service
+ * object soc.
+ *
* @param url URL of the needed contract
* @param contractName String
* @return byte[]
*/
- public static byte[] dump(URL url,
- String contractName) {
+ public static byte[] dump(URL url, String contractName) {
ClassReader cr = null;
InputStream is = null;
@@ -55,14 +57,14 @@
ClassWriter cw = new ClassWriter(true);
- //String[] segment = contractName.split("[.]");
- //String className = "org/apache/felix/ipojo/" + segment[segment.length - 1] + "Nullable";
+ // String[] segment = contractName.split("[.]");
+ // String className = "org/apache/felix/ipojo/" +
+ // segment[segment.length - 1] + "Nullable";
String className = contractName.replace('.', '/') + "Nullable";
-
// Create the class
- cw.visit(V1_2, ACC_PUBLIC + ACC_SUPER, className, null,
- "java/lang/Object", new String[]{contractName.replace('.', '/'), "org/apache/felix/ipojo/Nullable"});
+ cw.visit(V1_2, ACC_PUBLIC + ACC_SUPER, className, null, "java/lang/Object", new String[] { contractName.replace('.', '/'),
+ "org/apache/felix/ipojo/Nullable" });
// Inject a constructor <INIT>()V
MethodVisitor cst = cw.visitMethod(ACC_PUBLIC, "<init>", "()V", null, null);
@@ -85,38 +87,43 @@
MethodVisitor mv = cw.visitMethod(ACC_PUBLIC, name, desc, sign, exc);
Type returnType = Type.getReturnType(desc);
- // TODO : manage the other type primitive for Nullable
- // Primitive type :
+ // Primitive type :
switch (returnType.getSort()) {
case Type.BOOLEAN:
case Type.INT:
case Type.BYTE:
+ case Type.CHAR:
case Type.SHORT:
// Integer or Boolean : return 0 ( false)
mv.visitInsn(ICONST_0);
mv.visitInsn(IRETURN);
break;
case Type.LONG:
- mv.visitInsn(LCONST_0);
- mv.visitInsn(LRETURN);
- break;
+ mv.visitInsn(LCONST_0);
+ mv.visitInsn(LRETURN);
+ break;
case Type.DOUBLE:
// Double : return 0.0
mv.visitInsn(DCONST_0);
mv.visitInsn(DRETURN);
break;
- case Type.ARRAY :
- case Type.OBJECT :
+ case Type.FLOAT:
+ // Double : return 0.0
+ mv.visitInsn(FCONST_0);
+ mv.visitInsn(FRETURN);
+ break;
+ case Type.ARRAY:
+ case Type.OBJECT:
// Return always null for array and object
mv.visitInsn(ACONST_NULL);
mv.visitInsn(ARETURN);
break;
- case Type.VOID :
+ case Type.VOID:
mv.visitInsn(RETURN);
break;
- default :
+ default:
System.err.println("Type not yet managed : " + returnType);
- break;
+ break;
}
mv.visitMaxs(0, 0);
mv.visitEnd();
@@ -124,7 +131,7 @@
// End process
cw.visitEnd();
- b = cw.toByteArray();
+ b = cw.toByteArray();
} catch (IOException e) {
e.printStackTrace();
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 95d9588..5385d38 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
@@ -25,11 +25,12 @@
/**
* 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;
@@ -43,7 +44,7 @@
* Callback object.
*/
private Callback m_callback;
-
+
/**
* Method called by the callback.
*/
@@ -51,6 +52,7 @@
/**
* LifecycleCallback constructor.
+ *
* @param hh : the callback handler calling the callback
* @param initialState : initial state of the callback
* @param finalState : finali state of the callback
@@ -58,17 +60,27 @@
* @param isStatic : is the method static ?
*/
public LifecycleCallback(LifecycleCallbackHandler hh, String initialState, String finalState, String method, boolean isStatic) {
- if (initialState.equals("VALID")) { m_initialState = InstanceManager.VALID; }
- if (initialState.equals("INVALID")) { m_initialState = InstanceManager.INVALID; }
- if (finalState.equals("VALID")) { m_finalState = InstanceManager.VALID; }
- if (finalState.equals("INVALID")) { m_finalState = InstanceManager.INVALID; }
-
+ 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());
}
/**
- * Call the hook method when the transition from inital to final state is detected.
+ * Call the hook method when the transition from inital to final state is
+ * detected.
+ *
* @throws NoSuchMethodException : Method is not found in the class
* @throws InvocationTargetException : The method is not static
* @throws IllegalAccessException : The method can not be invoked
@@ -76,24 +88,17 @@
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; }
+
+ 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 3ee96ea..931612e 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
@@ -29,6 +29,7 @@
/**
* Lifecycle callback handler.
+ *
* @author <a href="mailto:felix-dev@incubator.apache.org">Felix Project Team</a>
*/
public class LifecycleCallbackHandler extends Handler {
@@ -48,18 +49,21 @@
*/
private InstanceManager m_manager;
- /**
- * Does a POJO object be created at starting.
- */
- private boolean m_immediate = false;
+ /**
+ * Does a POJO object be created at starting.
+ */
+ private boolean m_immediate = false;
/**
* Add the given callback to the callback list.
+ *
* @param hk : the element to add
*/
private void addCallback(LifecycleCallback hk) {
for (int i = 0; (m_callbacks != null) && (i < m_callbacks.length); i++) {
- if (m_callbacks[i] == hk) { return; }
+ if (m_callbacks[i] == hk) {
+ return;
+ }
}
if (m_callbacks.length > 0) {
@@ -68,19 +72,25 @@
newHk[m_callbacks.length] = hk;
m_callbacks = newHk;
} else {
- m_callbacks = new LifecycleCallback[] {hk};
+ m_callbacks = new LifecycleCallback[] { hk };
}
}
/**
- * @see org.apache.felix.ipojo.Handler#configure(org.apache.felix.ipojo.InstanceManager, org.apache.felix.ipojo.metadata.Element)
+ * Configure the handler.
+ * @param cm : the instance manager
+ * @param metadata : the component type metadata
+ * @param configuration : the instance configuration
+ * @see org.apache.felix.ipojo.Handler#configure(org.apache.felix.ipojo.InstanceManager, org.apache.felix.ipojo.metadata.Element, java.util.Dictionary)
*/
public void configure(InstanceManager cm, Element metadata, Dictionary configuration) {
m_manager = cm;
m_callbacks = new LifecycleCallback[0];
-
- if (metadata.containsAttribute("immediate") && metadata.getAttribute("immediate").equalsIgnoreCase("true")) { m_immediate = true; }
+
+ if (metadata.containsAttribute("immediate") && metadata.getAttribute("immediate").equalsIgnoreCase("true")) {
+ m_immediate = true;
+ }
Element[] hooksMetadata = metadata.getElements("callback");
for (int i = 0; i < hooksMetadata.length; i++) {
@@ -89,20 +99,27 @@
String finalState = hooksMetadata[i].getAttribute("final");
String method = hooksMetadata[i].getAttribute("method");
boolean isStatic = false;
- if (hooksMetadata[i].containsAttribute("isStatic") && hooksMetadata[i].getAttribute("isStatic").equals("true")) { isStatic = true; }
+ if (hooksMetadata[i].containsAttribute("isStatic") && hooksMetadata[i].getAttribute("isStatic").equals("true")) {
+ isStatic = true;
+ }
LifecycleCallback hk = new LifecycleCallback(this, initialState, finalState, method, isStatic);
addCallback(hk);
}
- if (m_callbacks.length > 0 || m_immediate) { m_manager.register(this); }
+ if (m_callbacks.length > 0 || m_immediate) {
+ m_manager.register(this);
+ }
}
/**
+ * Start the handler.
* @see org.apache.felix.ipojo.Handler#start()
*/
- public void start() { } //Do nothing during the start
+ public void start() {
+ } // Do nothing during the start
/**
+ * Stop the handler.
* @see org.apache.felix.ipojo.Handler#stop()
*/
public void stop() {
@@ -110,30 +127,40 @@
}
/**
+ * Get the instance manager.
* @return the instance manager
*/
- protected InstanceManager getInstanceManager() { return m_manager; }
+ protected InstanceManager getInstanceManager() {
+ return m_manager;
+ }
/**
- * When the state change call the associated hooks.
+ * When the state change call the associated callback.
+ *
+ * @param state : the new isntance state.
* @see org.apache.felix.ipojo.Handler#stateChanged(int)
*/
public void stateChanged(int state) {
- // Manage immediate component
- if (m_state == ComponentInstance.INVALID && state == ComponentInstance.VALID && m_manager.getPojoObjects().length == 0) {
- m_manager.createPojoObject();
- }
-
+ // Manage immediate component
+ if (m_state == ComponentInstance.INVALID && state == ComponentInstance.VALID && m_manager.getPojoObjects().length == 0) {
+ m_manager.createPojoObject();
+ }
+
for (int i = 0; i < m_callbacks.length; i++) {
if (m_callbacks[i].getInitialState() == m_state && m_callbacks[i].getFinalState() == state) {
try {
m_callbacks[i].call();
} catch (NoSuchMethodException e) {
- m_manager.getFactory().getLogger().log(Logger.ERROR, "[" + m_manager.getClassName() + "] The callback method " + m_callbacks[i].getMethod() + " is not found", e);
+ m_manager.getFactory().getLogger().log(Logger.ERROR,
+ "[" + m_manager.getClassName() + "] The callback method " + m_callbacks[i].getMethod() + " is not found", e);
} catch (IllegalAccessException e) {
- m_manager.getFactory().getLogger().log(Logger.ERROR, "[" + m_manager.getClassName() + "] The callback method " + m_callbacks[i].getMethod() + " is not accessible", e);
+ m_manager.getFactory().getLogger().log(Logger.ERROR,
+ "[" + m_manager.getClassName() + "] The callback method " + m_callbacks[i].getMethod() + " is not accessible", e);
} catch (InvocationTargetException e) {
- 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());
+ 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/providedservice/Property.java b/ipojo/src/main/java/org/apache/felix/ipojo/handlers/providedservice/Property.java
index 6e0664f..c468932 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
@@ -27,18 +27,17 @@
import org.apache.felix.ipojo.util.Logger;
/**
- * Represent a property i.e. a set : [name, type, value].
- * A property can be attached to a field.
- * The value of the property is thefield value.
- * When the value change, the published value change too.
+ * Represent a property i.e. a set : [name, type, value]. A property can be
+ * attached to a field. The value of the property is thefield value. When the
+ * value change, the published value change too.
+ *
* @author <a href="mailto:felix-dev@incubator.apache.org">Felix Project Team</a>
*/
public class Property {
/**
- * A property is link with a service.
- * This field represent this provided service.
- * m_providedService : ProvidedService
+ * A property is link with a service. This field represent this provided
+ * service. m_providedService : ProvidedService
*/
private ProvidedService m_providedService;
@@ -46,7 +45,7 @@
* Value of the property (before we know the type).
*/
private Object m_value;
-
+
/**
* Field of the property.
*/
@@ -69,6 +68,7 @@
/**
* Property constructor.
+ *
* @param ps : the provided service
* @param name : name of the property
* @param field : name of the field (if a field is attached to the property)
@@ -85,27 +85,38 @@
// Dynamic property case :
if (m_field != null) {
- if (m_name == null) { m_name = m_field; }
+ if (m_name == null) {
+ m_name = m_field;
+ }
}
-
+
// 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; }
+ if (field == null) {
+ ps.getInstanceManager().getFactory().getLogger().log(Logger.ERROR, "The property " + m_name + " has neither type neither field.");
+ return;
+ }
for (int j = 0; j < manipulation.getElements("Field").length; j++) {
if (field.equals(manipulation.getElements("Field")[j].getAttribute("name"))) {
m_type = manipulation.getElements("Field")[j].getAttribute("type");
break;
}
}
- if (m_type == null) { m_providedService.getInstanceManager().getFactory().getLogger().log(Logger.ERROR, "[" + ps.getInstanceManager().getClassName() + "] A declared property was not found in the class : " + m_field); }
+ if (m_type == null) {
+ m_providedService.getInstanceManager().getFactory().getLogger().log(Logger.ERROR,
+ "[" + ps.getInstanceManager().getClassName() + "] A declared property was not found in the class : " + m_field);
+ }
}
-
- if (m_initialValue != null) { setValue(m_initialValue); }
+
+ if (m_initialValue != null) {
+ setValue(m_initialValue);
+ }
}
/**
- * Property constructor.
- * This constructor is used only for non-field property (property not attached to a field).
+ * Property constructor. This constructor is used only for non-field
+ * property (property not attached to a field).
+ *
* @param ps : the provided service
* @param name : the name of the property
* @param value : the value of the property
@@ -118,13 +129,17 @@
}
/**
+ * Get the property value.
* @return the Object value of the property
*/
- protected Object get() { return m_value; }
+ protected Object get() {
+ return m_value;
+ }
/**
- * This method is automaticaly called when the value of the property is changed.
- * Set the value of a property.
+ * This method is automaticaly called when the value of the property is
+ * changed. Set the value of a property.
+ *
* @param s : the new value of the property (in String)
*/
protected void set(String s) {
@@ -132,8 +147,9 @@
}
/**
- * This method is called when the value of the property is changed.
- * Set the value of a property.
+ * This method is called when the value of the property is changed. Set the
+ * value of a property.
+ *
* @param o : the new value of the property (object)
*/
protected void set(Object o) {
@@ -142,6 +158,7 @@
/**
* Set the provided service of this property.
+ *
* @param ps : the provided service to attached.
*/
void setProvidedService(ProvidedService ps) {
@@ -150,6 +167,7 @@
/**
* Set the value of the property.
+ *
* @param value : value of the property (String)
*/
private void setValue(String value) {
@@ -162,154 +180,210 @@
}
// Simple :
- 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; }
+ 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.
+ // 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.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});
+ // 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 " + m_type);
- e.printStackTrace();
+ m_providedService.getInstanceManager().getFactory().getLogger().log(Logger.ERROR, "Class not found exception in setValue on " + m_type);
} catch (SecurityException e) {
- e.printStackTrace();
+ m_providedService.getInstanceManager().getFactory().getLogger().log(Logger.ERROR, "Security Exception in setValue on " + m_type);
} catch (NoSuchMethodException e) {
- System.err.println("Constructor not found exeption in setValue on " + m_type);
- e.printStackTrace();
+ m_providedService.getInstanceManager().getFactory().getLogger().log(Logger.ERROR, "Constructor not found exeption in setValue on " + m_type);
} catch (IllegalArgumentException e) {
- System.err.println("Argument problem to call the constructor of the type " + m_type);
- e.printStackTrace();
+ m_providedService.getInstanceManager().getFactory().getLogger().log(Logger.ERROR, "Argument problem to call the constructor of the type " + m_type);
} catch (InstantiationException e) {
- System.err.println("Instantiation problem " + m_type);
- e.printStackTrace();
+ m_providedService.getInstanceManager().getFactory().getLogger().log(Logger.ERROR, "Instantiation problem " + m_type);
} catch (IllegalAccessException e) {
- e.printStackTrace();
+ m_providedService.getInstanceManager().getFactory().getLogger().log(Logger.ERROR, "Illegal Access Exception in setValue on " + m_type);
} catch (InvocationTargetException e) {
- System.err.println("Invocation problem " + m_type);
- e.printStackTrace();
+ m_providedService.getInstanceManager().getFactory().getLogger().log(Logger.ERROR, "Invocation problem " + m_type);
}
}
/**
* Set a array value to the current property.
+ *
* @param internalType : internal array type
* @param values : the new 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")) {
+ m_value = values;
+ 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]).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]).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]).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]).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]).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]).floatValue();
+ }
m_value = fl;
- return;
+ return;
}
if (internalType.equals("double")) {
double[] dl = new double[values.length];
- for (int i = 0; i < values.length; i++) { dl[i] = new Double(values[i]).doubleValue(); }
+ for (int i = 0; i < values.length; i++) {
+ dl[i] = new Double(values[i]).doubleValue();
+ }
m_value = dl;
- return;
+ return;
}
- // Else it is a neither a primitive type neither a String -> create the object by calling a constructor with a string in argument.
+ // 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.getInstanceManager().getContext().getBundle().loadClass(internalType);
- Constructor cst = c.getConstructor(new Class[] {String.class});
+ 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] });
}
m_value = ob;
return;
} catch (ClassNotFoundException e) {
- System.err.println("Class not found exception in setValue on " + internalType);
- e.printStackTrace();
+ m_providedService.getInstanceManager().getFactory().getLogger().log(Logger.ERROR, "Class not found exception in setArrayValue on " + internalType);
} catch (SecurityException e) {
- e.printStackTrace();
+ m_providedService.getInstanceManager().getFactory().getLogger().log(Logger.ERROR, "Security Exception in setArrayValue on " + internalType);
} catch (NoSuchMethodException e) {
- System.err.println("Constructor not found exeption in setValue on " + internalType);
- e.printStackTrace();
+ m_providedService.getInstanceManager().getFactory().getLogger().log(Logger.ERROR,
+ "Constructor not found exception in setArrayValue on " + internalType);
} catch (IllegalArgumentException e) {
- System.err.println("Argument problem to call the constructor of the type " + internalType);
- e.printStackTrace();
+ m_providedService.getInstanceManager().getFactory().getLogger().log(Logger.ERROR,
+ "Argument problem to call the constructor of the type " + internalType);
} catch (InstantiationException e) {
- System.err.println("Instantiation problem " + internalType);
- e.printStackTrace();
+ m_providedService.getInstanceManager().getFactory().getLogger().log(Logger.ERROR, "Instantiation problem " + internalType);
} catch (IllegalAccessException e) {
- e.printStackTrace();
+ m_providedService.getInstanceManager().getFactory().getLogger().log(Logger.ERROR, "Illegal Access Exception in setArrayValue on " + internalType);
} catch (InvocationTargetException e) {
- System.err.println("Invocation problem " + internalType);
- e.printStackTrace();
+ m_providedService.getInstanceManager().getFactory().getLogger().log(Logger.ERROR, "Invocation problem " + internalType);
}
}
/**
+ * Get the stored value.
* @return the value of the property.
*/
- public Object getValue() { return m_value; }
-
+ public Object getValue() {
+ return m_value;
+ }
+
/**
+ * Get the property name.
* @return the name of the property
*/
- public String getName() { return m_name; }
-
+ public String getName() {
+ return m_name;
+ }
+
/**
- * @return the field name of the property (null if the property has no field).
+ * Get the property field.
+ * @return the field name of the property (null if the property has no
+ * field).
*/
- protected String getField() { return m_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; }
+ /**
+ * 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 initial value of the property.
- */
- public String getInitialValue() { return m_initialValue; }
-
+ /**
+ * Get the property type.
+ * @return the type of the property.
+ */
+ public String getType() {
+ return m_type;
+ }
+
+ /**
+ * Get the property initial value.
+ * @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/ProvidedService.java b/ipojo/src/main/java/org/apache/felix/ipojo/handlers/providedservice/ProvidedService.java
index d446087..37fe087 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
@@ -29,9 +29,9 @@
import org.osgi.framework.ServiceReference;
import org.osgi.framework.ServiceRegistration;
-
/**
* Provided Service represent a provided service by the component.
+ *
* @author <a href="mailto:felix-dev@incubator.apache.org">Felix Project Team</a>
*/
public class ProvidedService implements ServiceFactory {
@@ -67,15 +67,13 @@
private int m_factoryPolicy = SINGLETON_FACTORY;
/**
- * The service registration.
- * is null when the service is not registred.
+ * The service registration. is null when the service is not registred.
* m_serviceRegistration : ServiceRegistration
*/
private ServiceRegistration m_serviceRegistration;
/**
- * Link to the owner handler.
- * m_handler : Provided Service Handler
+ * Link to the owner handler. m_handler : Provided Service Handler
*/
private ProvidedServiceHandler m_handler;
@@ -84,42 +82,47 @@
*/
private Property[] m_properties = new Property[0];
-
/**
* Construct a provided service object.
+ *
* @param handler : the provided service handler.
* @param specification : specifications provided by this provided service
* @param factoryPolicy : service providing policy
*/
public ProvidedService(ProvidedServiceHandler handler, String[] specification, int factoryPolicy) {
m_handler = handler;
-
+
m_serviceSpecification = specification;
m_factoryPolicy = factoryPolicy;
-
- //Add service pid and factory pid
+
+ // Add service pid and factory pid
addProperty(new Property(this, org.osgi.framework.Constants.SERVICE_PID, handler.getInstanceManager().getInstanceName()));
- addProperty(new Property(this, "factory.pid", handler.getInstanceManager().getFactory().getFactoryName()));
+ addProperty(new Property(this, "factory.pid", handler.getInstanceManager().getFactory().getName()));
}
-
- //TODO check if we need to erase previous props or add to the previous props.
+
+ // 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]);
- }
+ protected void setProperties(Property[] props) {
+ for (int i = 0; i < props.length; i++) {
+ addProperty(props[i]);
+ }
}
/**
* Add the given property to the property list.
+ *
* @param p : the element to add
*/
private synchronized void addProperty(Property p) {
for (int i = 0; (m_properties != null) && (i < m_properties.length); i++) {
- if (m_properties[i] == p) { return; }
+ if (m_properties[i] == p) {
+ return;
+ }
}
if (m_properties.length > 0) {
@@ -127,29 +130,33 @@
System.arraycopy(m_properties, 0, newProp, 0, m_properties.length);
newProp[m_properties.length] = p;
m_properties = newProp;
- } else {
- m_properties = new Property[] {p};
+ } else {
+ m_properties = new Property[] { p };
}
}
/**
* Remove a property.
+ *
* @param name : the property to remove
*/
private synchronized void removeProperty(String name) {
int idx = -1;
for (int i = 0; i < m_properties.length; i++) {
- if (m_properties[i].getName() == name) { idx = i; break; }
+ if (m_properties[i].getName() == name) {
+ idx = i;
+ break;
+ }
}
if (idx >= 0) {
- if ((m_properties.length - 1) == 0) {
- m_properties = new Property[0];
+ if ((m_properties.length - 1) == 0) {
+ m_properties = new Property[0];
} else {
Property[] newPropertiesList = new Property[m_properties.length - 1];
System.arraycopy(m_properties, 0, newPropertiesList, 0, idx);
if (idx < newPropertiesList.length) {
- System.arraycopy(m_properties, idx + 1, newPropertiesList, idx, newPropertiesList.length - idx);
+ System.arraycopy(m_properties, idx + 1, newPropertiesList, idx, newPropertiesList.length - idx);
}
m_properties = newPropertiesList;
}
@@ -157,33 +164,43 @@
}
/**
- * @return the service reference of the provided service (null if the service is not published).
+ * Get the service reference of the service registration.
+ * @return the service reference of the provided service (null if the
+ * service is not published).
*/
public ServiceReference getServiceReference() {
- if (m_serviceRegistration != null) {
- return m_serviceRegistration.getReference();
- } else { return null; }
+ if (m_serviceRegistration != null) {
+ return m_serviceRegistration.getReference();
+ } else {
+ return null;
+ }
}
/**
* Return a service object for the dependency.
- * @see org.osgi.framework.ServiceFactory#getService(org.osgi.framework.Bundle, org.osgi.framework.ServiceRegistration)
+ *
+ * @see org.osgi.framework.ServiceFactory#getService(org.osgi.framework.Bundle,
+ * org.osgi.framework.ServiceRegistration)
* @param bundle : the bundle
* @param registration : the service registration of the registred service
- * @return : a new service object or a already created service object (in the case of singleton)
+ * @return : a new service object or a already created service object (in
+ * the case of singleton)
*/
public Object getService(Bundle bundle, ServiceRegistration registration) {
- switch(m_factoryPolicy) {
+ switch (m_factoryPolicy) {
- case SINGLETON_FACTORY :
+ case SINGLETON_FACTORY:
return m_handler.getInstanceManager().getPojoObject();
- case SERVICE_FACTORY :
+ case SERVICE_FACTORY:
return m_handler.getInstanceManager().createPojoObject();
- default :
- m_handler.getInstanceManager().getFactory().getLogger().log(Logger.ERROR, "[" + m_handler.getInstanceManager().getClassName() + "] Unknown factory policy for " + m_serviceSpecification + " : " + m_factoryPolicy);
+ default:
+ m_handler.getInstanceManager().getFactory().getLogger().log(
+ Logger.ERROR,
+ "[" + m_handler.getInstanceManager().getClassName() + "] Unknown factory policy for " + m_serviceSpecification + " : "
+ + m_factoryPolicy);
return null;
}
@@ -191,19 +208,21 @@
/**
* The unget method.
- * @see org.osgi.framework.ServiceFactory#ungetService(org.osgi.framework.Bundle, org.osgi.framework.ServiceRegistration, java.lang.Object)
+ *
+ * @see org.osgi.framework.ServiceFactory#ungetService(org.osgi.framework.Bundle,
+ * org.osgi.framework.ServiceRegistration, java.lang.Object)
* @param bundle : bundle
* @param registration : service registration
* @param service : service object
*/
public void ungetService(Bundle bundle, ServiceRegistration registration, Object service) {
- //Nothing to do
+ // Nothing to do
}
/**
- * Register the service.
- * The service object must be able to serve this service.
- * To avoid cycle in Check Context, the registred service is set to registred before the real registration.
+ * Register the service. The service object must be able to serve this
+ * service. To avoid cycle in Check Context, the registred service is set to
+ * registred before the real registration.
*/
protected synchronized void registerService() {
if (m_serviceRegistration == null) {
@@ -214,9 +233,7 @@
// Contruct the service properties list
Properties serviceProperties = getServiceProperties();
- m_serviceRegistration =
- m_handler.getInstanceManager().getContext().registerService(
- m_serviceSpecification, this, serviceProperties);
+ m_serviceRegistration = m_handler.getInstanceManager().getContext().registerService(m_serviceSpecification, this, serviceProperties);
}
}
@@ -227,32 +244,33 @@
if (m_serviceRegistration != null) {
try {
m_serviceRegistration.unregister();
- } catch (Exception e) { return; }
+ } catch (Exception e) {
+ return;
+ }
m_serviceRegistration = null;
}
}
/**
+ * Get the current provided service state.
* @return The state of the provided service.
*/
public int getState() {
- if (m_serviceRegistration == null) {
- return UNREGISTERED;
- } else {
- return REGISTERED;
- }
+ if (m_serviceRegistration == null) {
+ return UNREGISTERED;
+ } else {
+ return REGISTERED;
+ }
}
- /**
- * @return the instance manager.
- */
protected InstanceManager getInstanceManager() {
return m_handler.getInstanceManager();
}
/**
- * Return the list of properties attached to this service.
- * This list contains only property where a value are assigned.
+ * Return the list of properties attached to this service. This list
+ * contains only property where a value are assigned.
+ *
* @return the properties attached to the provided service.
*/
private Properties getServiceProperties() {
@@ -267,6 +285,7 @@
}
/**
+ * Get the list of properties attached to the service registration.
* @return the properties attached to the provided service.
*/
public Property[] getProperties() {
@@ -274,15 +293,15 @@
}
/**
- * Update the service properties.
- * The new list of properties is sended to the service registry.
+ * Update the service properties. The new list of properties is sended to
+ * the service registry.
*/
public synchronized void update() {
// Contruct the service properties list
Properties serviceProperties = getServiceProperties();
-
+
if (serviceProperties == null) {
- m_handler.getInstanceManager().getFactory().getLogger().log(Logger.ERROR, "Cannot get the properties of the provided service");
+ m_handler.getInstanceManager().getFactory().getLogger().log(Logger.ERROR, "Cannot get the properties of the provided service");
}
// Update the service registration
@@ -293,6 +312,7 @@
/**
* Add properties to the list.
+ *
* @param props : properties to add
*/
protected void addProperties(Dictionary props) {
@@ -307,6 +327,7 @@
/**
* Remove properties from the list.
+ *
* @param props : properties to remove
*/
protected void deleteProperties(Dictionary props) {
@@ -317,9 +338,21 @@
}
}
- /**
- * @return the list of provided service specifications (i.e. java interface).
- */
- public String[] getServiceSpecification() { return m_serviceSpecification; }
+ /**
+ * Get the published service specifications.
+ * @return the list of provided service specifications (i.e. java
+ * interface).
+ */
+ public String[] getServiceSpecification() {
+ return m_serviceSpecification;
+ }
+
+ /**
+ * Get the service registration.
+ * @return the service registration of this service.
+ */
+ public ServiceRegistration getServiceRegistration() {
+ return m_serviceRegistration;
+ }
}
diff --git a/ipojo/src/main/java/org/apache/felix/ipojo/handlers/providedservice/ProvidedServiceDescription.java b/ipojo/src/main/java/org/apache/felix/ipojo/handlers/providedservice/ProvidedServiceDescription.java
index 0041298..daec557 100644
--- a/ipojo/src/main/java/org/apache/felix/ipojo/handlers/providedservice/ProvidedServiceDescription.java
+++ b/ipojo/src/main/java/org/apache/felix/ipojo/handlers/providedservice/ProvidedServiceDescription.java
@@ -20,24 +20,24 @@
import java.util.Properties;
-import org.apache.felix.ipojo.handlers.dependency.DependencyDescription;
import org.osgi.framework.ServiceReference;
/**
* Provided Service Description.
+ *
* @author <a href="mailto:felix-dev@incubator.apache.org">Felix Project Team</a>
*/
public class ProvidedServiceDescription {
-
- /**
- * State : the service is unregistered.
- */
- public static final int UNREGISTERED = 0;
-
- /**
- * State : the service is registered.
- */
- public static final int REGISTERED = 1;
+
+ /**
+ * State : the service is unregistered.
+ */
+ public static final int UNREGISTERED = 0;
+
+ /**
+ * State : the service is registered.
+ */
+ public static final int REGISTERED = 1;
/**
* Provided Service Specification.
@@ -45,11 +45,6 @@
private String[] m_serviceSpecification;
/**
- * Dependency of the service.
- */
- private DependencyDescription[] m_dependencies = new DependencyDescription[0];
-
- /**
* State.
*/
private int m_state;
@@ -59,31 +54,33 @@
*/
private ServiceReference m_serviceReference;
-// /**
-// * Handler on the component description who contains this description.
-// */
-// private InstanceDescription m_parent;
+ // /**
+ // * Handler on the component description who contains this description.
+ // */
+ // private InstanceDescription m_parent;
/**
* Properties of the provided service.
*/
private Properties m_properties = new Properties();
-
/**
* Constructor.
+ *
* @param serviceSpecification : the provided contract
* @param state : state (UNREGITRED | REGISTRED)
- * @param sr : Service Registration (to obtain the reference), or null if state is UNREGISTRED
+ * @param sr : Service Registration (to obtain the reference), or null if
+ * state is UNREGISTRED
*/
public ProvidedServiceDescription(String[] serviceSpecification, int state, ServiceReference sr) {
m_serviceSpecification = serviceSpecification;
m_state = state;
m_serviceReference = sr;
- // m_parent = parent;
+ // m_parent = parent;
}
/**
+ * Get the list of provided service specifications.
* @return the provided contract name.
*/
public String[] getServiceSpecification() {
@@ -92,6 +89,7 @@
/**
* Add a property to the current provided service description.
+ *
* @param key : the key of the property
* @param value : the value of the property
*/
@@ -101,6 +99,7 @@
/**
* Set the set of properties. This function create a clone of the argument.
+ *
* @param props : the properties
*/
public void setProperty(Properties props) {
@@ -108,13 +107,7 @@
}
/**
- * @return the dependeny description list.
- */
- public DependencyDescription[] getDependencies() {
- return m_dependencies;
- }
-
- /**
+ * Get the list of properties.
* @return the properties.
*/
public Properties getProperties() {
@@ -122,13 +115,15 @@
}
/**
- * @return the state of the provided service (UNREGISTRED | REGISTRED).
+ * Get provided service state.
+ * @return the state of the provided service (UNREGISTERED | REGISTRED).
*/
public int getState() {
return m_state;
}
/**
+ * Get the service reference.
* @return the service reference (null if the service is unregistred).
*/
public ServiceReference getServiceReference() {
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 7253e15..86ae62d 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
@@ -32,11 +32,12 @@
import org.osgi.framework.Constants;
/**
+ * Composite PRovided Service Handler.
+ * This handler maange the service providing for a composition.
* @author <a href="mailto:felix-dev@incubator.apache.org">Felix Project Team</a>
*/
public class ProvidedServiceHandler extends Handler {
-
/**
* The list of the provided service.
*/
@@ -49,12 +50,15 @@
/**
* Add a provided service to the list .
+ *
* @param ps : the provided service to add
*/
private void addProvidedService(ProvidedService ps) {
- // Verify that the provided service is not already in the array.
+ // Verify that the provided service is not already in the array.
for (int i = 0; (m_providedServices != null) && (i < m_providedServices.length); i++) {
- if (m_providedServices[i] == ps) { return; }
+ if (m_providedServices[i] == ps) {
+ return;
+ }
}
if (m_providedServices.length > 0) {
@@ -62,23 +66,33 @@
System.arraycopy(m_providedServices, 0, newPS, 0, m_providedServices.length);
newPS[m_providedServices.length] = ps;
m_providedServices = newPS;
- } else {
- m_providedServices = new ProvidedService[] {ps};
+ } else {
+ m_providedServices = new ProvidedService[] { ps };
}
}
/**
+ * Get the instance manager.
* @return the instance manager.
*/
- public InstanceManager getInstanceManager() { return m_manager; }
+ public InstanceManager getInstanceManager() {
+ return m_manager;
+ }
/**
+ * Get the array of provided service.
* @return the list of the provided service.
*/
- public ProvidedService[] getProvidedService() { return m_providedServices; }
+ public ProvidedService[] getProvidedService() {
+ return m_providedServices;
+ }
/**
- * @see org.apache.felix.ipojo.Handler#configure(org.apache.felix.ipojo.InstanceManager, org.apache.felix.ipojo.metadata.Element)
+ * Configure the handler.
+ * @param im : the instance manager
+ * @param componentMetadata : the component type metadata
+ * @param configuration : the instance configuration
+ * @see org.apache.felix.ipojo.Handler#configure(org.apache.felix.ipojo.InstanceManager, org.apache.felix.ipojo.metadata.Element, java.util.Dictionary)
*/
public void configure(InstanceManager im, Element componentMetadata, Dictionary configuration) {
// Fix the instance manager & clean the provided service list
@@ -97,7 +111,7 @@
String[] serviceSpecification = new String[0];
if (providedServices[i].containsAttribute("interface")) {
String serviceSpecificationStr = providedServices[i].getAttribute("interface");
- //Get serviceSpecification if exist in the metadata
+ // Get serviceSpecification if exist in the metadata
serviceSpecification = ParseUtils.parseArrays(serviceSpecificationStr);
} else {
serviceSpecification = new String[manipulation.getElements("Interface").length];
@@ -105,11 +119,17 @@
serviceSpecification[j] = manipulation.getElements("Interface")[j].getAttribute("name");
}
}
- if (serviceSpecification.length == 0) { m_manager.getFactory().getLogger().log(Logger.ERROR, "Cannot instantiate a provided service : no specifications found (no interfaces implemented by the pojo)"); return; }
+ if (serviceSpecification.length == 0) {
+ m_manager.getFactory().getLogger().log(Logger.ERROR,
+ "Cannot instantiate a provided service : no specifications found (no interfaces implemented by the pojo)");
+ return;
+ }
// Get the factory policy
int factory = ProvidedService.SINGLETON_FACTORY;
- if (providedServices[i].containsAttribute("factory") && providedServices[i].getAttribute("factory").equals("service")) { factory = ProvidedService.SERVICE_FACTORY; }
+ if (providedServices[i].containsAttribute("factory") && providedServices[i].getAttribute("factory").equals("service")) {
+ factory = ProvidedService.SERVICE_FACTORY;
+ }
// Then create the provided service
ProvidedService ps = new ProvidedService(this, serviceSpecification, factory);
@@ -118,20 +138,28 @@
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"); }
+ if (props[j].containsAttribute("name")) {
+ name = props[j].getAttribute("name");
+ }
String value = null;
- if (props[j].containsAttribute("value")) { value = props[j].getAttribute("value"); }
+ if (props[j].containsAttribute("value")) {
+ value = props[j].getAttribute("value");
+ }
String type = null;
- if (props[j].containsAttribute("type")) { type = props[j].getAttribute("type"); }
+ if (props[j].containsAttribute("type")) {
+ type = props[j].getAttribute("type");
+ }
String field = null;
- if (props[j].containsAttribute("field")) { field = props[j].getAttribute("field"); }
+ if (props[j].containsAttribute("field")) {
+ field = props[j].getAttribute("field");
+ }
- if (name != null && configuration.get(name) != null && configuration.get(name) instanceof String) {
- value = (String) configuration.get(name);
- } else {
- if (field != null && configuration.get(field) != null && configuration.get(field) instanceof String) {
- value = (String) configuration.get(field);
- }
+ if (name != null && configuration.get(name) != null && configuration.get(name) instanceof String) {
+ value = (String) configuration.get(name);
+ } else {
+ if (field != null && configuration.get(field) != null && configuration.get(field) instanceof String) {
+ value = (String) configuration.get(field);
+ }
}
Property prop = new Property(ps, name, field, type, value, manipulation);
@@ -140,22 +168,26 @@
// Attached to properties to the provided service
ps.setProperties(properties);
-
+
if (checkProvidedService(ps, manipulation)) {
addProvidedService(ps);
// Change ComponentInfo
- for (int k = 0; k < ps.getServiceSpecification().length; k++) { cd.addProvidedServiceSpecification(ps.getServiceSpecification()[k]); }
- for (int k = 0; k < ps.getProperties().length; k++) {
- if (!ps.getProperties()[k].getName().equals(Constants.SERVICE_PID) && !ps.getProperties()[k].getName().equals("factory.pid")) {
- cd.addProperty(new PropertyDescription(ps.getProperties()[k].getName(), ps.getProperties()[k].getType(), ps.getProperties()[k].getInitialValue()));
- }
+ 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];
}
- m_manager.getFactory().getLogger().log(Logger.ERROR, "[" + m_manager.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;
}
@@ -168,13 +200,14 @@
for (int j = 0; j < ps.getProperties().length; j++) {
Property prop = ps.getProperties()[j];
- // Check if the instance configuration has a value for this property
- if (prop.getName() != null && configuration.get(prop.getName()) != null && !(configuration.get(prop.getName()) instanceof String)) {
- prop.set(configuration.get(prop.getName()));
- } else {
- if (prop.getField() != null && configuration.get(prop.getField()) != null && !(configuration.get(prop.getField()) instanceof String)) {
- prop.set(configuration.get(prop.getField()));
- }
+ // Check if the instance configuration has a value for this
+ // property
+ if (prop.getName() != null && configuration.get(prop.getName()) != null && !(configuration.get(prop.getName()) instanceof String)) {
+ prop.set(configuration.get(prop.getName()));
+ } else {
+ if (prop.getField() != null && configuration.get(prop.getField()) != null && !(configuration.get(prop.getField()) instanceof String)) {
+ prop.set(configuration.get(prop.getField()));
+ }
}
if (prop.getField() != null) {
String[] newFields = new String[fields.length + 1];
@@ -185,28 +218,34 @@
}
}
- m_manager.register(this, fields);
+ m_manager.register(this, fields);
}
}
/**
- * Check the provided service given in argument in the sense that the metadata are consistent.
- * @param ps : the provided service to check
+ * Check the provided service given in argument in the sense that the
+ * metadata are consistent.
+ *
+ * @param ps : the provided service to check.
+ * @param manipulation : componenet-type manipulation metadata.
* @return true if the provided service is correct
*/
private boolean checkProvidedService(ProvidedService ps, Element manipulation) {
for (int i = 0; i < ps.getServiceSpecification().length; i++) {
- boolean b = false;
- for (int ii = 0; ii < manipulation.getElements("Interface").length; ii++) {
+ 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;
- }
+ if (!b) {
+ m_manager.getFactory().getLogger().log(
+ Logger.ERROR,
+ "[" + m_manager.getClassName() + "] The service specification " + ps.getServiceSpecification()[i]
+ + " is not implemented by the component class");
+ return false;
+ }
}
@@ -226,10 +265,11 @@
}
}
if (type == null) {
- m_manager.getFactory().getLogger().log(Logger.ERROR, "[" + m_manager.getClassName() + "] A declared property was not found in the class : " + prop.getField());
+ m_manager.getFactory().getLogger().log(Logger.ERROR,
+ "[" + m_manager.getClassName() + "] A declared property was not found in the class : " + prop.getField());
return false;
}
- prop.setType(type); //Set the type
+ prop.setType(type); // Set the type
}
}
return true;
@@ -237,18 +277,27 @@
/**
* Stop the provided service handler.
+ *
* @see org.apache.felix.ipojo.Handler#stop()
*/
- public void stop() { }
+ public void stop() {
+ }
/**
* Start the provided service handler.
+ *
* @see org.apache.felix.ipojo.Handler#start()
*/
- public void start() { }
+ public void start() {
+ }
- /**
- * @see org.apache.felix.ipojo.Handler#setterCallback(java.lang.String, java.lang.Object)
+ /**
+ * Setter Callback Method.
+ * Check if the modified field is a property to update the value.
+ * @param fieldName : field name
+ * @param value : new value
+ * @see org.apache.felix.ipojo.Handler#setterCallback(java.lang.String,
+ * java.lang.Object)
*/
public void setterCallback(String fieldName, Object value) {
// Verify that the field name coreespond to a dependency
@@ -263,13 +312,21 @@
update = true;
}
}
- if (update) { ps.update(); }
+ if (update) {
+ ps.update();
+ }
}
- //Else do nothing
+ // Else do nothing
}
/**
- * @see org.apache.felix.ipojo.Handler#getterCallback(java.lang.String, java.lang.Object)
+ * Getter Callback Method.
+ * Check if the field is a property to push the stored value.
+ * @param fieldName : field name
+ * @param value : value pushed by the previous handler
+ * @return the stored value or the previous value.
+ * @see org.apache.felix.ipojo.Handler#getterCallback(java.lang.String,
+ * java.lang.Object)
*/
public Object getterCallback(String fieldName, Object value) {
for (int i = 0; i < m_providedServices.length; i++) {
@@ -287,14 +344,16 @@
}
/**
- * Register the services if the new state is VALID.
- * Unregister the services if the new state is UNRESOLVED.
- * @see org.apache.felix.ipojo.Handler#stateChanged(int)
+ * Register the services if the new state is VALID. Unregister the services
+ * if the new state is UNRESOLVED.
+ *
+ * @param state : the new instance state.
+ * @see org.apache.felix.ipojo.CompositeHandler#stateChanged(int)
*/
public void stateChanged(int state) {
// If the new state is UNRESOLVED => unregister all the services
if (state == InstanceManager.INVALID) {
- for (int i = 0; i < m_providedServices.length; i++) {
+ for (int i = 0; i < m_providedServices.length; i++) {
m_providedServices[i].unregisterService();
}
return;
@@ -302,7 +361,7 @@
// If the new state is VALID => regiter all the services
if (state == InstanceManager.VALID) {
- for (int i = 0; i < m_providedServices.length; i++) {
+ for (int i = 0; i < m_providedServices.length; i++) {
m_providedServices[i].registerService();
}
return;
@@ -312,6 +371,7 @@
/**
* Add properties to all provided services.
+ *
* @param dict : dictionary fo properties to add
*/
public void addProperties(Dictionary dict) {
@@ -323,6 +383,7 @@
/**
* Remove properties form all provided services.
+ *
* @param dict : dictionary of properties to delete.
*/
public void removeProperties(Dictionary dict) {
@@ -331,46 +392,56 @@
m_providedServices[i].update();
}
}
-
- /**
- * @see org.apache.felix.ipojo.Handler#getDescription()
- */
- public HandlerDescription getDescription() {
- ProvidedServiceHandlerDescription pshd = new ProvidedServiceHandlerDescription(this.isValid());
- for (int j = 0; j < getProvidedService().length; j++) {
- ProvidedService ps = getProvidedService()[j];
- ProvidedServiceDescription psd = new ProvidedServiceDescription(ps.getServiceSpecification(), ps.getState(), ps.getServiceReference());
+ /**
+ * Build the provided service description.
+ * @return the handler description.
+ * @see org.apache.felix.ipojo.Handler#getDescription()
+ */
+ public HandlerDescription getDescription() {
+ ProvidedServiceHandlerDescription pshd = new ProvidedServiceHandlerDescription(this.isValid());
- Properties props = new Properties();
- for (int k = 0; k < ps.getProperties().length; k++) {
- Property prop = ps.getProperties()[k];
- if (prop.getValue() != null) { props.put(prop.getName(), prop.getValue().toString()); }
- }
- psd.setProperty(props);
- pshd.addProvidedService(psd);
- }
- return pshd;
- }
-
- /**
- * @see org.apache.felix.ipojo.Handler#reconfigure(java.util.Dictionary)
- */
- public void reconfigure(Dictionary dict) {
- for (int j = 0; j < getProvidedService().length; j++) {
- ProvidedService ps = getProvidedService()[j];
- Property[] props = ps.getProperties();
- boolean update = false;
- for (int k = 0; k < props.length; k++) {
- if (dict.get(props[k].getName()) != null) {
- update = true;
- if (dict.get(props[k].getName()) instanceof String) {
- props[k].set((String) dict.get(props[k].getName()));
- } else { props[k].set(dict.get(props[k].getName())); }
- }
- }
- if (update) { ps.update(); }
- }
- }
+ for (int j = 0; j < getProvidedService().length; j++) {
+ ProvidedService ps = getProvidedService()[j];
+ ProvidedServiceDescription psd = new ProvidedServiceDescription(ps.getServiceSpecification(), ps.getState(), ps.getServiceReference());
+
+ Properties props = new Properties();
+ for (int k = 0; k < ps.getProperties().length; k++) {
+ Property prop = ps.getProperties()[k];
+ if (prop.getValue() != null) {
+ props.put(prop.getName(), prop.getValue().toString());
+ }
+ }
+ psd.setProperty(props);
+ pshd.addProvidedService(psd);
+ }
+ return pshd;
+ }
+
+ /**
+ * Reconfigure provided service.
+ * @param dict : the new instance configuration.
+ * @see org.apache.felix.ipojo.Handler#reconfigure(java.util.Dictionary)
+ */
+ public void reconfigure(Dictionary dict) {
+ for (int j = 0; j < getProvidedService().length; j++) {
+ ProvidedService ps = getProvidedService()[j];
+ Property[] props = ps.getProperties();
+ boolean update = false;
+ for (int k = 0; k < props.length; k++) {
+ if (dict.get(props[k].getName()) != null) {
+ update = true;
+ if (dict.get(props[k].getName()) instanceof String) {
+ props[k].set((String) dict.get(props[k].getName()));
+ } else {
+ props[k].set(dict.get(props[k].getName()));
+ }
+ }
+ }
+ if (update) {
+ ps.update();
+ }
+ }
+ }
}
diff --git a/ipojo/src/main/java/org/apache/felix/ipojo/handlers/providedservice/ProvidedServiceHandlerDescription.java b/ipojo/src/main/java/org/apache/felix/ipojo/handlers/providedservice/ProvidedServiceHandlerDescription.java
index 90acdc6..3645089 100644
--- a/ipojo/src/main/java/org/apache/felix/ipojo/handlers/providedservice/ProvidedServiceHandlerDescription.java
+++ b/ipojo/src/main/java/org/apache/felix/ipojo/handlers/providedservice/ProvidedServiceHandlerDescription.java
@@ -21,9 +21,12 @@
import java.util.Iterator;
import org.apache.felix.ipojo.architecture.HandlerDescription;
+import org.apache.felix.ipojo.metadata.Attribute;
+import org.apache.felix.ipojo.metadata.Element;
/**
* Provided Service Handler Description.
+ *
* @author <a href="mailto:felix-dev@incubator.apache.org">Felix Project Team</a>
*/
public class ProvidedServiceHandlerDescription extends HandlerDescription {
@@ -33,9 +36,9 @@
*/
private ProvidedServiceDescription[] m_providedServices = new ProvidedServiceDescription[0];
-
/**
* Constructor.
+ *
* @param isValid : the validity of the provided service handler.
*/
public ProvidedServiceHandlerDescription(boolean isValid) {
@@ -43,19 +46,25 @@
}
/**
+ * Get the provided service descriptions.
* @return the provided service description list.
*/
- public ProvidedServiceDescription[] getProvidedServices() { return m_providedServices; }
+ public ProvidedServiceDescription[] getProvidedServices() {
+ return m_providedServices;
+ }
/**
* Add a provided service.
+ *
* @param pds : the provided service to add
*/
public void addProvidedService(ProvidedServiceDescription pds) {
- //Verify that the provided service description is not already in the array.
- for (int i = 0; (i < m_providedServices.length); i++) {
+ // Verify that the provided service description is not already in the
+ // array.
+ for (int i = 0; i < m_providedServices.length; i++) {
if (m_providedServices[i] == pds) {
- return; //NOTHING DO DO, the description is already in the array
+ return; // NOTHING DO DO, the description is already in the
+ // array
}
}
// The component Description is not in the array, add it
@@ -66,27 +75,40 @@
}
/**
+ * Build the provided service handler description.
+ * @return the handler description.
* @see org.apache.felix.ipojo.architecture.HandlerDescription#getHandlerInfo()
*/
- public String getHandlerInfo() {
- String info = "";
+ public Element getHandlerInfo() {
+ Element services = super.getHandlerInfo();
for (int i = 0; i < m_providedServices.length; i++) {
+ Element service = new Element("service", "");
String state = "unregistered";
- if (m_providedServices[i].getState() == ProvidedService.REGISTERED) { state = "registered"; }
- String spec = "";
- for (int j = 0; j < m_providedServices[i].getServiceSpecification().length; j++) {
- spec += m_providedServices[i].getServiceSpecification()[j] + " ";
+ if (m_providedServices[i].getState() == ProvidedService.REGISTERED) {
+ state = "registered";
}
- info += "\t Provided Service [" + spec + "] is " + state;
+ String spec = "[";
+ for (int j = 0; j < m_providedServices[i].getServiceSpecification().length; j++) {
+ if (j == 0) {
+ spec += m_providedServices[i].getServiceSpecification()[j];
+ } else {
+ spec += ", " + m_providedServices[i].getServiceSpecification()[j];
+ }
+ }
+ spec += "]";
+ service.addAttribute(new Attribute("specifications", spec));
+ service.addAttribute(new Attribute("state", state));
Iterator it = m_providedServices[i].getProperties().keySet().iterator();
while (it.hasNext()) {
+ Element prop = new Element("property", "");
String k = (String) it.next();
- info += "\n\t\t Service Property : " + k + " = " + m_providedServices[i].getProperties().getProperty(k);
+ prop.addAttribute(new Attribute("name", k));
+ prop.addAttribute(new Attribute("value", m_providedServices[i].getProperties().getProperty(k).toString()));
+ service.addElement(prop);
}
+ services.addElement(service);
}
- return info;
+ return services;
}
-
-
}
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 58ff68a..09cd633 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
@@ -25,8 +25,8 @@
import org.apache.felix.ipojo.metadata.Element;
/**
- * Manifest Metadata parser.
- * Read a manifest file and construct metadata
+ * Manifest Metadata parser. Read a manifest file and construct metadata
+ *
* @author <a href="mailto:felix-dev@incubator.apache.org">Felix Project Team</a>
*/
public class ManifestMetadataParser {
@@ -42,6 +42,7 @@
private Element[] m_elements = new Element[0];
/**
+ * Get the array of component type metadata.
* @return the component metadata (composite & component).
* @throws ParseException when a parsing error occurs
*/
@@ -51,17 +52,18 @@
Element[] all = new Element[components.length + composites.length];
int l = 0;
for (int i = 0; i < components.length; i++) {
- all[l] = components[i];
- l++;
+ all[l] = components[i];
+ l++;
}
for (int i = 0; i < composites.length; i++) {
- all[l] = composites[i];
- l++;
+ all[l] = composites[i];
+ l++;
}
return all;
}
/**
+ * Get the array of instance configuration described in the metadata.
* @return the instances list.
* @throws ParseException : if the metadata cannot be parsed successfully
*/
@@ -73,53 +75,64 @@
}
return dicts;
}
-
+
/**
* Parse an Element to get a dictionary.
+ *
* @param instance : the Element describing an instance.
* @return : the resulting dictionary
- * @throws ParseException
+ * @throws ParseException : occurs when a configuration cannot be parse correctly.
*/
private Dictionary parseInstance(Element instance) throws ParseException {
- Dictionary dict = new Properties();
- if (!instance.containsAttribute("name")) { throw new ParseException("An instance does not have the 'name' attribute"); }
- if (!instance.containsAttribute("component")) { throw new ParseException("An instance does not have the 'component' attribute"); }
- dict.put("name", instance.getAttribute("name"));
- dict.put("component", instance.getAttribute("component"));
-
- for (int i = 0; i < instance.getElements("property").length; i++) {
- parseProperty(instance.getElements("property")[i], dict);
- }
-
- return dict;
+ Dictionary dict = new Properties();
+ if (!instance.containsAttribute("name")) {
+ throw new ParseException("An instance does not have the 'name' attribute");
+ }
+ if (!instance.containsAttribute("component")) {
+ throw new ParseException("An instance does not have the 'component' attribute");
+ }
+ dict.put("name", instance.getAttribute("name"));
+ dict.put("component", instance.getAttribute("component"));
+
+ for (int i = 0; i < instance.getElements("property").length; i++) {
+ parseProperty(instance.getElements("property")[i], dict);
+ }
+
+ return dict;
}
-
+
/**
- * @param prop
- * @param dict
- * @throws ParseException
+ * Parse a property.
+ * @param prop : the current element to parse
+ * @param dict : the dictionary to populate
+ * @throws ParseException : occurs if the proeprty cannot be parsed correctly
*/
private void parseProperty(Element prop, Dictionary dict) throws ParseException {
- // Check that the property has a name
- if (!prop.containsAttribute("name")) { throw new ParseException("A property does not have the 'name' attribute"); }
- // Final case : the property element has a 'value' attribute
- if (prop.containsAttribute("value")) {
- dict.put(prop.getAttribute("name"), prop.getAttribute("value"));
- } else {
- // Recursive case
- // Check if there is 'property' element
- Element[] subProps = prop.getElements("property");
- if (subProps.length == 0) { throw new ParseException("A complex property must have at least one 'property' sub-element"); }
- Dictionary dict2 = new Properties();
- for (int i = 0; i < subProps.length; i++) {
- parseProperty(subProps[i], dict2);
- dict.put(prop.getAttribute("name"), dict2);
- }
- }
+ // Check that the property has a name
+ if (!prop.containsAttribute("name")) {
+ throw new ParseException("A property does not have the 'name' attribute");
+ }
+ // Final case : the property element has a 'value' attribute
+ if (prop.containsAttribute("value")) {
+ dict.put(prop.getAttribute("name"), prop.getAttribute("value"));
+ } else {
+ // Recursive case
+ // Check if there is 'property' element
+ Element[] subProps = prop.getElements("property");
+ if (subProps.length == 0) {
+ throw new ParseException("A complex property must have at least one 'property' sub-element");
+ }
+ Dictionary dict2 = new Properties();
+ for (int i = 0; i < subProps.length; i++) {
+ parseProperty(subProps[i], dict2);
+ dict.put(prop.getAttribute("name"), dict2);
+ }
+ }
}
/**
* Add an element to the list.
+ *
* @param elem : the element to add
*/
private void addElement(Element elem) {
@@ -128,11 +141,14 @@
System.arraycopy(m_elements, 0, newElementsList, 0, m_elements.length);
newElementsList[m_elements.length] = elem;
m_elements = newElementsList;
- } else { m_elements = new Element[] {elem}; }
+ } else {
+ m_elements = new Element[] { elem };
+ }
}
/**
* Remove an element to the list.
+ *
* @return an element to remove
*/
private Element removeLastElement() {
@@ -155,32 +171,37 @@
/**
* Parse the given dictionnary and create the instance managers.
+ *
* @param dict : the given headers of the manifest file
* @throws ParseException : if any error occurs
*/
public void parse(Dictionary dict) throws ParseException {
m_headers = dict;
String componentClassesStr = (String) m_headers.get("iPOJO-Components");
- //Add the ipojo element inside the element list
+ // Add the ipojo element inside the element list
addElement(new Element("iPOJO", ""));
parseElements(componentClassesStr.trim());
}
/**
* Parse the metadata from the string given in argument.
+ *
* @param metadata : the metadata to parse
* @return Element : the root element resulting of the parsing
* @throws ParseException : if any error occurs
*/
- public static Element parse(String metadata) throws ParseException {
+ public static Element parse(String metadata) throws ParseException {
ManifestMetadataParser parser = new ManifestMetadataParser();
parser.parseElements(metadata);
- if (parser.m_elements.length != 1) { throw new ParseException("Error in parsing, root element not found : " + metadata); }
+ if (parser.m_elements.length != 1) {
+ throw new ParseException("Error in parsing, root element not found : " + metadata);
+ }
return parser.m_elements[0];
}
/**
* Paser the given string.
+ *
* @param s : the string to parse
*/
private void parseElements(String s) {
@@ -189,9 +210,9 @@
for (int i = 0; i < string.length; i++) {
char c = string[i];
- switch(c) {
- // Beginning of an attribute.
- case '$' :
+ switch (c) {
+ // Beginning of an attribute.
+ case '$':
String attName = "";
String attValue = "";
String attNs = "";
@@ -201,7 +222,9 @@
if (c == ':') {
attNs = attName;
attName = "";
- } else { attName = attName + c; }
+ } else {
+ attName = attName + c;
+ }
i = i + 1;
c = string[i];
}
@@ -216,12 +239,12 @@
i++; // skip "
c = string[i];
- Attribute att = new Attribute(attName, attNs , attValue);
+ Attribute att = new Attribute(attName, attNs, attValue);
m_elements[m_elements.length - 1].addAttribute(att);
break;
- // End of an element
- case '}' :
+ // End of an element
+ case '}':
Element lastElement = removeLastElement();
if (m_elements.length != 0) {
Element newQueue = m_elements[m_elements.length - 1];
@@ -232,33 +255,35 @@
break;
// Space
- case ' ' :
- break; // do nothing;
-
+ case ' ':
+ break; // do nothing;
+
// Default case
- default :
+ default:
String name = "";
- String ns = "";
- c = string[i];
- while (c != ' ') {
- if (c == ':') {
- ns = name;
- name = "";
- i++;
- c = string[i];
- } else {
- name = name + c;
- i++;
- c = string[i];
- }
- }
- // Skip spaces
- while (string[i] == ' ') { i = i + 1; }
- i = i + 1; // skip {
- Element elem = new Element(name, ns);
- addElement(elem);
- break;
- }
+ String ns = "";
+ c = string[i];
+ while (c != ' ') {
+ if (c == ':') {
+ ns = name;
+ name = "";
+ i++;
+ c = string[i];
+ } else {
+ name = name + c;
+ i++;
+ c = string[i];
+ }
+ }
+ // Skip spaces
+ while (string[i] == ' ') {
+ i = i + 1;
+ }
+ i = i + 1; // skip {
+ Element elem = new Element(name, ns);
+ addElement(elem);
+ break;
+ }
}
}
diff --git a/ipojo/src/main/java/org/apache/felix/ipojo/parser/ParseUtils.java b/ipojo/src/main/java/org/apache/felix/ipojo/parser/ParseUtils.java
index 19294f9..98fa65c 100644
--- a/ipojo/src/main/java/org/apache/felix/ipojo/parser/ParseUtils.java
+++ b/ipojo/src/main/java/org/apache/felix/ipojo/parser/ParseUtils.java
@@ -20,30 +20,34 @@
/**
* Parse Utils Methods.
+ *
* @author <a href="mailto:felix-dev@incubator.apache.org">Felix Project Team</a>
*/
public class ParseUtils {
-
- /**
- * Parse the string form of an array as {a, b, c}.
- * @param str : the string form
- * @return the resulting string array
- */
- public static String[] parseArrays(String str) {
- // Remove { and }
- if (str.startsWith("{") && str.endsWith("}")) {
- String m = str.substring(1, str.length() - 1);
- // Check empty array
- m = m.trim();
- if (m.length() == 0) { return new String[0]; }
- String[] values = m.split(",");
- for (int i = 0; i < values.length; i++) {
- values[i] = values[i].trim();
- }
- return values;
- } else {
- return new String[] {str};
- }
- }
+
+ /**
+ * Parse the string form of an array as {a, b, c}.
+ *
+ * @param str : the string form
+ * @return the resulting string array
+ */
+ public static String[] parseArrays(String str) {
+ // Remove { and }
+ if (str.startsWith("{") && str.endsWith("}")) {
+ String m = str.substring(1, str.length() - 1);
+ // Check empty array
+ m = m.trim();
+ if (m.length() == 0) {
+ return new String[0];
+ }
+ String[] values = m.split(",");
+ for (int i = 0; i < values.length; i++) {
+ values[i] = values[i].trim();
+ }
+ return values;
+ } else {
+ return new String[] { str };
+ }
+ }
}
diff --git a/ipojo/src/main/java/org/apache/felix/ipojo/util/Callback.java b/ipojo/src/main/java/org/apache/felix/ipojo/util/Callback.java
index 3e8f3f3..0b62ab2 100644
--- a/ipojo/src/main/java/org/apache/felix/ipojo/util/Callback.java
+++ b/ipojo/src/main/java/org/apache/felix/ipojo/util/Callback.java
@@ -23,10 +23,9 @@
import org.apache.felix.ipojo.InstanceManager;
-
-
/**
* A callback allows calling a method on the component instances.
+ *
* @author <a href="mailto:felix-dev@incubator.apache.org">Felix Project Team</a>
*/
public class Callback {
@@ -48,6 +47,7 @@
/**
* LifecycleCallback constructor.
+ *
* @param method : the name of the method to call
* @param isStatic : is the method a static method
* @param im : the instance manager of the component containing the method
@@ -60,28 +60,31 @@
/**
* Call the method.
+ *
* @throws NoSuchMethodException : Method is not found in the class
* @throws InvocationTargetException : The method is not static
* @throws IllegalAccessException : The method can not be invoked
*/
public void call() throws NoSuchMethodException, IllegalAccessException, InvocationTargetException {
- m_manager.getFactory().getLogger().log(Logger.INFO, "[" + m_manager.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().getDeclaredMethod(m_method, new Class[] {});
method.setAccessible(true);
- if (m_isStatic) {
- method.invoke(null, new Object[]{});
+ if (m_isStatic) {
+ method.invoke(null, new Object[] {});
} else {
// Two cases :
// - if instances already exists : call on each instances
// - if no instance exists : create an instance
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[]{});
+ 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.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[]{});
+ 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[] {});
}
}
}
@@ -89,13 +92,13 @@
/**
* Call the current callback method on the instance given in parameter.
+ *
* @param instance : instance on which call the callbakc
* @throws NoSuchMethodException : the method was not found
* @throws IllegalAccessException : the method cannont be called
* @throws InvocationTargetException : an error happens in the method
*/
- public void call(Object instance) throws NoSuchMethodException,
- IllegalAccessException, InvocationTargetException {
+ public void call(Object instance) throws NoSuchMethodException, IllegalAccessException, InvocationTargetException {
Method method = m_manager.getClazz().getDeclaredMethod(m_method, new Class[] {});
method.setAccessible(true);
method.invoke(instance, new Object[] {});
@@ -103,32 +106,35 @@
/**
* Call the callback on the method with the argument given in parameter.
+ *
* @param arg : the parameters
* @throws NoSuchMethodException : the callback method is not found
* @throws IllegalAccessException : the callbback method cannot be called
- * @throws InvocationTargetException : an error occurs inside the called method
+ * @throws InvocationTargetException : an error occurs inside the called
+ * method
*/
public void call(Object[] arg) throws NoSuchMethodException, IllegalAccessException, InvocationTargetException {
- m_manager.getFactory().getLogger().log(Logger.INFO, "[" + m_manager.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];
for (int i = 0; i < arg.length; i++) {
classes[i] = arg[i].getClass();
}
-
+
Method method = m_manager.getClazz().getDeclaredMethod(m_method, classes);
method.setAccessible(true);
- if (m_isStatic) {
- method.invoke(null, arg);
+ if (m_isStatic) {
+ method.invoke(null, arg);
} else {
// Two cases :
// - if instances already exists : call on each instances
// - if no instance exists : create an instance
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[]{});
+ 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.getPojoObjects().length; i++) {
method.invoke(m_manager.getPojoObjects()[i], arg);
@@ -138,12 +144,15 @@
}
/**
- * Call the callback on the method with the argument given in parameter and with the arguments given in parameter too.
+ * Call the callback on the method with the argument given in parameter and
+ * with the arguments given in parameter too.
+ *
* @param instance : instance on which call the callback
* @param arg : the argument array
* @throws NoSuchMethodException : the callback method is not found
* @throws IllegalAccessException : the callbback method cannot be called
- * @throws InvocationTargetException : an error occurs inside the called method
+ * @throws InvocationTargetException : an error occurs inside the called
+ * method
*/
public void call(Object instance, Object[] arg) throws NoSuchMethodException, IllegalAccessException, InvocationTargetException {
// Build an array of call for 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
index b548efb..6f8c601 100644
--- a/ipojo/src/main/java/org/apache/felix/ipojo/util/Logger.java
+++ b/ipojo/src/main/java/org/apache/felix/ipojo/util/Logger.java
@@ -26,152 +26,178 @@
import org.osgi.service.log.LogService;
/**
- * iPOJO Logger.
- * This logger send log message to a log service if presents.
+ * iPOJO Logger. This logger send log message to a log service if presents.
+ *
* @author <a href="mailto:felix-dev@incubator.apache.org">Felix Project Team</a>
*/
public class Logger implements ServiceListener {
-
- // TODO how to stop the logging (remove listener ...)
-
- /**
- * Log Level ERROR.
- */
- public static final int ERROR = 1;
-
- /**
- * Log Level WARNING.
+
+ // TODO how to stop the logging (remove listener ...)
+
+ /**
+ * Log Level ERROR.
+ */
+ public static final int ERROR = 1;
+
+ /**
+ * Log Level WARNING.
*/
public static final int WARNING = 2;
-
+
/**
* Log Level INFO.
*/
public static final int INFO = 3;
-
+
/**
- * Log Level DEBUG.
+ * Log Level DEBUG.
*/
public static final int DEBUG = 4;
-
+
/**
* Bundle Context.
*/
private BundleContext m_context;
-
+
/**
- * Service Reference of the log service is available.
+ * Service Reference of the log service is available.
*/
private ServiceReference m_ref;
-
+
/**
- * Log service object.
+ * Log service object.
*/
private LogService m_log;
-
+
/**
- * Name of the logger.
+ * Name of the logger.
*/
private String m_name;
-
+
/**
- * trace level of this logger.
+ * trace level of this logger.
*/
private int m_level;
-
+
/**
* Constructor.
+ *
* @param bc : bundle context
* @param name : name of the logger
* @param level : trace level
*/
- public Logger(BundleContext bc, String name, int level) {
- m_name = name;
- m_level = level;
- m_context = bc;
-
- m_ref = m_context.getServiceReference(LogService.class.getName());
- if (m_ref != null) { m_log = (LogService) m_context.getService(m_ref); }
-
- try {
- m_context.addServiceListener(this, "(objectClass=" + LogService.class.getName() + ")");
- } catch (InvalidSyntaxException e) { e.printStackTrace(); }
+ 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();
+ }
}
-
+
/**
* Log a message.
+ *
* @param level : level of the message
* @param msg : the message to log
*/
public void log(int level, String msg) {
- if (m_level >= level) {
- synchronized (this) { _log(level, msg, null); }
- }
+ if (m_level >= level) {
+ synchronized (this) {
+ dispatch(level, msg, null);
+ }
+ }
}
-
+
/**
* Log a message with an exception.
+ *
* @param level : level of the message
* @param msg : message to log
* @param ex : exception attached to the message
*/
public void log(int level, String msg, Throwable ex) {
- if (m_level >= level) {
- synchronized (this) { _log(level, msg, ex); }
- }
+ if (m_level >= level) {
+ synchronized (this) {
+ dispatch(level, msg, ex);
+ }
+ }
}
-
+
/**
* Internal log method.
+ *
* @param level : level of the message.
* @param msg : message to log
* @param ex : exception attached to the message
*/
- private void _log(int level, String msg, Throwable ex) {
+ private void dispatch(int level, String msg, Throwable ex) {
String s = msg;
- s = (ex == null) ? s : s + " (" + ex.getMessage() + ")";
+ if (ex != null) {
+ 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); }
+ 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); }
+ 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);
+ 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); }
+ 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);
- break;
+ break;
}
}
- /**
- * @see org.osgi.framework.ServiceListener#serviceChanged(org.osgi.framework.ServiceEvent)
- */
- 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); }
- }
-
- }
+ /**
+ * Service Listener implementation.
+ * @param ev : the service event
+ * @see org.osgi.framework.ServiceListener#serviceChanged(org.osgi.framework.ServiceEvent)
+ */
+ 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/cm/Configuration.java b/ipojo/src/main/java/org/osgi/service/cm/Configuration.java
index a4d54cd..90a633f 100644
--- a/ipojo/src/main/java/org/osgi/service/cm/Configuration.java
+++ b/ipojo/src/main/java/org/osgi/service/cm/Configuration.java
@@ -1,19 +1,21 @@
/*
- * $Header: /cvshome/build/org.osgi.service.cm/src/org/osgi/service/cm/Configuration.java,v 1.16 2006/03/14 01:21:09 hargrave Exp $
- *
+ * $Header:
+ * /cvshome/build/org.osgi.service.cm/src/org/osgi/service/cm/Configuration.java,v
+ * 1.16 2006/03/14 01:21:09 hargrave Exp $
+ *
* Copyright (c) OSGi Alliance (2001, 2005). 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
- *
+ *
+ * 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.
+ * 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.cm;
@@ -63,165 +65,165 @@
* @version $Revision: 1.16 $
*/
public interface Configuration {
- /**
- * Get the PID for this <code>Configuration</code> object.
- *
- * @return the PID for this <code>Configuration</code> object.
- * @throws IllegalStateException if this configuration has been deleted
- */
- public String getPid();
+ /**
+ * Get the PID for this <code>Configuration</code> object.
+ *
+ * @return the PID for this <code>Configuration</code> object.
+ * @throws IllegalStateException if this configuration has been deleted
+ */
+ public String getPid();
- /**
- * Return the properties of this <code>Configuration</code> object.
- *
- * The <code>Dictionary</code> object returned is a private copy for the
- * caller and may be changed without influencing the stored configuration.
- * The keys in the returned dictionary are case insensitive and are always
- * of type <code>String</code>.
- *
- * <p>
- * If called just after the configuration is created and before update has
- * been called, this method returns <code>null</code>.
- *
- * @return A private copy of the properties for the caller or
- * <code>null</code>. These properties must not contain the
- * "service.bundleLocation" property. The value of this property may
- * be obtained from the <code>getBundleLocation</code> method.
- * @throws IllegalStateException if this configuration has been deleted
- */
- public Dictionary getProperties();
+ /**
+ * Return the properties of this <code>Configuration</code> object.
+ *
+ * The <code>Dictionary</code> object returned is a private copy for the
+ * caller and may be changed without influencing the stored configuration.
+ * The keys in the returned dictionary are case insensitive and are always
+ * of type <code>String</code>.
+ *
+ * <p>
+ * If called just after the configuration is created and before update has
+ * been called, this method returns <code>null</code>.
+ *
+ * @return A private copy of the properties for the caller or
+ * <code>null</code>. These properties must not contain the
+ * "service.bundleLocation" property. The value of this property may be
+ * obtained from the <code>getBundleLocation</code> method.
+ * @throws IllegalStateException if this configuration has been deleted
+ */
+ public Dictionary getProperties();
- /**
- * Update the properties of this <code>Configuration</code> object.
- *
- * Stores the properties in persistent storage after adding or overwriting
- * the following properties:
- * <ul>
- * <li>"service.pid" : is set to be the PID of this configuration.</li>
- * <li>"service.factoryPid" : if this is a factory configuration it is set
- * to the factory PID else it is not set.</li>
- * </ul>
- * These system properties are all of type <code>String</code>.
- *
- * <p>
- * If the corresponding Managed Service/Managed Service Factory is
- * registered, its updated method must be called asynchronously. Else, this
- * callback is delayed until aforementioned registration occurs.
- *
- * <p>
- * Also intiates an asynchronous call to all
- * <code>ConfigurationListener</code>s with a
- * <code>ConfigurationEvent.CM_UPDATED</code> event.
- *
- * @param properties the new set of properties for this configuration
- * @throws IOException if update cannot be made persistent
- * @throws IllegalArgumentException if the <code>Dictionary</code> object
- * contains invalid configuration types or contains case variants of
- * the same key name.
- * @throws IllegalStateException if this configuration has been deleted
- */
- public void update(Dictionary properties) throws IOException;
+ /**
+ * Update the properties of this <code>Configuration</code> object.
+ *
+ * Stores the properties in persistent storage after adding or overwriting
+ * the following properties:
+ * <ul>
+ * <li>"service.pid" : is set to be the PID of this configuration.</li>
+ * <li>"service.factoryPid" : if this is a factory configuration it is set
+ * to the factory PID else it is not set.</li>
+ * </ul>
+ * These system properties are all of type <code>String</code>.
+ *
+ * <p>
+ * If the corresponding Managed Service/Managed Service Factory is
+ * registered, its updated method must be called asynchronously. Else, this
+ * callback is delayed until aforementioned registration occurs.
+ *
+ * <p>
+ * Also intiates an asynchronous call to all
+ * <code>ConfigurationListener</code>s with a
+ * <code>ConfigurationEvent.CM_UPDATED</code> event.
+ *
+ * @param properties the new set of properties for this configuration
+ * @throws IOException if update cannot be made persistent
+ * @throws IllegalArgumentException if the <code>Dictionary</code> object
+ * contains invalid configuration types or contains case variants of the
+ * same key name.
+ * @throws IllegalStateException if this configuration has been deleted
+ */
+ public void update(Dictionary properties) throws IOException;
- /**
- * Delete this <code>Configuration</code> object.
- *
- * Removes this configuration object from the persistent store. Notify
- * asynchronously the corresponding Managed Service or Managed Service
- * Factory. A <code>ManagedService</code> object is notified by a call to
- * its <code>updated</code> method with a <code>null</code> properties
- * argument. A <code>ManagedServiceFactory</code> object is notified by a
- * call to its <code>deleted</code> method.
- *
- * <p>
- * Also intiates an asynchronous call to all
- * <code>ConfigurationListener</code>s with a
- * <code>ConfigurationEvent.CM_DELETED</code> event.
- *
- * @throws IOException If delete fails
- * @throws IllegalStateException if this configuration has been deleted
- */
- public void delete() throws IOException;
+ /**
+ * Delete this <code>Configuration</code> object.
+ *
+ * Removes this configuration object from the persistent store. Notify
+ * asynchronously the corresponding Managed Service or Managed Service
+ * Factory. A <code>ManagedService</code> object is notified by a call to
+ * its <code>updated</code> method with a <code>null</code> properties
+ * argument. A <code>ManagedServiceFactory</code> object is notified by a
+ * call to its <code>deleted</code> method.
+ *
+ * <p>
+ * Also intiates an asynchronous call to all
+ * <code>ConfigurationListener</code>s with a
+ * <code>ConfigurationEvent.CM_DELETED</code> event.
+ *
+ * @throws IOException If delete fails
+ * @throws IllegalStateException if this configuration has been deleted
+ */
+ public void delete() throws IOException;
- /**
- * For a factory configuration return the PID of the corresponding Managed
- * Service Factory, else return <code>null</code>.
- *
- * @return factory PID or <code>null</code>
- * @throws IllegalStateException if this configuration has been deleted
- */
- public String getFactoryPid();
+ /**
+ * For a factory configuration return the PID of the corresponding Managed
+ * Service Factory, else return <code>null</code>.
+ *
+ * @return factory PID or <code>null</code>
+ * @throws IllegalStateException if this configuration has been deleted
+ */
+ public String getFactoryPid();
- /**
- * Update the <code>Configuration</code> object with the current
- * properties.
- *
- * Initiate the <code>updated</code> callback to the Managed Service or
- * Managed Service Factory with the current properties asynchronously.
- *
- * <p>
- * This is the only way for a bundle that uses a Configuration Plugin
- * service to initate a callback. For example, when that bundle detects a
- * change that requires an update of the Managed Service or Managed Service
- * Factory via its <code>ConfigurationPlugin</code> object.
- *
- * @see ConfigurationPlugin
- * @throws IOException if update cannot access the properties in persistent
- * storage
- * @throws IllegalStateException if this configuration has been deleted
- */
- public void update() throws IOException;
+ /**
+ * Update the <code>Configuration</code> object with the current
+ * properties.
+ *
+ * Initiate the <code>updated</code> callback to the Managed Service or
+ * Managed Service Factory with the current properties asynchronously.
+ *
+ * <p>
+ * This is the only way for a bundle that uses a Configuration Plugin
+ * service to initate a callback. For example, when that bundle detects a
+ * change that requires an update of the Managed Service or Managed Service
+ * Factory via its <code>ConfigurationPlugin</code> object.
+ *
+ * @see ConfigurationPlugin
+ * @throws IOException if update cannot access the properties in persistent
+ * storage
+ * @throws IllegalStateException if this configuration has been deleted
+ */
+ public void update() throws IOException;
- /**
- * Bind this <code>Configuration</code> object to the specified bundle
- * location.
- *
- * If the bundleLocation parameter is <code>null</code> then the
- * <code>Configuration</code> object will not be bound to a location. It
- * will be set to the bundle's location before the first time a Managed
- * Service/Managed Service Factory receives this <code>Configuration</code>
- * object via the updated method and before any plugins are called. The
- * bundle location will be set persistently.
- *
- * @param bundleLocation a bundle location or <code>null</code>
- * @throws IllegalStateException If this configuration has been deleted.
- * @throws SecurityException If the caller does not have
- * <code>ConfigurationPermission[*,CONFIGURE]</code>.
- */
- public void setBundleLocation(String bundleLocation);
+ /**
+ * Bind this <code>Configuration</code> object to the specified bundle
+ * location.
+ *
+ * If the bundleLocation parameter is <code>null</code> then the
+ * <code>Configuration</code> object will not be bound to a location. It
+ * will be set to the bundle's location before the first time a Managed
+ * Service/Managed Service Factory receives this <code>Configuration</code>
+ * object via the updated method and before any plugins are called. The
+ * bundle location will be set persistently.
+ *
+ * @param bundleLocation a bundle location or <code>null</code>
+ * @throws IllegalStateException If this configuration has been deleted.
+ * @throws SecurityException If the caller does not have
+ * <code>ConfigurationPermission[*,CONFIGURE]</code>.
+ */
+ public void setBundleLocation(String bundleLocation);
- /**
- * Get the bundle location.
- *
- * Returns the bundle location to which this configuration is bound, or
- * <code>null</code> if it is not yet bound to a bundle location.
- *
- * @return location to which this configuration is bound, or
- * <code>null</code>.
- * @throws IllegalStateException If this <code>Configuration</code> object
- * has been deleted.
- * @throws SecurityException If the caller does not have
- * <code>ConfigurationPermission[*,CONFIGURE]</code>.
- */
- public String getBundleLocation();
+ /**
+ * Get the bundle location.
+ *
+ * Returns the bundle location to which this configuration is bound, or
+ * <code>null</code> if it is not yet bound to a bundle location.
+ *
+ * @return location to which this configuration is bound, or
+ * <code>null</code>.
+ * @throws IllegalStateException If this <code>Configuration</code> object
+ * has been deleted.
+ * @throws SecurityException If the caller does not have
+ * <code>ConfigurationPermission[*,CONFIGURE]</code>.
+ */
+ public String getBundleLocation();
- /**
- * Equality is defined to have equal PIDs
- *
- * Two Configuration objects are equal when their PIDs are equal.
- *
- * @param other <code>Configuration</code> object to compare against
- * @return <code>true</code> if equal, <code>false</code> if not a
- * <code>Configuration</code> object or one with a different PID.
- */
- public boolean equals(Object other);
+ /**
+ * Equality is defined to have equal PIDs
+ *
+ * Two Configuration objects are equal when their PIDs are equal.
+ *
+ * @param other <code>Configuration</code> object to compare against
+ * @return <code>true</code> if equal, <code>false</code> if not a
+ * <code>Configuration</code> object or one with a different PID.
+ */
+ public boolean equals(Object other);
- /**
- * Hash code is based on PID.
- *
- * The hashcode for two Configuration objects must be the same when the
- * Configuration PID's are the same.
- *
- * @return hash code for this Configuration object
- */
- public int hashCode();
+ /**
+ * Hash code is based on PID.
+ *
+ * The hashcode for two Configuration objects must be the same when the
+ * Configuration PID's are the same.
+ *
+ * @return hash code for this Configuration object
+ */
+ public int hashCode();
}
diff --git a/ipojo/src/main/java/org/osgi/service/cm/ConfigurationAdmin.java b/ipojo/src/main/java/org/osgi/service/cm/ConfigurationAdmin.java
index f0f7836..0ca830c 100644
--- a/ipojo/src/main/java/org/osgi/service/cm/ConfigurationAdmin.java
+++ b/ipojo/src/main/java/org/osgi/service/cm/ConfigurationAdmin.java
@@ -1,19 +1,21 @@
/*
- * $Header: /cvshome/build/org.osgi.service.cm/src/org/osgi/service/cm/ConfigurationAdmin.java,v 1.14 2006/03/14 01:21:09 hargrave Exp $
- *
+ * $Header:
+ * /cvshome/build/org.osgi.service.cm/src/org/osgi/service/cm/ConfigurationAdmin.java,v
+ * 1.14 2006/03/14 01:21:09 hargrave Exp $
+ *
* Copyright (c) OSGi Alliance (2001, 2005). 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
- *
+ *
+ * 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.
+ * 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.cm;
@@ -103,154 +105,157 @@
* @version $Revision: 1.14 $
*/
public interface ConfigurationAdmin {
- /**
- * Service property naming the Factory PID in the configuration dictionary.
- * The property's value is of type <code>String</code>.
- *
- * @since 1.1
- */
- public final static String SERVICE_FACTORYPID = "service.factoryPid";
- /**
- * Service property naming the location of the bundle that is associated
- * with a a <code>Configuration</code> object. This property can be
- * searched for but must not appear in the configuration dictionary for
- * security reason. The property's value is of type <code>String</code>.
- *
- * @since 1.1
- */
- public final static String SERVICE_BUNDLELOCATION = "service.bundleLocation";
+ /**
+ * Service property naming the Factory PID in the configuration dictionary.
+ * The property's value is of type <code>String</code>.
+ *
+ * @since 1.1
+ */
+ public final static String SERVICE_FACTORYPID = "service.factoryPid";
- /**
- * Create a new factory <code>Configuration</code> object with a new PID.
- *
- * The properties of the new <code>Configuration</code> object are
- * <code>null</code> until the first time that its
- * {@link Configuration#update(Dictionary)}method is called.
- *
- * <p>
- * It is not required that the <code>factoryPid</code> maps to a
- * registered Managed Service Factory.
- * <p>
- * The <code>Configuration</code> object is bound to the location of the
- * calling bundle.
- *
- * @param factoryPid PID of factory (not <code>null</code>).
- * @return A new <code>Configuration</code> object.
- * @throws IOException if access to persistent storage fails.
- * @throws SecurityException if caller does not have <code>ConfigurationPermission[*,CONFIGURE]</code> and <code>factoryPid</code> is bound to another bundle.
- */
- public Configuration createFactoryConfiguration(String factoryPid)
- throws IOException;
+ /**
+ * Service property naming the location of the bundle that is associated
+ * with a a <code>Configuration</code> object. This property can be
+ * searched for but must not appear in the configuration dictionary for
+ * security reason. The property's value is of type <code>String</code>.
+ *
+ * @since 1.1
+ */
+ public final static String SERVICE_BUNDLELOCATION = "service.bundleLocation";
- /**
- * Create a new factory <code>Configuration</code> object with a new PID.
- *
- * The properties of the new <code>Configuration</code> object are
- * <code>null</code> until the first time that its
- * {@link Configuration#update(Dictionary)}method is called.
- *
- * <p>
- * It is not required that the <code>factoryPid</code> maps to a
- * registered Managed Service Factory.
- *
- * <p>
- * The <code>Configuration</code> is bound to the location specified. If
- * this location is <code>null</code> it will be bound to the location of
- * the first bundle that registers a Managed Service Factory with a
- * corresponding PID.
- *
- * @param factoryPid PID of factory (not <code>null</code>).
- * @param location A bundle location string, or <code>null</code>.
- * @return a new <code>Configuration</code> object.
- * @throws IOException if access to persistent storage fails.
- * @throws SecurityException if caller does not have <code>ConfigurationPermission[*,CONFIGURE]</code>.
- */
- public Configuration createFactoryConfiguration(String factoryPid, String location)
- throws IOException;
+ /**
+ * Create a new factory <code>Configuration</code> object with a new PID.
+ *
+ * The properties of the new <code>Configuration</code> object are
+ * <code>null</code> until the first time that its
+ * {@link Configuration#update(Dictionary)}method is called.
+ *
+ * <p>
+ * It is not required that the <code>factoryPid</code> maps to a
+ * registered Managed Service Factory.
+ * <p>
+ * The <code>Configuration</code> object is bound to the location of the
+ * calling bundle.
+ *
+ * @param factoryPid PID of factory (not <code>null</code>).
+ * @return A new <code>Configuration</code> object.
+ * @throws IOException if access to persistent storage fails.
+ * @throws SecurityException if caller does not have
+ * <code>ConfigurationPermission[*,CONFIGURE]</code> and
+ * <code>factoryPid</code> is bound to another bundle.
+ */
+ public Configuration createFactoryConfiguration(String factoryPid) throws IOException;
- /**
- * Get an existing <code>Configuration</code> object from the persistent
- * store, or create a new <code>Configuration</code> object.
- *
- * <p>
- * If a <code>Configuration</code> with this PID already exists in
- * Configuration Admin service return it. The location parameter is ignored
- * in this case.
- *
- * <p>
- * Else, return a new <code>Configuration</code> object. This new object
- * is bound to the location and the properties are set to <code>null</code>.
- * If the location parameter is <code>null</code>, it will be set when a
- * Managed Service with the corresponding PID is registered for the first
- * time.
- *
- * @param pid Persistent identifier.
- * @param location The bundle location string, or <code>null</code>.
- * @return An existing or new <code>Configuration</code> object.
- * @throws IOException if access to persistent storage fails.
- * @throws SecurityException if the caller does not have <code>ConfigurationPermission[*,CONFIGURE]</code>.
- */
- public Configuration getConfiguration(String pid, String location)
- throws IOException;
+ /**
+ * Create a new factory <code>Configuration</code> object with a new PID.
+ *
+ * The properties of the new <code>Configuration</code> object are
+ * <code>null</code> until the first time that its
+ * {@link Configuration#update(Dictionary)}method is called.
+ *
+ * <p>
+ * It is not required that the <code>factoryPid</code> maps to a
+ * registered Managed Service Factory.
+ *
+ * <p>
+ * The <code>Configuration</code> is bound to the location specified. If
+ * this location is <code>null</code> it will be bound to the location of
+ * the first bundle that registers a Managed Service Factory with a
+ * corresponding PID.
+ *
+ * @param factoryPid PID of factory (not <code>null</code>).
+ * @param location A bundle location string, or <code>null</code>.
+ * @return a new <code>Configuration</code> object.
+ * @throws IOException if access to persistent storage fails.
+ * @throws SecurityException if caller does not have
+ * <code>ConfigurationPermission[*,CONFIGURE]</code>.
+ */
+ public Configuration createFactoryConfiguration(String factoryPid, String location) throws IOException;
- /**
- * Get an existing or new <code>Configuration</code> object from the
- * persistent store.
- *
- * If the <code>Configuration</code> object for this PID does not exist,
- * create a new <code>Configuration</code> object for that PID, where
- * properties are <code>null</code>. Bind its location to the calling
- * bundle's location.
- *
- * <p>
- * Otherwise, if the location of the existing <code>Configuration</code> object
- * is <code>null</code>, set it to the calling bundle's location.
- *
- * @param pid persistent identifier.
- * @return an existing or new <code>Configuration</code> matching the PID.
- * @throws IOException if access to persistent storage fails.
- * @throws SecurityException if the <code>Configuration</code> object is bound to a location different from that of the calling bundle and it has no <code>ConfigurationPermission[*,CONFIGURE]</code>.
- */
- public Configuration getConfiguration(String pid) throws IOException;
+ /**
+ * Get an existing <code>Configuration</code> object from the persistent
+ * store, or create a new <code>Configuration</code> object.
+ *
+ * <p>
+ * If a <code>Configuration</code> with this PID already exists in
+ * Configuration Admin service return it. The location parameter is ignored
+ * in this case.
+ *
+ * <p>
+ * Else, return a new <code>Configuration</code> object. This new object
+ * is bound to the location and the properties are set to <code>null</code>.
+ * If the location parameter is <code>null</code>, it will be set when a
+ * Managed Service with the corresponding PID is registered for the first
+ * time.
+ *
+ * @param pid Persistent identifier.
+ * @param location The bundle location string, or <code>null</code>.
+ * @return An existing or new <code>Configuration</code> object.
+ * @throws IOException if access to persistent storage fails.
+ * @throws SecurityException if the caller does not have
+ * <code>ConfigurationPermission[*,CONFIGURE]</code>.
+ */
+ public Configuration getConfiguration(String pid, String location) throws IOException;
- /**
- * List the current <code>Configuration</code> objects which match the
- * filter.
- *
- * <p>
- * Only <code>Configuration</code> objects with non- <code>null</code>
- * properties are considered current. That is,
- * <code>Configuration.getProperties()</code> is guaranteed not to return
- * <code>null</code> for each of the returned <code>Configuration</code>
- * objects.
- *
- * <p>
- * Normally only <code>Configuration</code> objects that are bound to the
- * location of the calling bundle are returned, or all if the caller has
- * <code>ConfigurationPermission[*,CONFIGURE]</code>.
- *
- * <p>
- * The syntax of the filter string is as defined in the <code>Filter</code>
- * class. The filter can test any configuration parameters including the
- * following system properties:
- * <ul>
- * <li><code>service.pid</code>-<code>String</code>- the PID under
- * which this is registered</li>
- * <li><code>service.factoryPid</code>-<code>String</code>- the
- * factory if applicable</li>
- * <li><code>service.bundleLocation</code>-<code>String</code>- the
- * bundle location</li>
- * </ul>
- * The filter can also be <code>null</code>, meaning that all
- * <code>Configuration</code> objects should be returned.
- *
- * @param filter a <code>Filter</code> object, or <code>null</code> to
- * retrieve all <code>Configuration</code> objects.
- * @return all matching <code>Configuration</code> objects, or
- * <code>null</code> if there aren't any
- * @throws IOException if access to persistent storage fails
- * @throws InvalidSyntaxException if the filter string is invalid
- */
- public Configuration[] listConfigurations(String filter) throws IOException,
- InvalidSyntaxException;
+ /**
+ * Get an existing or new <code>Configuration</code> object from the
+ * persistent store.
+ *
+ * If the <code>Configuration</code> object for this PID does not exist,
+ * create a new <code>Configuration</code> object for that PID, where
+ * properties are <code>null</code>. Bind its location to the calling
+ * bundle's location.
+ *
+ * <p>
+ * Otherwise, if the location of the existing <code>Configuration</code>
+ * object is <code>null</code>, set it to the calling bundle's location.
+ *
+ * @param pid persistent identifier.
+ * @return an existing or new <code>Configuration</code> matching the PID.
+ * @throws IOException if access to persistent storage fails.
+ * @throws SecurityException if the <code>Configuration</code> object is
+ * bound to a location different from that of the calling bundle and it has
+ * no <code>ConfigurationPermission[*,CONFIGURE]</code>.
+ */
+ public Configuration getConfiguration(String pid) throws IOException;
+
+ /**
+ * List the current <code>Configuration</code> objects which match the
+ * filter.
+ *
+ * <p>
+ * Only <code>Configuration</code> objects with non- <code>null</code>
+ * properties are considered current. That is,
+ * <code>Configuration.getProperties()</code> is guaranteed not to return
+ * <code>null</code> for each of the returned <code>Configuration</code>
+ * objects.
+ *
+ * <p>
+ * Normally only <code>Configuration</code> objects that are bound to the
+ * location of the calling bundle are returned, or all if the caller has
+ * <code>ConfigurationPermission[*,CONFIGURE]</code>.
+ *
+ * <p>
+ * The syntax of the filter string is as defined in the <code>Filter</code>
+ * class. The filter can test any configuration parameters including the
+ * following system properties:
+ * <ul>
+ * <li><code>service.pid</code>-<code>String</code>- the PID under
+ * which this is registered</li>
+ * <li><code>service.factoryPid</code>-<code>String</code>- the
+ * factory if applicable</li>
+ * <li><code>service.bundleLocation</code>-<code>String</code>- the
+ * bundle location</li>
+ * </ul>
+ * The filter can also be <code>null</code>, meaning that all
+ * <code>Configuration</code> objects should be returned.
+ *
+ * @param filter a <code>Filter</code> object, or <code>null</code> to
+ * retrieve all <code>Configuration</code> objects.
+ * @return all matching <code>Configuration</code> objects, or
+ * <code>null</code> if there aren't any
+ * @throws IOException if access to persistent storage fails
+ * @throws InvalidSyntaxException if the filter string is invalid
+ */
+ public Configuration[] listConfigurations(String filter) throws IOException, InvalidSyntaxException;
}
diff --git a/ipojo/src/main/java/org/osgi/service/cm/ConfigurationEvent.java b/ipojo/src/main/java/org/osgi/service/cm/ConfigurationEvent.java
index 28ef9e4..31683ac 100644
--- a/ipojo/src/main/java/org/osgi/service/cm/ConfigurationEvent.java
+++ b/ipojo/src/main/java/org/osgi/service/cm/ConfigurationEvent.java
@@ -1,19 +1,21 @@
/*
- * $Header: /cvshome/build/org.osgi.service.cm/src/org/osgi/service/cm/ConfigurationEvent.java,v 1.8 2006/03/14 01:21:09 hargrave Exp $
+ * $Header:
+ * /cvshome/build/org.osgi.service.cm/src/org/osgi/service/cm/ConfigurationEvent.java,v
+ * 1.8 2006/03/14 01:21:09 hargrave Exp $
*
* Copyright (c) OSGi Alliance (2004, 2005). 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
- *
+ * 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.
+ * 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.cm;
@@ -50,118 +52,122 @@
* @since 1.2
*/
public class ConfigurationEvent {
- /**
- * A <code>Configuration</code> has been updated.
- *
- * <p>
- * This <code>ConfigurationEvent</code> type that indicates that a
- * <code>Configuration</code> object has been updated with new properties.
- *
- * An event is fired when a call to <code>Configuration.update</code>
- * successfully changes a configuration.
- *
- * <p>
- * The value of <code>CM_UPDATED</code> is 1.
- */
- public static final int CM_UPDATED = 1;
- /**
- * A <code>Configuration</code> has been deleted.
- *
- * <p>
- * This <code>ConfigurationEvent</code> type that indicates that a
- * <code>Configuration</code> object has been deleted.
- *
- * An event is fired when a call to <code>Configuration.delete</code>
- * successfully deletes a configuration.
- *
- * <p>
- * The value of <code>CM_DELETED</code> is 2.
- */
- public static final int CM_DELETED = 2;
- /**
- * Type of this event.
- *
- * @see #getType
- */
- private final int type;
- /**
- * The factory pid associated with this event.
- */
- private final String factoryPid;
- /**
- * The pid associated with this event.
- */
- private final String pid;
- /**
- * The ConfigurationAdmin service which created this event.
- */
- private final ServiceReference reference;
+ /**
+ * A <code>Configuration</code> has been updated.
+ *
+ * <p>
+ * This <code>ConfigurationEvent</code> type that indicates that a
+ * <code>Configuration</code> object has been updated with new properties.
+ *
+ * An event is fired when a call to <code>Configuration.update</code>
+ * successfully changes a configuration.
+ *
+ * <p>
+ * The value of <code>CM_UPDATED</code> is 1.
+ */
+ public static final int CM_UPDATED = 1;
- /**
- * Constructs a <code>ConfigurationEvent</code> object from the given
- * <code>ServiceReference</code> object, event type, and pids.
- *
- * @param reference The <code>ServiceReference</code> object of the
- * Configuration Admin service that created this event.
- * @param type The event type. See {@link #getType}.
- * @param factoryPid The factory pid of the associated configuration if the
- * target of the configuration is a ManagedServiceFactory. Otherwise
- * <code>null</code> if the target of the configuration is a
- * ManagedService.
- * @param pid The pid of the associated configuration.
- */
- public ConfigurationEvent(ServiceReference reference, int type,
- String factoryPid, String pid) {
- this.reference = reference;
- this.type = type;
- this.factoryPid = factoryPid;
- this.pid = pid;
- }
+ /**
+ * A <code>Configuration</code> has been deleted.
+ *
+ * <p>
+ * This <code>ConfigurationEvent</code> type that indicates that a
+ * <code>Configuration</code> object has been deleted.
+ *
+ * An event is fired when a call to <code>Configuration.delete</code>
+ * successfully deletes a configuration.
+ *
+ * <p>
+ * The value of <code>CM_DELETED</code> is 2.
+ */
+ public static final int CM_DELETED = 2;
- /**
- * Returns the factory pid of the associated configuration.
- *
- * @return Returns the factory pid of the associated configuration if the
- * target of the configuration is a ManagedServiceFactory. Otherwise
- * <code>null</code> if the target of the configuration is a
- * ManagedService.
- */
- public String getFactoryPid() {
- return factoryPid;
- }
+ /**
+ * Type of this event.
+ *
+ * @see #getType
+ */
+ private final int type;
- /**
- * Returns the pid of the associated configuration.
- *
- * @return Returns the pid of the associated configuration.
- */
- public String getPid() {
- return pid;
- }
+ /**
+ * The factory pid associated with this event.
+ */
+ private final String factoryPid;
- /**
- * Return the type of this event.
- * <p>
- * The type values are:
- * <ul>
- * <li>{@link #CM_UPDATED}
- * <li>{@link #CM_DELETED}
- * </ul>
- *
- * @return The type of this event.
- */
- public int getType() {
- return type;
- }
+ /**
+ * The pid associated with this event.
+ */
+ private final String pid;
- /**
- * Return the <code>ServiceReference</code> object of the Configuration
- * Admin service that created this event.
- *
- * @return The <code>ServiceReference</code> object for the Configuration
- * Admin service that created this event.
- */
- public ServiceReference getReference() {
- return reference;
- }
+ /**
+ * The ConfigurationAdmin service which created this event.
+ */
+ private final ServiceReference reference;
+
+ /**
+ * Constructs a <code>ConfigurationEvent</code> object from the given
+ * <code>ServiceReference</code> object, event type, and pids.
+ *
+ * @param reference The <code>ServiceReference</code> object of the
+ * Configuration Admin service that created this event.
+ * @param type The event type. See {@link #getType}.
+ * @param factoryPid The factory pid of the associated configuration if the
+ * target of the configuration is a ManagedServiceFactory. Otherwise
+ * <code>null</code> if the target of the configuration is a
+ * ManagedService.
+ * @param pid The pid of the associated configuration.
+ */
+ public ConfigurationEvent(ServiceReference reference, int type, String factoryPid, String pid) {
+ this.reference = reference;
+ this.type = type;
+ this.factoryPid = factoryPid;
+ this.pid = pid;
+ }
+
+ /**
+ * Returns the factory pid of the associated configuration.
+ *
+ * @return Returns the factory pid of the associated configuration if the
+ * target of the configuration is a ManagedServiceFactory. Otherwise
+ * <code>null</code> if the target of the configuration is a
+ * ManagedService.
+ */
+ public String getFactoryPid() {
+ return factoryPid;
+ }
+
+ /**
+ * Returns the pid of the associated configuration.
+ *
+ * @return Returns the pid of the associated configuration.
+ */
+ public String getPid() {
+ return pid;
+ }
+
+ /**
+ * Return the type of this event.
+ * <p>
+ * The type values are:
+ * <ul>
+ * <li>{@link #CM_UPDATED}
+ * <li>{@link #CM_DELETED}
+ * </ul>
+ *
+ * @return The type of this event.
+ */
+ public int getType() {
+ return type;
+ }
+
+ /**
+ * Return the <code>ServiceReference</code> object of the Configuration
+ * Admin service that created this event.
+ *
+ * @return The <code>ServiceReference</code> object for the Configuration
+ * Admin service that created this event.
+ */
+ public ServiceReference getReference() {
+ return reference;
+ }
}
\ No newline at end of file
diff --git a/ipojo/src/main/java/org/osgi/service/cm/ConfigurationException.java b/ipojo/src/main/java/org/osgi/service/cm/ConfigurationException.java
index 6d41dce..709d335 100644
--- a/ipojo/src/main/java/org/osgi/service/cm/ConfigurationException.java
+++ b/ipojo/src/main/java/org/osgi/service/cm/ConfigurationException.java
@@ -1,19 +1,21 @@
/*
- * $Header: /cvshome/build/org.osgi.service.cm/src/org/osgi/service/cm/ConfigurationException.java,v 1.11 2006/03/14 01:21:09 hargrave Exp $
- *
+ * $Header:
+ * /cvshome/build/org.osgi.service.cm/src/org/osgi/service/cm/ConfigurationException.java,v
+ * 1.11 2006/03/14 01:21:09 hargrave Exp $
+ *
* Copyright (c) OSGi Alliance (2001, 2005). 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
- *
+ *
+ * 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.
+ * 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.cm;
@@ -24,89 +26,89 @@
* @version $Revision: 1.11 $
*/
public class ConfigurationException extends Exception {
- static final long serialVersionUID = -1690090413441769377L;
+ static final long serialVersionUID = -1690090413441769377L;
- private String property;
- private String reason;
+ private String property;
- /**
- * Nested exception.
- */
- private Throwable cause;
+ private String reason;
- /**
- * Create a <code>ConfigurationException</code> object.
- *
- * @param property name of the property that caused the problem,
- * <code>null</code> if no specific property was the cause
- * @param reason reason for failure
- */
- public ConfigurationException(String property, String reason) {
- super(property + " : " + reason);
- this.property = property;
- this.reason = reason;
- this.cause = null;
- }
+ /**
+ * Nested exception.
+ */
+ private Throwable cause;
- /**
- * Create a <code>ConfigurationException</code> object.
- *
- * @param property name of the property that caused the problem,
- * <code>null</code> if no specific property was the cause
- * @param reason reason for failure
- * @param cause The cause of this exception.
- * @since 1.2
- */
- public ConfigurationException(String property, String reason,
- Throwable cause) {
- super(property + " : " + reason);
- this.property = property;
- this.reason = reason;
- this.cause = cause;
- }
+ /**
+ * Create a <code>ConfigurationException</code> object.
+ *
+ * @param property name of the property that caused the problem,
+ * <code>null</code> if no specific property was the cause
+ * @param reason reason for failure
+ */
+ public ConfigurationException(String property, String reason) {
+ super(property + " : " + reason);
+ this.property = property;
+ this.reason = reason;
+ this.cause = null;
+ }
- /**
- * Return the property name that caused the failure or null.
- *
- * @return name of property or null if no specific property caused the
- * problem
- */
- public String getProperty() {
- return property;
- }
+ /**
+ * Create a <code>ConfigurationException</code> object.
+ *
+ * @param property name of the property that caused the problem,
+ * <code>null</code> if no specific property was the cause
+ * @param reason reason for failure
+ * @param cause The cause of this exception.
+ * @since 1.2
+ */
+ public ConfigurationException(String property, String reason, Throwable cause) {
+ super(property + " : " + reason);
+ this.property = property;
+ this.reason = reason;
+ this.cause = cause;
+ }
- /**
- * Return the reason for this exception.
- *
- * @return reason of the failure
- */
- public String getReason() {
- return reason;
- }
+ /**
+ * Return the property name that caused the failure or null.
+ *
+ * @return name of property or null if no specific property caused the
+ * problem
+ */
+ public String getProperty() {
+ return property;
+ }
- /**
- * Returns the cause of this exception or <code>null</code> if no cause
- * was specified when this exception was created.
- *
- * @return The cause of this exception or <code>null</code> if no cause
- * was specified.
- * @since 1.2
- */
- public Throwable getCause() {
- return cause;
- }
+ /**
+ * Return the reason for this exception.
+ *
+ * @return reason of the failure
+ */
+ public String getReason() {
+ return reason;
+ }
- /**
- * The cause of this exception can only be set when constructed.
- *
- * @param cause Cause of the exception.
- * @return This object.
- * @throws java.lang.IllegalStateException This method will always throw an
- * <code>IllegalStateException</code> since the cause of this
- * exception can only be set when constructed.
- * @since 1.2
- */
- public Throwable initCause(Throwable cause) {
- throw new IllegalStateException();
- }
+ /**
+ * Returns the cause of this exception or <code>null</code> if no cause
+ * was specified when this exception was created.
+ *
+ * @return The cause of this exception or <code>null</code> if no cause
+ * was specified.
+ * @since 1.2
+ */
+ public Throwable getCause() {
+ return cause;
+ }
+
+ /**
+ * The cause of this exception can only be set when constructed.
+ *
+ * @param cause Cause of the exception.
+ * @return This object.
+ * @throws java.lang.IllegalStateException This method will always throw an
+ * <code>IllegalStateException</code> since the cause of this exception
+ * can only be set when constructed.
+ * @since 1.2
+ */
+ public Throwable initCause(Throwable cause) {
+ throw new IllegalStateException();
+ }
}
diff --git a/ipojo/src/main/java/org/osgi/service/cm/ConfigurationListener.java b/ipojo/src/main/java/org/osgi/service/cm/ConfigurationListener.java
index f7fb6a6..83dd364 100644
--- a/ipojo/src/main/java/org/osgi/service/cm/ConfigurationListener.java
+++ b/ipojo/src/main/java/org/osgi/service/cm/ConfigurationListener.java
@@ -1,19 +1,21 @@
/*
- * $Header: /cvshome/build/org.osgi.service.cm/src/org/osgi/service/cm/ConfigurationListener.java,v 1.9 2006/03/14 01:21:09 hargrave Exp $
+ * $Header:
+ * /cvshome/build/org.osgi.service.cm/src/org/osgi/service/cm/ConfigurationListener.java,v
+ * 1.9 2006/03/14 01:21:09 hargrave Exp $
*
* Copyright (c) OSGi Alliance (2004, 2005). 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
- *
+ * 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.
+ * 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.cm;
@@ -41,10 +43,10 @@
* @since 1.2
*/
public interface ConfigurationListener {
- /**
- * Receives notification of a Configuration that has changed.
- *
- * @param event The <code>ConfigurationEvent</code>.
- */
- public void configurationEvent(ConfigurationEvent event);
+ /**
+ * Receives notification of a Configuration that has changed.
+ *
+ * @param event The <code>ConfigurationEvent</code>.
+ */
+ public void configurationEvent(ConfigurationEvent event);
}
\ No newline at end of file
diff --git a/ipojo/src/main/java/org/osgi/service/cm/ConfigurationPermission.java b/ipojo/src/main/java/org/osgi/service/cm/ConfigurationPermission.java
index 6d5119f..33f9ab2 100644
--- a/ipojo/src/main/java/org/osgi/service/cm/ConfigurationPermission.java
+++ b/ipojo/src/main/java/org/osgi/service/cm/ConfigurationPermission.java
@@ -1,19 +1,21 @@
/*
- * $Header: /cvshome/build/org.osgi.service.cm/src/org/osgi/service/cm/ConfigurationPermission.java,v 1.20 2006/03/14 01:21:09 hargrave Exp $
+ * $Header:
+ * /cvshome/build/org.osgi.service.cm/src/org/osgi/service/cm/ConfigurationPermission.java,v
+ * 1.20 2006/03/14 01:21:09 hargrave Exp $
*
* Copyright (c) OSGi Alliance (2004, 2005). 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
- *
+ * 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.
+ * 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.cm;
@@ -34,93 +36,93 @@
*/
public final class ConfigurationPermission extends BasicPermission {
- static final long serialVersionUID = 5716868734811965383L;
- /**
- * The action string <code>configure</code>.
- */
- public final static String CONFIGURE = "configure";
+ static final long serialVersionUID = 5716868734811965383L;
- /**
- * Create a new ConfigurationPermission.
- *
- * @param name Name must be "*".
- * @param actions <code>configure</code> (canonical order).
- */
+ /**
+ * The action string <code>configure</code>.
+ */
+ public final static String CONFIGURE = "configure";
- public ConfigurationPermission(String name, String actions) {
- super(name);
- if (!name.equals("*")) {
- throw new IllegalArgumentException("name must be *");
- }
- actions = actions.trim();
- if (actions.equalsIgnoreCase(CONFIGURE)||actions.equals("*"))
- return;
-
- throw new IllegalArgumentException("actions must be " + CONFIGURE);
- }
+ /**
+ * Create a new ConfigurationPermission.
+ *
+ * @param name Name must be "*".
+ * @param actions <code>configure</code> (canonical order).
+ */
- /**
- * Determines if a <code>ConfigurationPermission</code> object "implies"
- * the specified permission.
- *
- * @param p The target permission to check.
- * @return <code>true</code> if the specified permission is implied by
- * this object; <code>false</code> otherwise.
- */
+ public ConfigurationPermission(String name, String actions) {
+ super(name);
+ if (!name.equals("*")) {
+ throw new IllegalArgumentException("name must be *");
+ }
+ actions = actions.trim();
+ if (actions.equalsIgnoreCase(CONFIGURE) || actions.equals("*"))
+ return;
- public boolean implies(Permission p) {
- return p instanceof ConfigurationPermission;
- }
+ throw new IllegalArgumentException("actions must be " + CONFIGURE);
+ }
- /**
- * Determines the equality of two <code>ConfigurationPermission</code>
- * objects.
- * <p>
- * Two <code>ConfigurationPermission</code> objects are equal.
- *
- * @param obj The object being compared for equality with this object.
- * @return <code>true</code> if <code>obj</code> is equivalent to this
- * <code>ConfigurationPermission</code>; <code>false</code>
- * otherwise.
- */
- public boolean equals(Object obj) {
- return obj instanceof ConfigurationPermission;
- }
+ /**
+ * Determines if a <code>ConfigurationPermission</code> object "implies"
+ * the specified permission.
+ *
+ * @param p The target permission to check.
+ * @return <code>true</code> if the specified permission is implied by
+ * this object; <code>false</code> otherwise.
+ */
- /**
- * Returns the hash code value for this object.
- *
- * @return Hash code value for this object.
- */
+ public boolean implies(Permission p) {
+ return p instanceof ConfigurationPermission;
+ }
- public int hashCode() {
- return getName().hashCode() ^ getActions().hashCode();
- }
+ /**
+ * Determines the equality of two <code>ConfigurationPermission</code>
+ * objects.
+ * <p>
+ * Two <code>ConfigurationPermission</code> objects are equal.
+ *
+ * @param obj The object being compared for equality with this object.
+ * @return <code>true</code> if <code>obj</code> is equivalent to this
+ * <code>ConfigurationPermission</code>; <code>false</code> otherwise.
+ */
+ public boolean equals(Object obj) {
+ return obj instanceof ConfigurationPermission;
+ }
- /**
- * Returns the canonical string representation of the
- * <code>ConfigurationPermission</code> actions.
- *
- * <p>
- * Always returns present <code>ConfigurationPermission</code> actions in
- * the following order: <code>CONFIGURE</code>
- *
- * @return Canonical string representation of the
- * <code>ConfigurationPermission</code> actions.
- */
- public String getActions() {
- return CONFIGURE;
- }
+ /**
+ * Returns the hash code value for this object.
+ *
+ * @return Hash code value for this object.
+ */
- /**
- * Returns a new <code>PermissionCollection</code> object suitable for
- * storing <code>ConfigurationPermission</code>s.
- *
- * @return A new <code>PermissionCollection</code> object.
- */
- public PermissionCollection newPermissionCollection() {
- return new ConfigurationPermissionCollection();
- }
+ public int hashCode() {
+ return getName().hashCode() ^ getActions().hashCode();
+ }
+
+ /**
+ * Returns the canonical string representation of the
+ * <code>ConfigurationPermission</code> actions.
+ *
+ * <p>
+ * Always returns present <code>ConfigurationPermission</code> actions in
+ * the following order: <code>CONFIGURE</code>
+ *
+ * @return Canonical string representation of the
+ * <code>ConfigurationPermission</code> actions.
+ */
+ public String getActions() {
+ return CONFIGURE;
+ }
+
+ /**
+ * Returns a new <code>PermissionCollection</code> object suitable for
+ * storing <code>ConfigurationPermission</code>s.
+ *
+ * @return A new <code>PermissionCollection</code> object.
+ */
+ public PermissionCollection newPermissionCollection() {
+ return new ConfigurationPermissionCollection();
+ }
}
/**
@@ -131,89 +133,86 @@
* @see java.security.PermissionCollection
*/
final class ConfigurationPermissionCollection extends PermissionCollection {
- static final long serialVersionUID = -6917638867081695839L;
- /**
- * True if collection is non-empty.
- *
- * @serial
- */
- private boolean hasElement;
+ static final long serialVersionUID = -6917638867081695839L;
- /**
- * Creates an empty <tt>ConfigurationPermissionCollection</tt> object.
- *
- */
- public ConfigurationPermissionCollection() {
- hasElement = false;
- }
+ /**
+ * True if collection is non-empty.
+ *
+ * @serial
+ */
+ private boolean hasElement;
- /**
- * Adds the specified permission to the
- * <tt>ConfigurationPermissionCollection</tt>. The key for the hash is
- * the interface name of the service.
- *
- * @param permission The <tt>Permission</tt> object to add.
- *
- * @exception IllegalArgumentException If the permission is not an
- * <tt>ConfigurationPermission</tt>.
- *
- * @exception SecurityException If this ConfigurationPermissionCollection
- * object has been marked read-only.
- */
+ /**
+ * Creates an empty <tt>ConfigurationPermissionCollection</tt> object.
+ *
+ */
+ public ConfigurationPermissionCollection() {
+ hasElement = false;
+ }
- public void add(Permission permission) {
- if (!(permission instanceof ConfigurationPermission)) {
- throw new IllegalArgumentException("invalid permission: "
- + permission);
- }
+ /**
+ * Adds the specified permission to the
+ * <tt>ConfigurationPermissionCollection</tt>. The key for the hash is
+ * the interface name of the service.
+ *
+ * @param permission The <tt>Permission</tt> object to add.
+ *
+ * @exception IllegalArgumentException If the permission is not an
+ * <tt>ConfigurationPermission</tt>.
+ *
+ * @exception SecurityException If this ConfigurationPermissionCollection
+ * object has been marked read-only.
+ */
- if (isReadOnly())
- throw new SecurityException("attempt to add a Permission to a "
- + "readonly PermissionCollection");
+ public void add(Permission permission) {
+ if (!(permission instanceof ConfigurationPermission)) {
+ throw new IllegalArgumentException("invalid permission: " + permission);
+ }
- hasElement = true;
- }
+ if (isReadOnly())
+ throw new SecurityException("attempt to add a Permission to a " + "readonly PermissionCollection");
- /**
- * Determines if the specified set of permissions implies the permissions
- * expressed in the parameter <tt>permission</tt>.
- *
- * @param p The Permission object to compare.
- *
- * @return true if permission is a proper subset of a permission in the set;
- * false otherwise.
- */
+ hasElement = true;
+ }
- public boolean implies(Permission p) {
- return hasElement && (p instanceof ConfigurationPermission);
- }
+ /**
+ * Determines if the specified set of permissions implies the permissions
+ * expressed in the parameter <tt>permission</tt>.
+ *
+ * @param p The Permission object to compare.
+ *
+ * @return true if permission is a proper subset of a permission in the set;
+ * false otherwise.
+ */
- /**
- * Returns an enumeration of an <tt>ConfigurationPermission</tt> object.
- *
- * @return Enumeration of an <tt>ConfigurationPermission</tt> object.
- */
+ public boolean implies(Permission p) {
+ return hasElement && (p instanceof ConfigurationPermission);
+ }
- public Enumeration elements() {
- return new Enumeration() {
- private boolean more = hasElement;
+ /**
+ * Returns an enumeration of an <tt>ConfigurationPermission</tt> object.
+ *
+ * @return Enumeration of an <tt>ConfigurationPermission</tt> object.
+ */
- public boolean hasMoreElements() {
- return more;
- }
+ public Enumeration elements() {
+ return new Enumeration() {
+ private boolean more = hasElement;
- public Object nextElement() {
- if (more) {
- more = false;
+ public boolean hasMoreElements() {
+ return more;
+ }
- return new ConfigurationPermission("*",
- ConfigurationPermission.CONFIGURE);
- }
- else {
- throw new NoSuchElementException();
- }
- }
- };
- }
+ public Object nextElement() {
+ if (more) {
+ more = false;
+
+ return new ConfigurationPermission("*", ConfigurationPermission.CONFIGURE);
+ } else {
+ throw new NoSuchElementException();
+ }
+ }
+ };
+ }
}
diff --git a/ipojo/src/main/java/org/osgi/service/cm/ConfigurationPlugin.java b/ipojo/src/main/java/org/osgi/service/cm/ConfigurationPlugin.java
index 089e626..2eee326 100644
--- a/ipojo/src/main/java/org/osgi/service/cm/ConfigurationPlugin.java
+++ b/ipojo/src/main/java/org/osgi/service/cm/ConfigurationPlugin.java
@@ -1,19 +1,21 @@
/*
- * $Header: /cvshome/build/org.osgi.service.cm/src/org/osgi/service/cm/ConfigurationPlugin.java,v 1.10 2006/03/14 01:21:09 hargrave Exp $
- *
+ * $Header:
+ * /cvshome/build/org.osgi.service.cm/src/org/osgi/service/cm/ConfigurationPlugin.java,v
+ * 1.10 2006/03/14 01:21:09 hargrave Exp $
+ *
* Copyright (c) OSGi Alliance (2001, 2005). 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
- *
+ *
+ * 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.
+ * 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.cm;
@@ -79,53 +81,53 @@
* @version $Revision: 1.10 $
*/
public interface ConfigurationPlugin {
- /**
- * A service property to limit the Managed Service or Managed Service
- * Factory configuration dictionaries a Configuration Plugin service
- * receives.
- *
- * This property contains a <code>String[]</code> of PIDs. A Configuration
- * Admin service must call a Configuration Plugin service only when this
- * property is not set, or the target service's PID is listed in this
- * property.
- */
- public static final String CM_TARGET = "cm.target";
- /**
- * A service property to specify the order in which plugins are invoked.
- *
- * This property contains an <code>Integer</code> ranking of the plugin.
- * Not specifying this registration property, or setting it to something
- * other than an <code>Integer</code>, is the same as setting it to the
- * <code>Integer</code> zero. This property determines the order in which
- * plugins are invoked. Lower ranked plugins are called before higher ranked
- * ones.
- *
- * @since 1.2
- */
- public static final String CM_RANKING = "service.cmRanking";
+ /**
+ * A service property to limit the Managed Service or Managed Service
+ * Factory configuration dictionaries a Configuration Plugin service
+ * receives.
+ *
+ * This property contains a <code>String[]</code> of PIDs. A Configuration
+ * Admin service must call a Configuration Plugin service only when this
+ * property is not set, or the target service's PID is listed in this
+ * property.
+ */
+ public static final String CM_TARGET = "cm.target";
- /**
- * View and possibly modify the a set of configuration properties before
- * they are sent to the Managed Service or the Managed Service Factory. The
- * Configuration Plugin services are called in increasing order of their
- * <code>service.cmRanking</code> property. If this property is undefined
- * or is a non- <code>Integer</code> type, 0 is used.
- *
- * <p>
- * This method should not modify the properties unless the
- * <code>service.cmRanking</code> of this plugin is in the range
- * <code>0 <= service.cmRanking <= 1000</code>.
- * <p>
- * If this method throws any <code>Exception</code>, the Configuration
- * Admin service must catch it and should log it.
- *
- * @param reference reference to the Managed Service or Managed Service
- * Factory
- * @param properties The configuration properties. This argument must not
- * contain the "service.bundleLocation" property. The value of this
- * property may be obtained from the
- * <code>Configuration.getBundleLocation</code> method.
- */
- public void modifyConfiguration(ServiceReference reference,
- Dictionary properties);
+ /**
+ * A service property to specify the order in which plugins are invoked.
+ *
+ * This property contains an <code>Integer</code> ranking of the plugin.
+ * Not specifying this registration property, or setting it to something
+ * other than an <code>Integer</code>, is the same as setting it to the
+ * <code>Integer</code> zero. This property determines the order in which
+ * plugins are invoked. Lower ranked plugins are called before higher ranked
+ * ones.
+ *
+ * @since 1.2
+ */
+ public static final String CM_RANKING = "service.cmRanking";
+
+ /**
+ * View and possibly modify the a set of configuration properties before
+ * they are sent to the Managed Service or the Managed Service Factory. The
+ * Configuration Plugin services are called in increasing order of their
+ * <code>service.cmRanking</code> property. If this property is undefined
+ * or is a non- <code>Integer</code> type, 0 is used.
+ *
+ * <p>
+ * This method should not modify the properties unless the
+ * <code>service.cmRanking</code> of this plugin is in the range
+ * <code>0 <= service.cmRanking <= 1000</code>.
+ * <p>
+ * If this method throws any <code>Exception</code>, the Configuration
+ * Admin service must catch it and should log it.
+ *
+ * @param reference reference to the Managed Service or Managed Service
+ * Factory
+ * @param properties The configuration properties. This argument must not
+ * contain the "service.bundleLocation" property. The value of this property
+ * may be obtained from the <code>Configuration.getBundleLocation</code>
+ * method.
+ */
+ public void modifyConfiguration(ServiceReference reference, Dictionary properties);
}
diff --git a/ipojo/src/main/java/org/osgi/service/cm/ManagedService.java b/ipojo/src/main/java/org/osgi/service/cm/ManagedService.java
index b5ccce4..e7582a2 100644
--- a/ipojo/src/main/java/org/osgi/service/cm/ManagedService.java
+++ b/ipojo/src/main/java/org/osgi/service/cm/ManagedService.java
@@ -1,19 +1,21 @@
/*
- * $Header: /cvshome/build/org.osgi.service.cm/src/org/osgi/service/cm/ManagedService.java,v 1.11 2006/03/14 01:21:09 hargrave Exp $
- *
+ * $Header:
+ * /cvshome/build/org.osgi.service.cm/src/org/osgi/service/cm/ManagedService.java,v
+ * 1.11 2006/03/14 01:21:09 hargrave Exp $
+ *
* Copyright (c) OSGi Alliance (2001, 2005). 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
- *
+ *
+ * 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.
+ * 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.cm;
@@ -110,31 +112,30 @@
* @version $Revision: 1.11 $
*/
public interface ManagedService {
- /**
- * Update the configuration for a Managed Service.
- *
- * <p>
- * When the implementation of <code>updated(Dictionary)</code> detects any
- * kind of error in the configuration properties, it should create a new
- * <code>ConfigurationException</code> which describes the problem. This
- * can allow a management system to provide useful information to a human
- * administrator.
- *
- * <p>
- * If this method throws any other <code>Exception</code>, the
- * Configuration Admin service must catch it and should log it.
- * <p>
- * The Configuration Admin service must call this method asynchronously
- * which initiated the callback. This implies that implementors of Managed
- * Service can be assured that the callback will not take place during
- * registration when they execute the registration in a synchronized method.
- *
- * @param properties A copy of the Configuration properties, or
- * <code>null</code>. This argument must not contain the
- * "service.bundleLocation" property. The value of this property may
- * be obtained from the <code>Configuration.getBundleLocation</code>
- * method.
- * @throws ConfigurationException when the update fails
- */
- public void updated(Dictionary properties) throws ConfigurationException;
+ /**
+ * Update the configuration for a Managed Service.
+ *
+ * <p>
+ * When the implementation of <code>updated(Dictionary)</code> detects any
+ * kind of error in the configuration properties, it should create a new
+ * <code>ConfigurationException</code> which describes the problem. This
+ * can allow a management system to provide useful information to a human
+ * administrator.
+ *
+ * <p>
+ * If this method throws any other <code>Exception</code>, the
+ * Configuration Admin service must catch it and should log it.
+ * <p>
+ * The Configuration Admin service must call this method asynchronously
+ * which initiated the callback. This implies that implementors of Managed
+ * Service can be assured that the callback will not take place during
+ * registration when they execute the registration in a synchronized method.
+ *
+ * @param properties A copy of the Configuration properties, or
+ * <code>null</code>. This argument must not contain the
+ * "service.bundleLocation" property. The value of this property may be
+ * obtained from the <code>Configuration.getBundleLocation</code> method.
+ * @throws ConfigurationException when the update fails
+ */
+ public void updated(Dictionary properties) throws ConfigurationException;
}
diff --git a/ipojo/src/main/java/org/osgi/service/cm/ManagedServiceFactory.java b/ipojo/src/main/java/org/osgi/service/cm/ManagedServiceFactory.java
index 001ddd8..fccaa6a 100644
--- a/ipojo/src/main/java/org/osgi/service/cm/ManagedServiceFactory.java
+++ b/ipojo/src/main/java/org/osgi/service/cm/ManagedServiceFactory.java
@@ -1,19 +1,21 @@
/*
- * $Header: /cvshome/build/org.osgi.service.cm/src/org/osgi/service/cm/ManagedServiceFactory.java,v 1.10 2006/03/14 01:21:09 hargrave Exp $
- *
+ * $Header:
+ * /cvshome/build/org.osgi.service.cm/src/org/osgi/service/cm/ManagedServiceFactory.java,v
+ * 1.10 2006/03/14 01:21:09 hargrave Exp $
+ *
* Copyright (c) OSGi Alliance (2001, 2005). 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
- *
+ *
+ * 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.
+ * 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.cm;
@@ -97,66 +99,65 @@
* @version $Revision: 1.10 $
*/
public interface ManagedServiceFactory {
- /**
- * Return a descriptive name of this factory.
- *
- * @return the name for the factory, which might be localized
- */
- public String getName();
+ /**
+ * Return a descriptive name of this factory.
+ *
+ * @return the name for the factory, which might be localized
+ */
+ public String getName();
- /**
- * Create a new instance, or update the configuration of an existing
- * instance.
- *
- * If the PID of the <code>Configuration</code> object is new for the
- * Managed Service Factory, then create a new factory instance, using the
- * configuration <code>properties</code> provided. Else, update the
- * service instance with the provided <code>properties</code>.
- *
- * <p>
- * If the factory instance is registered with the Framework, then the
- * configuration <code>properties</code> should be copied to its registry
- * properties. This is not mandatory and security sensitive properties
- * should obviously not be copied.
- *
- * <p>
- * If this method throws any <code>Exception</code>, the Configuration
- * Admin service must catch it and should log it.
- *
- * <p>
- * When the implementation of updated detects any kind of error in the
- * configuration properties, it should create a new
- * {@link ConfigurationException}which describes the problem.
- *
- * <p>
- * The Configuration Admin service must call this method asynchronously.
- * This implies that implementors of the <code>ManagedServiceFactory</code>
- * class can be assured that the callback will not take place during
- * registration when they execute the registration in a synchronized method.
- *
- * @param pid The PID for this configuration.
- * @param properties A copy of the configuration properties. This argument
- * must not contain the service.bundleLocation" property. The value
- * of this property may be obtained from the
- * <code>Configuration.getBundleLocation</code> method.
- * @throws ConfigurationException when the configuration properties are
- * invalid.
- */
- public void updated(String pid, Dictionary properties)
- throws ConfigurationException;
+ /**
+ * Create a new instance, or update the configuration of an existing
+ * instance.
+ *
+ * If the PID of the <code>Configuration</code> object is new for the
+ * Managed Service Factory, then create a new factory instance, using the
+ * configuration <code>properties</code> provided. Else, update the
+ * service instance with the provided <code>properties</code>.
+ *
+ * <p>
+ * If the factory instance is registered with the Framework, then the
+ * configuration <code>properties</code> should be copied to its registry
+ * properties. This is not mandatory and security sensitive properties
+ * should obviously not be copied.
+ *
+ * <p>
+ * If this method throws any <code>Exception</code>, the Configuration
+ * Admin service must catch it and should log it.
+ *
+ * <p>
+ * When the implementation of updated detects any kind of error in the
+ * configuration properties, it should create a new
+ * {@link ConfigurationException}which describes the problem.
+ *
+ * <p>
+ * The Configuration Admin service must call this method asynchronously.
+ * This implies that implementors of the <code>ManagedServiceFactory</code>
+ * class can be assured that the callback will not take place during
+ * registration when they execute the registration in a synchronized method.
+ *
+ * @param pid The PID for this configuration.
+ * @param properties A copy of the configuration properties. This argument
+ * must not contain the service.bundleLocation" property. The value of this
+ * property may be obtained from the
+ * <code>Configuration.getBundleLocation</code> method.
+ * @throws ConfigurationException when the configuration properties are
+ * invalid.
+ */
+ public void updated(String pid, Dictionary properties) throws ConfigurationException;
- /**
- * Remove a factory instance.
- *
- * Remove the factory instance associated with the PID. If the instance was
- * registered with the service registry, it should be unregistered.
- * <p>
- * If this method throws any <code>Exception</code>, the Configuration
- * Admin service must catch it and should log it.
- * <p>
- * The Configuration Admin service must call this method asynchronously.
- *
- * @param pid the PID of the service to be removed
- */
- public void deleted(String pid);
+ /**
+ * Remove a factory instance.
+ *
+ * Remove the factory instance associated with the PID. If the instance was
+ * registered with the service registry, it should be unregistered.
+ * <p>
+ * If this method throws any <code>Exception</code>, the Configuration
+ * Admin service must catch it and should log it.
+ * <p>
+ * The Configuration Admin service must call this method asynchronously.
+ *
+ * @param pid the PID of the service to be removed
+ */
+ public void deleted(String pid);
}
diff --git a/ipojo/src/main/java/org/osgi/service/log/LogEntry.java b/ipojo/src/main/java/org/osgi/service/log/LogEntry.java
index 12e6c8d..c45f168 100644
--- a/ipojo/src/main/java/org/osgi/service/log/LogEntry.java
+++ b/ipojo/src/main/java/org/osgi/service/log/LogEntry.java
@@ -1,19 +1,21 @@
/*
- * $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 $
- *
+ * $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
- *
+ *
+ * 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.
+ * 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;
@@ -34,76 +36,76 @@
* @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 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 <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 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 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 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();
+ /**
+ * 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
index 3731c28..3f7fd4e 100644
--- a/ipojo/src/main/java/org/osgi/service/log/LogListener.java
+++ b/ipojo/src/main/java/org/osgi/service/log/LogListener.java
@@ -1,34 +1,37 @@
/*
- * $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 $
- *
+ * $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
- *
+ *
+ * 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.
+ * 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>.
+ * 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.
+ * 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
@@ -37,15 +40,15 @@
* @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);
+ /**
+ * 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
index 4176ebc..43b6a9d 100644
--- a/ipojo/src/main/java/org/osgi/service/log/LogReaderService.java
+++ b/ipojo/src/main/java/org/osgi/service/log/LogReaderService.java
@@ -1,19 +1,21 @@
/*
- * $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 $
- *
+ * $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
- *
+ *
+ * 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.
+ * 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;
@@ -24,12 +26,13 @@
* <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.
+ * <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
@@ -37,62 +40,64 @@
* @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);
+ /**
+ * 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);
+ /**
+ * 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();
+ /**
+ * 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
index 4858c58..6271437 100644
--- a/ipojo/src/main/java/org/osgi/service/log/LogService.java
+++ b/ipojo/src/main/java/org/osgi/service/log/LogService.java
@@ -1,19 +1,21 @@
/*
- * $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 $
- *
+ * $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
- *
+ *
+ * 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.
+ * 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;
@@ -23,8 +25,8 @@
* 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.
+ * <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
@@ -39,118 +41,121 @@
* @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;
+ /**
+ * 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;
- /**
- * 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);
+ /**
+ * 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;
- /**
- * 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);
+ /**
+ * 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;
- /**
- * 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);
+ /**
+ * 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 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);
+ /**
+ * 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);
}
diff --git a/pom.xml b/pom.xml
index f19ef57..e721f27 100644
--- a/pom.xml
+++ b/pom.xml
@@ -140,6 +140,9 @@
<module>scr</module>
<module>configadmin</module>
<module>metatype</module>
+
+ <module>ipojo</module>
+ <module>ipojo.metadata</module>
</modules>
</profile>
@@ -172,8 +175,7 @@
<!-- <module>tools/mangen</module> -->
- <module>ipojo</module>
- <module>ipojo.metadata</module>
+
</modules>
</profile>