felix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From clem...@apache.org
Subject svn commit: r565749 [1/2] - in /felix/trunk/ipojo: annotations/ annotations/src/ annotations/src/main/ annotations/src/main/java/ annotations/src/main/java/org/ annotations/src/main/java/org/apache/ annotations/src/main/java/org/apache/felix/ annotatio...
Date Tue, 14 Aug 2007 13:44:34 GMT
Author: clement
Date: Tue Aug 14 06:44:32 2007
New Revision: 565749

URL: http://svn.apache.org/viewvc?view=rev&rev=565749
Log:
Add annotation support in iPOJO. It is now possible to define component-type with Java 5 annotations.
(however, only the annotations project requires Java 5)

Added:
    felix/trunk/ipojo/annotations/   (with props)
    felix/trunk/ipojo/annotations/pom.xml
    felix/trunk/ipojo/annotations/src/
    felix/trunk/ipojo/annotations/src/main/
    felix/trunk/ipojo/annotations/src/main/java/
    felix/trunk/ipojo/annotations/src/main/java/org/
    felix/trunk/ipojo/annotations/src/main/java/org/apache/
    felix/trunk/ipojo/annotations/src/main/java/org/apache/felix/
    felix/trunk/ipojo/annotations/src/main/java/org/apache/felix/ipojo/
    felix/trunk/ipojo/annotations/src/main/java/org/apache/felix/ipojo/annotations/
    felix/trunk/ipojo/annotations/src/main/java/org/apache/felix/ipojo/annotations/Attribute.java
    felix/trunk/ipojo/annotations/src/main/java/org/apache/felix/ipojo/annotations/Bind.java
    felix/trunk/ipojo/annotations/src/main/java/org/apache/felix/ipojo/annotations/Component.java
    felix/trunk/ipojo/annotations/src/main/java/org/apache/felix/ipojo/annotations/Element.java
    felix/trunk/ipojo/annotations/src/main/java/org/apache/felix/ipojo/annotations/Invalidate.java
    felix/trunk/ipojo/annotations/src/main/java/org/apache/felix/ipojo/annotations/Property.java
    felix/trunk/ipojo/annotations/src/main/java/org/apache/felix/ipojo/annotations/Provides.java
    felix/trunk/ipojo/annotations/src/main/java/org/apache/felix/ipojo/annotations/Requires.java
    felix/trunk/ipojo/annotations/src/main/java/org/apache/felix/ipojo/annotations/ServiceProperty.java
    felix/trunk/ipojo/annotations/src/main/java/org/apache/felix/ipojo/annotations/SubElement.java
    felix/trunk/ipojo/annotations/src/main/java/org/apache/felix/ipojo/annotations/Unbind.java
    felix/trunk/ipojo/annotations/src/main/java/org/apache/felix/ipojo/annotations/Validate.java
    felix/trunk/ipojo/manipulator/src/main/java/org/apache/felix/ipojo/manipulation/annotations/
    felix/trunk/ipojo/manipulator/src/main/java/org/apache/felix/ipojo/manipulation/annotations/FieldCollector.java
    felix/trunk/ipojo/manipulator/src/main/java/org/apache/felix/ipojo/manipulation/annotations/MetadataCollector.java
    felix/trunk/ipojo/manipulator/src/main/java/org/apache/felix/ipojo/manipulation/annotations/MethodCollector.java
Modified:
    felix/trunk/ipojo/manipulator/pom.xml
    felix/trunk/ipojo/manipulator/src/main/java/org/apache/felix/ipojo/manipulation/ClassChecker.java
    felix/trunk/ipojo/manipulator/src/main/java/org/apache/felix/ipojo/manipulation/PojoAdapter.java
    felix/trunk/ipojo/manipulator/src/main/java/org/apache/felix/ipojo/manipulator/Pojoization.java
    felix/trunk/ipojo/manipulator/src/main/java/org/apache/felix/ipojo/xml/parser/XMLMetadataParser.java
    felix/trunk/ipojo/metadata/pom.xml
    felix/trunk/ipojo/plugin/pom.xml
    felix/trunk/ipojo/plugin/src/main/java/org/apache/felix/ipojo/plugin/ManipulatorMojo.java

Propchange: felix/trunk/ipojo/annotations/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Tue Aug 14 06:44:32 2007
@@ -0,0 +1,6 @@
+target
+bin
+.settings
+.checkstyle
+.classpath
+.project

Added: felix/trunk/ipojo/annotations/pom.xml
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/annotations/pom.xml?view=auto&rev=565749
==============================================================================
--- felix/trunk/ipojo/annotations/pom.xml (added)
+++ felix/trunk/ipojo/annotations/pom.xml Tue Aug 14 06:44:32 2007
@@ -0,0 +1,40 @@
+<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.1.0-SNAPSHOT</version>
+    <relativePath>../../pom/pom.xml</relativePath>
+  </parent>
+  <modelVersion>4.0.0</modelVersion>
+  <artifactId>org.apache.felix.ipojo.annotations</artifactId>
+  <packaging>bundle</packaging>
+  <version>0.7.3-SNAPSHOT</version>
+  <name>iPOJO Annotations</name>
+  <build>
+  <plugins>
+  <plugin>
+		<groupId>org.apache.maven.plugins</groupId>
+		<artifactId>maven-compiler-plugin</artifactId>
+		<configuration>
+		<source>1.5</source>
+		<target>1.5</target>
+		</configuration>
+	  </plugin>
+  	<plugin>
+    	<groupId>org.apache.felix</groupId>
+    	<artifactId>maven-bundle-plugin</artifactId>
+    	<version>1.1.0-SNAPSHOT</version>
+    	<extensions>true</extensions>
+    	<configuration>
+        	<instructions>          
+          		<Bundle-Name>iPOJO Annotation</Bundle-Name>
+		        <Bundle-Vendor>Clement ESCOFFIER</Bundle-Vendor>
+        		<Bundle-Description> iPOJO Annotations </Bundle-Description>
+          		<Export-Package>org.apache.felix.ipojo.annotations</Export-Package>
+        	</instructions>
+    	</configuration>
+  	</plugin>
+  </plugins>
+  </build>
+</project>
\ No newline at end of file

Added: felix/trunk/ipojo/annotations/src/main/java/org/apache/felix/ipojo/annotations/Attribute.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/annotations/src/main/java/org/apache/felix/ipojo/annotations/Attribute.java?view=auto&rev=565749
==============================================================================
--- felix/trunk/ipojo/annotations/src/main/java/org/apache/felix/ipojo/annotations/Attribute.java (added)
+++ felix/trunk/ipojo/annotations/src/main/java/org/apache/felix/ipojo/annotations/Attribute.java Tue Aug 14 06:44:32 2007
@@ -0,0 +1,38 @@
+/* 
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.felix.ipojo.annotations;
+
+/**
+* This annotation declares an attribute.
+* This annotation must only be used in the attributes array of the Element annotation.
+* @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
+*/
+public @interface Attribute {
+    
+    /**
+     * Set attribute name.
+     */
+    String name();
+    
+    /**
+     * Set attribute value.
+     */
+    String value();
+
+}

Added: felix/trunk/ipojo/annotations/src/main/java/org/apache/felix/ipojo/annotations/Bind.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/annotations/src/main/java/org/apache/felix/ipojo/annotations/Bind.java?view=auto&rev=565749
==============================================================================
--- felix/trunk/ipojo/annotations/src/main/java/org/apache/felix/ipojo/annotations/Bind.java (added)
+++ felix/trunk/ipojo/annotations/src/main/java/org/apache/felix/ipojo/annotations/Bind.java Tue Aug 14 06:44:32 2007
@@ -0,0 +1,61 @@
+/* 
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.felix.ipojo.annotations;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Target;
+
+/**
+ * This annotation declares a bind method.
+ * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
+ */
+@Target(ElementType.METHOD)
+public @interface Bind {
+    
+    /**
+     * Set the dependency filter.
+     * Default : no filter
+     */
+    String filter() default "";
+    
+    /**
+     * Set if the dependency is an aggregate dependency.
+     * Default : false
+     */
+    boolean aggregate() default false;
+    
+    /**
+     * Set if the dependency is optional.
+     * Default : false
+     */
+    boolean optional() default false;
+    
+    /**
+     * Set the required specification.
+     * Default : empty (try to discover)
+     */
+    String specification() default "";
+    
+    /**
+     * Set the dependency id.
+     * Default : empty
+     */
+    String id() default "";
+
+}

Added: felix/trunk/ipojo/annotations/src/main/java/org/apache/felix/ipojo/annotations/Component.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/annotations/src/main/java/org/apache/felix/ipojo/annotations/Component.java?view=auto&rev=565749
==============================================================================
--- felix/trunk/ipojo/annotations/src/main/java/org/apache/felix/ipojo/annotations/Component.java (added)
+++ felix/trunk/ipojo/annotations/src/main/java/org/apache/felix/ipojo/annotations/Component.java Tue Aug 14 06:44:32 2007
@@ -0,0 +1,61 @@
+/* 
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.felix.ipojo.annotations;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Target;
+
+/**
+ * This annotation declares a component.
+ * This annotation is mandatory to declares an iPOJO component.
+ * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
+ */
+@Target(ElementType.TYPE)
+public @interface Component {
+    
+    /**
+     * Set if the component type is public.
+     * Default: false
+     */
+    boolean factory() default false;
+    
+    /**
+     * Set the component type name.
+     * Default : implementation class name.
+     */
+    String name() default "";
+    
+    /**
+     * Enable / Disable the architecture exposition.
+     * Default : false
+     */
+    boolean architecture() default false;
+    
+    /**
+     * Set if the component is immediate.
+     * Default : false
+     */
+    boolean immediate() default false;
+    
+    /**
+     * Set if the component must propagate received configuration to provided services.
+     * default: false
+     */
+    boolean propagation() default false;
+}

Added: felix/trunk/ipojo/annotations/src/main/java/org/apache/felix/ipojo/annotations/Element.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/annotations/src/main/java/org/apache/felix/ipojo/annotations/Element.java?view=auto&rev=565749
==============================================================================
--- felix/trunk/ipojo/annotations/src/main/java/org/apache/felix/ipojo/annotations/Element.java (added)
+++ felix/trunk/ipojo/annotations/src/main/java/org/apache/felix/ipojo/annotations/Element.java Tue Aug 14 06:44:32 2007
@@ -0,0 +1,54 @@
+/* 
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.felix.ipojo.annotations;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Target;
+
+/**
+* This annotation declares a generic element.
+* @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
+*/
+@Target(ElementType.TYPE)
+public @interface Element {
+    
+    /**
+     * Set element name.
+     */
+    String name();
+    
+    /**
+     * Set the element namespace.
+     * Default : no namespace.
+     */
+    String namespace() default "";
+    
+    /**
+     * Set element attributes (@Attribute).
+     * Default : no attributes.
+     */
+    Attribute[] attributes() default { };
+    
+    /**
+     * Set element sub-elements (@SubElement).
+     * Default : no sub-element.
+     */
+    SubElement[] elements() default { };
+
+}

Added: felix/trunk/ipojo/annotations/src/main/java/org/apache/felix/ipojo/annotations/Invalidate.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/annotations/src/main/java/org/apache/felix/ipojo/annotations/Invalidate.java?view=auto&rev=565749
==============================================================================
--- felix/trunk/ipojo/annotations/src/main/java/org/apache/felix/ipojo/annotations/Invalidate.java (added)
+++ felix/trunk/ipojo/annotations/src/main/java/org/apache/felix/ipojo/annotations/Invalidate.java Tue Aug 14 06:44:32 2007
@@ -0,0 +1,31 @@
+/* 
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.felix.ipojo.annotations;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Target;
+
+/**
+ * This annotation declares an invalidate callback.
+ * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
+ */
+@Target(ElementType.METHOD)
+public @interface Invalidate {
+
+}

Added: felix/trunk/ipojo/annotations/src/main/java/org/apache/felix/ipojo/annotations/Property.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/annotations/src/main/java/org/apache/felix/ipojo/annotations/Property.java?view=auto&rev=565749
==============================================================================
--- felix/trunk/ipojo/annotations/src/main/java/org/apache/felix/ipojo/annotations/Property.java (added)
+++ felix/trunk/ipojo/annotations/src/main/java/org/apache/felix/ipojo/annotations/Property.java Tue Aug 14 06:44:32 2007
@@ -0,0 +1,43 @@
+/* 
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.felix.ipojo.annotations;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Target;
+
+/**
+ * This annotation declares a component property.
+ * It can target both fields and methods.
+ * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
+ */
+@Target({ ElementType.FIELD, ElementType.METHOD })
+public @interface Property {
+    
+    /**
+     * Set property name.
+     * Default : empty
+     */
+    String name() default "";
+    
+    /**
+     * Set property value.
+     * Default : empty
+     */
+    String value() default "";
+}

Added: felix/trunk/ipojo/annotations/src/main/java/org/apache/felix/ipojo/annotations/Provides.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/annotations/src/main/java/org/apache/felix/ipojo/annotations/Provides.java?view=auto&rev=565749
==============================================================================
--- felix/trunk/ipojo/annotations/src/main/java/org/apache/felix/ipojo/annotations/Provides.java (added)
+++ felix/trunk/ipojo/annotations/src/main/java/org/apache/felix/ipojo/annotations/Provides.java Tue Aug 14 06:44:32 2007
@@ -0,0 +1,43 @@
+/* 
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.felix.ipojo.annotations;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Target;
+
+/**
+* This annotation declares that the component instances will provide a service.
+* @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
+*/
+@Target(ElementType.TYPE)
+public @interface Provides {
+    
+    /**
+     * Set the provided specifications.
+     * Default : all implemented interfaces
+     */
+    String specification() default "";
+    
+    /**
+     * Set the service object creation policy.
+     * Two value are possible: SINGLETON or FACTORY. FACTORY means OSGi Service Factory.
+     * Default : SINGLETON
+     */
+    String factory() default "SINGLETON";
+}

Added: felix/trunk/ipojo/annotations/src/main/java/org/apache/felix/ipojo/annotations/Requires.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/annotations/src/main/java/org/apache/felix/ipojo/annotations/Requires.java?view=auto&rev=565749
==============================================================================
--- felix/trunk/ipojo/annotations/src/main/java/org/apache/felix/ipojo/annotations/Requires.java (added)
+++ felix/trunk/ipojo/annotations/src/main/java/org/apache/felix/ipojo/annotations/Requires.java Tue Aug 14 06:44:32 2007
@@ -0,0 +1,50 @@
+/* 
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.felix.ipojo.annotations;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Target;
+
+/**
+ * This annotation declares a service requirement.
+ * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
+ */
+@Target(ElementType.FIELD)
+public @interface Requires {
+    
+    /**
+     * Set the LDAP filter of the dependency.
+     * Default : no filter
+     */
+    String filter() default "";
+    
+    /**
+     * Set if the dependency is optional.
+     * Default : false
+     */
+    boolean optional() default false;
+    
+    
+    /**
+     * Set the dependency id.
+     * Default : empty
+     */
+    String id() default "";
+
+}

Added: felix/trunk/ipojo/annotations/src/main/java/org/apache/felix/ipojo/annotations/ServiceProperty.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/annotations/src/main/java/org/apache/felix/ipojo/annotations/ServiceProperty.java?view=auto&rev=565749
==============================================================================
--- felix/trunk/ipojo/annotations/src/main/java/org/apache/felix/ipojo/annotations/ServiceProperty.java (added)
+++ felix/trunk/ipojo/annotations/src/main/java/org/apache/felix/ipojo/annotations/ServiceProperty.java Tue Aug 14 06:44:32 2007
@@ -0,0 +1,44 @@
+/* 
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.felix.ipojo.annotations;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Target;
+
+/**
+ * This annotation declares a service property.
+ * It can target both fields and methods.
+ * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
+ */
+@Target({ ElementType.FIELD, ElementType.METHOD })
+public @interface ServiceProperty {
+    
+    /**
+     * Set the property name.
+     * Default : empty
+     */
+    String name() default "";
+    
+    /**
+     * Set the property value.
+     * Default : empty
+     */
+    String value() default "";
+
+}

Added: felix/trunk/ipojo/annotations/src/main/java/org/apache/felix/ipojo/annotations/SubElement.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/annotations/src/main/java/org/apache/felix/ipojo/annotations/SubElement.java?view=auto&rev=565749
==============================================================================
--- felix/trunk/ipojo/annotations/src/main/java/org/apache/felix/ipojo/annotations/SubElement.java (added)
+++ felix/trunk/ipojo/annotations/src/main/java/org/apache/felix/ipojo/annotations/SubElement.java Tue Aug 14 06:44:32 2007
@@ -0,0 +1,45 @@
+/* 
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.felix.ipojo.annotations;
+
+/**
+* This annotation declares a sub-attribute.
+* This annotation must only be used in the elements array of the Element annotation.
+* @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
+*/
+public @interface SubElement {
+    
+    /**
+     * Set the sub-element name.
+     */
+    String name();
+    
+    /**
+     * Set the sub-element namespace.
+     * Default : no namespace.
+     */
+    String namespace() default "";
+    
+    /**
+     * Set the sub-element attributes (@Attribute).
+     * Default : no attributes.
+     */
+    Attribute[] attributes() default { };
+
+}

Added: felix/trunk/ipojo/annotations/src/main/java/org/apache/felix/ipojo/annotations/Unbind.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/annotations/src/main/java/org/apache/felix/ipojo/annotations/Unbind.java?view=auto&rev=565749
==============================================================================
--- felix/trunk/ipojo/annotations/src/main/java/org/apache/felix/ipojo/annotations/Unbind.java (added)
+++ felix/trunk/ipojo/annotations/src/main/java/org/apache/felix/ipojo/annotations/Unbind.java Tue Aug 14 06:44:32 2007
@@ -0,0 +1,62 @@
+/* 
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.felix.ipojo.annotations;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Target;
+
+/**
+ * This annotation declares an unbind method.
+ * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
+ */
+@Target(ElementType.METHOD)
+public @interface Unbind {
+    
+    /**
+     * Set the dependency filter.
+     * Default : no filter
+     */
+    String filter() default "";
+    
+    /**
+     * Set if the dependency is an aggregate dependency.
+     * Default : false
+     */
+    boolean aggregate() default false;
+    
+    
+    /**
+     * Set if the dependency is optional.
+     * Default : false
+     */
+    boolean optional() default false;
+    
+    /**
+     * Set the required specification.
+     * Default : empty (try to discover).
+     */
+    String specification() default "";
+    
+    /**
+     * Set the dependency id.
+     * Default : empty.
+     */
+    String id() default "";
+
+}

Added: felix/trunk/ipojo/annotations/src/main/java/org/apache/felix/ipojo/annotations/Validate.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/annotations/src/main/java/org/apache/felix/ipojo/annotations/Validate.java?view=auto&rev=565749
==============================================================================
--- felix/trunk/ipojo/annotations/src/main/java/org/apache/felix/ipojo/annotations/Validate.java (added)
+++ felix/trunk/ipojo/annotations/src/main/java/org/apache/felix/ipojo/annotations/Validate.java Tue Aug 14 06:44:32 2007
@@ -0,0 +1,31 @@
+/* 
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.felix.ipojo.annotations;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Target;
+
+/**
+ * This annotation declares a validate callback.
+ * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
+ */
+@Target(ElementType.METHOD)
+public @interface Validate {
+
+}

Modified: felix/trunk/ipojo/manipulator/pom.xml
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/manipulator/pom.xml?view=diff&rev=565749&r1=565748&r2=565749
==============================================================================
--- felix/trunk/ipojo/manipulator/pom.xml (original)
+++ felix/trunk/ipojo/manipulator/pom.xml Tue Aug 14 06:44:32 2007
@@ -48,7 +48,8 @@
             <Bundle-Description> iPOJO Manipulator </Bundle-Description>
             <Export-Package>org.apache.felix.ipojo.manipulator</Export-Package>
             <Private-Package>
-            	org.apache.felix.ipojo.manipulation,
+            	org.apache.felix.ipojo.manipulation,
+            	org.apache.felix.ipojo.manipulation.annotations,
             	org.apache.felix.ipojo.xml.parser,
               	org.objectweb.asm,
               	org.objectweb.asm.commons,

Modified: felix/trunk/ipojo/manipulator/src/main/java/org/apache/felix/ipojo/manipulation/ClassChecker.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/manipulator/src/main/java/org/apache/felix/ipojo/manipulation/ClassChecker.java?view=diff&rev=565749&r1=565748&r2=565749
==============================================================================
--- felix/trunk/ipojo/manipulator/src/main/java/org/apache/felix/ipojo/manipulation/ClassChecker.java (original)
+++ felix/trunk/ipojo/manipulator/src/main/java/org/apache/felix/ipojo/manipulation/ClassChecker.java Tue Aug 14 06:44:32 2007
@@ -23,20 +23,19 @@
 import java.util.List;
 import java.util.Map;
 
-import org.objectweb.asm.AnnotationVisitor;
-import org.objectweb.asm.Attribute;
 import org.objectweb.asm.ClassVisitor;
 import org.objectweb.asm.FieldVisitor;
 import org.objectweb.asm.MethodVisitor;
 import org.objectweb.asm.Opcodes;
 import org.objectweb.asm.Type;
+import org.objectweb.asm.commons.EmptyVisitor;
 
 /**
  * Check that a POJO is already manipulated or not.
  * Moreover it allows to get manipulation data about this class. 
  * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
  */
-public class ClassChecker implements ClassVisitor, Opcodes {
+public class ClassChecker extends EmptyVisitor implements ClassVisitor, Opcodes {
 
     /**
      * True if the class is already manipulated.
@@ -121,56 +120,6 @@
     }
 
     /**
-     * Visit sources.
-     * Do nothing
-     * @param source : the name of the source file from which the class was compiled. May be null.
-       @param debug : additional debug information to compute the relationship between source and compiled elements of the class. May be null.
-     * @see org.objectweb.asm.ClassVisitor#visitSource(java.lang.String, java.lang.String)
-     */
-    public void visitSource(String source, String debug) { }
-
-    /**
-     * Visit an outer class.
-     * @param owner - internal name of the enclosing class of the class.
-     * @param name - the name of the method that contains the class, or null if the class is not enclosed in a method of its enclosing class.
-     * @param desc - the descriptor of the method that contains the class, or null if the class is not enclosed in a method of its enclosing class.
-     * @see org.objectweb.asm.ClassVisitor#visitOuterClass(java.lang.String, java.lang.String, java.lang.String)
-     */
-    public void visitOuterClass(String owner, String name, String desc) {
-    }
-
-    /**
-     * Visit an annotation.
-     * Do nothing.
-     * @param desc - the class descriptor of the annotation class.
-     * @param visible - true if the annotation is visible at runtime.
-     * @return null.
-     * @see org.objectweb.asm.ClassVisitor#visitAnnotation(java.lang.String, boolean)
-     */
-    public AnnotationVisitor visitAnnotation(String desc, boolean visible) {
-        return null;
-    }
-
-    /**
-     * Visit a non standard attribute of the class.
-     * @param attr - an attribute.
-     * @see org.objectweb.asm.ClassVisitor#visitAttribute(org.objectweb.asm.Attribute)
-     */
-    public void visitAttribute(Attribute attr) {
-    }
-
-    /**
-     * Visit an inner class.
-     * @param name - the internal name of an inner class (see getInternalName).
-     * @param outerName - the internal name of the class to which the inner class belongs (see getInternalName). May be null for not member classes.
-     * @param innerName - the (simple) name of the inner class inside its enclosing class. May be null for anonymous inner classes.
-     * @param access - the access flags of the inner class as originally declared in the enclosing class.
-     * @see org.objectweb.asm.ClassVisitor#visitInnerClass(java.lang.String,
-     *      java.lang.String, java.lang.String, int)
-     */
-    public void visitInnerClass(String name, String outerName, String innerName, int access) { }
-
-    /**
      * Visit a method.
      * Update the method list (except if it init or clinit.
      * @param  access - the method's access flags (see Opcodes). This parameter also indicates if the method is synthetic and/or deprecated.
@@ -188,13 +137,7 @@
         }
         return null;
     }
-
-    /**
-     * End of the class visit.
-     * @see org.objectweb.asm.ClassVisitor#visitEnd()
-     */
-    public void visitEnd() { }
-
+    
     /**
      * Get collected interfaces.
      * @return the interfaces implemented by the component class.

Modified: felix/trunk/ipojo/manipulator/src/main/java/org/apache/felix/ipojo/manipulation/PojoAdapter.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/manipulator/src/main/java/org/apache/felix/ipojo/manipulation/PojoAdapter.java?view=diff&rev=565749&r1=565748&r2=565749
==============================================================================
--- felix/trunk/ipojo/manipulator/src/main/java/org/apache/felix/ipojo/manipulation/PojoAdapter.java (original)
+++ felix/trunk/ipojo/manipulator/src/main/java/org/apache/felix/ipojo/manipulation/PojoAdapter.java Tue Aug 14 06:44:32 2007
@@ -129,7 +129,7 @@
     /**
      * Visit a field.
      * Call the adapter generating getter and setter methods.
-     * @param access : field acess.
+     * @param access : field access.
      * @param name : field name
      * @param desc : field descriptor
      * @param signature : field signature

Added: felix/trunk/ipojo/manipulator/src/main/java/org/apache/felix/ipojo/manipulation/annotations/FieldCollector.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/manipulator/src/main/java/org/apache/felix/ipojo/manipulation/annotations/FieldCollector.java?view=auto&rev=565749
==============================================================================
--- felix/trunk/ipojo/manipulator/src/main/java/org/apache/felix/ipojo/manipulation/annotations/FieldCollector.java (added)
+++ felix/trunk/ipojo/manipulator/src/main/java/org/apache/felix/ipojo/manipulation/annotations/FieldCollector.java Tue Aug 14 06:44:32 2007
@@ -0,0 +1,279 @@
+/* 
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.felix.ipojo.manipulation.annotations;
+
+import org.apache.felix.ipojo.metadata.Attribute;
+import org.apache.felix.ipojo.metadata.Element;
+import org.objectweb.asm.AnnotationVisitor;
+import org.objectweb.asm.FieldVisitor;
+import org.objectweb.asm.commons.EmptyVisitor;
+
+/**
+ * Collect field annotations. 
+ * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
+ */
+public class FieldCollector extends EmptyVisitor implements FieldVisitor {
+    
+    /**
+     * Collected element.
+     */
+    private Element m_element;
+    
+    /**
+     * Field name. 
+     */
+    private String m_field;
+    
+    /**
+     * Constructor.
+     * @param fieldName : field name
+     * @param elem : element on which append the collected metadata.
+     */
+    public FieldCollector(String fieldName, Element elem) {
+        m_element = elem;
+        m_field = fieldName;
+    }
+
+    /**
+     * Visit annotations on the current field.
+     * @param arg0 : annotation name
+     * @param arg1 : is the annotation a runtime annotation.
+     * @return the annotation visitor visiting the annotation
+     * @see org.objectweb.asm.FieldVisitor#visitAnnotation(java.lang.String, boolean)
+     */
+    public AnnotationVisitor visitAnnotation(String arg0, boolean arg1) {
+        if (arg0.equals("Lorg/apache/felix/ipojo/annotations/Requires;")) {
+            return new RequiresAnnotationParser(m_field);
+        }
+        if (arg0.equals("Lorg/apache/felix/ipojo/annotations/ServiceProperty;")) {
+            if (m_element.getElements("Provides", "").length == 0) {
+                System.err.println("The component does not provide services, skip ServiceProperty for " + m_field);
+                return null;
+            }
+            Element provides = m_element.getElements("Provides", "")[0];
+            return new PropertyAnnotationParser(provides, m_field);
+        }
+        if (arg0.equals("Lorg/apache/felix/ipojo/annotations/Property;")) {
+            Element parent = null;
+            if (m_element.getElements("Properties", "").length == 0) {
+                parent = new Element("Properties", "");
+                m_element.addElement(parent);
+            }
+            parent = m_element.getElements("Properties", "")[0];
+            return new PropertyAnnotationParser(parent, m_field);
+        }
+        return null;
+       
+    }
+    
+    /**
+     * AnnotationVisitor parsing the @requires annotation.
+     */
+    private final class RequiresAnnotationParser extends EmptyVisitor implements AnnotationVisitor {
+        
+        /**
+         * Dependency field.
+         */
+        private String m_field;
+        
+        /**
+         * Dependency filter.
+         */
+        private String m_filter;
+        
+        /**
+         * Is the dependency optional ?
+         */
+        private String m_optional;
+        
+        /**
+         * Is the dependency aggregate ?
+         */
+        private String m_aggregate;
+        
+        /**
+         * Dependency specification.
+         */
+        private String m_specification;
+        
+        /**
+         * Dependency id.
+         */
+        private String m_id;
+        
+        /**
+         * Constructor.
+         * @param name : field name.
+         */
+        private RequiresAnnotationParser(String name) {
+            m_field = name;
+        }
+
+        /**
+         * Visit one "simple" annotation.
+         * @param arg0 : annotation name
+         * @param arg1 : annotation value
+         * @see org.objectweb.asm.AnnotationVisitor#visit(java.lang.String, java.lang.Object)
+         */
+        public void visit(String arg0, Object arg1) {
+            if (arg0.equals("filter")) {
+                m_filter = arg1.toString();
+                return;
+            }
+            if (arg0.equals("optional")) {
+                m_optional = arg1.toString();
+                return;
+            }
+            if (arg0.equals("specification")) {
+                m_specification = arg1.toString();
+                return;
+            }
+            if (arg0.equals("id")) {
+                m_id = arg1.toString();
+                return;
+            }
+        }
+
+        /**
+         * End of the annotation.
+         * Create a "requires" element
+         * @see org.objectweb.asm.AnnotationVisitor#visitEnd()
+         */
+        public void visitEnd() { 
+         // Check if it is a full-determined requirement
+            Element req = null;
+            Element[] reqs = m_element.getElements("requires");
+            for (int i = 0; i < reqs.length; i++) {
+                if (reqs[i].containsAttribute("id") && (reqs[i].getAttribute("id").equals(m_id) || reqs[i].getAttribute("id").equals(m_field))) {
+                    req = reqs[i];
+                    break;
+                }
+            }
+            if (req == null) {
+                // Add the complete requires
+                req = new Element("requires", "");
+            }
+            req.addAttribute(new Attribute("field", m_field));
+            if (m_specification != null) {
+                req.addAttribute(new Attribute("interface", m_specification));
+            }
+            if (m_aggregate != null) {
+                req.addAttribute(new Attribute("aggregate", m_aggregate));
+            }
+            if (m_filter != null) {
+                req.addAttribute(new Attribute("filter", m_filter));
+            }
+            if (m_optional != null) {
+                req.addAttribute(new Attribute("optional", m_optional));
+            }
+            if (m_id != null) {
+                req.addAttribute(new Attribute("id", m_id));
+            }
+            m_element.addElement(req);
+            return;
+        }
+    }
+    
+    /**
+     * Parse a @property annotation.
+     */
+    private final class PropertyAnnotationParser extends EmptyVisitor implements AnnotationVisitor {
+        
+        /**
+         * Parent element (element on which append collected metadata).
+         */
+        private Element m_parent;
+        
+        /**
+         * Field name. 
+         */
+        private String m_field;
+        
+        /**
+         * Property name. 
+         */
+        private String m_name;
+        
+        /**
+         * Property value.  
+         */
+        private String m_value;
+        
+        
+        /**
+         * Constructor.
+         * @param parent : parent element.
+         * @param field : field name.
+         */
+        private PropertyAnnotationParser(Element parent, String field) {
+            m_parent = parent;
+            m_field = field;
+        }
+
+        /**
+         * Visit one "simple" annotation.
+         * @param arg0 : annotation name
+         * @param arg1 : annotation value
+         * @see org.objectweb.asm.AnnotationVisitor#visit(java.lang.String, java.lang.Object)
+         */
+        public void visit(String arg0, Object arg1) {
+            if (arg0.equals("name")) {
+                m_name = arg1.toString();
+                return;
+            }
+            if (arg0.equals("value")) {
+                m_value = arg1.toString();
+                return;
+            }
+        }
+
+        /**
+         * End of the annotation.
+         * Create a "property" element
+         * @see org.objectweb.asm.AnnotationVisitor#visitEnd()
+         */
+        public void visitEnd() {
+            if (m_name == null) {
+                m_name = m_field;
+            }
+            
+            Element[] props = m_parent.getElements("Property");
+            Element prop = null;
+            for (int i = 0; prop == null && i < props.length; i++) {
+                if (props[i].containsAttribute("name") && props[i].getAttribute("name").equals(m_name)) {
+                    prop = props[i];
+                }
+            }
+            
+            if (prop == null) {
+                prop = new Element("property", "");
+                m_parent.addElement(prop);
+                if (m_name != null) { 
+                    prop.addAttribute(new Attribute("name", m_name));
+                }
+            }
+            
+            prop.addAttribute(new Attribute("field", m_field));
+            if (m_value != null) {
+                prop.addAttribute(new Attribute("value", m_value));
+            }
+            
+        }
+    }
+}

Added: felix/trunk/ipojo/manipulator/src/main/java/org/apache/felix/ipojo/manipulation/annotations/MetadataCollector.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/manipulator/src/main/java/org/apache/felix/ipojo/manipulation/annotations/MetadataCollector.java?view=auto&rev=565749
==============================================================================
--- felix/trunk/ipojo/manipulator/src/main/java/org/apache/felix/ipojo/manipulation/annotations/MetadataCollector.java (added)
+++ felix/trunk/ipojo/manipulator/src/main/java/org/apache/felix/ipojo/manipulation/annotations/MetadataCollector.java Tue Aug 14 06:44:32 2007
@@ -0,0 +1,413 @@
+/* 
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.felix.ipojo.manipulation.annotations;
+
+import org.apache.felix.ipojo.metadata.Attribute;
+import org.apache.felix.ipojo.metadata.Element;
+import org.objectweb.asm.AnnotationVisitor;
+import org.objectweb.asm.FieldVisitor;
+import org.objectweb.asm.MethodVisitor;
+import org.objectweb.asm.Opcodes;
+import org.objectweb.asm.commons.EmptyVisitor;
+
+/**
+ * Collect metadata from classes by parsing annotation.
+ * This class collects type (i.e.) annotations and create method & field collectors.
+ * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
+ */
+public class MetadataCollector extends EmptyVisitor implements Opcodes {
+
+    /**
+     * Class name.
+     */
+    private String m_className;
+    
+    /**
+     * Root element of computed metadata.
+     */
+    private Element m_elem = new Element("component", "");
+    
+    /**
+     * True if the visited class is a component type declaration (i.e. contains the @component annotation).
+     */
+    private boolean m_containsAnnotation = false;
+    
+    public Element getElem() {
+        return m_elem;
+    }
+    
+    public boolean isAnnotated() {
+        return m_containsAnnotation;
+    }
+
+    /**
+     * Start visiting a class.
+     * Initialize the getter/setter generator, add the _cm field, add the pojo interface.
+     * @param version : class version
+     * @param access : class access
+     * @param name : class name 
+     * @param signature : class signature
+     * @param superName : class super class
+     * @param interfaces : implemented interfaces
+     * @see org.objectweb.asm.ClassAdapter#visit(int, int, java.lang.String, java.lang.String, java.lang.String, java.lang.String[])
+     */
+    public void visit(int version, int access, String name, String signature, String superName, String[] interfaces) {
+        m_className = name;
+    }
+
+    
+    /**
+     * Visit class annotations.
+     * This method detects @component, @provides and @Element annotations.
+     * @param desc : annotation descriptor.
+     * @param visible : is the annotation visible at runtime.
+     * @return the annotation visitor.
+     * @see org.objectweb.asm.ClassAdapter#visitAnnotation(java.lang.String, boolean)
+     */
+    public AnnotationVisitor visitAnnotation(String desc, boolean visible) {
+        // @Component
+        if (desc.equals("Lorg/apache/felix/ipojo/annotations/Component;")) {
+            // It is a component
+            m_containsAnnotation = true;
+            m_elem.addAttribute(new Attribute("className", m_className.replace('/', '.')));
+            return new ComponentVisitor();
+        }
+        
+        // @Provides
+        if (desc.equals("Lorg/apache/felix/ipojo/annotations/Provides;")) {
+            return new ProvidesVisitor();
+        }
+        
+        //@Element
+        if (desc.equals("Lorg/apache/felix/ipojo/annotations/Element;")) {
+            return new ElementVisitor(m_elem);
+        }
+        
+        return null;
+    }
+
+    /**
+     * Visit a field.
+     * Call the field collector visitor.
+     * @param access : field access.
+     * @param name : field name
+     * @param desc : field descriptor
+     * @param signature : field signature
+     * @param value : field value (static field only)
+     * @return the field visitor.
+     * @see org.objectweb.asm.ClassAdapter#visitField(int, java.lang.String, java.lang.String, java.lang.String, java.lang.Object)
+     */
+    public FieldVisitor visitField(int access, String name, String desc, String signature, Object value) {
+        return new FieldCollector(name, m_elem);
+    }
+
+    /**
+     * Visit a method.
+     * Call the method collector visitor.
+     * @param access : method access
+     * @param name : method name
+     * @param desc : method descriptor
+     * @param signature : method signature
+     * @param exceptions : method exceptions
+     * @return the Method Visitor.
+     * @see org.objectweb.asm.ClassAdapter#visitMethod(int, java.lang.String, java.lang.String, java.lang.String, java.lang.String[])
+     */
+    public MethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions) {
+        return new MethodCollector(name, m_elem);
+    }
+    
+    /**
+     * Parse the @provides annotation.
+     */
+    private class ProvidesVisitor extends EmptyVisitor implements AnnotationVisitor {
+        /**
+         * Provides element.
+         */
+        Element m_prov = new Element("provides", "");
+
+        /**
+         * Visit @provides annotation attributes.
+         * @param arg0 : annotation attribute name
+         * @param arg1 : annotation attribute value
+         * @see org.objectweb.asm.commons.EmptyVisitor#visit(java.lang.String, java.lang.Object)
+         */
+        public void visit(String arg0, Object arg1) {
+            if (arg0.equals("specifications")) {
+                m_prov.addAttribute(new Attribute("interface", arg1.toString()));
+            }
+            if (arg0.equals("factory")) {
+                m_prov.addAttribute(new Attribute("factory", arg1.toString()));
+            }
+        }
+        
+        /**
+         * End of the visit.
+         * Append to the parent element the computed "provides" element.
+         * @see org.objectweb.asm.commons.EmptyVisitor#visitEnd()
+         */
+        public void visitEnd() {
+            m_elem.addElement(m_prov);            
+        }
+        
+    }
+    
+    /**
+     * Parse the @component annotation.
+     */
+    private class ComponentVisitor extends EmptyVisitor implements AnnotationVisitor {
+        
+        /**
+         * Factory attribute.
+         */
+        private String m_factory;
+
+        /**
+         * Is the component an immediate component? 
+         */
+        private String m_immediate;
+        
+        /**
+         * Component name (cannot be null). 
+         */
+        private String m_name;
+        
+        /**
+         * Does the component exposes its architecture?
+         */
+        private String m_architecture;
+
+        /**
+         * Does the component propagate configuration to provided services?
+         */
+        private String m_propagation;
+
+        /**
+         * Visit @component annotation attribute.
+         * @param arg0 : attribute name
+         * @param arg1 : attribute value
+         * @see org.objectweb.asm.commons.EmptyVisitor#visit(java.lang.String, java.lang.Object)
+         */
+        public void visit(String arg0, Object arg1) {
+            if (arg0.equals("factory")) {
+                m_factory = arg1.toString();
+                return;
+            }
+            if (arg0.equals("name")) {
+                m_name = arg1.toString();
+                return;
+            }
+            if (arg0.equals("immediate")) {
+                m_immediate = arg1.toString();
+                return;
+            }
+            if (arg0.equals("architecture")) {
+                m_architecture = arg1.toString();
+                return;
+            }
+            if (arg0.equals("propagation")) {
+                m_propagation = arg1.toString();
+                return;
+            }
+        }
+
+        /**
+         * End of the visit.
+         * Append to the "component" element computed attribute.
+         * @see org.objectweb.asm.commons.EmptyVisitor#visitEnd()
+         */
+        public void visitEnd() { 
+            if (m_name == null) {
+                m_name = m_className.replace('/', '.');
+            }
+            m_elem.addAttribute(new Attribute("name", m_name));
+            if (m_factory == null) {
+                m_elem.addAttribute(new Attribute("factory", "false"));
+            } else {
+                m_elem.addAttribute(new Attribute("factory", m_factory)); 
+            }
+            if (m_architecture != null) {
+                m_elem.addAttribute(new Attribute("architecture", m_architecture));
+            }
+            if (m_immediate != null) {
+                m_elem.addAttribute(new Attribute("immediate", m_immediate));
+            }
+            if (m_propagation != null) {
+                Element props = new Element("properties", "");
+                props.addAttribute(new Attribute("propagation", m_propagation));
+                m_elem.addElement(props);
+            }
+        }        
+    }
+
+    /**
+     * Parse the @Element & @SubElement annotations. 
+     */
+    private class ElementVisitor extends EmptyVisitor implements AnnotationVisitor {
+        
+        /**
+         * Element name.
+         */
+        private String m_name;
+        
+        /**
+         * Element namespace. 
+         */
+        private String m_namespace;
+        
+        /**
+         * Parent Element. 
+         */
+        private Element m_parent;
+        
+        /**
+         * Accumulator element to store temporary attributes and sub-elements.
+         */
+        private Element m_accu = new Element("accu", "");
+        
+        /**
+         * Constructor.
+         * @param parent : parent element.
+         */
+        public ElementVisitor(Element parent) {
+            m_parent = parent;
+        }
+
+        /**
+         * Visit annotation attribute.
+         * @param arg0 : name of the attribute
+         * @param arg1 : value of the attribute
+         * @see org.objectweb.asm.AnnotationVisitor#visit(java.lang.String, java.lang.Object)
+         */
+        public void visit(String arg0, Object arg1) {
+            if (arg0.equals("name")) {
+                m_name = arg1.toString();
+            }
+            if (arg0.equals("namespace")) {
+                m_namespace = arg1.toString();
+            }
+        }
+
+        
+        /**
+         * Visit array annotation attribute (attributes & elements).
+         * @param arg0 : attribute name
+         * @return the annotation visitor which will visit the content of the array
+         * @see org.objectweb.asm.AnnotationVisitor#visitArray(java.lang.String)
+         */
+        public AnnotationVisitor visitArray(String arg0) {
+            if (arg0.equals("attributes")) {
+                return new EmptyVisitor() {
+                    public AnnotationVisitor visitAnnotation(String arg0, String arg1) {
+                        return new AttributeVisitor(m_accu);
+                    }
+                    
+                };
+            }
+            if (arg0.equals("elements")) {
+                return new EmptyVisitor() {
+                    public AnnotationVisitor visitAnnotation(String arg0, String arg1) {
+                        return new ElementVisitor(m_accu);
+                    }
+                    
+                };
+            }
+            return null;
+        }
+
+        /**
+         * End of the visit.
+         * Append computed element to the parent element.
+         * @see org.objectweb.asm.AnnotationVisitor#visitEnd()
+         */
+        public void visitEnd() {
+            Element elem = null;
+            if (m_namespace != null) {
+                elem = new Element(m_name, m_namespace);
+            } else {
+                elem = new Element(m_name, "");
+            }
+
+            Attribute[] atts = m_accu.getAttributes();
+            for (int i = 0; i < atts.length; i++) {
+                elem.addAttribute(atts[i]);
+            }
+
+            Element[] elems = m_accu.getElements();
+            for (int i = 0; i < elems.length; i++) {
+                elem.addElement(elems[i]);
+            }
+
+            m_parent.addElement(elem);
+        }
+        
+    }
+    
+    /**
+     * Parse an @attribute annotation.
+     */
+    private class AttributeVisitor extends EmptyVisitor implements AnnotationVisitor {
+        /**
+         * Parent element.
+         */
+        private Element m_parent;
+
+        /**
+         * Attribute name.
+         */
+        private String m_name;
+        
+        /**
+         * Attribute value. 
+         */
+        private String m_value;
+        
+        /**
+         * Constructor.
+         * @param parent : parent element.
+         */
+        public AttributeVisitor(Element parent) {
+            m_parent = parent;
+        }
+
+        /**
+         * Visit attributes. 
+         * @param arg0 : attribute name
+         * @param arg1 : attribute value
+         * @see org.objectweb.asm.commons.EmptyVisitor#visit(java.lang.String, java.lang.Object)
+         */
+        public void visit(String arg0, Object arg1) {
+            if (arg0.equals("name")) {
+                m_name = arg1.toString();
+                return;
+            }
+            if (arg0.equals("value")) {
+                m_value = arg1.toString();
+            }
+        }
+
+        /**
+         * End of the visit.
+         * Append this current attribute to the parent element.
+         * @see org.objectweb.asm.commons.EmptyVisitor#visitEnd()
+         */
+        public void visitEnd() {
+            m_parent.addAttribute(new Attribute(m_name, m_value));
+        }        
+    }
+}

Added: felix/trunk/ipojo/manipulator/src/main/java/org/apache/felix/ipojo/manipulation/annotations/MethodCollector.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/manipulator/src/main/java/org/apache/felix/ipojo/manipulation/annotations/MethodCollector.java?view=auto&rev=565749
==============================================================================
--- felix/trunk/ipojo/manipulator/src/main/java/org/apache/felix/ipojo/manipulation/annotations/MethodCollector.java (added)
+++ felix/trunk/ipojo/manipulator/src/main/java/org/apache/felix/ipojo/manipulation/annotations/MethodCollector.java Tue Aug 14 06:44:32 2007
@@ -0,0 +1,356 @@
+/* 
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.felix.ipojo.manipulation.annotations;
+
+import org.apache.felix.ipojo.metadata.Attribute;
+import org.apache.felix.ipojo.metadata.Element;
+import org.objectweb.asm.AnnotationVisitor;
+import org.objectweb.asm.commons.EmptyVisitor;
+
+/**
+ * This class collects method annotations, and give them to the metadata collector. 
+ * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
+ */
+public class MethodCollector extends EmptyVisitor {
+
+    /**
+     * Parent element (component).
+     */
+    private Element m_element;
+    
+    /**
+     * Method name. 
+     */
+    private String m_name;
+
+    /**
+     * Constructor.
+     * @param name : name of the method.
+     * @param element : parent element.
+     */
+    public MethodCollector(String name, Element element) {
+        m_element = element;
+        m_name = name;
+    }
+
+    /**
+     * Visit method annotations.
+     * @param arg0 : annotation name.
+     * @param arg1 : is the annotation visible at runtime.
+     * @return the visitor paring the visited annotation.
+     * @see org.objectweb.asm.commons.EmptyVisitor#visitAnnotation(java.lang.String, boolean)
+     */
+    public AnnotationVisitor visitAnnotation(String arg0, boolean arg1) {
+        if (arg0.equals("Lorg/apache/felix/ipojo/annotations/Property;")) {
+            return processProperty();
+        }
+        if (arg0.equals("Lorg/apache/felix/ipojo/annotations/ServiceProperty;")) {
+            return processServiceProperty();
+        }
+        if (arg0.equals("Lorg/apache/felix/ipojo/annotations/Validate;")) {
+            return processValidate();
+        }
+        if (arg0.equals("Lorg/apache/felix/ipojo/annotations/Invalidate;")) {
+            return processInvalidate();
+        }
+        if (arg0.equals("Lorg/apache/felix/ipojo/annotations/Bind;")) {
+            return processBind("bind");
+        }
+        if (arg0.equals("Lorg/apache/felix/ipojo/annotations/Unbind;")) {
+            return processBind("unbind");
+        }
+        return null;
+    }
+
+    /**
+     * Process @bind & @unbind.
+     * @param type : bind or unbind
+     * @return the visitor parsing @bind & @unbind annotations.
+     */
+    private AnnotationVisitor processBind(String type) {
+        return new BindAnnotationParser(m_name, type);
+    }
+
+    /**
+     * Process @validate annotation.
+     * @return null.
+     */
+    private AnnotationVisitor processValidate() {
+        Element cb = new Element("callback", "");
+        cb.addAttribute(new org.apache.felix.ipojo.metadata.Attribute("transition", "validate"));
+        cb.addAttribute(new org.apache.felix.ipojo.metadata.Attribute("method", m_name));
+        m_element.addElement(cb);
+        return null;
+    }
+
+    /**
+     * Process @invalidate annotation.
+     * @return null.
+     */
+    private AnnotationVisitor processInvalidate() {
+        Element cb = new Element("callback", "");
+        cb.addAttribute(new org.apache.felix.ipojo.metadata.Attribute("transition", "invalidate"));
+        cb.addAttribute(new org.apache.felix.ipojo.metadata.Attribute("method", m_name));
+        m_element.addElement(cb);
+        return null;
+    }
+
+    /**
+     * Process @serviceProperty annotation.
+     * @return the visitor parsing the visited annotation.
+     */
+    private AnnotationVisitor processServiceProperty() {
+        if (m_element.getElements("Provides", "").length == 0) {
+            System.err.println("the component does not provide services, skip ServiceProperty for " + m_name);
+            return null;
+        }
+        Element provides = m_element.getElements("Provides", "")[0];
+        return new PropertyAnnotationParser(provides, m_name);
+    }
+
+    /**
+     * Process @property annotation.
+     * @return the visitor parsing the visited annotation.
+     */
+    private AnnotationVisitor processProperty() {
+        if (m_element.getElements("Properties", "").length == 0) {
+            m_element.addElement(new Element("Properties", ""));
+        }
+        Element props = m_element.getElements("Properties", "")[0];
+        return new PropertyAnnotationParser(props, m_name);
+    }
+
+    /**
+     * Parse @bind & @unbind annotations.
+     */
+    private final class BindAnnotationParser extends EmptyVisitor implements AnnotationVisitor {
+
+        /**
+         * Method name.
+         */
+        private String m_name;
+
+        /**
+         * Requirement filter.
+         */
+        private String m_filter;
+
+        /**
+         * Is the requirement optional?
+         */
+        private String m_optional;
+
+        /**
+         * Is the requirement aggregate?
+         */
+        private String m_aggregate;
+
+        /**
+         * Required specification. 
+         */
+        private String m_specification;
+
+        /**
+         * Requirement id.
+         */
+        private String m_id;
+
+        /**
+         * Bind or Unbind method?
+         */
+        private String m_type;
+
+        /**
+         * Constructor.
+         * @param bind : method name.
+         * @param type : is the callback a bind or an unbind method.
+         */
+        private BindAnnotationParser(String bind, String type) {
+            m_name = bind;
+            m_type = type;
+        }
+
+        /**
+         * Visit annotation attribute.
+         * @param arg0 : annotation name
+         * @param arg1 : annotation value
+         * @see org.objectweb.asm.commons.EmptyVisitor#visit(java.lang.String, java.lang.Object)
+         */
+        public void visit(String arg0, Object arg1) {
+            if (arg0.equals("filter")) {
+                m_filter = arg1.toString();
+                return;
+            }
+            if (arg0.equals("optional")) {
+                m_optional = arg1.toString();
+                return;
+            }
+            if (arg0.equals("aggregate")) {
+                m_aggregate = arg1.toString();
+                return;
+            }
+            if (arg0.equals("specification")) {
+                m_specification = arg1.toString();
+                return;
+            }
+            if (arg0.equals("id")) {
+                m_id = arg1.toString();
+                return;
+            }
+        }
+
+        /**
+         * End of the visit.
+         * Create or append the requirement info to a created or already existing "requires" element.
+         * @see org.objectweb.asm.commons.EmptyVisitor#visitEnd()
+         */
+        public void visitEnd() {
+            if (m_id == null) {
+                if (m_name.startsWith("bind")) {
+                    m_id = m_name.substring("bind".length());
+                } else if (m_name.startsWith("unbind")) {
+                    m_id = m_name.substring("unbind".length());
+                } else {
+                    System.err.println("Cannot determine the id of the bind method : " + m_name);
+                    return;
+                }
+            }
+            // Check if it is a full-determined requirement
+            Element req = null;
+            Element[] reqs = m_element.getElements("requires");
+            for (int i = 0; i < reqs.length; i++) {
+                if (reqs[i].containsAttribute("id") && reqs[i].getAttribute("id").equals(m_id)) {
+                    req = reqs[i];
+                    break;
+                }
+                if (reqs[i].containsAttribute("field") && reqs[i].getAttribute("field").equals(m_id)) {
+                    req = reqs[i];
+                    break;
+                }
+            }
+            if (req == null) {
+                // Add the complete requires
+                req = new Element("requires", "");
+                if (m_specification != null) {
+                    req.addAttribute(new Attribute("interface", m_specification));
+                }
+                if (m_aggregate != null) {
+                    req.addAttribute(new Attribute("aggregate", m_aggregate));
+                }
+                if (m_filter != null) {
+                    req.addAttribute(new Attribute("filter", m_filter));
+                }
+                if (m_optional != null) {
+                    req.addAttribute(new Attribute("optional", m_optional));
+                }
+                if (m_id != null) {
+                    req.addAttribute(new Attribute("id", m_id));
+                }
+            }
+            Element method = new Element("callback", "");
+            method.addAttribute(new Attribute("method", m_name));
+            method.addAttribute(new Attribute("type", m_type));
+            req.addElement(method);
+            m_element.addElement(req);
+            return;
+        }
+    }
+
+    private final class PropertyAnnotationParser extends EmptyVisitor implements AnnotationVisitor {
+
+        /**
+         * Parent element.
+         */
+        private Element m_parent;
+        
+        /**
+         * Attached method.
+         */
+        private String m_method;
+        
+        /**
+         * Property name. 
+         */
+        private String m_name;
+        
+        /**
+         * Property value. 
+         */
+        private String m_value;
+
+        /**
+         * Constructor.
+         * @param parent : parent element.
+         * @param method : attached method.
+         */
+        private PropertyAnnotationParser(Element parent, String method) {
+            m_parent = parent;
+            m_method = method;
+        }
+
+        /**
+         * Visit annotation attributes.
+         * @param arg0 : annotation name
+         * @param arg1 : annotation value
+         * @see org.objectweb.asm.commons.EmptyVisitor#visit(java.lang.String, java.lang.Object)
+         */
+        public void visit(String arg0, Object arg1) {
+            if (arg0.equals("name")) {
+                m_name = arg1.toString();
+                return;
+            }
+            if (arg0.equals("value")) {
+                m_value = arg1.toString();
+                return;
+            }
+        }
+
+        /**
+         * End of the visit.
+         * Append the computed element to the parent element.
+         * @see org.objectweb.asm.commons.EmptyVisitor#visitEnd()
+         */
+        public void visitEnd() {
+            if (m_name == null && m_method.startsWith("set")) {
+                m_name = m_method.substring("set".length());
+            }
+            Element[] props = m_parent.getElements("Property");
+            Element prop = null;
+            for (int i = 0; prop == null && i < props.length; i++) {
+                if (props[i].containsAttribute("name") && props[i].getAttribute("name").equals(m_name)) {
+                    prop = props[i];
+                }
+            }
+
+            if (prop == null) {
+                prop = new Element("property", "");
+                m_parent.addElement(prop);
+                if (m_name != null) {
+                    prop.addAttribute(new Attribute("name", m_name));
+                }
+            }
+
+            prop.addAttribute(new Attribute("method", m_method));
+            if (m_value != null) {
+                prop.addAttribute(new Attribute("value", m_value));
+            }
+
+        }
+    }
+}

Modified: felix/trunk/ipojo/manipulator/src/main/java/org/apache/felix/ipojo/manipulator/Pojoization.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/manipulator/src/main/java/org/apache/felix/ipojo/manipulator/Pojoization.java?view=diff&rev=565749&r1=565748&r2=565749
==============================================================================
--- felix/trunk/ipojo/manipulator/src/main/java/org/apache/felix/ipojo/manipulator/Pojoization.java (original)
+++ felix/trunk/ipojo/manipulator/src/main/java/org/apache/felix/ipojo/manipulator/Pojoization.java Tue Aug 14 06:44:32 2007
@@ -39,13 +39,14 @@
 import java.util.jar.Manifest;
 
 import org.apache.felix.ipojo.manipulation.Manipulator;
+import org.apache.felix.ipojo.manipulation.annotations.MetadataCollector;
 import org.apache.felix.ipojo.metadata.Element;
 import org.apache.felix.ipojo.xml.parser.ParseException;
 import org.apache.felix.ipojo.xml.parser.XMLMetadataParser;
+import org.objectweb.asm.ClassReader;
 import org.xml.sax.InputSource;
 import org.xml.sax.SAXException;
 import org.xml.sax.XMLReader;
-import org.xml.sax.helpers.XMLReaderFactory;
 
 /**
  * Pojoization allows creating an iPOJO bundle from a "normal" bundle.  
@@ -61,7 +62,7 @@
     /**
      * Metadata (in internal format).
      */
-    private Element[] m_metadata;
+    private Element[] m_metadata = new Element[0];
 
     /**
      * Errors which occur during the manipulation.
@@ -114,18 +115,28 @@
      * @param metadataFile : iPOJO metadata file (XML). 
      */
     public void pojoization(File in, File out, File metadataFile) {
-        // Get the metadata.xml location
-        String path = metadataFile.getAbsolutePath();
-        if (!path.startsWith("/")) {
-            path = "/" + path;
+        // Get the metadata.xml location if not null
+        if (metadataFile != null) {
+            String path = metadataFile.getAbsolutePath();
+            if (!path.startsWith("/")) {
+                path = "/" + path;
+            }
+            m_metadata = parseXMLMetadata(path);
+        }
+        
+        JarFile inputJar;
+        try {
+            inputJar = new JarFile(in);
+        } catch (IOException e) {
+            error("The input file " + in.getAbsolutePath() + " is not a Jar file");
+            return;
         }
-        m_metadata = parseXMLMetadata(path);
 
         // Get the list of declared component
         m_components = getDeclaredComponents(m_metadata);
 
         // Start the manipulation
-        manipulation(in, out);
+        manipulation(inputJar, out);
 
         // Check that all declared components are manipulated
         for (int i = 0; i < m_components.size(); i++) {
@@ -137,21 +148,47 @@
     }
 
     /**
-     * Manipulate the Bundle.
-     * @param in : original bundle
-     * @param out : final bundle
+     * Parse the content of the input Jar file to detect annotated classes.
+     * @param inC : the class to inspect.
      */
-    private void manipulation(File in, File out) {
-        // Get a jar file from the given file
-        JarFile inputJar = null;
-        try {
-            inputJar = new JarFile(in);
-        } catch (IOException e) {
-            error("The input file is not a JarFile : " + in.getAbsolutePath());
-            return;
+    private void computeAnnotations(byte[] inC) {
+        ClassReader cr = new ClassReader(inC);
+        MetadataCollector xml = new MetadataCollector();
+        cr.accept(xml, 0);
+        if (xml.isAnnotated()) {
+            boolean toskip = false;
+            for (int i = 0; !toskip && i < m_metadata.length; i++) {
+                if (m_metadata[i].containsAttribute("name")
+                        && m_metadata[i].getAttribute("name").equalsIgnoreCase(xml.getElem().getAttribute("name"))) {
+                    toskip = true;
+                    warn("The component " + xml.getElem().getAttribute("name") + " is overriden by the metadata file");
+                }
+            }
+            if (!toskip) {
+                if (m_metadata != null || m_metadata.length != 0) {
+                    Element[] newElementsList = new Element[m_metadata.length + 1];
+                    System.arraycopy(m_metadata, 0, newElementsList, 0, m_metadata.length);
+                    newElementsList[m_metadata.length] = xml.getElem();
+                    m_metadata = newElementsList;
+                } else {
+                    m_metadata = new Element[] { xml.getElem() };
+                }
+                String name = m_metadata[m_metadata.length - 1].getAttribute("classname");
+                name = name.replace('.', '/');
+                name += ".class";
+                m_components.add(new ComponentInfo(name, m_metadata[m_metadata.length - 1]));
+            }
         }
+    }
 
+    /**
+     * Manipulate the Bundle.
+     * @param inputJar : original bundle (JarFile)
+     * @param out : final bundle
+     */
+    private void manipulation(JarFile inputJar, File out) {
         manipulateComponents(inputJar); // Manipulate classes
+        m_referredPackages = getReferredPackages();
         Manifest mf = doManifest(inputJar); // Compute the manifest
 
         // Create a new Jar file
@@ -161,7 +198,7 @@
             fos = new FileOutputStream(out);
             jos = new JarOutputStream(fos, mf);
         } catch (FileNotFoundException e1) {
-            error("Cannot manipulate the Jar file : the file " + out.getAbsolutePath() + " not found");
+            error("Cannot manipulate the Jar file : the output file " + out.getAbsolutePath() + " is not found");
             return;
         } catch (IOException e) {
             error("Cannot manipulate the Jar file : cannot access to " + out.getAbsolutePath());
@@ -235,12 +272,30 @@
         Enumeration entries = inputJar.entries();
         while (entries.hasMoreElements()) {
             JarEntry curEntry = (JarEntry) entries.nextElement();
-            // Check if we need to manipulate the class
-            for (int i = 0; i < m_components.size(); i++) {
-                ComponentInfo ci = (ComponentInfo) m_components.get(i);
-                if (ci.m_classname.equals(curEntry.getName())) {
-                    byte[] outClazz = manipulateComponent(inputJar, curEntry, ci);
-                    m_classes.put(curEntry.getName(), outClazz);
+            if (curEntry.getName().endsWith(".class")) {
+                try {
+                    InputStream currIn = inputJar.getInputStream(curEntry);
+                    byte[] in = new byte[0];
+                    int c;
+                    while ((c = currIn.read()) >= 0) {
+                        byte[] in2 = new byte[in.length + 1];
+                        System.arraycopy(in, 0, in2, 0, in.length);
+                        in2[in.length] = (byte) c;
+                        in = in2;
+                    }
+                    currIn.close();
+                    computeAnnotations(in);
+                    // Check if we need to manipulate the class
+                    for (int i = 0; i < m_components.size(); i++) {
+                        ComponentInfo ci = (ComponentInfo) m_components.get(i);
+                        if (ci.m_classname.equals(curEntry.getName())) {
+                            byte[] outClazz = manipulateComponent(in, curEntry, ci);
+                            m_classes.put(curEntry.getName(), outClazz);
+                        }
+                    }
+                } catch (IOException e) {
+                    error("Cannot read the class : " + curEntry.getName());
+                    return;
                 }
             }
         }
@@ -268,24 +323,14 @@
 
     /**
      * Manipulate a component class.
-     * @param inputJar : input bundle
+     * @param in : the byte array of the class to manipulate
      * @param je : Jar entry of the classes
      * @param ci : attached component info (containing metadata and manipulation metadata)
      * @return the generated class (byte array)
      */
-    private byte[] manipulateComponent(JarFile inputJar, JarEntry je, ComponentInfo ci) {
+    private byte[] manipulateComponent(byte[] in, JarEntry je, ComponentInfo ci) {
         Manipulator man = new Manipulator();
         try {
-            InputStream currIn = inputJar.getInputStream(je);
-            byte[] in = new byte[0];
-            int c;
-            while ((c = currIn.read()) >= 0) {
-                byte[] in2 = new byte[in.length + 1];
-                System.arraycopy(in, 0, in2, 0, in.length);
-                in2[in.length] = (byte) c;
-                in = in2;
-            }
-            currIn.close();
             byte[] out = man.manipulate(in); // iPOJO manipulation
             // Insert information to metadata
             ci.m_componentMetadata.addElement(man.getManipulationMetadata());
@@ -529,18 +574,17 @@
         try {
             url = metadata.toURL();
             if (url == null) {
-                error("Cannot find the metadata file : " + path);
-                return null;
+                warn("Cannot find the metadata file : " + path);
+                return new Element[0];
             }
 
-            InputStream stream = url.openStream();
-            XMLReader parser = XMLReaderFactory.createXMLReader("org.apache.xerces.parsers.SAXParser");
+            InputStream stream = url.openStream();            
+            XMLReader parser = (XMLReader) Class.forName("org.apache.xerces.parsers.SAXParser").newInstance();
             XMLMetadataParser handler = new XMLMetadataParser();
             parser.setContentHandler(handler);
             InputSource is = new InputSource(stream);
             parser.parse(is);
             meta = handler.getMetadata();
-            m_referredPackages = handler.getReferredPackages();
             stream.close();
 
         } catch (MalformedURLException e) {
@@ -555,6 +599,15 @@
         } catch (SAXException e) {
             error("Parsing Error when parsing (Sax Error) the XML file " + path + " : " + e.getMessage());
             return null;
+        } catch (InstantiationException e) {
+            error("Cannot instantiate the SAX parser for the XML file " + path + " : " + e.getMessage());
+            return null;
+        } catch (IllegalAccessException e) {
+            error("Cannot instantiate  the SAX parser (IllegalAccess) for the XML file " + path + " : " + e.getMessage());
+            return null;
+        } catch (ClassNotFoundException e) {
+            error("Cannot load the Sax Parser : " + e.getMessage());
+            return null;
         }
 
         if (meta == null || meta.length == 0) {
@@ -562,6 +615,29 @@
         }
 
         return meta;
+    }
+    
+    /**
+     * Get packages referenced by composite.
+     * 
+     * @return the list of referenced packages.
+     */
+    private List getReferredPackages() {
+        List referred = new ArrayList();
+        for (int i = 0; i < m_metadata.length; i++) {
+            if (m_metadata[i].getName().equalsIgnoreCase("composite")) {
+                for (int j = 0; j < m_metadata[i].getElements().length; j++) {
+                    if (m_metadata[i].getElements()[j].containsAttribute("specification")) {
+                        String p = m_metadata[i].getElements()[j].getAttribute("specification");
+                        int last = p.lastIndexOf('.');
+                        if (last != -1) {
+                            referred.add(p.substring(0, last));
+                        }
+                    }
+                }
+            }
+        }
+        return referred;
     }
 
     /**

Modified: felix/trunk/ipojo/manipulator/src/main/java/org/apache/felix/ipojo/xml/parser/XMLMetadataParser.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/manipulator/src/main/java/org/apache/felix/ipojo/xml/parser/XMLMetadataParser.java?view=diff&rev=565749&r1=565748&r2=565749
==============================================================================
--- felix/trunk/ipojo/manipulator/src/main/java/org/apache/felix/ipojo/xml/parser/XMLMetadataParser.java (original)
+++ felix/trunk/ipojo/manipulator/src/main/java/org/apache/felix/ipojo/xml/parser/XMLMetadataParser.java Tue Aug 14 06:44:32 2007
@@ -18,9 +18,6 @@
  */
 package org.apache.felix.ipojo.xml.parser;
 
-import java.util.ArrayList;
-import java.util.List;
-
 import org.apache.felix.ipojo.metadata.Attribute;
 import org.apache.felix.ipojo.metadata.Element;
 import org.xml.sax.Attributes;
@@ -61,28 +58,6 @@
             l++;
         }
         return metadata;
-    }
-
-    /**
-     * Get packages referenced by composite.
-     * 
-     * @return the list of referenced packages.
-     */
-    public List getReferredPackages() {
-        List referred = new ArrayList();
-        Element[] compo = m_elements[0].getElements("Composite");
-        for (int i = 0; i < compo.length; i++) {
-            for (int j = 0; j < compo[i].getElements().length; j++) {
-                if (compo[i].getElements()[j].containsAttribute("specification")) {
-                    String p = compo[i].getElements()[j].getAttribute("specification");
-                    int last = p.lastIndexOf('.');
-                    if (last != -1) {
-                        referred.add(p.substring(0, last));
-                    }
-                }
-            }
-        }
-        return referred;
     }
 
     /**



Mime
View raw message