Avoid calling Filter.match(ServiceReference) to avoid ClassCastException on Equinox.
Change the iPOJO Log level key when configured from the manifest
Modify the method parsing arrays to create an empty array when parsing an empty String.
git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@650599 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/ipojo/core/src/main/java/org/apache/felix/ipojo/ComponentFactory.java b/ipojo/core/src/main/java/org/apache/felix/ipojo/ComponentFactory.java
index dbd73f2..8be6408 100644
--- a/ipojo/core/src/main/java/org/apache/felix/ipojo/ComponentFactory.java
+++ b/ipojo/core/src/main/java/org/apache/felix/ipojo/ComponentFactory.java
@@ -200,8 +200,10 @@
* Stop all the instance managers.
*/
public synchronized void stopping() {
- m_tracker.close();
- m_tracker = null;
+ if (m_tracker != null) {
+ m_tracker.close();
+ m_tracker = null;
+ }
m_classLoader = null;
m_clazz = null;
}
diff --git a/ipojo/core/src/main/java/org/apache/felix/ipojo/context/ServiceReferenceImpl.java b/ipojo/core/src/main/java/org/apache/felix/ipojo/context/ServiceReferenceImpl.java
index 7bdb382..5a57c83 100644
--- a/ipojo/core/src/main/java/org/apache/felix/ipojo/context/ServiceReferenceImpl.java
+++ b/ipojo/core/src/main/java/org/apache/felix/ipojo/context/ServiceReferenceImpl.java
@@ -18,6 +18,8 @@
*/
package org.apache.felix.ipojo.context;
+import java.util.Dictionary;
+
import org.apache.felix.ipojo.ComponentInstance;
import org.osgi.framework.Bundle;
import org.osgi.framework.ServiceReference;
@@ -87,6 +89,10 @@
public String[] getPropertyKeys() {
return m_registration.getPropertyKeys();
}
+
+ public Dictionary getProperties() {
+ return m_registration.getProperties();
+ }
/**
diff --git a/ipojo/core/src/main/java/org/apache/felix/ipojo/context/ServiceRegistrationImpl.java b/ipojo/core/src/main/java/org/apache/felix/ipojo/context/ServiceRegistrationImpl.java
index 9cd8edf..0dc8dfb 100644
--- a/ipojo/core/src/main/java/org/apache/felix/ipojo/context/ServiceRegistrationImpl.java
+++ b/ipojo/core/src/main/java/org/apache/felix/ipojo/context/ServiceRegistrationImpl.java
@@ -24,6 +24,7 @@
import java.util.Iterator;
import java.util.List;
import java.util.Map;
+import java.util.Properties;
import org.apache.felix.ipojo.ComponentInstance;
import org.apache.felix.ipojo.InstanceManager;
@@ -155,7 +156,6 @@
/**
* Look for a property in the service properties.
- *
* @param key : property key
* @return the object associated with the key or null if the key is not
* present.
@@ -179,6 +179,22 @@
return (String[]) m_list.toArray(new String[m_list.size()]);
}
}
+
+ /**
+ * Gets the published properties.
+ * @return the dictionary containing each published properties.
+ */
+ protected Dictionary getProperties() {
+ synchronized (m_propMap) {
+ Dictionary dict = new Properties();
+ Iterator keys = m_propMap.keySet().iterator();
+ while (keys.hasNext()) {
+ String key = (String) keys.next();
+ dict.put(key, m_propMap.get(key));
+ }
+ return dict;
+ }
+ }
/**
* Get the service object.
@@ -196,7 +212,6 @@
/**
* Initialize properties.
- *
* @param dict : service properties to publish.
*/
private void initializeProperties(Dictionary dict) {
diff --git a/ipojo/core/src/main/java/org/apache/felix/ipojo/context/ServiceRegistry.java b/ipojo/core/src/main/java/org/apache/felix/ipojo/context/ServiceRegistry.java
index 6eb3d7e..3eaebdd 100644
--- a/ipojo/core/src/main/java/org/apache/felix/ipojo/context/ServiceRegistry.java
+++ b/ipojo/core/src/main/java/org/apache/felix/ipojo/context/ServiceRegistry.java
@@ -177,7 +177,8 @@
if (info.m_filter == null) {
info.m_listener.serviceChanged(event);
}
- if (info.m_filter != null && info.m_filter.match(ref)) {
+ Dictionary props = ((ServiceReferenceImpl) ref).getProperties();
+ if (info.m_filter != null && info.m_filter.match(props)) {
info.m_listener.serviceChanged(event);
}
}
@@ -210,15 +211,16 @@
boolean matched = false;
// If className is null, then look at filter only.
- if ((className == null) && ((filter == null) || filter.match(reg.getReference()))) {
+ if ((className == null) && ((filter == null) || filter.match(reg.getProperties()))) {
matched = true;
} else if (className != null) {
// If className is not null, then first match the
// objectClass property before looking at the
// filter.
- String[] objectClass = (String[]) ((ServiceRegistrationImpl) reg).getProperty(Constants.OBJECTCLASS);
+ Dictionary props = ((ServiceRegistrationImpl) reg).getProperties();
+ String[] objectClass = (String[]) props.get(Constants.OBJECTCLASS);
for (int classIdx = 0; classIdx < objectClass.length; classIdx++) {
- if (objectClass[classIdx].equals(className) && ((filter == null) || filter.match(reg.getReference()))) {
+ if (objectClass[classIdx].equals(className) && ((filter == null) || filter.match(props))) {
matched = true;
break;
}
diff --git a/ipojo/core/src/main/java/org/apache/felix/ipojo/handlers/providedservice/ProvidedServiceHandler.java b/ipojo/core/src/main/java/org/apache/felix/ipojo/handlers/providedservice/ProvidedServiceHandler.java
index 1fc3e1d..fad5a30 100644
--- a/ipojo/core/src/main/java/org/apache/felix/ipojo/handlers/providedservice/ProvidedServiceHandler.java
+++ b/ipojo/core/src/main/java/org/apache/felix/ipojo/handlers/providedservice/ProvidedServiceHandler.java
@@ -506,7 +506,7 @@
try {
all = computeInterfaces(serviceSpecification, parent, desc.getBundleContext().getBundle());
} catch (ClassNotFoundException e) {
- throw new ConfigurationException("A interface cannot be loaded : " + e.getMessage());
+ throw new ConfigurationException("An interface cannot be loaded : " + e.getMessage());
}
String serviceSpecificationStr = provides[i].getAttribute("interface");
@@ -540,7 +540,6 @@
}
specs.append('}');
-
provides[i].addAttribute(new Attribute("interface", specs.toString())); // Add interface attribute to avoid checking in the configure method
Element[] props = provides[i].getElements("property");
diff --git a/ipojo/core/src/main/java/org/apache/felix/ipojo/parser/ManifestMetadataParser.java b/ipojo/core/src/main/java/org/apache/felix/ipojo/parser/ManifestMetadataParser.java
index ea0709e..833be9c 100644
--- a/ipojo/core/src/main/java/org/apache/felix/ipojo/parser/ManifestMetadataParser.java
+++ b/ipojo/core/src/main/java/org/apache/felix/ipojo/parser/ManifestMetadataParser.java
@@ -210,6 +210,22 @@
}
return parser.m_elements[0];
}
+
+ /**
+ * Parse the metadata from the given header string.
+ * @param header : the header to parse
+ * @return Element : the root element resulting of the parsing
+ * @throws ParseException : if any error occurs
+ */
+ public static Element parseHeaderMetadata(String header) throws ParseException {
+ ManifestMetadataParser parser = new ManifestMetadataParser();
+ parser.addElement(new Element("iPOJO", ""));
+ parser.parseElements(header);
+ if (parser.m_elements.length != 1) {
+ throw new ParseException("Error in parsing, root element not found : " + header);
+ }
+ return parser.m_elements[0];
+ }
/**
* Parse the given string.
diff --git a/ipojo/core/src/main/java/org/apache/felix/ipojo/parser/ParseUtils.java b/ipojo/core/src/main/java/org/apache/felix/ipojo/parser/ParseUtils.java
index e1597a3..e8d5bba 100644
--- a/ipojo/core/src/main/java/org/apache/felix/ipojo/parser/ParseUtils.java
+++ b/ipojo/core/src/main/java/org/apache/felix/ipojo/parser/ParseUtils.java
@@ -36,6 +36,10 @@
* @return the resulting string array
*/
public static String[] parseArrays(String str) {
+ if (str.length() == 0) {
+ return new String[0];
+ }
+
// Remove { and }
if (str.charAt(0) == '{' && str.charAt(str.length() - 1) == '}') {
String internal = (str.substring(1, str.length() - 1)).trim();
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 d644805..21b9b3a 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
@@ -24,6 +24,7 @@
import java.util.List;
import org.apache.felix.ipojo.ConfigurationException;
+import org.apache.felix.ipojo.context.ServiceReferenceImpl;
import org.apache.felix.ipojo.metadata.Element;
import org.osgi.framework.BundleContext;
import org.osgi.framework.Filter;
@@ -240,11 +241,32 @@
* @see org.apache.felix.ipojo.util.TrackerCustomizer#addedService(org.osgi.framework.ServiceReference)
*/
public void addedService(ServiceReference ref) {
- if ((m_filter == null || m_filter.match(ref)) && match(ref)) {
+ if (matchAgainstFilter(ref) && match(ref)) {
manageArrival(ref);
}
// Do not store the service if it doesn't match.
}
+
+ /**
+ * Check if the given service reference match the current filter.
+ * This method aims to avoid calling {@link Filter#match(ServiceReference)}
+ * method when manipulating a composite reference. In fact, this method throws
+ * a {@link ClassCastException} on Equinox.
+ * @param ref : the service reference to check.
+ * @return true if the service reference matches.
+ */
+ private boolean matchAgainstFilter(ServiceReference ref) {
+ boolean match = true;
+ if (m_filter != null) {
+ if (ref instanceof ServiceReferenceImpl) {
+ // Can't use the match(ref) as it throw a class cast exception on Equinox.
+ match = m_filter.match(((ServiceReferenceImpl) ref).getProperties());
+ } else { // Non composite reference.
+ match = m_filter.match(ref);
+ }
+ }
+ return match;
+ }
/**
* Manage the arrival of a new service reference. The reference is valid and match the filter and the match method. This method has different
@@ -346,7 +368,7 @@
public void modifiedService(ServiceReference ref, Object arg1) {
if (m_matchingRefs.contains(ref)) {
// It's a used service. Check if the service always match.
- if (!(m_filter == null || m_filter.match(ref)) && match(ref)) {
+ if (!matchAgainstFilter(ref) && match(ref)) {
// The service does not match anymore. Call removedService.
manageDeparture(ref, arg1);
} else {
@@ -354,7 +376,7 @@
}
} else {
// The service was not used. Check if it matches.
- if ((m_filter == null || m_filter.match(ref)) && match(ref)) {
+ if (matchAgainstFilter(ref) && match(ref)) {
manageArrival(ref);
}
// Else, the service does not match.
@@ -522,7 +544,7 @@
// Compute matching services.
List matching = new ArrayList();
for (int i = 0; i < refs.length; i++) {
- if (m_filter == null || m_filter.match(refs[i]) && match(refs[i])) {
+ if (matchAgainstFilter(refs[i]) && match(refs[i])) {
matching.add(refs[i]);
}
}
diff --git a/ipojo/core/src/main/java/org/apache/felix/ipojo/util/Logger.java b/ipojo/core/src/main/java/org/apache/felix/ipojo/util/Logger.java
index c8b8c26..0cde723 100644
--- a/ipojo/core/src/main/java/org/apache/felix/ipojo/util/Logger.java
+++ b/ipojo/core/src/main/java/org/apache/felix/ipojo/util/Logger.java
@@ -244,7 +244,8 @@
// If null, look in bundle manifest
if (level == null) {
- level = (String) context.getBundle().getHeaders().get(IPOJO_LOG_LEVEL);
+ String key = IPOJO_LOG_LEVEL.replace('.', '-');
+ level = (String) context.getBundle().getHeaders().get(key);
}
if (level != null) {
diff --git a/ipojo/core/src/main/java/org/apache/felix/ipojo/util/Property.java b/ipojo/core/src/main/java/org/apache/felix/ipojo/util/Property.java
index 3c11693..a36bf40 100644
--- a/ipojo/core/src/main/java/org/apache/felix/ipojo/util/Property.java
+++ b/ipojo/core/src/main/java/org/apache/felix/ipojo/util/Property.java
@@ -318,7 +318,9 @@
if (Character.TYPE.equals(type)) { return new Character(strValue.charAt(0)); }
// Array :
- if (type.isArray()) { return createArrayObject(type.getComponentType(), ParseUtils.parseArrays(strValue)); }
+ if (type.isArray()) {
+ return createArrayObject(type.getComponentType(), ParseUtils.parseArrays(strValue));
+ }
// Else it is a neither a primitive type neither a String -> create
// the object by calling a constructor with a string in argument.
try {
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 7dd3349..a4d3526 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
@@ -24,6 +24,7 @@
import java.util.LinkedList;
import java.util.List;
+import org.apache.felix.ipojo.context.ServiceReferenceImpl;
import org.osgi.framework.BundleContext;
import org.osgi.framework.Constants;
import org.osgi.framework.Filter;
@@ -607,8 +608,15 @@
switch (event.getType()) {
case ServiceEvent.REGISTERED:
case ServiceEvent.MODIFIED:
- if (m_listenerFilter == null) { // user supplied filter
- if (m_filter.match(reference)) {
+ if (m_listenerFilter == null) { // user supplied filter
+ boolean match = true;
+ if (reference instanceof ServiceReferenceImpl) {
+ // Can't use the match(ref) as it throw a class cast exception on Equinox.
+ match = m_filter.match(((ServiceReferenceImpl) reference).getProperties());
+ } else { // Non compute reference.
+ match = m_filter.match(reference);
+ }
+ if (match) {
track(reference); // Arrival
} else {
untrack(reference); // Departure