FELIX-1229 : Add new annotations for activate and deactivate; add enumerations for policy and strategy
git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@784173 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/scr-annotations/src/main/java/org/apache/felix/scr/annotations/Activate.java b/scr-annotations/src/main/java/org/apache/felix/scr/annotations/Activate.java
new file mode 100644
index 0000000..46222c5
--- /dev/null
+++ b/scr-annotations/src/main/java/org/apache/felix/scr/annotations/Activate.java
@@ -0,0 +1,35 @@
+/*
+ * 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.scr.annotations;
+
+import java.lang.annotation.*;
+
+/**
+ * The <code>Activate</code> annotation defines the method which is used
+ * to activate the component.
+ * Please note that this annotation only marks the method name which is
+ * put into the configuration. The DS implementation will still use its
+ * search strategy to find the method.
+ */
+@Target( { ElementType.METHOD })
+@Retention(RetentionPolicy.SOURCE)
+@Documented
+public @interface Activate {
+
+}
diff --git a/scr-annotations/src/main/java/org/apache/felix/scr/annotations/Component.java b/scr-annotations/src/main/java/org/apache/felix/scr/annotations/Component.java
index 2829d4a..6efb369 100644
--- a/scr-annotations/src/main/java/org/apache/felix/scr/annotations/Component.java
+++ b/scr-annotations/src/main/java/org/apache/felix/scr/annotations/Component.java
@@ -107,4 +107,9 @@
*/
boolean createPid() default true;
+ /**
+ * The configuration policy
+ * @since 1.0
+ */
+ ConfigurationPolicy policy() default ConfigurationPolicy.OPTIONAL;
}
diff --git a/scr-annotations/src/main/java/org/apache/felix/scr/annotations/ConfigurationPolicy.java b/scr-annotations/src/main/java/org/apache/felix/scr/annotations/ConfigurationPolicy.java
new file mode 100644
index 0000000..871cebe
--- /dev/null
+++ b/scr-annotations/src/main/java/org/apache/felix/scr/annotations/ConfigurationPolicy.java
@@ -0,0 +1,49 @@
+/*
+ * 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.scr.annotations;
+
+/**
+ * Options for {@link Component#policy()} property.
+ */
+public enum ConfigurationPolicy {
+
+ /**
+ * If a configuration is available it will be used, if not the component
+ * will be activated anyway (this is the default).
+ */
+ OPTIONAL,
+
+ /**
+ * The configuration admin is not consulted for a configuration for this component.
+ */
+ IGNORE,
+
+ /**
+ * In order to activate this component a configuration is required.
+ */
+ REQUIRE;
+
+ /**
+ * @return String representation of policy
+ */
+ public String getPolicyString() {
+ return this.name().toLowerCase();
+ }
+
+}
diff --git a/scr-annotations/src/main/java/org/apache/felix/scr/annotations/Deactivate.java b/scr-annotations/src/main/java/org/apache/felix/scr/annotations/Deactivate.java
new file mode 100644
index 0000000..e079d8b
--- /dev/null
+++ b/scr-annotations/src/main/java/org/apache/felix/scr/annotations/Deactivate.java
@@ -0,0 +1,35 @@
+/*
+ * 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.scr.annotations;
+
+import java.lang.annotation.*;
+
+/**
+ * The <code>Dectivate</code> annotation defines the method which is used
+ * to deactivate the component.
+ * Please note that this annotation only marks the method name which is
+ * put into the configuration. The DS implementation will still use its
+ * search strategy to find the method.
+ */
+@Target( { ElementType.METHOD })
+@Retention(RetentionPolicy.SOURCE)
+@Documented
+public @interface Deactivate {
+
+}
diff --git a/scr-annotations/src/main/java/org/apache/felix/scr/annotations/Reference.java b/scr-annotations/src/main/java/org/apache/felix/scr/annotations/Reference.java
index 423d86e..6a7277e 100644
--- a/scr-annotations/src/main/java/org/apache/felix/scr/annotations/Reference.java
+++ b/scr-annotations/src/main/java/org/apache/felix/scr/annotations/Reference.java
@@ -103,6 +103,6 @@
* TODO: parameter documentation missing
* @since 1.0.9
*/
- String strategy() default "";
+ ReferenceStrategy strategy() default ReferenceStrategy.EVENT;
}
diff --git a/scr-annotations/src/main/java/org/apache/felix/scr/annotations/ReferenceStrategy.java b/scr-annotations/src/main/java/org/apache/felix/scr/annotations/ReferenceStrategy.java
new file mode 100644
index 0000000..4193781
--- /dev/null
+++ b/scr-annotations/src/main/java/org/apache/felix/scr/annotations/ReferenceStrategy.java
@@ -0,0 +1,37 @@
+/*
+ * 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.scr.annotations;
+
+/**
+ * Options for {@link Reference#strategy()} property.
+ */
+public enum ReferenceStrategy {
+
+ EVENT,
+
+ LOOKUP;
+
+ /**
+ * @return String representation of the stragey
+ */
+ public String getStrategyString() {
+ return this.name().toLowerCase();
+ }
+
+}