FELIX-1229 : Add support for new modified method.
git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@793474 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
index 46222c5..7d2dd29 100644
--- 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
@@ -25,7 +25,7 @@
* 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.
+ * search strategy to find the method based on the name.
*/
@Target( { ElementType.METHOD })
@Retention(RetentionPolicy.SOURCE)
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
index e079d8b..e9d5a54 100644
--- 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
@@ -25,7 +25,7 @@
* 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.
+ * search strategy to find the method based on the name.
*/
@Target( { ElementType.METHOD })
@Retention(RetentionPolicy.SOURCE)
diff --git a/scr-annotations/src/main/java/org/apache/felix/scr/annotations/Modified.java b/scr-annotations/src/main/java/org/apache/felix/scr/annotations/Modified.java
new file mode 100644
index 0000000..9419c2a
--- /dev/null
+++ b/scr-annotations/src/main/java/org/apache/felix/scr/annotations/Modified.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>Modified</code> annotation defines the method which is used
+ * to update 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 based on the name.
+ */
+@Target( { ElementType.METHOD })
+@Retention(RetentionPolicy.SOURCE)
+@Documented
+public @interface Modified {
+
+}
diff --git a/scrplugin/src/main/java/org/apache/felix/scrplugin/Constants.java b/scrplugin/src/main/java/org/apache/felix/scrplugin/Constants.java
index ebd5f99..41f625f 100644
--- a/scrplugin/src/main/java/org/apache/felix/scrplugin/Constants.java
+++ b/scrplugin/src/main/java/org/apache/felix/scrplugin/Constants.java
@@ -68,6 +68,9 @@
// The component activate method name (V1.1)
public static final String COMPONENT_DEACTIVATE = "deactivate";
+ // The component modified method name (V1.1)
+ public static final String COMPONENT_MODIFIED = "modified";
+
public static final String PROPERTY = "scr.property";
public static final String PROPERTY_NAME = "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 523d884..09615ca 100644
--- a/scrplugin/src/main/java/org/apache/felix/scrplugin/SCRDescriptorMojo.java
+++ b/scrplugin/src/main/java/org/apache/felix/scrplugin/SCRDescriptorMojo.java
@@ -485,6 +485,10 @@
component.setSpecVersion(Constants.VERSION_1_1);
component.setDeactivate(tag.getNamedParameter(Constants.COMPONENT_DEACTIVATE));
}
+ if ( tag.getNamedParameter(Constants.COMPONENT_MODIFIED) != null ) {
+ component.setSpecVersion(Constants.VERSION_1_1);
+ component.setModified(tag.getNamedParameter(Constants.COMPONENT_MODIFIED));
+ }
// whether metatype information is to generated for the component
final String metaType = tag.getNamedParameter(Constants.COMPONENT_METATYPE);
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 e7dccf7..7a3dab6 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
@@ -72,6 +72,9 @@
/** Deactivation method. (V1.1) */
protected String deactivate;
+ /** Modified method. (V1.1) */
+ protected String modified;
+
/** The spec version. */
protected int specVersion;
@@ -231,6 +234,21 @@
public void setActivate(final String value) {
this.activate = value;
}
+
+ /**
+ * Set the name of the modified method (or null for default)
+ */
+ public void setModified(final String value) {
+ this.modified = value;
+ }
+
+ /**
+ * Get the name of the modified method (or null for default)
+ */
+ public String getModified() {
+ return this.modified;
+ }
+
/**
* Validate the component description.
* If errors occur a message is added to the issues list,
@@ -269,6 +287,9 @@
this.checkLifecycleMethod(specVersion, javaClass, activateName, true, iLog);
this.checkLifecycleMethod(specVersion, javaClass, deactivateName, false, iLog);
+ if ( this.modified != null && specVersion == Constants.VERSION_1_1 ) {
+ this.checkLifecycleMethod(specVersion, javaClass, this.modified, true, iLog);
+ }
// ensure public default constructor
boolean constructorFound = true;
JavaMethod[] methods = javaClass.getMethods();
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
index 3421536..cacee15 100644
--- 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
@@ -139,6 +139,9 @@
if ( a.getType().getJavaClass().getFullyQualifiedName().equals(Deactivate.class.getName()) ) {
map.put(Constants.COMPONENT_DEACTIVATE, jm.getName());
}
+ if ( a.getType().getJavaClass().getFullyQualifiedName().equals(Modified.class.getName()) ) {
+ map.put(Constants.COMPONENT_MODIFIED, jm.getName());
+ }
}
}
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 e7f93ba..d997848 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
@@ -75,12 +75,15 @@
/** Component: The name attribute. */
private static final String COMPONENT_ATTR_NAME = "name";
- /** Component: The immediate attribute. */
+ /** Component: The activate attribute. */
private static final String COMPONENT_ATTR_ACTIVATE = "activate";
- /** Component: The immediate attribute. */
+ /** Component: The deactivate attribute. */
private static final String COMPONENT_ATTR_DEACTIVATE = "deactivate";
+ /** Component: The modified attribute. */
+ private static final String COMPONENT_ATTR_MODIFIED = "modified";
+
private static final String IMPLEMENTATION = "implementation";
private static final String IMPLEMENTATION_QNAME = IMPLEMENTATION;
@@ -190,6 +193,7 @@
IOUtils.addAttribute(ai, COMPONENT_ATTR_POLICY, component.getConfigurationPolicy());
IOUtils.addAttribute(ai, COMPONENT_ATTR_ACTIVATE, component.getActivate());
IOUtils.addAttribute(ai, COMPONENT_ATTR_DEACTIVATE, component.getDeactivate());
+ IOUtils.addAttribute(ai, COMPONENT_ATTR_MODIFIED, component.getModified());
}
IOUtils.indent(contentHandler, 1);
@@ -415,6 +419,7 @@
this.currentComponent.setConfigurationPolicy(attributes.getValue(COMPONENT_ATTR_POLICY));
this.currentComponent.setActivate(attributes.getValue(COMPONENT_ATTR_ACTIVATE));
this.currentComponent.setDeactivate(attributes.getValue(COMPONENT_ATTR_DEACTIVATE));
+ this.currentComponent.setModified(attributes.getValue(COMPONENT_ATTR_MODIFIED));
}
} else if (localName.equals(IMPLEMENTATION)) {
// Set the implementation class name (mandatory)