FELIX-3551 : Support the DS annotations
git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@1349925 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/scrplugin/annotations/DEPENDENCIES b/scrplugin/annotations/DEPENDENCIES
index 6f08d32..603988f 100644
--- a/scrplugin/annotations/DEPENDENCIES
+++ b/scrplugin/annotations/DEPENDENCIES
@@ -1,5 +1,5 @@
Apache Felix SCR Annotations
-Copyright 2007-2011 The Apache Software Foundation
+Copyright 2007-2012 The Apache Software Foundation
This software was developed at the Apache Software Foundation
(http://www.apache.org) and may have dependencies on other
diff --git a/scrplugin/annotations/src/main/java/org/apache/felix/scrplugin/processing/SCRAnnotationProcessor.java b/scrplugin/annotations/src/main/java/org/apache/felix/scrplugin/processing/SCRAnnotationProcessor.java
index 271d284..3c73f5e 100644
--- a/scrplugin/annotations/src/main/java/org/apache/felix/scrplugin/processing/SCRAnnotationProcessor.java
+++ b/scrplugin/annotations/src/main/java/org/apache/felix/scrplugin/processing/SCRAnnotationProcessor.java
@@ -64,7 +64,7 @@
/**
* @throws SCRDescriptorException
* @throws SCRDescriptorFailureException
- * @see org.apache.felix.scrplugin.AnnotationProcessor#process(ScannedClass, ClassDescription)
+ * @see org.apache.felix.scrplugin.annotations.AnnotationProcessor#process(org.apache.felix.scrplugin.annotations.ScannedClass, org.apache.felix.scrplugin.description.ClassDescription)
*/
public void process(final ScannedClass scannedClass, final ClassDescription describedClass)
throws SCRDescriptorFailureException, SCRDescriptorException {
@@ -157,7 +157,7 @@
}
/**
- * @see org.apache.felix.scrplugin.AnnotationProcessor#getRanking()
+ * @see org.apache.felix.scrplugin.annotations.AnnotationProcessor#getRanking()
*/
public int getRanking() {
return 1000;
diff --git a/scrplugin/annotations/src/main/java/org/apache/felix/scrplugin/processing/SlingAnnotationProcessor.java b/scrplugin/annotations/src/main/java/org/apache/felix/scrplugin/processing/SlingAnnotationProcessor.java
index 7a760bd..b7614a2 100644
--- a/scrplugin/annotations/src/main/java/org/apache/felix/scrplugin/processing/SlingAnnotationProcessor.java
+++ b/scrplugin/annotations/src/main/java/org/apache/felix/scrplugin/processing/SlingAnnotationProcessor.java
@@ -41,7 +41,7 @@
public class SlingAnnotationProcessor implements AnnotationProcessor {
/**
- * @see org.apache.felix.scrplugin.AnnotationProcessor#process(ScannedClass, ClassDescription)
+ * @see org.apache.felix.scrplugin.annotations.AnnotationProcessor#process(org.apache.felix.scrplugin.annotations.ScannedClass, org.apache.felix.scrplugin.description.ClassDescription)
*/
public void process(final ScannedClass scannedClass,
final ClassDescription describedClass)
@@ -64,7 +64,7 @@
}
/**
- * @see org.apache.felix.scrplugin.AnnotationProcessor#getRanking()
+ * @see org.apache.felix.scrplugin.annotations.AnnotationProcessor#getRanking()
*/
public int getRanking() {
return 500;
diff --git a/scrplugin/ds-annotations/.classpath b/scrplugin/ds-annotations/.classpath
new file mode 100644
index 0000000..30daf94
--- /dev/null
+++ b/scrplugin/ds-annotations/.classpath
@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+ <classpathentry kind="src" output="target/classes" path="src/main/java"/>
+ <classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources"/>
+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5"/>
+ <classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER"/>
+ <classpathentry kind="output" path="target/classes"/>
+</classpath>
diff --git a/scrplugin/ds-annotations/.project b/scrplugin/ds-annotations/.project
new file mode 100644
index 0000000..afadbf1
--- /dev/null
+++ b/scrplugin/ds-annotations/.project
@@ -0,0 +1,23 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>org.apache.felix.scr.spec-annotations</name>
+ <comment></comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ <buildCommand>
+ <name>org.eclipse.jdt.core.javabuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.m2e.core.maven2Builder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>org.eclipse.jdt.core.javanature</nature>
+ <nature>org.eclipse.m2e.core.maven2Nature</nature>
+ </natures>
+</projectDescription>
diff --git a/scrplugin/ds-annotations/.settings/org.eclipse.core.resources.prefs b/scrplugin/ds-annotations/.settings/org.eclipse.core.resources.prefs
new file mode 100644
index 0000000..d3c1df2
--- /dev/null
+++ b/scrplugin/ds-annotations/.settings/org.eclipse.core.resources.prefs
@@ -0,0 +1,2 @@
+eclipse.preferences.version=1
+encoding//src/main/resources=UTF-8
diff --git a/scrplugin/ds-annotations/.settings/org.eclipse.jdt.core.prefs b/scrplugin/ds-annotations/.settings/org.eclipse.jdt.core.prefs
new file mode 100644
index 0000000..abec6ca
--- /dev/null
+++ b/scrplugin/ds-annotations/.settings/org.eclipse.jdt.core.prefs
@@ -0,0 +1,5 @@
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5
+org.eclipse.jdt.core.compiler.compliance=1.5
+org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
+org.eclipse.jdt.core.compiler.source=1.5
diff --git a/scrplugin/ds-annotations/.settings/org.eclipse.m2e.core.prefs b/scrplugin/ds-annotations/.settings/org.eclipse.m2e.core.prefs
new file mode 100644
index 0000000..f897a7f
--- /dev/null
+++ b/scrplugin/ds-annotations/.settings/org.eclipse.m2e.core.prefs
@@ -0,0 +1,4 @@
+activeProfiles=
+eclipse.preferences.version=1
+resolveWorkspaceProjects=true
+version=1
diff --git a/scrplugin/ds-annotations/DEPENDENCIES b/scrplugin/ds-annotations/DEPENDENCIES
new file mode 100644
index 0000000..a58a9e8
--- /dev/null
+++ b/scrplugin/ds-annotations/DEPENDENCIES
@@ -0,0 +1,20 @@
+Apache Felix SCR DS Annotations
+Copyright 2012 The Apache Software Foundation
+
+This software was developed at the Apache Software Foundation
+(http://www.apache.org) and may have dependencies on other
+Apache software licensed under Apache License 2.0.
+
+I. Included Third-Party Software
+
+
+II. Used Third-Party Software
+
+This product uses software developed at
+The OSGi Alliance (http://www.osgi.org/).
+Copyright (c) OSGi Alliance (2000, 2012).
+Licensed under the Apache License 2.0.
+
+
+III. License Summary
+- Apache License 2.0
diff --git a/scrplugin/ds-annotations/LICENSE b/scrplugin/ds-annotations/LICENSE
new file mode 100644
index 0000000..d645695
--- /dev/null
+++ b/scrplugin/ds-annotations/LICENSE
@@ -0,0 +1,202 @@
+
+ Apache License
+ Version 2.0, January 2004
+ http://www.apache.org/licenses/
+
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+ 1. Definitions.
+
+ "License" shall mean the terms and conditions for use, reproduction,
+ and distribution as defined by Sections 1 through 9 of this document.
+
+ "Licensor" shall mean the copyright owner or entity authorized by
+ the copyright owner that is granting the License.
+
+ "Legal Entity" shall mean the union of the acting entity and all
+ other entities that control, are controlled by, or are under common
+ control with that entity. For the purposes of this definition,
+ "control" means (i) the power, direct or indirect, to cause the
+ direction or management of such entity, whether by contract or
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
+ outstanding shares, or (iii) beneficial ownership of such entity.
+
+ "You" (or "Your") shall mean an individual or Legal Entity
+ exercising permissions granted by this License.
+
+ "Source" form shall mean the preferred form for making modifications,
+ including but not limited to software source code, documentation
+ source, and configuration files.
+
+ "Object" form shall mean any form resulting from mechanical
+ transformation or translation of a Source form, including but
+ not limited to compiled object code, generated documentation,
+ and conversions to other media types.
+
+ "Work" shall mean the work of authorship, whether in Source or
+ Object form, made available under the License, as indicated by a
+ copyright notice that is included in or attached to the work
+ (an example is provided in the Appendix below).
+
+ "Derivative Works" shall mean any work, whether in Source or Object
+ form, that is based on (or derived from) the Work and for which the
+ editorial revisions, annotations, elaborations, or other modifications
+ represent, as a whole, an original work of authorship. For the purposes
+ of this License, Derivative Works shall not include works that remain
+ separable from, or merely link (or bind by name) to the interfaces of,
+ the Work and Derivative Works thereof.
+
+ "Contribution" shall mean any work of authorship, including
+ the original version of the Work and any modifications or additions
+ to that Work or Derivative Works thereof, that is intentionally
+ submitted to Licensor for inclusion in the Work by the copyright owner
+ or by an individual or Legal Entity authorized to submit on behalf of
+ the copyright owner. For the purposes of this definition, "submitted"
+ means any form of electronic, verbal, or written communication sent
+ to the Licensor or its representatives, including but not limited to
+ communication on electronic mailing lists, source code control systems,
+ and issue tracking systems that are managed by, or on behalf of, the
+ Licensor for the purpose of discussing and improving the Work, but
+ excluding communication that is conspicuously marked or otherwise
+ designated in writing by the copyright owner as "Not a Contribution."
+
+ "Contributor" shall mean Licensor and any individual or Legal Entity
+ on behalf of whom a Contribution has been received by Licensor and
+ subsequently incorporated within the Work.
+
+ 2. Grant of Copyright License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ copyright license to reproduce, prepare Derivative Works of,
+ publicly display, publicly perform, sublicense, and distribute the
+ Work and such Derivative Works in Source or Object form.
+
+ 3. Grant of Patent License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ (except as stated in this section) patent license to make, have made,
+ use, offer to sell, sell, import, and otherwise transfer the Work,
+ where such license applies only to those patent claims licensable
+ by such Contributor that are necessarily infringed by their
+ Contribution(s) alone or by combination of their Contribution(s)
+ with the Work to which such Contribution(s) was submitted. If You
+ institute patent litigation against any entity (including a
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
+ or a Contribution incorporated within the Work constitutes direct
+ or contributory patent infringement, then any patent licenses
+ granted to You under this License for that Work shall terminate
+ as of the date such litigation is filed.
+
+ 4. Redistribution. You may reproduce and distribute copies of the
+ Work or Derivative Works thereof in any medium, with or without
+ modifications, and in Source or Object form, provided that You
+ meet the following conditions:
+
+ (a) You must give any other recipients of the Work or
+ Derivative Works a copy of this License; and
+
+ (b) You must cause any modified files to carry prominent notices
+ stating that You changed the files; and
+
+ (c) You must retain, in the Source form of any Derivative Works
+ that You distribute, all copyright, patent, trademark, and
+ attribution notices from the Source form of the Work,
+ excluding those notices that do not pertain to any part of
+ the Derivative Works; and
+
+ (d) If the Work includes a "NOTICE" text file as part of its
+ distribution, then any Derivative Works that You distribute must
+ include a readable copy of the attribution notices contained
+ within such NOTICE file, excluding those notices that do not
+ pertain to any part of the Derivative Works, in at least one
+ of the following places: within a NOTICE text file distributed
+ as part of the Derivative Works; within the Source form or
+ documentation, if provided along with the Derivative Works; or,
+ within a display generated by the Derivative Works, if and
+ wherever such third-party notices normally appear. The contents
+ of the NOTICE file are for informational purposes only and
+ do not modify the License. You may add Your own attribution
+ notices within Derivative Works that You distribute, alongside
+ or as an addendum to the NOTICE text from the Work, provided
+ that such additional attribution notices cannot be construed
+ as modifying the License.
+
+ You may add Your own copyright statement to Your modifications and
+ may provide additional or different license terms and conditions
+ for use, reproduction, or distribution of Your modifications, or
+ for any such Derivative Works as a whole, provided Your use,
+ reproduction, and distribution of the Work otherwise complies with
+ the conditions stated in this License.
+
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
+ any Contribution intentionally submitted for inclusion in the Work
+ by You to the Licensor shall be under the terms and conditions of
+ this License, without any additional terms or conditions.
+ Notwithstanding the above, nothing herein shall supersede or modify
+ the terms of any separate license agreement you may have executed
+ with Licensor regarding such Contributions.
+
+ 6. Trademarks. This License does not grant permission to use the trade
+ names, trademarks, service marks, or product names of the Licensor,
+ except as required for reasonable and customary use in describing the
+ origin of the Work and reproducing the content of the NOTICE file.
+
+ 7. Disclaimer of Warranty. Unless required by applicable law or
+ agreed to in writing, Licensor provides the Work (and each
+ Contributor provides its Contributions) on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ implied, including, without limitation, any warranties or conditions
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+ PARTICULAR PURPOSE. You are solely responsible for determining the
+ appropriateness of using or redistributing the Work and assume any
+ risks associated with Your exercise of permissions under this License.
+
+ 8. Limitation of Liability. In no event and under no legal theory,
+ whether in tort (including negligence), contract, or otherwise,
+ unless required by applicable law (such as deliberate and grossly
+ negligent acts) or agreed to in writing, shall any Contributor be
+ liable to You for damages, including any direct, indirect, special,
+ incidental, or consequential damages of any character arising as a
+ result of this License or out of the use or inability to use the
+ Work (including but not limited to damages for loss of goodwill,
+ work stoppage, computer failure or malfunction, or any and all
+ other commercial damages or losses), even if such Contributor
+ has been advised of the possibility of such damages.
+
+ 9. Accepting Warranty or Additional Liability. While redistributing
+ the Work or Derivative Works thereof, You may choose to offer,
+ and charge a fee for, acceptance of support, warranty, indemnity,
+ or other liability obligations and/or rights consistent with this
+ License. However, in accepting such obligations, You may act only
+ on Your own behalf and on Your sole responsibility, not on behalf
+ of any other Contributor, and only if You agree to indemnify,
+ defend, and hold each Contributor harmless for any liability
+ incurred by, or claims asserted against, such Contributor by reason
+ of your accepting any such warranty or additional liability.
+
+ END OF TERMS AND CONDITIONS
+
+ APPENDIX: How to apply the Apache License to your work.
+
+ To apply the Apache License to your work, attach the following
+ boilerplate notice, with the fields enclosed by brackets "[]"
+ replaced with your own identifying information. (Don't include
+ the brackets!) The text should be enclosed in the appropriate
+ comment syntax for the file format. We also recommend that a
+ file or class name and description of purpose be included on the
+ same "printed page" as the copyright notice for easier
+ identification within third-party archives.
+
+ Copyright [yyyy] [name of copyright owner]
+
+ 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.
diff --git a/scrplugin/ds-annotations/NOTICE b/scrplugin/ds-annotations/NOTICE
new file mode 100644
index 0000000..bed91c8
--- /dev/null
+++ b/scrplugin/ds-annotations/NOTICE
@@ -0,0 +1,6 @@
+Apache Felix SCR DS Annotations
+Copyright 2012 The Apache Software Foundation
+
+This product includes software developed at
+The Apache Software Foundation (http://www.apache.org/).
+Licensed under the Apache License 2.0.
diff --git a/scrplugin/ds-annotations/pom.xml b/scrplugin/ds-annotations/pom.xml
new file mode 100644
index 0000000..fb3e1ac
--- /dev/null
+++ b/scrplugin/ds-annotations/pom.xml
@@ -0,0 +1,92 @@
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied. See the License for the
+ specific language governing permissions and limitations
+ under the License.
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <artifactId>felix-parent</artifactId>
+ <groupId>org.apache.felix</groupId>
+ <version>1.2.0</version>
+ <relativePath>../pom/pom.xml</relativePath>
+ </parent>
+
+ <groupId>org.apache.felix</groupId>
+ <artifactId>org.apache.felix.scr.ds-annotations</artifactId>
+
+ <!-- We use the same major version as the spec. -->
+ <version>1.2.0-SNAPSHOT</version>
+ <packaging>jar</packaging>
+
+ <name>Annotations for DS</name>
+ <description>
+ Annotations for generating OSGi service descriptors.
+ </description>
+
+ <scm>
+ <connection>scm:svn:http://svn.apache.org/repos/asf/felix/trunk/scrplugin/ds-annotations</connection>
+ <developerConnection>scm:svn:https://svn.apache.org/repos/asf/felix/trunk/scrplugin/ds-annotations</developerConnection>
+ <url>http://svn.apache.org/repos/asf/felix/scrplugin/ds-annotations</url>
+ </scm>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>org.apache.felix.scr.generator</artifactId>
+ <version>1.2.0-SNAPSHOT</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.osgi</groupId>
+ <artifactId>org.osgi.compendium</artifactId>
+ <version>4.3.0</version>
+ <scope>provided</scope>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <resources>
+ <resource>
+ <directory>${basedir}/src/main/resources</directory>
+ </resource>
+ <resource>
+ <targetPath>META-INF</targetPath>
+ <directory>${basedir}</directory>
+ <includes>
+ <include>LICENSE</include>
+ <include>NOTICE</include>
+ <include>DEPENDENCIES</include>
+ </includes>
+ </resource>
+ </resources>
+ <plugins>
+
+ <!-- JDK 1.5 needed for annotation support -->
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <configuration>
+ <source>1.5</source>
+ <target>1.5</target>
+ </configuration>
+ </plugin>
+
+ </plugins>
+ </build>
+
+</project>
diff --git a/scrplugin/ds-annotations/src/main/java/org/apache/felix/scrplugin/ds/DSAnnotationProcessor.java b/scrplugin/ds-annotations/src/main/java/org/apache/felix/scrplugin/ds/DSAnnotationProcessor.java
new file mode 100644
index 0000000..780bf70
--- /dev/null
+++ b/scrplugin/ds-annotations/src/main/java/org/apache/felix/scrplugin/ds/DSAnnotationProcessor.java
@@ -0,0 +1,274 @@
+/*
+ * 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.scrplugin.ds;
+
+import java.lang.reflect.Method;
+import java.lang.reflect.Modifier;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.felix.scrplugin.SCRDescriptorException;
+import org.apache.felix.scrplugin.SCRDescriptorFailureException;
+import org.apache.felix.scrplugin.annotations.AnnotationProcessor;
+import org.apache.felix.scrplugin.annotations.ClassAnnotation;
+import org.apache.felix.scrplugin.annotations.MethodAnnotation;
+import org.apache.felix.scrplugin.annotations.ScannedClass;
+import org.apache.felix.scrplugin.description.ClassDescription;
+import org.apache.felix.scrplugin.description.ComponentConfigurationPolicy;
+import org.apache.felix.scrplugin.description.ComponentDescription;
+import org.apache.felix.scrplugin.description.MethodDescription;
+import org.apache.felix.scrplugin.description.ReferenceCardinality;
+import org.apache.felix.scrplugin.description.ReferenceDescription;
+import org.apache.felix.scrplugin.description.ReferencePolicy;
+import org.apache.felix.scrplugin.description.ReferenceStrategy;
+import org.apache.felix.scrplugin.description.ServiceDescription;
+import org.apache.felix.scrplugin.description.SpecVersion;
+import org.osgi.service.component.annotations.Activate;
+import org.osgi.service.component.annotations.Component;
+import org.osgi.service.component.annotations.Deactivate;
+import org.osgi.service.component.annotations.Modified;
+import org.osgi.service.component.annotations.Reference;
+
+/**
+ * This is the processor for the DS annotations.
+ */
+public class DSAnnotationProcessor implements AnnotationProcessor {
+
+ /**
+ * @see org.apache.felix.scrplugin.annotations.AnnotationProcessor#process(org.apache.felix.scrplugin.annotations.ScannedClass, org.apache.felix.scrplugin.description.ClassDescription)
+ */
+ public void process(final ScannedClass scannedClass,
+ final ClassDescription describedClass)
+ throws SCRDescriptorFailureException, SCRDescriptorException {
+ final List<ClassAnnotation> componentTags = scannedClass.getClassAnnotations(Component.class.getName());
+ scannedClass.processed(componentTags);
+
+ for (final ClassAnnotation cad : componentTags) {
+ this.createComponent(cad, describedClass, scannedClass);
+ }
+
+ // search for the component descriptions and use the first one
+ final List<ComponentDescription> componentDescs = describedClass.getDescriptions(ComponentDescription.class);
+ ComponentDescription found = null;
+ if (!componentDescs.isEmpty()) {
+ found = componentDescs.get(0);
+ }
+
+ if (found != null) {
+ final ComponentDescription cd = found;
+
+ // search for methods
+ final List<MethodAnnotation> methodTags = scannedClass.getMethodAnnotations(null);
+ for (final MethodAnnotation m : methodTags) {
+ if (m.getName().equals(Activate.class.getName())) {
+ cd.setActivate(new MethodDescription(m.getAnnotatedMethod()));
+ scannedClass.processed(m);
+ } else if (m.getName().equals(Deactivate.class.getName())) {
+ cd.setDeactivate(new MethodDescription(m.getAnnotatedMethod()));
+ scannedClass.processed(m);
+ } else if (m.getName().equals(Modified.class.getName())) {
+ cd.setModified(new MethodDescription(m.getAnnotatedMethod()));
+ scannedClass.processed(m);
+ } else if (m.getName().equals(Reference.class.getName()) ) {
+ this.processReference(describedClass, m);
+ scannedClass.processed(m);
+ }
+ }
+
+ }
+ }
+
+ /**
+ * @see org.apache.felix.scrplugin.annotations.AnnotationProcessor#getRanking()
+ */
+ public int getRanking() {
+ return 300;
+ }
+
+ /**
+ * Create a component description.
+ *
+ * @param cad The component annotation for the class.
+ * @param scannedClass The scanned class.
+ */
+ private ComponentDescription createComponent(final ClassAnnotation cad,
+ final ClassDescription describedClass,
+ final ScannedClass scannedClass)
+ throws SCRDescriptorException {
+ final ComponentDescription component = new ComponentDescription(cad);
+ describedClass.add(component);
+
+ // Although not defined in the spec, we support abstract classes.
+ final boolean classIsAbstract = Modifier.isAbstract(scannedClass.getClass().getModifiers());
+ component.setAbstract(classIsAbstract);
+
+ // name
+ component.setName(cad.getStringValue("name", scannedClass.getScannedClass().getName()));
+
+ // services
+ final List<String> listedInterfaces = new ArrayList<String>();
+ if (cad.getValue("service") != null) {
+ final String[] interfaces = (String[]) cad.getValue("service");
+ for (final String t : interfaces) {
+ listedInterfaces.add(t);
+ }
+ } else {
+ // scan directly implemented interfaces
+ this.searchInterfaces(listedInterfaces, scannedClass.getScannedClass());
+ }
+ if ( listedInterfaces.size() > 0 ) {
+ final ServiceDescription serviceDesc = new ServiceDescription(cad);
+ describedClass.add(serviceDesc);
+
+ for(final String name : listedInterfaces) {
+ serviceDesc.addInterface(name);
+ }
+ serviceDesc.setServiceFactory(cad.getBooleanValue("servicefactory", false));
+ }
+
+ // factory
+ component.setFactory(cad.getStringValue("factory", null));
+
+ // enabled
+ if (cad.getValue("enabled") != null) {
+ component.setEnabled(cad.getBooleanValue("enabled", true));
+ }
+
+ // immediate
+ if (cad.getValue("immediate") != null) {
+ component.setEnabled(cad.getBooleanValue("immediate", false));
+ }
+
+ // TODO: property/properties
+
+ // xmlns
+ if (cad.getValue("xmlns") != null) {
+ final SpecVersion spec = SpecVersion.fromNamespaceUrl(cad.getValue("xmlns").toString());
+ if ( spec == null ) {
+ throw new SCRDescriptorException("Unknown xmlns attribute value: " + cad.getValue("xmlns"),
+ describedClass.getSource(), -1);
+ }
+ component.setSpecVersion(spec);
+ }
+
+ // configuration policy
+ component.setConfigurationPolicy(ComponentConfigurationPolicy.valueOf(cad.getEnumValue("policy",
+ ComponentConfigurationPolicy.OPTIONAL.name())));
+
+ // configuration pid (TODO)
+ component.setCreatePid(cad.getBooleanValue("createPid", true));
+
+ // no inheritance
+ component.setInherit(false);
+
+ return component;
+ }
+
+ /**
+ * Get all directly implemented interfaces
+ */
+ private void searchInterfaces(final List<String> interfaceList, final Class<?> javaClass) {
+ final Class<?>[] interfaces = javaClass.getInterfaces();
+ for (final Class<?> i : interfaces) {
+ interfaceList.add(i.getName());
+ }
+ }
+
+ /**
+ * Process a reference
+ */
+ private void processReference(final ClassDescription describedClass, final MethodAnnotation ad) {
+ final ReferenceDescription ref = new ReferenceDescription(ad);
+ describedClass.add(ref);
+
+ ref.setStrategy(ReferenceStrategy.EVENT);
+
+ final String methodName = ad.getAnnotatedMethod().getName();
+ final String defaultUnbindMethodName;
+ final String refNameByMethod;
+ if ( methodName.startsWith("add") ) {
+ refNameByMethod = methodName.substring(3);
+ defaultUnbindMethodName = "remove" + refNameByMethod;
+ } else if ( methodName.startsWith("set") ) {
+ refNameByMethod = methodName.substring(3);
+ defaultUnbindMethodName = "un" + refNameByMethod;
+ } else if ( methodName.startsWith("bind") ) {
+ refNameByMethod = methodName.substring(4);
+ defaultUnbindMethodName = "un" + refNameByMethod;
+ } else {
+ refNameByMethod = methodName;
+ defaultUnbindMethodName = "un" + refNameByMethod;
+ }
+ final String defaultUpdateMethodName = "updated" + refNameByMethod;
+
+ // bind method
+ ref.setBind(new MethodDescription(ad.getAnnotatedMethod()));
+ // unbind method
+ final String unbind = ad.getStringValue("unbind",
+ this.hasMethod(describedClass, defaultUnbindMethodName) ? defaultUnbindMethodName : "-");
+ if ( !unbind.equals("-") ) {
+ ref.setUnbind(new MethodDescription(unbind));
+ }
+ // update method
+ final String update = ad.getStringValue("updated",
+ this.hasMethod(describedClass, defaultUpdateMethodName) ? defaultUpdateMethodName : "-");
+ if ( !update.equals("-") ) {
+ ref.setUpdated(new MethodDescription(update));
+ }
+
+ // name
+ ref.setName(ad.getStringValue("name", refNameByMethod));
+ // service
+ final String serviceName = ad.getStringValue("service", null);
+ if ( serviceName != null ) {
+ ref.setInterfaceName(serviceName);
+ } else {
+ final Class<?>[] params = ad.getAnnotatedMethod().getParameterTypes();
+ if ( params != null && params.length > 0 ) {
+ ref.setInterfaceName(params[0].getName());
+ }
+ }
+ // cardinality
+ final String cardinality = ad.getEnumValue("cardinality", "MANDATORY");
+ if ( cardinality.equals("OPTIONAL") ) {
+ ref.setCardinality(ReferenceCardinality.OPTIONAL_UNARY);
+ } else if ( cardinality.equals("MULTIPLE") ) {
+ ref.setCardinality(ReferenceCardinality.OPTIONAL_MULTIPLE);
+ } else if ( cardinality.equals("AT_LEAST_ONE") ) {
+ ref.setCardinality(ReferenceCardinality.MANDATORY_MULTIPLE);
+ } else {
+ ref.setCardinality(ReferenceCardinality.MANDATORY_UNARY);
+ }
+
+ // policy
+ ref.setPolicy(ReferencePolicy.valueOf(ad.getEnumValue("policy", ReferencePolicy.STATIC.name())));
+ // target
+ ref.setTarget(ad.getStringValue("target", null));
+ }
+
+ private boolean hasMethod(final ClassDescription classDescription, final String name) {
+ final Method[] allMethods = classDescription.getDescribedClass().getDeclaredMethods();
+ for(final Method m : allMethods) {
+ if ( m.getName().equals(name) ) {
+ return true;
+ }
+ }
+ return false;
+ }
+}
diff --git a/scrplugin/ds-annotations/src/main/resources/META-INF/services/org.apache.felix.scrplugin.annotations.AnnotationProcessor b/scrplugin/ds-annotations/src/main/resources/META-INF/services/org.apache.felix.scrplugin.annotations.AnnotationProcessor
new file mode 100644
index 0000000..8303823
--- /dev/null
+++ b/scrplugin/ds-annotations/src/main/resources/META-INF/services/org.apache.felix.scrplugin.annotations.AnnotationProcessor
@@ -0,0 +1 @@
+org.apache.felix.scrplugin.ds.DSAnnotationProcessor
diff --git a/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/description/ReferenceDescription.java b/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/description/ReferenceDescription.java
index 03d8b09..b7c18eb 100644
--- a/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/description/ReferenceDescription.java
+++ b/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/description/ReferenceDescription.java
@@ -35,11 +35,11 @@
* <li>cardinality</li>
* <li>policy</li>
* <li>strategy</li>
- * <li>field</li>
* </ul>
*
* These values have the following default values:
* <ul>
+ * <li>field : null</li>
* <li>bind : null</li>
* <li>unbind : null</li>
* <li>updated : null</li>
diff --git a/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/description/SpecVersion.java b/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/description/SpecVersion.java
index 1f0d11a..21558d8 100644
--- a/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/description/SpecVersion.java
+++ b/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/description/SpecVersion.java
@@ -16,9 +16,9 @@
public enum SpecVersion {
- VERSION_1_0("1.0"), // R4.1
- VERSION_1_1("1.1"), // R4.2
- VERSION_1_1_FELIX("1.1_FELIX"); // R4.2 + FELIX-1893
+ VERSION_1_0("1.0", "http://www.osgi.org/xmlns/scr/v1.0.0"), // R4.1
+ VERSION_1_1("1.1", "http://www.osgi.org/xmlns/scr/v1.1.0"), // R4.2
+ VERSION_1_1_FELIX("1.1_FELIX", "http://felix.apache.org/xmlns/scr/v1.1.0-felix"); // R4.2 + FELIX-1893
/**
* internal human readable name
@@ -26,12 +26,19 @@
private final String name;
/**
+ * Namespace url
+ */
+ private final String namespaceUrl;
+
+ /**
* Create a type
*
- * @param name name
+ * @param name A human readable name
+ * @param namespaceUrl The namespace URL for this spec version
*/
- private SpecVersion(final String name) {
+ private SpecVersion(final String name, final String namespaceUrl) {
this.name = name;
+ this.namespaceUrl = namespaceUrl;
}
/**
@@ -44,7 +51,15 @@
}
/**
- * Creates a version for the given name. if the name cannot be mapped
+ * Return the namespace url.
+ * @return The namespace url.
+ */
+ public String getNamespaceUrl() {
+ return this.namespaceUrl;
+ }
+
+ /**
+ * Creates a version for the given name. If the name cannot be mapped
* to a enum type or if it's <code>null</code>, <code>null</code> is
* returned.
*
@@ -67,4 +82,24 @@
}
return null;
}
+
+ /**
+ * Creates a version for the given url. If the url cannot be mapped
+ * to a enum type or if it's <code>null</code>, <code>null</code> is
+ * returned.
+ *
+ * @param n the url
+ * @return the type or <code>null</code>
+ */
+ public static SpecVersion fromNamespaceUrl(final String n) {
+ if (n == null) {
+ return null;
+ }
+ for(final SpecVersion sv : SpecVersion.values() ) {
+ if ( sv.getNamespaceUrl().equals(n)) {
+ return sv;
+ }
+ }
+ return null;
+ }
}
diff --git a/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/xml/ComponentDescriptorIO.java b/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/xml/ComponentDescriptorIO.java
index 33d1c97..7ea5bc9 100644
--- a/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/xml/ComponentDescriptorIO.java
+++ b/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/xml/ComponentDescriptorIO.java
@@ -61,15 +61,6 @@
*/
public class ComponentDescriptorIO {
- /** The namespace for R4.1 - Version 1.0 */
- public static final String NAMESPACE_URI_1_0 = "http://www.osgi.org/xmlns/scr/v1.0.0";
-
- /** The namespace for R4.2 - Version 1.1 */
- public static final String NAMESPACE_URI_1_1 = "http://www.osgi.org/xmlns/scr/v1.1.0";
-
- /** The namespace for R4.2+FELIX-1893 - Version 1.1-felix */
- public static final String NAMESPACE_URI_1_1_FELIX = "http://felix.apache.org/xmlns/scr/v1.1.0-felix";
-
/** The inner namespace - used for all inner elements. */
public static final String INNER_NAMESPACE_URI = "";
@@ -170,14 +161,8 @@
*/
protected static void generateXML(Components components, ContentHandler contentHandler) throws SAXException {
// detect namespace to use
- final String namespace;
- if (components.getSpecVersion() == SpecVersion.VERSION_1_0) {
- namespace = NAMESPACE_URI_1_0;
- } else if (components.getSpecVersion() == SpecVersion.VERSION_1_1) {
- namespace = NAMESPACE_URI_1_1;
- } else {
- namespace = NAMESPACE_URI_1_1_FELIX;
- }
+ final String namespace = components.getSpecVersion().getNamespaceUrl();
+
contentHandler.startDocument();
contentHandler.startPrefixMapping(PREFIX, namespace);
@@ -213,7 +198,7 @@
IOUtils.addAttribute(ai, COMPONENT_ATTR_FACTORY, component.getFactory());
// attributes new in 1.1
- if (NAMESPACE_URI_1_1.equals(namespace) || NAMESPACE_URI_1_1_FELIX.equals(namespace)) {
+ if (SpecVersion.VERSION_1_1.getNamespaceUrl().equals(namespace) || SpecVersion.VERSION_1_1_FELIX.getNamespaceUrl().equals(namespace)) {
if ( component.getConfigurationPolicy() != ComponentConfigurationPolicy.OPTIONAL ) {
IOUtils.addAttribute(ai, COMPONENT_ATTR_POLICY, component.getConfigurationPolicy().name());
}
@@ -350,7 +335,7 @@
IOUtils.addAttribute(ai, "unbind", reference.getUnbind());
// attributes new in 1.1-felix (FELIX-1893)
- if (NAMESPACE_URI_1_1_FELIX.equals(namespace)) {
+ if (SpecVersion.VERSION_1_1_FELIX.getNamespaceUrl().equals(namespace)) {
IOUtils.addAttribute(ai, "updated", reference.getUpdated());
}
@@ -420,7 +405,7 @@
if (this.firstElement) {
this.firstElement = false;
if (localName.equals(COMPONENT) && "".equals(uri)) {
- this.overrideNamespace = NAMESPACE_URI_1_0;
+ this.overrideNamespace = SpecVersion.VERSION_1_0.getNamespaceUrl();
}
}
@@ -432,19 +417,12 @@
// of a component are unqualified, so they don't have
// the namespace - we allow both: with or without namespace!
if (this.isComponent && "".equals(uri)) {
- uri = NAMESPACE_URI_1_0;
+ uri = SpecVersion.VERSION_1_0.getNamespaceUrl();
}
// from here on, uri has the namespace regardless of the used xml format
- if (NAMESPACE_URI_1_0.equals(uri) || NAMESPACE_URI_1_1.equals(uri) || NAMESPACE_URI_1_1_FELIX.equals(uri)) {
-
- if (NAMESPACE_URI_1_0.equals(uri)) {
- specVersion = SpecVersion.VERSION_1_0;
- } else if (NAMESPACE_URI_1_1.equals(uri)) {
- specVersion = SpecVersion.VERSION_1_1;
- } else if (NAMESPACE_URI_1_1_FELIX.equals(uri)) {
- specVersion = SpecVersion.VERSION_1_1_FELIX;
- }
+ specVersion = SpecVersion.fromNamespaceUrl(uri);
+ if (specVersion != null) {
if (localName.equals(COMPONENT)) {
this.isComponent = true;
@@ -601,10 +579,10 @@
}
if (this.isComponent && "".equals(uri)) {
- uri = NAMESPACE_URI_1_0;
+ uri = SpecVersion.VERSION_1_0.getNamespaceUrl();
}
- if (NAMESPACE_URI_1_0.equals(uri) || NAMESPACE_URI_1_1.equals(uri) || NAMESPACE_URI_1_1_FELIX.equals(uri)) {
+ if (SpecVersion.fromNamespaceUrl(uri) != null) {
if (localName.equals(COMPONENT)) {
this.currentClass = null;
this.currentComponent = null;