You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@felix.apache.org by cl...@apache.org on 2008/03/03 16:46:43 UTC
svn commit: r633138 [5/7] - in /felix/sandbox/clement/ipojo: composite/
composite/src/main/java/org/apache/felix/ipojo/composite/
composite/src/main/java/org/apache/felix/ipojo/composite/architecture/
composite/src/main/java/org/apache/felix/ipojo/comp...
Modified: felix/sandbox/clement/ipojo/core/src/main/java/org/apache/felix/ipojo/handlers/configuration/ConfigurationHandler.java
URL: http://svn.apache.org/viewvc/felix/sandbox/clement/ipojo/core/src/main/java/org/apache/felix/ipojo/handlers/configuration/ConfigurationHandler.java?rev=633138&r1=633137&r2=633138&view=diff
==============================================================================
--- felix/sandbox/clement/ipojo/core/src/main/java/org/apache/felix/ipojo/handlers/configuration/ConfigurationHandler.java (original)
+++ felix/sandbox/clement/ipojo/core/src/main/java/org/apache/felix/ipojo/handlers/configuration/ConfigurationHandler.java Mon Mar 3 07:46:27 2008
@@ -36,6 +36,7 @@
import org.apache.felix.ipojo.parser.FieldMetadata;
import org.apache.felix.ipojo.parser.MethodMetadata;
import org.apache.felix.ipojo.parser.PojoMetadata;
+import org.apache.felix.ipojo.util.Property;
/**
* Handler managing the Configuration Admin.
@@ -46,7 +47,7 @@
/**
* List of the configurable fields.
*/
- private ConfigurableProperty[] m_configurableProperties = new ConfigurableProperty[0];
+ private Property[] m_configurableProperties = new Property[0];
/**
* ProvidedServiceHandler of the component. It is useful to propagate
@@ -71,12 +72,12 @@
/**
* Initialize the component type.
- * @param cd : component type description to populate.
+ * @param desc : component type description to populate.
* @param metadata : component type metadata.
* @throws ConfigurationException : metadata are incorrect.
* @see org.apache.felix.ipojo.Handler#initializeComponentFactory(org.apache.felix.ipojo.architecture.ComponentTypeDescription, org.apache.felix.ipojo.metadata.Element)
*/
- public void initializeComponentFactory(ComponentTypeDescription cd, Element metadata) throws ConfigurationException {
+ public void initializeComponentFactory(ComponentTypeDescription desc, Element metadata) throws ConfigurationException {
Element[] confs = metadata.getElements("Properties", "");
if (confs == null) { return; }
Element[] configurables = confs[0].getElements("Property");
@@ -90,10 +91,10 @@
String name = configurables[i].getAttribute("name");
if (name == null) {
- if (fieldName != null) {
- name = fieldName;
- } else {
+ if (fieldName == null) {
name = methodName;
+ } else {
+ name = fieldName;
}
configurables[i].addAttribute(new Attribute("name", name)); // Add the type to avoid configure checking
}
@@ -103,28 +104,28 @@
// Detect the type of the property
PojoMetadata manipulation = getFactory().getPojoMetadata();
String type = null;
- if (fieldName != null) {
- FieldMetadata fm = manipulation.getField(fieldName);
- if (fm == null) { throw new ConfigurationException("Malformed property : The field " + fieldName + " does not exist in the implementation"); }
- type = fm.getFieldType();
- configurables[i].addAttribute(new Attribute("type", type)); // Add the type to avoid configure checking
- } else {
- MethodMetadata[] mm = manipulation.getMethods(methodName);
- if (mm.length != 0) {
- if (mm[0].getMethodArguments().length != 1) {
- throw new ConfigurationException("Malformed property : The method " + methodName + " does not have one argument");
- }
- if (type != null && !type.equals(mm[0].getMethodArguments()[0])) {
- throw new ConfigurationException("Malformed property : The field type (" + type + ") and the method type (" + mm[0].getMethodArguments()[0] + ") are not the same.");
- }
- type = mm[0].getMethodArguments()[0];
- configurables[i].addAttribute(new Attribute("type", type)); // Add the type to avoid configure checking
- } else {
+ if (fieldName == null) {
+ MethodMetadata[] method = manipulation.getMethods(methodName);
+ if (method.length == 0) {
type = configurables[i].getAttribute("type");
if (type == null) {
throw new ConfigurationException("Malformed property : The type of the property cannot be discovered, please add a 'type' attribute");
}
+ } else {
+ if (method[0].getMethodArguments().length != 1) {
+ throw new ConfigurationException("Malformed property : The method " + methodName + " does not have one argument");
+ }
+ if (type != null && !type.equals(method[0].getMethodArguments()[0])) {
+ throw new ConfigurationException("Malformed property : The field type (" + type + ") and the method type (" + method[0].getMethodArguments()[0] + ") are not the same.");
+ }
+ type = method[0].getMethodArguments()[0];
+ configurables[i].addAttribute(new Attribute("type", type)); // Add the type to avoid configure checking
}
+ } else {
+ FieldMetadata field = manipulation.getField(fieldName);
+ if (field == null) { throw new ConfigurationException("Malformed property : The field " + fieldName + " does not exist in the implementation"); }
+ type = field.getFieldType();
+ configurables[i].addAttribute(new Attribute("type", type)); // Add the type to avoid configure checking
}
// Is the property set to immutable
@@ -134,10 +135,10 @@
immutable = true;
}
- if (value != null) {
- cd.addProperty(new PropertyDescription(name, type, value, immutable));
+ if (value == null) {
+ desc.addProperty(new PropertyDescription(name, type, null, false)); // Cannot be immutable if we have no value.
} else {
- cd.addProperty(new PropertyDescription(name, type, null, immutable));
+ desc.addProperty(new PropertyDescription(name, type, value, immutable));
}
}
}
@@ -153,7 +154,7 @@
*/
public void configure(Element metadata, Dictionary configuration) throws ConfigurationException {
// Store the component manager
- m_configurableProperties = new ConfigurableProperty[0];
+ m_configurableProperties = new Property[0];
// Build the map
Element[] confs = metadata.getElements("Properties", "");
@@ -168,7 +169,7 @@
m_toPropagate = configuration;
}
- List ff = new ArrayList();
+ List fields = new ArrayList();
for (int i = 0; configurables != null && i < configurables.length; i++) {
String fieldName = configurables[i].getAttribute("field");
@@ -177,34 +178,26 @@
String name = configurables[i].getAttribute("name"); // The initialize method has fixed the property name.
String value = configurables[i].getAttribute("value");
- if (configuration.get(name) != null && configuration.get(name) instanceof String) {
- value = (String) configuration.get(name);
- } else {
- if (fieldName != null && configuration.get(fieldName) != null && configuration.get(fieldName) instanceof String) {
- value = (String) configuration.get(fieldName);
- }
- }
-
String type = configurables[i].getAttribute("type"); // The initialize method has fixed the property name.
if (fieldName != null) {
- FieldMetadata fm = new FieldMetadata(fieldName, type);
- ff.add(fm);
+ FieldMetadata field = new FieldMetadata(fieldName, type);
+ fields.add(field);
}
- ConfigurableProperty cp = new ConfigurableProperty(name, fieldName, methodName, value, type, this);
- addProperty(cp);
+ Property prop = new Property(name, fieldName, methodName, value, type, getInstanceManager(), this);
+ addProperty(prop);
// Check if the instance configuration contains value for the current property :
- if (configuration.get(name) != null && !(configuration.get(name) instanceof String)) {
- cp.setValue(configuration.get(name));
- } else {
- if (fieldName != null && configuration.get(fieldName) != null && !(configuration.get(fieldName) instanceof String)) {
- cp.setValue(configuration.get(fieldName));
+ if (configuration.get(name) == null) {
+ if (fieldName != null && configuration.get(fieldName) != null) {
+ prop.setValue(configuration.get(fieldName));
}
+ } else {
+ prop.setValue(configuration.get(name));
}
}
- getInstanceManager().register(this, (FieldMetadata[]) ff.toArray(new FieldMetadata[ff.size()]), null);
+ getInstanceManager().register(this, (FieldMetadata[]) fields.toArray(new FieldMetadata[fields.size()]), null);
}
/**
@@ -213,6 +206,7 @@
* @see org.apache.felix.ipojo.Handler#stop()
*/
public void stop() {
+ // Nothing to do.
}
/**
@@ -244,11 +238,11 @@
public void onSet(Object pojo, String fieldName, Object value) {
// Verify that the field name correspond to a configurable property
for (int i = 0; i < m_configurableProperties.length; i++) {
- ConfigurableProperty cp = m_configurableProperties[i];
- if (cp.hasField() && cp.getField().equals(fieldName)) {
+ Property prop = m_configurableProperties[i];
+ if (prop.hasField() && prop.getField().equals(fieldName)) {
// Check if the value has changed
- if (cp.getValue() == null || !cp.getValue().equals(value)) {
- cp.setValue(value); // Change the value
+ if (prop.getValue() == null || !prop.getValue().equals(value)) {
+ prop.setValue(value); // Change the value
}
}
}
@@ -294,20 +288,20 @@
/**
* Add the given property metadata to the property metadata list.
*
- * @param p : property metadata to add
+ * @param prop : property metadata to add
*/
- protected void addProperty(ConfigurableProperty p) {
+ protected void addProperty(Property prop) {
for (int i = 0; (m_configurableProperties != null) && (i < m_configurableProperties.length); i++) {
- if (m_configurableProperties[i].getName().equals(p.getName())) { return; }
+ if (m_configurableProperties[i].getName().equals(prop.getName())) { return; }
}
if (m_configurableProperties.length > 0) {
- ConfigurableProperty[] newProp = new ConfigurableProperty[m_configurableProperties.length + 1];
+ Property[] newProp = new Property[m_configurableProperties.length + 1];
System.arraycopy(m_configurableProperties, 0, newProp, 0, m_configurableProperties.length);
- newProp[m_configurableProperties.length] = p;
+ newProp[m_configurableProperties.length] = prop;
m_configurableProperties = newProp;
} else {
- m_configurableProperties = new ConfigurableProperty[] { p };
+ m_configurableProperties = new Property[] { prop };
}
}
@@ -327,15 +321,15 @@
/**
* Reconfigure the component instance.
* Check if the new configuration modify the current configuration.
- * @param np : the new configuration
+ * @param configuration : the new configuration
* @see org.apache.felix.ipojo.Handler#reconfigure(java.util.Dictionary)
*/
- public void reconfigure(Dictionary np) {
+ public void reconfigure(Dictionary configuration) {
Properties toPropagate = new Properties();
- Enumeration keysEnumeration = np.keys();
+ Enumeration keysEnumeration = configuration.keys();
while (keysEnumeration.hasMoreElements()) {
String name = (String) keysEnumeration.nextElement();
- Object value = np.get(name);
+ Object value = configuration.get(name);
boolean found = false;
// Check if the name is a configurable property
for (int i = 0; i < m_configurableProperties.length; i++) {
@@ -347,7 +341,7 @@
}
if (m_configurableProperties[i].hasMethod()) {
m_configurableProperties[i].setValue(value);
- m_configurableProperties[i].invoke();
+ m_configurableProperties[i].invoke(null); // Call on all created pojo objects.
}
}
found = true;
Modified: felix/sandbox/clement/ipojo/core/src/main/java/org/apache/felix/ipojo/handlers/dependency/Dependency.java
URL: http://svn.apache.org/viewvc/felix/sandbox/clement/ipojo/core/src/main/java/org/apache/felix/ipojo/handlers/dependency/Dependency.java?rev=633138&r1=633137&r2=633138&view=diff
==============================================================================
--- felix/sandbox/clement/ipojo/core/src/main/java/org/apache/felix/ipojo/handlers/dependency/Dependency.java (original)
+++ felix/sandbox/clement/ipojo/core/src/main/java/org/apache/felix/ipojo/handlers/dependency/Dependency.java Mon Mar 3 07:46:27 2008
@@ -25,11 +25,10 @@
import java.util.Comparator;
import java.util.List;
-import org.apache.felix.ipojo.ComponentInstance;
import org.apache.felix.ipojo.InstanceManager;
import org.apache.felix.ipojo.Nullable;
import org.apache.felix.ipojo.PolicyServiceContext;
-import org.apache.felix.ipojo.util.AbstractServiceDependency;
+import org.apache.felix.ipojo.util.DependencyModel;
import org.osgi.framework.BundleContext;
import org.osgi.framework.Filter;
import org.osgi.framework.ServiceReference;
@@ -38,7 +37,7 @@
* Represent a service dependency of the component instance.
* @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
*/
-public class Dependency extends AbstractServiceDependency {
+public class Dependency extends DependencyModel {
/**
* Reference on the Dependency Handler.
@@ -64,7 +63,7 @@
* Is the provider set frozen ?
*/
private boolean m_isFrozen = false;
-
+
/**
* Is the dependency started ?
*/
@@ -93,29 +92,32 @@
/**
* Dependency constructor. After the creation the dependency is not started.
*
- * @param dh : the dependency handler managing this dependency
+ * @param handler : the dependency handler managing this dependency
* @param field : field of the dependency
* @param spec : required specification
* @param filter : LDAP filter of the dependency
* @param isOptional : is the dependency an optional dependency ?
* @param isAggregate : is the dependency an aggregate dependency
- * @param id : id of the dependency, may be null
- * @param sc : bundle context (or service context) to use.
+ * @param identity : id of the dependency, may be null
+ * @param context : bundle context (or service context) to use.
* @param policy : resolution policy
* @param cmp : comparator to sort references
- * @param di : default-implementation class
+ * @param defaultImplem : default-implementation class
*/
- public Dependency(DependencyHandler dh, String field, Class spec, Filter filter, boolean isOptional, boolean isAggregate, String id, BundleContext sc, int policy, Comparator cmp, String di) {
- super(spec, isAggregate, isOptional, filter, cmp, policy, sc, dh);
- m_handler = dh;
+ public Dependency(DependencyHandler handler, String field, Class spec, Filter filter, boolean isOptional, boolean isAggregate, String identity, BundleContext context, int policy, Comparator cmp, String defaultImplem) {
+ super(spec, isAggregate, isOptional, filter, cmp, policy, context, handler);
+ m_handler = handler;
m_field = field;
- m_di = di;
+ m_di = defaultImplem;
- if (id != null) {
- m_id = id;
- } else if (spec != null) {
- m_id = spec.getName();
- } // Else wait the setSpecification call.
+ if (identity == null) {
+ if (spec != null) {
+ m_id = spec.getName();
+ }
+ } else {
+ m_id = identity;
+ }
+ // Else wait the setSpecification call.
}
/**
@@ -123,7 +125,7 @@
* In order to store the id of the dependency, this
* method is override.
* @param spec : request service Class
- * @see org.apache.felix.ipojo.util.AbstractServiceDependency#setSpecification(java.lang.Class)
+ * @see org.apache.felix.ipojo.util.DependencyModel#setSpecification(java.lang.Class)
*/
public void setSpecification(Class spec) {
super.setSpecification(spec);
@@ -138,22 +140,22 @@
/**
* Add a callback to the dependency.
- * @param cb : callback to add
+ * @param callback : callback to add
*/
- protected void addDependencyCallback(DependencyCallback cb) {
+ protected void addDependencyCallback(DependencyCallback callback) {
if (m_callbacks.length > 0) {
DependencyCallback[] newCallbacks = new DependencyCallback[m_callbacks.length + 1];
System.arraycopy(m_callbacks, 0, newCallbacks, 0, m_callbacks.length);
- newCallbacks[m_callbacks.length] = cb;
+ newCallbacks[m_callbacks.length] = callback;
m_callbacks = newCallbacks;
} else {
- m_callbacks = new DependencyCallback[] { cb };
+ m_callbacks = new DependencyCallback[] { callback };
}
}
/**
* Stop the current dependency.
- * @see org.apache.felix.ipojo.util.AbstractServiceDependency#stop()
+ * @see org.apache.felix.ipojo.util.DependencyModel#stop()
*/
public void stop() {
m_isStarted = false;
@@ -210,40 +212,15 @@
}
}
- /**
- * Call unbind callback method.
- * @param ref : reference to send (if accepted) to the method
- */
- private void callUnbindMethod(ServiceReference ref) {
- if (m_handler.getInstanceManager().getState() > InstanceManager.STOPPED && m_handler.getInstanceManager().getPojoObjects() != null) {
- for (int i = 0; i < m_callbacks.length; i++) {
- if (m_callbacks[i].getMethodType() == DependencyCallback.UNBIND) {
- try {
- m_callbacks[i].call(ref, getService(ref));
- } catch (NoSuchMethodException e) {
- m_handler.error("The method " + m_callbacks[i].getMethodName() + " does not exist in the class " + m_handler.getInstanceManager().getClassName());
- m_handler.getInstanceManager().stop();
- } catch (IllegalAccessException e) {
- m_handler.error("The method " + m_callbacks[i].getMethodName() + " is not accessible in the class " + m_handler.getInstanceManager().getClassName());
- m_handler.getInstanceManager().stop();
- } catch (InvocationTargetException e) {
- m_handler.error("The method " + m_callbacks[i].getMethodName() + " in the class " + m_handler.getInstanceManager().getClassName() + "throws an exception : " + e.getTargetException().getMessage());
- m_handler.getInstanceManager().stop();
- }
- }
- }
- }
- }
-
public synchronized boolean isFrozen() {
return m_isFrozen;
}
/**
* Call the bind method.
- * @param instance : instance on which calling the bind method.
+ * @param pojo : pojo instance on which calling the bind method.
*/
- protected synchronized void onObjectCreation(Object instance) {
+ protected synchronized void onObjectCreation(Object pojo) {
if (!m_isStarted) { return; }
// We are notified of an instance creation, we have to freeze when the static policy is used
@@ -254,51 +231,65 @@
// Check optional case : nullable object case : do not call bind on nullable object
if (isOptional() && getSize() == 0) { return; }
- if (isAggregate()) {
- ServiceReference[] refs = getServiceReferences();
- for (int i = 0; i < refs.length; i++) {
- ServiceReference ref = (ServiceReference) refs[i];
- for (int j = 0; j < m_callbacks.length; j++) {
- if (m_callbacks[j].getMethodType() == DependencyCallback.BIND) {
- try {
- m_callbacks[j].callOnInstance(instance, ref, getService(ref));
- } catch (NoSuchMethodException e) {
- m_handler.error("The method " + m_callbacks[j].getMethodName() + " does not exist in the class " + m_handler.getInstanceManager().getClassName());
- m_handler.getInstanceManager().stop();
- } catch (IllegalAccessException e) {
- m_handler.error("The method " + m_callbacks[j].getMethodName() + " is not accessible in the class " + m_handler.getInstanceManager().getClassName());
- m_handler.getInstanceManager().stop();
- } catch (InvocationTargetException e) {
- m_handler.error("The method " + m_callbacks[j].getMethodName() + " in the class " + m_handler.getInstanceManager().getClassName() + "throws an exception : " + e.getTargetException().getMessage(), e.getTargetException());
- m_handler.getInstanceManager().setState(ComponentInstance.INVALID);
- }
+ // Call bind callback.
+ for (int j = 0; j < m_callbacks.length; j++) {
+ if (m_callbacks[j].getMethodType() == DependencyCallback.BIND) {
+ if (isAggregate()) {
+ ServiceReference[] refs = getServiceReferences();
+ for (int i = 0; i < refs.length; i++) {
+ invokeCallback(m_callbacks[j], refs[i], pojo);
+ }
+ } else {
+ ServiceReference ref = getServiceReference();
+ if (ref != null) {
+ invokeCallback(m_callbacks[j], ref, pojo);
}
}
}
- } else {
- for (int j = 0; j < m_callbacks.length; j++) {
- if (m_callbacks[j].getMethodType() == DependencyCallback.BIND) {
- try {
- ServiceReference ref = getServiceReference();
- if (ref != null) {
- m_callbacks[j].callOnInstance(instance, ref, getService(ref));
- }
- } catch (NoSuchMethodException e) {
- m_handler.error("The method " + m_callbacks[j].getMethodName() + " does not exist in the class " + m_handler.getInstanceManager().getClassName());
- m_handler.getInstanceManager().stop();
- } catch (IllegalAccessException e) {
- m_handler.error("The method " + m_callbacks[j].getMethodName() + " is not accessible in the class " + m_handler.getInstanceManager().getClassName());
- m_handler.getInstanceManager().stop();
- } catch (InvocationTargetException e) {
- m_handler.error("The method " + m_callbacks[j].getMethodName() + " in the class " + m_handler.getInstanceManager().getClassName() + "throws an exception : " + e.getTargetException().getMessage(), e.getTargetException());
- m_handler.getInstanceManager().setState(ComponentInstance.INVALID);
- }
+ }
+ }
+
+ /**
+ * Call unbind callback method.
+ * @param ref : reference to send (if accepted) to the method
+ */
+ private void callUnbindMethod(ServiceReference ref) {
+ if (m_handler.getInstanceManager().getState() > InstanceManager.STOPPED && m_handler.getInstanceManager().getPojoObjects() != null) {
+ for (int i = 0; i < m_callbacks.length; i++) {
+ if (m_callbacks[i].getMethodType() == DependencyCallback.UNBIND) {
+ invokeCallback(m_callbacks[i], ref, null); // Call on each created pojo objects.
}
}
}
}
/**
+ * Helper method calling the given callback.
+ * @param callback : callback to call.
+ * @param ref : service reference.
+ * @param pojo : pojo on which calling the callback, if null call on each created pojo objects.
+ */
+ private void invokeCallback(DependencyCallback callback, ServiceReference ref, Object pojo) {
+ try {
+ if (pojo == null) {
+ callback.call(ref, getService(ref));
+ } else {
+ callback.callOnInstance(pojo, ref, getService(ref));
+ }
+ } catch (NoSuchMethodException e) {
+ m_handler.error("The method " + callback.getMethodName() + " does not exist in the class " + m_handler.getInstanceManager().getClassName());
+ m_handler.getInstanceManager().stop();
+ } catch (IllegalAccessException e) {
+ m_handler.error("The method " + callback.getMethodName() + " is not accessible in the class " + m_handler.getInstanceManager().getClassName());
+ m_handler.getInstanceManager().stop();
+ } catch (InvocationTargetException e) {
+ m_handler.error("The method " + callback.getMethodName() + " in the class " + m_handler.getInstanceManager().getClassName() + "throws an exception : " + e.getTargetException().getMessage());
+ m_handler.getInstanceManager().stop();
+ }
+
+ }
+
+ /**
* Call bind method with the service reference in parameter (if accepted).
* @param ref : the service reference of the new service
*/
@@ -308,19 +299,7 @@
if (m_handler.getInstanceManager().getState() > InstanceManager.STOPPED && m_handler.getInstanceManager().getPojoObjects() != null) {
for (int i = 0; i < m_callbacks.length; i++) {
if (m_callbacks[i].getMethodType() == DependencyCallback.BIND) {
- try {
- m_callbacks[i].call(ref, getService(ref));
- ungetService(ref);
- } catch (NoSuchMethodException e) {
- m_handler.error("The method " + m_callbacks[i].getMethodName() + " does not exist in the class " + m_handler.getInstanceManager().getClassName());
- m_handler.getInstanceManager().stop();
- } catch (IllegalAccessException e) {
- m_handler.error("The method " + m_callbacks[i].getMethodName() + " is not accessible in the class " + m_handler.getInstanceManager().getClassName());
- m_handler.getInstanceManager().stop();
- } catch (InvocationTargetException e) {
- m_handler.error("The method " + m_callbacks[i].getMethodName() + " in the class " + m_handler.getInstanceManager().getClassName() + "throws an exception : " + e.getTargetException().getMessage());
- m_handler.getInstanceManager().setState(ComponentInstance.INVALID);
- }
+ invokeCallback(m_callbacks[i], ref, null);
}
}
}
@@ -331,10 +310,13 @@
*/
public void start() {
if (isOptional() && !isAggregate()) {
- if (m_di != null) {
+ if (m_di == null) {
+ // To load the proxy we use the POJO class loader. Indeed, this classloader imports iPOJO (so can access to Nullable) and has access to the service specification.
+ m_nullable = Proxy.newProxyInstance(getHandler().getInstanceManager().getClazz().getClassLoader(), new Class[] { getSpecification(), Nullable.class }, new NullableObject()); // NOPMD
+ } else {
try {
- Class c = getHandler().getInstanceManager().getContext().getBundle().loadClass(m_di);
- m_nullable = c.newInstance();
+ Class clazz = getHandler().getInstanceManager().getContext().getBundle().loadClass(m_di);
+ m_nullable = clazz.newInstance();
} catch (IllegalAccessException e) {
throw new IllegalStateException("Cannot load the default-implementation " + m_di + " : " + e.getMessage());
} catch (InstantiationException e) {
@@ -342,8 +324,6 @@
} catch (ClassNotFoundException e) {
throw new IllegalStateException("Cannot load the default-implementation " + m_di + " : " + e.getMessage());
}
- } else {
- m_nullable = Proxy.newProxyInstance(getHandler().getInstanceManager().getClazz().getClassLoader(), new Class[] { getSpecification(), Nullable.class }, new NullableObject());
}
}
@@ -352,7 +332,7 @@
if (getBindingPolicy() == STATIC_BINDING_POLICY && m_handler.getInstanceManager().getPojoObjects() != null) {
m_isFrozen = true;
}
-
+
m_isStarted = true;
}
@@ -404,7 +384,7 @@
/**
* A new service has to be injected.
* @param reference : the new matching service reference.
- * @see org.apache.felix.ipojo.util.AbstractServiceDependency#onServiceArrival(org.osgi.framework.ServiceReference)
+ * @see org.apache.felix.ipojo.util.DependencyModel#onServiceArrival(org.osgi.framework.ServiceReference)
*/
public void onServiceArrival(ServiceReference reference) {
callBindMethod(reference);
@@ -414,7 +394,7 @@
/**
* A used (already injected) service disappears.
* @param ref : leaving service reference.
- * @see org.apache.felix.ipojo.util.AbstractServiceDependency#onServiceDeparture(org.osgi.framework.ServiceReference)
+ * @see org.apache.felix.ipojo.util.DependencyModel#onServiceDeparture(org.osgi.framework.ServiceReference)
*/
public void onServiceDeparture(ServiceReference ref) {
callUnbindMethod(ref);
@@ -424,7 +404,7 @@
* The dependency has been reconfigured.
* @param departs : service no more matching.
* @param arrivals : new services
- * @see org.apache.felix.ipojo.util.AbstractServiceDependency#onDependencyReconfiguration(org.osgi.framework.ServiceReference[], org.osgi.framework.ServiceReference[])
+ * @see org.apache.felix.ipojo.util.DependencyModel#onDependencyReconfiguration(org.osgi.framework.ServiceReference[], org.osgi.framework.ServiceReference[])
*/
public void onDependencyReconfiguration(ServiceReference[] departs, ServiceReference[] arrivals) {
throw new UnsupportedOperationException("Dependency set change is not yet supported");
@@ -436,10 +416,10 @@
*/
public List getServiceReferencesAsList() {
ServiceReference[] refs = super.getServiceReferences();
- if (refs != null) {
- return Arrays.asList(refs);
- } else {
+ if (refs == null) {
return null;
+ } else {
+ return Arrays.asList(refs);
}
}
Modified: felix/sandbox/clement/ipojo/core/src/main/java/org/apache/felix/ipojo/handlers/dependency/DependencyCallback.java
URL: http://svn.apache.org/viewvc/felix/sandbox/clement/ipojo/core/src/main/java/org/apache/felix/ipojo/handlers/dependency/DependencyCallback.java?rev=633138&r1=633137&r2=633138&view=diff
==============================================================================
--- felix/sandbox/clement/ipojo/core/src/main/java/org/apache/felix/ipojo/handlers/dependency/DependencyCallback.java (original)
+++ felix/sandbox/clement/ipojo/core/src/main/java/org/apache/felix/ipojo/handlers/dependency/DependencyCallback.java Mon Mar 3 07:46:27 2008
@@ -107,15 +107,14 @@
if (methods[i].getName().equals(m_method)) {
// Check arguments
Class[] clazzes = methods[i].getParameterTypes();
- if (clazzes.length == m_argument.length) { // Test size to avoid useless loop
- boolean ok = true;
- for (int j = 0; j < m_argument.length; j++) {
- if (!m_argument[j].equals(clazzes[j].getName())) {
- ok = false;
+ if (clazzes.length == m_argument.length) { // Test size to avoid useless loop // NOPMD
+ int argIndex = 0;
+ for (; argIndex < m_argument.length; argIndex++) {
+ if (!m_argument[argIndex].equals(clazzes[argIndex].getName())) {
break;
}
}
- if (ok) {
+ if (argIndex == m_argument.length) { // If the array was completely read.
m_methodObj = methods[i]; // It is the looked method.
m_methodObj.setAccessible(true);
return;
Modified: felix/sandbox/clement/ipojo/core/src/main/java/org/apache/felix/ipojo/handlers/dependency/DependencyDescription.java
URL: http://svn.apache.org/viewvc/felix/sandbox/clement/ipojo/core/src/main/java/org/apache/felix/ipojo/handlers/dependency/DependencyDescription.java?rev=633138&r1=633137&r2=633138&view=diff
==============================================================================
--- felix/sandbox/clement/ipojo/core/src/main/java/org/apache/felix/ipojo/handlers/dependency/DependencyDescription.java (original)
+++ felix/sandbox/clement/ipojo/core/src/main/java/org/apache/felix/ipojo/handlers/dependency/DependencyDescription.java Mon Mar 3 07:46:27 2008
@@ -105,9 +105,9 @@
/**
* Set the service reference array.
- * @param sr : the list of service reference
+ * @param refs : the list of service reference
*/
- public void setServiceReferences(List sr) { m_serviceReferences = sr; }
+ public void setServiceReferences(List refs) { m_serviceReferences = refs; }
/**
* Get the used service set.
@@ -117,10 +117,10 @@
/**
* Set the usedServices.
- * @param hm : the list of used service reference.
+ * @param usages : the list of used service reference.
*/
- public void setUsedServices(List hm) {
- m_usedServices = hm;
+ public void setUsedServices(List usages) {
+ m_usedServices = usages;
}
Modified: felix/sandbox/clement/ipojo/core/src/main/java/org/apache/felix/ipojo/handlers/dependency/DependencyHandler.java
URL: http://svn.apache.org/viewvc/felix/sandbox/clement/ipojo/core/src/main/java/org/apache/felix/ipojo/handlers/dependency/DependencyHandler.java?rev=633138&r1=633137&r2=633138&view=diff
==============================================================================
--- felix/sandbox/clement/ipojo/core/src/main/java/org/apache/felix/ipojo/handlers/dependency/DependencyHandler.java (original)
+++ felix/sandbox/clement/ipojo/core/src/main/java/org/apache/felix/ipojo/handlers/dependency/DependencyHandler.java Mon Mar 3 07:46:27 2008
@@ -33,8 +33,8 @@
import org.apache.felix.ipojo.parser.FieldMetadata;
import org.apache.felix.ipojo.parser.MethodMetadata;
import org.apache.felix.ipojo.parser.PojoMetadata;
-import org.apache.felix.ipojo.util.AbstractServiceDependency;
-import org.apache.felix.ipojo.util.DependencyLifecycleListener;
+import org.apache.felix.ipojo.util.DependencyModel;
+import org.apache.felix.ipojo.util.DependencyStateListener;
import org.osgi.framework.BundleContext;
import org.osgi.framework.Filter;
import org.osgi.framework.InvalidSyntaxException;
@@ -44,7 +44,7 @@
* The dependency handler manages a list of service dependencies.
* @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
*/
-public class DependencyHandler extends PrimitiveHandler implements DependencyLifecycleListener {
+public class DependencyHandler extends PrimitiveHandler implements DependencyStateListener {
/**
* List of dependencies of the component.
@@ -61,16 +61,18 @@
* @param dep : the dependency to add
*/
private void addDependency(Dependency dep) {
- for (int i = 0; i < m_dependencies.length; i++) {
- if (m_dependencies[i] == dep) { return; }
+ for (int i = 0; m_dependencies != null && i < m_dependencies.length; i++) {
+ if (m_dependencies[i] == dep) {
+ return;
+ }
}
- if (m_dependencies.length > 0) {
+ if (m_dependencies == null) {
+ m_dependencies = new Dependency[] { dep };
+ } else {
Dependency[] newDep = new Dependency[m_dependencies.length + 1];
System.arraycopy(m_dependencies, 0, newDep, 0, m_dependencies.length);
newDep[m_dependencies.length] = dep;
m_dependencies = newDep;
- } else {
- m_dependencies = new Dependency[] { dep };
}
}
@@ -85,18 +87,18 @@
/**
* Validate method. This method is invoked by an AbstractServiceDependency when this dependency becomes RESOLVED.
* @param dep : the dependency becoming RESOLVED.
- * @see org.apache.felix.ipojo.util.DependencyLifecycleListener#validate(org.apache.felix.ipojo.util.AbstractServiceDependency)
+ * @see org.apache.felix.ipojo.util.DependencyStateListener#validate(org.apache.felix.ipojo.util.DependencyModel)
*/
- public void validate(AbstractServiceDependency dep) {
+ public void validate(DependencyModel dep) {
checkContext();
}
/**
* Invalidate method. This method is invoked by an AbstractServiceDependency when this dependency becomes UNRESOLVED or BROKEN.
* @param dep : the dependency becoming UNRESOLVED or BROKEN.
- * @see org.apache.felix.ipojo.util.DependencyLifecycleListener#invalidate(org.apache.felix.ipojo.util.AbstractServiceDependency)
+ * @see org.apache.felix.ipojo.util.DependencyStateListener#invalidate(org.apache.felix.ipojo.util.DependencyModel)
*/
- public void invalidate(AbstractServiceDependency dep) {
+ public void invalidate(DependencyModel dep) {
setValidity(false);
}
@@ -104,7 +106,9 @@
* Check the validity of the dependencies.
*/
protected void checkContext() {
- if (!m_started) { return; }
+ if (!m_started) {
+ return;
+ }
synchronized (m_dependencies) {
// Store the initial state
boolean initialState = getValidity();
@@ -150,88 +154,61 @@
String field = dep.getField();
DependencyCallback[] callbacks = dep.getCallbacks();
- if (callbacks.length == 0 && field == null) { throw new ConfigurationException("A service requirement requires at least callbacks or a field"); }
+ if (callbacks.length == 0 && field == null) {
+ throw new ConfigurationException("A service requirement requires at least callbacks or a field");
+ }
for (int i = 0; i < callbacks.length; i++) {
MethodMetadata[] mets = manipulation.getMethods(callbacks[i].getMethodName());
- if (mets.length != 0) {
- if (mets[0].getMethodArguments().length > 2) { throw new ConfigurationException("Requirement Callback : A requirement callback " + callbacks[i].getMethodName() + " must have 0 or 1 or 2 arguments"); }
+ if (mets.length == 0) {
+ info("A requirement callback " + callbacks[i].getMethodName() + " does not exist in the implementation, try the super classes");
+ } else {
+ if (mets[0].getMethodArguments().length > 2) {
+ throw new ConfigurationException("Requirement Callback : A requirement callback "
+ + callbacks[i].getMethodName()
+ + " must have 0 or 1 or 2 arguments");
+ }
callbacks[i].setArgument(mets[0].getMethodArguments());
+
if (mets[0].getMethodArguments().length == 1) {
if (!mets[0].getMethodArguments()[0].equals(ServiceReference.class.getName())) {
- if (dep.getSpecification() == null) {
- try {
- dep.setSpecification(getInstanceManager().getContext().getBundle().loadClass(mets[0].getMethodArguments()[0]));
- } catch (ClassNotFoundException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
- if (!dep.getSpecification().getName().equals(mets[0].getMethodArguments()[0])) {
- warn("[DependencyHandler on " + getInstanceManager().getInstanceName() + "] The field type [" + mets[0].getMethodArguments()[0] + "] and the needed service interface [" + dep.getSpecification() + "] are not the same");
- try {
- dep.setSpecification(getInstanceManager().getContext().getBundle().loadClass(mets[0].getMethodArguments()[0]));
- } catch (ClassNotFoundException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
+ // The callback receives the service object.
+ setSpecification(dep, mets[0].getMethodArguments()[0], false); // Just warn if a mismatch is discovered.
}
} else if (mets[0].getMethodArguments().length == 2) {
- // Check that the second arguments is a service reference
+ // The callback receives service object, service reference. Check that the second argument is a service reference
if (!mets[0].getMethodArguments()[1].equals(ServiceReference.class.getName())) {
- String message = "The requirement callback " + callbacks[i].getMethodName() + " must have a ServiceReference as the second arguments";
+ String message =
+ "The requirement callback " + callbacks[i].getMethodName() + " must have a ServiceReference as the second argument";
throw new ConfigurationException(message);
}
- if (dep.getSpecification() == null) {
- try {
- dep.setSpecification(getInstanceManager().getContext().getBundle().loadClass(mets[0].getMethodArguments()[0]));
- } catch (ClassNotFoundException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- } else {
- if (!dep.getSpecification().getName().equals(mets[0].getMethodArguments()[0])) {
- warn("[DependencyHandler on " + getInstanceManager().getInstanceName() + "] The field type [" + mets[0].getMethodArguments()[0] + "] and the needed service interface [" + dep.getSpecification() + "] are not the same");
- try {
- dep.setSpecification(getInstanceManager().getContext().getBundle().loadClass(mets[0].getMethodArguments()[0]));
- } catch (ClassNotFoundException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
- }
+ setSpecification(dep, mets[0].getMethodArguments()[0], false); // Just warn if a mismatch is discovered.
}
- } else {
- info("A requirement callback " + callbacks[i].getMethodName() + " does not exist in the implementation, try the super classes");
}
}
if (field != null) {
- FieldMetadata fm = manipulation.getField(field);
- if (fm == null) { throw new ConfigurationException("Requirement Callback : A requirement field " + field + " does not exist in the implementation class"); }
- String type = fm.getFieldType();
+ FieldMetadata meta = manipulation.getField(field);
+ if (meta == null) {
+ throw new ConfigurationException("Requirement Callback : A requirement field "
+ + field
+ + " does not exist in the implementation class");
+ }
+ String type = meta.getFieldType();
if (type.endsWith("[]")) {
// Set the dependency to multiple
dep.setAggregate(true);
type = type.substring(0, type.length() - 2);
} else {
- if (dep.isAggregate()) { throw new ConfigurationException("A required service is not correct : the field " + fm.getFieldName() + " must be an array to support aggregate injections"); }
- }
-
- if (dep.getSpecification() == null) {
- try {
- dep.setSpecification(getInstanceManager().getContext().getBundle().loadClass(type));
- } catch (ClassNotFoundException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- } else if (!dep.getSpecification().getName().equals(type)) {
- throw new ConfigurationException("A required service is not correct : the field type [" + type + "] and the needed service interface [" + dep.getSpecification().getName()
- + "] are not the same");
+ if (dep.isAggregate()) {
+ throw new ConfigurationException("A required service is not correct : the field "
+ + meta.getFieldName()
+ + " must be an array to support aggregate injections");
+ }
}
+ setSpecification(dep, type, true); // Throw an exception if the filed type mismatch.
}
// Check that all required info are set
@@ -239,21 +216,58 @@
}
/**
+ * Check if we have to set the dependency specification with the given class name.
+ * @param dep : dependency to check
+ * @param className : class name
+ * @param error : set to true to throw an error if the set dependency specification and the given specification are different.
+ * @throws ConfigurationException : the specification class cannot be loaded correctly
+ */
+ private void setSpecification(Dependency dep, String className, boolean error) throws ConfigurationException {
+ // We have to set the dependency in two cases : either the dependency as no specification, or the specification is different from the given
+ // one
+ if (dep.getSpecification() == null || !dep.getSpecification().getName().equals(className)) {
+ if (dep.getSpecification() != null) {
+ if (error) {
+ throw new ConfigurationException("A required service is not correct : the discoevered type ["
+ + className
+ + "] and the specified (or already discovered) service interface ["
+ + dep.getSpecification().getName()
+ + "] are not the same");
+ } else {
+ // If the specification is different, warn that we will overide it.
+ warn("[DependencyHandler on "
+ + getInstanceManager().getInstanceName()
+ + "] The field type ["
+ + className
+ + "] and the needed service interface ["
+ + dep.getSpecification()
+ + "] are not the same");
+ }
+ }
+ try {
+ dep.setSpecification(getInstanceManager().getContext().getBundle().loadClass(className));
+ } catch (ClassNotFoundException e) {
+ throw new ConfigurationException("The required service interface cannot be loaded : " + e.getMessage());
+ }
+ }
+ }
+
+ /**
* Configure the handler.
* @param componentMetadata : the component type metadata
* @param configuration : the instance configuration
* @throws ConfigurationException : one dependency metadata is not correct.
- * @see org.apache.felix.ipojo.Handler#configure(org.apache.felix.ipojo.InstanceManager, org.apache.felix.ipojo.metadata.Element, java.util.Dictionary)
+ * @see org.apache.felix.ipojo.Handler#configure(org.apache.felix.ipojo.InstanceManager, org.apache.felix.ipojo.metadata.Element,
+ * java.util.Dictionary)
*/
public void configure(Element componentMetadata, Dictionary configuration) throws ConfigurationException {
// getPojoMetadata();
PojoMetadata manipulation = getFactory().getPojoMetadata();
- List fl = new ArrayList();
+ List fields = new ArrayList();
// Create the dependency according to the component metadata
Element[] deps = componentMetadata.getElements("Requires");
- m_dependencies = new Dependency[0]; // TODO avoid using non optimized array (add directly inside the loop)
-
+
// Get instance filters.
Dictionary filtersConfiguration = (Dictionary) configuration.get("requires.filters");
@@ -264,28 +278,34 @@
String filter = deps[i].getAttribute("filter");
String opt = deps[i].getAttribute("optional");
boolean optional = opt != null && opt.equalsIgnoreCase("true");
- String di = deps[i].getAttribute("default-implementation");
+ String defaultImplem = deps[i].getAttribute("default-implementation");
String agg = deps[i].getAttribute("aggregate");
boolean aggregate = agg != null && agg.equalsIgnoreCase("true");
- String id = deps[i].getAttribute("id");
+ String identitity = deps[i].getAttribute("id");
String scope = deps[i].getAttribute("scope");
- BundleContext bc = getInstanceManager().getContext(); // Get the default bundle context.
+ BundleContext context = getInstanceManager().getContext(); // Get the default bundle context.
if (scope != null) {
// If we are not in a composite, the policy is set to global.
if (scope.equalsIgnoreCase("global") || ((((IPojoContext) getInstanceManager().getContext()).getServiceContext()) == null)) {
- bc = new PolicyServiceContext(getInstanceManager().getGlobalContext(), getInstanceManager().getLocalServiceContext(), PolicyServiceContext.GLOBAL);
+ context =
+ new PolicyServiceContext(getInstanceManager().getGlobalContext(), getInstanceManager().getLocalServiceContext(),
+ PolicyServiceContext.GLOBAL);
} else if (scope.equalsIgnoreCase("composite")) {
- bc = new PolicyServiceContext(getInstanceManager().getGlobalContext(), getInstanceManager().getLocalServiceContext(), PolicyServiceContext.LOCAL);
+ context =
+ new PolicyServiceContext(getInstanceManager().getGlobalContext(), getInstanceManager().getLocalServiceContext(),
+ PolicyServiceContext.LOCAL);
} else if (scope.equalsIgnoreCase("composite+global")) {
- bc = new PolicyServiceContext(getInstanceManager().getGlobalContext(), getInstanceManager().getLocalServiceContext(), PolicyServiceContext.LOCAL_AND_GLOBAL);
+ context =
+ new PolicyServiceContext(getInstanceManager().getGlobalContext(), getInstanceManager().getLocalServiceContext(),
+ PolicyServiceContext.LOCAL_AND_GLOBAL);
}
}
// Get instance filter if available
- if (filtersConfiguration != null && id != null && filtersConfiguration.get(id) != null) {
- filter = (String) filtersConfiguration.get(id);
+ if (filtersConfiguration != null && identitity != null && filtersConfiguration.get(identitity) != null) {
+ filter = (String) filtersConfiguration.get(identitity);
}
Filter fil = null;
@@ -299,17 +319,19 @@
Class spec = null;
if (serviceSpecification != null) {
- spec = AbstractServiceDependency.loadSpecification(serviceSpecification, getInstanceManager().getContext());
+ spec = DependencyModel.loadSpecification(serviceSpecification, getInstanceManager().getContext());
}
- int policy = AbstractServiceDependency.getPolicy(deps[i]);
- Comparator cmp = AbstractServiceDependency.getComparator(deps[i], getInstanceManager().getGlobalContext());
- Dependency dep = new Dependency(this, field, spec, fil, optional, aggregate, id, bc, policy, cmp, di);
+ int policy = DependencyModel.getPolicy(deps[i]);
+ Comparator cmp = DependencyModel.getComparator(deps[i], getInstanceManager().getGlobalContext());
+ Dependency dep = new Dependency(this, field, spec, fil, optional, aggregate, identitity, context, policy, cmp, defaultImplem);
// Look for dependency callback :
Element[] cbs = deps[i].getElements("Callback");
for (int j = 0; cbs != null && j < cbs.length; j++) {
- if (!cbs[j].containsAttribute("method") && cbs[j].containsAttribute("type")) { throw new ConfigurationException("Requirement Callback : a dependency callback must contain a method and a type attribute"); }
+ if (!cbs[j].containsAttribute("method") && cbs[j].containsAttribute("type")) {
+ throw new ConfigurationException("Requirement Callback : a dependency callback must contain a method and a type attribute");
+ }
String method = cbs[j].getAttribute("method");
String type = cbs[j].getAttribute("type");
int methodType = 0;
@@ -319,21 +341,21 @@
methodType = DependencyCallback.UNBIND;
}
- DependencyCallback dc = new DependencyCallback(dep, method, methodType);
- dep.addDependencyCallback(dc);
+ DependencyCallback callback = new DependencyCallback(dep, method, methodType);
+ dep.addDependencyCallback(callback);
}
// Check the dependency :
if (checkDependency(dep, manipulation)) {
addDependency(dep);
if (dep.getField() != null) {
- fl.add(manipulation.getField(dep.getField()));
+ fields.add(manipulation.getField(dep.getField()));
}
}
}
if (deps.length > 0) {
- getInstanceManager().register(this, (FieldMetadata[]) fl.toArray(new FieldMetadata[0]), manipulation.getMethods());
+ getInstanceManager().register(this, (FieldMetadata[]) fields.toArray(new FieldMetadata[fields.size()]), manipulation.getMethods());
} else {
throw new ConfigurationException("No dependencies found in " + getInstanceManager().getInstanceName());
}
@@ -450,10 +472,11 @@
for (int j = 0; j < getDependencies().length; j++) {
Dependency dep = getDependencies()[j];
// Create & add the dependency description
- DependencyDescription dd = new DependencyDescription(dep.getSpecification().getName(), dep.isAggregate(), dep.isOptional(), dep.getFilter(), dep.getState());
- dd.setServiceReferences(dep.getServiceReferencesAsList());
- dd.setUsedServices(dep.getUsedServiceReferences());
- dhd.addDependency(dd);
+ DependencyDescription desc =
+ new DependencyDescription(dep.getSpecification().getName(), dep.isAggregate(), dep.isOptional(), dep.getFilter(), dep.getState());
+ desc.setServiceReferences(dep.getServiceReferencesAsList());
+ desc.setUsedServices(dep.getUsedServiceReferences());
+ dhd.addDependency(desc);
}
return dhd;
}
Modified: felix/sandbox/clement/ipojo/core/src/main/java/org/apache/felix/ipojo/handlers/dependency/DependencyHandlerDescription.java
URL: http://svn.apache.org/viewvc/felix/sandbox/clement/ipojo/core/src/main/java/org/apache/felix/ipojo/handlers/dependency/DependencyHandlerDescription.java?rev=633138&r1=633137&r2=633138&view=diff
==============================================================================
--- felix/sandbox/clement/ipojo/core/src/main/java/org/apache/felix/ipojo/handlers/dependency/DependencyHandlerDescription.java (original)
+++ felix/sandbox/clement/ipojo/core/src/main/java/org/apache/felix/ipojo/handlers/dependency/DependencyHandlerDescription.java Mon Mar 3 07:46:27 2008
@@ -42,10 +42,10 @@
/**
* Constructor.
- * @param h : Handler.
+ * @param handler : Handler.
*/
- public DependencyHandlerDescription(Handler h) {
- super(h);
+ public DependencyHandlerDescription(Handler handler) {
+ super(handler);
}
/**
@@ -113,14 +113,14 @@
dep.addAttribute(new Attribute("State", state));
List set = m_dependencies[i].getUsedServices();
if (set != null) {
- Iterator it = set.iterator();
- while (it.hasNext()) {
+ Iterator iterator = set.iterator();
+ while (iterator.hasNext()) {
Element use = new Element("Uses", "");
- ServiceReference ref = (ServiceReference) it.next();
+ ServiceReference ref = (ServiceReference) iterator.next();
use.addAttribute(new Attribute("service.id", ref.getProperty(Constants.SERVICE_ID).toString()));
- String in = (String) ref.getProperty("instance.name");
- if (in != null) {
- use.addAttribute(new Attribute("instance.name", in));
+ String instance = (String) ref.getProperty("instance.name");
+ if (instance != null) {
+ use.addAttribute(new Attribute("instance.name", instance));
}
dep.addElement(use);
}
Modified: felix/sandbox/clement/ipojo/core/src/main/java/org/apache/felix/ipojo/handlers/dependency/ServiceUsage.java
URL: http://svn.apache.org/viewvc/felix/sandbox/clement/ipojo/core/src/main/java/org/apache/felix/ipojo/handlers/dependency/ServiceUsage.java?rev=633138&r1=633137&r2=633138&view=diff
==============================================================================
--- felix/sandbox/clement/ipojo/core/src/main/java/org/apache/felix/ipojo/handlers/dependency/ServiceUsage.java (original)
+++ felix/sandbox/clement/ipojo/core/src/main/java/org/apache/felix/ipojo/handlers/dependency/ServiceUsage.java Mon Mar 3 07:46:27 2008
@@ -34,6 +34,7 @@
* Structure contained in the Thread Local.
*/
private class Usage {
+
/**
* Stack Size.
*/
@@ -46,6 +47,7 @@
* List of used objects.
*/
List m_objects = new ArrayList();
+
}
/**
@@ -62,8 +64,7 @@
* @return the list of stored references.
*/
public List getReferences() {
- Usage use = (Usage) super.get();
- return use.m_refs;
+ return ((Usage) super.get()).m_refs;
}
/**
@@ -71,18 +72,17 @@
* @return the list of stored service objects.
*/
public List getObjects() {
- Usage use = (Usage) get();
- return use.m_objects;
+ return ((Usage) super.get()).m_objects;
}
/**
* Add a service usage.
- * @param o : object used
+ * @param object : object used
* @param ref : service reference
*/
- public void addUsage(Object o, ServiceReference ref) {
+ public void addUsage(Object object, ServiceReference ref) {
Usage use = (Usage) get();
- use.m_objects.add(o);
+ use.m_objects.add(object);
use.m_refs.add(ref);
set(use);
}
Modified: felix/sandbox/clement/ipojo/core/src/main/java/org/apache/felix/ipojo/handlers/lifecycle/callback/LifecycleCallback.java
URL: http://svn.apache.org/viewvc/felix/sandbox/clement/ipojo/core/src/main/java/org/apache/felix/ipojo/handlers/lifecycle/callback/LifecycleCallback.java?rev=633138&r1=633137&r2=633138&view=diff
==============================================================================
--- felix/sandbox/clement/ipojo/core/src/main/java/org/apache/felix/ipojo/handlers/lifecycle/callback/LifecycleCallback.java (original)
+++ felix/sandbox/clement/ipojo/core/src/main/java/org/apache/felix/ipojo/handlers/lifecycle/callback/LifecycleCallback.java Mon Mar 3 07:46:27 2008
@@ -53,29 +53,29 @@
/**
* LifecycleCallback constructor.
*
- * @param hh : the callback handler calling the callback
+ * @param handler : the callback handler calling the callback
* @param transition : transition on which calling the callback
- * @param mm : method metadata to invoke
+ * @param method : method metadata to invoke
*/
- public LifecycleCallback(LifecycleCallbackHandler hh, int transition, MethodMetadata mm) {
+ public LifecycleCallback(LifecycleCallbackHandler handler, int transition, MethodMetadata method) {
m_transition = transition;
- m_callback = new Callback(mm, hh.getInstanceManager());
+ m_callback = new Callback(method, handler.getInstanceManager());
}
/**
* LifecycleCallback constructor.
*
- * @param hh : the callback handler calling the callback
+ * @param handler : the callback handler calling the callback
* @param transition : transition on which calling the callback
- * @param mm : method name to invoke
+ * @param method : method name to invoke
*/
- public LifecycleCallback(LifecycleCallbackHandler hh, int transition, String mm) {
+ public LifecycleCallback(LifecycleCallbackHandler handler, int transition, String method) {
m_transition = transition;
- m_callback = new Callback(mm, new String[0], false, hh.getInstanceManager());
+ m_callback = new Callback(method, new String[0], false, handler.getInstanceManager());
}
/**
- * Call the callback method when the transition from inital to final state is
+ * Call the callback method when the transition from inital tostate is
* detected.
*
* @throws NoSuchMethodException : Method is not found in the class
Modified: felix/sandbox/clement/ipojo/core/src/main/java/org/apache/felix/ipojo/handlers/lifecycle/callback/LifecycleCallbackHandler.java
URL: http://svn.apache.org/viewvc/felix/sandbox/clement/ipojo/core/src/main/java/org/apache/felix/ipojo/handlers/lifecycle/callback/LifecycleCallbackHandler.java?rev=633138&r1=633137&r2=633138&view=diff
==============================================================================
--- felix/sandbox/clement/ipojo/core/src/main/java/org/apache/felix/ipojo/handlers/lifecycle/callback/LifecycleCallbackHandler.java (original)
+++ felix/sandbox/clement/ipojo/core/src/main/java/org/apache/felix/ipojo/handlers/lifecycle/callback/LifecycleCallbackHandler.java Mon Mar 3 07:46:27 2008
@@ -53,11 +53,11 @@
/**
* Add the given callback to the callback list.
*
- * @param hk : the element to add
+ * @param callback : the element to add
*/
- private void addCallback(LifecycleCallback hk) {
+ private void addCallback(LifecycleCallback callback) {
for (int i = 0; (m_callbacks != null) && (i < m_callbacks.length); i++) {
- if (m_callbacks[i] == hk) {
+ if (m_callbacks[i] == callback) {
return;
}
}
@@ -65,10 +65,10 @@
if (m_callbacks.length > 0) {
LifecycleCallback[] newHk = new LifecycleCallback[m_callbacks.length + 1];
System.arraycopy(m_callbacks, 0, newHk, 0, m_callbacks.length);
- newHk[m_callbacks.length] = hk;
+ newHk[m_callbacks.length] = callback;
m_callbacks = newHk;
} else {
- m_callbacks = new LifecycleCallback[] { hk };
+ m_callbacks = new LifecycleCallback[] { callback };
}
}
@@ -86,7 +86,7 @@
String imm = metadata.getAttribute("immediate");
m_immediate = imm != null && imm.equalsIgnoreCase("true");
- PojoMetadata mm = getFactory().getPojoMetadata();
+ PojoMetadata meta = getFactory().getPojoMetadata();
Element[] hooksMetadata = metadata.getElements("callback");
for (int i = 0; hooksMetadata != null && i < hooksMetadata.length; i++) {
@@ -95,11 +95,13 @@
throw new ConfigurationException("Lifecycle callback : A callback needs to contains a method attribute");
}
- MethodMetadata met = mm.getMethod(method, new String[0]);
+ MethodMetadata met = meta.getMethod(method, new String[0]);
int transition = -1;
String trans = hooksMetadata[i].getAttribute("transition");
- if (trans != null) {
+ if (trans == null) {
+ throw new ConfigurationException("Lifecycle callback : the transition attribute is missing");
+ } else {
if (trans.equalsIgnoreCase("validate")) {
transition = LifecycleCallback.VALIDATE;
} else if (trans.equalsIgnoreCase("invalidate")) {
@@ -107,17 +109,15 @@
} else {
throw new ConfigurationException("Lifecycle callback : Unknown or malformed transition : " + trans);
}
- } else {
- throw new ConfigurationException("Lifecycle callback : the transition attribute is missing");
}
- LifecycleCallback hk = null;
- if (met != null) {
- hk = new LifecycleCallback(this, transition, met);
+ LifecycleCallback callback = null;
+ if (met == null) {
+ callback = new LifecycleCallback(this, transition, method);
} else {
- hk = new LifecycleCallback(this, transition, method);
+ callback = new LifecycleCallback(this, transition, met);
}
- addCallback(hk);
+ addCallback(callback);
}
}
@@ -126,7 +126,8 @@
* @see org.apache.felix.ipojo.Handler#start()
*/
public void start() {
- } // Do nothing during the start
+ // Do nothing during the start
+ }
/**
* Stop the handler.
@@ -161,10 +162,10 @@
try {
m_callbacks[i].call();
} catch (NoSuchMethodException e) {
- error("[" + getInstanceManager().getInstanceName() + "] The callback method " + m_callbacks[i].getMethod() + " is not found", e);
+ error("[" + getInstanceManager().getInstanceName() + "] The callback method " + m_callbacks[i].getMethod() + " is not found");
throw new IllegalStateException(e.getMessage());
} catch (IllegalAccessException e) {
- error("[" + getInstanceManager().getInstanceName() + "] The callback method " + m_callbacks[i].getMethod() + " is not accessible", e);
+ error("[" + getInstanceManager().getInstanceName() + "] The callback method " + m_callbacks[i].getMethod() + " is not accessible");
throw new IllegalStateException(e.getMessage());
} catch (InvocationTargetException e) {
error("[" + getInstanceManager().getInstanceName() + "] The callback method " + m_callbacks[i].getMethod() + " has throws an exception : " + e.getTargetException().getMessage(), e.getTargetException());
Modified: felix/sandbox/clement/ipojo/core/src/main/java/org/apache/felix/ipojo/handlers/lifecycle/controller/ControllerHandler.java
URL: http://svn.apache.org/viewvc/felix/sandbox/clement/ipojo/core/src/main/java/org/apache/felix/ipojo/handlers/lifecycle/controller/ControllerHandler.java?rev=633138&r1=633137&r2=633138&view=diff
==============================================================================
--- felix/sandbox/clement/ipojo/core/src/main/java/org/apache/felix/ipojo/handlers/lifecycle/controller/ControllerHandler.java (original)
+++ felix/sandbox/clement/ipojo/core/src/main/java/org/apache/felix/ipojo/handlers/lifecycle/controller/ControllerHandler.java Mon Mar 3 07:46:27 2008
@@ -50,8 +50,8 @@
* @see org.apache.felix.ipojo.Handler#configure(org.apache.felix.ipojo.InstanceManager, org.apache.felix.ipojo.metadata.Element, java.util.Dictionary)
*/
public void configure(Element metadata, Dictionary configuration) throws ConfigurationException {
- Element[] lc = metadata.getElements("controller");
- String field = lc[0].getAttribute("field");
+ Element[] controller = metadata.getElements("controller");
+ String field = controller[0].getAttribute("field");
getInstanceManager().register(this, new FieldMetadata[] {new FieldMetadata(field, "boolean")}, null);
}
@@ -69,17 +69,19 @@
* Nothing to do.
* @see org.apache.felix.ipojo.Handler#stop()
*/
- public void stop() { }
+ public void stop() {
+ // Nothing to do.
+ }
/**
* GetterCallback.
* @param pojo : the pojo object on which the field is accessed
* Return the stored value.
* @param field : field name.
- * @param o : value given by the previous handler.
+ * @param value : value given by the previous handler.
* @return : the handler state.
*/
- public Object onGet(Object pojo, String field, Object o) {
+ public Object onGet(Object pojo, String field, Object value) {
return new Boolean(m_state);
}
@@ -88,13 +90,13 @@
* @param pojo : the pojo object on which the field is accessed
* Store the new field value & invalidate / validate the handler is required.
* @param field : field name.
- * @param o : new value.
+ * @param value : new value.
*/
- public void onSet(Object pojo, String field, Object o) {
- if (o instanceof Boolean) {
- boolean nv = ((Boolean) o).booleanValue();
- if (nv != m_state) {
- m_state = nv;
+ public void onSet(Object pojo, String field, Object value) {
+ if (value instanceof Boolean) {
+ boolean newValue = ((Boolean) value).booleanValue();
+ if (newValue != m_state) {
+ m_state = newValue;
if (m_state) {
((InstanceManager) getHandlerManager()).setState(ComponentInstance.VALID);
} else {
@@ -110,28 +112,28 @@
/**
* Initialize the component factory.
* The controller field is checked to avoid configure check.
- * @param cd : component description
+ * @param desc : component description
* @param metadata : component type metadata
* @throws ConfigurationException : occurs if the controller field is not in the POJO class or is not a boolean.
* @see org.apache.felix.ipojo.Handler#initializeComponentFactory(org.apache.felix.ipojo.architecture.ComponentTypeDescription, org.apache.felix.ipojo.metadata.Element)
*/
- public void initializeComponentFactory(ComponentTypeDescription cd, Element metadata) throws ConfigurationException {
+ public void initializeComponentFactory(ComponentTypeDescription desc, Element metadata) throws ConfigurationException {
String field = null;
- Element[] lc = metadata.getElements("controller");
+ Element[] controller = metadata.getElements("controller");
// Use only the first controller
- field = lc[0].getAttribute("field");
+ field = controller[0].getAttribute("field");
if (field == null) {
throw new ConfigurationException("Lifecycle controller : the controller element needs to have a field attribute");
}
- PojoMetadata mm = getFactory().getPojoMetadata();
- FieldMetadata fm = mm.getField(field);
- if (fm == null) {
+ PojoMetadata method = getFactory().getPojoMetadata();
+ FieldMetadata fieldMetadata = method.getField(field);
+ if (fieldMetadata == null) {
throw new ConfigurationException("Lifecycle controller : The field " + field + " does not exist in the class");
}
- if (!fm.getFieldType().equalsIgnoreCase("boolean")) {
- throw new ConfigurationException("Lifecycle controller : The field " + field + " must be a boolean (" + fm.getFieldType() + " found)");
+ if (!fieldMetadata.getFieldType().equalsIgnoreCase("boolean")) {
+ throw new ConfigurationException("Lifecycle controller : The field " + field + " must be a boolean (" + fieldMetadata.getFieldType() + " found)");
}
}
Modified: felix/sandbox/clement/ipojo/core/src/main/java/org/apache/felix/ipojo/handlers/providedservice/ProvidedService.java
URL: http://svn.apache.org/viewvc/felix/sandbox/clement/ipojo/core/src/main/java/org/apache/felix/ipojo/handlers/providedservice/ProvidedService.java?rev=633138&r1=633137&r2=633138&view=diff
==============================================================================
--- felix/sandbox/clement/ipojo/core/src/main/java/org/apache/felix/ipojo/handlers/providedservice/ProvidedService.java (original)
+++ felix/sandbox/clement/ipojo/core/src/main/java/org/apache/felix/ipojo/handlers/providedservice/ProvidedService.java Mon Mar 3 07:46:27 2008
@@ -22,7 +22,9 @@
import java.util.Enumeration;
import java.util.Properties;
+import org.apache.felix.ipojo.ConfigurationException;
import org.apache.felix.ipojo.InstanceManager;
+import org.apache.felix.ipojo.util.Property;
import org.osgi.framework.Bundle;
import org.osgi.framework.ServiceFactory;
import org.osgi.framework.ServiceReference;
@@ -84,7 +86,7 @@
/**
* Properties Array.
*/
- private Property[] m_properties = new Property[0];
+ private Property[] m_properties;
/**
* Construct a provided service object.
@@ -100,8 +102,12 @@
m_factoryPolicy = factoryPolicy;
// Add instance name & factory name
- addProperty(new Property(this, "instance.name", handler.getInstanceManager().getInstanceName()));
- addProperty(new Property(this, "factory.name", handler.getInstanceManager().getFactory().getName()));
+ try {
+ addProperty(new Property("instance.name", null, null, handler.getInstanceManager().getInstanceName(), String.class.getName(), handler.getInstanceManager(), handler));
+ addProperty(new Property("factory.name", null, null, handler.getInstanceManager().getFactory().getFactoryName(), String.class.getName(), handler.getInstanceManager(), handler));
+ } catch (ConfigurationException e) {
+ m_handler.error("An exception occurs when adding instance.name and factory.name property : " + e.getMessage());
+ }
}
/**
@@ -117,22 +123,22 @@
/**
* Add the given property to the property list.
*
- * @param p : the element to add
+ * @param prop : the element to add
*/
- private synchronized void addProperty(Property p) {
+ private synchronized void addProperty(Property prop) {
for (int i = 0; (m_properties != null) && (i < m_properties.length); i++) {
- if (m_properties[i] == p) {
+ if (m_properties[i] == prop) {
return;
}
}
- if (m_properties.length > 0) {
+ if (m_properties == null) {
+ m_properties = new Property[] { prop };
+ } else {
Property[] newProp = new Property[m_properties.length + 1];
System.arraycopy(m_properties, 0, newProp, 0, m_properties.length);
- newProp[m_properties.length] = p;
+ newProp[m_properties.length] = prop;
m_properties = newProp;
- } else {
- m_properties = new Property[] { p };
}
}
@@ -152,7 +158,7 @@
if (idx >= 0) {
if ((m_properties.length - 1) == 0) {
- m_properties = new Property[0];
+ m_properties = null;
} else {
Property[] newPropertiesList = new Property[m_properties.length - 1];
System.arraycopy(m_properties, 0, newPropertiesList, 0, idx);
@@ -170,10 +176,10 @@
* service is not published).
*/
public ServiceReference getServiceReference() {
- if (m_serviceRegistration != null) {
- return m_serviceRegistration.getReference();
- } else {
+ if (m_serviceRegistration == null) {
return null;
+ } else {
+ return m_serviceRegistration.getReference();
}
}
@@ -267,8 +273,8 @@
// Contruct the service properties list
Properties serviceProperties = new Properties();
for (int i = 0; i < m_properties.length; i++) {
- if (m_properties[i].get() != null) {
- serviceProperties.put(m_properties[i].getName(), m_properties[i].get());
+ if (m_properties[i].getValue() != null) {
+ serviceProperties.put(m_properties[i].getName(), m_properties[i].getValue());
}
}
return serviceProperties;
@@ -302,8 +308,13 @@
while (keys.hasMoreElements()) {
String key = (String) keys.nextElement();
Object value = props.get(key);
- Property prop = new Property(this, key, value);
- addProperty(prop);
+ Property prop;
+ try {
+ prop = new Property(key, null, null, value.toString(), value.getClass().getName(), getInstanceManager(), m_handler);
+ addProperty(prop);
+ } catch (ConfigurationException e) {
+ m_handler.error("The propagated property " + key + " cannot be pcreated correctly : " + e.getMessage());
+ }
}
}
Modified: felix/sandbox/clement/ipojo/core/src/main/java/org/apache/felix/ipojo/handlers/providedservice/ProvidedServiceDescription.java
URL: http://svn.apache.org/viewvc/felix/sandbox/clement/ipojo/core/src/main/java/org/apache/felix/ipojo/handlers/providedservice/ProvidedServiceDescription.java?rev=633138&r1=633137&r2=633138&view=diff
==============================================================================
--- felix/sandbox/clement/ipojo/core/src/main/java/org/apache/felix/ipojo/handlers/providedservice/ProvidedServiceDescription.java (original)
+++ felix/sandbox/clement/ipojo/core/src/main/java/org/apache/felix/ipojo/handlers/providedservice/ProvidedServiceDescription.java Mon Mar 3 07:46:27 2008
@@ -69,13 +69,13 @@
*
* @param serviceSpecification : the provided contract
* @param state : state (UNREGITRED | REGISTRED)
- * @param sr : Service Registration (to obtain the reference), or null if
+ * @param ref : Service Registration (to obtain the reference), or null if
* state is UNREGISTRED
*/
- public ProvidedServiceDescription(String[] serviceSpecification, int state, ServiceReference sr) {
+ public ProvidedServiceDescription(String[] serviceSpecification, int state, ServiceReference ref) {
m_serviceSpecification = serviceSpecification;
m_state = state;
- m_serviceReference = sr;
+ m_serviceReference = ref;
// m_parent = parent;
}