FELIX-1010 : Add annotations support for SCR plugin. Apply patch from Stefan Seifert
git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@760528 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/scrplugin-annotations/LICENSE b/scrplugin-annotations/LICENSE
new file mode 100644
index 0000000..d645695
--- /dev/null
+++ b/scrplugin-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-annotations/NOTICE b/scrplugin-annotations/NOTICE
new file mode 100644
index 0000000..776aef1
--- /dev/null
+++ b/scrplugin-annotations/NOTICE
@@ -0,0 +1,21 @@
+Apache Felix SCR Maven Plugin Annotations
+Copyright 2007-2009 The Apache Software Foundation
+
+
+I. Included Software
+
+This product includes software developed at
+The Apache Software Foundation (http://www.apache.org/).
+Licensed under the Apache License 2.0.
+
+
+II. Used Software
+
+This product uses software developed at
+The Apache Software Foundation (http://www.apache.org/).
+Licensed under the Apache License 2.0.
+
+This product uses software developed at
+The OSGi Alliance (http://www.osgi.org/).
+Copyright 2006 The OSGi Alliance.
+Licensed under the Apache License 2.0.
diff --git a/scrplugin-annotations/pom.xml b/scrplugin-annotations/pom.xml
new file mode 100644
index 0000000..e8417cc
--- /dev/null
+++ b/scrplugin-annotations/pom.xml
@@ -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.
+-->
+<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</artifactId>
+ <groupId>org.apache.felix</groupId>
+ <version>1.0.4</version>
+ </parent>
+
+ <groupId>org.apache.felix</groupId>
+ <artifactId>maven-scr-plugin-annotations</artifactId>
+
+ <version>1.0.11-SNAPSHOT</version>
+ <packaging>jar</packaging>
+
+ <name>Annotations for Maven SCR Plugin</name>
+ <description>
+ Annotations for generating OSGi service descriptors with Maven SCR plugin.
+ </description>
+
+ <scm>
+ <connection>scm:svn:http://svn.apache.org/repos/asf/felix/trunk/scrplugin-annotations</connection>
+ <developerConnection>scm:svn:http://svn.apache.org/repos/asf/felix/trunk/scrplugin-annotations</developerConnection>
+ <url>http://svn.apache.org/repos/asf/felix/scrplugin-annotations</url>
+ </scm>
+
+ <build>
+ <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-annotations/src/main/java/org/apache/felix/scrplugin/annotations/AutoDetect.java b/scrplugin-annotations/src/main/java/org/apache/felix/scrplugin/annotations/AutoDetect.java
new file mode 100644
index 0000000..125e56a
--- /dev/null
+++ b/scrplugin-annotations/src/main/java/org/apache/felix/scrplugin/annotations/AutoDetect.java
@@ -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.scrplugin.annotations;
+
+/**
+ * Placeholder class for default value of annotation properties with
+ * "auto detect" capabilities.
+ */
+public final class AutoDetect {
+
+ private AutoDetect() {
+ // disallows instancing this class
+ }
+
+}
diff --git a/scrplugin-annotations/src/main/java/org/apache/felix/scrplugin/annotations/Component.java b/scrplugin-annotations/src/main/java/org/apache/felix/scrplugin/annotations/Component.java
new file mode 100644
index 0000000..ce4625d
--- /dev/null
+++ b/scrplugin-annotations/src/main/java/org/apache/felix/scrplugin/annotations/Component.java
@@ -0,0 +1,113 @@
+/*
+ * 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.annotations;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+/**
+ * The <code>Component</code> annotation is the only required annotation. If
+ * this annotation is not declared in a Java class, the class is not declared as
+ * a component.
+ * <p>
+ * This annotation is used to declare the <component> element of the
+ * component declaration. See section 112.4.3, Component Element, in the OSGi
+ * Service Platform Service Compendium Specification for more information. The
+ * required <implementation> element is automatically generated with the
+ * fully qualified name of the class containing the <code>Component</code>
+ * annotation.
+ * </p>
+ */
+@Target(ElementType.TYPE)
+@Retention(RetentionPolicy.RUNTIME)
+public @interface Component {
+
+ /**
+ * Defines the Component name also used as the PID for the Configuration
+ * Admin Service. Default value: Fully qualified name of the Java class.
+ */
+ String name() default "";
+
+ /**
+ * This is generally used as a title for the object described by the meta
+ * type. This name may be localized by prepending a % sign to the name.
+ * Default value: %<name>.name
+ */
+ String label() default "";
+
+ /**
+ * This is generally used as a description for the object described by the
+ * meta type. This name may be localized by prepending a % sign to the name.
+ * Default value: %<name>.name
+ */
+ String description() default "";
+
+ /**
+ * Whether the component is enabled when the bundle starts.
+ */
+ boolean enabled() default true;
+
+ /**
+ * Whether the component is a factory component.
+ */
+ String factory() default "";
+
+ /**
+ * Whether the component is immediately activated.
+ */
+ boolean immediate() default false;
+
+ /**
+ * Whether any service, property and reference declarations from base
+ * classes should be inherited by this class.
+ */
+ boolean inherit() default true;
+
+ /**
+ * Whether Metatype Service data is generated or not. If this parameter is
+ * not set or set to true Metatype Service data is generated in the
+ * <code>metatype.xml</code> file for this component. Otherwise no Metatype
+ * Service data is generated for this component.
+ */
+ boolean metatype() default true;
+
+ /**
+ * This marks an abstract service description which is not added to the
+ * descriptor but intended for reuse through inheritance. This attribute
+ * defaults to true for abstract classes and false for concrete classes.
+ */
+ boolean componentAbstract() default false;
+
+ /**
+ * Whether Declarative Services descriptor is generated or not. If this
+ * parameter is not set or set to true the Declarative Services descriptor
+ * is generated in the service descriptor file for this component. Otherwise
+ * no Declarative Services descriptor is generated for this component.
+ */
+ boolean ds() default true;
+
+ /**
+ * Generated <code>service.pid</code> property by default, if none declared
+ * explicitly.
+ */
+ boolean createPid() default true;
+
+}
diff --git a/scrplugin-annotations/src/main/java/org/apache/felix/scrplugin/annotations/Properties.java b/scrplugin-annotations/src/main/java/org/apache/felix/scrplugin/annotations/Properties.java
new file mode 100644
index 0000000..0c72e30
--- /dev/null
+++ b/scrplugin-annotations/src/main/java/org/apache/felix/scrplugin/annotations/Properties.java
@@ -0,0 +1,40 @@
+/*
+ * 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.annotations;
+
+import java.lang.annotation.Documented;
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+/**
+ * Allows to define multiple {@link Property} annotations for one type.
+ */
+@Target(ElementType.TYPE)
+@Retention(RetentionPolicy.RUNTIME)
+@Documented
+public @interface Properties {
+
+ /**
+ * List of {@link Property} annotations.
+ */
+ Property[] value();
+
+}
diff --git a/scrplugin-annotations/src/main/java/org/apache/felix/scrplugin/annotations/Property.java b/scrplugin-annotations/src/main/java/org/apache/felix/scrplugin/annotations/Property.java
new file mode 100644
index 0000000..ab6a4cc
--- /dev/null
+++ b/scrplugin-annotations/src/main/java/org/apache/felix/scrplugin/annotations/Property.java
@@ -0,0 +1,124 @@
+/*
+ * 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.annotations;
+
+import java.lang.annotation.Documented;
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+/**
+ * The <code>Property</code> annotation defines properties which are made
+ * available to the component through the ComponentContext.getProperties()
+ * method. These annotations are not strictly required but may be used by
+ * components to defined initial configuration. Additionally properties may be
+ * set here to identify the component if it is registered as a service, for
+ * example the service.description and service.vendor properties.
+ * <p>
+ * This tag is used to declare <property> elements of the component
+ * declaration. See section 112.4.5, Properties and Property Elements, in the
+ * OSGi Service Platform Service Compendium Specification for more information.
+ */
+@Target(ElementType.TYPE)
+@Retention(RetentionPolicy.RUNTIME)
+@Documented
+public @interface Property {
+
+ /**
+ * The name of the property
+ */
+ String name();
+
+ /**
+ * The label to display in a form to configure this property. This name may
+ * be localized by prepending a % sign to the name. Default value:
+ * %<name>.name
+ */
+ String label() default "";
+
+ /**
+ * A descriptive text to provide the client in a form to configure this
+ * property. This name may be localized by prepending a % sign to the name.
+ * Default value: %<name>.description
+ */
+ String description() default "";
+
+ /**
+ * The value(s) of the property. If the property type is not String, parsing
+ * of the value is done using the valueOf(String) method of the class
+ * defined by the property type.
+ */
+ String[] value();
+
+ /**
+ * The type of the property value. This must be one of {@link String},
+ * {@link Long}, {@link Double}, {@link Float}, {@link Integer},
+ * {@link Byte}, {@link Character}, {@link Boolean} and {@link Short}.
+ */
+ Class type() default AutoDetect.class;
+
+ /**
+ * Defines the cardinality of the property and its collection type. If the
+ * cardinality is negative, the property is expected to be stored in a
+ * {@link java.util.Vector} (primitive types such as boolean are boxed in
+ * the Wrapper class), if the cardinality is positive, the property is
+ * stored in an array (primitve types are unboxed, that is Boolean type
+ * values are stored in boolean[]). The actual value defines the maximum
+ * number of elements in the vector or array, where Integer.MIN_INT
+ * describes an unbounded Vector and Integer.MAX_INT describes an unbounded
+ * array. If the cardinality is zero, the property is a scalar value. If the
+ * defined value of the property is set in the value attribute, the
+ * cardinality defaults to 0 (zero for scalar value). If the property is
+ * defined in one or more properties starting with values, the cardinality
+ * defaults to Integer.MAX_INT, that is an unbounded array.
+ */
+ int cardinality() default 0;
+
+ /**
+ * Boolean flag defining whether a metatype descriptor entry should be
+ * generated for this property or not. By default a metatype descriptor
+ * entry, i.e. an AD element, is generated except for the properties
+ * <code>service.pid</code>, <code>service.description</code>,
+ * <code>service.id</code>, <code>service.ranking</code>,
+ * <code>service.vendor</code>, <code>service.bundlelocation</code> and
+ * <code>service.factoryPid</code>. If a property should not be available
+ * for display in a configuration user interface, this parameter should be
+ * set to true.
+ */
+ boolean propertyPrivate() default false;
+
+ /**
+ * Some properties may only be set to a set of possible values. To support
+ * user interfaces which provide a selection list of values or a list of
+ * checkboxes the option values and labels may be defined as parameters to
+ * the {@link Property} annotation. All parameters in the form of name-value
+ * pairs are used to build the list of available value options. The
+ * parameter name is used as the value while the parameter value is used as
+ * the label in the user interface. This label may be prepended with a %
+ * sign to localize the string.
+ * <p>
+ * The options are written to the metatype.xml file as Option elements
+ * inside the AD element defining the property. The name of the parameter
+ * will be used for the Option.value attribute while the value of the
+ * parameter defines the Option.label attribute.
+ */
+ PropertyOption[] options() default {};
+
+}
diff --git a/scrplugin-annotations/src/main/java/org/apache/felix/scrplugin/annotations/PropertyOption.java b/scrplugin-annotations/src/main/java/org/apache/felix/scrplugin/annotations/PropertyOption.java
new file mode 100644
index 0000000..07b5b26
--- /dev/null
+++ b/scrplugin-annotations/src/main/java/org/apache/felix/scrplugin/annotations/PropertyOption.java
@@ -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.scrplugin.annotations;
+
+import java.lang.annotation.Documented;
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+/**
+ * Defines a {@link Property} option.
+ */
+@Target(ElementType.ANNOTATION_TYPE)
+@Retention(RetentionPolicy.RUNTIME)
+@Documented
+public @interface PropertyOption {
+
+ /**
+ * Name of the option
+ */
+ String name();
+
+ /**
+ * Value of the option
+ */
+ String value();
+
+}
diff --git a/scrplugin-annotations/src/main/java/org/apache/felix/scrplugin/annotations/Reference.java b/scrplugin-annotations/src/main/java/org/apache/felix/scrplugin/annotations/Reference.java
new file mode 100644
index 0000000..e0daac0
--- /dev/null
+++ b/scrplugin-annotations/src/main/java/org/apache/felix/scrplugin/annotations/Reference.java
@@ -0,0 +1,112 @@
+/*
+ * 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.annotations;
+
+import java.lang.annotation.Documented;
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+/**
+ * The <code>Reference</code> annotation defines references to other services
+ * made available to the component by the Service Component Runtime.
+ * <p>
+ * This annotation may be declared for a Java Class or any Java Field to which
+ * it might apply. Depending on where the annotation is declared, the parameters
+ * may have different default values.
+ * <p>
+ * This annotation is used to declare <reference> elements of the
+ * component declaration. See section 112.4.7, Reference Element, in the OSGi
+ * Service Platform Service Compendium Specification for more information.
+ */
+@Target( { ElementType.TYPE, ElementType.FIELD })
+@Retention(RetentionPolicy.RUNTIME)
+@Documented
+public @interface Reference {
+
+ /**
+ * The local name of the reference. If the annotation is declared on class
+ * level, this parameter is required. If the tag is declared for a field,
+ * the default value for the name parameter is the name of the field.
+ */
+ String name() default "";
+
+ /**
+ * The name of the service interface. This name is used by the Service
+ * Component Runtime to access the service on behalf of the component. If
+ * the annotation is declared on class level, this parameter is required. If
+ * the annotation is declared for a field, the default value for the
+ * interface parameter is the type of the field.
+ */
+ Class referenceInterface() default AutoDetect.class;
+
+ /**
+ * The cardinality of the service reference. This must be one of 0..1, 1..1,
+ * 0..n, and 1..n.
+ */
+ ReferenceCardinality cardinality() default ReferenceCardinality.ONE_TO_ONE;
+
+ /**
+ * The dynamicity policy of the reference. If dynamic the service will be
+ * made available to the component as it comes and goes. If static the
+ * component will be deactivated and re-activated if the service comes
+ * and/or goes away.
+ */
+ ReferencePolicy policy() default ReferencePolicy.STATIC;
+
+ /**
+ * A service target filter to select specific services to be made available.
+ * In order to be able to overwrite the value of this value by a
+ * configuration property, this parameter must be declared. If the parameter
+ * is not declared, the respective declaration attribute will not be
+ * generated.
+ */
+ String target() default "";
+
+ /**
+ * The name of the method to be called when the service is to be bound to
+ * the component. The default value is the name created by appending the
+ * reference name to the string bind. The method must be declared
+ * <code>public</code> or <code>protected</code> and take single argument
+ * which is declared with the service interface type.
+ */
+ String bind() default "";
+
+ /**
+ * The name of the method to be called when the service is to be unbound
+ * from the component. The default value is the name created by appending
+ * the reference name to the string unbind. The method must be declared
+ * <code>public</code> or <code>protected</code> and take single argument
+ * which is declared with the service interface type.
+ */
+ String unbind() default "";
+
+ /**
+ * TODO: parameter documentation missing
+ */
+ boolean checked() default false;
+
+ /**
+ * TODO: parameter documentation missing
+ * @since 1.0.9
+ */
+ String strategy() default "";
+
+}
diff --git a/scrplugin-annotations/src/main/java/org/apache/felix/scrplugin/annotations/ReferenceCardinality.java b/scrplugin-annotations/src/main/java/org/apache/felix/scrplugin/annotations/ReferenceCardinality.java
new file mode 100644
index 0000000..fea82f7
--- /dev/null
+++ b/scrplugin-annotations/src/main/java/org/apache/felix/scrplugin/annotations/ReferenceCardinality.java
@@ -0,0 +1,59 @@
+/*
+ * 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.annotations;
+
+/**
+ * Options for {@link Reference#cardinality()} property.
+ */
+public enum ReferenceCardinality {
+
+ /**
+ * Cardinality 0..1
+ */
+ ZERO_TO_ONE("0..1"),
+
+ /**
+ * Cardinality 1..1
+ */
+ ONE_TO_ONE("1..1"),
+
+ /**
+ * Cardinality 0..n
+ */
+ ZERO_TO_MANY("0..n"),
+
+ /**
+ * Cardinality 1..n
+ */
+ ONE_TO_MANY("1..n");
+
+ private final String cardinalityString;
+
+ private ReferenceCardinality(final String cardinalityString) {
+ this.cardinalityString = cardinalityString;
+ }
+
+ /**
+ * @return String representation of cardinality
+ */
+ public String getCardinalityString() {
+ return this.cardinalityString;
+ }
+
+}
diff --git a/scrplugin-annotations/src/main/java/org/apache/felix/scrplugin/annotations/ReferencePolicy.java b/scrplugin-annotations/src/main/java/org/apache/felix/scrplugin/annotations/ReferencePolicy.java
new file mode 100644
index 0000000..598e7e1
--- /dev/null
+++ b/scrplugin-annotations/src/main/java/org/apache/felix/scrplugin/annotations/ReferencePolicy.java
@@ -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.scrplugin.annotations;
+
+/**
+ * Options for {@link Reference#policy()} property.
+ */
+public enum ReferencePolicy {
+
+ /**
+ * The component will be deactivated and re-activated if the service comes
+ * and/or goes away.
+ */
+ STATIC,
+
+ /**
+ * The service will be made available to the component as it comes and goes.
+ */
+ DYNAMIC;
+
+ /**
+ * @return String representation of policy
+ */
+ public String getPolicyString() {
+ return this.name().toLowerCase();
+ }
+
+}
diff --git a/scrplugin-annotations/src/main/java/org/apache/felix/scrplugin/annotations/References.java b/scrplugin-annotations/src/main/java/org/apache/felix/scrplugin/annotations/References.java
new file mode 100644
index 0000000..6706935
--- /dev/null
+++ b/scrplugin-annotations/src/main/java/org/apache/felix/scrplugin/annotations/References.java
@@ -0,0 +1,40 @@
+/*
+ * 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.annotations;
+
+import java.lang.annotation.Documented;
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+/**
+ * Allows to define multiple {@link Reference} annotations for one type.
+ */
+@Target(ElementType.TYPE)
+@Retention(RetentionPolicy.RUNTIME)
+@Documented
+public @interface References {
+
+ /**
+ * List of {@link Reference} annotations.
+ */
+ Reference[] value();
+
+}
diff --git a/scrplugin-annotations/src/main/java/org/apache/felix/scrplugin/annotations/Service.java b/scrplugin-annotations/src/main/java/org/apache/felix/scrplugin/annotations/Service.java
new file mode 100644
index 0000000..94e13be
--- /dev/null
+++ b/scrplugin-annotations/src/main/java/org/apache/felix/scrplugin/annotations/Service.java
@@ -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.scrplugin.annotations;
+
+import java.lang.annotation.Documented;
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+/**
+ * The <code>Service</code> annotation defines whether and which service
+ * interfaces are provided by the component.
+ * <p>
+ * This annotation is used to declare <service> and <provide>
+ * elements of the component declaration. See section 112.4.6, Service Elements,
+ * in the OSGi Service Platform Service Compendium Specification for more
+ * information.
+ */
+@Target(ElementType.TYPE)
+@Retention(RetentionPolicy.RUNTIME)
+@Documented
+public @interface Service {
+
+ /**
+ * The class of the service interface provided by the component. If this
+ * property is not set provide elements will be generated for all interfaces
+ * generated by the class
+ */
+ Class value() default AutoDetect.class;
+
+ /**
+ * Whether the component is registered as a
+ * <code>org.osgi.framework.ServiceFactory</code> or not.
+ */
+ boolean serviceFactory() default false;
+
+}
diff --git a/scrplugin-annotations/src/main/java/org/apache/felix/scrplugin/annotations/Services.java b/scrplugin-annotations/src/main/java/org/apache/felix/scrplugin/annotations/Services.java
new file mode 100644
index 0000000..5acf325
--- /dev/null
+++ b/scrplugin-annotations/src/main/java/org/apache/felix/scrplugin/annotations/Services.java
@@ -0,0 +1,40 @@
+/*
+ * 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.annotations;
+
+import java.lang.annotation.Documented;
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+/**
+ * Allows to define multiple {@link Service} annotations for one type.
+ */
+@Target(ElementType.TYPE)
+@Retention(RetentionPolicy.RUNTIME)
+@Documented
+public @interface Services {
+
+ /**
+ * List of {@link Service} annotations.
+ */
+ Service[] value();
+
+}
diff --git a/scrplugin-annotations/src/main/java/org/apache/felix/scrplugin/annotations/package-info.java b/scrplugin-annotations/src/main/java/org/apache/felix/scrplugin/annotations/package-info.java
new file mode 100644
index 0000000..d48edb2
--- /dev/null
+++ b/scrplugin-annotations/src/main/java/org/apache/felix/scrplugin/annotations/package-info.java
@@ -0,0 +1,24 @@
+/*
+ * 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.
+ */
+/**
+ * The scr goal of the maven-scr-plugin looks for the annotations defined in the package when building component descriptors.
+ * The annotations are not interpreted in runtime.
+ */
+package org.apache.felix.scrplugin.annotations;
+
diff --git a/scrplugin/pom.xml b/scrplugin/pom.xml
index 5432ddb..a704547 100644
--- a/scrplugin/pom.xml
+++ b/scrplugin/pom.xml
@@ -97,5 +97,29 @@
<artifactId>slf4j-simple</artifactId>
<version>1.4.3</version>
</dependency>
+
+ <dependency>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>maven-scr-plugin-annotations</artifactId>
+ <version>1.0.11-SNAPSHOT</version>
+ </dependency>
+
</dependencies>
+
+ <build>
+ <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/src/main/java/org/apache/felix/scrplugin/PropertyHandler.java b/scrplugin/src/main/java/org/apache/felix/scrplugin/PropertyHandler.java
index f7e5e6e..266148a 100644
--- a/scrplugin/src/main/java/org/apache/felix/scrplugin/PropertyHandler.java
+++ b/scrplugin/src/main/java/org/apache/felix/scrplugin/PropertyHandler.java
@@ -39,7 +39,7 @@
* This is a map using the property name as the key and
* {@link PropertyDescription} as values.
*/
- final private Map properties = new LinkedHashMap();
+ final private Map<String, PropertyDescription> properties = new LinkedHashMap<String, PropertyDescription>();
/** The component. */
final private Component component;
@@ -76,15 +76,15 @@
this.setPropertyValueRef(tag, prop, valueRef);
} else {
// check for multivalue - these can either be values or value refs
- final List values = new ArrayList();
- final Map valueMap = tag.getNamedParameterMap();
- for (Iterator vi = valueMap.entrySet().iterator(); vi.hasNext();) {
- final Map.Entry entry = (Map.Entry) vi.next();
- final String key = (String) entry.getKey();
+ final List<String> values = new ArrayList<String>();
+ final Map<String, String> valueMap = tag.getNamedParameterMap();
+ for (Iterator<Map.Entry<String, String>> vi = valueMap.entrySet().iterator(); vi.hasNext();) {
+ final Map.Entry<String, String> entry = vi.next();
+ final String key = entry.getKey();
if (key.startsWith(Constants.PROPERTY_MULTIVALUE_PREFIX) ) {
values.add(entry.getValue());
} else if ( key.startsWith(Constants.PROPERTY_MULTIVALUE_REF_PREFIX) ) {
- final String[] stringValues = this.getPropertyValueRef(tag, prop, (String)entry.getValue());
+ final String[] stringValues = this.getPropertyValueRef(tag, prop, entry.getValue());
if ( stringValues != null ) {
for(int i=0; i<stringValues.length; i++) {
values.add(stringValues[i]);
@@ -93,7 +93,7 @@
}
}
if ( values.size() > 0 ) {
- prop.setMultiValue((String[])values.toArray(new String[values.size()]));
+ prop.setMultiValue(values.toArray(new String[values.size()]));
} else {
// we have no value, valueRef or values so let's try to
// get the value of the field if a name attribute is specified
@@ -166,10 +166,10 @@
// check options
String[] parameters = tag.getParameters();
- Map options = null;
+ Map<String, String> options = null;
for (int j=0; j < parameters.length; j++) {
if (Constants.PROPERTY_OPTIONS.equals(parameters[j])) {
- options = new LinkedHashMap();
+ options = new LinkedHashMap<String, String>();
} else if (options != null) {
String optionLabel = parameters[j];
String optionValue = (j < parameters.length-2) ? parameters[j+2] : null;
@@ -334,25 +334,25 @@
* Process all found properties for the component.
* @throws MojoExecutionException
*/
- public void processProperties(final Map globalProperties)
+ public void processProperties(final Map<String, String> globalProperties)
throws MojoExecutionException {
- final Iterator propIter = properties.entrySet().iterator();
+ final Iterator<Map.Entry<String, PropertyDescription>> propIter = properties.entrySet().iterator();
while ( propIter.hasNext() ) {
- final Map.Entry entry = (Map.Entry)propIter.next();
- final String propName = entry.getKey().toString();
- final PropertyDescription desc = (PropertyDescription)entry.getValue();
+ final Map.Entry<String, PropertyDescription> entry = propIter.next();
+ final String propName = entry.getKey();
+ final PropertyDescription desc = entry.getValue();
this.processProperty(desc.propertyTag, propName, desc.field);
}
// apply pre configured global properties
if ( globalProperties != null ) {
- final Iterator globalPropIter = globalProperties.entrySet().iterator();
+ final Iterator<Map.Entry<String, String>> globalPropIter = globalProperties.entrySet().iterator();
while ( globalPropIter.hasNext() ) {
- final Map.Entry entry = (Map.Entry)globalPropIter.next();
- final String name = entry.getKey().toString();
+ final Map.Entry<String, String> entry = globalPropIter.next();
+ final String name = entry.getKey();
// check if the service already provides this property
if ( !properties.containsKey(name) && entry.getValue() != null ) {
- final String value = entry.getValue().toString();
+ final String value = entry.getValue();
final Property p = new Property();
p.setName(name);
diff --git a/scrplugin/src/main/java/org/apache/felix/scrplugin/SCRDescriptorMojo.java b/scrplugin/src/main/java/org/apache/felix/scrplugin/SCRDescriptorMojo.java
index 283e326..c1fa0a7 100644
--- a/scrplugin/src/main/java/org/apache/felix/scrplugin/SCRDescriptorMojo.java
+++ b/scrplugin/src/main/java/org/apache/felix/scrplugin/SCRDescriptorMojo.java
@@ -92,7 +92,18 @@
*
* @parameter
*/
- private Map properties = new HashMap();
+ private Map<String, String> properties = new HashMap<String, String>();
+
+ /**
+ * Allows to define additional implementations of the interface
+ * {@link org.apache.felix.scrplugin.tags.annotation.AnnotationTagProvider}
+ * that provide mappings from custom annotations to
+ * {@link org.apache.felix.scrplugin.tags.JavaTag} implementations.
+ * List of full qualified class file names.
+ *
+ * @parameter
+ */
+ private String[] annotationTagProviders = {};
/**
* @see org.apache.maven.plugin.AbstractMojo#execute()
@@ -105,6 +116,7 @@
JavaClassDescriptorManager jManager = new JavaClassDescriptorManager(this.getLog(),
this.project,
+ this.annotationTagProviders,
this.sourceExcludes);
// iterate through all source classes and check for component tag
final JavaClassDescription[] javaSources = jManager.getSourceDescriptions();
@@ -154,9 +166,10 @@
// write meta type info if there is a file name
if (!StringUtils.isEmpty(this.metaTypeName)) {
File mtFile = new File(this.outputDirectory, "OSGI-INF" + File.separator + "metatype" + File.separator + this.metaTypeName);
- if ( metaData.getDescriptors().size() > 0 ) {
+ final int size = metaData.getOCDs().size() + metaData.getDesignates().size();
+ if (size > 0 ) {
this.getLog().info("Generating "
- + metaData.getDescriptors().size()
+ + size
+ " MetaType Descriptors to " + mtFile);
mtFile.getParentFile().mkdirs();
MetaTypeIO.write(metaData, mtFile);
@@ -223,9 +236,10 @@
if (addResources) {
final String ourRsrcPath = this.outputDirectory.getAbsolutePath();
boolean found = false;
- final Iterator rsrcIterator = this.project.getResources().iterator();
+ @SuppressWarnings("unchecked")
+ final Iterator<Resource> rsrcIterator = this.project.getResources().iterator();
while ( !found && rsrcIterator.hasNext() ) {
- final Resource rsrc = (Resource)rsrcIterator.next();
+ final Resource rsrc = rsrcIterator.next();
found = rsrc.getDirectory().equals(ourRsrcPath);
}
if ( !found ) {
@@ -256,7 +270,7 @@
this.doServices(description.getTagsByName(Constants.SERVICE, inherited), component, description);
// collect references from class tags and fields
- final Map references = new HashMap();
+ final Map<String, Object[]> references = new HashMap<String, Object[]>();
// Utility handler for propertie
final PropertyHandler propertyHandler = new PropertyHandler(component, ocd);
@@ -292,11 +306,11 @@
propertyHandler.processProperties(this.properties);
// process references
- final Iterator refIter = references.entrySet().iterator();
+ final Iterator<Map.Entry<String, Object[]>> refIter = references.entrySet().iterator();
while ( refIter.hasNext() ) {
- final Map.Entry entry = (Map.Entry)refIter.next();
- final String refName = entry.getKey().toString();
- final Object[] values = (Object[])entry.getValue();
+ final Map.Entry<String, Object[]> entry = refIter.next();
+ final String refName = entry.getKey();
+ final Object[] values = entry.getValue();
final JavaTag tag = (JavaTag)values[0];
this.doReference(tag, refName, component, values[1].toString());
}
@@ -306,9 +320,9 @@
if ( createPid ) {
// check for an existing pid first
boolean found = false;
- final Iterator iter = component.getProperties().iterator();
+ final Iterator<Property> iter = component.getProperties().iterator();
while ( !found && iter.hasNext() ) {
- final Property prop = (Property)iter.next();
+ final Property prop = iter.next();
found = org.osgi.framework.Constants.SERVICE_PID.equals( prop.getName() );
}
if ( !found ) {
@@ -319,18 +333,18 @@
}
}
- final List issues = new ArrayList();
- final List warnings = new ArrayList();
+ final List<String> issues = new ArrayList<String>();
+ final List<String> warnings = new ArrayList<String>();
component.validate(issues, warnings);
// now log warnings and errors (warnings first)
- Iterator i = warnings.iterator();
+ Iterator<String> i = warnings.iterator();
while ( i.hasNext() ) {
- this.getLog().warn((String)i.next());
+ this.getLog().warn(i.next());
}
i = issues.iterator();
while ( i.hasNext() ) {
- this.getLog().error((String)i.next());
+ this.getLog().error(i.next());
}
// return nothing if validation fails
@@ -475,7 +489,7 @@
* @param isInspectedClass
* @throws MojoExecutionException
*/
- protected void testReference(Map references, JavaTag reference, String defaultName, boolean isInspectedClass)
+ protected void testReference(Map<String, Object[]> references, JavaTag reference, String defaultName, boolean isInspectedClass)
throws MojoExecutionException {
final String refName = this.getReferenceName(reference, defaultName);
diff --git a/scrplugin/src/main/java/org/apache/felix/scrplugin/om/Component.java b/scrplugin/src/main/java/org/apache/felix/scrplugin/om/Component.java
index 70055cc..20f5f0c 100644
--- a/scrplugin/src/main/java/org/apache/felix/scrplugin/om/Component.java
+++ b/scrplugin/src/main/java/org/apache/felix/scrplugin/om/Component.java
@@ -18,7 +18,8 @@
*/
package org.apache.felix.scrplugin.om;
-import java.util.*;
+import java.util.ArrayList;
+import java.util.List;
import org.apache.felix.scrplugin.tags.*;
import org.apache.maven.plugin.MojoExecutionException;
@@ -46,13 +47,13 @@
protected Implementation implementation;
/** All properties. */
- protected List properties = new ArrayList();
+ protected List<Property> properties = new ArrayList<Property>();
/** The corresponding service. */
protected Service service;
/** The references. */
- protected List references = new ArrayList();
+ protected List<Reference> references = new ArrayList<Reference>();
/** Is this an abstract description? */
protected boolean isAbstract;
@@ -87,11 +88,11 @@
/**
* @return All properties of this component.
*/
- public List getProperties() {
+ public List<Property> getProperties() {
return this.properties;
}
- public void setProperties(List properties) {
+ public void setProperties(List<Property> properties) {
this.properties = properties;
}
@@ -147,11 +148,11 @@
this.service = service;
}
- public List getReferences() {
+ public List<Reference> getReferences() {
return this.references;
}
- public void setReferences(List references) {
+ public void setReferences(List<Reference> references) {
this.references = references;
}
@@ -180,7 +181,7 @@
* If errors occur a message is added to the issues list,
* warnings can be added to the warnings list.
*/
- public void validate(List issues, List warnings)
+ public void validate(List<String> issues, List<String> warnings)
throws MojoExecutionException {
final int currentIssueCount = issues.size();
@@ -231,8 +232,7 @@
}
// verify properties
- for (Iterator pi = this.getProperties().iterator(); pi.hasNext();) {
- Property prop = (Property) pi.next();
+ for(final Property prop : this.getProperties()) {
prop.validate(issues, warnings);
}
@@ -259,8 +259,7 @@
}
if ( issues.size() == currentIssueCount ) {
// verify references
- for (Iterator ri = this.getReferences().iterator(); ri.hasNext();) {
- final Reference ref = (Reference) ri.next();
+ for(final Reference ref : this.getReferences()) {
ref.validate(issues, warnings, this.isAbstract);
}
}
@@ -273,7 +272,7 @@
* @param methodName The method name.
* @param warnings The list of warnings used to add new warnings.
*/
- protected void checkLifecycleMethod(JavaClassDescription javaClass, String methodName, List warnings)
+ protected void checkLifecycleMethod(JavaClassDescription javaClass, String methodName, List<String> warnings)
throws MojoExecutionException {
final JavaMethod method = javaClass.getMethodBySignature(methodName, new String[] {"org.osgi.service.component.ComponentContext"});
if ( method != null ) {
diff --git a/scrplugin/src/main/java/org/apache/felix/scrplugin/om/Components.java b/scrplugin/src/main/java/org/apache/felix/scrplugin/om/Components.java
index b3db488..05f2944 100644
--- a/scrplugin/src/main/java/org/apache/felix/scrplugin/om/Components.java
+++ b/scrplugin/src/main/java/org/apache/felix/scrplugin/om/Components.java
@@ -29,19 +29,19 @@
public class Components {
/** The list of {@link Component}s. */
- protected List components = new ArrayList();
+ protected List<Component> components = new ArrayList<Component>();
/**
* Return the list of {@link Component}s.
*/
- public List getComponents() {
+ public List<Component> getComponents() {
return this.components;
}
/**
* Set the list of {@link Component}s.
*/
- public void setComponents(List components) {
+ public void setComponents(List<Component> components) {
this.components = components;
}
diff --git a/scrplugin/src/main/java/org/apache/felix/scrplugin/om/Interface.java b/scrplugin/src/main/java/org/apache/felix/scrplugin/om/Interface.java
index eb798e8..956c3b1 100644
--- a/scrplugin/src/main/java/org/apache/felix/scrplugin/om/Interface.java
+++ b/scrplugin/src/main/java/org/apache/felix/scrplugin/om/Interface.java
@@ -59,7 +59,7 @@
* If errors occur a message is added to the issues list,
* warnings can be added to the warnings list.
*/
- public void validate(List issues, List warnings)
+ public void validate(List<String> issues, List<String> warnings)
throws MojoExecutionException {
final JavaClassDescription javaClass = this.tag.getJavaClassDescription();
if (javaClass == null) {
diff --git a/scrplugin/src/main/java/org/apache/felix/scrplugin/om/Property.java b/scrplugin/src/main/java/org/apache/felix/scrplugin/om/Property.java
index 1880d01..265b35d 100644
--- a/scrplugin/src/main/java/org/apache/felix/scrplugin/om/Property.java
+++ b/scrplugin/src/main/java/org/apache/felix/scrplugin/om/Property.java
@@ -91,7 +91,7 @@
* If errors occur a message is added to the issues list,
* warnings can be added to the warnings list.
*/
- public void validate(List issues, List warnings) {
+ public void validate(List<String> issues, List<String> warnings) {
if ( name == null || name.trim().length() == 0 ) {
issues.add(this.getMessage("Property name can not be empty."));
}
diff --git a/scrplugin/src/main/java/org/apache/felix/scrplugin/om/Reference.java b/scrplugin/src/main/java/org/apache/felix/scrplugin/om/Reference.java
index 764be66..3bf26f3 100644
--- a/scrplugin/src/main/java/org/apache/felix/scrplugin/om/Reference.java
+++ b/scrplugin/src/main/java/org/apache/felix/scrplugin/om/Reference.java
@@ -37,7 +37,7 @@
protected String policy;
protected String bind;
protected String unbind;
-
+
/** @since 1.0.9 */
protected String strategy;
@@ -128,7 +128,7 @@
public void setChecked(boolean checked) {
this.checked = checked;
}
-
+
/** @since 1.0.9 */
public String getStrategy() {
return strategy;
@@ -138,7 +138,7 @@
public void setStrategy(String strategy) {
this.strategy = strategy;
}
-
+
/** @since 1.0.9 */
public boolean isLookupStrategy() {
return "lookup".equals(getStrategy());
@@ -149,7 +149,7 @@
* If errors occur a message is added to the issues list,
* warnings can be added to the warnings list.
*/
- public void validate(List issues, List warnings, boolean componentIsAbstract)
+ public void validate(List<String> issues, List<String> warnings, boolean componentIsAbstract)
throws MojoExecutionException {
// if this reference is already checked, return immediately
if ( this.checked ) {
@@ -181,7 +181,7 @@
} else if (!"static".equals(this.policy) && !"dynamic".equals(this.policy)) {
issues.add(this.getMessage("Invalid Policy specification " + this.policy));
}
-
+
// validate strategy
if (this.strategy == null) {
this.strategy = "event";
@@ -214,9 +214,9 @@
}
}
- protected String validateMethod(String methodName,
- List issues,
- List warnings,
+ protected String validateMethod(String methodName,
+ List<String> issues,
+ List<String> warnings,
boolean componentIsAbstract)
throws MojoExecutionException {
final JavaMethod method = this.findMethod(methodName);
diff --git a/scrplugin/src/main/java/org/apache/felix/scrplugin/om/Service.java b/scrplugin/src/main/java/org/apache/felix/scrplugin/om/Service.java
index 02a4435..aa18742 100644
--- a/scrplugin/src/main/java/org/apache/felix/scrplugin/om/Service.java
+++ b/scrplugin/src/main/java/org/apache/felix/scrplugin/om/Service.java
@@ -31,7 +31,7 @@
protected boolean isServicefactory;
/** The list of implemented interfaces. */
- protected final List interfaces = new ArrayList();
+ protected final List<Interface> interfaces = new ArrayList<Interface>();
/**
* Default constructor.
@@ -54,7 +54,7 @@
this.isServicefactory = flag;
}
- public List getInterfaces() {
+ public List<Interface> getInterfaces() {
return this.interfaces;
}
@@ -64,9 +64,9 @@
* @return The interface if it is implemented by this service or null.
*/
public Interface findInterface(String name) {
- final Iterator i = this.interfaces.iterator();
+ final Iterator<Interface> i = this.getInterfaces().iterator();
while ( i.hasNext() ) {
- final Interface current = (Interface)i.next();
+ final Interface current = i.next();
if ( current.getInterfacename().equals(name) ) {
return current;
}
@@ -90,11 +90,9 @@
* If errors occur a message is added to the issues list,
* warnings can be added to the warnings list.
*/
- public void validate(List issues, List warnings)
+ public void validate(List<String> issues, List<String> warnings)
throws MojoExecutionException {
- final Iterator i = this.interfaces.iterator();
- while ( i.hasNext() ) {
- final Interface interf = (Interface)i.next();
+ for(final Interface interf : this.getInterfaces()) {
interf.validate(issues, warnings);
}
}
diff --git a/scrplugin/src/main/java/org/apache/felix/scrplugin/om/metatype/AttributeDefinition.java b/scrplugin/src/main/java/org/apache/felix/scrplugin/om/metatype/AttributeDefinition.java
index 8f63f66..c32ccb1 100644
--- a/scrplugin/src/main/java/org/apache/felix/scrplugin/om/metatype/AttributeDefinition.java
+++ b/scrplugin/src/main/java/org/apache/felix/scrplugin/om/metatype/AttributeDefinition.java
@@ -38,7 +38,7 @@
protected Integer cardinality;
- protected Map options;
+ protected Map<String, String> options;
public String getId() {
return this.id;
@@ -108,11 +108,11 @@
this.cardinality = cardinality;
}
- public Map getOptions() {
+ public Map<String, String> getOptions() {
return this.options;
}
- public void setOptions(Map options) {
+ public void setOptions(Map<String, String> options) {
this.options = options;
}
}
diff --git a/scrplugin/src/main/java/org/apache/felix/scrplugin/om/metatype/MetaData.java b/scrplugin/src/main/java/org/apache/felix/scrplugin/om/metatype/MetaData.java
index e1084e1..33841cd 100644
--- a/scrplugin/src/main/java/org/apache/felix/scrplugin/om/metatype/MetaData.java
+++ b/scrplugin/src/main/java/org/apache/felix/scrplugin/om/metatype/MetaData.java
@@ -18,14 +18,16 @@
*/
package org.apache.felix.scrplugin.om.metatype;
-import java.util.List;
import java.util.ArrayList;
+import java.util.List;
public class MetaData {
protected String localization;
- protected List descriptors = new ArrayList();
+ protected List<OCD> ocds = new ArrayList<OCD>();
+
+ protected List<Designate> designates = new ArrayList<Designate>();
public String getLocalization() {
return this.localization;
@@ -35,15 +37,19 @@
this.localization = localization;
}
- public List getDescriptors() {
- return this.descriptors;
+ public List<OCD> getOCDs() {
+ return this.ocds;
+ }
+
+ public List<Designate> getDesignates() {
+ return this.designates;
}
public void addOCD(OCD ocd) {
- this.descriptors.add(ocd);
+ this.ocds.add(ocd);
}
public void addDesignate(Designate d) {
- this.descriptors.add(d);
+ this.designates.add(d);
}
}
diff --git a/scrplugin/src/main/java/org/apache/felix/scrplugin/om/metatype/OCD.java b/scrplugin/src/main/java/org/apache/felix/scrplugin/om/metatype/OCD.java
index 50dd6c7..f167d49 100644
--- a/scrplugin/src/main/java/org/apache/felix/scrplugin/om/metatype/OCD.java
+++ b/scrplugin/src/main/java/org/apache/felix/scrplugin/om/metatype/OCD.java
@@ -29,7 +29,7 @@
protected String description;
- protected List properties = new ArrayList();
+ protected List<AttributeDefinition> properties = new ArrayList<AttributeDefinition>();
public String getId() {
return this.id;
@@ -55,11 +55,11 @@
this.description = description;
}
- public List getProperties() {
+ public List<AttributeDefinition> getProperties() {
return this.properties;
}
- public void setProperties(List properties) {
+ public void setProperties(List<AttributeDefinition> properties) {
this.properties = properties;
}
}
diff --git a/scrplugin/src/main/java/org/apache/felix/scrplugin/tags/JavaClassDescriptionInheritanceComparator.java b/scrplugin/src/main/java/org/apache/felix/scrplugin/tags/JavaClassDescriptionInheritanceComparator.java
index 2980bb1..80a9cbe 100644
--- a/scrplugin/src/main/java/org/apache/felix/scrplugin/tags/JavaClassDescriptionInheritanceComparator.java
+++ b/scrplugin/src/main/java/org/apache/felix/scrplugin/tags/JavaClassDescriptionInheritanceComparator.java
@@ -37,14 +37,11 @@
* <li>Finally, the natural order of the class names is returned
* </ol>
*/
-public class JavaClassDescriptionInheritanceComparator implements Comparator
+public class JavaClassDescriptionInheritanceComparator implements Comparator<JavaClassDescription>
{
- public int compare( Object o1, Object o2 )
+ public int compare( JavaClassDescription cd1, JavaClassDescription cd2 )
{
- JavaClassDescription cd1 = ( JavaClassDescription ) o1;
- JavaClassDescription cd2 = ( JavaClassDescription ) o2;
-
// the descriptors are the same
if ( equals( cd1, cd2 ) )
{
diff --git a/scrplugin/src/main/java/org/apache/felix/scrplugin/tags/JavaClassDescriptorManager.java b/scrplugin/src/main/java/org/apache/felix/scrplugin/tags/JavaClassDescriptorManager.java
index 48035e2..1d060c6 100644
--- a/scrplugin/src/main/java/org/apache/felix/scrplugin/tags/JavaClassDescriptorManager.java
+++ b/scrplugin/src/main/java/org/apache/felix/scrplugin/tags/JavaClassDescriptorManager.java
@@ -27,6 +27,8 @@
import org.apache.felix.scrplugin.Constants;
import org.apache.felix.scrplugin.om.Component;
import org.apache.felix.scrplugin.om.Components;
+import org.apache.felix.scrplugin.tags.annotation.AnnotationJavaClassDescription;
+import org.apache.felix.scrplugin.tags.annotation.AnnotationTagProviderManager;
import org.apache.felix.scrplugin.tags.cl.ClassLoaderJavaClassDescription;
import org.apache.felix.scrplugin.tags.qdox.QDoxJavaClassDescription;
import org.apache.felix.scrplugin.xml.ComponentDescriptorIO;
@@ -59,41 +61,50 @@
protected final ClassLoader classloader;
/** A cache containing the java class descriptions hashed by classname. */
- protected final Map javaClassDescriptions = new HashMap();
+ protected final Map<String, JavaClassDescription> javaClassDescriptions = new HashMap<String, JavaClassDescription>();
/** The component definitions from other bundles hashed by classname. */
- protected final Map componentDescriptions = new HashMap();
+ protected final Map<String, Component> componentDescriptions = new HashMap<String, Component>();
/** The maven project. */
protected final MavenProject project;
/**
+ * Supports mapping of built-in and custom java anntoations to {@link JavaTag} implementations.
+ */
+ protected final AnnotationTagProviderManager annotationTagProviderManager;
+
+ /**
* Construct a new manager.
* @param log
* @param project
+ * @param annotationTagProviders List of annotation tag providers
* @throws MojoFailureException
* @throws MojoExecutionException
*/
public JavaClassDescriptorManager(final Log log,
final MavenProject project,
+ final String[] annotationTagProviders,
final String excludeString)
throws MojoFailureException, MojoExecutionException {
this.log = log;
this.project = project;
+ this.annotationTagProviderManager = new AnnotationTagProviderManager(annotationTagProviders);
this.classloader = this.getCompileClassLoader();
// get all the class sources through qdox
this.log.debug("Setting up QDox");
JavaDocBuilder builder = new JavaDocBuilder();
builder.getClassLibrary().addClassLoader(this.classloader);
- final Iterator i = project.getCompileSourceRoots().iterator();
+ @SuppressWarnings("unchecked")
+ final Iterator<String> i = project.getCompileSourceRoots().iterator();
// FELIX-509: check for excludes
if ( excludeString != null ) {
final String[] excludes = StringUtils.split(excludeString, ",");
final String[] includes = new String[] {"**/*.java"};
while ( i.hasNext() ) {
- final String tree = (String)i.next();
+ final String tree = i.next();
this.log.debug("Scanning source tree " + tree);
final File directory = new File(tree);
final DirectoryScanner scanner = new DirectoryScanner();
@@ -123,7 +134,7 @@
}
} else {
while ( i.hasNext() ) {
- final String tree = (String)i.next();
+ final String tree = i.next();
this.log.debug("Adding source tree " + tree);
final File directory = new File(tree);
builder.addSourceTree(directory);
@@ -132,19 +143,21 @@
this.sources = builder.getSources();
// and now scan artifacts
- final List components = new ArrayList();
- final Map resolved = project.getArtifactMap();
- final Set artifacts = project.getDependencyArtifacts();
- final Iterator it = artifacts.iterator();
+ final List<Component> components = new ArrayList<Component>();
+ @SuppressWarnings("unchecked")
+ final Map<String, Artifact> resolved = project.getArtifactMap();
+ @SuppressWarnings("unchecked")
+ final Set<Artifact> artifacts = project.getDependencyArtifacts();
+ final Iterator<Artifact> it = artifacts.iterator();
while ( it.hasNext() ) {
- final Artifact declared = (Artifact) it.next();
+ final Artifact declared = it.next();
this.log.debug("Checking artifact " + declared);
if ( this.isJavaArtifact(declared)) {
if (Artifact.SCOPE_COMPILE.equals(declared.getScope())
|| Artifact.SCOPE_RUNTIME.equals(declared.getScope())
|| Artifact.SCOPE_PROVIDED.equals(declared.getScope())) {
this.log.debug("Resolving artifact " + declared);
- final Artifact artifact = (Artifact) resolved.get(ArtifactUtils.versionlessKey(declared));
+ final Artifact artifact = resolved.get(ArtifactUtils.versionlessKey(declared));
if (artifact != null) {
this.log.debug("Trying to get manifest from artifact " + artifact);
try {
@@ -197,9 +210,7 @@
}
}
// now create map with component descriptions
- final Iterator cI = components.iterator();
- while ( cI.hasNext() ) {
- final Component component = (Component) cI.next();
+ for(final Component component : components) {
this.componentDescriptions.put(component.getImplementation().getClassame(), component);
}
}
@@ -239,6 +250,13 @@
}
/**
+ * @return Annotation tag provider manager
+ */
+ public AnnotationTagProviderManager getAnnotationTagProviderManager() {
+ return this.annotationTagProviderManager;
+ }
+
+ /**
* Read the service component description.
* @param artifact
* @param entry
@@ -272,11 +290,12 @@
protected ClassLoader getCompileClassLoader()
throws MojoFailureException {
- List artifacts = this.getProject().getCompileArtifacts();
+ @SuppressWarnings("unchecked")
+ List<Artifact> artifacts = this.getProject().getCompileArtifacts();
URL[] path = new URL[artifacts.size() + 1];
int i = 0;
- for (Iterator ai=artifacts.iterator(); ai.hasNext(); ) {
- Artifact a = (Artifact) ai.next();
+ for (Iterator<Artifact> ai=artifacts.iterator(); ai.hasNext(); ) {
+ Artifact a = ai.next();
try {
path[i++] = a.getFile().toURI().toURL();
} catch (IOException ioe) {
@@ -343,7 +362,13 @@
for(int i=0; i<this.sources.length; i++) {
final String className = this.sources[i].getClasses()[0].getFullyQualifiedName();
try {
- descs[i] = new QDoxJavaClassDescription(this.classloader.loadClass(className), this.sources[i], this);
+ // check for java annotation descriptions - fallback to QDox if none found
+ Class clazz = this.classloader.loadClass(className);
+ if (getAnnotationTagProviderManager().hasScrPluginAnnotation(clazz)) {
+ descs[i] = new AnnotationJavaClassDescription(clazz, this.sources[i], this);
+ } else {
+ descs[i] = new QDoxJavaClassDescription(clazz, this.sources[i], this);
+ }
} catch (ClassNotFoundException e) {
throw new MojoExecutionException("Unable to load class " + className);
}
@@ -359,15 +384,22 @@
*/
public JavaClassDescription getJavaClassDescription(String className)
throws MojoExecutionException {
- JavaClassDescription result = (JavaClassDescription) this.javaClassDescriptions.get(className);
+ JavaClassDescription result = this.javaClassDescriptions.get(className);
if ( result == null ) {
this.log.debug("Searching description for: " + className);
int index = 0;
while ( result == null && index < this.sources.length) {
if ( this.sources[index].getClasses()[0].getFullyQualifiedName().equals(className) ) {
try {
- this.log.debug("Found qdox description for: " + className);
- result = new QDoxJavaClassDescription(this.classloader.loadClass(className), this.sources[index], this);
+ // check for java annotation descriptions - fallback to QDox if none found
+ Class clazz = this.classloader.loadClass(className);
+ if (getAnnotationTagProviderManager().hasScrPluginAnnotation(clazz)) {
+ this.log.debug("Found java annotation description for: " + className);
+ result = new AnnotationJavaClassDescription(clazz, this.sources[index], this);
+ } else {
+ this.log.debug("Found qdox description for: " + className);
+ result = new QDoxJavaClassDescription(clazz, this.sources[index], this);
+ }
} catch (ClassNotFoundException e) {
throw new MojoExecutionException("Unable to load class " + className);
}
@@ -378,7 +410,7 @@
if ( result == null ) {
try {
this.log.debug("Generating classloader description for: " + className);
- result = new ClassLoaderJavaClassDescription(this.classloader.loadClass(className), (Component)this.componentDescriptions.get(className), this);
+ result = new ClassLoaderJavaClassDescription(this.classloader.loadClass(className), this.componentDescriptions.get(className), this);
} catch (ClassNotFoundException e) {
throw new MojoExecutionException("Unable to load class " + className);
}
diff --git a/scrplugin/src/main/java/org/apache/felix/scrplugin/tags/JavaTag.java b/scrplugin/src/main/java/org/apache/felix/scrplugin/tags/JavaTag.java
index fb8503d..ba82aa1 100644
--- a/scrplugin/src/main/java/org/apache/felix/scrplugin/tags/JavaTag.java
+++ b/scrplugin/src/main/java/org/apache/felix/scrplugin/tags/JavaTag.java
@@ -38,5 +38,5 @@
JavaField getField();
- Map getNamedParameterMap();
+ Map<String, String> getNamedParameterMap();
}
diff --git a/scrplugin/src/main/java/org/apache/felix/scrplugin/tags/annotation/AnnotationJavaClassDescription.java b/scrplugin/src/main/java/org/apache/felix/scrplugin/tags/annotation/AnnotationJavaClassDescription.java
new file mode 100644
index 0000000..5bc342c
--- /dev/null
+++ b/scrplugin/src/main/java/org/apache/felix/scrplugin/tags/annotation/AnnotationJavaClassDescription.java
@@ -0,0 +1,134 @@
+/*
+ * 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.tags.annotation;
+
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Field;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+import org.apache.felix.scrplugin.tags.JavaClassDescription;
+import org.apache.felix.scrplugin.tags.JavaClassDescriptorManager;
+import org.apache.felix.scrplugin.tags.JavaField;
+import org.apache.felix.scrplugin.tags.JavaTag;
+import org.apache.felix.scrplugin.tags.qdox.QDoxJavaClassDescription;
+import org.apache.maven.plugin.MojoExecutionException;
+
+import com.thoughtworks.qdox.model.JavaSource;
+
+/**
+ * Reading class description based on java annotations. This extends
+ * {@link QDoxJavaClassDescription} to re-use annotation-independent logic and
+ * automatic generation of bind/unbind methods.
+ */
+public class AnnotationJavaClassDescription extends QDoxJavaClassDescription {
+
+ /**
+ * @param clazz Java class
+ * @param source QDox source
+ * @param manager description manager
+ */
+ public AnnotationJavaClassDescription(Class clazz, JavaSource source, JavaClassDescriptorManager manager) {
+ super(clazz, source, manager);
+ }
+
+ /**
+ * @see JavaClassDescription#getTagByName(String)
+ */
+ @Override
+ public JavaTag getTagByName(String name) {
+ for (Annotation annotation : this.clazz.getAnnotations()) {
+ List<JavaTag> tags = manager.getAnnotationTagProviderManager().getTags(annotation, this);
+ for (JavaTag tag : tags) {
+ if (tag.getName().equals(name)) {
+ return tag;
+ }
+ }
+ }
+ return null;
+ }
+
+ /**
+ * @see JavaClassDescription#getTagsByName(String, boolean)
+ */
+ @Override
+ public JavaTag[] getTagsByName(String name, boolean inherited) throws MojoExecutionException {
+
+ List<JavaTag> tags = new ArrayList<JavaTag>();
+
+ for (Annotation annotation : this.clazz.getAnnotations()) {
+ List<JavaTag> annotationTags = manager.getAnnotationTagProviderManager().getTags(annotation, this);
+ for (JavaTag tag : annotationTags) {
+ if (tag.getName().equals(name)) {
+ tags.add(tag);
+ }
+ }
+ }
+
+ if (inherited && this.getSuperClass() != null) {
+ final JavaTag[] superTags = this.getSuperClass().getTagsByName(name, inherited);
+ if (superTags.length > 0) {
+ tags.addAll(Arrays.asList(superTags));
+ }
+ }
+
+ return tags.toArray(new JavaTag[tags.size()]);
+ }
+
+ /**
+ * @see JavaClassDescription#getFields()
+ */
+ @Override
+ public JavaField[] getFields() {
+ final Field[] fields = this.clazz.getDeclaredFields();
+ final JavaField[] javaFields = new JavaField[fields.length];
+ for (int i = 0; i < fields.length; i++) {
+ javaFields[i] = new AnnotationJavaField(fields[i], this);
+ }
+ return javaFields;
+ }
+
+ /**
+ * @see JavaClassDescription#getFieldByName(String)
+ */
+ @Override
+ public JavaField getFieldByName(String name) throws MojoExecutionException {
+ Field field = null;
+ try {
+ field = this.clazz.getField(name);
+ } catch (SecurityException e) {
+ // ignore
+ } catch (NoSuchFieldException e) {
+ // ignore
+ }
+ if (field != null) {
+ return new AnnotationJavaField(field, this);
+ }
+ if (this.getSuperClass() != null) {
+ this.getSuperClass().getFieldByName(name);
+ }
+ return null;
+ }
+
+ protected JavaClassDescriptorManager getManager() {
+ return this.manager;
+ }
+
+}
diff --git a/scrplugin/src/main/java/org/apache/felix/scrplugin/tags/annotation/AnnotationJavaField.java b/scrplugin/src/main/java/org/apache/felix/scrplugin/tags/annotation/AnnotationJavaField.java
new file mode 100644
index 0000000..d2edabc
--- /dev/null
+++ b/scrplugin/src/main/java/org/apache/felix/scrplugin/tags/annotation/AnnotationJavaField.java
@@ -0,0 +1,85 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.felix.scrplugin.tags.annotation;
+
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Field;
+import java.util.List;
+
+import org.apache.felix.scrplugin.tags.ClassUtil;
+import org.apache.felix.scrplugin.tags.JavaField;
+import org.apache.felix.scrplugin.tags.JavaTag;
+
+/**
+ * Description of a java field
+ */
+public class AnnotationJavaField implements JavaField {
+
+ protected final Field field;
+
+ protected final AnnotationJavaClassDescription description;
+
+ /**
+ * @param field Field
+ * @param description description
+ */
+ public AnnotationJavaField(Field field, AnnotationJavaClassDescription description) {
+ this.field = field;
+ this.description = description;
+ }
+
+ /**
+ * @see JavaField#getInitializationExpression()
+ */
+ public String[] getInitializationExpression() {
+ return ClassUtil.getInitializationExpression(this.description.getCompiledClass(), this.getName());
+ }
+
+ /**
+ * @see JavaField#getName()
+ */
+ public String getName() {
+ return this.field.getName();
+ }
+
+ /**
+ * @see JavaField#getTagByName(String)
+ */
+ public JavaTag getTagByName(String name) {
+ for (Annotation annotation : this.field.getAnnotations()) {
+ List<JavaTag> tags = description.getManager().getAnnotationTagProviderManager().getTags(annotation,
+ this.description, this);
+ for (JavaTag tag : tags) {
+ if (tag.getName().equals(name)) {
+ return tag;
+ }
+
+ }
+ }
+ return null;
+ }
+
+ /**
+ * @see JavaField#getType()
+ */
+ public String getType() {
+ return this.field.getType().getName();
+ }
+
+}
diff --git a/scrplugin/src/main/java/org/apache/felix/scrplugin/tags/annotation/AnnotationTagProvider.java b/scrplugin/src/main/java/org/apache/felix/scrplugin/tags/annotation/AnnotationTagProvider.java
new file mode 100644
index 0000000..9bbdaa5
--- /dev/null
+++ b/scrplugin/src/main/java/org/apache/felix/scrplugin/tags/annotation/AnnotationTagProvider.java
@@ -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.scrplugin.tags.annotation;
+
+import java.lang.annotation.Annotation;
+import java.util.List;
+
+import org.apache.felix.scrplugin.tags.JavaField;
+import org.apache.felix.scrplugin.tags.JavaTag;
+
+/**
+ * Interface for provider classes, that map java annotations to {@link JavaTag}
+ * implementations.
+ */
+public interface AnnotationTagProvider {
+
+ /**
+ * Maps a annotation to one or many {@link JavaTag} implementations.
+ * @param pAnnotation Java annotation
+ * @param description Annotations-based java class description
+ * @param field Reference to field (set on field-level annotations, null on
+ * other annotations)
+ * @return List of tag implementations. Return empty list if this provider
+ * cannot map the annotation to any tag instance.
+ */
+ List<JavaTag> getTags(Annotation pAnnotation, AnnotationJavaClassDescription description, JavaField field);
+
+}
diff --git a/scrplugin/src/main/java/org/apache/felix/scrplugin/tags/annotation/AnnotationTagProviderManager.java b/scrplugin/src/main/java/org/apache/felix/scrplugin/tags/annotation/AnnotationTagProviderManager.java
new file mode 100644
index 0000000..cc553a8
--- /dev/null
+++ b/scrplugin/src/main/java/org/apache/felix/scrplugin/tags/annotation/AnnotationTagProviderManager.java
@@ -0,0 +1,121 @@
+/*
+ * 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.tags.annotation;
+
+import java.lang.annotation.Annotation;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.felix.scrplugin.tags.JavaField;
+import org.apache.felix.scrplugin.tags.JavaTag;
+import org.apache.felix.scrplugin.tags.annotation.defaulttag.DefaultAnnotationTagProvider;
+import org.apache.maven.plugin.MojoFailureException;
+
+/**
+ * Supports mapping of built-in and custom java anntoations to {@link JavaTag}
+ * implementations.
+ */
+public class AnnotationTagProviderManager {
+
+ /**
+ * Allows to define additional implementations of the interface
+ * {@link org.apache.felix.scrplugin.tags.annotation.AnnotationTagProvider}
+ * that provide mappings from custom annotations to
+ * {@link org.apache.felix.scrplugin.tags.JavaTag} implementations.
+ */
+ private final List<AnnotationTagProvider> annotationTagProviders = new ArrayList<AnnotationTagProvider>();
+
+ /**
+ * @param annotationTagProviderClasses List of classes that implements
+ * {@link AnnotationTagProvider} interface.
+ * @throws MojoFailureException
+ */
+ public AnnotationTagProviderManager(String[] annotationTagProviderClasses) throws MojoFailureException {
+
+ // always add provider supporting built-in SCR default properties
+ annotationTagProviders.add(new DefaultAnnotationTagProvider());
+
+ // add custom providers defined in pom
+ for (int i = 0; i < annotationTagProviderClasses.length; i++) {
+ try {
+ Class clazz = Class.forName(annotationTagProviderClasses[i]);
+ try {
+ annotationTagProviders.add((AnnotationTagProvider) clazz.newInstance());
+ } catch (ClassCastException e) {
+ throw new MojoFailureException("Class '" + clazz.getName() + "' "
+ + "does not implement interface '" + AnnotationTagProvider.class.getName() + "'.");
+ } catch (InstantiationException e) {
+ throw new MojoFailureException("Unable to instantiate class '" + clazz.getName() + "': "
+ + e.getMessage());
+ } catch (IllegalAccessException e) {
+ throw new MojoFailureException("Illegal access to class '" + clazz.getName() + "': "
+ + e.getMessage());
+ }
+ } catch (ClassNotFoundException ex) {
+ throw new MojoFailureException("Annotation provider class '" + annotationTagProviderClasses[i]
+ + "' not found.");
+ }
+ }
+
+ }
+
+ /**
+ * Converts a java annotation to {@link JavaTag} if a mapping can be found.
+ *
+ * @param annotation Java annotation
+ * @param description Description
+ * @return Tag declaration or null if no mapping found
+ */
+ public List<JavaTag> getTags(Annotation annotation, AnnotationJavaClassDescription description) {
+ return getTags(annotation, description, null);
+ }
+
+ /**
+ * Converts a java annotation to {@link JavaTag} if a mapping can be found.
+ *
+ * @param annotation Java annotation
+ * @param description Description
+ * @param field Field
+ * @return Tag declaration or null if no mapping found
+ */
+ public List<JavaTag> getTags(Annotation annotation, AnnotationJavaClassDescription description, JavaField field) {
+ List<JavaTag> tags = new ArrayList<JavaTag>();
+
+ for (AnnotationTagProvider provider : this.annotationTagProviders) {
+ tags.addAll(provider.getTags(annotation, description, field));
+ }
+
+ return tags;
+ }
+
+ /**
+ * Checks if the given class has any SCR plugin java annotations defined.
+ * @param pClass Class
+ * @return true if SCR plugin java annotation found
+ */
+ public boolean hasScrPluginAnnotation(Class pClass) {
+ for (Annotation annotation : pClass.getAnnotations()) {
+ if (getTags(annotation, null).size() > 0) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+}
diff --git a/scrplugin/src/main/java/org/apache/felix/scrplugin/tags/annotation/defaulttag/AbstractTag.java b/scrplugin/src/main/java/org/apache/felix/scrplugin/tags/annotation/defaulttag/AbstractTag.java
new file mode 100644
index 0000000..02f483c
--- /dev/null
+++ b/scrplugin/src/main/java/org/apache/felix/scrplugin/tags/annotation/defaulttag/AbstractTag.java
@@ -0,0 +1,108 @@
+/*
+ * 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.tags.annotation.defaulttag;
+
+import java.util.Map;
+
+import org.apache.felix.scrplugin.tags.*;
+
+/**
+ * Description of a java tag for components.
+ */
+public abstract class AbstractTag implements JavaTag {
+
+ protected final JavaClassDescription description;
+
+ protected final JavaField field;
+
+ /**
+ * @param desc Description
+ * @param field Field
+ */
+ public AbstractTag(JavaClassDescription desc, JavaField field) {
+ this.description = desc;
+ this.field = field;
+ }
+
+ /**
+ * @see JavaTag#getNamedParameter(String)
+ */
+ public String getNamedParameter(String name) {
+ final Map<String, String> map = this.getNamedParameterMap();
+ if (map != null) {
+ return map.get(name);
+ }
+ return null;
+ }
+
+ /**
+ * @see JavaTag#getParameters()
+ */
+ public String[] getParameters() {
+ final Map<?, ?> map = this.getNamedParameterMap();
+ if (map != null) {
+ return map.keySet().toArray(new String[5]);
+ }
+ return new String[0];
+ }
+
+ /**
+ * @see JavaTag#getSourceLocation()
+ */
+ public String getSourceLocation() {
+ return "Java annotations in " + this.description.getName();
+ }
+
+ /**
+ * @see JavaTag#getJavaClassDescription()
+ */
+ public JavaClassDescription getJavaClassDescription() {
+ return this.description;
+ }
+
+ /**
+ * @see JavaTag#getField()
+ */
+ public JavaField getField() {
+ return this.field;
+ }
+
+ /**
+ * Maps an empty or null string value to null
+ * @param value String value
+ * @return Non-empty string value or null
+ */
+ protected String emptyToNull(String value) {
+ if (value == null || value.length() == 0) {
+ return null;
+ }
+ return value;
+ }
+
+ /**
+ * @see JavaTag#getName()
+ */
+ public abstract String getName();
+
+ /**
+ * @see JavaTag#getNamedParameterMap()
+ */
+ public abstract Map<String, String> getNamedParameterMap();
+
+}
diff --git a/scrplugin/src/main/java/org/apache/felix/scrplugin/tags/annotation/defaulttag/ComponentTag.java b/scrplugin/src/main/java/org/apache/felix/scrplugin/tags/annotation/defaulttag/ComponentTag.java
new file mode 100644
index 0000000..510956e
--- /dev/null
+++ b/scrplugin/src/main/java/org/apache/felix/scrplugin/tags/annotation/defaulttag/ComponentTag.java
@@ -0,0 +1,68 @@
+/*
+ * 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.tags.annotation.defaulttag;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.felix.scrplugin.Constants;
+import org.apache.felix.scrplugin.annotations.Component;
+import org.apache.felix.scrplugin.tags.JavaClassDescription;
+
+/**
+ * Description of a java tag for components.
+ */
+public class ComponentTag extends AbstractTag {
+
+ protected final Component annotation;
+
+ /**
+ * @param annotation Annotation
+ * @param desc Description
+ */
+ public ComponentTag(Component annotation, JavaClassDescription desc) {
+ super(desc, null);
+ this.annotation = annotation;
+ }
+
+ @Override
+ public String getName() {
+ return Constants.COMPONENT;
+ }
+
+ @Override
+ public Map<String, String> getNamedParameterMap() {
+ final Map<String, String> map = new HashMap<String, String>();
+
+ map.put(Constants.COMPONENT_NAME, emptyToNull(this.annotation.name()));
+ map.put(Constants.COMPONENT_LABEL, emptyToNull(this.annotation.label()));
+ map.put(Constants.COMPONENT_DESCRIPTION, emptyToNull(this.annotation.description()));
+ map.put(Constants.COMPONENT_ENABLED, String.valueOf(this.annotation.enabled()));
+ map.put(Constants.COMPONENT_FACTORY, emptyToNull(this.annotation.factory()));
+ map.put(Constants.COMPONENT_IMMEDIATE, String.valueOf(this.annotation.immediate()));
+ map.put(Constants.COMPONENT_INHERIT, String.valueOf(this.annotation.inherit()));
+ map.put(Constants.COMPONENT_METATYPE, String.valueOf(this.annotation.metatype()));
+ map.put(Constants.COMPONENT_ABSTRACT, String.valueOf(this.annotation.componentAbstract()));
+ map.put(Constants.COMPONENT_DS, String.valueOf(this.annotation.ds()));
+ map.put(Constants.COMPONENT_CREATE_PID, String.valueOf(this.annotation.createPid()));
+
+ return map;
+ }
+
+}
diff --git a/scrplugin/src/main/java/org/apache/felix/scrplugin/tags/annotation/defaulttag/DefaultAnnotationTagProvider.java b/scrplugin/src/main/java/org/apache/felix/scrplugin/tags/annotation/defaulttag/DefaultAnnotationTagProvider.java
new file mode 100644
index 0000000..203bcc8
--- /dev/null
+++ b/scrplugin/src/main/java/org/apache/felix/scrplugin/tags/annotation/defaulttag/DefaultAnnotationTagProvider.java
@@ -0,0 +1,78 @@
+/*
+ * 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.tags.annotation.defaulttag;
+
+import java.lang.annotation.Annotation;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.felix.scrplugin.annotations.Component;
+import org.apache.felix.scrplugin.annotations.Properties;
+import org.apache.felix.scrplugin.annotations.Property;
+import org.apache.felix.scrplugin.annotations.Reference;
+import org.apache.felix.scrplugin.annotations.References;
+import org.apache.felix.scrplugin.annotations.Service;
+import org.apache.felix.scrplugin.annotations.Services;
+import org.apache.felix.scrplugin.tags.JavaField;
+import org.apache.felix.scrplugin.tags.JavaTag;
+import org.apache.felix.scrplugin.tags.annotation.AnnotationJavaClassDescription;
+import org.apache.felix.scrplugin.tags.annotation.AnnotationTagProvider;
+
+/**
+ * Provides mapping of default SCR annotations to tag implementations.
+ */
+public class DefaultAnnotationTagProvider implements AnnotationTagProvider {
+
+ /**
+ * @see AnnotationTagProvider#getTags(Annotation,
+ * AnnotationJavaClassDescription, JavaField)
+ */
+ public List<JavaTag> getTags(Annotation annotation, AnnotationJavaClassDescription description, JavaField field) {
+ List<JavaTag> tags = new ArrayList<JavaTag>();
+
+ // check for single annotations
+ if (annotation instanceof Component) {
+ tags.add(new ComponentTag((Component) annotation, description));
+ } else if (annotation instanceof Property) {
+ tags.add(new PropertyTag((Property) annotation, description));
+ } else if (annotation instanceof Service) {
+ tags.add(new ServiceTag((Service) annotation, description));
+ } else if (annotation instanceof Reference) {
+ tags.add(new ReferenceTag((Reference) annotation, description, field));
+ }
+
+ // check for multi-annotations
+ else if (annotation instanceof Properties) {
+ for (Property property : ((Properties) annotation).value()) {
+ tags.add(new PropertyTag(property, description));
+ }
+ } else if (annotation instanceof Services) {
+ for (Service service : ((Services) annotation).value()) {
+ tags.add(new ServiceTag(service, description));
+ }
+ } else if (annotation instanceof References) {
+ for (Reference reference : ((References) annotation).value()) {
+ tags.add(new ReferenceTag(reference, description, field));
+ }
+ }
+
+ return tags;
+ }
+
+}
diff --git a/scrplugin/src/main/java/org/apache/felix/scrplugin/tags/annotation/defaulttag/PropertyTag.java b/scrplugin/src/main/java/org/apache/felix/scrplugin/tags/annotation/defaulttag/PropertyTag.java
new file mode 100644
index 0000000..0fc24a0
--- /dev/null
+++ b/scrplugin/src/main/java/org/apache/felix/scrplugin/tags/annotation/defaulttag/PropertyTag.java
@@ -0,0 +1,105 @@
+/*
+ * 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.tags.annotation.defaulttag;
+
+import java.util.*;
+
+import org.apache.felix.scrplugin.Constants;
+import org.apache.felix.scrplugin.annotations.*;
+import org.apache.felix.scrplugin.tags.JavaClassDescription;
+
+/**
+ * Description of a java tag for components.
+ */
+public class PropertyTag extends AbstractTag {
+
+ protected final Property annotation;
+
+ /**
+ * @param annotation Annotation
+ * @param desc Description
+ */
+ public PropertyTag(Property annotation, JavaClassDescription desc) {
+ super(desc, null);
+ this.annotation = annotation;
+ }
+
+ @Override
+ public String getName() {
+ return Constants.PROPERTY;
+ }
+
+ @Override
+ public Map<String, String> getNamedParameterMap() {
+ final Map<String, String> map = new HashMap<String, String>();
+
+ map.put(Constants.PROPERTY_NAME, emptyToNull(this.annotation.name()));
+ map.put(Constants.PROPERTY_LABEL, emptyToNull(this.annotation.label()));
+ map.put(Constants.PROPERTY_DESCRIPTION, emptyToNull(this.annotation.description()));
+
+ String[] values = this.annotation.value();
+ if (values == null || values.length == 0) {
+ map.put(Constants.PROPERTY_VALUE, "");
+ } else if (values.length == 1) {
+ map.put(Constants.PROPERTY_VALUE, values[0]);
+ } else {
+ for (int i = 0; i < values.length; i++) {
+ map.put(Constants.PROPERTY_MULTIVALUE_PREFIX + '.' + i, values[i]);
+ }
+ }
+
+ String type = null;
+ if (this.annotation.type() != AutoDetect.class) {
+ type = this.annotation.type().getSimpleName();
+ }
+ map.put(Constants.PROPERTY_TYPE, type);
+
+ if (this.annotation.cardinality() != 0) {
+ map.put(Constants.PROPERTY_CARDINALITY, String.valueOf(this.annotation.cardinality()));
+ }
+
+ map.put(Constants.PROPERTY_PRIVATE, String.valueOf(this.annotation.propertyPrivate()));
+
+ return map;
+ }
+
+ @Override
+ public String[] getParameters() {
+ List<String> parameters = new ArrayList<String>();
+
+ String[] defaultParameters = super.getParameters();
+ if (defaultParameters != null) {
+ parameters.addAll(Arrays.asList(defaultParameters));
+ }
+
+ // if defined: add options as parameters to the end of parameter list
+ // (strange parsing due to qdox tag restrictions...)
+ if (this.annotation.options().length > 0) {
+ parameters.add(Constants.PROPERTY_OPTIONS);
+ for (PropertyOption option : this.annotation.options()) {
+ parameters.add(option.name());
+ parameters.add("=");
+ parameters.add(option.value());
+ }
+ }
+
+ return parameters.toArray(new String[parameters.size()]);
+ }
+
+}
diff --git a/scrplugin/src/main/java/org/apache/felix/scrplugin/tags/annotation/defaulttag/ReferenceTag.java b/scrplugin/src/main/java/org/apache/felix/scrplugin/tags/annotation/defaulttag/ReferenceTag.java
new file mode 100644
index 0000000..4cf97e7
--- /dev/null
+++ b/scrplugin/src/main/java/org/apache/felix/scrplugin/tags/annotation/defaulttag/ReferenceTag.java
@@ -0,0 +1,75 @@
+/*
+ * 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.tags.annotation.defaulttag;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.felix.scrplugin.Constants;
+import org.apache.felix.scrplugin.annotations.AutoDetect;
+import org.apache.felix.scrplugin.annotations.Reference;
+import org.apache.felix.scrplugin.tags.JavaClassDescription;
+import org.apache.felix.scrplugin.tags.JavaField;
+
+/**
+ * Description of a java tag for components.
+ */
+public class ReferenceTag extends AbstractTag {
+
+ protected final Reference annotation;
+
+ /**
+ * @param annotation Annotation
+ * @param desc Description
+ * @param field Field
+ */
+ public ReferenceTag(Reference annotation, JavaClassDescription desc, JavaField field) {
+ super(desc, field);
+ this.annotation = annotation;
+ }
+
+ @Override
+ public String getName() {
+ return Constants.REFERENCE;
+ }
+
+ @Override
+ public Map<String, String> getNamedParameterMap() {
+ final Map<String, String> map = new HashMap<String, String>();
+
+ map.put(Constants.REFERENCE_NAME, emptyToNull(this.annotation.name()));
+
+ String referenceInterface = null;
+ if (this.annotation.referenceInterface() != AutoDetect.class) {
+ referenceInterface = this.annotation.referenceInterface().getName();
+ }
+ map.put(Constants.REFERENCE_INTERFACE, referenceInterface);
+
+ map.put(Constants.REFERENCE_CARDINALITY, this.annotation.cardinality().getCardinalityString());
+ map.put(Constants.REFERENCE_POLICY, this.annotation.policy().getPolicyString());
+ map.put(Constants.REFERENCE_TARGET, emptyToNull(this.annotation.target()));
+ map.put(Constants.REFERENCE_BIND, emptyToNull(this.annotation.bind()));
+ map.put(Constants.REFERENCE_UNDBIND, emptyToNull(this.annotation.unbind()));
+ map.put(Constants.REFERENCE_CHECKED, String.valueOf(this.annotation.checked()));
+ map.put(Constants.REFERENCE_STRATEGY, emptyToNull(this.annotation.strategy()));
+
+ return map;
+ }
+
+}
diff --git a/scrplugin/src/main/java/org/apache/felix/scrplugin/tags/annotation/defaulttag/ServiceTag.java b/scrplugin/src/main/java/org/apache/felix/scrplugin/tags/annotation/defaulttag/ServiceTag.java
new file mode 100644
index 0000000..7578f25
--- /dev/null
+++ b/scrplugin/src/main/java/org/apache/felix/scrplugin/tags/annotation/defaulttag/ServiceTag.java
@@ -0,0 +1,65 @@
+/*
+ * 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.tags.annotation.defaulttag;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.felix.scrplugin.Constants;
+import org.apache.felix.scrplugin.annotations.AutoDetect;
+import org.apache.felix.scrplugin.annotations.Service;
+import org.apache.felix.scrplugin.tags.JavaClassDescription;
+
+/**
+ * Description of a java tag for components.
+ */
+public class ServiceTag extends AbstractTag {
+
+ protected final Service annotation;
+
+ /**
+ * @param annotation Annotation
+ * @param desc Description
+ */
+ public ServiceTag(Service annotation, JavaClassDescription desc) {
+ super(desc, null);
+ this.annotation = annotation;
+ }
+
+ @Override
+ public String getName() {
+ return Constants.SERVICE;
+ }
+
+ @Override
+ public Map<String, String> getNamedParameterMap() {
+ final Map<String, String> map = new HashMap<String, String>();
+
+ String serviceInterface = null;
+ if (this.annotation.value() != AutoDetect.class) {
+ serviceInterface = this.annotation.value().getName();
+ }
+ map.put(Constants.SERVICE_INTERFACE, serviceInterface);
+
+ map.put(Constants.SERVICE_FACTORY, String.valueOf(this.annotation.serviceFactory()));
+
+ return map;
+ }
+
+}
diff --git a/scrplugin/src/main/java/org/apache/felix/scrplugin/tags/annotation/defaulttag/package-info.java b/scrplugin/src/main/java/org/apache/felix/scrplugin/tags/annotation/defaulttag/package-info.java
new file mode 100644
index 0000000..67c4673
--- /dev/null
+++ b/scrplugin/src/main/java/org/apache/felix/scrplugin/tags/annotation/defaulttag/package-info.java
@@ -0,0 +1,24 @@
+/*
+ * 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.
+ */
+/**
+ * SCR plugin annotation tag provider default implementation for annotations provided in package
+ * <code>org.apache.felix.scrplugin.annotations</code>.
+ */
+package org.apache.felix.scrplugin.tags.annotation.defaulttag;
+
diff --git a/scrplugin/src/main/java/org/apache/felix/scrplugin/tags/annotation/package-info.java b/scrplugin/src/main/java/org/apache/felix/scrplugin/tags/annotation/package-info.java
new file mode 100644
index 0000000..a00ab18
--- /dev/null
+++ b/scrplugin/src/main/java/org/apache/felix/scrplugin/tags/annotation/package-info.java
@@ -0,0 +1,23 @@
+/*
+ * 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.
+ */
+/**
+ * Extracting SCR tags from source file declared as Java 1.5 annotations.
+ */
+package org.apache.felix.scrplugin.tags.annotation;
+
diff --git a/scrplugin/src/main/java/org/apache/felix/scrplugin/tags/cl/ClassLoaderJavaClassDescription.java b/scrplugin/src/main/java/org/apache/felix/scrplugin/tags/cl/ClassLoaderJavaClassDescription.java
index 34468a3..299f83f 100644
--- a/scrplugin/src/main/java/org/apache/felix/scrplugin/tags/cl/ClassLoaderJavaClassDescription.java
+++ b/scrplugin/src/main/java/org/apache/felix/scrplugin/tags/cl/ClassLoaderJavaClassDescription.java
@@ -22,7 +22,7 @@
import java.util.*;
import org.apache.felix.scrplugin.Constants;
-import org.apache.felix.scrplugin.om.*;
+import org.apache.felix.scrplugin.om.Component;
import org.apache.felix.scrplugin.tags.*;
import org.apache.maven.plugin.MojoExecutionException;
@@ -194,7 +194,7 @@
this.component.getService().getInterfaces().size() > 0 ) {
javaTags = new JavaTag[this.component.getService().getInterfaces().size()];
for(int i=0; i<this.component.getService().getInterfaces().size(); i++) {
- javaTags[i] = new ClassLoaderJavaTag(this, (Interface)this.component.getService().getInterfaces().get(i),
+ javaTags[i] = new ClassLoaderJavaTag(this, this.component.getService().getInterfaces().get(i),
this.component.getService().isServicefactory());
}
}
@@ -202,14 +202,14 @@
if ( this.component.getProperties().size() > 0 ) {
javaTags = new JavaTag[this.component.getProperties().size()];
for(int i=0; i<this.component.getProperties().size(); i++) {
- javaTags[i] = new ClassLoaderJavaTag(this, (Property)this.component.getProperties().get(i));
+ javaTags[i] = new ClassLoaderJavaTag(this, this.component.getProperties().get(i));
}
}
} else if ( Constants.REFERENCE.equals(name) ) {
if ( this.component.getReferences().size() > 0 ) {
javaTags = new JavaTag[this.component.getReferences().size()];
for(int i=0; i<this.component.getReferences().size(); i++) {
- javaTags[i] = new ClassLoaderJavaTag(this, (Reference)this.component.getReferences().get(i));
+ javaTags[i] = new ClassLoaderJavaTag(this, this.component.getReferences().get(i));
}
}
}
@@ -217,9 +217,9 @@
if ( inherited && this.getSuperClass() != null ) {
final JavaTag[] superTags = this.getSuperClass().getTagsByName(name, inherited);
if ( superTags.length > 0 ) {
- final List list = new ArrayList(Arrays.asList(javaTags));
+ final List<JavaTag> list = new ArrayList<JavaTag>(Arrays.asList(javaTags));
list.addAll(Arrays.asList(superTags));
- javaTags = (JavaTag[]) list.toArray(new JavaTag[list.size()]);
+ javaTags = list.toArray(new JavaTag[list.size()]);
}
}
return javaTags;
diff --git a/scrplugin/src/main/java/org/apache/felix/scrplugin/tags/cl/ClassLoaderJavaTag.java b/scrplugin/src/main/java/org/apache/felix/scrplugin/tags/cl/ClassLoaderJavaTag.java
index 8980aeb..cfe721e 100644
--- a/scrplugin/src/main/java/org/apache/felix/scrplugin/tags/cl/ClassLoaderJavaTag.java
+++ b/scrplugin/src/main/java/org/apache/felix/scrplugin/tags/cl/ClassLoaderJavaTag.java
@@ -92,9 +92,9 @@
* @see org.apache.felix.scrplugin.tags.JavaTag#getNamedParameter(java.lang.String)
*/
public String getNamedParameter(String name) {
- final Map map = this.getNamedParameterMap();
+ final Map<String, String> map = this.getNamedParameterMap();
if ( map != null ) {
- return (String)map.get(name);
+ return map.get(name);
}
return null;
}
@@ -102,9 +102,9 @@
/**
* @see org.apache.felix.scrplugin.tags.JavaTag#getNamedParameterMap()
*/
- public Map getNamedParameterMap() {
+ public Map<String, String> getNamedParameterMap() {
if ( this.reference != null ) {
- final Map map = new HashMap();
+ final Map<String, String> map = new HashMap<String, String>();
map.put(Constants.REFERENCE_BIND, this.reference.getBind());
map.put(Constants.REFERENCE_CARDINALITY, this.reference.getCardinality());
map.put(Constants.REFERENCE_INTERFACE, this.reference.getInterfacename());
@@ -116,7 +116,7 @@
map.put(Constants.REFERENCE_STRATEGY, this.reference.getStrategy());
return map;
} else if ( this.property != null ) {
- final Map map = new HashMap();
+ final Map<String, String> map = new HashMap<String, String>();
map.put(Constants.PROPERTY_TYPE, this.property.getType());
map.put(Constants.PROPERTY_NAME, this.property.getName());
final String[] values = this.property.getMultiValue();
@@ -139,7 +139,7 @@
}
return map;
} else if ( this.interf != null ) {
- final Map map = new HashMap();
+ final Map<String, String> map = new HashMap<String, String>();
map.put(Constants.SERVICE_INTERFACE, this.interf.getInterfacename());
if ( this.isServiceFactory ) {
map.put(Constants.SERVICE_FACTORY, "true");
@@ -153,9 +153,9 @@
* @see org.apache.felix.scrplugin.tags.JavaTag#getParameters()
*/
public String[] getParameters() {
- final Map map = this.getNamedParameterMap();
+ final Map<String, String> map = this.getNamedParameterMap();
if ( map != null ) {
- return (String[])map.keySet().toArray(new String[5]);
+ return map.keySet().toArray(new String[5]);
}
return new String[0];
}
diff --git a/scrplugin/src/main/java/org/apache/felix/scrplugin/tags/qdox/QDoxJavaClassDescription.java b/scrplugin/src/main/java/org/apache/felix/scrplugin/tags/qdox/QDoxJavaClassDescription.java
index a59eab3..064e996 100644
--- a/scrplugin/src/main/java/org/apache/felix/scrplugin/tags/qdox/QDoxJavaClassDescription.java
+++ b/scrplugin/src/main/java/org/apache/felix/scrplugin/tags/qdox/QDoxJavaClassDescription.java
@@ -102,9 +102,9 @@
if ( inherited && this.getSuperClass() != null ) {
final JavaTag[] superTags = this.getSuperClass().getTagsByName(name, inherited);
if ( superTags.length > 0 ) {
- final List list = new ArrayList(Arrays.asList(javaTags));
+ final List<JavaTag> list = new ArrayList<JavaTag>(Arrays.asList(javaTags));
list.addAll(Arrays.asList(superTags));
- javaTags = (JavaTag[]) list.toArray(new JavaTag[list.size()]);
+ javaTags = list.toArray(new JavaTag[list.size()]);
}
}
return javaTags;
diff --git a/scrplugin/src/main/java/org/apache/felix/scrplugin/tags/qdox/QDoxJavaTag.java b/scrplugin/src/main/java/org/apache/felix/scrplugin/tags/qdox/QDoxJavaTag.java
index d0a6f05..53e9353 100644
--- a/scrplugin/src/main/java/org/apache/felix/scrplugin/tags/qdox/QDoxJavaTag.java
+++ b/scrplugin/src/main/java/org/apache/felix/scrplugin/tags/qdox/QDoxJavaTag.java
@@ -84,7 +84,8 @@
/**
* @see org.apache.felix.scrplugin.tags.JavaTag#getNamedParameterMap()
*/
- public Map getNamedParameterMap() {
+ @SuppressWarnings("unchecked")
+ public Map<String, String> getNamedParameterMap() {
return this.docletTag.getNamedParameterMap();
}
diff --git a/scrplugin/src/main/java/org/apache/felix/scrplugin/xml/ComponentDescriptorIO.java b/scrplugin/src/main/java/org/apache/felix/scrplugin/xml/ComponentDescriptorIO.java
index 627ef5e..1468522 100644
--- a/scrplugin/src/main/java/org/apache/felix/scrplugin/xml/ComponentDescriptorIO.java
+++ b/scrplugin/src/main/java/org/apache/felix/scrplugin/xml/ComponentDescriptorIO.java
@@ -20,7 +20,6 @@
import java.io.File;
import java.io.IOException;
-import java.util.Iterator;
import java.util.StringTokenizer;
import javax.xml.transform.TransformerException;
@@ -119,9 +118,7 @@
contentHandler.startElement("", ComponentDescriptorIO.COMPONENTS, ComponentDescriptorIO.COMPONENTS, new AttributesImpl());
IOUtils.newline(contentHandler);
- final Iterator i = components.getComponents().iterator();
- while ( i.hasNext() ) {
- final Component component = (Component)i.next();
+ for(final Component component : components.getComponents()) {
generateXML(component, contentHandler, isScrPrivateFile);
}
// end wrapper element
@@ -153,16 +150,12 @@
generateXML(component.getService(), contentHandler);
}
if ( component.getProperties() != null ) {
- final Iterator i = component.getProperties().iterator();
- while ( i.hasNext() ) {
- final Property property = (Property)i.next();
+ for(final Property property : component.getProperties()) {
generateXML(property, contentHandler, isScrPrivateFile);
}
}
if ( component.getReferences() != null ) {
- final Iterator i = component.getReferences().iterator();
- while ( i.hasNext() ) {
- final Reference reference = (Reference)i.next();
+ for(final Reference reference : component.getReferences()) {
generateXML(reference, contentHandler, isScrPrivateFile);
}
}
@@ -201,9 +194,7 @@
contentHandler.startElement(INNER_NAMESPACE_URI, ComponentDescriptorIO.SERVICE, ComponentDescriptorIO.SERVICE_QNAME, ai);
if ( service.getInterfaces() != null && service.getInterfaces().size() > 0 ) {
IOUtils.newline(contentHandler);
- final Iterator i = service.getInterfaces().iterator();
- while ( i.hasNext() ) {
- final Interface interf = (Interface)i.next();
+ for(final Interface interf : service.getInterfaces()) {
generateXML(interf, contentHandler);
}
IOUtils.indent(contentHandler, 2);
diff --git a/scrplugin/src/main/java/org/apache/felix/scrplugin/xml/IOUtils.java b/scrplugin/src/main/java/org/apache/felix/scrplugin/xml/IOUtils.java
index 0259cb7..46b819a 100644
--- a/scrplugin/src/main/java/org/apache/felix/scrplugin/xml/IOUtils.java
+++ b/scrplugin/src/main/java/org/apache/felix/scrplugin/xml/IOUtils.java
@@ -133,19 +133,19 @@
/**
* The prefixes of startPrefixMapping() declarations for the coming element.
*/
- private List prefixList = new ArrayList();
+ private List<String> prefixList = new ArrayList<String>();
/**
* The URIs of startPrefixMapping() declarations for the coming element.
*/
- private List uriList = new ArrayList();
+ private List<String> uriList = new ArrayList<String>();
/**
* Maps of URI<->prefix mappings. Used to work around a bug in the Xalan
* serializer.
*/
- private Map uriToPrefixMap = new HashMap();
- private Map prefixToUriMap = new HashMap();
+ private Map<String, String> uriToPrefixMap = new HashMap<String, String>();
+ private Map<String, String> prefixToUriMap = new HashMap<String, String>();
/**
* True if there has been some startPrefixMapping() for the coming element.
@@ -215,8 +215,8 @@
for (int mapping = 0; mapping < mappingCount; mapping++) {
// Build infos for this namespace
- String uri = (String) this.uriList.get(mapping);
- String prefix = (String) this.prefixList.get(mapping);
+ String uri = this.uriList.get(mapping);
+ String prefix = this.prefixList.get(mapping);
String qName = prefix.length() == 0 ? "xmlns" : ("xmlns:" + prefix);
// Search for the corresponding xmlns* attribute
diff --git a/scrplugin/src/main/java/org/apache/felix/scrplugin/xml/MetaTypeIO.java b/scrplugin/src/main/java/org/apache/felix/scrplugin/xml/MetaTypeIO.java
index aa680c2..978a7a7 100644
--- a/scrplugin/src/main/java/org/apache/felix/scrplugin/xml/MetaTypeIO.java
+++ b/scrplugin/src/main/java/org/apache/felix/scrplugin/xml/MetaTypeIO.java
@@ -95,15 +95,13 @@
contentHandler.startElement(NAMESPACE_URI, METADATA_ELEMENT, METADATA_ELEMENT_QNAME, ai);
IOUtils.newline(contentHandler);
- final Iterator i = metaData.getDescriptors().iterator();
- while ( i.hasNext() ) {
- final Object obj = i.next();
- if ( obj instanceof OCD ) {
- generateXML((OCD)obj, contentHandler);
- } else {
- generateXML((Designate)obj, contentHandler);
- }
+ for(final OCD ocd : metaData.getOCDs()) {
+ generateXML(ocd, contentHandler);
}
+ for(final Designate d : metaData.getDesignates()) {
+ generateXML(d, contentHandler);
+ }
+
// end wrapper element
contentHandler.endElement(NAMESPACE_URI, METADATA_ELEMENT, METADATA_ELEMENT_QNAME);
IOUtils.newline(contentHandler);
@@ -122,9 +120,9 @@
if ( ocd.getProperties().size() > 0 ) {
IOUtils.newline(contentHandler);
- final Iterator i = ocd.getProperties().iterator();
+ final Iterator<AttributeDefinition> i = ocd.getProperties().iterator();
while ( i.hasNext() ) {
- final AttributeDefinition ad = (AttributeDefinition) i.next();
+ final AttributeDefinition ad = i.next();
generateXML(ad, contentHandler);
}
IOUtils.indent(contentHandler, 1);
@@ -159,11 +157,11 @@
if (ad.getOptions() != null && ad.getOptions().size() > 0) {
IOUtils.newline(contentHandler);
- for (Iterator oi=ad.getOptions().entrySet().iterator(); oi.hasNext(); ) {
- final Map.Entry entry = (Map.Entry) oi.next();
+ for (Iterator<Map.Entry<String, String>> oi=ad.getOptions().entrySet().iterator(); oi.hasNext(); ) {
+ final Map.Entry<String, String> entry = oi.next();
ai.clear();
- IOUtils.addAttribute(ai, "value", String.valueOf(entry.getKey()));
- IOUtils.addAttribute(ai, "label", String.valueOf(entry.getValue()));
+ IOUtils.addAttribute(ai, "value", entry.getKey());
+ IOUtils.addAttribute(ai, "label", entry.getValue());
IOUtils.indent(contentHandler, 3);
contentHandler.startElement(INNER_NAMESPACE_URI, OPTION_ELEMENT, OPTION_ELEMENT_QNAME, ai);
contentHandler.endElement(INNER_NAMESPACE_URI, OPTION_ELEMENT, OPTION_ELEMENT_QNAME);