You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@felix.apache.org by ri...@apache.org on 2007/04/17 16:31:47 UTC
svn commit: r529623 [1/9] - in /incubator/felix/trunk: ./ ipojo.arch/
ipojo.arch/src/main/java/org/apache/felix/ipojo/arch/ ipojo.metadata/
ipojo.metadata/src/main/java/org/apache/felix/ipojo/metadata/ ipojo.plugin/
ipojo.plugin/src/main/java/org/apach...
Author: rickhall
Date: Tue Apr 17 07:31:35 2007
New Revision: 529623
URL: http://svn.apache.org/viewvc?view=rev&rev=529623
Log:
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.
Modified:
incubator/felix/trunk/ipojo.arch/pom.xml
incubator/felix/trunk/ipojo.arch/src/main/java/org/apache/felix/ipojo/arch/ArchCommandImpl.java
incubator/felix/trunk/ipojo.metadata/pom.xml
incubator/felix/trunk/ipojo.metadata/src/main/java/org/apache/felix/ipojo/metadata/Element.java
incubator/felix/trunk/ipojo.plugin/pom.xml
incubator/felix/trunk/ipojo.plugin/src/main/java/org/apache/felix/ipojo/plugin/OsgiJarMojo.java
incubator/felix/trunk/ipojo/pom.xml
incubator/felix/trunk/ipojo/src/main/java/org/apache/felix/ipojo/Activator.java
incubator/felix/trunk/ipojo/src/main/java/org/apache/felix/ipojo/ComponentFactory.java
incubator/felix/trunk/ipojo/src/main/java/org/apache/felix/ipojo/ComponentInstance.java
incubator/felix/trunk/ipojo/src/main/java/org/apache/felix/ipojo/CompositeHandler.java
incubator/felix/trunk/ipojo/src/main/java/org/apache/felix/ipojo/CompositeManager.java
incubator/felix/trunk/ipojo/src/main/java/org/apache/felix/ipojo/DefaultServiceContext.java
incubator/felix/trunk/ipojo/src/main/java/org/apache/felix/ipojo/Factory.java
incubator/felix/trunk/ipojo/src/main/java/org/apache/felix/ipojo/Handler.java
incubator/felix/trunk/ipojo/src/main/java/org/apache/felix/ipojo/IPojoConfiguration.java
incubator/felix/trunk/ipojo/src/main/java/org/apache/felix/ipojo/IPojoContext.java
incubator/felix/trunk/ipojo/src/main/java/org/apache/felix/ipojo/InstanceCreator.java
incubator/felix/trunk/ipojo/src/main/java/org/apache/felix/ipojo/InstanceManager.java
incubator/felix/trunk/ipojo/src/main/java/org/apache/felix/ipojo/Nullable.java
incubator/felix/trunk/ipojo/src/main/java/org/apache/felix/ipojo/Pojo.java
incubator/felix/trunk/ipojo/src/main/java/org/apache/felix/ipojo/ServiceContext.java
incubator/felix/trunk/ipojo/src/main/java/org/apache/felix/ipojo/UnacceptableConfiguration.java
incubator/felix/trunk/ipojo/src/main/java/org/apache/felix/ipojo/architecture/ComponentDescription.java
incubator/felix/trunk/ipojo/src/main/java/org/apache/felix/ipojo/architecture/HandlerDescription.java
incubator/felix/trunk/ipojo/src/main/java/org/apache/felix/ipojo/architecture/InstanceDescription.java
incubator/felix/trunk/ipojo/src/main/java/org/apache/felix/ipojo/architecture/PropertyDescription.java
incubator/felix/trunk/ipojo/src/main/java/org/apache/felix/ipojo/composite/CompositeServiceContext.java
incubator/felix/trunk/ipojo/src/main/java/org/apache/felix/ipojo/composite/FactoryProxy.java
incubator/felix/trunk/ipojo/src/main/java/org/apache/felix/ipojo/composite/ServiceReferenceImpl.java
incubator/felix/trunk/ipojo/src/main/java/org/apache/felix/ipojo/composite/ServiceRegistrationImpl.java
incubator/felix/trunk/ipojo/src/main/java/org/apache/felix/ipojo/composite/ServiceRegistry.java
incubator/felix/trunk/ipojo/src/main/java/org/apache/felix/ipojo/composite/StringMap.java
incubator/felix/trunk/ipojo/src/main/java/org/apache/felix/ipojo/composite/architecture/ArchitectureHandler.java
incubator/felix/trunk/ipojo/src/main/java/org/apache/felix/ipojo/composite/service/importer/ImportExportDescription.java
incubator/felix/trunk/ipojo/src/main/java/org/apache/felix/ipojo/composite/service/importer/ImportExportHandler.java
incubator/felix/trunk/ipojo/src/main/java/org/apache/felix/ipojo/composite/service/importer/ServiceExporter.java
incubator/felix/trunk/ipojo/src/main/java/org/apache/felix/ipojo/composite/service/importer/ServiceImporter.java
incubator/felix/trunk/ipojo/src/main/java/org/apache/felix/ipojo/composite/service/instantiator/ServiceInstantiatorDescription.java
incubator/felix/trunk/ipojo/src/main/java/org/apache/felix/ipojo/composite/service/instantiator/ServiceInstantiatorHandler.java
incubator/felix/trunk/ipojo/src/main/java/org/apache/felix/ipojo/composite/service/instantiator/SvcInstance.java
incubator/felix/trunk/ipojo/src/main/java/org/apache/felix/ipojo/handlers/architecture/ArchitectureHandler.java
incubator/felix/trunk/ipojo/src/main/java/org/apache/felix/ipojo/handlers/configuration/ConfigurableProperty.java
incubator/felix/trunk/ipojo/src/main/java/org/apache/felix/ipojo/handlers/configuration/ConfigurationHandler.java
incubator/felix/trunk/ipojo/src/main/java/org/apache/felix/ipojo/handlers/dependency/Dependency.java
incubator/felix/trunk/ipojo/src/main/java/org/apache/felix/ipojo/handlers/dependency/DependencyCallback.java
incubator/felix/trunk/ipojo/src/main/java/org/apache/felix/ipojo/handlers/dependency/DependencyDescription.java
incubator/felix/trunk/ipojo/src/main/java/org/apache/felix/ipojo/handlers/dependency/DependencyHandler.java
incubator/felix/trunk/ipojo/src/main/java/org/apache/felix/ipojo/handlers/dependency/DependencyHandlerDescription.java
incubator/felix/trunk/ipojo/src/main/java/org/apache/felix/ipojo/handlers/dependency/nullable/MethodSignature.java
incubator/felix/trunk/ipojo/src/main/java/org/apache/felix/ipojo/handlers/dependency/nullable/MethodSignatureVisitor.java
incubator/felix/trunk/ipojo/src/main/java/org/apache/felix/ipojo/handlers/dependency/nullable/NullableObjectWriter.java
incubator/felix/trunk/ipojo/src/main/java/org/apache/felix/ipojo/handlers/lifecycle/callback/LifecycleCallback.java
incubator/felix/trunk/ipojo/src/main/java/org/apache/felix/ipojo/handlers/lifecycle/callback/LifecycleCallbackHandler.java
incubator/felix/trunk/ipojo/src/main/java/org/apache/felix/ipojo/handlers/providedservice/Property.java
incubator/felix/trunk/ipojo/src/main/java/org/apache/felix/ipojo/handlers/providedservice/ProvidedService.java
incubator/felix/trunk/ipojo/src/main/java/org/apache/felix/ipojo/handlers/providedservice/ProvidedServiceDescription.java
incubator/felix/trunk/ipojo/src/main/java/org/apache/felix/ipojo/handlers/providedservice/ProvidedServiceHandler.java
incubator/felix/trunk/ipojo/src/main/java/org/apache/felix/ipojo/handlers/providedservice/ProvidedServiceHandlerDescription.java
incubator/felix/trunk/ipojo/src/main/java/org/apache/felix/ipojo/parser/ManifestMetadataParser.java
incubator/felix/trunk/ipojo/src/main/java/org/apache/felix/ipojo/parser/ParseUtils.java
incubator/felix/trunk/ipojo/src/main/java/org/apache/felix/ipojo/util/Callback.java
incubator/felix/trunk/ipojo/src/main/java/org/apache/felix/ipojo/util/Logger.java
incubator/felix/trunk/ipojo/src/main/java/org/osgi/service/cm/Configuration.java
incubator/felix/trunk/ipojo/src/main/java/org/osgi/service/cm/ConfigurationAdmin.java
incubator/felix/trunk/ipojo/src/main/java/org/osgi/service/cm/ConfigurationEvent.java
incubator/felix/trunk/ipojo/src/main/java/org/osgi/service/cm/ConfigurationException.java
incubator/felix/trunk/ipojo/src/main/java/org/osgi/service/cm/ConfigurationListener.java
incubator/felix/trunk/ipojo/src/main/java/org/osgi/service/cm/ConfigurationPermission.java
incubator/felix/trunk/ipojo/src/main/java/org/osgi/service/cm/ConfigurationPlugin.java
incubator/felix/trunk/ipojo/src/main/java/org/osgi/service/cm/ManagedService.java
incubator/felix/trunk/ipojo/src/main/java/org/osgi/service/cm/ManagedServiceFactory.java
incubator/felix/trunk/ipojo/src/main/java/org/osgi/service/log/LogEntry.java
incubator/felix/trunk/ipojo/src/main/java/org/osgi/service/log/LogListener.java
incubator/felix/trunk/ipojo/src/main/java/org/osgi/service/log/LogReaderService.java
incubator/felix/trunk/ipojo/src/main/java/org/osgi/service/log/LogService.java
incubator/felix/trunk/pom.xml
Modified: incubator/felix/trunk/ipojo.arch/pom.xml
URL: http://svn.apache.org/viewvc/incubator/felix/trunk/ipojo.arch/pom.xml?view=diff&rev=529623&r1=529622&r2=529623
==============================================================================
--- incubator/felix/trunk/ipojo.arch/pom.xml (original)
+++ incubator/felix/trunk/ipojo.arch/pom.xml Tue Apr 17 07:31:35 2007
@@ -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>
Modified: incubator/felix/trunk/ipojo.arch/src/main/java/org/apache/felix/ipojo/arch/ArchCommandImpl.java
URL: http://svn.apache.org/viewvc/incubator/felix/trunk/ipojo.arch/src/main/java/org/apache/felix/ipojo/arch/ArchCommandImpl.java?view=diff&rev=529623&r1=529622&r2=529623
==============================================================================
--- incubator/felix/trunk/ipojo.arch/src/main/java/org/apache/felix/ipojo/arch/ArchCommandImpl.java (original)
+++ incubator/felix/trunk/ipojo.arch/src/main/java/org/apache/felix/ipojo/arch/ArchCommandImpl.java Tue Apr 17 07:31:35 2007
@@ -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");
}
}
Modified: incubator/felix/trunk/ipojo.metadata/pom.xml
URL: http://svn.apache.org/viewvc/incubator/felix/trunk/ipojo.metadata/pom.xml?view=diff&rev=529623&r1=529622&r2=529623
==============================================================================
--- incubator/felix/trunk/ipojo.metadata/pom.xml (original)
+++ incubator/felix/trunk/ipojo.metadata/pom.xml Tue Apr 17 07:31:35 2007
@@ -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>
Modified: incubator/felix/trunk/ipojo.metadata/src/main/java/org/apache/felix/ipojo/metadata/Element.java
URL: http://svn.apache.org/viewvc/incubator/felix/trunk/ipojo.metadata/src/main/java/org/apache/felix/ipojo/metadata/Element.java?view=diff&rev=529623&r1=529622&r2=529623
==============================================================================
--- incubator/felix/trunk/ipojo.metadata/src/main/java/org/apache/felix/ipojo/metadata/Element.java (original)
+++ incubator/felix/trunk/ipojo.metadata/src/main/java/org/apache/felix/ipojo/metadata/Element.java Tue Apr 17 07:31:35 2007
@@ -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;
+ }
+ }
}
Modified: incubator/felix/trunk/ipojo.plugin/pom.xml
URL: http://svn.apache.org/viewvc/incubator/felix/trunk/ipojo.plugin/pom.xml?view=diff&rev=529623&r1=529622&r2=529623
==============================================================================
--- incubator/felix/trunk/ipojo.plugin/pom.xml (original)
+++ incubator/felix/trunk/ipojo.plugin/pom.xml Tue Apr 17 07:31:35 2007
@@ -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>
Modified: incubator/felix/trunk/ipojo.plugin/src/main/java/org/apache/felix/ipojo/plugin/OsgiJarMojo.java
URL: http://svn.apache.org/viewvc/incubator/felix/trunk/ipojo.plugin/src/main/java/org/apache/felix/ipojo/plugin/OsgiJarMojo.java?view=diff&rev=529623&r1=529622&r2=529623
==============================================================================
--- incubator/felix/trunk/ipojo.plugin/src/main/java/org/apache/felix/ipojo/plugin/OsgiJarMojo.java (original)
+++ incubator/felix/trunk/ipojo.plugin/src/main/java/org/apache/felix/ipojo/plugin/OsgiJarMojo.java Tue Apr 17 07:31:35 2007
@@ -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()+")");
Modified: incubator/felix/trunk/ipojo/pom.xml
URL: http://svn.apache.org/viewvc/incubator/felix/trunk/ipojo/pom.xml?view=diff&rev=529623&r1=529622&r2=529623
==============================================================================
--- incubator/felix/trunk/ipojo/pom.xml (original)
+++ incubator/felix/trunk/ipojo/pom.xml Tue Apr 17 07:31:35 2007
@@ -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>
Modified: incubator/felix/trunk/ipojo/src/main/java/org/apache/felix/ipojo/Activator.java
URL: http://svn.apache.org/viewvc/incubator/felix/trunk/ipojo/src/main/java/org/apache/felix/ipojo/Activator.java?view=diff&rev=529623&r1=529622&r2=529623
==============================================================================
--- incubator/felix/trunk/ipojo/src/main/java/org/apache/felix/ipojo/Activator.java (original)
+++ incubator/felix/trunk/ipojo/src/main/java/org/apache/felix/ipojo/Activator.java Tue Apr 17 07:31:35 2007
@@ -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);
}
}
Modified: incubator/felix/trunk/ipojo/src/main/java/org/apache/felix/ipojo/ComponentFactory.java
URL: http://svn.apache.org/viewvc/incubator/felix/trunk/ipojo/src/main/java/org/apache/felix/ipojo/ComponentFactory.java?view=diff&rev=529623&r1=529622&r2=529623
==============================================================================
--- incubator/felix/trunk/ipojo/src/main/java/org/apache/felix/ipojo/ComponentFactory.java (original)
+++ incubator/felix/trunk/ipojo/src/main/java/org/apache/felix/ipojo/ComponentFactory.java Tue Apr 17 07:31:35 2007
@@ -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();
- } 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();
+ 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();
}
-
+
// 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;
- }
-
- String pid = null;
- if (configuration.get("name") != null) {
- pid = (String) configuration.get("name");
+ 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");
} 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");
- }
- }
- }
-
- /**
- * @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.
+ 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");
+ }
+ }
+ }
+
+ /**
+ * 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
- }
+ }
}
Modified: incubator/felix/trunk/ipojo/src/main/java/org/apache/felix/ipojo/ComponentInstance.java
URL: http://svn.apache.org/viewvc/incubator/felix/trunk/ipojo/src/main/java/org/apache/felix/ipojo/ComponentInstance.java?view=diff&rev=529623&r1=529622&r2=529623
==============================================================================
--- incubator/felix/trunk/ipojo/src/main/java/org/apache/felix/ipojo/ComponentInstance.java (original)
+++ incubator/felix/trunk/ipojo/src/main/java/org/apache/felix/ipojo/ComponentInstance.java Tue Apr 17 07:31:35 2007
@@ -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);
-
+
}
Modified: incubator/felix/trunk/ipojo/src/main/java/org/apache/felix/ipojo/CompositeHandler.java
URL: http://svn.apache.org/viewvc/incubator/felix/trunk/ipojo/src/main/java/org/apache/felix/ipojo/CompositeHandler.java?view=diff&rev=529623&r1=529622&r2=529623
==============================================================================
--- incubator/felix/trunk/ipojo/src/main/java/org/apache/felix/ipojo/CompositeHandler.java (original)
+++ incubator/felix/trunk/ipojo/src/main/java/org/apache/felix/ipojo/CompositeHandler.java Tue Apr 17 07:31:35 2007
@@ -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) {
+ }
}
Modified: incubator/felix/trunk/ipojo/src/main/java/org/apache/felix/ipojo/CompositeManager.java
URL: http://svn.apache.org/viewvc/incubator/felix/trunk/ipojo/src/main/java/org/apache/felix/ipojo/CompositeManager.java?view=diff&rev=529623&r1=529622&r2=529623
==============================================================================
--- incubator/felix/trunk/ipojo/src/main/java/org/apache/felix/ipojo/CompositeManager.java (original)
+++ incubator/felix/trunk/ipojo/src/main/java/org/apache/felix/ipojo/CompositeManager.java Tue Apr 17 07:31:35 2007
@@ -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);
+ }
+ }
+
+ /**
+ * Get the instance name.
+ * @return the instance name
+ * @see org.apache.felix.ipojo.ComponentInstance#getInstanceName()
+ */
+ public String getInstanceName() {
+ return m_name;
+ }
+
+ /**
+ * 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);
+ }
}
- /**
- * @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; }
+ /**
+ * Get the internal service context of this instance.
+ * @return the internal service context.
+ */
+ public ServiceContext getServiceContext() {
+ return m_internalContext;
+ }
}