Fix FELIX-2631 Rename @Publisher and @Subscriber attributes to follow the java naming conventions
git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@1002041 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/ipojo/annotations/src/main/java/org/apache/felix/ipojo/handlers/event/Publisher.java b/ipojo/annotations/src/main/java/org/apache/felix/ipojo/handlers/event/Publisher.java
index 3db2069..0144d03 100644
--- a/ipojo/annotations/src/main/java/org/apache/felix/ipojo/handlers/event/Publisher.java
+++ b/ipojo/annotations/src/main/java/org/apache/felix/ipojo/handlers/event/Publisher.java
@@ -1,4 +1,4 @@
-/*
+/*
* 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
@@ -24,18 +24,18 @@
/**
* Event Admin Publisher handler.
- * Be aware that despite is it provided in the annotations jar,
+ * Be aware that despite is it provided in the annotations jar,
* it refers to an external handler.
* @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
*/
@Target(ElementType.FIELD)
public @interface Publisher {
-
+
/**
* Sets the publisher name.
*/
String name();
-
+
/**
* Sets topics on which event are sent.
* The topics are separated by a ',' such as in
@@ -43,18 +43,26 @@
* Default : no topics (configured in the instance configuration)
*/
String topics() default "";
-
+
/**
* Enables/Disables synchronous sending.
- * Default : false (asynchronous)
+ * Default : false (asynchronous)
*/
boolean synchronous() default false;
-
+
+ /**
+ * Sets the data key in which the data is
+ * put.
+ * Default : user.data
+ * @deprecated replaced by dataKey
+ */
+ String data_key() default "user.data";
+
/**
* Sets the data key in which the data is
* put.
* Default : user.data
*/
- String data_key() default "user.data";
+ String dataKey() default "user.data";
}
diff --git a/ipojo/annotations/src/main/java/org/apache/felix/ipojo/handlers/event/Subscriber.java b/ipojo/annotations/src/main/java/org/apache/felix/ipojo/handlers/event/Subscriber.java
index b0b2372..70cb7a8 100644
--- a/ipojo/annotations/src/main/java/org/apache/felix/ipojo/handlers/event/Subscriber.java
+++ b/ipojo/annotations/src/main/java/org/apache/felix/ipojo/handlers/event/Subscriber.java
@@ -1,4 +1,4 @@
-/*
+/*
* 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
@@ -24,18 +24,18 @@
/**
* Event Admin Subscriber handler.
- * Be aware that despite is it provided in the annotations jar,
+ * Be aware that despite is it provided in the annotations jar,
* it refers to an external handler.
* @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
*/
@Target(ElementType.METHOD)
public @interface Subscriber {
-
+
/**
* Sets the subscriber name.
*/
String name();
-
+
/**
* Sets topics on which event are received.
* The topics are separated by a ',' such as in
@@ -43,23 +43,38 @@
* Default : no topics (configured in the instance configuration)
*/
String topics() default "";
-
+
+ /**
+ * Sets the data key in which the data is
+ * stored.
+ * Default : no key
+ * @deprecated replaced by dataKey
+ */
+ String data_key() default "";
+
+ /**
+ * Sets the data type (type of the received data).
+ * Default : no type.
+ * @deprecated replaced by dataType
+ */
+ String data_type() default "";
+
/**
* Sets the data key in which the data is
* stored.
* Default : no key
*/
- String data_key() default "";
-
+ String dataKey() default "";
+
/**
* Sets the data type (type of the received data).
* Default : no type.
*/
- String data_type() default "";
-
-
+ String dataType() default "";
+
+
/**
- * Sets the event filter. Only event matching with the
+ * Sets the event filter. Only event matching with the
* specified LDAP filter are received.
* default : no filter;
*/
diff --git a/ipojo/handler/eventadmin/src/main/java/org/apache/felix/ipojo/handlers/event/publisher/EventAdminPublisherMetadata.java b/ipojo/handler/eventadmin/src/main/java/org/apache/felix/ipojo/handlers/event/publisher/EventAdminPublisherMetadata.java
index 4358836..1c210ea 100644
--- a/ipojo/handler/eventadmin/src/main/java/org/apache/felix/ipojo/handlers/event/publisher/EventAdminPublisherMetadata.java
+++ b/ipojo/handler/eventadmin/src/main/java/org/apache/felix/ipojo/handlers/event/publisher/EventAdminPublisherMetadata.java
@@ -1,4 +1,4 @@
-/*
+/*
* 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
@@ -25,7 +25,7 @@
/**
* Represent a publisher.
- *
+ *
* @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
*/
class EventAdminPublisherMetadata {
@@ -96,7 +96,7 @@
/**
* Constructs a publisher from its metadata description.
- *
+ *
* @param publisher the publisher metadata description.
* @throws ConfigurationException if the configuration of the component or
* the instance is invalid.
@@ -151,7 +151,11 @@
if (publisher.containsAttribute(DATA_KEY_ATTRIBUTE)) {
m_dataKey = publisher.getAttribute(DATA_KEY_ATTRIBUTE);
} else if (publisher.containsAttribute("data_key")) {
+ // XML Case
m_dataKey = publisher.getAttribute("data_key");
+ } else if (publisher.containsAttribute("dataKey")) {
+ // Annotation case.
+ m_dataKey = publisher.getAttribute("dataKey");
} else {
m_dataKey = DEFAULT_DATA_KEY_VALUE;
}
@@ -159,7 +163,7 @@
/**
* Sets the topics attribute of the publisher.
- *
+ *
* @param topicsString the comma separated list of the topics on which
* events are sent
* @throws ConfigurationException the specified topic string is malformed
@@ -180,7 +184,7 @@
/**
* Checks that the required instance configurable attributes are all set.
- *
+ *
* @throws ConfigurationException if a required attribute is missing
*/
public void check() throws ConfigurationException {
@@ -193,7 +197,7 @@
/**
* Gets the name attribute of the publisher.
- *
+ *
* @return the name
*/
public String getName() {
@@ -202,7 +206,7 @@
/**
* Gets the field attribute of the publisher.
- *
+ *
* @return the field
*/
public String getField() {
@@ -211,7 +215,7 @@
/**
* Gets the topics attribute of the publisher.
- *
+ *
* @return the topics
*/
public String[] getTopics() {
@@ -220,7 +224,7 @@
/**
* Gets the synchronous attribute of the publisher.
- *
+ *
* @return the synchronous mode
*/
public boolean isSynchronous() {
@@ -229,7 +233,7 @@
/**
* Gets the dataKey attribute of the publisher.
- *
+ *
* @return the data key
*/
public String getDataKey() {
diff --git a/ipojo/handler/eventadmin/src/main/java/org/apache/felix/ipojo/handlers/event/subscriber/EventAdminSubscriberMetadata.java b/ipojo/handler/eventadmin/src/main/java/org/apache/felix/ipojo/handlers/event/subscriber/EventAdminSubscriberMetadata.java
index 376df3e..3d9f0a5 100644
--- a/ipojo/handler/eventadmin/src/main/java/org/apache/felix/ipojo/handlers/event/subscriber/EventAdminSubscriberMetadata.java
+++ b/ipojo/handler/eventadmin/src/main/java/org/apache/felix/ipojo/handlers/event/subscriber/EventAdminSubscriberMetadata.java
@@ -1,4 +1,4 @@
-/*
+/*
* 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
@@ -28,7 +28,7 @@
/**
* Represent an subscriber.
- *
+ *
* @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
*/
class EventAdminSubscriberMetadata {
@@ -109,7 +109,7 @@
/**
* Constructor.
- *
+ *
* @param bundleContext the bundle context of the managed instance.
* @param subscriber the subscriber metadata.
* @throws ConfigurationException if the configuration of the component or
@@ -158,15 +158,25 @@
// DATA_KEY_ATTRIBUTE
m_dataKey = subscriber.getAttribute(DATA_KEY_ATTRIBUTE);
- if (m_dataKey == null) { // Alternative configuration
+ if (m_dataKey == null) { // Alternative configurations (data_key and dataKey)
+ // XML
m_dataKey = subscriber.getAttribute("data_key");
+ if (m_dataKey == null) {
+ // Annotation
+ m_dataKey = subscriber.getAttribute("dataKey");
+ }
}
-
+
String t = subscriber.getAttribute(DATA_TYPE_ATTRIBUTE);
- if (t == null) { // Alternative configuration
+ if (t == null) { // Alternative configurations
+ // XML
t = subscriber.getAttribute("data_type");
+ if (t == null) {
+ /// Annotation
+ t = subscriber.getAttribute("dataType");
+ }
}
-
+
if (t != null) {
// Check that the data-key attribute is set.
if (m_dataKey == null) {
@@ -194,7 +204,7 @@
/**
* Sets the topics attribute of the subscriber.
- *
+ *
* @param topicsString the comma separated list of the topics to listen
* @throws ConfigurationException if the specified topic list is malformed
*/
@@ -214,7 +224,7 @@
/**
* Sets the filter attribute of the subscriber.
- *
+ *
* @param filterString the string representation of the event filter
* @throws ConfigurationException if the LDAP filter is malformed
*/
@@ -228,7 +238,7 @@
/**
* Checks that the required instance configurable attributes are all set.
- *
+ *
* @throws ConfigurationException if a required attribute is missing
*/
public void check() throws ConfigurationException {
@@ -241,7 +251,7 @@
/**
* Gets the name attribute of the subscriber.
- *
+ *
* @return the name
*/
public String getName() {
@@ -250,7 +260,7 @@
/**
* Gets the topics attribute of the subscriber.
- *
+ *
* @return the topics
*/
public String[] getTopics() {
@@ -259,7 +269,7 @@
/**
* Gets the callback attribute of the subscriber.
- *
+ *
* @return the callback
*/
public String getCallback() {
@@ -268,7 +278,7 @@
/**
* Gets the data key attribute of the subscriber.
- *
+ *
* @return the dataKey
*/
public String getDataKey() {
@@ -277,7 +287,7 @@
/**
* Gets the data type attribute of the subscriber.
- *
+ *
* @return the dataType
*/
public Class getDataType() {
@@ -286,7 +296,7 @@
/**
* Gets the filter attribute of the subscriber.
- *
+ *
* @return the filter
*/
public Filter getFilter() {
diff --git a/ipojo/tests/core/annotations/src/main/java/org/apache/felix/ipojo/test/scenarios/annotations/EventAdmin.java b/ipojo/tests/core/annotations/src/main/java/org/apache/felix/ipojo/test/scenarios/annotations/EventAdmin.java
index bb93202..4262f94 100644
--- a/ipojo/tests/core/annotations/src/main/java/org/apache/felix/ipojo/test/scenarios/annotations/EventAdmin.java
+++ b/ipojo/tests/core/annotations/src/main/java/org/apache/felix/ipojo/test/scenarios/annotations/EventAdmin.java
@@ -6,21 +6,27 @@
public class EventAdmin extends OSGiTestCase {
String type = "org.apache.felix.ipojo.test.scenarios.component.event.PubSub";
+ String deprecated = "org.apache.felix.ipojo.test.scenarios.component.event.PubSubDeprecated";
+
String namespace = "org.apache.felix.ipojo.handlers.event";
-
+
Element component;
+ Element componentDeprecated;
private IPOJOHelper helper;
-
+
public void setUp() {
helper = new IPOJOHelper(this);
component = helper.getMetadata(type);
+ componentDeprecated = helper.getMetadata(deprecated);
assertNotNull("Check component", component);
}
-
+
public void tearDown() {
component = null;
+ componentDeprecated = null;
+
}
-
+
public void testP1() {
//P1, synchronous
Element elem = getElementByName("p1");
@@ -28,9 +34,19 @@
assertNull("Check topics", elem.getAttribute("topics"));
assertEquals("Check synchronous", "true", elem.getAttribute("synchronous"));
assertEquals("Check field", "publisher1", elem.getAttribute("field"));
- assertNull("Check data_key", elem.getAttribute("data_key"));
+ assertNull("Check data_key", elem.getAttribute("dataKey"));
}
-
+
+ public void testP1Deprecated() {
+ //P1, synchronous
+ Element elem = getDeprecatedElementByName("p1");
+ checkPublisher(elem);
+ assertNull("Check topics", elem.getAttribute("topics"));
+ assertEquals("Check synchronous", "true", elem.getAttribute("synchronous"));
+ assertEquals("Check field", "publisher1", elem.getAttribute("field"));
+ assertNull("Check data_key", elem.getAttribute("data_key"));
+ }
+
public void testP2() {
//name="p2", synchronous=false, topics="foo,bar", data_key="data"
Element elem = getElementByName("p2");
@@ -38,9 +54,19 @@
assertEquals("Check topics (" + elem.getAttribute("topics")+")", "foo,bar", elem.getAttribute("topics"));
assertEquals("Check synchronous", "false", elem.getAttribute("synchronous"));
assertEquals("Check field", "publisher2", elem.getAttribute("field"));
- assertEquals("Check data_key", "data" ,elem.getAttribute("data_key"));
+ assertEquals("Check data_key", "data" ,elem.getAttribute("dataKey"));
}
-
+
+ public void testP2Deprecated() {
+ //name="p2", synchronous=false, topics="foo,bar", data_key="data"
+ Element elem = getDeprecatedElementByName("p2");
+ checkPublisher(elem);
+ assertEquals("Check topics (" + elem.getAttribute("topics")+")", "foo,bar", elem.getAttribute("topics"));
+ assertEquals("Check synchronous", "false", elem.getAttribute("synchronous"));
+ assertEquals("Check field", "publisher2", elem.getAttribute("field"));
+ assertEquals("Check data_key", "data" ,elem.getAttribute("data_key"));
+ }
+
public void testP3() {
//name="p3", synchronous=true, topics="bar"
Element elem = getElementByName("p3");
@@ -48,44 +74,87 @@
assertEquals("Check topics", "bar" ,elem.getAttribute("topics"));
assertEquals("Check synchronous", "true", elem.getAttribute("synchronous"));
assertEquals("Check field", "publisher3", elem.getAttribute("field"));
- assertNull("Check data_key", elem.getAttribute("data_key"));
+ assertNull("Check data_key", elem.getAttribute("dataKey"));
}
-
+
+ public void testP3Deprecated() {
+ //name="p3", synchronous=true, topics="bar"
+ Element elem = getDeprecatedElementByName("p3");
+ checkPublisher(elem);
+ assertEquals("Check topics", "bar" ,elem.getAttribute("topics"));
+ assertEquals("Check synchronous", "true", elem.getAttribute("synchronous"));
+ assertEquals("Check field", "publisher3", elem.getAttribute("field"));
+ assertNull("Check data_key", elem.getAttribute("data_key"));
+ }
+
public void testS1() {
//name="s1", data_key="data"
Element elem = getElementByName("s1");
checkSubscriber(elem);
assertNull("Check topics",elem.getAttribute("topics"));
assertEquals("Check method", "receive1", elem.getAttribute("method"));
- assertEquals("Check data_key", "data" ,elem.getAttribute("data_key"));
+ assertEquals("Check data_key", "data" ,elem.getAttribute("dataKey"));
+ assertNull("Check data_type", elem.getAttribute("dataType"));
+ assertNull("Check filter", elem.getAttribute("filter"));
+ }
+
+ public void testS1Deprecated() {
+ //name="s1", data_key="data"
+ Element elem = getDeprecatedElementByName("s1");
+ checkSubscriber(elem);
+ assertNull("Check topics",elem.getAttribute("topics"));
+ assertEquals("Check method", "receive1", elem.getAttribute("method"));
+ assertEquals("Check data_key", "data" ,elem.getAttribute("data_key"));
assertNull("Check data_type", elem.getAttribute("data_type"));
assertNull("Check filter", elem.getAttribute("filter"));
}
-
+
public void testS2() {
//name="s2", topics="foo,bar", filter="(foo=true)"
Element elem = getElementByName("s2");
checkSubscriber(elem);
assertEquals("Check topics", "foo,bar", elem.getAttribute("topics"));
assertEquals("Check method", "receive2", elem.getAttribute("method"));
- assertNull("Check data_key" ,elem.getAttribute("data_key"));
+ assertNull("Check data_key" ,elem.getAttribute("dataKey"));
+ assertNull("Check data_type", elem.getAttribute("dataType"));
+ assertEquals("Check filter","(foo=true)" , elem.getAttribute("filter"));
+ }
+
+ public void testS2Deprecated() {
+ //name="s2", topics="foo,bar", filter="(foo=true)"
+ Element elem = getDeprecatedElementByName("s2");
+ checkSubscriber(elem);
+ assertEquals("Check topics", "foo,bar", elem.getAttribute("topics"));
+ assertEquals("Check method", "receive2", elem.getAttribute("method"));
+ assertNull("Check data_key" ,elem.getAttribute("data_key"));
assertNull("Check data_type", elem.getAttribute("data_type"));
assertEquals("Check filter","(foo=true)" , elem.getAttribute("filter"));
}
-
+
public void testS3() {
//name="s3", topics="foo", data_key="data", data_type="java.lang.String"
Element elem = getElementByName("s3");
checkSubscriber(elem);
assertEquals("Check topics", "foo", elem.getAttribute("topics"));
assertEquals("Check method", "receive3", elem.getAttribute("method"));
- assertEquals("Check data_key", "data" ,elem.getAttribute("data_key"));
+ assertEquals("Check data_key", "data" ,elem.getAttribute("dataKey"));
+ assertEquals("Check data_type", "java.lang.String", elem.getAttribute("dataType"));
+ assertNull("Check filter", elem.getAttribute("filter"));
+ }
+
+ public void testS3Deprecated() {
+ //name="s3", topics="foo", data_key="data", data_type="java.lang.String"
+ Element elem = getDeprecatedElementByName("s3");
+ checkSubscriber(elem);
+ assertEquals("Check topics", "foo", elem.getAttribute("topics"));
+ assertEquals("Check method", "receive3", elem.getAttribute("method"));
+ assertEquals("Check data_key", "data" ,elem.getAttribute("data_key"));
assertEquals("Check data_type", "java.lang.String", elem.getAttribute("data_type"));
assertNull("Check filter", elem.getAttribute("filter"));
}
-
-
-
+
+
+
public Element getElementByName(String name) {
Element [] elems = component.getElements();
for (int i = 0; i < elems.length; i++) {
@@ -95,7 +164,17 @@
}
return null;
}
-
+
+ public Element getDeprecatedElementByName(String name) {
+ Element [] elems = componentDeprecated.getElements();
+ for (int i = 0; i < elems.length; i++) {
+ if (elems[i].containsAttribute("name") && elems[i].getAttribute("name").equals(name)) {
+ return elems[i];
+ }
+ }
+ return null;
+ }
+
public void checkSubscriber(Element elem) {
assertNotNull("Can't check subscriber : null element",elem);
String ns = elem.getNameSpace();
@@ -104,7 +183,7 @@
assertEquals("Elem is not a subscriber : bad name", "subscriber", nm);
}
-
+
public void checkPublisher(Element elem) {
assertNotNull("Can't check publisher : null element",elem);
String ns = elem.getNameSpace();
diff --git a/ipojo/tests/core/annotations/src/main/java/org/apache/felix/ipojo/test/scenarios/component/event/PubSub.java b/ipojo/tests/core/annotations/src/main/java/org/apache/felix/ipojo/test/scenarios/component/event/PubSub.java
index be15ac2..ac75616 100644
--- a/ipojo/tests/core/annotations/src/main/java/org/apache/felix/ipojo/test/scenarios/component/event/PubSub.java
+++ b/ipojo/tests/core/annotations/src/main/java/org/apache/felix/ipojo/test/scenarios/component/event/PubSub.java
@@ -9,29 +9,29 @@
public class PubSub {
@org.apache.felix.ipojo.handlers.event.Publisher(name="p1", synchronous=true)
org.apache.felix.ipojo.handlers.event.publisher.Publisher publisher1;
-
- @org.apache.felix.ipojo.handlers.event.Publisher(name="p2", synchronous=false, topics="foo,bar", data_key="data")
+
+ @org.apache.felix.ipojo.handlers.event.Publisher(name="p2", synchronous=false, topics="foo,bar", dataKey="data")
org.apache.felix.ipojo.handlers.event.publisher.Publisher publisher2;
-
+
@org.apache.felix.ipojo.handlers.event.Publisher(name="p3", synchronous=true, topics="bar")
org.apache.felix.ipojo.handlers.event.publisher.Publisher publisher3;
-
- @Subscriber(name="s1", data_key="data")
+
+ @Subscriber(name="s1", dataKey="data")
public void receive1(Object foo) {
// Nothing
}
-
+
@Subscriber(name="s2", topics="foo,bar", filter="(foo=true)")
public void receive2(Event foo) {
// Nothing
}
-
-
- @Subscriber(name="s3", topics="foo", data_key="data", data_type="java.lang.String")
+
+
+ @Subscriber(name="s3", topics="foo", dataKey="data", dataType="java.lang.String")
public void receive3(String foo) {
// Nothing
}
-
-
-
+
+
+
}
diff --git a/ipojo/tests/core/annotations/src/main/java/org/apache/felix/ipojo/test/scenarios/component/event/PubSubDeprecated.java b/ipojo/tests/core/annotations/src/main/java/org/apache/felix/ipojo/test/scenarios/component/event/PubSubDeprecated.java
new file mode 100644
index 0000000..618f6ff
--- /dev/null
+++ b/ipojo/tests/core/annotations/src/main/java/org/apache/felix/ipojo/test/scenarios/component/event/PubSubDeprecated.java
@@ -0,0 +1,37 @@
+package org.apache.felix.ipojo.test.scenarios.component.event;
+
+import org.apache.felix.ipojo.annotations.Component;
+import org.apache.felix.ipojo.handlers.event.Subscriber;
+import org.osgi.service.event.Event;
+
+
+@Component
+public class PubSubDeprecated {
+ @org.apache.felix.ipojo.handlers.event.Publisher(name="p1", synchronous=true)
+ org.apache.felix.ipojo.handlers.event.publisher.Publisher publisher1;
+
+ @org.apache.felix.ipojo.handlers.event.Publisher(name="p2", synchronous=false, topics="foo,bar", data_key="data")
+ org.apache.felix.ipojo.handlers.event.publisher.Publisher publisher2;
+
+ @org.apache.felix.ipojo.handlers.event.Publisher(name="p3", synchronous=true, topics="bar")
+ org.apache.felix.ipojo.handlers.event.publisher.Publisher publisher3;
+
+ @Subscriber(name="s1", data_key="data")
+ public void receive1(Object foo) {
+ // Nothing
+ }
+
+ @Subscriber(name="s2", topics="foo,bar", filter="(foo=true)")
+ public void receive2(Event foo) {
+ // Nothing
+ }
+
+
+ @Subscriber(name="s3", topics="foo", data_key="data", data_type="java.lang.String")
+ public void receive3(String foo) {
+ // Nothing
+ }
+
+
+
+}