Fix FELIX-2666 Rename the temporal handler annotation to avoid collision
@Requires (for temporal dependencies) becomes deprecated, replaced by @Temporal.
git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@1052475 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/ipojo/handler/temporal/src/main/java/org/apache/felix/ipojo/handler/temporal/TemporalHandler.java b/ipojo/handler/temporal/src/main/java/org/apache/felix/ipojo/handler/temporal/TemporalHandler.java
index de9c2a8..6e05562 100644
--- a/ipojo/handler/temporal/src/main/java/org/apache/felix/ipojo/handler/temporal/TemporalHandler.java
+++ b/ipojo/handler/temporal/src/main/java/org/apache/felix/ipojo/handler/temporal/TemporalHandler.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
@@ -41,12 +41,12 @@
* @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
*/
public class TemporalHandler extends PrimitiveHandler implements DependencyStateListener {
-
+
/**
* Default timeout if not specified.
*/
public static final int DEFAULT_TIMEOUT = 3000;
-
+
/**
* No policy.
*/
@@ -64,15 +64,15 @@
*/
public static final int EMPTY = 3;
/**
- * Uses {@code null}.
+ * Uses {@code null}.
*/
public static final int NULL = 4;
-
+
/**
* The handler namespace.
*/
public static final String NAMESPACE = "org.apache.felix.ipojo.handler.temporal";
-
+
/**
* The list of managed dependencies.
*/
@@ -87,7 +87,7 @@
((TemporalDependency) m_dependencies.get(i)).start();
}
}
-
+
/**
* Stop method. Stops managed dependencies.
* @see org.apache.felix.ipojo.Handler#stop()
@@ -109,6 +109,12 @@
public void configure(Element meta, Dictionary dictionary) throws ConfigurationException {
PojoMetadata manipulation = getFactory().getPojoMetadata();
Element[] deps = meta.getElements("requires", NAMESPACE);
+
+ // Also check with temporal is no requires.
+ if (deps == null || deps.length == 0) {
+ deps = meta.getElements("temporal", NAMESPACE);
+ }
+
for (int i = 0; i < deps.length; i++) {
if (!deps[i].containsAttribute("field") || m_dependencies.contains(deps[i].getAttribute("field"))) {
error("One temporal dependency must be attached to a field or the field is already used");
@@ -120,10 +126,10 @@
if (fieldmeta == null) {
error("The field " + field + " does not exist in the class " + getInstanceManager().getClassName());
return;
- }
-
+ }
+
String fil = deps[i].getAttribute("filter");
- Filter filter = null;
+ Filter filter = null;
if (fil != null) {
try {
filter = getInstanceManager().getContext().createFilter(fil);
@@ -132,7 +138,7 @@
return;
}
}
-
+
boolean agg = false;
boolean collection = false;
String spec = fieldmeta.getFieldType();
@@ -148,24 +154,24 @@
error("A dependency injected inside a Collection must contain the 'specification' attribute");
}
}
-
+
String prox = deps[i].getAttribute("proxy");
//boolean proxy = prox != null && prox.equals("true");
// Use proxy by default except for array:
boolean proxy = prox == null || prox.equals("true");
-
+
if (prox == null && proxy) { // Proxy set because of the default.
if (agg && ! collection) { // Aggregate and array
proxy = false;
}
}
-
+
if (proxy && agg) {
if (! collection) {
error("Proxied aggregate temporal dependencies cannot be an array. Only collections are supported");
}
}
-
+
long timeout = DEFAULT_TIMEOUT;
if (deps[i].containsAttribute("timeout")) {
String to = deps[i].getAttribute("timeout");
@@ -175,7 +181,7 @@
timeout = new Long(deps[i].getAttribute("timeout")).longValue();
}
}
-
+
int policy = NO_POLICY;
String di = null;
String onTimeout = deps[i].getAttribute("onTimeout");
@@ -195,20 +201,20 @@
policy = DEFAULT_IMPLEMENTATION;
}
}
-
+
Class specification = DependencyModel.loadSpecification(spec, getInstanceManager().getContext());
TemporalDependency dep = new TemporalDependency(specification, agg, collection, proxy, filter, getInstanceManager().getContext(), timeout, policy, di, this);
m_dependencies.add(dep);
-
+
if (! proxy) { // Register method interceptor only if are not a proxy
MethodMetadata[] methods = manipulation.getMethods();
for (int k = 0; k < methods.length; k++) {
getInstanceManager().register(methods[k], dep);
}
}
-
+
getInstanceManager().register(fieldmeta, dep);
- }
+ }
}
/**
@@ -226,6 +232,6 @@
* @see org.apache.felix.ipojo.util.DependencyStateListener#validate(org.apache.felix.ipojo.util.DependencyModel)
*/
public void validate(DependencyModel dependencymodel) { }
-
+
}
diff --git a/ipojo/handler/temporal/src/main/resources/metadata.xml b/ipojo/handler/temporal/src/main/resources/metadata.xml
index bd52e4c..e514b20 100644
--- a/ipojo/handler/temporal/src/main/resources/metadata.xml
+++ b/ipojo/handler/temporal/src/main/resources/metadata.xml
@@ -6,9 +6,9 @@
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
@@ -21,4 +21,8 @@
classname="org.apache.felix.ipojo.handler.temporal.TemporalHandler"
name="requires" namespace="org.apache.felix.ipojo.handler.temporal">
</handler>
+ <handler
+ classname="org.apache.felix.ipojo.handler.temporal.TemporalHandler"
+ name="temporal" namespace="org.apache.felix.ipojo.handler.temporal">
+ </handler>
</ipojo>
\ No newline at end of file
diff --git a/ipojo/handler/temporal/src/main/resources/temporal.xsd b/ipojo/handler/temporal/src/main/resources/temporal.xsd
index 3f2d47c..33bd3bd 100644
--- a/ipojo/handler/temporal/src/main/resources/temporal.xsd
+++ b/ipojo/handler/temporal/src/main/resources/temporal.xsd
@@ -6,9 +6,9 @@
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
@@ -21,6 +21,8 @@
xmlns:xs="http://www.w3.org/2001/XMLSchema"
elementFormDefault="qualified">
<xs:element name="requires" type="TemporalServiceDependencyType"></xs:element>
+ <xs:element name="temporal" type="TemporalServiceDependencyType"></xs:element>
+
<xs:complexType name="TemporalServiceDependencyType">