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 2006/06/14 17:22:08 UTC
svn commit: r414287 [1/6] - in /incubator/felix/trunk:
org.apache.felix.ipojo.arch/ org.apache.felix.ipojo.arch/src/
org.apache.felix.ipojo.arch/src/main/
org.apache.felix.ipojo.arch/src/main/java/
org.apache.felix.ipojo.arch/src/main/java/org/ org.apa...
Author: rickhall
Date: Wed Jun 14 08:22:03 2006
New Revision: 414287
URL: http://svn.apache.org/viewvc?rev=414287&view=rev
Log:
Initial commit of iPOJO source, which was accepted as a subproject
contribution by a vote.
Added:
incubator/felix/trunk/org.apache.felix.ipojo/ (with props)
incubator/felix/trunk/org.apache.felix.ipojo.arch/ (with props)
incubator/felix/trunk/org.apache.felix.ipojo.arch/pom.xml (with props)
incubator/felix/trunk/org.apache.felix.ipojo.arch/src/
incubator/felix/trunk/org.apache.felix.ipojo.arch/src/main/
incubator/felix/trunk/org.apache.felix.ipojo.arch/src/main/java/
incubator/felix/trunk/org.apache.felix.ipojo.arch/src/main/java/org/
incubator/felix/trunk/org.apache.felix.ipojo.arch/src/main/java/org/apache/
incubator/felix/trunk/org.apache.felix.ipojo.arch/src/main/java/org/apache/felix/
incubator/felix/trunk/org.apache.felix.ipojo.arch/src/main/java/org/apache/felix/ipojo/
incubator/felix/trunk/org.apache.felix.ipojo.arch/src/main/java/org/apache/felix/ipojo/arch/
incubator/felix/trunk/org.apache.felix.ipojo.arch/src/main/java/org/apache/felix/ipojo/arch/ArchCommandImpl.java (with props)
incubator/felix/trunk/org.apache.felix.ipojo.arch/src/main/resources/
incubator/felix/trunk/org.apache.felix.ipojo.arch/src/main/resources/metadata.xml (with props)
incubator/felix/trunk/org.apache.felix.ipojo.metadata/ (with props)
incubator/felix/trunk/org.apache.felix.ipojo.metadata/pom.xml (with props)
incubator/felix/trunk/org.apache.felix.ipojo.metadata/src/
incubator/felix/trunk/org.apache.felix.ipojo.metadata/src/main/
incubator/felix/trunk/org.apache.felix.ipojo.metadata/src/main/java/
incubator/felix/trunk/org.apache.felix.ipojo.metadata/src/main/java/org/
incubator/felix/trunk/org.apache.felix.ipojo.metadata/src/main/java/org/apache/
incubator/felix/trunk/org.apache.felix.ipojo.metadata/src/main/java/org/apache/felix/
incubator/felix/trunk/org.apache.felix.ipojo.metadata/src/main/java/org/apache/felix/ipojo/
incubator/felix/trunk/org.apache.felix.ipojo.metadata/src/main/java/org/apache/felix/ipojo/metadata/
incubator/felix/trunk/org.apache.felix.ipojo.metadata/src/main/java/org/apache/felix/ipojo/metadata/Attribute.java (with props)
incubator/felix/trunk/org.apache.felix.ipojo.metadata/src/main/java/org/apache/felix/ipojo/metadata/Element.java (with props)
incubator/felix/trunk/org.apache.felix.ipojo.metadata/src/main/resources/
incubator/felix/trunk/org.apache.felix.ipojo.plugin/ (with props)
incubator/felix/trunk/org.apache.felix.ipojo.plugin/pom.xml (with props)
incubator/felix/trunk/org.apache.felix.ipojo.plugin/src/
incubator/felix/trunk/org.apache.felix.ipojo.plugin/src/main/
incubator/felix/trunk/org.apache.felix.ipojo.plugin/src/main/java/
incubator/felix/trunk/org.apache.felix.ipojo.plugin/src/main/java/org/
incubator/felix/trunk/org.apache.felix.ipojo.plugin/src/main/java/org/apache/
incubator/felix/trunk/org.apache.felix.ipojo.plugin/src/main/java/org/apache/felix/
incubator/felix/trunk/org.apache.felix.ipojo.plugin/src/main/java/org/apache/felix/ipojo/
incubator/felix/trunk/org.apache.felix.ipojo.plugin/src/main/java/org/apache/felix/ipojo/manipulation/
incubator/felix/trunk/org.apache.felix.ipojo.plugin/src/main/java/org/apache/felix/ipojo/manipulation/ManipulationProperty.java (with props)
incubator/felix/trunk/org.apache.felix.ipojo.plugin/src/main/java/org/apache/felix/ipojo/manipulation/Manipulator.java (with props)
incubator/felix/trunk/org.apache.felix.ipojo.plugin/src/main/java/org/apache/felix/ipojo/manipulation/PreprocessClassAdapter.java (with props)
incubator/felix/trunk/org.apache.felix.ipojo.plugin/src/main/java/org/apache/felix/ipojo/manipulation/PreprocessCodeAdapter.java (with props)
incubator/felix/trunk/org.apache.felix.ipojo.plugin/src/main/java/org/apache/felix/ipojo/parser/
incubator/felix/trunk/org.apache.felix.ipojo.plugin/src/main/java/org/apache/felix/ipojo/parser/ManifestMetadataParser.java (with props)
incubator/felix/trunk/org.apache.felix.ipojo.plugin/src/main/java/org/apache/felix/ipojo/parser/ParseException.java (with props)
incubator/felix/trunk/org.apache.felix.ipojo.plugin/src/main/java/org/apache/felix/ipojo/parser/XMLMetadataParser.java (with props)
incubator/felix/trunk/org.apache.felix.ipojo.plugin/src/main/java/org/apache/felix/ipojo/plugin/
incubator/felix/trunk/org.apache.felix.ipojo.plugin/src/main/java/org/apache/felix/ipojo/plugin/Clazz.java (with props)
incubator/felix/trunk/org.apache.felix.ipojo.plugin/src/main/java/org/apache/felix/ipojo/plugin/IpojoPluginConfiguration.java (with props)
incubator/felix/trunk/org.apache.felix.ipojo.plugin/src/main/java/org/apache/felix/ipojo/plugin/Jar.java (with props)
incubator/felix/trunk/org.apache.felix.ipojo.plugin/src/main/java/org/apache/felix/ipojo/plugin/OsgiJarMojo.java (with props)
incubator/felix/trunk/org.apache.felix.ipojo.plugin/src/main/java/org/apache/felix/ipojo/plugin/OsgiManifest.java (with props)
incubator/felix/trunk/org.apache.felix.ipojo.plugin/src/main/java/org/apache/felix/ipojo/plugin/QuotedTokenizer.java (with props)
incubator/felix/trunk/org.apache.felix.ipojo.plugin/src/main/resources/
incubator/felix/trunk/org.apache.felix.ipojo.plugin/src/main/resources/META-INF/
incubator/felix/trunk/org.apache.felix.ipojo.plugin/src/main/resources/META-INF/archetype.xml (with props)
incubator/felix/trunk/org.apache.felix.ipojo.plugin/src/main/resources/META-INF/plexus/
incubator/felix/trunk/org.apache.felix.ipojo.plugin/src/main/resources/META-INF/plexus/components.xml (with props)
incubator/felix/trunk/org.apache.felix.ipojo.plugin/src/main/resources/archetype-resources/
incubator/felix/trunk/org.apache.felix.ipojo.plugin/src/main/resources/archetype-resources/pom.xml (with props)
incubator/felix/trunk/org.apache.felix.ipojo.plugin/src/main/resources/archetype-resources/src/
incubator/felix/trunk/org.apache.felix.ipojo.plugin/src/main/resources/archetype-resources/src/main/
incubator/felix/trunk/org.apache.felix.ipojo.plugin/src/main/resources/archetype-resources/src/main/java/
incubator/felix/trunk/org.apache.felix.ipojo.plugin/src/main/resources/archetype-resources/src/main/java/source.txt (with props)
incubator/felix/trunk/org.apache.felix.ipojo.plugin/src/main/resources/archetype-resources/src/main/resources/
incubator/felix/trunk/org.apache.felix.ipojo.plugin/src/main/resources/archetype-resources/src/main/resources/metadata.xml (with props)
incubator/felix/trunk/org.apache.felix.ipojo/pom.xml (with props)
incubator/felix/trunk/org.apache.felix.ipojo/src/
incubator/felix/trunk/org.apache.felix.ipojo/src/main/
incubator/felix/trunk/org.apache.felix.ipojo/src/main/java/
incubator/felix/trunk/org.apache.felix.ipojo/src/main/java/org/
incubator/felix/trunk/org.apache.felix.ipojo/src/main/java/org/apache/
incubator/felix/trunk/org.apache.felix.ipojo/src/main/java/org/apache/felix/
incubator/felix/trunk/org.apache.felix.ipojo/src/main/java/org/apache/felix/ipojo/
incubator/felix/trunk/org.apache.felix.ipojo/src/main/java/org/apache/felix/ipojo/Activator.java (with props)
incubator/felix/trunk/org.apache.felix.ipojo/src/main/java/org/apache/felix/ipojo/Callback.java (with props)
incubator/felix/trunk/org.apache.felix.ipojo/src/main/java/org/apache/felix/ipojo/ComponentManager.java (with props)
incubator/felix/trunk/org.apache.felix.ipojo/src/main/java/org/apache/felix/ipojo/ComponentManagerFactory.java (with props)
incubator/felix/trunk/org.apache.felix.ipojo/src/main/java/org/apache/felix/ipojo/ComponentMetadata.java (with props)
incubator/felix/trunk/org.apache.felix.ipojo/src/main/java/org/apache/felix/ipojo/DummyActivator.java (with props)
incubator/felix/trunk/org.apache.felix.ipojo/src/main/java/org/apache/felix/ipojo/Handler.java (with props)
incubator/felix/trunk/org.apache.felix.ipojo/src/main/java/org/apache/felix/ipojo/IPojoConfiguration.java (with props)
incubator/felix/trunk/org.apache.felix.ipojo/src/main/java/org/apache/felix/ipojo/Nullable.java (with props)
incubator/felix/trunk/org.apache.felix.ipojo/src/main/java/org/apache/felix/ipojo/architecture/
incubator/felix/trunk/org.apache.felix.ipojo/src/main/java/org/apache/felix/ipojo/architecture/Architecture.java (with props)
incubator/felix/trunk/org.apache.felix.ipojo/src/main/java/org/apache/felix/ipojo/architecture/ComponentDescription.java (with props)
incubator/felix/trunk/org.apache.felix.ipojo/src/main/java/org/apache/felix/ipojo/architecture/DependencyDescription.java (with props)
incubator/felix/trunk/org.apache.felix.ipojo/src/main/java/org/apache/felix/ipojo/architecture/ProvidedServiceDescription.java (with props)
incubator/felix/trunk/org.apache.felix.ipojo/src/main/java/org/apache/felix/ipojo/architecture/State.java (with props)
incubator/felix/trunk/org.apache.felix.ipojo/src/main/java/org/apache/felix/ipojo/handlers/
incubator/felix/trunk/org.apache.felix.ipojo/src/main/java/org/apache/felix/ipojo/handlers/architecture/
incubator/felix/trunk/org.apache.felix.ipojo/src/main/java/org/apache/felix/ipojo/handlers/architecture/ArchitectureHandler.java (with props)
incubator/felix/trunk/org.apache.felix.ipojo/src/main/java/org/apache/felix/ipojo/handlers/configuration/
incubator/felix/trunk/org.apache.felix.ipojo/src/main/java/org/apache/felix/ipojo/handlers/configuration/ConfigurableProperty.java (with props)
incubator/felix/trunk/org.apache.felix.ipojo/src/main/java/org/apache/felix/ipojo/handlers/configuration/ConfigurationHandler.java (with props)
incubator/felix/trunk/org.apache.felix.ipojo/src/main/java/org/apache/felix/ipojo/handlers/dependency/
incubator/felix/trunk/org.apache.felix.ipojo/src/main/java/org/apache/felix/ipojo/handlers/dependency/Dependency.java (with props)
incubator/felix/trunk/org.apache.felix.ipojo/src/main/java/org/apache/felix/ipojo/handlers/dependency/DependencyCallback.java (with props)
incubator/felix/trunk/org.apache.felix.ipojo/src/main/java/org/apache/felix/ipojo/handlers/dependency/DependencyHandler.java (with props)
incubator/felix/trunk/org.apache.felix.ipojo/src/main/java/org/apache/felix/ipojo/handlers/dependency/DependencyMetadata.java (with props)
incubator/felix/trunk/org.apache.felix.ipojo/src/main/java/org/apache/felix/ipojo/handlers/dependency/NullableClassloader.java (with props)
incubator/felix/trunk/org.apache.felix.ipojo/src/main/java/org/apache/felix/ipojo/handlers/dependency/nullable/
incubator/felix/trunk/org.apache.felix.ipojo/src/main/java/org/apache/felix/ipojo/handlers/dependency/nullable/MethodSignature.java (with props)
incubator/felix/trunk/org.apache.felix.ipojo/src/main/java/org/apache/felix/ipojo/handlers/dependency/nullable/MethodSignatureVisitor.java (with props)
incubator/felix/trunk/org.apache.felix.ipojo/src/main/java/org/apache/felix/ipojo/handlers/dependency/nullable/NullableObjectWriter.java (with props)
incubator/felix/trunk/org.apache.felix.ipojo/src/main/java/org/apache/felix/ipojo/handlers/lifecycle/
incubator/felix/trunk/org.apache.felix.ipojo/src/main/java/org/apache/felix/ipojo/handlers/lifecycle/callback/
incubator/felix/trunk/org.apache.felix.ipojo/src/main/java/org/apache/felix/ipojo/handlers/lifecycle/callback/LifecycleCallback.java (with props)
incubator/felix/trunk/org.apache.felix.ipojo/src/main/java/org/apache/felix/ipojo/handlers/lifecycle/callback/LifecycleCallbackHandler.java (with props)
incubator/felix/trunk/org.apache.felix.ipojo/src/main/java/org/apache/felix/ipojo/handlers/lifecycle/callback/LifecycleCallbackMetadata.java (with props)
incubator/felix/trunk/org.apache.felix.ipojo/src/main/java/org/apache/felix/ipojo/handlers/providedService/
incubator/felix/trunk/org.apache.felix.ipojo/src/main/java/org/apache/felix/ipojo/handlers/providedService/Property.java (with props)
incubator/felix/trunk/org.apache.felix.ipojo/src/main/java/org/apache/felix/ipojo/handlers/providedService/PropertyMetadata.java (with props)
incubator/felix/trunk/org.apache.felix.ipojo/src/main/java/org/apache/felix/ipojo/handlers/providedService/ProvidedService.java (with props)
incubator/felix/trunk/org.apache.felix.ipojo/src/main/java/org/apache/felix/ipojo/handlers/providedService/ProvidedServiceHandler.java (with props)
incubator/felix/trunk/org.apache.felix.ipojo/src/main/java/org/apache/felix/ipojo/handlers/providedService/ProvidedServiceMetadata.java (with props)
incubator/felix/trunk/org.apache.felix.ipojo/src/main/java/org/apache/felix/ipojo/parser/
incubator/felix/trunk/org.apache.felix.ipojo/src/main/java/org/apache/felix/ipojo/parser/ManifestMetadataParser.java (with props)
incubator/felix/trunk/org.apache.felix.ipojo/src/main/java/org/apache/felix/ipojo/parser/ParseException.java (with props)
incubator/felix/trunk/org.apache.felix.ipojo/src/main/java/org/osgi/
incubator/felix/trunk/org.apache.felix.ipojo/src/main/java/org/osgi/service/
incubator/felix/trunk/org.apache.felix.ipojo/src/main/java/org/osgi/service/cm/
incubator/felix/trunk/org.apache.felix.ipojo/src/main/java/org/osgi/service/cm/Configuration.java (with props)
incubator/felix/trunk/org.apache.felix.ipojo/src/main/java/org/osgi/service/cm/ConfigurationAdmin.java (with props)
incubator/felix/trunk/org.apache.felix.ipojo/src/main/java/org/osgi/service/cm/ConfigurationEvent.java (with props)
incubator/felix/trunk/org.apache.felix.ipojo/src/main/java/org/osgi/service/cm/ConfigurationException.java (with props)
incubator/felix/trunk/org.apache.felix.ipojo/src/main/java/org/osgi/service/cm/ConfigurationListener.java (with props)
incubator/felix/trunk/org.apache.felix.ipojo/src/main/java/org/osgi/service/cm/ConfigurationPermission.java (with props)
incubator/felix/trunk/org.apache.felix.ipojo/src/main/java/org/osgi/service/cm/ConfigurationPlugin.java (with props)
incubator/felix/trunk/org.apache.felix.ipojo/src/main/java/org/osgi/service/cm/ManagedService.java (with props)
incubator/felix/trunk/org.apache.felix.ipojo/src/main/java/org/osgi/service/cm/ManagedServiceFactory.java (with props)
incubator/felix/trunk/org.apache.felix.ipojo/src/main/java/org/osgi/service/cm/package.html (with props)
incubator/felix/trunk/org.apache.felix.ipojo/src/main/java/org/osgi/service/cm/packageinfo
incubator/felix/trunk/org.apache.felix.ipojo/src/main/resources/
Propchange: incubator/felix/trunk/org.apache.felix.ipojo/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Wed Jun 14 08:22:03 2006
@@ -0,0 +1,17 @@
+classes
+target
+*.log
+*.ipr
+*.iws
+*.iml
+lib
+bundle
+dist
+.project
+.classpath
+bin
+build
+.settings
+.wtpmodules
+.deployables
+
Propchange: incubator/felix/trunk/org.apache.felix.ipojo.arch/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Wed Jun 14 08:22:03 2006
@@ -0,0 +1,17 @@
+classes
+target
+*.log
+*.ipr
+*.iws
+*.iml
+lib
+bundle
+dist
+.project
+.classpath
+bin
+build
+.settings
+.wtpmodules
+.deployables
+
Added: incubator/felix/trunk/org.apache.felix.ipojo.arch/pom.xml
URL: http://svn.apache.org/viewvc/incubator/felix/trunk/org.apache.felix.ipojo.arch/pom.xml?rev=414287&view=auto
==============================================================================
--- incubator/felix/trunk/org.apache.felix.ipojo.arch/pom.xml (added)
+++ incubator/felix/trunk/org.apache.felix.ipojo.arch/pom.xml Wed Jun 14 08:22:03 2006
@@ -0,0 +1,43 @@
+<project>
+ <parent>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>felix</artifactId>
+ <version>0.8.0-SNAPSHOT</version>
+ </parent>
+ <modelVersion>4.0.0</modelVersion>
+ <packaging>ipojo-bundle</packaging>
+ <name>Apache Felix iPOJO Arch Command</name>
+ <version>0.6.0-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>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>${pom.groupId}</groupId>
+ <artifactId>org.apache.felix.shell</artifactId>
+ <version>0.8.0-SNAPSHOT</version>
+ <scope>provided</scope>
+ </dependency>
+ </dependencies>
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>${pom.groupId}</groupId>
+ <artifactId>org.apache.felix.ipojo.plugin</artifactId>
+ <extensions>true</extensions>
+ <configuration>
+ <osgiManifest>
+ <bundleName>iPOJO Arch Command</bundleName>
+ <bundleSymbolicName>${pom.artifactId}</bundleSymbolicName>
+ <bundleDescription>Architecture Shell Command (arch)</bundleDescription>
+ <iPOJOMetadata>metadata.xml</iPOJOMetadata>
+ </osgiManifest>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+</project>
Propchange: incubator/felix/trunk/org.apache.felix.ipojo.arch/pom.xml
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/felix/trunk/org.apache.felix.ipojo.arch/src/main/java/org/apache/felix/ipojo/arch/ArchCommandImpl.java
URL: http://svn.apache.org/viewvc/incubator/felix/trunk/org.apache.felix.ipojo.arch/src/main/java/org/apache/felix/ipojo/arch/ArchCommandImpl.java?rev=414287&view=auto
==============================================================================
--- incubator/felix/trunk/org.apache.felix.ipojo.arch/src/main/java/org/apache/felix/ipojo/arch/ArchCommandImpl.java (added)
+++ incubator/felix/trunk/org.apache.felix.ipojo.arch/src/main/java/org/apache/felix/ipojo/arch/ArchCommandImpl.java Wed Jun 14 08:22:03 2006
@@ -0,0 +1,91 @@
+package org.apache.felix.ipojo.arch;
+
+
+import java.io.PrintStream;
+import java.util.Enumeration;
+import java.util.HashMap;
+import java.util.Iterator;
+
+import org.apache.felix.ipojo.architecture.Architecture;
+import org.apache.felix.ipojo.architecture.ComponentDescription;
+import org.apache.felix.ipojo.architecture.DependencyDescription;
+import org.apache.felix.ipojo.architecture.ProvidedServiceDescription;
+import org.apache.felix.ipojo.architecture.State;
+import org.ungoverned.osgi.service.shell.Command;
+
+
+/**
+ * Implementation of the archi command printing the actual architecture.
+ * @author Clement Escoffier
+ */
+public class ArchCommandImpl implements Command {
+
+ /**
+ * List of archi service
+ */
+ private Architecture archiService[];
+
+ /**
+ * @see org.ungoverned.osgi.service.shell.Command#getName()
+ */
+ public String getName() {
+ return "arch";
+ }
+
+ /**
+ * @see org.ungoverned.osgi.service.shell.Command#getUsage()
+ */
+ public String getUsage() {
+ return "arch -> Dispaly architecture information";
+ }
+
+ /**
+ * @see org.ungoverned.osgi.service.shell.Command#getShortDescription()
+ */
+ public String getShortDescription() {
+ return "Architecture command : display the architecture";
+ }
+
+ /**
+ * @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++) {
+ ComponentDescription component = archiService[i].getComponentDescription();
+ out.println("Component : " + component.getClassName() + " - " + State.printComponentState(component.getState()));
+ for(int j = 0; j < component.getDependencies().length; j++) {
+ DependencyDescription dd = component.getDependencies()[j];
+ out.println("\t Dependency : " + dd.getInterface() + " - " + State.printDependencyState(dd.getState()) + " - Optional : " + dd.isOptional() + " - Multiple : " + dd.isMultiple());
+ // getUsedServices :
+ HashMap hm = dd.getUsedServices();
+ Iterator it = hm.keySet().iterator();
+ while(it.hasNext()) {
+ String key = (String) it.next();
+ out.println("\t\t Used Service : " + key + " - " + hm.get(key));
+ }
+ }
+ for(int j=0; j < component.getProvideServices().length; j++) {
+ ProvidedServiceDescription ps = component.getProvideServices()[j];
+ String spec = "";
+ for(int k = 0; k < ps.getServiceSpecification().length; k++) {
+ spec = spec + " " + ps.getServiceSpecification()[k];
+ }
+ out.println("\t Provides : " + spec + " - " + State.printProvidedServiceState(ps.getState()));
+ Enumeration e = ps.getProperties().propertyNames();
+ while(e.hasMoreElements()) {
+ Object key = e.nextElement();
+ out.println("\t\t Service Property : " + key.toString() + " = " + ps.getProperties().getProperty(key.toString()));
+ }
+ }
+ out.println("\tCreated Instances : ");
+ for(int j=0; j < component.getInstances().length; j++) {
+ out.println("\t\t" + component.getInstances()[j]);
+ }
+
+ out.print("\n");
+ }
+ }
+
+ }
+}
\ No newline at end of file
Propchange: incubator/felix/trunk/org.apache.felix.ipojo.arch/src/main/java/org/apache/felix/ipojo/arch/ArchCommandImpl.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/felix/trunk/org.apache.felix.ipojo.arch/src/main/resources/metadata.xml
URL: http://svn.apache.org/viewvc/incubator/felix/trunk/org.apache.felix.ipojo.arch/src/main/resources/metadata.xml?rev=414287&view=auto
==============================================================================
--- incubator/felix/trunk/org.apache.felix.ipojo.arch/src/main/resources/metadata.xml (added)
+++ incubator/felix/trunk/org.apache.felix.ipojo.arch/src/main/resources/metadata.xml Wed Jun 14 08:22:03 2006
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<iPOJO>
+ <Component className="org.apache.felix.ipojo.arch.ArchCommandImpl">
+ <Provides interface="org.ungoverned.osgi.service.shell.Command"/>
+ <Dependency field="archiService" optional="true"/>
+ </Component>
+</iPOJO>
\ No newline at end of file
Propchange: incubator/felix/trunk/org.apache.felix.ipojo.arch/src/main/resources/metadata.xml
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/felix/trunk/org.apache.felix.ipojo.metadata/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Wed Jun 14 08:22:03 2006
@@ -0,0 +1,17 @@
+classes
+target
+*.log
+*.ipr
+*.iws
+*.iml
+lib
+bundle
+dist
+.project
+.classpath
+bin
+build
+.settings
+.wtpmodules
+.deployables
+
Added: incubator/felix/trunk/org.apache.felix.ipojo.metadata/pom.xml
URL: http://svn.apache.org/viewvc/incubator/felix/trunk/org.apache.felix.ipojo.metadata/pom.xml?rev=414287&view=auto
==============================================================================
--- incubator/felix/trunk/org.apache.felix.ipojo.metadata/pom.xml (added)
+++ incubator/felix/trunk/org.apache.felix.ipojo.metadata/pom.xml Wed Jun 14 08:22:03 2006
@@ -0,0 +1,12 @@
+<project>
+ <parent>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>felix</artifactId>
+ <version>0.8.0-SNAPSHOT</version>
+ </parent>
+ <modelVersion>4.0.0</modelVersion>
+ <artifactId>org.apache.felix.ipojo.metadata</artifactId>
+ <packaging>jar</packaging>
+ <version>0.6.0-SNAPSHOT</version>
+ <name>Apache Felix iPOJO Metadata</name>
+</project>
Propchange: incubator/felix/trunk/org.apache.felix.ipojo.metadata/pom.xml
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/felix/trunk/org.apache.felix.ipojo.metadata/src/main/java/org/apache/felix/ipojo/metadata/Attribute.java
URL: http://svn.apache.org/viewvc/incubator/felix/trunk/org.apache.felix.ipojo.metadata/src/main/java/org/apache/felix/ipojo/metadata/Attribute.java?rev=414287&view=auto
==============================================================================
--- incubator/felix/trunk/org.apache.felix.ipojo.metadata/src/main/java/org/apache/felix/ipojo/metadata/Attribute.java (added)
+++ incubator/felix/trunk/org.apache.felix.ipojo.metadata/src/main/java/org/apache/felix/ipojo/metadata/Attribute.java Wed Jun 14 08:22:03 2006
@@ -0,0 +1,78 @@
+/*
+ * Copyright 2006 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+package org.apache.felix.ipojo.metadata;
+
+/**
+ * Attribute.
+ * @author Clement Escoffier
+ */
+public class Attribute {
+
+ /**
+ * Name of the attribute.
+ */
+ private String m_name;
+
+ /**
+ * Value of the attribute.
+ */
+ private String m_value;
+
+ /**
+ * Namepsace of the attribute.
+ */
+ private String m_nameSpace;
+
+ /**
+ * Constructor.
+ * @param name : name of the attribute.
+ * @param value : value of the attribute.
+ */
+ public Attribute(String name, String value) {
+ m_name = name.toLowerCase();
+ m_value = value;
+ m_nameSpace = "";
+ }
+
+ /**
+ * Constructor.
+ * @param name : name of the attribute.
+ * @param value : value of the attribute.
+ * @param ns : namespace of the attribute.
+ */
+ public Attribute(String name, String ns, String value) {
+ m_name = name.toLowerCase();
+ m_value = value;
+ m_nameSpace = ns;
+ }
+
+ /**
+ * @return the name
+ */
+ public String getName() { return m_name; }
+
+ /**
+ * @return the value
+ */
+ public String getValue() { return m_value; }
+
+ /**
+ * @return the namespace
+ */
+ public String getNameSpace() { return m_nameSpace; }
+
+}
Propchange: incubator/felix/trunk/org.apache.felix.ipojo.metadata/src/main/java/org/apache/felix/ipojo/metadata/Attribute.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/felix/trunk/org.apache.felix.ipojo.metadata/src/main/java/org/apache/felix/ipojo/metadata/Element.java
URL: http://svn.apache.org/viewvc/incubator/felix/trunk/org.apache.felix.ipojo.metadata/src/main/java/org/apache/felix/ipojo/metadata/Element.java?rev=414287&view=auto
==============================================================================
--- incubator/felix/trunk/org.apache.felix.ipojo.metadata/src/main/java/org/apache/felix/ipojo/metadata/Element.java (added)
+++ incubator/felix/trunk/org.apache.felix.ipojo.metadata/src/main/java/org/apache/felix/ipojo/metadata/Element.java Wed Jun 14 08:22:03 2006
@@ -0,0 +1,311 @@
+/*
+ * Copyright 2006 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+package org.apache.felix.ipojo.metadata;
+
+/**
+ * Element.
+ * @author Clement Escoffier
+ */
+public class Element {
+
+ /**
+ * Name of the element.
+ */
+ private String m_name;
+
+ /**
+ * Name space of the element.
+ */
+ private String m_nameSpace;
+
+ /**
+ * List of the attributes of the element.
+ */
+ private Attribute[] m_attributes = new Attribute[0];
+
+ /**
+ * List of the subelement of the element.
+ */
+ private Element[] m_elements = new Element[0];
+
+ /**
+ * Constructor.
+ * @param name : the name of the element
+ * @pram ns : the namespace of the element
+ */
+ public Element(String name, String ns) {
+ m_name = name.toLowerCase();
+ m_nameSpace = ns;
+ }
+
+ /**
+ * @return the sub elements
+ */
+ public Element[] getElements() { return m_elements; }
+
+ /**
+ * @return the attributes
+ */
+ public Attribute[] getAttributes() { return m_attributes; }
+
+ /**
+ * @return the name of the element
+ */
+ public String getName() { return m_name; }
+
+ /**
+ * @return the namespace of the element
+ */
+ public String getNameSpace() { return m_nameSpace; }
+
+ /**
+ * Return the value of the attribute given in parameter.
+ * @param name : the name of the searched attribute
+ * @return the value of the attrbitue given in parameter, null if the attribute does not exist
+ */
+ public String getAttribute(String name) {
+ name = name.toLowerCase();
+ for (int i = 0; i < m_attributes.length; i++) {
+ if (m_attributes[i].getName().equals(name)) {
+ return m_attributes[i].getValue();
+ }
+ }
+ System.err.println("[Error in Metadata] The attribute " + name + " does not exist in " + m_name + " [" + m_nameSpace + "]");
+ return null;
+ }
+
+ /**
+ * Return the value of the attrbitue "name" of the namespace "ns".
+ * @param name : name of the attribute to find
+ * @param ns : namespace of the attribute to find
+ * @return the String value of the attribute, or null if the attribute is not found.
+ */
+ public String getAttribute(String name, String ns) {
+ name = name.toLowerCase();
+ for (int i = 0; i < m_attributes.length; i++) {
+ if (m_attributes[i].getName().equals(name) && m_attributes[i].getNameSpace().equals(ns)) {
+ return m_attributes[i].getValue();
+ }
+ }
+ System.err.println("[Error in Metadata] The attribute " + name + "[" + ns + "] does not exist in " + m_name + " [" + m_nameSpace + "]");
+ return null;
+ }
+
+ /**
+ * Add a subelement.
+ * @param elem : the element to add
+ */
+ public void addElement(Element elem) {
+ for (int i = 0; (m_elements != null) && (i < m_elements.length); i++) {
+ if (m_elements[i] == elem) { return; }
+ }
+
+ if (m_elements != null) {
+ Element[] newElementsList = new Element[m_elements.length + 1];
+ System.arraycopy(m_elements, 0, newElementsList, 0, m_elements.length);
+ newElementsList[m_elements.length] = elem;
+ m_elements = newElementsList;
+ }
+ else { m_elements = new Element[] {elem}; }
+ }
+
+ private static Element[] addElement(Element[] list, Element elem) {
+ if (list != null) {
+ Element[] newElementsList = new Element[list.length + 1];
+ System.arraycopy(list, 0, newElementsList, 0, list.length);
+ newElementsList[list.length] = elem;
+ return newElementsList;
+ }
+ else { return new Element[] {elem}; }
+ }
+
+ /**
+ * Remove a subelement.
+ * @param elem : the element to remove
+ */
+ public void removeElement(Element elem) {
+ int idx = -1;
+ for (int i = 0; i < m_elements.length; i++) {
+ if (m_elements[i] == elem) { idx = i; break; }
+ }
+
+ if (idx >= 0) {
+ if ((m_elements.length - 1) == 0) { m_elements = new Element[0]; }
+ else {
+ Element[] newElementsList = new Element[m_elements.length - 1];
+ System.arraycopy(m_elements, 0, newElementsList, 0, idx);
+ if (idx < newElementsList.length) {
+ System.arraycopy(m_elements, idx + 1, newElementsList, idx, newElementsList.length - idx); }
+ m_elements = newElementsList;
+ }
+ }
+ }
+
+ /**
+ * Add a attribute.
+ * @param att : the attribute to add
+ */
+ public void addAttribute(Attribute att) {
+ for (int i = 0; (m_attributes != null) && (i < m_attributes.length); i++) {
+ if (m_attributes[i] == att) { return; }
+ }
+
+ if (m_attributes != null) {
+ Attribute[] newAttributesList = new Attribute[m_attributes.length + 1];
+ System.arraycopy(m_attributes, 0, newAttributesList, 0, m_attributes.length);
+ newAttributesList[m_attributes.length] = att;
+ m_attributes = newAttributesList;
+ }
+ else { m_attributes = new Attribute[] {att}; }
+ }
+
+ /**
+ * Remove an attribute.
+ * @param att : the attribute to remove
+ */
+ public void removeAttribute(Attribute att) {
+ int idx = -1;
+ for (int i = 0; i < m_attributes.length; i++) {
+ if (m_attributes[i] == att) { idx = i; break; }
+ }
+
+ if (idx >= 0) {
+ if ((m_attributes.length - 1) == 0) { m_attributes = new Attribute[0]; }
+ else {
+ Attribute[] newAttributesList = new Attribute[m_attributes.length - 1];
+ System.arraycopy(m_attributes, 0, newAttributesList, 0, idx);
+ if (idx < newAttributesList.length) {
+ System.arraycopy(m_attributes, idx + 1, newAttributesList, idx, newAttributesList.length - idx); }
+ m_attributes = newAttributesList;
+ }
+ }
+ }
+
+ /**
+ * Get the elements array of the element type given in parameter.
+ * This method look for an empty namespace.
+ * @param name : the type of the element to find (element name)
+ * @return the resulting element array (empty if the search failed)
+ */
+ public Element[] getElements(String name) {
+ name = name.toLowerCase();
+ Element[] list = new Element[0];
+ for (int i = 0; i < m_elements.length; i++) {
+ if (m_elements[i].getName().equals(name) && m_elements[i].getNameSpace().equals("")) {
+ list = Element.addElement(list, m_elements[i]);
+ }
+ }
+ return list;
+ }
+
+ /**
+ * Get the elements array of the element type given in parameter.
+ * @param name : the type of the element to find (element name)
+ * @param ns : the namespace of the element
+ * @return the resulting element array (empty if the search failed)
+ */
+ public Element[] getElements(String name, String ns) {
+ name = name.toLowerCase();
+ Element[] list = new Element[0];
+ for (int i = 0; i < m_elements.length; i++) {
+ if (m_elements[i].getName().equals(name) && m_elements[i].getNameSpace().equals(ns)) {
+ list = Element.addElement(list, m_elements[i]);
+ }
+ }
+ return list;
+ }
+
+ /**
+ * Is the element contains a subelement of the type given in parameter.
+ * This method does not manage the namespace
+ * @param name : type of the element to check.
+ * @return true if the element contains an element of the type "name"
+ */
+ public boolean containsElement(String name) {
+ name = name.toLowerCase();
+ for (int i = 0; i < m_elements.length; i++) {
+ if (m_elements[i].getName().equals(name)) { return true; }
+ }
+ return false;
+ }
+
+ /**
+ * Is the element contains a subelement of the type given in parameter.
+ * This method does not manage the namespace
+ * @param name : type of the element to check.
+ * @return true if the element contains an element of the type "name"
+ */
+ public boolean containsElement(String name, String ns) {
+ name = name.toLowerCase();
+ ns = ns.toLowerCase();
+ for (int i = 0; i < m_elements.length; i++) {
+ if (m_elements[i].getName().equals(name) && m_elements[i].getNameSpace().equals(ns)) { return true; }
+ }
+ return false;
+ }
+
+ /**
+ * Is the element contains an attribute of the name given in parameter.
+ * @param name : name of the element
+ * @return true if the element contains an attribute of the type "name"
+ */
+ public boolean containsAttribute(String name) {
+ name = name.toLowerCase();
+ for (int i = 0; i < m_attributes.length; i++) {
+ if (m_attributes[i].getName().equals(name)) { return true; }
+ }
+ return false;
+ }
+
+ /**
+ * @return the first-order namespaces list of the current element. First-order namespace are namespace of the element attribute and namespaces of its direct sub-element.
+ */
+ public String[] getNamespaces() {
+ String[] ns = new String[0];
+
+ // Look for each direct sub-element
+ for (int i = 0; i < m_elements.length; i++) {
+ boolean found = false;
+ for (int j = 0; !found && j < ns.length; j++) {
+ if (ns[j].equals(m_elements[i].getNameSpace())) { found = true; }
+ }
+ if (!found) {
+ String[] newNSList = new String[ns.length + 1];
+ System.arraycopy(ns, 0, newNSList, 0, ns.length);
+ newNSList[ns.length] = m_elements[i].getNameSpace();
+ ns = newNSList;
+ }
+ }
+
+ // Look for each attribute
+ for (int i = 0; i < m_attributes.length; i++) {
+ boolean found = false;
+ for (int j = 0; !found && j < ns.length; j++) {
+ if (ns[j].equals(m_attributes[i].getNameSpace())) { found = true; }
+ }
+ if (!found) {
+ String[] newNSList = new String[ns.length + 1];
+ System.arraycopy(ns, 0, newNSList, 0, ns.length);
+ newNSList[ns.length] = m_attributes[i].getNameSpace();
+ ns = newNSList;
+ }
+ }
+
+ return ns;
+ }
+
+}
Propchange: incubator/felix/trunk/org.apache.felix.ipojo.metadata/src/main/java/org/apache/felix/ipojo/metadata/Element.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/felix/trunk/org.apache.felix.ipojo.plugin/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Wed Jun 14 08:22:03 2006
@@ -0,0 +1,17 @@
+classes
+target
+*.log
+*.ipr
+*.iws
+*.iml
+lib
+bundle
+dist
+.project
+.classpath
+bin
+build
+.settings
+.wtpmodules
+.deployables
+
Added: incubator/felix/trunk/org.apache.felix.ipojo.plugin/pom.xml
URL: http://svn.apache.org/viewvc/incubator/felix/trunk/org.apache.felix.ipojo.plugin/pom.xml?rev=414287&view=auto
==============================================================================
--- incubator/felix/trunk/org.apache.felix.ipojo.plugin/pom.xml (added)
+++ incubator/felix/trunk/org.apache.felix.ipojo.plugin/pom.xml Wed Jun 14 08:22:03 2006
@@ -0,0 +1,54 @@
+<project>
+ <parent>
+ <artifactId>felix</artifactId>
+ <groupId>org.apache.felix</groupId>
+ <version>0.8.0-SNAPSHOT</version>
+ </parent>
+ <modelVersion>4.0.0</modelVersion>
+ <artifactId>org.apache.felix.ipojo.plugin</artifactId>
+ <version>0.6.0-SNAPSHOT</version>
+ <name>Apache Felix iPOJO Maven Plugin</name>
+ <packaging>maven-plugin</packaging>
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.maven</groupId>
+ <artifactId>maven-plugin-api</artifactId>
+ <version>2.0</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.maven</groupId>
+ <artifactId>maven-archiver</artifactId>
+ <version>2.0</version>
+ </dependency>
+ <dependency>
+ <groupId>org.codehaus.plexus</groupId>
+ <artifactId>plexus-utils</artifactId>
+ <version>1.1</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.maven</groupId>
+ <artifactId>maven-artifact</artifactId>
+ <version>2.0</version>
+ </dependency>
+ <dependency>
+ <groupId>kxml2</groupId>
+ <artifactId>kxml2</artifactId>
+ <version>2.2.2</version>
+ </dependency>
+ <dependency>
+ <groupId>asm</groupId>
+ <artifactId>asm</artifactId>
+ <version>2.2.1</version>
+ </dependency>
+ <dependency>
+ <groupId>xerces</groupId>
+ <artifactId>xercesImpl</artifactId>
+ <version>2.4.0</version>
+ </dependency>
+ <dependency>
+ <groupId>${pom.groupId}</groupId>
+ <artifactId>org.apache.felix.ipojo.metadata</artifactId>
+ <version>${pom.version}</version>
+ </dependency>
+ </dependencies>
+</project>
Propchange: incubator/felix/trunk/org.apache.felix.ipojo.plugin/pom.xml
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/felix/trunk/org.apache.felix.ipojo.plugin/src/main/java/org/apache/felix/ipojo/manipulation/ManipulationProperty.java
URL: http://svn.apache.org/viewvc/incubator/felix/trunk/org.apache.felix.ipojo.plugin/src/main/java/org/apache/felix/ipojo/manipulation/ManipulationProperty.java?rev=414287&view=auto
==============================================================================
--- incubator/felix/trunk/org.apache.felix.ipojo.plugin/src/main/java/org/apache/felix/ipojo/manipulation/ManipulationProperty.java (added)
+++ incubator/felix/trunk/org.apache.felix.ipojo.plugin/src/main/java/org/apache/felix/ipojo/manipulation/ManipulationProperty.java Wed Jun 14 08:22:03 2006
@@ -0,0 +1,57 @@
+/*
+ * Copyright 2006 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+package org.apache.felix.ipojo.manipulation;
+
+/**
+ * Store properties for the manipulation process.
+ * @author Clement Escoffier
+ *
+ */
+public class ManipulationProperty {
+
+ /**
+ * iPOJO Package name.
+ */
+ protected static final String IPOJO_PACKAGE_NAME = "org.apache.felix.ipojo";
+
+ /**
+ * Activator internal package name.
+ */
+ protected static final String IPOJO_INTERNAL_PACKAGE_NAME = "org/apache/felix/ipojo/";
+
+ /**
+ * Ipojo internal package name for internal descriptor.
+ */
+ protected static final String IPOJO_INTERNAL_DESCRIPTOR = "L" + IPOJO_INTERNAL_PACKAGE_NAME;
+
+ /**
+ * Helper array for bytecode manipulation of primitive type.
+ */
+ protected static final String[][] PRIMITIVE_BOXING_INFORMATION =
+ new String[][] {
+ {"V", "ILLEGAL", "ILLEGAL"}, // Void type [0]
+ {"Z", "java/lang/Boolean", "booleanValue"}, // boolean [1]
+ {"C", "java/lang/Character", "charValue"}, // char [2]
+ {"B", "java/lang/Byte", "byteValue"}, // byte [3]
+ {"S", "java/lang/Short", "shortValue"}, // short [4]
+ {"I", "java/lang/Integer", "intValue"}, // int [5]
+ {"F", "java/lang/Float", "floatValue"}, // float [6]
+ {"J", "java/lang/Long", "longValue"}, // long [7]
+ {"D", "java/lang/Double", "doubleValue"} // double [8]
+ };
+
+}
Propchange: incubator/felix/trunk/org.apache.felix.ipojo.plugin/src/main/java/org/apache/felix/ipojo/manipulation/ManipulationProperty.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/felix/trunk/org.apache.felix.ipojo.plugin/src/main/java/org/apache/felix/ipojo/manipulation/Manipulator.java
URL: http://svn.apache.org/viewvc/incubator/felix/trunk/org.apache.felix.ipojo.plugin/src/main/java/org/apache/felix/ipojo/manipulation/Manipulator.java?rev=414287&view=auto
==============================================================================
--- incubator/felix/trunk/org.apache.felix.ipojo.plugin/src/main/java/org/apache/felix/ipojo/manipulation/Manipulator.java (added)
+++ incubator/felix/trunk/org.apache.felix.ipojo.plugin/src/main/java/org/apache/felix/ipojo/manipulation/Manipulator.java Wed Jun 14 08:22:03 2006
@@ -0,0 +1,115 @@
+/*
+ * Copyright 2006 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+package org.apache.felix.ipojo.manipulation;
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.InputStream;
+import java.net.URL;
+import java.util.HashMap;
+import java.util.logging.Level;
+
+import org.apache.felix.ipojo.plugin.IpojoPluginConfiguration;
+import org.objectweb.asm.ClassReader;
+import org.objectweb.asm.ClassWriter;
+
+/**
+ * iPOJO Bytecode Manipulator.
+ * @author Clement Escoffier
+ *
+ */
+public class Manipulator {
+ /**
+ * Store the visited fields : [name fo the field, type of the field].
+ */
+ private HashMap m_fields = new HashMap();
+
+ /**
+ * Store the interface implemented by the class.
+ */
+ private String[] m_interfaces = new String[0];
+
+ /**
+ * Return the hashmap [name of the field, type of the field].
+ * This information is found when the class is manipulated
+ * It is a clone of the original hashmap to avoid modification by handlers
+ * @return the hashmap [name of the field, type of the field].
+ */
+ public HashMap getFields() {
+ return (HashMap)m_fields.clone();
+ }
+
+ /**
+ * Return the hashmap [name of the field, type of the field].
+ * This information is found when the class is manipulated
+ * It is a clone of the original hashmap to avoid modification by handlers
+ * @return the hashmap [name of the field, type of the field].
+ */
+ public String[] getInterfaces() { return (String[])m_interfaces.clone(); }
+
+ /**
+ * Manipulate the class.
+ * @param bundle The component's m_bundle
+ * @param name The name of the class
+ * @param cm The component manager attached to this manipulation
+ * @return A byte array.
+ * @throws Exception : throwed if the manipulation failed.
+ */
+ public void preProcess(String name, File outputDirectory) throws Exception {
+
+ // gets an input stream to read the bytecode of the class
+ String path = outputDirectory+"/"+name.replace('.', '/') + ".class";
+ File clazz = new File(path);
+ URL url = clazz.toURI().toURL();
+
+ //if (url == null) { throw new ClassNotFoundException(name); }
+ IpojoPluginConfiguration.getLogger().log(Level.INFO, "Manipulate the class file : " + clazz.getAbsolutePath());
+
+ InputStream is = url.openStream();
+
+ //Manipulation ->
+ // Add the _setComponentManager method
+ // Instrument all fields
+ ClassReader cr0 = new ClassReader(is);
+ ClassWriter cw0 = new ClassWriter(true);
+ PreprocessClassAdapter preprocess = new PreprocessClassAdapter(cw0);
+ cr0.accept(preprocess, false);
+ is.close();
+
+ File file = null;
+ try {
+ file = new File(url.getFile());
+
+
+ //file.createNewFile();
+ FileOutputStream fos = new FileOutputStream(file);
+
+ fos.write(cw0.toByteArray());
+
+ fos.close();
+ IpojoPluginConfiguration.getLogger().log(Level.INFO, "Put the file " + file.getAbsolutePath() + " in the jar file");
+ } catch (Exception e) { System.err.println("Problem to write the adapted class on the file system " + " [ "+ file.getAbsolutePath() +" ] " + e.getMessage()); }
+
+ m_fields = preprocess.getFields();
+ m_interfaces = new String[preprocess.getInterfaces().length];
+ for (int i = 0; i < m_interfaces.length; i++) {
+ m_interfaces[i] = preprocess.getInterfaces()[i].replace('/', '.');
+ }
+ }
+
+
+}
Propchange: incubator/felix/trunk/org.apache.felix.ipojo.plugin/src/main/java/org/apache/felix/ipojo/manipulation/Manipulator.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/felix/trunk/org.apache.felix.ipojo.plugin/src/main/java/org/apache/felix/ipojo/manipulation/PreprocessClassAdapter.java
URL: http://svn.apache.org/viewvc/incubator/felix/trunk/org.apache.felix.ipojo.plugin/src/main/java/org/apache/felix/ipojo/manipulation/PreprocessClassAdapter.java?rev=414287&view=auto
==============================================================================
--- incubator/felix/trunk/org.apache.felix.ipojo.plugin/src/main/java/org/apache/felix/ipojo/manipulation/PreprocessClassAdapter.java (added)
+++ incubator/felix/trunk/org.apache.felix.ipojo.plugin/src/main/java/org/apache/felix/ipojo/manipulation/PreprocessClassAdapter.java Wed Jun 14 08:22:03 2006
@@ -0,0 +1,485 @@
+/*
+ * Copyright 2006 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+package org.apache.felix.ipojo.manipulation;
+
+import java.util.HashMap;
+import java.util.logging.Level;
+
+import org.apache.felix.ipojo.plugin.IpojoPluginConfiguration;
+import org.objectweb.asm.ClassAdapter;
+import org.objectweb.asm.ClassVisitor;
+import org.objectweb.asm.FieldVisitor;
+import org.objectweb.asm.Label;
+import org.objectweb.asm.MethodVisitor;
+import org.objectweb.asm.Opcodes;
+import org.objectweb.asm.Type;
+
+
+/**
+ * Manipulate the class.
+ * - Add a static component manager field (_cm) ok
+ * - Create getter and setter for each fields ok
+ * - Store information about field ok
+ * - Store information about implemented interfaces ok
+ * - Change GETFIELD and PUTFIELD to called the getter and setter method
+ * @author Clement Escoffier
+ *
+ */
+public class PreprocessClassAdapter extends ClassAdapter implements Opcodes {
+
+ /**
+ * The owner.
+ * m_owner : String
+ */
+ private String m_owner;
+
+ /**
+ * Interfaces implemented by the component.
+ */
+ private String[] m_itfs = new String[0];
+
+ /**
+ * Field hashmap [field name, type] discovered in the component class.
+ */
+ private HashMap m_fields = new HashMap();
+
+
+ /**
+ * Constructor.
+ * @param cv : Class visitor
+ */
+ public PreprocessClassAdapter(final ClassVisitor cv) {
+ super(cv);
+ }
+
+ /** The visit method.
+ * - Insert the _cm field
+ * - Create the _initialize method
+ * - Create the _cm setter method
+ * @see org.objectweb.asm.ClassVisitor#visit(int, int, String, String, String, String[])
+ * @param version : Version
+ * @param access : Access modifier
+ * @param name : name of the visited element
+ * @param signature : singature of the visited element
+ * @param superName : superclasses (extend clause)
+ * @param interfaces : implement clause
+ */
+ public void visit(
+ final int version,
+ final int access,
+ final String name,
+ final String signature,
+ final String superName,
+ final String[] interfaces) {
+
+ m_owner = name;
+
+ // Insert _cm field
+ super.visitField(ACC_PUBLIC + ACC_STATIC, "_cm", ManipulationProperty.IPOJO_INTERNAL_DESCRIPTOR + "ComponentManager;", null, null);
+
+ // Create the _cmSetter(ComponentManager cm) method
+ createComponentManagerSetter();
+
+ //Store the interfaces :
+ m_itfs = interfaces;
+
+ super.visit(version, access, name, signature, superName, interfaces);
+ }
+
+ /** visit method method :-).
+ * @see org.objectweb.asm.ClassVisitor#visitMethod(int, java.lang.String, java.lang.String, java.lang.String, java.lang.String[])
+ * @param access : access modifier
+ * @param name : name of the method
+ * @param desc : descriptor of the method
+ * @param signature : signature of the method
+ * @param exceptions : exception launched by the method
+ * @return MethodVisitor
+ */
+ public MethodVisitor visitMethod(
+ final int access,
+ final String name,
+ final String desc,
+ final String signature,
+ final String[] exceptions) {
+ MethodVisitor mv = cv.visitMethod(access,
+ name,
+ desc,
+ signature,
+ exceptions);
+
+ if (mv == null) { return null; }
+ else { return new PreprocessCodeAdapter(mv, m_owner); }
+
+ }
+
+ /**
+ * Create the setter method for the _cm field.
+ * The generated method must be called only one time.
+ */
+ private void createComponentManagerSetter() {
+ MethodVisitor mv = super.visitMethod(ACC_PUBLIC + ACC_STATIC, "setComponentManager", "(" + ManipulationProperty.IPOJO_INTERNAL_DESCRIPTOR + "ComponentManager;)V", null, null);
+
+ mv.visitVarInsn(ALOAD, 0);
+ mv.visitFieldInsn(PUTSTATIC, m_owner, "_cm", ManipulationProperty.IPOJO_INTERNAL_DESCRIPTOR + "ComponentManager;");
+ mv.visitInsn(RETURN);
+
+ mv.visitMaxs(0, 0);
+ mv.visitEnd();
+ }
+
+ /** visit Field method.
+ * @see org.objectweb.asm.ClassVisitor#visitField(int, java.lang.String, java.lang.String, java.lang.String, java.lang.Object)
+ * @param access : acces modifier
+ * @param name : name of the field
+ * @param desc : description of the field
+ * @param signature : signature of the field
+ * @param value : value of the field
+ * @return FieldVisitor
+ */
+ public FieldVisitor visitField(
+ final int access,
+ final String name,
+ final String desc,
+ final String signature,
+ final Object value) {
+ if ((access & ACC_STATIC) == 0) {
+ IpojoPluginConfiguration.getLogger().log(Level.INFO, "Manipulate the field declaration of " + name);
+ Type type = Type.getType(desc);
+
+ // Keep the field in the code
+ FieldVisitor fv = cv.visitField(access, name, desc, signature, value);
+
+ if (type.getSort() == Type.ARRAY) {
+ if (type.getInternalName().startsWith("L")) {
+ String internalType = type.getInternalName().substring(1);
+ String nameType = internalType.replace('/', '.');
+ m_fields.put(name, nameType + "[]");
+ }
+ else {
+ String nameType = type.getClassName().substring(0, type.getClassName().length() - 2);
+ m_fields.put(name, nameType);
+ }
+
+ // TODO : Getter & SETTER on array :
+ String gDesc = "()" + desc;
+ createArrayGetter(name, gDesc, type);
+
+ // Generates setter method
+ String sDesc = "(" + desc + ")V";
+ createArraySetter(name, sDesc, type);
+
+ }
+ else {
+ // Store information on the fields
+ m_fields.put(name, type.getClassName());
+
+ // Generate the getter method
+ String gDesc = "()" + desc;
+ createSimpleGetter(name, gDesc, type);
+
+ // Generates setter method
+ String sDesc = "(" + desc + ")V";
+ createSimpleSetter(name, sDesc, type);
+ }
+
+ return fv;
+
+ }
+ return super.visitField(access, name, desc, signature, value);
+ }
+
+ private void createArraySetter(String name, String desc, Type type) {
+ MethodVisitor mv = cv.visitMethod(ACC_PUBLIC, "_set" + name, desc, null, null);
+
+ String internalType = desc.substring(1);
+ internalType = internalType.substring(0, internalType.length() - 2);
+
+ mv.visitVarInsn(ALOAD, 0);
+ mv.visitVarInsn(ALOAD, 1);
+ mv.visitFieldInsn(PUTFIELD, m_owner, name, internalType);
+
+ mv.visitFieldInsn(GETSTATIC, m_owner, "_cm", "Lorg/apache/felix/ipojo/ComponentManager;");
+ mv.visitLdcInsn(name);
+ mv.visitVarInsn(ALOAD, 1);
+ mv.visitMethodInsn(INVOKEVIRTUAL, "org/apache/felix/ipojo/ComponentManager", "setterCallback", "(Ljava/lang/String;Ljava/lang/Object;)V");
+
+ mv.visitInsn(RETURN);
+
+ // End
+ mv.visitMaxs(0, 0);
+ mv.visitEnd();
+ }
+
+ private void createArrayGetter(String name, String desc, Type type) {
+
+// try {
+// System.out.println("Field Name : " + name);
+// System.out.println("Desc : " + desc);
+// System.out.println("ClassName : " + type.getClassName());
+// System.out.println("Descriptor of the type : " + type.getDescriptor());
+// System.out.println("Internal Name : " + type.getInternalName());
+// } catch(Exception e) {}
+//
+
+ String methodName = "_get" + name;
+ MethodVisitor mv = cv.visitMethod(ACC_PUBLIC, methodName, desc, null, null);
+
+ String internalType = desc.substring(2);
+
+ mv.visitVarInsn(ALOAD, 0);
+ //mv.visitFieldInsn(GETFIELD, m_owner, name, "["+type.getInternalName()+";");
+ mv.visitFieldInsn(GETFIELD, m_owner, name, internalType);
+ mv.visitVarInsn(ASTORE, 1);
+
+ mv.visitFieldInsn(GETSTATIC, m_owner, "_cm", "Lorg/apache/felix/ipojo/ComponentManager;");
+ mv.visitLdcInsn(name);
+ mv.visitVarInsn(ALOAD, 1);
+ mv.visitMethodInsn(INVOKEVIRTUAL, "org/apache/felix/ipojo/ComponentManager", "getterCallback", "(Ljava/lang/String;Ljava/lang/Object;)Ljava/lang/Object;");
+ mv.visitVarInsn(ASTORE, 2);
+
+ mv.visitVarInsn(ALOAD, 2);
+ mv.visitTypeInsn(CHECKCAST, internalType);
+ mv.visitVarInsn(ASTORE, 3);
+
+ Label l3a = new Label();
+ mv.visitLabel(l3a);
+
+ mv.visitVarInsn(ALOAD, 1);
+ Label l4a = new Label();
+ mv.visitJumpInsn(IFNULL, l4a);
+ mv.visitVarInsn(ALOAD, 1);
+ mv.visitVarInsn(ALOAD, 3);
+ mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/Object", "equals", "(Ljava/lang/Object;)Z");
+
+ Label l5a = new Label();
+ mv.visitJumpInsn(IFNE, l5a);
+ mv.visitLabel(l4a);
+
+ mv.visitVarInsn(ALOAD, 0);
+ mv.visitVarInsn(ALOAD, 3);
+ mv.visitMethodInsn(INVOKEVIRTUAL, m_owner, "_set" + name, "(" + internalType + ")V");
+ mv.visitLabel(l5a);
+
+ mv.visitVarInsn(ALOAD, 3);
+ mv.visitInsn(ARETURN);
+
+ //End
+ mv.visitMaxs(0, 0);
+ mv.visitEnd();
+ }
+
+
+ /**
+ * Create the getter for service dependency.
+ * @param name : field of the dependency
+ * @param desc : description of the getter method
+ * @param type : type to return
+ */
+ private void createSimpleGetter(String name, String desc, Type type) {
+
+ String methodName = "_get" + name;
+ MethodVisitor mv = cv.visitMethod(ACC_PUBLIC, methodName, desc, null, null);
+
+ switch (type.getSort()) {
+ case Type.BOOLEAN :
+ case Type.CHAR :
+ case Type.BYTE :
+ case Type.SHORT :
+ case Type.INT :
+ case Type.FLOAT :
+ case Type.LONG :
+ case Type.DOUBLE :
+
+ String internalName = ManipulationProperty.PRIMITIVE_BOXING_INFORMATION[type.getSort()][0];
+ String boxingType = ManipulationProperty.PRIMITIVE_BOXING_INFORMATION[type.getSort()][1];
+ String unboxingMethod = ManipulationProperty.PRIMITIVE_BOXING_INFORMATION[type.getSort()][2];
+
+ mv.visitVarInsn(ALOAD, 0);
+ mv.visitFieldInsn(GETFIELD, m_owner, name, internalName);
+ mv.visitVarInsn(type.getOpcode(ISTORE), 1);
+
+ mv.visitTypeInsn(NEW, boxingType);
+ mv.visitInsn(DUP);
+ mv.visitVarInsn(type.getOpcode(ILOAD), 1);
+ mv.visitMethodInsn(INVOKESPECIAL, boxingType, "<init>", "(" + internalName + ")V");
+ mv.visitVarInsn(ASTORE, 2);
+
+ mv.visitFieldInsn(GETSTATIC, m_owner, "_cm", "Lorg/apache/felix/ipojo/ComponentManager;");
+ mv.visitLdcInsn(name);
+ mv.visitVarInsn(ALOAD, 2);
+ mv.visitMethodInsn(INVOKEVIRTUAL, "org/apache/felix/ipojo/ComponentManager", "getterCallback", "(Ljava/lang/String;Ljava/lang/Object;)Ljava/lang/Object;");
+ mv.visitVarInsn(ASTORE, 3);
+
+ mv.visitVarInsn(ALOAD, 3);
+ mv.visitTypeInsn(CHECKCAST, boxingType);
+ mv.visitVarInsn(ASTORE, 4);
+
+ mv.visitVarInsn(ALOAD, 4);
+ mv.visitMethodInsn(INVOKEVIRTUAL, boxingType, unboxingMethod, "()" + internalName);
+ mv.visitVarInsn(type.getOpcode(ISTORE), 5);
+
+ Label l5 = new Label();
+ mv.visitLabel(l5);
+
+ mv.visitVarInsn(type.getOpcode(ILOAD), 1);
+ mv.visitVarInsn(type.getOpcode(ILOAD), 5);
+ Label l6 = new Label();
+ mv.visitJumpInsn(type.getOpcode(IF_ICMPEQ), l6);
+
+ Label l7 = new Label();
+ mv.visitLabel(l7);
+ mv.visitVarInsn(ALOAD, 0);
+ mv.visitVarInsn(type.getOpcode(ILOAD), 5);
+ mv.visitMethodInsn(INVOKEVIRTUAL, m_owner, "_set" + name, "(" + internalName + ")V");
+ mv.visitLabel(l6);
+
+ mv.visitVarInsn(type.getOpcode(ILOAD), 5);
+ mv.visitInsn(type.getOpcode(IRETURN));
+ break;
+
+ case Type.OBJECT :
+
+ mv.visitVarInsn(ALOAD, 0);
+ mv.visitFieldInsn(GETFIELD, m_owner, name, "L" + type.getInternalName() + ";");
+ mv.visitVarInsn(ASTORE, 1);
+
+ mv.visitFieldInsn(GETSTATIC, m_owner, "_cm", "Lorg/apache/felix/ipojo/ComponentManager;");
+ mv.visitLdcInsn(name);
+ mv.visitVarInsn(ALOAD, 1);
+ mv.visitMethodInsn(INVOKEVIRTUAL, "org/apache/felix/ipojo/ComponentManager", "getterCallback", "(Ljava/lang/String;Ljava/lang/Object;)Ljava/lang/Object;");
+ mv.visitVarInsn(ASTORE, 2);
+
+ mv.visitVarInsn(ALOAD, 2);
+ mv.visitTypeInsn(CHECKCAST, type.getInternalName());
+ mv.visitVarInsn(ASTORE, 3);
+
+ Label l3b = new Label();
+ mv.visitLabel(l3b);
+
+ mv.visitVarInsn(ALOAD, 1);
+ Label l4b = new Label();
+ mv.visitJumpInsn(IFNULL, l4b);
+ mv.visitVarInsn(ALOAD, 1);
+ mv.visitVarInsn(ALOAD, 3);
+ mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/Object", "equals", "(Ljava/lang/Object;)Z");
+
+ Label l5b = new Label();
+ mv.visitJumpInsn(IFNE, l5b);
+ mv.visitLabel(l4b);
+
+ mv.visitVarInsn(ALOAD, 0);
+ mv.visitVarInsn(ALOAD, 3);
+ mv.visitMethodInsn(INVOKEVIRTUAL, m_owner, "_set" + name, "(L" + type.getInternalName() + ";)V");
+ mv.visitLabel(l5b);
+
+ mv.visitVarInsn(ALOAD, 3);
+ mv.visitInsn(ARETURN);
+
+ break;
+
+ default :
+ IpojoPluginConfiguration.getLogger().log(Level.SEVERE, "Manipulation problem in " + m_owner + " : a type is not implemented : " + type);
+ break;
+ }
+
+ mv.visitMaxs(0, 0);
+ mv.visitEnd();
+ }
+
+ /**
+ * Create the setter method for one property.
+ * The name of the method is _set+name of the field
+ * @param name : name of the field representing a property
+ * @param desc : description of the setter method
+ * @param type : type of the property
+ */
+ private void createSimpleSetter(String name, String desc, Type type) {
+ MethodVisitor mv = cv.visitMethod(ACC_PUBLIC, "_set" + name, desc, null, null);
+
+ switch(type.getSort()) {
+ case Type.BOOLEAN :
+ case Type.CHAR :
+ case Type.BYTE :
+ case Type.SHORT :
+ case Type.INT :
+ case Type.FLOAT :
+ case Type.LONG :
+ case Type.DOUBLE :
+
+ String internalName = ManipulationProperty.PRIMITIVE_BOXING_INFORMATION[type.getSort()][0];
+ String boxingType = ManipulationProperty.PRIMITIVE_BOXING_INFORMATION[type.getSort()][1];
+
+ mv.visitVarInsn(ALOAD, 0);
+ mv.visitVarInsn(type.getOpcode(ILOAD), 1);
+ mv.visitFieldInsn(PUTFIELD, m_owner, name, internalName);
+ Label l1 = new Label();
+ mv.visitLabel(l1);
+
+ mv.visitTypeInsn(NEW, boxingType);
+ mv.visitInsn(DUP);
+ mv.visitVarInsn(type.getOpcode(ILOAD), 1);
+ mv.visitMethodInsn(INVOKESPECIAL, boxingType, "<init>", "(" + internalName + ")V");
+ mv.visitVarInsn(ASTORE, 2);
+
+ Label l2 = new Label();
+ mv.visitLabel(l2);
+ mv.visitFieldInsn(GETSTATIC, m_owner, "_cm", "Lorg/apache/felix/ipojo/ComponentManager;");
+ mv.visitLdcInsn(name);
+ mv.visitVarInsn(ALOAD, 2);
+ mv.visitMethodInsn(INVOKEVIRTUAL, "org/apache/felix/ipojo/ComponentManager", "setterCallback", "(Ljava/lang/String;Ljava/lang/Object;)V");
+
+ Label l3 = new Label();
+ mv.visitLabel(l3);
+ mv.visitInsn(RETURN);
+ break;
+ case (Type.OBJECT) :
+
+ mv.visitVarInsn(ALOAD, 0);
+ mv.visitVarInsn(ALOAD, 1);
+ mv.visitFieldInsn(PUTFIELD, m_owner, name, "L" + type.getInternalName() + ";");
+
+ mv.visitFieldInsn(GETSTATIC, m_owner, "_cm", "Lorg/apache/felix/ipojo/ComponentManager;");
+ mv.visitLdcInsn(name);
+ mv.visitVarInsn(ALOAD, 1);
+ mv.visitMethodInsn(INVOKEVIRTUAL, "org/apache/felix/ipojo/ComponentManager", "setterCallback", "(Ljava/lang/String;Ljava/lang/Object;)V");
+
+ mv.visitInsn(RETURN);
+ break;
+ default :
+ IpojoPluginConfiguration.getLogger().log(Level.SEVERE, "Manipulation Error : Cannot create the setter method for the field : " + name + " (" + type + ")");
+ break;
+ }
+
+ mv.visitMaxs(0, 0);
+ mv.visitEnd();
+ }
+
+ /**
+ * @return the interfaces implemented by the component class.
+ */
+ public String[] getInterfaces() {
+ return m_itfs;
+ }
+
+ /**
+ * @return the field hashmap [field_name, type]
+ */
+ public HashMap getFields() {
+ return m_fields;
+ }
+}
+
Propchange: incubator/felix/trunk/org.apache.felix.ipojo.plugin/src/main/java/org/apache/felix/ipojo/manipulation/PreprocessClassAdapter.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/felix/trunk/org.apache.felix.ipojo.plugin/src/main/java/org/apache/felix/ipojo/manipulation/PreprocessCodeAdapter.java
URL: http://svn.apache.org/viewvc/incubator/felix/trunk/org.apache.felix.ipojo.plugin/src/main/java/org/apache/felix/ipojo/manipulation/PreprocessCodeAdapter.java?rev=414287&view=auto
==============================================================================
--- incubator/felix/trunk/org.apache.felix.ipojo.plugin/src/main/java/org/apache/felix/ipojo/manipulation/PreprocessCodeAdapter.java (added)
+++ incubator/felix/trunk/org.apache.felix.ipojo.plugin/src/main/java/org/apache/felix/ipojo/manipulation/PreprocessCodeAdapter.java Wed Jun 14 08:22:03 2006
@@ -0,0 +1,80 @@
+/*
+ * Copyright 2006 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+package org.apache.felix.ipojo.manipulation;
+
+import java.util.logging.Level;
+
+import org.apache.felix.ipojo.plugin.IpojoPluginConfiguration;
+import org.objectweb.asm.MethodAdapter;
+import org.objectweb.asm.MethodVisitor;
+import org.objectweb.asm.Opcodes;
+
+
+/**
+ * Date : 29 janv. 2006
+ * @author clément
+ *
+ */
+public class PreprocessCodeAdapter extends MethodAdapter implements Opcodes {
+
+ /** The owner class of the field.
+ * m_owner : String
+ */
+ private String m_owner;
+
+ /** PropertyCodeAdapter constructor.
+ * A new FiledCodeAdapter should be create for each method visit.
+ * @param mv MethodVisitor
+ * @param owner Name of the class
+ */
+ public PreprocessCodeAdapter(final MethodVisitor mv, final String owner) {
+ super(mv);
+ m_owner = owner;
+ }
+
+
+ /** Visit Method for Filed instance (GETFIELD).
+ * @see org.objectweb.asm.MethodVisitor#visitFieldInsn(int, String, String, String)
+ * @param opcode : visited operation code
+ * @param owner : owner of the field
+ * @param name : name of the field
+ * @param desc : decriptor of the field
+ */
+ public void visitFieldInsn(
+ final int opcode,
+ final String owner,
+ final String name,
+ final String desc) {
+ if (owner.equals(m_owner)) {
+ if (opcode == GETFIELD) {
+ IpojoPluginConfiguration.getLogger().log(Level.INFO, "Manipulate a GETFIELD on : " + name);
+ String gDesc = "()" + desc;
+ visitMethodInsn(INVOKEVIRTUAL, owner, "_get" + name, gDesc);
+ return;
+ } else
+ if (opcode == PUTFIELD) {
+ // replaces PUTFIELD f by INVOKESPECIAL _setf
+ IpojoPluginConfiguration.getLogger().log(Level.INFO, "Manipulate a PUTFIELD on : " + name);
+ String sDesc = "(" + desc + ")V";
+ visitMethodInsn(INVOKESPECIAL, owner, "_set" + name, sDesc);
+ return;
+ }
+ }
+ super.visitFieldInsn(opcode, owner, name, desc);
+ }
+}
+
Propchange: incubator/felix/trunk/org.apache.felix.ipojo.plugin/src/main/java/org/apache/felix/ipojo/manipulation/PreprocessCodeAdapter.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/felix/trunk/org.apache.felix.ipojo.plugin/src/main/java/org/apache/felix/ipojo/parser/ManifestMetadataParser.java
URL: http://svn.apache.org/viewvc/incubator/felix/trunk/org.apache.felix.ipojo.plugin/src/main/java/org/apache/felix/ipojo/parser/ManifestMetadataParser.java?rev=414287&view=auto
==============================================================================
--- incubator/felix/trunk/org.apache.felix.ipojo.plugin/src/main/java/org/apache/felix/ipojo/parser/ManifestMetadataParser.java (added)
+++ incubator/felix/trunk/org.apache.felix.ipojo.plugin/src/main/java/org/apache/felix/ipojo/parser/ManifestMetadataParser.java Wed Jun 14 08:22:03 2006
@@ -0,0 +1,181 @@
+/*
+ * Copyright 2006 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+package org.apache.felix.ipojo.parser;
+
+import java.util.Dictionary;
+import java.util.logging.Level;
+
+import org.apache.felix.ipojo.metadata.Attribute;
+import org.apache.felix.ipojo.metadata.Element;
+import org.apache.felix.ipojo.plugin.IpojoPluginConfiguration;
+
+/**
+ * Manifest Metadata parser.
+ * Read a manifest file and construct metadata
+ * @author Clement Escoffier
+ */
+public class ManifestMetadataParser {
+
+ /**
+ * Manifest Headers.
+ */
+ private Dictionary m_headers;
+
+ /**
+ * Element list.
+ */
+ private Element[] m_elements = new Element[0];
+
+ /**
+ * @return the component metadata.
+ * @throws ParseException when a parsing error occurs
+ */
+ public Element[] getComponentsMetadata() throws ParseException {
+ return m_elements[0].getElements("Component");
+ }
+
+ private void addElement(Element elem) {
+ for (int i = 0; (m_elements != null) && (i < m_elements.length); i++) {
+ if (m_elements[i] == elem) { return; }
+ }
+
+ if (m_elements != null) {
+ Element[] newElementsList = new Element[m_elements.length + 1];
+ System.arraycopy(m_elements, 0, newElementsList, 0, m_elements.length);
+ newElementsList[m_elements.length] = elem;
+ m_elements = newElementsList;
+ }
+ else { m_elements = new Element[] {elem}; }
+ }
+
+ private Element removeLastElement() {
+ int idx = -1;
+ idx = m_elements.length - 1;
+ Element last = m_elements[idx];
+ if (idx >= 0) {
+ if ((m_elements.length - 1) == 0) {
+ // It is the last element of the list;
+ m_elements = new Element[0];
+ }
+ else {
+ // Remove the last element of the list :
+ Element[] newElementsList = new Element[m_elements.length - 1];
+ System.arraycopy(m_elements, 0, newElementsList, 0, idx);
+ m_elements = newElementsList;
+ }
+ }
+ return last;
+ }
+
+ /**
+ * Parse the given dictionnary and create the components manager.
+ * @param dict : the given headers of the manifest file
+ * @throws ParseException : if any error occurs
+ */
+ public void parse(Dictionary dict) throws ParseException {
+ m_headers = dict;
+ String componentClassesStr = (String)m_headers.get("iPOJO-Components");
+ System.out.println("Parse : " + componentClassesStr);
+ parseElements(componentClassesStr.trim());
+
+ }
+
+ /**
+ * PArse the metadata from the string given in argument.
+ * @param metadata : the metadata
+ * @throws ParseException when a parse error occurs
+ */
+ public void parse(String metadata) throws ParseException {
+ parseElements(metadata);
+ }
+
+ private void parseElements(String s) {
+ //Add the ipojo element inside the element list
+ addElement(new Element("iPOJO", ""));
+ char[] string = s.toCharArray();
+
+ for (int i = 0; i < string.length; i++) {
+ char c = string[i];
+ System.out.println("Analyse : " + c);
+ switch(c) {
+
+ case '$' :
+ String attName = "";
+ String attValue = "";
+ String attNs = "";
+ i++;
+ c = string[i];
+ while (c != '=') {
+ if(c == ':') {
+ attNs = attName;
+ attName= "";
+ } else { attName = attName + c; }
+ i = i + 1;
+ c = string[i];
+ }
+ i++; // skip =
+ c = string[i];
+ while (c != ' ') {
+ attValue = attValue + c;
+ i++;
+ c = string[i];
+ }
+ Attribute att = new Attribute(attName, attNs ,attValue);
+ IpojoPluginConfiguration.getLogger().log(Level.INFO, "Detect a new attribute : '" + "[" + attNs + "]" + attName + "' = '" + attValue + "'");
+ m_elements[m_elements.length - 1].addAttribute(att);
+ break;
+
+ case '}' :
+ Element lastElement = removeLastElement();
+ IpojoPluginConfiguration.getLogger().log(Level.INFO, "End of the element : " + lastElement.getName());
+ if (m_elements.length != 0) {
+ Element newQueue = m_elements[m_elements.length - 1];
+ newQueue.addElement(lastElement);
+ }
+ else {
+ addElement(lastElement);
+ }
+ break;
+ case ' ' : break; // do nothing;
+ default :
+ String name = "";
+ String ns = "";
+ c = string[i];
+ while (c != ' ') {
+ if(c == ':') {
+ ns = name;
+ name = "";
+ i++;
+ }
+ else {
+ name = name + c;
+ i++;
+ c = string[i];
+ }
+ }
+ // Skip spaces
+ while (string[i] == ' ') { i = i + 1; }
+ i = i + 1; // skip {
+ Element elem = new Element(name, ns);
+ addElement(elem);
+ IpojoPluginConfiguration.getLogger().log(Level.INFO, "Start an new element : " + name);
+ break;
+ }
+ }
+ }
+
+}
Propchange: incubator/felix/trunk/org.apache.felix.ipojo.plugin/src/main/java/org/apache/felix/ipojo/parser/ManifestMetadataParser.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/felix/trunk/org.apache.felix.ipojo.plugin/src/main/java/org/apache/felix/ipojo/parser/ParseException.java
URL: http://svn.apache.org/viewvc/incubator/felix/trunk/org.apache.felix.ipojo.plugin/src/main/java/org/apache/felix/ipojo/parser/ParseException.java?rev=414287&view=auto
==============================================================================
--- incubator/felix/trunk/org.apache.felix.ipojo.plugin/src/main/java/org/apache/felix/ipojo/parser/ParseException.java (added)
+++ incubator/felix/trunk/org.apache.felix.ipojo.plugin/src/main/java/org/apache/felix/ipojo/parser/ParseException.java Wed Jun 14 08:22:03 2006
@@ -0,0 +1,38 @@
+/*
+ * Copyright 2006 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+package org.apache.felix.ipojo.parser;
+
+/**
+ * Exceptions thrown by parsers.
+ * @author Clement Escoffier
+ */
+public class ParseException extends Exception {
+
+ /**
+ * serialVersionUID.
+ */
+ private static final long serialVersionUID = 1L;
+
+ /**
+ * Parsing error.
+ * @param msg : the error emssage.
+ */
+ public ParseException(String msg) {
+ super(msg);
+ }
+
+}
Propchange: incubator/felix/trunk/org.apache.felix.ipojo.plugin/src/main/java/org/apache/felix/ipojo/parser/ParseException.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/felix/trunk/org.apache.felix.ipojo.plugin/src/main/java/org/apache/felix/ipojo/parser/XMLMetadataParser.java
URL: http://svn.apache.org/viewvc/incubator/felix/trunk/org.apache.felix.ipojo.plugin/src/main/java/org/apache/felix/ipojo/parser/XMLMetadataParser.java?rev=414287&view=auto
==============================================================================
--- incubator/felix/trunk/org.apache.felix.ipojo.plugin/src/main/java/org/apache/felix/ipojo/parser/XMLMetadataParser.java (added)
+++ incubator/felix/trunk/org.apache.felix.ipojo.plugin/src/main/java/org/apache/felix/ipojo/parser/XMLMetadataParser.java Wed Jun 14 08:22:03 2006
@@ -0,0 +1,193 @@
+/**
+ *
+ */
+package org.apache.felix.ipojo.parser;
+
+import java.util.logging.Level;
+
+import org.apache.felix.ipojo.metadata.Attribute;
+import org.apache.felix.ipojo.metadata.Element;
+import org.apache.felix.ipojo.plugin.IpojoPluginConfiguration;
+import org.xml.sax.Attributes;
+import org.xml.sax.ContentHandler;
+import org.xml.sax.Locator;
+import org.xml.sax.SAXException;
+
+/**
+ * @author escoffie
+ *
+ */
+public class XMLMetadataParser implements ContentHandler {
+
+
+ /**
+ * Element of the metadata.
+ */
+ private Element[] m_elements = new Element[0];
+
+ /**
+ * @return a components metadata
+ * @throws ParseException when an error occurs in the xml parsing
+ */
+ public Element[] getComponentsMetadata() throws ParseException {
+ return m_elements[0].getElements("Component");
+ }
+
+
+
+ /* (non-Javadoc)
+ * @see org.xml.sax.ContentHandler#characters(char[], int, int)
+ */
+ public void characters(char[] ch, int start, int length)
+ throws SAXException {
+ // NOTHING TO DO
+
+ }
+
+ /* (non-Javadoc)
+ * @see org.xml.sax.ContentHandler#endDocument()
+ */
+ public void endDocument() throws SAXException {
+ IpojoPluginConfiguration.getLogger().log(Level.INFO, "End of the XML parsing, " + m_elements.length + " primary elements found");
+
+ }
+
+ /* (non-Javadoc)
+ * @see org.xml.sax.ContentHandler#endElement(java.lang.String, java.lang.String, java.lang.String)
+ */
+ public void endElement(String namespaceURI, String localName, String qName)
+ throws SAXException {
+ // Get the last element of the list
+ Element lastElement = removeLastElement();
+
+ // Check if the name is consitent with the name of this end tag
+ if (!lastElement.getName().equalsIgnoreCase(qName) && !lastElement.getNameSpace().equals(namespaceURI)) {
+ IpojoPluginConfiguration.getLogger().log(Level.SEVERE, "Parse error when ending an element : " + qName + " [" + namespaceURI + "]");
+ throw new SAXException("Parse error when ending an element : " + qName + " [" + namespaceURI + "]");
+ }
+
+ // The name is consitent
+ // Add this element last element with if it is not the root
+ if (m_elements.length != 0) {
+ Element newQueue = m_elements[m_elements.length - 1];
+ newQueue.addElement(lastElement);
+ }
+ else {
+ // It is the last element
+ addElement(lastElement);
+ }
+
+ }
+
+ /* (non-Javadoc)
+ * @see org.xml.sax.ContentHandler#endPrefixMapping(java.lang.String)
+ */
+ public void endPrefixMapping(String prefix) throws SAXException {
+ //NOTHING TO DO
+
+ }
+
+ /* (non-Javadoc)
+ * @see org.xml.sax.ContentHandler#ignorableWhitespace(char[], int, int)
+ */
+ public void ignorableWhitespace(char[] ch, int start, int length)
+ throws SAXException {
+ // NOTHING TO DO
+ }
+
+ /* (non-Javadoc)
+ * @see org.xml.sax.ContentHandler#processingInstruction(java.lang.String, java.lang.String)
+ */
+ public void processingInstruction(String target, String data)
+ throws SAXException {
+ // DO NOTHING
+ }
+
+ /* (non-Javadoc)
+ * @see org.xml.sax.ContentHandler#setDocumentLocator(org.xml.sax.Locator)
+ */
+ public void setDocumentLocator(Locator locator) {
+ // NOTHING TO DO
+
+ }
+
+ /* (non-Javadoc)
+ * @see org.xml.sax.ContentHandler#skippedEntity(java.lang.String)
+ */
+ public void skippedEntity(String name) throws SAXException {
+ // NOTHING TO DO
+
+ }
+
+ /* (non-Javadoc)
+ * @see org.xml.sax.ContentHandler#startDocument()
+ */
+ public void startDocument() throws SAXException {
+ IpojoPluginConfiguration.getLogger().log(Level.INFO, "Start of the XML parsing");
+
+ }
+
+ /* (non-Javadoc)
+ * @see org.xml.sax.ContentHandler#startElement(java.lang.String, java.lang.String, java.lang.String, org.xml.sax.Attributes)
+ */
+ public void startElement(String namespaceURI, String localName,
+ String qName, Attributes atts) throws SAXException {
+ IpojoPluginConfiguration.getLogger().log(Level.INFO, "An XML tag was openend : " + localName + " [" + namespaceURI + "]");
+
+ Element elem = new Element(localName, namespaceURI);
+
+ for (int i = 0; i < atts.getLength(); i++) {
+ String name = (String)atts.getLocalName(i);
+ String ns = (String) atts.getURI(i);
+ String value = (String)atts.getValue(i);
+ Attribute att = new Attribute(name, ns, value);
+ elem.addAttribute(att);
+ }
+
+ addElement(elem);
+
+ }
+
+ /* (non-Javadoc)
+ * @see org.xml.sax.ContentHandler#startPrefixMapping(java.lang.String, java.lang.String)
+ */
+ public void startPrefixMapping(String prefix, String uri)
+ throws SAXException {
+ // NOTHING TO DO
+
+ }
+
+ private void addElement(Element elem) {
+ for (int i = 0; (m_elements != null) && (i < m_elements.length); i++) {
+ if (m_elements[i] == elem) { return; }
+ }
+
+ if (m_elements != null) {
+ Element[] newElementsList = new Element[m_elements.length + 1];
+ System.arraycopy(m_elements, 0, newElementsList, 0, m_elements.length);
+ newElementsList[m_elements.length] = elem;
+ m_elements = newElementsList;
+ }
+ else { m_elements = new Element[] {elem}; }
+ }
+
+ private Element removeLastElement() {
+ int idx = -1;
+ idx = m_elements.length - 1;
+ Element last = m_elements[idx];
+ if (idx >= 0) {
+ if ((m_elements.length - 1) == 0) {
+ // It is the last element of the list;
+ m_elements = new Element[0];
+ }
+ else {
+ // Remove the last element of the list :
+ Element[] newElementsList = new Element[m_elements.length - 1];
+ System.arraycopy(m_elements, 0, newElementsList, 0, idx);
+ m_elements = newElementsList;
+ }
+ }
+ return last;
+ }
+
+}
Propchange: incubator/felix/trunk/org.apache.felix.ipojo.plugin/src/main/java/org/apache/felix/ipojo/parser/XMLMetadataParser.java
------------------------------------------------------------------------------
svn:eol-style = native