You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@felix.apache.org by cl...@apache.org on 2008/03/28 16:35:29 UTC
svn commit: r642265 [2/11] - in /felix/trunk/ipojo: ./ annotations/ ant/
ant/src/main/java/org/apache/felix/ipojo/task/ arch/
arch/src/main/java/org/apache/felix/ipojo/arch/ arch/src/main/resources/
composite/ composite/src/ composite/src/main/ composi...
Propchange: felix/trunk/ipojo/
------------------------------------------------------------------------------
--- svn:ignore (original)
+++ svn:ignore Fri Mar 28 08:33:36 2008
@@ -15,3 +15,7 @@
.wtpmodules
.deployables
.checkstyle
+
+*.patch
+.externalToolBuilders
+maven-eclipse.xml
Modified: felix/trunk/ipojo/annotations/pom.xml
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/annotations/pom.xml?rev=642265&r1=642264&r2=642265&view=diff
==============================================================================
--- felix/trunk/ipojo/annotations/pom.xml (original)
+++ felix/trunk/ipojo/annotations/pom.xml Fri Mar 28 08:33:36 2008
@@ -19,16 +19,15 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
- <groupId>org.apache.felix</groupId>
- <artifactId>felix</artifactId>
- <version>1.0.2</version>
- <relativePath>../../pom/pom.xml</relativePath>
+ <artifactId>iPOJO</artifactId>
+ <groupId>org.apache.felix</groupId>
+ <version>0.7.6-SNAPSHOT</version>
+ <relativePath>../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>org.apache.felix.ipojo.annotations</artifactId>
<packaging>bundle</packaging>
- <version>0.7.5-SNAPSHOT</version>
- <name>iPOJO Annotations</name>
+ <name>Apache Felix iPOJO Annotations</name>
<build>
<plugins>
<plugin>
@@ -38,9 +37,9 @@
<source>1.5</source>
<target>1.5</target>
</configuration>
- </plugin>
+ </plugin>
<plugin>
- <groupId>org.apache.felix</groupId>
+ <groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<version>1.4.0</version>
<extensions>true</extensions>
@@ -55,4 +54,15 @@
</plugin>
</plugins>
</build>
+ <reporting>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-checkstyle-plugin</artifactId>
+ <configuration>
+ <configLocation>http://people.apache.org/~clement/styles/checkstyle_ipojo.xml</configLocation>
+ </configuration>
+ </plugin>
+ </plugins>
+ </reporting>
</project>
Modified: felix/trunk/ipojo/ant/pom.xml
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/ant/pom.xml?rev=642265&r1=642264&r2=642265&view=diff
==============================================================================
--- felix/trunk/ipojo/ant/pom.xml (original)
+++ felix/trunk/ipojo/ant/pom.xml Fri Mar 28 08:33:36 2008
@@ -1,74 +1,90 @@
-<!--
- 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.
--->
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
- <parent>
- <groupId>org.apache.felix</groupId>
- <artifactId>felix</artifactId>
- <version>1.0.2</version>
- <relativePath>../../pom/pom.xml</relativePath>
- </parent>
- <modelVersion>4.0.0</modelVersion>
- <artifactId>org.apache.felix.ipojo.ant</artifactId>
- <packaging>bundle</packaging>
- <version>0.7.5-SNAPSHOT</version>
- <name>Apache Felix iPOJO Ant Task</name>
- <dependencies>
- <dependency>
- <groupId>${pom.groupId}</groupId>
- <artifactId>org.apache.felix.ipojo.metadata</artifactId>
- <version>0.7.5-SNAPSHOT</version>
- </dependency>
- <dependency>
- <groupId>${pom.groupId}</groupId>
- <artifactId>org.apache.felix.ipojo.manipulator</artifactId>
- <version>0.7.5-SNAPSHOT</version>
- </dependency>
- <dependency>
- <groupId>xerces</groupId>
- <artifactId>xercesImpl</artifactId>
- <version>2.4.0</version>
- </dependency>
- <dependency>
- <groupId>ant</groupId>
- <artifactId>ant</artifactId>
- <version>1.6.5</version>
- </dependency>
- </dependencies>
-
- <build>
- <plugins>
- <plugin>
- <groupId>org.apache.felix</groupId>
- <artifactId>maven-bundle-plugin</artifactId>
- <version>1.4.0</version>
- <extensions>true</extensions>
- <configuration>
- <instructions>
- <Bundle-Name>iPOJO Ant Task</Bundle-Name>
- <Bundle-Vendor>Clement ESCOFFIER</Bundle-Vendor>
- <Bundle-Description> iPOJO Ant Task </Bundle-Description>
- <Private-Package>org.apache.felix.ipojo.metadata, org.apache.felix.ipojo.manipulator, org.apache.felix.ipojo.xml.parser, org.apache.felix.ipojo.manipulation*, org.objectweb.asm;-split-package:=merge-first, org.objectweb.asm.commons;-split-package:=merge-first, org.apache.xerces.parsers, org.apache.xerces.xni*, org.apache.xerces.impl*, org.apache.xerces.util.*</Private-Package>
- <Export-Package>org.apache.felix.ipojo.task</Export-Package>
- </instructions>
- </configuration>
- </plugin>
- </plugins>
- </build>
+<!--
+ 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.
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <parent>
+ <artifactId>iPOJO</artifactId>
+ <groupId>org.apache.felix</groupId>
+ <version>0.7.6-SNAPSHOT</version>
+ <relativePath>../pom.xml</relativePath>
+ </parent>
+ <modelVersion>4.0.0</modelVersion>
+ <artifactId>org.apache.felix.ipojo.ant</artifactId>
+ <packaging>bundle</packaging>
+ <name>Apache Felix iPOJO Ant Task</name>
+ <dependencies>
+ <dependency>
+ <groupId>${pom.groupId}</groupId>
+ <artifactId>org.apache.felix.ipojo.metadata</artifactId>
+ <version>${pom.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>${pom.groupId}</groupId>
+ <artifactId>org.apache.felix.ipojo.manipulator</artifactId>
+ <version>${pom.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>xerces</groupId>
+ <artifactId>xercesImpl</artifactId>
+ <version>2.4.0</version>
+ </dependency>
+ <dependency>
+ <groupId>ant</groupId>
+ <artifactId>ant</artifactId>
+ <version>1.6.5</version>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>maven-bundle-plugin</artifactId>
+ <version>1.4.0</version>
+ <extensions>true</extensions>
+ <configuration>
+ <instructions>
+ <Bundle-Name>iPOJO Ant Task</Bundle-Name>
+ <Bundle-Vendor>Clement ESCOFFIER</Bundle-Vendor>
+ <Bundle-Description>
+ iPOJO Ant Task
+ </Bundle-Description>
+ <Private-Package>
+ org.apache.felix.ipojo.metadata,
+ org.apache.felix.ipojo.manipulator,
+ org.apache.felix.ipojo.xml.parser,
+ org.apache.felix.ipojo.manipulation*,
+ org.objectweb.asm.util;-split-package:=merge-first,
+ org.objectweb.asm;-split-package:=merge-first,
+ org.objectweb.asm.commons;-split-package:=merge-first,
+ org.apache.xerces.parsers,
+ org.apache.xerces.xni*,
+ org.apache.xerces.impl*,
+ org.apache.xerces.util.*
+ </Private-Package>
+ <Export-Package>
+ org.apache.felix.ipojo.task
+ </Export-Package>
+ </instructions>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
</project>
Modified: felix/trunk/ipojo/ant/src/main/java/org/apache/felix/ipojo/task/IPojoTask.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/ant/src/main/java/org/apache/felix/ipojo/task/IPojoTask.java?rev=642265&r1=642264&r2=642265&view=diff
==============================================================================
--- felix/trunk/ipojo/ant/src/main/java/org/apache/felix/ipojo/task/IPojoTask.java (original)
+++ felix/trunk/ipojo/ant/src/main/java/org/apache/felix/ipojo/task/IPojoTask.java Fri Mar 28 08:33:36 2008
@@ -25,30 +25,21 @@
import org.apache.tools.ant.Task;
/**
-* iPOJO Ant Task.
-* This Ant taks manipulate an input bundle.
-* @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
-*/
+ * iPOJO Ant Task. This Ant task manipulates an input bundle.
+ * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
+ */
public class IPojoTask extends Task {
- /**
- * Metadata file.
- */
+ /** Metadata file. */
private File m_metadata;
- /**
- * Input bundle.
- */
+ /** Input bundle. */
private File m_input;
- /**
- * Output bundle.
- */
+ /** Output bundle. */
private File m_output;
- /**
- * Flag describing if we need to ignore annotation of not.
- */
+ /** Flag describing if we need to ignore annotation of not. */
private boolean m_ignoreAnnotations = false;
/**
@@ -96,7 +87,7 @@
throw new BuildException("The input bundle " + m_input.getAbsolutePath() + " does not exist");
}
- System.out.println("Input Bundle File : " + m_input.getAbsolutePath());
+ log("Input Bundle File : " + m_input.getAbsolutePath());
// Get metadata file
if (m_metadata == null) {
@@ -104,25 +95,25 @@
if (!m_metadata.exists()) {
// Verify if annotations are ignored
if (m_ignoreAnnotations) {
- System.out.println("No metadata file found - ignore annotations");
+ log("No metadata file found & ignore annotations : nothing to do");
return;
} else {
- System.out.println("No metadata file found - try to use only annotations");
+ log("No metadata file found - try to use only annotations");
m_metadata = null;
}
} else {
- System.out.println("Metadata File : " + m_metadata.getAbsolutePath());
+ log("Metadata File : " + m_metadata.getAbsolutePath());
}
} else {
- // Metadata file is specified, check existency
+ // Metadata file is specified, check existence
if (!m_metadata.exists()) {
throw new BuildException("No metadata file found - the file " + m_metadata.getAbsolutePath() + " does not exist");
} else {
- System.out.println("Metadata File : " + m_metadata.getAbsolutePath());
+ log("Metadata File : " + m_metadata.getAbsolutePath());
}
}
- System.out.println("Start bundle manipulation");
+ log("Start bundle manipulation");
if (m_output == null) {
m_output = new File("./_out.jar");
@@ -139,7 +130,7 @@
}
pojo.pojoization(m_input, m_output, m_metadata);
for (int i = 0; i < pojo.getWarnings().size(); i++) {
- System.out.println((String) pojo.getWarnings().get(i));
+ log((String) pojo.getWarnings().get(i));
}
if (pojo.getErrors().size() > 0) { throw new BuildException((String) pojo.getErrors().get(0)); }
@@ -152,8 +143,8 @@
out = m_output.getAbsolutePath();
}
- System.out.println("Bundle manipulation - SUCCESS");
- System.out.println("Output File : " + out);
+ log("Bundle manipulation - SUCCESS");
+ log("Output File : " + out);
}
Modified: felix/trunk/ipojo/arch/pom.xml
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/arch/pom.xml?rev=642265&r1=642264&r2=642265&view=diff
==============================================================================
--- felix/trunk/ipojo/arch/pom.xml (original)
+++ felix/trunk/ipojo/arch/pom.xml Fri Mar 28 08:33:36 2008
@@ -1,80 +1,85 @@
<!--
- 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.
+ 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.
-->
<project>
- <parent>
- <groupId>org.apache.felix</groupId>
- <artifactId>felix</artifactId>
- <version>1.0.2</version>
- <relativePath>../../pom/pom.xml</relativePath>
- </parent>
- <modelVersion>4.0.0</modelVersion>
- <packaging>bundle</packaging>
- <name>Apache Felix iPOJO Arch Command</name>
- <version>0.7.5-SNAPSHOT</version>
- <artifactId>org.apache.felix.ipojo.arch</artifactId>
- <dependencies>
- <dependency>
- <groupId>${pom.groupId}</groupId>
- <artifactId>org.apache.felix.ipojo</artifactId>
- <version>${pom.version}</version>
- </dependency>
- <dependency>
- <groupId>${pom.groupId}</groupId>
- <artifactId>org.apache.felix.ipojo.metadata</artifactId>
- <version>${pom.version}</version>
- </dependency>
- <dependency>
- <groupId>${pom.groupId}</groupId>
- <artifactId>org.apache.felix.shell</artifactId>
- <version>1.1.0-SNAPSHOT</version>
- </dependency>
- </dependencies>
- <build>
- <plugins>
- <plugin>
- <groupId>org.apache.felix</groupId>
- <artifactId>maven-bundle-plugin</artifactId>
- <version>1.4.0</version>
- <extensions>true</extensions>
- <configuration>
- <instructions>
- <Bundle-Name>iPOJO Arch Command</Bundle-Name>
- <Bundle-SymbolicName>${pom.artifactId}</Bundle-SymbolicName>
- <Private-Package>org.apache.felix.ipojo.arch</Private-Package>
- </instructions>
- </configuration>
- </plugin>
- <plugin>
- <groupId>org.apache.felix</groupId>
- <artifactId>maven-ipojo-plugin</artifactId>
- <version>${pom.version}</version>
- <executions>
- <execution>
- <goals>
- <goal>ipojo-bundle</goal>
- </goals>
- <configuration>
- <ignoreAnnotations>true</ignoreAnnotations>
- </configuration>
- </execution>
- </executions>
- </plugin>
- </plugins>
- </build>
+ <parent>
+ <artifactId>iPOJO</artifactId>
+ <groupId>org.apache.felix</groupId>
+ <version>0.7.6-SNAPSHOT</version>
+ <relativePath>../pom.xml</relativePath>
+ </parent>
+ <modelVersion>4.0.0</modelVersion>
+ <packaging>bundle</packaging>
+ <name>Apache Felix iPOJO Arch Command</name>
+ <artifactId>org.apache.felix.ipojo.arch</artifactId>
+ <dependencies>
+ <dependency>
+ <groupId>${pom.groupId}</groupId>
+ <artifactId>org.apache.felix.ipojo</artifactId>
+ <version>${pom.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>${pom.groupId}</groupId>
+ <artifactId>org.apache.felix.ipojo.metadata</artifactId>
+ <version>${pom.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>${pom.groupId}</groupId>
+ <artifactId>org.apache.felix.shell</artifactId>
+ <version>1.0.0</version>
+ </dependency>
+ </dependencies>
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>maven-bundle-plugin</artifactId>
+ <version>1.4.0</version>
+ <extensions>true</extensions>
+ <configuration>
+ <instructions>
+ <Bundle-Name>
+ iPOJO Arch Felix Command
+ </Bundle-Name>
+ <Bundle-SymbolicName>
+ ${pom.artifactId}
+ </Bundle-SymbolicName>
+ <Private-Package>
+ org.apache.felix.ipojo.arch
+ </Private-Package>
+ </instructions>
+ </configuration>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>maven-ipojo-plugin</artifactId>
+ <version>${pom.version}</version>
+ <executions>
+ <execution>
+ <goals>
+ <goal>ipojo-bundle</goal>
+ </goals>
+ <configuration>
+ <ignoreAnnotations>true</ignoreAnnotations>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
</project>
Modified: felix/trunk/ipojo/arch/src/main/java/org/apache/felix/ipojo/arch/ArchCommandImpl.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/arch/src/main/java/org/apache/felix/ipojo/arch/ArchCommandImpl.java?rev=642265&r1=642264&r2=642265&view=diff
==============================================================================
--- felix/trunk/ipojo/arch/src/main/java/org/apache/felix/ipojo/arch/ArchCommandImpl.java (original)
+++ felix/trunk/ipojo/arch/src/main/java/org/apache/felix/ipojo/arch/ArchCommandImpl.java Fri Mar 28 08:33:36 2008
@@ -19,7 +19,10 @@
package org.apache.felix.ipojo.arch;
import java.io.PrintStream;
+import java.lang.reflect.Field;
+import java.util.List;
+import org.apache.felix.ipojo.IPojoFactory;
import org.apache.felix.ipojo.ComponentInstance;
import org.apache.felix.ipojo.Factory;
import org.apache.felix.ipojo.HandlerFactory;
@@ -29,25 +32,17 @@
/**
* Implementation of the arch command printing the actual architecture.
- *
* @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
*/
public class ArchCommandImpl implements Command {
- /**
- * List of arch service.
- */
+ /** List of arch services. */
private Architecture[] m_archs;
- /**
- * Factory services.
- */
+ /** Factory services. */
private Factory[] m_factories;
-
- /**
- * Handler Factories.
- */
+ /** Handler Factories. */
private Factory[] m_handlers;
/**
@@ -60,7 +55,7 @@
}
/**
- * Get help message.
+ * Gets help message.
* @return the command usage.
* @see org.apache.felix.shell.Command#getUsage()
*/
@@ -69,7 +64,7 @@
}
/**
- * Get a small description.
+ * Gets a small description.
* @return get a description.
* @see org.apache.felix.shell.Command#getShortDescription()
*/
@@ -78,7 +73,7 @@
}
/**
- * Execute the arch command.
+ * Executes the arch command.
* @param line : command line
* @param out : the default output stream
* @param err : the error output stream
@@ -113,15 +108,41 @@
printHandlers(out);
return;
}
+
+ if (line2.startsWith("-stats")) {
+ printStats(out);
+ return;
+ }
err.println(getUsage());
}
/**
- * Print instance list.
- *
- * @param out :
- * default print stream
+ * Prints the statistics.
+ * @param out the out
+ */
+ private void printStats(PrintStream out) {
+ try {
+ Field field = IPojoFactory.class.getDeclaredField("m_instancesName");
+ field.setAccessible(true); // The field is not accessible.
+ List names = (List) field.get(null);
+ out.println("Number of living instances : " + names.size());
+ out.println("Created instances : " + names);
+ } catch (SecurityException e) {
+ out.println("Cannot compute stats : " + e.getMessage());
+ } catch (IllegalArgumentException e) {
+ out.println("Cannot compute stats : " + e.getMessage());
+ } catch (IllegalAccessException e) {
+ out.println("Cannot compute stats : " + e.getMessage());
+ } catch (NoSuchFieldException e) {
+ out.println("Cannot compute stats : " + e.getMessage());
+ }
+
+ }
+
+ /**
+ * Prints instance list.
+ * @param out : default print stream
*/
private void printInstances(PrintStream out) {
for (int i = 0; i < m_archs.length; i++) {
@@ -139,7 +160,7 @@
}
/**
- * Print instance description.
+ * Prints instance description.
* @param name : instance name
* @param out : default print stream
* @param err : error print stream (if the instance is not found)
@@ -156,7 +177,7 @@
}
/**
- * Print Factory information.
+ * Prints factories.
* @param out : output stream
*/
private void printFactories(PrintStream out) {
@@ -170,7 +191,7 @@
}
/**
- * Print factory description.
+ * Prints factory description.
* @param name : factory name
* @param out : default print stream
* @param err : error print stream (if the factory is not found)
@@ -186,7 +207,7 @@
}
/**
- * Print the list of available handlers (and validity).
+ * Prints the list of available handlers (and validity).
* @param out : default print stream
*/
private void printHandlers(PrintStream out) {
Modified: felix/trunk/ipojo/arch/src/main/resources/metadata.xml
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/arch/src/main/resources/metadata.xml?rev=642265&r1=642264&r2=642265&view=diff
==============================================================================
--- felix/trunk/ipojo/arch/src/main/resources/metadata.xml (original)
+++ felix/trunk/ipojo/arch/src/main/resources/metadata.xml Fri Mar 28 08:33:36 2008
@@ -1,10 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<iPOJO>
- <Component className="org.apache.felix.ipojo.arch.ArchCommandImpl" factory="false">
- <Provides/>
- <Requires field="m_archs" optional="true"/>
- <Requires field="m_factories" optional="true" filter="(!(handler.name=*))"/>
- <Requires field="m_handlers" optional="true" filter="(handler.name=*)"/>
+ <Component className="org.apache.felix.ipojo.arch.ArchCommandImpl"
+ factory="false">
+ <Provides />
+ <Requires field="m_archs" optional="true" />
+ <Requires field="m_factories" optional="true"
+ filter="(!(handler.name=*))" />
+ <Requires field="m_handlers" optional="true"
+ filter="(handler.name=*)" />
</Component>
- <instance component="org.apache.felix.ipojo.arch.ArchCommandImpl" name="ArchCommand"/>
+ <instance component="org.apache.felix.ipojo.arch.ArchCommandImpl"
+ name="ArchCommand" />
</iPOJO>
Propchange: felix/trunk/ipojo/composite/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Fri Mar 28 08:33:36 2008
@@ -0,0 +1,9 @@
+.checkstyle
+.classpath
+.project
+target
+.pmd
+reports
+maven-eclipse.xml
+.settings
+.externalToolBuilders
Copied: felix/trunk/ipojo/composite/pom.xml (from r640936, felix/sandbox/clement/ipojo/composite/pom.xml)
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/composite/pom.xml?p2=felix/trunk/ipojo/composite/pom.xml&p1=felix/sandbox/clement/ipojo/composite/pom.xml&r1=640936&r2=642265&rev=642265&view=diff
==============================================================================
--- felix/sandbox/clement/ipojo/composite/pom.xml (original)
+++ felix/trunk/ipojo/composite/pom.xml Fri Mar 28 08:33:36 2008
@@ -1,3 +1,21 @@
+<!--
+ 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.
+-->
<project>
<parent>
<artifactId>iPOJO</artifactId>
@@ -45,12 +63,10 @@
<extensions>true</extensions>
<configuration>
<instructions>
- <Bundle-Name>
- iPOJO Composite
- </Bundle-Name>
+ <Bundle-Name>iPOJO Composite</Bundle-Name>
<Bundle-Vendor>Clement ESCOFFIER</Bundle-Vendor>
<Bundle-Description>
- iPOJO Composititon Framework
+ iPOJO Composititon Framework
</Bundle-Description>
<Import-Package>
org.apache.felix.ipojo,
@@ -101,17 +117,4 @@
</plugin>
</plugins>
</build>
- <reporting>
- <plugins>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-checkstyle-plugin</artifactId>
- <configuration>
- <configLocation>
- http://people.apache.org/~clement/styles/checkstyle_ipojo.xml
- </configLocation>
- </configuration>
- </plugin>
- </plugins>
- </reporting>
</project>
Copied: felix/trunk/ipojo/composite/src/main/resources/metadata.xml (from r640936, felix/sandbox/clement/ipojo/composite/src/main/resources/metadata.xml)
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/composite/src/main/resources/metadata.xml?p2=felix/trunk/ipojo/composite/src/main/resources/metadata.xml&p1=felix/sandbox/clement/ipojo/composite/src/main/resources/metadata.xml&r1=640936&r2=642265&rev=642265&view=diff
==============================================================================
--- felix/sandbox/clement/ipojo/composite/src/main/resources/metadata.xml (original)
+++ felix/trunk/ipojo/composite/src/main/resources/metadata.xml Fri Mar 28 08:33:36 2008
@@ -1,18 +1,27 @@
<ipojo>
-<!-- Composite Handler -->
-<handler classname="org.apache.felix.ipojo.composite.instance.InstanceHandler" name="instance" type="composite" architecture="false" level="1">
- <requires filter="(factory.state=1)" field="m_factories" optional="true">
- <callback type="bind" method="bindFactory"/>
- <callback type="unbind" method="unbindFactory"/>
- </requires>
-</handler>
-<handler classname="org.apache.felix.ipojo.composite.service.instantiator.ServiceDependencyHandler" name="subservice" type="composite" architecture="false">
-</handler>
-<handler classname="org.apache.felix.ipojo.composite.service.provides.ProvidedServiceHandler" name="provides" type="composite" architecture="false" level="3">
-</handler>
-<handler classname="org.apache.felix.ipojo.composite.architecture.ArchitectureHandler" name="architecture" type="composite" architecture="false">
- <provides>
- <property field="m_name" name="instance.name" value=""/>
- </provides>
-</handler>
+ <!-- Composite Handler -->
+ <handler
+ classname="org.apache.felix.ipojo.composite.instance.InstanceHandler"
+ name="instance" type="composite" architecture="false" level="1">
+ <requires filter="(factory.state=1)" field="m_factories"
+ optional="true">
+ <callback type="bind" method="bindFactory" />
+ <callback type="unbind" method="unbindFactory" />
+ </requires>
+ </handler>
+ <handler
+ classname="org.apache.felix.ipojo.composite.service.instantiator.ServiceDependencyHandler"
+ name="subservice" type="composite" architecture="false">
+ </handler>
+ <handler
+ classname="org.apache.felix.ipojo.composite.service.provides.ProvidedServiceHandler"
+ name="provides" type="composite" architecture="false" level="3">
+ </handler>
+ <handler
+ classname="org.apache.felix.ipojo.composite.architecture.ArchitectureHandler"
+ name="architecture" type="composite" architecture="false">
+ <provides>
+ <property field="m_name" name="instance.name" value="" />
+ </provides>
+ </handler>
</ipojo>
Propchange: felix/trunk/ipojo/core/
------------------------------------------------------------------------------
--- svn:ignore (original)
+++ svn:ignore Fri Mar 28 08:33:36 2008
@@ -15,7 +15,8 @@
.wtpmodules
.deployables
.checkstyle
-
+.pmd
+report
*.patch
.externalToolBuilders
maven-eclipse.xml
Modified: felix/trunk/ipojo/core/pom.xml
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/core/pom.xml?rev=642265&r1=642264&r2=642265&view=diff
==============================================================================
--- felix/trunk/ipojo/core/pom.xml (original)
+++ felix/trunk/ipojo/core/pom.xml Fri Mar 28 08:33:36 2008
@@ -1,118 +1,125 @@
<!--
- 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.
+ 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.
-->
<project>
- <parent>
- <groupId>org.apache.felix</groupId>
- <artifactId>felix</artifactId>
- <version>1.0.2</version>
- <relativePath>../../pom/pom.xml</relativePath>
- </parent>
- <modelVersion>4.0.0</modelVersion>
- <packaging>bundle</packaging>
- <name>Apache Felix iPOJO</name>
- <artifactId>org.apache.felix.ipojo</artifactId>
- <version>0.7.5-SNAPSHOT</version>
- <dependencies>
- <dependency>
- <groupId>${pom.groupId}</groupId>
- <artifactId>org.osgi.core</artifactId>
- <version>1.1.0-SNAPSHOT</version>
- </dependency>
- <dependency>
- <groupId>${pom.groupId}</groupId>
- <artifactId>org.osgi.compendium</artifactId>
- <version>1.0.0</version>
- </dependency>
- <dependency>
- <groupId>${pom.groupId}</groupId>
- <artifactId>org.apache.felix.ipojo.metadata</artifactId>
- <version>0.7.5-SNAPSHOT</version>
- </dependency>
- <dependency>
- <groupId>${pom.groupId}</groupId>
- <artifactId>org.apache.felix.ipojo.manipulator</artifactId>
- <version>0.7.5-SNAPSHOT</version>
- </dependency>
- </dependencies>
- <build>
- <plugins>
- <plugin>
- <groupId>org.apache.felix</groupId>
- <artifactId>maven-bundle-plugin</artifactId>
- <version>1.4.0</version>
- <extensions>true</extensions>
- <configuration>
- <instructions>
- <Bundle-Name>iPOJO</Bundle-Name>
- <Bundle-Vendor>Clement ESCOFFIER</Bundle-Vendor>
- <Bundle-Description> iPOJO </Bundle-Description>
- <Bundle-Activator>org.apache.felix.ipojo.Extender</Bundle-Activator>
- <Import-Package>
- org.osgi.framework,
- org.osgi.service.cm,
- org.osgi.service.log,
- !org.objectweb.asm*
- </Import-Package>
- <Private-Package>
- org.apache.felix.ipojo.manipulation,
- org.apache.felix.ipojo.composite.architecture,
- org.apache.felix.ipojo.composite.service*,
- org.apache.felix.ipojo.composite.instance,
- 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.apache.felix.ipojo.handlers.lifecycle.controller,
- org.objectweb.asm*;-split-package:=merge-first
- </Private-Package>
- <Export-Package>
- org.apache.felix.ipojo; version="0.7.5",
- org.apache.felix.ipojo.metadata; version="0.7.5",
- org.apache.felix.ipojo.architecture; version="0.7.5",
- org.apache.felix.ipojo.parser; version="0.7.5",
- org.apache.felix.ipojo.util; version="0.7.5",
- org.apache.felix.ipojo.handlers.dependency; version="0.7.5",
- org.apache.felix.ipojo.handlers.providedservice; version="0.7.5",
- org.apache.felix.ipojo.composite; version="0.7.5",
- org.osgi.service.cm,
- org.osgi.service.log
- </Export-Package>
- <_donotcopy>(CVS|.svn|.+.bak|~.+|metadata.xml)</_donotcopy>
- </instructions>
- </configuration>
- </plugin>
- <plugin>
- <groupId>org.apache.felix</groupId>
- <artifactId>maven-ipojo-plugin</artifactId>
- <version>${pom.version}</version>
- <executions>
- <execution>
- <goals>
- <goal>ipojo-bundle</goal>
- </goals>
- <configuration>
- <metadata>metadata.xml</metadata>
- <ignoreAnnotations>true</ignoreAnnotations>
- </configuration>
- </execution>
- </executions>
- </plugin>
- </plugins>
- </build>
+ <parent>
+ <artifactId>iPOJO</artifactId>
+ <groupId>org.apache.felix</groupId>
+ <version>0.7.6-SNAPSHOT</version>
+ <relativePath>../pom.xml</relativePath>
+ </parent>
+ <modelVersion>4.0.0</modelVersion>
+ <packaging>bundle</packaging>
+ <name>Apache Felix iPOJO</name>
+ <artifactId>org.apache.felix.ipojo</artifactId>
+ <dependencies>
+ <dependency>
+ <groupId>${pom.groupId}</groupId>
+ <artifactId>org.osgi.core</artifactId>
+ <version>1.0.0</version>
+ </dependency>
+ <dependency>
+ <groupId>${pom.groupId}</groupId>
+ <artifactId>org.osgi.compendium</artifactId>
+ <version>1.0.0</version>
+ </dependency>
+ <dependency>
+ <groupId>${pom.groupId}</groupId>
+ <artifactId>org.apache.felix.ipojo.metadata</artifactId>
+ <version>0.7.6-SNAPSHOT</version>
+ </dependency>
+ <dependency>
+ <groupId>${pom.groupId}</groupId>
+ <artifactId>org.apache.felix.ipojo.manipulator</artifactId>
+ <version>0.7.6-SNAPSHOT</version>
+ </dependency>
+ </dependencies>
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>maven-bundle-plugin</artifactId>
+ <version>1.4.0</version>
+ <extensions>true</extensions>
+ <configuration>
+ <instructions>
+ <Bundle-Name>iPOJO</Bundle-Name>
+ <Bundle-Vendor>Clement ESCOFFIER</Bundle-Vendor>
+ <Bundle-Description>
+ iPOJO Core Framework
+ </Bundle-Description>
+ <Bundle-Activator>
+ org.apache.felix.ipojo.Extender
+ </Bundle-Activator>
+ <IPOJO-Extension>
+ component:org.apache.felix.ipojo.ComponentFactory,
+ handler:org.apache.felix.ipojo.HandlerFactory
+ </IPOJO-Extension>
+ <Import-Package>
+ org.osgi.framework, org.osgi.service.cm,
+ org.osgi.service.log
+ </Import-Package>
+ <Private-Package>
+ org.apache.felix.ipojo.handlers.architecture,
+ org.apache.felix.ipojo.handlers.configuration,
+ org.apache.felix.ipojo.handlers.lifecycle.callback,
+ org.apache.felix.ipojo.handlers.lifecycle.controller
+ </Private-Package>
+ <Export-Package>
+ org.apache.felix.ipojo; version="0.7.6",
+ org.apache.felix.ipojo.metadata;
+ version="0.7.6",
+ org.apache.felix.ipojo.architecture;
+ version="0.7.6",
+ org.apache.felix.ipojo.parser;
+ version="0.7.6",
+ org.apache.felix.ipojo.util;
+ version="0.7.6",
+ org.apache.felix.ipojo.handlers.dependency;
+ version="0.7.6",
+ org.apache.felix.ipojo.handlers.providedservice;
+ version="0.7.6",
+ org.apache.felix.ipojo.context;
+ version="0.7.6", org.osgi.service.cm,
+ org.osgi.service.log
+ </Export-Package>
+ <_donotcopy>
+ (CVS|.svn|.+.bak|~.+|metadata.xml)
+ </_donotcopy>
+ </instructions>
+ </configuration>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>maven-ipojo-plugin</artifactId>
+ <version>${pom.version}</version>
+ <executions>
+ <execution>
+ <goals>
+ <goal>ipojo-bundle</goal>
+ </goals>
+ <configuration>
+ <metadata>metadata.xml</metadata>
+ <ignoreAnnotations>true</ignoreAnnotations>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
</project>
Modified: felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/ComponentFactory.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/ComponentFactory.java?rev=642265&r1=642264&r2=642265&view=diff
==============================================================================
--- felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/ComponentFactory.java (original)
+++ felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/ComponentFactory.java Fri Mar 28 08:33:36 2008
@@ -21,27 +21,22 @@
import java.net.URL;
import java.security.ProtectionDomain;
import java.util.ArrayList;
-import java.util.Collection;
import java.util.Collections;
import java.util.Dictionary;
import java.util.HashMap;
-import java.util.Iterator;
import java.util.List;
import java.util.Map;
-import java.util.Properties;
-import org.apache.felix.ipojo.architecture.ComponentDescription;
+import org.apache.felix.ipojo.architecture.ComponentTypeDescription;
+import org.apache.felix.ipojo.metadata.Attribute;
import org.apache.felix.ipojo.metadata.Element;
+import org.apache.felix.ipojo.parser.PojoMetadata;
import org.apache.felix.ipojo.util.Logger;
import org.apache.felix.ipojo.util.Tracker;
import org.apache.felix.ipojo.util.TrackerCustomizer;
import org.osgi.framework.BundleContext;
-import org.osgi.framework.Constants;
import org.osgi.framework.InvalidSyntaxException;
import org.osgi.framework.ServiceReference;
-import org.osgi.framework.ServiceRegistration;
-import org.osgi.service.cm.ConfigurationException;
-import org.osgi.service.cm.ManagedServiceFactory;
/**
* The component factory manages component instance objects. This management
@@ -50,379 +45,114 @@
*
* @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
*/
-public class ComponentFactory implements Factory, ManagedServiceFactory, TrackerCustomizer {
-
- /**
- * List of the managed instance name. This list is shared by all factories.
- */
- protected static List m_instancesName = new ArrayList();
-
- /**
- * Component-Type description exposed by the factory service.
- */
- protected ComponentDescription m_componentDesc;
-
- /**
- * List of the managed instance managers. The key of this map is the
- * name (i.e. instance names) of the created instance
- */
- protected Map m_componentInstances = new HashMap();
-
- /**
- * Component Type provided by this factory.
- */
- protected Element m_componentMetadata;
-
- /**
- * The bundle context reference.
- */
- protected BundleContext m_context = null;
-
- /**
- * Factory Name. Could be the component class name if the
- * factory name is not set.
- */
- protected String m_factoryName;
-
- /**
- * List of required handler.
- */
- protected List m_handlerIdentifiers = new ArrayList();
-
- /**
- * List of listeners.
- */
- protected List m_listeners = new ArrayList(5);
-
- /**
- * Logger for the factory (and all component instance).
- */
- protected Logger m_logger;
-
- /**
- * Factory state.
- */
- protected int m_state = Factory.INVALID;
+public class ComponentFactory extends IPojoFactory implements TrackerCustomizer {
/**
* Tracker used to track required handler factories.
*/
protected Tracker m_tracker;
-
- /**
- * Is the factory public (expose as a service).
- */
- protected boolean m_isPublic;
/**
* Class loader to delegate loading.
*/
private FactoryClassloader m_classLoader = null;
-
+
/**
* Component Implementation class.
*/
private byte[] m_clazz = null;
-
+
/**
* Component Implementation Class Name.
*/
- private String m_componentClassName = null;
-
- /**
- * Index used to generate instance name if not set.
- */
- private long m_index = 0;
-
+ private String m_classname = null;
+
/**
- * Service Registration of this factory (Factory & ManagedServiceFactory).
+ * Manipulation Metadata of the internal POJO.
*/
- private ServiceRegistration m_sr;
-
+ private PojoMetadata m_manipulation = null;
+
/**
* Create a instance manager factory. The class is given in parameter. The
* component type is not a composite.
- * @param bc : bundle context
+ * @param context : bundle context
* @param clazz : the component class
- * @param cm : metadata of the component
+ * @param element : metadata of the component
+ * @throws ConfigurationException occurs when the element describing the factory is malformed.
*/
- public ComponentFactory(BundleContext bc, byte[] clazz, Element cm) {
- this(bc, cm);
+ public ComponentFactory(BundleContext context, byte[] clazz, Element element) throws ConfigurationException {
+ this(context, element);
m_clazz = clazz;
}
-
+
/**
* Create a instance manager factory.
- * @param bc : bundle context
- * @param cm : metadata of the component to create
+ * @param context : bundle context
+ * @param element : metadata of the component to create
+ * @throws ConfigurationException occurs when the element describing the factory is malformed.
*/
- public ComponentFactory(BundleContext bc, Element cm) {
- m_context = bc;
- m_componentMetadata = cm;
-
- if (! check(cm)) {
- return;
- }
-
- computeFactoryName();
- m_logger = new Logger(m_context, m_factoryName, Logger.WARNING);
-
- String fac = cm.getAttribute("factory");
- m_isPublic = fac == null || ! fac.equalsIgnoreCase("false");
-
- computeRequiredHandlers();
-
- }
-
- /**
- * Add a factory listener.
- * @param l : the factory listener to add
- * @see org.apache.felix.ipojo.Factory#addFactoryStateListener(org.apache.felix.ipojo.FactoryStateListener)
- */
- public void addFactoryStateListener(FactoryStateListener l) {
- synchronized (m_listeners) {
- m_listeners.add(l);
- }
- // TODO do we need to notify the actual state of the factory to the new listener ?
+ public ComponentFactory(BundleContext context, Element element) throws ConfigurationException {
+ super(context, element);
+ check(element); // NOPMD. This invocation is normal.
}
- /**
- * A new handler factory is detected.
- * Test if the factory can be used or not.
- * @param reference : the new service reference.
- * @return true if the given factory reference match with a required handler.
- * @see org.apache.felix.ipojo.util.TrackerCustomizer#addingService(org.osgi.framework.ServiceReference)
- */
- public boolean addingService(ServiceReference reference) {
- for (int i = 0; i < m_handlerIdentifiers.size(); i++) {
- HandlerIdentifier hi = (HandlerIdentifier) m_handlerIdentifiers.get(i);
- if (hi.m_reference == null && match(hi, reference)) {
- int oldP = hi.m_level;
- hi.setReference(reference);
- // If the priority has changed, sort the list.
- if (oldP != hi.m_level) {
- Collections.sort(m_handlerIdentifiers);
- }
- return true;
- }
- }
- return false;
- }
-
- /**
- * A matching service has been added to the tracker, we can no compute the factory state.
- * @param reference : added reference.
- * @see org.apache.felix.ipojo.util.TrackerCustomizer#addedService(org.osgi.framework.ServiceReference)
- */
- public void addedService(ServiceReference reference) {
- if (m_state == INVALID) {
- try {
- computeFactoryState();
- } catch (org.apache.felix.ipojo.ConfigurationException e) {
- m_logger.log(Logger.ERROR, "The component type metadata are not correct : " + e.getMessage());
- stop();
- }
- }
+ public ComponentTypeDescription getComponentTypeDescription() {
+ return new PrimitiveTypeDescription(this);
}
/**
* Check method : allow a factory to check if given element are correct.
* A component factory metadata are correct if they contain the 'classname' attribute.
- * @param cm : the metadata
- * @return true if the metadata are correct
+ * @param element : the metadata
+ * @throws ConfigurationException occurs when the element describing the factory is malformed.
*/
- public boolean check(Element cm) {
- m_componentClassName = cm.getAttribute("className");
- if (m_componentClassName == null) {
- System.err.println("A component needs a class name : " + cm);
- return false;
- } else {
- return true;
- }
+ public void check(Element element) throws ConfigurationException {
+ m_classname = element.getAttribute("className");
+ if (m_classname == null) { throw new ConfigurationException("A component needs a class name : " + element); }
}
- /**
- * 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.
- * @throws MissingHandlerException : occurs if an handler is unavailable when the instance is created.
- * @throws org.apache.felix.ipojo.ConfigurationException : occurs when the instance or type configuration are not correct.
- * @see org.apache.felix.ipojo.Factory#createComponentInstance(java.util.Dictionary)
- */
- public ComponentInstance createComponentInstance(Dictionary configuration) throws UnacceptableConfiguration, MissingHandlerException, org.apache.felix.ipojo.ConfigurationException {
- return createComponentInstance(configuration, null);
+ public String getClassName() {
+ return m_classname;
}
-
- /**
- * 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.
- * @throws MissingHandlerException : occurs when an handler is unavailable when creating the instance.
- * @throws org.apache.felix.ipojo.ConfigurationException : when the instance configuration failed.
- * @see org.apache.felix.ipojo.Factory#createComponentInstance(java.util.Dictionary)
- */
- public synchronized ComponentInstance createComponentInstance(Dictionary configuration, ServiceContext serviceContext) throws UnacceptableConfiguration, MissingHandlerException, org.apache.felix.ipojo.ConfigurationException {
- if (configuration == null) {
- configuration = new Properties();
- }
-
- 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 n = null;
- if (configuration.get("name") != null) {
- n = (String) configuration.get("name");
- if (m_instancesName.contains(n)) {
- throw new UnacceptableConfiguration("Name already used : " + n);
- }
- } else {
- n = generateName();
- configuration.put("name", n);
- }
- m_instancesName.add(n);
-
- BundleContext context = null;
- if (serviceContext == null) {
- context = new IPojoContext(m_context);
- } else {
- context = new IPojoContext(m_context, serviceContext);
- }
-
- List handlers = new ArrayList();
- for (int i = 0; i < m_handlerIdentifiers.size(); i++) {
- HandlerIdentifier hi = (HandlerIdentifier) m_handlerIdentifiers.get(i);
- handlers.add(getHandlerInstance(hi, serviceContext));
- }
-
- InstanceManager instance = new InstanceManager(this, context, (HandlerManager[]) handlers.toArray(new HandlerManager[m_handlerIdentifiers.size()]));
+ /**
+ * Create a primitive instance.
+ * @param config : instance configuration
+ * @param context : service context.
+ * @param handlers : handler to use
+ * @return the created instance
+ * @throws org.apache.felix.ipojo.ConfigurationException : if the configuration process failed.
+ * @see org.apache.felix.ipojo.IPojoFactory#createInstance(java.util.Dictionary, org.apache.felix.ipojo.IPojoContext, org.apache.felix.ipojo.HandlerManager[])
+ */
+ public ComponentInstance createInstance(Dictionary config, IPojoContext context, HandlerManager[] handlers) throws org.apache.felix.ipojo.ConfigurationException {
+ InstanceManager instance = new InstanceManager(this, context, handlers);
+ instance.configure(m_componentMetadata, config);
try {
- instance.configure(m_componentMetadata, configuration);
- } catch (org.apache.felix.ipojo.ConfigurationException e) {
- throw new org.apache.felix.ipojo.ConfigurationException(e.getMessage(), m_factoryName);
+ instance.start();
+ return instance;
+ } catch (IllegalStateException e) {
+ // An exception occurs during the start method.
+ m_logger.log(Logger.ERROR, e.getMessage(), e);
+ throw new ConfigurationException(e.getMessage());
}
- m_componentInstances.put(n, instance);
- instance.start();
-
- return instance;
}
/**
* Define a class.
* @param name : qualified name of the class
- * @param b : byte array of the class
+ * @param clazz : byte array of the class
* @param domain : protection domain of the class
* @return the defined class object
*/
- public Class defineClass(String name, byte[] b, ProtectionDomain domain) {
+ public Class defineClass(String name, byte[] clazz, ProtectionDomain domain) {
if (m_classLoader == null) {
m_classLoader = new FactoryClassloader();
}
- return m_classLoader.defineClass(name, b, domain);
- }
-
- /**
- * Delete an instance.
- * @param in : name of the instance to delete
- * @see org.osgi.service.cm.ManagedServiceFactory#deleted(java.lang.String)
- */
- public synchronized void deleted(String in) {
- m_instancesName.remove(in);
- final ComponentInstance cm = (ComponentInstance) m_componentInstances.remove(in);
- if (cm == null) {
- return; // do nothing, the component does not exist !
- } else {
- cm.dispose();
- }
- }
-
- /**
- * Get the component type description.
- * @return the component type description object. Null if not already computed.
- */
- public ComponentDescription getComponentDescription() {
- return m_componentDesc;
- }
-
- /**
- * Get the component type description attached to this factory.
- * @return : the component type description
- * @see org.apache.felix.ipojo.Factory#getDescription()
- */
- public Element getDescription() {
- if (m_componentDesc == null) { return new Element("No description available for " + m_factoryName, ""); }
- return m_componentDesc.getDescription();
- }
-
- /**
- * Get the logger used by instances of he current factory.
- * @return the factory logger.
- */
- public Logger getLogger() {
- return m_logger;
- }
-
- /**
- * Get the list of missing handlers.
- * @return the list of missing handlers (namespace:name)
- * @see org.apache.felix.ipojo.Factory#getMissingHandlers()
- */
- public List getMissingHandlers() {
- List l = new ArrayList();
- for (int i = 0; i < m_handlerIdentifiers.size(); i++) {
- HandlerIdentifier hi = (HandlerIdentifier) m_handlerIdentifiers.get(i);
- if (hi.m_reference == null) {
- l.add(hi.getFullName());
- }
- }
- return l;
- }
-
- /**
- * Get the name of this factory.
- *
- * @return the name of this factory
- * @see org.apache.felix.ipojo.Factory#getName()
- */
- public String getName() {
- return m_factoryName;
+ return m_classLoader.defineClass(name, clazz, domain);
}
/**
- * Get the list of required handlers.
- * @return the list of required handlers (namespace:name)
- * @see org.apache.felix.ipojo.Factory#getRequiredHandlers()
- */
- public List getRequiredHandlers() {
- List l = new ArrayList();
- for (int i = 0; i < m_handlerIdentifiers.size(); i++) {
- HandlerIdentifier hi = (HandlerIdentifier) m_handlerIdentifiers.get(i);
- l.add(hi.getFullName());
- }
- return l;
- }
-
- public String getClassName() {
- return m_componentClassName;
- }
-
- public int getState() {
- return m_state;
- }
-
- /**
* Return the URL of a resource.
* @param resName : resource name
* @return the URL of the resource
@@ -432,24 +162,6 @@
}
/**
- * Check if the given configuration is acceptable as a component instance
- * configuration. This method checks that 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) {
- try {
- checkAcceptability(conf);
- } catch (UnacceptableConfiguration e) {
- return false;
- } catch (MissingHandlerException e) {
- return false;
- }
- return true;
- }
-
- /**
* Load a class.
* @param className : name of the class to load
* @return the resulting Class object
@@ -457,587 +169,163 @@
* @throws ClassNotFoundException : happen when the class is not found
*/
public Class loadClass(String className) throws ClassNotFoundException {
- if (m_clazz != null && className.equals(m_componentClassName)) {
+ if (m_clazz != null && className.equals(m_classname)) {
// Used the factory classloader to load the component implementation
// class
if (m_classLoader == null) {
m_classLoader = new FactoryClassloader();
}
- try {
- return m_classLoader.defineClass(m_componentClassName, m_clazz, null);
- } catch (Exception e) {
- throw new ClassNotFoundException("[Bundle " + m_context.getBundle().getBundleId() + "] Cannot define the class : " + className, e);
- }
+ return m_classLoader.defineClass(m_classname, m_clazz, null);
}
return m_context.getBundle().loadClass(className);
}
/**
- * A used handler factory is modified.
- * @param reference : the service reference
- * @param service : the Factory object (if already get)
- * @see org.apache.felix.ipojo.util.TrackerCustomizer#modifiedService(org.osgi.framework.ServiceReference, java.lang.Object)
- */
- public void modifiedService(ServiceReference reference, Object service) {
- // Noting to do
- }
-
- /**
- * 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.
- * @throws MissingHandlerException : occurs if the current factory is not valid.
- * @see org.apache.felix.ipojo.Factory#reconfigure(java.util.Dictionary)
- */
- public synchronized void reconfigure(Dictionary properties) throws UnacceptableConfiguration, MissingHandlerException {
- if (properties == null || properties.get("name") == null) {
- throw new UnacceptableConfiguration("The configuration does not contains the \"name\" property");
- }
- final String name = (String) properties.get("name");
- InstanceManager 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
- }
- }
-
- /**
- * A used factory disappears.
- * @param reference : service reference.
- * @param service : factory object.
- * @see org.apache.felix.ipojo.util.TrackerCustomizer#removedService(org.osgi.framework.ServiceReference, java.lang.Object)
- */
- public void removedService(ServiceReference reference, Object service) {
- // Look for the implied reference and invalid the handler identifier
- for (int i = 0; i < m_handlerIdentifiers.size(); i++) {
- HandlerIdentifier hi = (HandlerIdentifier) m_handlerIdentifiers.get(i);
- if (reference.equals(hi.getReference())) {
- hi.unRef(); // This method will unget the service.
- try {
- computeFactoryState();
- } catch (org.apache.felix.ipojo.ConfigurationException e) {
- m_logger.log(Logger.ERROR, "The component type metadata are not correct : " + e.getMessage());
- stop();
- }
- return; // The factory can be used only once.
- }
- }
- }
-
- /**
- * Remove a factory listener.
- * @param l : the factory listener to remove
- * @see org.apache.felix.ipojo.Factory#removeFactoryStateListener(org.apache.felix.ipojo.FactoryStateListener)
- */
- public void removeFactoryStateListener(FactoryStateListener l) {
- synchronized (m_listeners) {
- m_listeners.remove(l);
- }
- }
-
- /**
* Start the factory.
*/
- public synchronized void start() {
- if (m_componentDesc != null) { // Already started.
- return;
- }
-
- if (m_handlerIdentifiers.size() != 0) {
+ public synchronized void starting() {
+ if (m_requiredHandlers.size() != 0) {
try {
- String filter = "(&(" + Constants.OBJECTCLASS + "=" + Factory.class.getName() + ")"
- + "(" + Handler.HANDLER_TYPE_PROPERTY + "=" + PrimitiveHandler.HANDLER_TYPE + ")"
- + "(factory.state=1)"
- + ")";
+ String filter = "(&(" + Handler.HANDLER_TYPE_PROPERTY + "=" + PrimitiveHandler.HANDLER_TYPE + ")" + "(factory.state=1)" + ")";
m_tracker = new Tracker(m_context, m_context.createFilter(filter), this);
m_tracker.open();
} catch (InvalidSyntaxException e) {
m_logger.log(Logger.ERROR, "A factory filter is not valid: " + e.getMessage());
stop();
- return;
}
}
-
- try {
- computeFactoryState();
- } catch (org.apache.felix.ipojo.ConfigurationException e) {
- m_logger.log(Logger.ERROR, "The component type metadata are not correct : " + e.getMessage());
- stop();
- return;
- }
-
- if (m_isPublic) {
- // Exposition of the factory service
- m_sr = m_context.registerService(new String[] { Factory.class.getName(), ManagedServiceFactory.class.getName() }, this, getProperties());
- }
}
/**
* Stop all the instance managers.
*/
- public synchronized void stop() {
- if (m_sr != null) {
- m_sr.unregister();
- m_sr = null;
- }
-
- if (m_tracker != null) {
- m_tracker.close();
- }
-
- final Collection col = m_componentInstances.values();
- final Iterator it = col.iterator();
- while (it.hasNext()) {
- InstanceManager ci = (InstanceManager) it.next();
- if (ci.getState() != ComponentInstance.DISPOSED) {
- ci.kill();
- }
- m_instancesName.remove(ci.getInstanceName());
- }
-
- m_componentInstances.clear();
-
- // Release each handler
- for (int i = 0; i < m_handlerIdentifiers.size(); i++) {
- ((HandlerIdentifier) m_handlerIdentifiers.get(i)).unRef();
- }
-
+ public synchronized void stopping() {
+ m_tracker.close();
m_tracker = null;
- m_componentDesc = null;
m_classLoader = null;
m_clazz = null;
- m_state = INVALID;
- }
-
- /**
- * Create of update an instance.
- * @param in : 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 synchronized void updated(String in, Dictionary properties) throws ConfigurationException {
- final InstanceManager cm = (InstanceManager) m_componentInstances.get(in);
- if (cm == null) {
- try {
- properties.put("name", in); // 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());
- } catch (MissingHandlerException e) {
- m_logger.log(Logger.ERROR, "Handler not available : " + e.getMessage());
- throw new ConfigurationException(properties.toString(), e.getMessage());
- } catch (org.apache.felix.ipojo.ConfigurationException e) {
- m_logger.log(Logger.ERROR, "The Component Type metadata are not correct : " + e.getMessage());
- throw new ConfigurationException(properties.toString(), e.getMessage());
- }
- } else {
- try {
- properties.put("name", in); // Add the name in the configuration
- reconfigure(properties); // re-configure the component
- } catch (UnacceptableConfiguration e) {
- m_logger.log(Logger.ERROR, "The configuration is not acceptable : " + e.getMessage());
- throw new ConfigurationException(properties.toString(), e.getMessage());
- } catch (MissingHandlerException e) {
- m_logger.log(Logger.ERROR, "The facotry is not valid, at least one handler is missing : " + e.getMessage());
- throw new ConfigurationException(properties.toString(), e.getMessage());
- }
- }
- }
-
- /**
- * Test is a configuration is acceptable for the factory.
- * @param conf : the configuration to test.
- * @throws UnacceptableConfiguration : the configuration is not acceptable.
- * @throws MissingHandlerException : the factory is not valid.
- */
- protected void checkAcceptability(Dictionary conf) throws UnacceptableConfiguration, MissingHandlerException {
- if (m_state == Factory.INVALID) {
- throw new MissingHandlerException(getMissingHandlers());
- }
-
- List props = m_componentDesc.getRequiredProperties();
- for (int i = 0; i < props.size(); i++) {
- // Failed if the props has no default value and the configuration does not push a value
- if (conf.get(props.get(i)) == null) {
- throw new UnacceptableConfiguration("The configuration does not contains the \"" + props.get(i) + "\" property");
- }
- }
- }
-
- /**
- * Compute the component type description.
- * The factory must be valid when calling this method.
- * @throws org.apache.felix.ipojo.ConfigurationException if one handler has rejected the configuration.
- */
- protected void computeDescription() throws org.apache.felix.ipojo.ConfigurationException {
- m_componentDesc = new ComponentDescription(this);
-
- for (int i = 0; i < m_handlerIdentifiers.size(); i++) {
- HandlerIdentifier hi = (HandlerIdentifier) m_handlerIdentifiers.get(i);
- HandlerManager hm = getHandlerInstance(hi, null);
- Handler ch = hm.getHandler();
- try {
- ch.setLogger(getLogger());
- ch.initializeComponentFactory(m_componentDesc, m_componentMetadata);
- ((Pojo) ch).getComponentInstance().dispose();
- } catch (org.apache.felix.ipojo.ConfigurationException e) {
- ((Pojo) ch).getComponentInstance().dispose();
- throw new org.apache.felix.ipojo.ConfigurationException(e.getMessage(), m_factoryName);
- }
- }
}
/**
* Compute the factory name.
+ * @return the factory name.
*/
- protected void computeFactoryName() {
- m_factoryName = m_componentMetadata.getAttribute("name");
- if (m_factoryName == null) { // No factory name, try with factory attribute
- m_factoryName = m_componentMetadata.getAttribute("factory");
- if (m_factoryName == null || m_factoryName.equalsIgnoreCase("true") || m_factoryName.equalsIgnoreCase("false")) { // Avoid boolean case
- m_factoryName = m_componentMetadata.getAttribute("className");
+ public String getFactoryName() {
+ String name = m_componentMetadata.getAttribute("name");
+ if (name == null) { // No factory name, try with factory attribute
+ name = m_componentMetadata.getAttribute("factory");
+ if (name == null || name.equalsIgnoreCase("true") || name.equalsIgnoreCase("false")) { // Avoid boolean case
+ name = m_componentMetadata.getAttribute("className");
}
}
+ return name;
}
-
- /**
- * Compute factory state.
- * @throws org.apache.felix.ipojo.ConfigurationException : occurs when the component type cannot be initialize.
- */
- protected void computeFactoryState() throws org.apache.felix.ipojo.ConfigurationException {
- boolean isValid = true;
- for (int i = 0; isValid && i < m_handlerIdentifiers.size(); i++) {
- HandlerIdentifier hi = (HandlerIdentifier) m_handlerIdentifiers.get(i);
- isValid = hi.m_reference != null;
- }
-
- if (isValid) {
- if (m_state == INVALID) {
-
- if (m_componentDesc == null) {
- computeDescription();
- }
-
- m_state = VALID;
- if (m_sr != null) {
- m_sr.setProperties(getProperties());
- }
- for (int i = 0; i < m_listeners.size(); i++) {
- ((FactoryStateListener) m_listeners.get(i)).stateChanged(this, VALID);
- }
- return;
- }
- } else {
- if (m_state == VALID) {
- m_state = INVALID;
-
- // Notify listeners.
- for (int i = 0; i < m_listeners.size(); i++) {
- ((FactoryStateListener) m_listeners.get(i)).stateChanged(this, INVALID);
- }
-
- // Dispose created instances.
- final Collection col = m_componentInstances.values();
- final Iterator it = col.iterator();
- while (it.hasNext()) {
- InstanceManager ci = (InstanceManager) it.next();
- if (ci.getState() != ComponentInstance.DISPOSED) {
- ci.kill();
- }
- m_instancesName.remove(ci.m_name);
- }
- m_componentInstances.clear();
-
- // Update service properties TODO : really useful ?
- if (m_sr != null) {
- m_sr.setProperties(getProperties());
- }
-
- return;
- }
- }
- }
-
/**
* Compute required handlers.
+ * @return the required handler list.
*/
- protected void computeRequiredHandlers() {
+ public List getRequiredHandlerList() {
+ List list = new ArrayList();
Element[] elems = m_componentMetadata.getElements();
for (int i = 0; i < elems.length; i++) {
- Element current = elems[i];
- if (current.getName().equals("manipulation")) { continue; }
- HandlerIdentifier hi = new HandlerIdentifier(current.getName(), current.getNameSpace());
- if (! m_handlerIdentifiers.contains(hi)) { m_handlerIdentifiers.add(hi); }
+ Element current = elems[i];
+ if (!"manipulation".equals(current.getName())) {
+ RequiredHandler req = new RequiredHandler(current.getName(), current.getNameSpace());
+ if (!list.contains(req)) {
+ list.add(req);
+ }
+ }
}
-
+
// Add architecture if architecture != 'false'
- HandlerIdentifier hi = new HandlerIdentifier("architecture", null);
String arch = m_componentMetadata.getAttribute("architecture");
if (arch == null || arch.equalsIgnoreCase("true")) {
- m_handlerIdentifiers.add(hi);
+ list.add(new RequiredHandler("architecture", null));
}
-
+
// Add lifecycle callback if immediate = true
- HandlerIdentifier hi2 = new HandlerIdentifier("callback", null);
+ RequiredHandler reqCallback = new RequiredHandler("callback", null);
String imm = m_componentMetadata.getAttribute("immediate");
- if (! m_handlerIdentifiers.contains(hi2) && imm != null && imm.equalsIgnoreCase("true")) {
- m_handlerIdentifiers.add(hi2);
+ if (!list.contains(reqCallback) && imm != null && imm.equalsIgnoreCase("true")) {
+ list.add(reqCallback);
}
- }
- /**
- * Callback called by instance when disposed.
- * @param ci : the destroyed instance
- */
- protected void disposed(ComponentInstance ci) {
- String name = ci.getInstanceName();
- m_instancesName.remove(name);
- m_componentInstances.remove(name);
+ return list;
}
-
+
/**
- * Generate an instance name.
- * @return an non already used name
+ * A new handler factory is detected.
+ * Test if the factory can be used or not.
+ * @param reference : the new service reference.
+ * @return true if the given factory reference match with a required handler.
+ * @see org.apache.felix.ipojo.util.TrackerCustomizer#addingService(org.osgi.framework.ServiceReference)
*/
- protected synchronized String generateName() {
- String name = m_factoryName + "-" + m_index;
- while (m_instancesName.contains(name)) {
- m_index = m_index + 1;
- name = m_factoryName + "-" + m_index;
+ public boolean addingService(ServiceReference reference) {
+ for (int i = 0; i < m_requiredHandlers.size(); i++) {
+ RequiredHandler req = (RequiredHandler) m_requiredHandlers.get(i);
+ if (req.getReference() == null && match(req, reference)) {
+ int oldP = req.getLevel();
+ req.setReference(reference);
+ // If the priority has changed, sort the list.
+ if (oldP != req.getLevel()) {
+ Collections.sort(m_requiredHandlers);
+ }
+ return true;
+ }
}
- return name;
- }
-
- /**
- * Return the bundle context.
- * @return the Bundle Context.
- */
- public BundleContext getBundleContext() {
- return m_context;
+ return false;
}
/**
- * Get the implementation class of the component type.
- *
- * @return the name of the component-type implementation class.
+ * A matching service has been added to the tracker, we can no compute the factory state.
+ * @param reference : added reference.
+ * @see org.apache.felix.ipojo.util.TrackerCustomizer#addedService(org.osgi.framework.ServiceReference)
*/
- protected String getComponentClassName() {
- return m_componentClassName;
+ public void addedService(ServiceReference reference) {
+ if (m_state == INVALID) {
+ computeFactoryState();
+ }
}
/**
- * Compute factory properties.
- * @return the properties.
+ * A used factory disappears.
+ * @param reference : service reference.
+ * @param service : factory object.
+ * @see org.apache.felix.ipojo.util.TrackerCustomizer#removedService(org.osgi.framework.ServiceReference, java.lang.Object)
*/
- protected Properties getProperties() {
- final Properties props = new Properties();
-
- props.put("component.class", m_componentClassName);
-
- props.put("factory.name", m_factoryName);
- props.put(Constants.SERVICE_PID, m_factoryName); // Service PID is required for the integration in the configuration admin.
-
- if (m_componentDesc != null) {
- props.put("component.providedServiceSpecifications", m_componentDesc.getprovidedServiceSpecification());
- props.put("component.properties", m_componentDesc.getProperties());
- props.put("component.description", m_componentDesc);
- }
-
- // Add factory state
- props.put("factory.state", "" + m_state);
-
- return props;
- }
-
- /**
- * Check if the given handler identifier and the service reference can match.
- * @param hi : the handler identifier.
- * @param ref : the service reference.
- * @return true if the service reference can fulfill the handler requirement
- */
- protected boolean match(HandlerIdentifier hi, ServiceReference ref) {
- String name = (String) ref.getProperty(Handler.HANDLER_NAME_PROPERTY);
- String ns = (String) ref.getProperty(Handler.HANDLER_NAMESPACE_PROPERTY);
- if (IPojoConfiguration.IPOJO_NAMESPACE.equals(ns)) {
- return name.equals(hi.m_name) && hi.m_namespace == null;
+ public void removedService(ServiceReference reference, Object service) {
+ // Look for the implied reference and invalid the handler identifier
+ for (int i = 0; i < m_requiredHandlers.size(); i++) {
+ RequiredHandler req = (RequiredHandler) m_requiredHandlers.get(i);
+ if (reference.equals(req.getReference())) {
+ req.unRef(); // This method will unget the service.
+ computeFactoryState();
+ return; // The factory can be used only once.
+ }
}
- return name.equals(hi.m_name) && ns.equals(hi.m_namespace);
}
/**
- * Return an handler object.
- * @param hi : handler to create.
- * @param sc : service context in which create the handler (instance context).
- * @return the Handler object.
+ * A used handler factory is modified.
+ * @param reference : the service reference
+ * @param service : the Factory object (if already get)
+ * @see org.apache.felix.ipojo.util.TrackerCustomizer#modifiedService(org.osgi.framework.ServiceReference, java.lang.Object)
*/
- private HandlerManager getHandlerInstance(HandlerIdentifier hi, ServiceContext sc) {
- try {
- return (HandlerManager) hi.getFactory().createComponentInstance(null, sc);
- } catch (MissingHandlerException e) {
- m_logger.log(Logger.ERROR, "The creation of the handler " + hi.getFullName() + " has failed: " + e.getMessage());
- stop();
- return null;
- } catch (UnacceptableConfiguration e) {
- m_logger.log(Logger.ERROR, "The creation of the handler " + hi.getFullName() + " has failed (UnacceptableConfiguration): " + e.getMessage());
- stop();
- return null;
- } catch (org.apache.felix.ipojo.ConfigurationException e) {
- m_logger.log(Logger.ERROR, "The configuration of the handler " + hi.getFullName() + " has failed (ConfigurationException): " + e.getMessage());
- stop();
- return null;
- }
+ public void modifiedService(ServiceReference reference, Object service) {
+ // Noting to do
}
/**
- * Structure storing required handlers.
- */
- class HandlerIdentifier implements Comparable {
- /**
- * Factory to create this handler.
- */
- private HandlerFactory m_factory;
-
- /**
- * Handler name.
- */
- private String m_name;
-
- /**
- * Handler start level.
- */
- private int m_level = Integer.MAX_VALUE;
-
- /**
- * Handler namespace.
- */
- private String m_namespace;
-
- /**
- * Service Reference of the handler factory.
- */
- private ServiceReference m_reference;
-
- /**
- * Constructor.
- * @param n : handler name.
- * @param ns : handler namespace.
- */
- public HandlerIdentifier(String n, String ns) {
- m_name = n;
- m_namespace = ns;
- }
-
- /**
- * Equals method.
- * Two handlers are equals if they have same name and namespace or they share the same service reference.
- * @param o : object to compare to the current object.
- * @return : true if the two compared object are equals
- * @see java.lang.Object#equals(java.lang.Object)
- */
- public boolean equals(Object o) {
- if (m_namespace == null) {
- return ((HandlerIdentifier) o).m_name.equalsIgnoreCase(m_name) && ((HandlerIdentifier) o).m_namespace == null;
- } else {
- return ((HandlerIdentifier) o).m_name.equalsIgnoreCase(m_name) && m_namespace.equalsIgnoreCase(((HandlerIdentifier) o).m_namespace);
- }
- }
-
- /**
- * Get the factory object used for this handler.
- * The object is get when used for the first time.
- * @return the factory object.
- */
- public HandlerFactory getFactory() {
- if (m_reference == null) {
- return null;
- }
- if (m_factory == null) {
- m_factory = (HandlerFactory) m_tracker.getService(getReference());
- }
- return m_factory;
- }
-
- /**
- * Get the handler full name (namespace:name).
- * @return the handler full name
- */
- public String getFullName() {
- if (m_namespace == null) {
- return IPojoConfiguration.IPOJO_NAMESPACE + ":" + m_name;
- } else {
- return m_namespace + ":" + m_name;
- }
- }
-
- public String getName() {
- return m_name;
- }
-
- public String getNamespace() {
- return m_namespace;
- }
-
- public ServiceReference getReference() {
- return m_reference;
- }
-
- public int getLevel() {
- return m_level;
- }
-
- /**
- * Release the reference of the used factory.
- */
- public void unRef() {
- if (m_reference != null) {
- m_tracker.ungetService(m_reference);
- m_factory = null;
- m_reference = null;
- }
- }
-
- /**
- * Set the service reference.
- * If the new service reference is null, it unget the used factory (if already get).
- * @param ref : new service reference.
- */
- public void setReference(ServiceReference ref) {
- m_reference = ref;
- Integer p = (Integer) m_reference.getProperty(Handler.HANDLER_LEVEL_PROPERTY);
- if (p != null) {
- m_level = p.intValue();
- }
- }
-
- /**
- * Start level Comparison.
- * This method is used to sort the handler array.
- * @param o : object on which compare.
- * @return -1, 0, +1 according to the comparison of their start level.
- * @see java.lang.Comparable#compareTo(java.lang.Object)
- */
- public int compareTo(Object o) {
- if (o instanceof HandlerIdentifier) {
- HandlerIdentifier hi = (HandlerIdentifier) o;
- if (this.m_level == hi.m_level) {
- return 0;
- } else if (this.m_level < hi.m_level) {
- return -1;
- } else {
- return +1;
- }
- }
- return 0;
+ * Returns manipulation metadata of this component type.
+ * The returned object is computed at the first call and then is cached.
+ * @return manipulation metadata of this component type.
+ */
+ public PojoMetadata getPojoMetadata() {
+ if (m_manipulation == null) {
+ m_manipulation = new PojoMetadata(m_componentMetadata);
}
+ return m_manipulation;
}
/**
@@ -1048,22 +336,20 @@
/**
* Map of defined classes [Name, Class Object].
*/
- private Map m_definedClasses = new HashMap();
+ private final Map m_definedClasses = new HashMap();
/**
* The defineClass method.
* @param name : name of the class
- * @param b : the byte array of the class
+ * @param clazz : the byte array of the class
* @param domain : the protection domain
* @return : the defined class.
*/
- public Class defineClass(String name, byte[] b, ProtectionDomain domain) {
- if (m_definedClasses.containsKey(name)) {
- return (Class) m_definedClasses.get(name);
- }
- final Class c = super.defineClass(name, b, 0, b.length, domain);
- m_definedClasses.put(name, c);
- return c;
+ public Class defineClass(String name, byte[] clazz, ProtectionDomain domain) {
+ if (m_definedClasses.containsKey(name)) { return (Class) m_definedClasses.get(name); }
+ Class clas = super.defineClass(name, clazz, 0, clazz.length, domain);
+ m_definedClasses.put(name, clas);
+ return clas;
}
/**
@@ -1084,8 +370,44 @@
* @return : the loaded class
* @throws ClassNotFoundException : the class to load is not found
*/
- protected Class loadClass(final String name, final boolean resolve) throws ClassNotFoundException {
+ protected synchronized Class loadClass(String name, boolean resolve) throws ClassNotFoundException {
return m_context.getBundle().loadClass(name);
+ }
+ }
+
+ private final class PrimitiveTypeDescription extends ComponentTypeDescription {
+
+ /**
+ * Constructor.
+ * @param factory : the represented factory.
+ */
+ public PrimitiveTypeDescription(Factory factory) {
+ super(factory);
+ }
+
+ /**
+ * Compute the properties to publish :
+ * component.class contains the pojo class name.
+ * @return the dictionary of properties to publish
+ * @see org.apache.felix.ipojo.architecture.ComponentTypeDescription#getPropertiesToPublish()
+ */
+ public Dictionary getPropertiesToPublish() {
+ Dictionary dict = super.getPropertiesToPublish();
+ if (m_classname != null) {
+ dict.put("component.class", m_classname);
+ }
+ return dict;
+ }
+
+ /**
+ * Add the "implementation-class" attribute to the type description.
+ * @return the component type description.
+ * @see org.apache.felix.ipojo.architecture.ComponentTypeDescription#getDescription()
+ */
+ public Element getDescription() {
+ Element elem = super.getDescription();
+ elem.addAttribute(new Attribute("Implementation-Class", m_classname));
+ return elem;
}
}
}