Add missing attributes in annotations (binding policy, nullable, default-implementation)
Modify the dynamic-priority binding policy in order to be able to sort the references when a provider modifies a service property influencing the ranking.
(and some cosmetic fix)
git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@651644 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/ipojo/annotations/src/main/java/org/apache/felix/ipojo/annotations/Bind.java b/ipojo/annotations/src/main/java/org/apache/felix/ipojo/annotations/Bind.java
index 7e23a3c..aeef012 100644
--- a/ipojo/annotations/src/main/java/org/apache/felix/ipojo/annotations/Bind.java
+++ b/ipojo/annotations/src/main/java/org/apache/felix/ipojo/annotations/Bind.java
@@ -57,5 +57,12 @@
* Default : empty
*/
String id() default "";
+
+ /**
+ * Set the binding policy.
+ * Acceptable policy are dynamic, static and dynamic-priority.
+ * Default: dynamic.
+ */
+ String policy() default "dynamic";
}
diff --git a/ipojo/annotations/src/main/java/org/apache/felix/ipojo/annotations/Component.java b/ipojo/annotations/src/main/java/org/apache/felix/ipojo/annotations/Component.java
index 321a7b3..96984d9 100644
--- a/ipojo/annotations/src/main/java/org/apache/felix/ipojo/annotations/Component.java
+++ b/ipojo/annotations/src/main/java/org/apache/felix/ipojo/annotations/Component.java
@@ -58,4 +58,10 @@
* default: false
*/
boolean propagation() default false;
+
+ /**
+ * Set the Managed Service PID.
+ * default no PID (i.e. the managed service will not be exposed).
+ */
+ String managedservice() default "";
}
diff --git a/ipojo/annotations/src/main/java/org/apache/felix/ipojo/annotations/Property.java b/ipojo/annotations/src/main/java/org/apache/felix/ipojo/annotations/Property.java
index ac0c7dd..f077397 100644
--- a/ipojo/annotations/src/main/java/org/apache/felix/ipojo/annotations/Property.java
+++ b/ipojo/annotations/src/main/java/org/apache/felix/ipojo/annotations/Property.java
@@ -40,4 +40,5 @@
* Default : empty
*/
String value() default "";
+
}
diff --git a/ipojo/annotations/src/main/java/org/apache/felix/ipojo/annotations/Requires.java b/ipojo/annotations/src/main/java/org/apache/felix/ipojo/annotations/Requires.java
index 146f239..15794ef 100644
--- a/ipojo/annotations/src/main/java/org/apache/felix/ipojo/annotations/Requires.java
+++ b/ipojo/annotations/src/main/java/org/apache/felix/ipojo/annotations/Requires.java
@@ -40,11 +40,29 @@
*/
boolean optional() default false;
-
/**
* Set the dependency id.
* Default : empty
*/
String id() default "";
-
+
+ /**
+ * Enable / Disable nullable pattern.
+ * Default : true
+ */
+ boolean nullable() default true;
+
+ /**
+ * Set the default-implementation to use if the dependency is optional,
+ * and no providers are available.
+ * Default : no default-implementation
+ */
+ String defaultimplementation() default "";
+
+ /**
+ * Set the binding policy.
+ * Acceptable policy are dynamic, static and dynamic-priority.
+ * Default: dynamic.
+ */
+ String policy() default "dynamic";
}
diff --git a/ipojo/annotations/src/main/java/org/apache/felix/ipojo/annotations/Unbind.java b/ipojo/annotations/src/main/java/org/apache/felix/ipojo/annotations/Unbind.java
index 73cd9fa..711b52f 100644
--- a/ipojo/annotations/src/main/java/org/apache/felix/ipojo/annotations/Unbind.java
+++ b/ipojo/annotations/src/main/java/org/apache/felix/ipojo/annotations/Unbind.java
@@ -58,5 +58,12 @@
* Default : empty.
*/
String id() default "";
+
+ /**
+ * Set the binding policy.
+ * Acceptable policy are dynamic, static and dynamic-priority.
+ * Default: dynamic.
+ */
+ String policy() default "dynamic";
}
diff --git a/ipojo/core/src/main/java/org/apache/felix/ipojo/util/DependencyModel.java b/ipojo/core/src/main/java/org/apache/felix/ipojo/util/DependencyModel.java
index 21b9b3a..38b9a8b 100644
--- a/ipojo/core/src/main/java/org/apache/felix/ipojo/util/DependencyModel.java
+++ b/ipojo/core/src/main/java/org/apache/felix/ipojo/util/DependencyModel.java
@@ -112,7 +112,7 @@
/**
* Binding policy of the dependency.
*/
- private int m_policy = DYNAMIC_BINDING_POLICY; // Is notas we have to handler policy change in a future version.
+ private int m_policy = DYNAMIC_BINDING_POLICY;
/**
* Service tracker used by this dependency.
@@ -460,7 +460,17 @@
* @param ref : modified service reference.
*/
public void onServiceModification(ServiceReference ref) {
- // Do nothing by default.
+ if (m_policy == DYNAMIC_PRIORITY_BINDING_POLICY) {
+ // Check that the order has changed or not.
+ int indexBefore = m_matchingRefs.indexOf(ref);
+ Collections.sort(m_matchingRefs, m_comparator);
+ if (indexBefore != m_matchingRefs.indexOf(ref) && ! m_aggregate) {
+ // The order has changed during the sort.
+ onServiceDeparture((ServiceReference) m_matchingRefs.get(1));
+ onServiceArrival(ref);
+ }
+
+ }
}
/**
diff --git a/ipojo/core/src/main/java/org/apache/felix/ipojo/util/ServiceReferenceRankingComparator.java b/ipojo/core/src/main/java/org/apache/felix/ipojo/util/ServiceReferenceRankingComparator.java
index 6263c63..c320f9d 100644
--- a/ipojo/core/src/main/java/org/apache/felix/ipojo/util/ServiceReferenceRankingComparator.java
+++ b/ipojo/core/src/main/java/org/apache/felix/ipojo/util/ServiceReferenceRankingComparator.java
@@ -70,9 +70,9 @@
}
} else if (rank1 > rank2) {
- return 1;
- } else {
return -1;
+ } else {
+ return 1;
}
} else {
diff --git a/ipojo/core/src/main/java/org/apache/felix/ipojo/util/Tracker.java b/ipojo/core/src/main/java/org/apache/felix/ipojo/util/Tracker.java
index a4d3526..9fe4925 100644
--- a/ipojo/core/src/main/java/org/apache/felix/ipojo/util/Tracker.java
+++ b/ipojo/core/src/main/java/org/apache/felix/ipojo/util/Tracker.java
@@ -222,7 +222,6 @@
try {
m_context.removeServiceListener(outgoing);
} catch (IllegalStateException e) { //NOPMD
- //System.err.println("Context stopped");
/* In case the context was stopped. */
}
if (references != null) {
diff --git a/ipojo/jmx.handler/src/main/java/org/apache/felix/ipojo/handlers/jmx/MBeanHandler.java b/ipojo/jmx.handler/src/main/java/org/apache/felix/ipojo/handlers/jmx/MBeanHandler.java
index ff3dd17..c751392 100644
--- a/ipojo/jmx.handler/src/main/java/org/apache/felix/ipojo/handlers/jmx/MBeanHandler.java
+++ b/ipojo/jmx.handler/src/main/java/org/apache/felix/ipojo/handlers/jmx/MBeanHandler.java
@@ -191,7 +191,7 @@
/**
* getterCallback : call when a POJO member is modified by the MBean.
- * @pojo : pojo object.
+ * @param pojo : pojo object.
* @param fieldName : name of the modified field
* @param value : old value of the field
* @return : new value of the field
diff --git a/ipojo/manipulator/src/main/java/org/apache/felix/ipojo/manipulation/annotations/FieldCollector.java b/ipojo/manipulator/src/main/java/org/apache/felix/ipojo/manipulation/annotations/FieldCollector.java
index a439e38..408b40a 100644
--- a/ipojo/manipulator/src/main/java/org/apache/felix/ipojo/manipulation/annotations/FieldCollector.java
+++ b/ipojo/manipulator/src/main/java/org/apache/felix/ipojo/manipulation/annotations/FieldCollector.java
@@ -136,6 +136,21 @@
private String m_id;
/**
+ * Binding policy.
+ */
+ private String m_policy;
+
+ /**
+ * Default-Implementation attribute.
+ */
+ private String m_defaultImplementation;
+
+ /**
+ * Enable or Disable Nullable pattern.
+ */
+ private String m_nullable;
+
+ /**
* Constructor.
* @param name : field name.
*/
@@ -158,6 +173,18 @@
m_optional = arg1.toString();
return;
}
+ if (arg0.equals("nullable")) {
+ m_nullable = arg1.toString();
+ return;
+ }
+ if (arg0.equals("policy")) {
+ m_policy = arg1.toString();
+ return;
+ }
+ if (arg0.equals("defaultimplementation")) {
+ m_defaultImplementation = arg1.toString();
+ return;
+ }
if (arg0.equals("specification")) {
m_specification = arg1.toString();
return;
@@ -198,6 +225,15 @@
if (m_optional != null) {
req.addAttribute(new Attribute("optional", m_optional));
}
+ if (m_nullable != null) {
+ req.addAttribute(new Attribute("nullable", m_nullable));
+ }
+ if (m_defaultImplementation != null) {
+ req.addAttribute(new Attribute("default-implementation", m_defaultImplementation));
+ }
+ if (m_policy != null) {
+ req.addAttribute(new Attribute("policy", m_policy));
+ }
if (m_id != null) {
req.addAttribute(new Attribute("id", m_id));
}
diff --git a/ipojo/manipulator/src/main/java/org/apache/felix/ipojo/manipulation/annotations/MetadataCollector.java b/ipojo/manipulator/src/main/java/org/apache/felix/ipojo/manipulation/annotations/MetadataCollector.java
index e2ed9ea..e38ed2c 100644
--- a/ipojo/manipulator/src/main/java/org/apache/felix/ipojo/manipulation/annotations/MetadataCollector.java
+++ b/ipojo/manipulator/src/main/java/org/apache/felix/ipojo/manipulation/annotations/MetadataCollector.java
@@ -295,6 +295,16 @@
* Does the component propagate configuration to provided services?
*/
private String m_propagation;
+
+ /**
+ * Managed Service PID.
+ */
+ private String m_managedservice;
+
+ /**
+ * Element properties.
+ */
+ private Element m_props;
/**
* Visit @component annotation attribute.
@@ -323,6 +333,10 @@
m_propagation = arg1.toString();
return;
}
+ if (arg0.equals("managedservice")) {
+ m_managedservice = arg1.toString();
+ return;
+ }
}
/**
@@ -347,10 +361,20 @@
m_elem.addAttribute(new Attribute("immediate", m_immediate));
}
if (m_propagation != null) {
- Element props = new Element("properties", "");
- props.addAttribute(new Attribute("propagation", m_propagation));
- getIds().put("properties", props);
- getElements().put(props, null);
+ if (m_props == null) {
+ m_props = new Element("properties", "");
+ getElements().put(m_props, null);
+ getIds().put("properties", m_props);
+ }
+ m_props.addAttribute(new Attribute("propagation", m_propagation));
+ }
+ if (m_managedservice != null) {
+ if (m_props == null) {
+ m_props = new Element("properties", "");
+ getElements().put(m_props, null);
+ getIds().put("properties", m_props);
+ }
+ m_props.addAttribute(new Attribute("pid", m_managedservice));
}
}
}
diff --git a/ipojo/manipulator/src/main/java/org/apache/felix/ipojo/manipulation/annotations/MethodCollector.java b/ipojo/manipulator/src/main/java/org/apache/felix/ipojo/manipulation/annotations/MethodCollector.java
index 0c5d53b..0b36062 100644
--- a/ipojo/manipulator/src/main/java/org/apache/felix/ipojo/manipulation/annotations/MethodCollector.java
+++ b/ipojo/manipulator/src/main/java/org/apache/felix/ipojo/manipulation/annotations/MethodCollector.java
@@ -187,6 +187,11 @@
* Bind or Unbind method?
*/
private String m_type;
+
+ /**
+ * Binding policy.
+ */
+ private String m_policy;
/**
* Constructor.
@@ -221,6 +226,10 @@
m_specification = arg1.toString();
return;
}
+ if (arg0.equals("policy")) {
+ m_policy = arg1.toString();
+ return;
+ }
if (arg0.equals("id")) {
m_id = arg1.toString();
return;
@@ -260,6 +269,9 @@
if (m_optional != null) {
req.addAttribute(new Attribute("optional", m_optional));
}
+ if (m_policy != null) {
+ req.addAttribute(new Attribute("policy", m_policy));
+ }
if (m_id != null) {
req.addAttribute(new Attribute("id", m_id));
}