You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@felix.apache.org by ri...@apache.org on 2007/04/17 16:31:47 UTC
svn commit: r529623 [7/9] - in /incubator/felix/trunk: ./ ipojo.arch/
ipojo.arch/src/main/java/org/apache/felix/ipojo/arch/ ipojo.metadata/
ipojo.metadata/src/main/java/org/apache/felix/ipojo/metadata/ ipojo.plugin/
ipojo.plugin/src/main/java/org/apach...
Modified: incubator/felix/trunk/ipojo/src/main/java/org/apache/felix/ipojo/handlers/dependency/nullable/NullableObjectWriter.java
URL: http://svn.apache.org/viewvc/incubator/felix/trunk/ipojo/src/main/java/org/apache/felix/ipojo/handlers/dependency/nullable/NullableObjectWriter.java?view=diff&rev=529623&r1=529622&r2=529623
==============================================================================
--- incubator/felix/trunk/ipojo/src/main/java/org/apache/felix/ipojo/handlers/dependency/nullable/NullableObjectWriter.java (original)
+++ incubator/felix/trunk/ipojo/src/main/java/org/apache/felix/ipojo/handlers/dependency/nullable/NullableObjectWriter.java Tue Apr 17 07:31:35 2007
@@ -18,7 +18,6 @@
*/
package org.apache.felix.ipojo.handlers.dependency.nullable;
-
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
@@ -29,19 +28,22 @@
import org.objectweb.asm.Opcodes;
import org.objectweb.asm.Type;
-/** Create the proxy class.
+/**
+ * Create the proxy class.
+ *
* @author <a href="mailto:felix-dev@incubator.apache.org">Felix Project Team</a>
*/
public class NullableObjectWriter implements Opcodes {
- /** Return the proxy classname for the contract contractname
- * on the service object soc.
+ /**
+ * Return the proxy classname for the contract contractname on the service
+ * object soc.
+ *
* @param url URL of the needed contract
* @param contractName String
* @return byte[]
*/
- public static byte[] dump(URL url,
- String contractName) {
+ public static byte[] dump(URL url, String contractName) {
ClassReader cr = null;
InputStream is = null;
@@ -55,14 +57,14 @@
ClassWriter cw = new ClassWriter(true);
- //String[] segment = contractName.split("[.]");
- //String className = "org/apache/felix/ipojo/" + segment[segment.length - 1] + "Nullable";
+ // String[] segment = contractName.split("[.]");
+ // String className = "org/apache/felix/ipojo/" +
+ // segment[segment.length - 1] + "Nullable";
String className = contractName.replace('.', '/') + "Nullable";
-
// Create the class
- cw.visit(V1_2, ACC_PUBLIC + ACC_SUPER, className, null,
- "java/lang/Object", new String[]{contractName.replace('.', '/'), "org/apache/felix/ipojo/Nullable"});
+ cw.visit(V1_2, ACC_PUBLIC + ACC_SUPER, className, null, "java/lang/Object", new String[] { contractName.replace('.', '/'),
+ "org/apache/felix/ipojo/Nullable" });
// Inject a constructor <INIT>()V
MethodVisitor cst = cw.visitMethod(ACC_PUBLIC, "<init>", "()V", null, null);
@@ -85,38 +87,43 @@
MethodVisitor mv = cw.visitMethod(ACC_PUBLIC, name, desc, sign, exc);
Type returnType = Type.getReturnType(desc);
- // TODO : manage the other type primitive for Nullable
- // Primitive type :
+ // Primitive type :
switch (returnType.getSort()) {
case Type.BOOLEAN:
case Type.INT:
case Type.BYTE:
+ case Type.CHAR:
case Type.SHORT:
// Integer or Boolean : return 0 ( false)
mv.visitInsn(ICONST_0);
mv.visitInsn(IRETURN);
break;
case Type.LONG:
- mv.visitInsn(LCONST_0);
- mv.visitInsn(LRETURN);
- break;
+ mv.visitInsn(LCONST_0);
+ mv.visitInsn(LRETURN);
+ break;
case Type.DOUBLE:
// Double : return 0.0
mv.visitInsn(DCONST_0);
mv.visitInsn(DRETURN);
break;
- case Type.ARRAY :
- case Type.OBJECT :
+ case Type.FLOAT:
+ // Double : return 0.0
+ mv.visitInsn(FCONST_0);
+ mv.visitInsn(FRETURN);
+ break;
+ case Type.ARRAY:
+ case Type.OBJECT:
// Return always null for array and object
mv.visitInsn(ACONST_NULL);
mv.visitInsn(ARETURN);
break;
- case Type.VOID :
+ case Type.VOID:
mv.visitInsn(RETURN);
break;
- default :
+ default:
System.err.println("Type not yet managed : " + returnType);
- break;
+ break;
}
mv.visitMaxs(0, 0);
mv.visitEnd();
@@ -124,7 +131,7 @@
// End process
cw.visitEnd();
- b = cw.toByteArray();
+ b = cw.toByteArray();
} catch (IOException e) {
e.printStackTrace();
Modified: incubator/felix/trunk/ipojo/src/main/java/org/apache/felix/ipojo/handlers/lifecycle/callback/LifecycleCallback.java
URL: http://svn.apache.org/viewvc/incubator/felix/trunk/ipojo/src/main/java/org/apache/felix/ipojo/handlers/lifecycle/callback/LifecycleCallback.java?view=diff&rev=529623&r1=529622&r2=529623
==============================================================================
--- incubator/felix/trunk/ipojo/src/main/java/org/apache/felix/ipojo/handlers/lifecycle/callback/LifecycleCallback.java (original)
+++ incubator/felix/trunk/ipojo/src/main/java/org/apache/felix/ipojo/handlers/lifecycle/callback/LifecycleCallback.java Tue Apr 17 07:31:35 2007
@@ -25,11 +25,12 @@
/**
* This class is the implementation of callback on lifecycle transition.
+ *
* @author <a href="mailto:felix-dev@incubator.apache.org">Felix Project Team</a>
*/
public class LifecycleCallback {
-
- /**
+
+ /**
* Initial state of the transition.
*/
private int m_initialState;
@@ -43,7 +44,7 @@
* Callback object.
*/
private Callback m_callback;
-
+
/**
* Method called by the callback.
*/
@@ -51,6 +52,7 @@
/**
* LifecycleCallback constructor.
+ *
* @param hh : the callback handler calling the callback
* @param initialState : initial state of the callback
* @param finalState : finali state of the callback
@@ -58,17 +60,27 @@
* @param isStatic : is the method static ?
*/
public LifecycleCallback(LifecycleCallbackHandler hh, String initialState, String finalState, String method, boolean isStatic) {
- if (initialState.equals("VALID")) { m_initialState = InstanceManager.VALID; }
- if (initialState.equals("INVALID")) { m_initialState = InstanceManager.INVALID; }
- if (finalState.equals("VALID")) { m_finalState = InstanceManager.VALID; }
- if (finalState.equals("INVALID")) { m_finalState = InstanceManager.INVALID; }
-
+ if (initialState.equals("VALID")) {
+ m_initialState = InstanceManager.VALID;
+ }
+ if (initialState.equals("INVALID")) {
+ m_initialState = InstanceManager.INVALID;
+ }
+ if (finalState.equals("VALID")) {
+ m_finalState = InstanceManager.VALID;
+ }
+ if (finalState.equals("INVALID")) {
+ m_finalState = InstanceManager.INVALID;
+ }
+
m_method = method;
m_callback = new Callback(method, isStatic, hh.getInstanceManager());
}
/**
- * Call the hook method when the transition from inital to final state is detected.
+ * Call the hook method when the transition from inital to final state is
+ * detected.
+ *
* @throws NoSuchMethodException : Method is not found in the class
* @throws InvocationTargetException : The method is not static
* @throws IllegalAccessException : The method can not be invoked
@@ -76,24 +88,17 @@
protected void call() throws NoSuchMethodException, IllegalAccessException, InvocationTargetException {
m_callback.call();
}
-
- /**
- * @return Returns the m_finalState.
- */
+
public int getFinalState() {
return m_finalState;
}
- /**
- * @return Returns the m_initialState.
- */
public int getInitialState() {
return m_initialState;
}
-
- /**
- * @return the method called by this callback.
- */
- public String getMethod() { return m_method; }
+
+ public String getMethod() {
+ return m_method;
+ }
}
Modified: incubator/felix/trunk/ipojo/src/main/java/org/apache/felix/ipojo/handlers/lifecycle/callback/LifecycleCallbackHandler.java
URL: http://svn.apache.org/viewvc/incubator/felix/trunk/ipojo/src/main/java/org/apache/felix/ipojo/handlers/lifecycle/callback/LifecycleCallbackHandler.java?view=diff&rev=529623&r1=529622&r2=529623
==============================================================================
--- incubator/felix/trunk/ipojo/src/main/java/org/apache/felix/ipojo/handlers/lifecycle/callback/LifecycleCallbackHandler.java (original)
+++ incubator/felix/trunk/ipojo/src/main/java/org/apache/felix/ipojo/handlers/lifecycle/callback/LifecycleCallbackHandler.java Tue Apr 17 07:31:35 2007
@@ -29,6 +29,7 @@
/**
* Lifecycle callback handler.
+ *
* @author <a href="mailto:felix-dev@incubator.apache.org">Felix Project Team</a>
*/
public class LifecycleCallbackHandler extends Handler {
@@ -48,18 +49,21 @@
*/
private InstanceManager m_manager;
- /**
- * Does a POJO object be created at starting.
- */
- private boolean m_immediate = false;
+ /**
+ * Does a POJO object be created at starting.
+ */
+ private boolean m_immediate = false;
/**
* Add the given callback to the callback list.
+ *
* @param hk : the element to add
*/
private void addCallback(LifecycleCallback hk) {
for (int i = 0; (m_callbacks != null) && (i < m_callbacks.length); i++) {
- if (m_callbacks[i] == hk) { return; }
+ if (m_callbacks[i] == hk) {
+ return;
+ }
}
if (m_callbacks.length > 0) {
@@ -68,19 +72,25 @@
newHk[m_callbacks.length] = hk;
m_callbacks = newHk;
} else {
- m_callbacks = new LifecycleCallback[] {hk};
+ m_callbacks = new LifecycleCallback[] { hk };
}
}
/**
- * @see org.apache.felix.ipojo.Handler#configure(org.apache.felix.ipojo.InstanceManager, org.apache.felix.ipojo.metadata.Element)
+ * Configure the handler.
+ * @param cm : the instance manager
+ * @param metadata : the component type metadata
+ * @param configuration : the instance configuration
+ * @see org.apache.felix.ipojo.Handler#configure(org.apache.felix.ipojo.InstanceManager, org.apache.felix.ipojo.metadata.Element, java.util.Dictionary)
*/
public void configure(InstanceManager cm, Element metadata, Dictionary configuration) {
m_manager = cm;
m_callbacks = new LifecycleCallback[0];
-
- if (metadata.containsAttribute("immediate") && metadata.getAttribute("immediate").equalsIgnoreCase("true")) { m_immediate = true; }
+
+ if (metadata.containsAttribute("immediate") && metadata.getAttribute("immediate").equalsIgnoreCase("true")) {
+ m_immediate = true;
+ }
Element[] hooksMetadata = metadata.getElements("callback");
for (int i = 0; i < hooksMetadata.length; i++) {
@@ -89,20 +99,27 @@
String finalState = hooksMetadata[i].getAttribute("final");
String method = hooksMetadata[i].getAttribute("method");
boolean isStatic = false;
- if (hooksMetadata[i].containsAttribute("isStatic") && hooksMetadata[i].getAttribute("isStatic").equals("true")) { isStatic = true; }
+ if (hooksMetadata[i].containsAttribute("isStatic") && hooksMetadata[i].getAttribute("isStatic").equals("true")) {
+ isStatic = true;
+ }
LifecycleCallback hk = new LifecycleCallback(this, initialState, finalState, method, isStatic);
addCallback(hk);
}
- if (m_callbacks.length > 0 || m_immediate) { m_manager.register(this); }
+ if (m_callbacks.length > 0 || m_immediate) {
+ m_manager.register(this);
+ }
}
/**
+ * Start the handler.
* @see org.apache.felix.ipojo.Handler#start()
*/
- public void start() { } //Do nothing during the start
+ public void start() {
+ } // Do nothing during the start
/**
+ * Stop the handler.
* @see org.apache.felix.ipojo.Handler#stop()
*/
public void stop() {
@@ -110,30 +127,40 @@
}
/**
+ * Get the instance manager.
* @return the instance manager
*/
- protected InstanceManager getInstanceManager() { return m_manager; }
+ protected InstanceManager getInstanceManager() {
+ return m_manager;
+ }
/**
- * When the state change call the associated hooks.
+ * When the state change call the associated callback.
+ *
+ * @param state : the new isntance state.
* @see org.apache.felix.ipojo.Handler#stateChanged(int)
*/
public void stateChanged(int state) {
- // Manage immediate component
- if (m_state == ComponentInstance.INVALID && state == ComponentInstance.VALID && m_manager.getPojoObjects().length == 0) {
- m_manager.createPojoObject();
- }
-
+ // Manage immediate component
+ if (m_state == ComponentInstance.INVALID && state == ComponentInstance.VALID && m_manager.getPojoObjects().length == 0) {
+ m_manager.createPojoObject();
+ }
+
for (int i = 0; i < m_callbacks.length; i++) {
if (m_callbacks[i].getInitialState() == m_state && m_callbacks[i].getFinalState() == state) {
try {
m_callbacks[i].call();
} catch (NoSuchMethodException e) {
- m_manager.getFactory().getLogger().log(Logger.ERROR, "[" + m_manager.getClassName() + "] The callback method " + m_callbacks[i].getMethod() + " is not found", e);
+ m_manager.getFactory().getLogger().log(Logger.ERROR,
+ "[" + m_manager.getClassName() + "] The callback method " + m_callbacks[i].getMethod() + " is not found", e);
} catch (IllegalAccessException e) {
- m_manager.getFactory().getLogger().log(Logger.ERROR, "[" + m_manager.getClassName() + "] The callback method " + m_callbacks[i].getMethod() + " is not accessible", e);
+ m_manager.getFactory().getLogger().log(Logger.ERROR,
+ "[" + m_manager.getClassName() + "] The callback method " + m_callbacks[i].getMethod() + " is not accessible", e);
} catch (InvocationTargetException e) {
- m_manager.getFactory().getLogger().log(Logger.ERROR, "[" + m_manager.getClassName() + "] The callback method " + m_callbacks[i].getMethod() + " has throws an exception : " + e.getMessage() + " -> " + e.getCause());
+ m_manager.getFactory().getLogger().log(
+ Logger.ERROR,
+ "[" + m_manager.getClassName() + "] The callback method " + m_callbacks[i].getMethod() + " has throws an exception : "
+ + e.getMessage() + " -> " + e.getCause());
}
}
}
Modified: incubator/felix/trunk/ipojo/src/main/java/org/apache/felix/ipojo/handlers/providedservice/Property.java
URL: http://svn.apache.org/viewvc/incubator/felix/trunk/ipojo/src/main/java/org/apache/felix/ipojo/handlers/providedservice/Property.java?view=diff&rev=529623&r1=529622&r2=529623
==============================================================================
--- incubator/felix/trunk/ipojo/src/main/java/org/apache/felix/ipojo/handlers/providedservice/Property.java (original)
+++ incubator/felix/trunk/ipojo/src/main/java/org/apache/felix/ipojo/handlers/providedservice/Property.java Tue Apr 17 07:31:35 2007
@@ -27,18 +27,17 @@
import org.apache.felix.ipojo.util.Logger;
/**
- * Represent a property i.e. a set : [name, type, value].
- * A property can be attached to a field.
- * The value of the property is thefield value.
- * When the value change, the published value change too.
+ * Represent a property i.e. a set : [name, type, value]. A property can be
+ * attached to a field. The value of the property is thefield value. When the
+ * value change, the published value change too.
+ *
* @author <a href="mailto:felix-dev@incubator.apache.org">Felix Project Team</a>
*/
public class Property {
/**
- * A property is link with a service.
- * This field represent this provided service.
- * m_providedService : ProvidedService
+ * A property is link with a service. This field represent this provided
+ * service. m_providedService : ProvidedService
*/
private ProvidedService m_providedService;
@@ -46,7 +45,7 @@
* Value of the property (before we know the type).
*/
private Object m_value;
-
+
/**
* Field of the property.
*/
@@ -69,6 +68,7 @@
/**
* Property constructor.
+ *
* @param ps : the provided service
* @param name : name of the property
* @param field : name of the field (if a field is attached to the property)
@@ -85,27 +85,38 @@
// Dynamic property case :
if (m_field != null) {
- if (m_name == null) { m_name = m_field; }
+ if (m_name == null) {
+ m_name = m_field;
+ }
}
-
+
// Check type if not already set
if (m_type == null) {
- if (field == null) { ps.getInstanceManager().getFactory().getLogger().log(Logger.ERROR, "The property " + m_name + " has neither type neither field."); return; }
+ if (field == null) {
+ ps.getInstanceManager().getFactory().getLogger().log(Logger.ERROR, "The property " + m_name + " has neither type neither field.");
+ return;
+ }
for (int j = 0; j < manipulation.getElements("Field").length; j++) {
if (field.equals(manipulation.getElements("Field")[j].getAttribute("name"))) {
m_type = manipulation.getElements("Field")[j].getAttribute("type");
break;
}
}
- if (m_type == null) { m_providedService.getInstanceManager().getFactory().getLogger().log(Logger.ERROR, "[" + ps.getInstanceManager().getClassName() + "] A declared property was not found in the class : " + m_field); }
+ if (m_type == null) {
+ m_providedService.getInstanceManager().getFactory().getLogger().log(Logger.ERROR,
+ "[" + ps.getInstanceManager().getClassName() + "] A declared property was not found in the class : " + m_field);
+ }
+ }
+
+ if (m_initialValue != null) {
+ setValue(m_initialValue);
}
-
- if (m_initialValue != null) { setValue(m_initialValue); }
}
/**
- * Property constructor.
- * This constructor is used only for non-field property (property not attached to a field).
+ * Property constructor. This constructor is used only for non-field
+ * property (property not attached to a field).
+ *
* @param ps : the provided service
* @param name : the name of the property
* @param value : the value of the property
@@ -118,13 +129,17 @@
}
/**
+ * Get the property value.
* @return the Object value of the property
*/
- protected Object get() { return m_value; }
+ protected Object get() {
+ return m_value;
+ }
/**
- * This method is automaticaly called when the value of the property is changed.
- * Set the value of a property.
+ * This method is automaticaly called when the value of the property is
+ * changed. Set the value of a property.
+ *
* @param s : the new value of the property (in String)
*/
protected void set(String s) {
@@ -132,8 +147,9 @@
}
/**
- * This method is called when the value of the property is changed.
- * Set the value of a property.
+ * This method is called when the value of the property is changed. Set the
+ * value of a property.
+ *
* @param o : the new value of the property (object)
*/
protected void set(Object o) {
@@ -142,6 +158,7 @@
/**
* Set the provided service of this property.
+ *
* @param ps : the provided service to attached.
*/
void setProvidedService(ProvidedService ps) {
@@ -150,6 +167,7 @@
/**
* Set the value of the property.
+ *
* @param value : value of the property (String)
*/
private void setValue(String value) {
@@ -162,154 +180,210 @@
}
// Simple :
- if (m_type.equals("string") || m_type.equals("String")) { m_value = new String(value); return; }
- if (m_type.equals("boolean")) { m_value = new Boolean(value); return; }
- if (m_type.equals("byte")) { m_value = new Byte(value); return; }
- if (m_type.equals("short")) { m_value = new Short(value); return; }
- if (m_type.equals("int")) { m_value = new Integer(value); return; }
- if (m_type.equals("long")) { m_value = new Long(value); return; }
- if (m_type.equals("float")) { m_value = new Float(value); return; }
- if (m_type.equals("double")) { m_value = new Double(value); return; }
+ if (m_type.equals("string") || m_type.equals("String")) {
+ m_value = new String(value);
+ return;
+ }
+ if (m_type.equals("boolean")) {
+ m_value = new Boolean(value);
+ return;
+ }
+ if (m_type.equals("byte")) {
+ m_value = new Byte(value);
+ return;
+ }
+ if (m_type.equals("short")) {
+ m_value = new Short(value);
+ return;
+ }
+ if (m_type.equals("int")) {
+ m_value = new Integer(value);
+ return;
+ }
+ if (m_type.equals("long")) {
+ m_value = new Long(value);
+ return;
+ }
+ if (m_type.equals("float")) {
+ m_value = new Float(value);
+ return;
+ }
+ if (m_type.equals("double")) {
+ m_value = new Double(value);
+ return;
+ }
- // Else it is a neither a primitive type neither a String -> create the object by calling a constructor with a string in argument.
+ // Else it is a neither a primitive type neither a String -> create the
+ // object by calling a constructor with a string in argument.
try {
Class c = m_providedService.getInstanceManager().getContext().getBundle().loadClass(m_type);
- //Class string = m_providedService.getComponentManager().getContext().getBundle().loadClass("java.lang.String");
- Constructor cst = c.getConstructor(new Class[] {String.class});
- m_value = cst.newInstance(new Object[] {value});
+ // Class string =
+ // m_providedService.getComponentManager().getContext().getBundle().loadClass("java.lang.String");
+ Constructor cst = c.getConstructor(new Class[] { String.class });
+ m_value = cst.newInstance(new Object[] { value });
} catch (ClassNotFoundException e) {
- System.err.println("Class not found exception in setValue on " + m_type);
- e.printStackTrace();
+ m_providedService.getInstanceManager().getFactory().getLogger().log(Logger.ERROR, "Class not found exception in setValue on " + m_type);
} catch (SecurityException e) {
- e.printStackTrace();
+ m_providedService.getInstanceManager().getFactory().getLogger().log(Logger.ERROR, "Security Exception in setValue on " + m_type);
} catch (NoSuchMethodException e) {
- System.err.println("Constructor not found exeption in setValue on " + m_type);
- e.printStackTrace();
+ m_providedService.getInstanceManager().getFactory().getLogger().log(Logger.ERROR, "Constructor not found exeption in setValue on " + m_type);
} catch (IllegalArgumentException e) {
- System.err.println("Argument problem to call the constructor of the type " + m_type);
- e.printStackTrace();
+ m_providedService.getInstanceManager().getFactory().getLogger().log(Logger.ERROR, "Argument problem to call the constructor of the type " + m_type);
} catch (InstantiationException e) {
- System.err.println("Instantiation problem " + m_type);
- e.printStackTrace();
+ m_providedService.getInstanceManager().getFactory().getLogger().log(Logger.ERROR, "Instantiation problem " + m_type);
} catch (IllegalAccessException e) {
- e.printStackTrace();
+ m_providedService.getInstanceManager().getFactory().getLogger().log(Logger.ERROR, "Illegal Access Exception in setValue on " + m_type);
} catch (InvocationTargetException e) {
- System.err.println("Invocation problem " + m_type);
- e.printStackTrace();
+ m_providedService.getInstanceManager().getFactory().getLogger().log(Logger.ERROR, "Invocation problem " + m_type);
}
}
/**
* Set a array value to the current property.
+ *
* @param internalType : internal array type
* @param values : the new value
*/
private void setArrayValue(String internalType, String[] values) {
- if (internalType.equals("string") || internalType.equals("String")) { m_value = values; return; }
+ if (internalType.equals("string") || internalType.equals("String")) {
+ m_value = values;
+ return;
+ }
if (internalType.equals("boolean")) {
boolean[] bool = new boolean[values.length];
- for (int i = 0; i < values.length; i++) { bool[i] = new Boolean(values[i]).booleanValue(); }
+ for (int i = 0; i < values.length; i++) {
+ bool[i] = new Boolean(values[i]).booleanValue();
+ }
m_value = bool;
return;
}
if (internalType.equals("byte")) {
byte[] byt = new byte[values.length];
- for (int i = 0; i < values.length; i++) { byt[i] = new Byte(values[i]).byteValue(); }
+ for (int i = 0; i < values.length; i++) {
+ byt[i] = new Byte(values[i]).byteValue();
+ }
m_value = byt;
return;
}
if (internalType.equals("short")) {
short[] shor = new short[values.length];
- for (int i = 0; i < values.length; i++) { shor[i] = new Short(values[i]).shortValue(); }
+ for (int i = 0; i < values.length; i++) {
+ shor[i] = new Short(values[i]).shortValue();
+ }
m_value = shor;
return;
}
if (internalType.equals("int")) {
int[] in = new int[values.length];
- for (int i = 0; i < values.length; i++) { in[i] = new Integer(values[i]).intValue(); }
+ for (int i = 0; i < values.length; i++) {
+ in[i] = new Integer(values[i]).intValue();
+ }
m_value = in;
return;
}
if (internalType.equals("long")) {
long[] ll = new long[values.length];
- for (int i = 0; i < values.length; i++) { ll[i] = new Long(values[i]).longValue(); }
+ for (int i = 0; i < values.length; i++) {
+ ll[i] = new Long(values[i]).longValue();
+ }
m_value = ll;
return;
}
if (internalType.equals("float")) {
float[] fl = new float[values.length];
- for (int i = 0; i < values.length; i++) { fl[i] = new Float(values[i]).floatValue(); }
+ for (int i = 0; i < values.length; i++) {
+ fl[i] = new Float(values[i]).floatValue();
+ }
m_value = fl;
- return;
+ return;
}
if (internalType.equals("double")) {
double[] dl = new double[values.length];
- for (int i = 0; i < values.length; i++) { dl[i] = new Double(values[i]).doubleValue(); }
+ for (int i = 0; i < values.length; i++) {
+ dl[i] = new Double(values[i]).doubleValue();
+ }
m_value = dl;
- return;
+ return;
}
- // Else it is a neither a primitive type neither a String -> create the object by calling a constructor with a string in argument.
+ // Else it is a neither a primitive type neither a String -> create the
+ // object by calling a constructor with a string in argument.
try {
Class c = m_providedService.getInstanceManager().getContext().getBundle().loadClass(internalType);
- Constructor cst = c.getConstructor(new Class[] {String.class});
+ Constructor cst = c.getConstructor(new Class[] { String.class });
Object[] ob = (Object[]) Array.newInstance(c, values.length);
for (int i = 0; i < values.length; i++) {
- ob[i] = cst.newInstance(new Object[] {values[i]});
+ ob[i] = cst.newInstance(new Object[] { values[i] });
}
m_value = ob;
return;
} catch (ClassNotFoundException e) {
- System.err.println("Class not found exception in setValue on " + internalType);
- e.printStackTrace();
+ m_providedService.getInstanceManager().getFactory().getLogger().log(Logger.ERROR, "Class not found exception in setArrayValue on " + internalType);
} catch (SecurityException e) {
- e.printStackTrace();
+ m_providedService.getInstanceManager().getFactory().getLogger().log(Logger.ERROR, "Security Exception in setArrayValue on " + internalType);
} catch (NoSuchMethodException e) {
- System.err.println("Constructor not found exeption in setValue on " + internalType);
- e.printStackTrace();
+ m_providedService.getInstanceManager().getFactory().getLogger().log(Logger.ERROR,
+ "Constructor not found exception in setArrayValue on " + internalType);
} catch (IllegalArgumentException e) {
- System.err.println("Argument problem to call the constructor of the type " + internalType);
- e.printStackTrace();
+ m_providedService.getInstanceManager().getFactory().getLogger().log(Logger.ERROR,
+ "Argument problem to call the constructor of the type " + internalType);
} catch (InstantiationException e) {
- System.err.println("Instantiation problem " + internalType);
- e.printStackTrace();
+ m_providedService.getInstanceManager().getFactory().getLogger().log(Logger.ERROR, "Instantiation problem " + internalType);
} catch (IllegalAccessException e) {
- e.printStackTrace();
+ m_providedService.getInstanceManager().getFactory().getLogger().log(Logger.ERROR, "Illegal Access Exception in setArrayValue on " + internalType);
} catch (InvocationTargetException e) {
- System.err.println("Invocation problem " + internalType);
- e.printStackTrace();
+ m_providedService.getInstanceManager().getFactory().getLogger().log(Logger.ERROR, "Invocation problem " + internalType);
}
}
/**
+ * Get the stored value.
* @return the value of the property.
*/
- public Object getValue() { return m_value; }
-
+ public Object getValue() {
+ return m_value;
+ }
+
/**
+ * Get the property name.
* @return the name of the property
*/
- public String getName() { return m_name; }
-
+ public String getName() {
+ return m_name;
+ }
+
+ /**
+ * Get the property field.
+ * @return the field name of the property (null if the property has no
+ * field).
+ */
+ protected String getField() {
+ return m_field;
+ }
+
/**
- * @return the field name of the property (null if the property has no field).
+ * Set the type of the property.
+ *
+ * @param type : the type to attached to the property
*/
- protected String getField() { return m_field; }
+ public void setType(String type) {
+ m_type = type;
+ }
+
+ /**
+ * Get the property type.
+ * @return the type of the property.
+ */
+ public String getType() {
+ return m_type;
+ }
+
+ /**
+ * Get the property initial value.
+ * @return the initial value of the property.
+ */
+ public String getInitialValue() {
+ return m_initialValue;
+ }
- /**
- * Set the type of the property.
- * @param type : the type to attached to the property
- */
- public void setType(String type) { m_type = type; }
-
- /**
- * @return the type of the property.
- */
- public String getType() { return m_type; }
-
- /**
- * @return the initial value of the property.
- */
- public String getInitialValue() { return m_initialValue; }
-
}
Modified: incubator/felix/trunk/ipojo/src/main/java/org/apache/felix/ipojo/handlers/providedservice/ProvidedService.java
URL: http://svn.apache.org/viewvc/incubator/felix/trunk/ipojo/src/main/java/org/apache/felix/ipojo/handlers/providedservice/ProvidedService.java?view=diff&rev=529623&r1=529622&r2=529623
==============================================================================
--- incubator/felix/trunk/ipojo/src/main/java/org/apache/felix/ipojo/handlers/providedservice/ProvidedService.java (original)
+++ incubator/felix/trunk/ipojo/src/main/java/org/apache/felix/ipojo/handlers/providedservice/ProvidedService.java Tue Apr 17 07:31:35 2007
@@ -29,9 +29,9 @@
import org.osgi.framework.ServiceReference;
import org.osgi.framework.ServiceRegistration;
-
/**
* Provided Service represent a provided service by the component.
+ *
* @author <a href="mailto:felix-dev@incubator.apache.org">Felix Project Team</a>
*/
public class ProvidedService implements ServiceFactory {
@@ -67,15 +67,13 @@
private int m_factoryPolicy = SINGLETON_FACTORY;
/**
- * The service registration.
- * is null when the service is not registred.
+ * The service registration. is null when the service is not registred.
* m_serviceRegistration : ServiceRegistration
*/
private ServiceRegistration m_serviceRegistration;
/**
- * Link to the owner handler.
- * m_handler : Provided Service Handler
+ * Link to the owner handler. m_handler : Provided Service Handler
*/
private ProvidedServiceHandler m_handler;
@@ -84,42 +82,47 @@
*/
private Property[] m_properties = new Property[0];
-
/**
* Construct a provided service object.
+ *
* @param handler : the provided service handler.
* @param specification : specifications provided by this provided service
* @param factoryPolicy : service providing policy
*/
public ProvidedService(ProvidedServiceHandler handler, String[] specification, int factoryPolicy) {
m_handler = handler;
-
+
m_serviceSpecification = specification;
m_factoryPolicy = factoryPolicy;
-
- //Add service pid and factory pid
+
+ // Add service pid and factory pid
addProperty(new Property(this, org.osgi.framework.Constants.SERVICE_PID, handler.getInstanceManager().getInstanceName()));
- addProperty(new Property(this, "factory.pid", handler.getInstanceManager().getFactory().getFactoryName()));
+ addProperty(new Property(this, "factory.pid", handler.getInstanceManager().getFactory().getName()));
}
-
- //TODO check if we need to erase previous props or add to the previous props.
+
+ // TODO check if we need to erase previous props or add to the previous
+ // props.
/**
* Add properties to the provided service.
+ *
* @param props : the properties to attached to the service registration
*/
- protected void setProperties(Property[] props) {
- for (int i = 0; i < props.length; i++) {
- addProperty(props[i]);
- }
+ protected void setProperties(Property[] props) {
+ for (int i = 0; i < props.length; i++) {
+ addProperty(props[i]);
+ }
}
/**
* Add the given property to the property list.
+ *
* @param p : the element to add
*/
private synchronized void addProperty(Property p) {
for (int i = 0; (m_properties != null) && (i < m_properties.length); i++) {
- if (m_properties[i] == p) { return; }
+ if (m_properties[i] == p) {
+ return;
+ }
}
if (m_properties.length > 0) {
@@ -127,29 +130,33 @@
System.arraycopy(m_properties, 0, newProp, 0, m_properties.length);
newProp[m_properties.length] = p;
m_properties = newProp;
- } else {
- m_properties = new Property[] {p};
+ } else {
+ m_properties = new Property[] { p };
}
}
/**
* Remove a property.
+ *
* @param name : the property to remove
*/
private synchronized void removeProperty(String name) {
int idx = -1;
for (int i = 0; i < m_properties.length; i++) {
- if (m_properties[i].getName() == name) { idx = i; break; }
+ if (m_properties[i].getName() == name) {
+ idx = i;
+ break;
+ }
}
if (idx >= 0) {
- if ((m_properties.length - 1) == 0) {
- m_properties = new Property[0];
+ if ((m_properties.length - 1) == 0) {
+ m_properties = new Property[0];
} else {
Property[] newPropertiesList = new Property[m_properties.length - 1];
System.arraycopy(m_properties, 0, newPropertiesList, 0, idx);
if (idx < newPropertiesList.length) {
- System.arraycopy(m_properties, idx + 1, newPropertiesList, idx, newPropertiesList.length - idx);
+ System.arraycopy(m_properties, idx + 1, newPropertiesList, idx, newPropertiesList.length - idx);
}
m_properties = newPropertiesList;
}
@@ -157,33 +164,43 @@
}
/**
- * @return the service reference of the provided service (null if the service is not published).
+ * Get the service reference of the service registration.
+ * @return the service reference of the provided service (null if the
+ * service is not published).
*/
public ServiceReference getServiceReference() {
- if (m_serviceRegistration != null) {
- return m_serviceRegistration.getReference();
- } else { return null; }
+ if (m_serviceRegistration != null) {
+ return m_serviceRegistration.getReference();
+ } else {
+ return null;
+ }
}
/**
* Return a service object for the dependency.
- * @see org.osgi.framework.ServiceFactory#getService(org.osgi.framework.Bundle, org.osgi.framework.ServiceRegistration)
+ *
+ * @see org.osgi.framework.ServiceFactory#getService(org.osgi.framework.Bundle,
+ * org.osgi.framework.ServiceRegistration)
* @param bundle : the bundle
* @param registration : the service registration of the registred service
- * @return : a new service object or a already created service object (in the case of singleton)
+ * @return : a new service object or a already created service object (in
+ * the case of singleton)
*/
public Object getService(Bundle bundle, ServiceRegistration registration) {
- switch(m_factoryPolicy) {
+ switch (m_factoryPolicy) {
- case SINGLETON_FACTORY :
+ case SINGLETON_FACTORY:
return m_handler.getInstanceManager().getPojoObject();
- case SERVICE_FACTORY :
+ case SERVICE_FACTORY:
return m_handler.getInstanceManager().createPojoObject();
- default :
- m_handler.getInstanceManager().getFactory().getLogger().log(Logger.ERROR, "[" + m_handler.getInstanceManager().getClassName() + "] Unknown factory policy for " + m_serviceSpecification + " : " + m_factoryPolicy);
+ default:
+ m_handler.getInstanceManager().getFactory().getLogger().log(
+ Logger.ERROR,
+ "[" + m_handler.getInstanceManager().getClassName() + "] Unknown factory policy for " + m_serviceSpecification + " : "
+ + m_factoryPolicy);
return null;
}
@@ -191,19 +208,21 @@
/**
* The unget method.
- * @see org.osgi.framework.ServiceFactory#ungetService(org.osgi.framework.Bundle, org.osgi.framework.ServiceRegistration, java.lang.Object)
+ *
+ * @see org.osgi.framework.ServiceFactory#ungetService(org.osgi.framework.Bundle,
+ * org.osgi.framework.ServiceRegistration, java.lang.Object)
* @param bundle : bundle
* @param registration : service registration
* @param service : service object
*/
public void ungetService(Bundle bundle, ServiceRegistration registration, Object service) {
- //Nothing to do
+ // Nothing to do
}
/**
- * Register the service.
- * The service object must be able to serve this service.
- * To avoid cycle in Check Context, the registred service is set to registred before the real registration.
+ * Register the service. The service object must be able to serve this
+ * service. To avoid cycle in Check Context, the registred service is set to
+ * registred before the real registration.
*/
protected synchronized void registerService() {
if (m_serviceRegistration == null) {
@@ -214,9 +233,7 @@
// Contruct the service properties list
Properties serviceProperties = getServiceProperties();
- m_serviceRegistration =
- m_handler.getInstanceManager().getContext().registerService(
- m_serviceSpecification, this, serviceProperties);
+ m_serviceRegistration = m_handler.getInstanceManager().getContext().registerService(m_serviceSpecification, this, serviceProperties);
}
}
@@ -227,32 +244,33 @@
if (m_serviceRegistration != null) {
try {
m_serviceRegistration.unregister();
- } catch (Exception e) { return; }
+ } catch (Exception e) {
+ return;
+ }
m_serviceRegistration = null;
}
}
/**
+ * Get the current provided service state.
* @return The state of the provided service.
*/
public int getState() {
- if (m_serviceRegistration == null) {
- return UNREGISTERED;
- } else {
- return REGISTERED;
- }
+ if (m_serviceRegistration == null) {
+ return UNREGISTERED;
+ } else {
+ return REGISTERED;
+ }
}
- /**
- * @return the instance manager.
- */
protected InstanceManager getInstanceManager() {
return m_handler.getInstanceManager();
}
/**
- * Return the list of properties attached to this service.
- * This list contains only property where a value are assigned.
+ * Return the list of properties attached to this service. This list
+ * contains only property where a value are assigned.
+ *
* @return the properties attached to the provided service.
*/
private Properties getServiceProperties() {
@@ -267,6 +285,7 @@
}
/**
+ * Get the list of properties attached to the service registration.
* @return the properties attached to the provided service.
*/
public Property[] getProperties() {
@@ -274,15 +293,15 @@
}
/**
- * Update the service properties.
- * The new list of properties is sended to the service registry.
+ * Update the service properties. The new list of properties is sended to
+ * the service registry.
*/
public synchronized void update() {
// Contruct the service properties list
Properties serviceProperties = getServiceProperties();
-
+
if (serviceProperties == null) {
- m_handler.getInstanceManager().getFactory().getLogger().log(Logger.ERROR, "Cannot get the properties of the provided service");
+ m_handler.getInstanceManager().getFactory().getLogger().log(Logger.ERROR, "Cannot get the properties of the provided service");
}
// Update the service registration
@@ -293,6 +312,7 @@
/**
* Add properties to the list.
+ *
* @param props : properties to add
*/
protected void addProperties(Dictionary props) {
@@ -307,6 +327,7 @@
/**
* Remove properties from the list.
+ *
* @param props : properties to remove
*/
protected void deleteProperties(Dictionary props) {
@@ -317,9 +338,21 @@
}
}
- /**
- * @return the list of provided service specifications (i.e. java interface).
- */
- public String[] getServiceSpecification() { return m_serviceSpecification; }
+ /**
+ * Get the published service specifications.
+ * @return the list of provided service specifications (i.e. java
+ * interface).
+ */
+ public String[] getServiceSpecification() {
+ return m_serviceSpecification;
+ }
+
+ /**
+ * Get the service registration.
+ * @return the service registration of this service.
+ */
+ public ServiceRegistration getServiceRegistration() {
+ return m_serviceRegistration;
+ }
}
Modified: incubator/felix/trunk/ipojo/src/main/java/org/apache/felix/ipojo/handlers/providedservice/ProvidedServiceDescription.java
URL: http://svn.apache.org/viewvc/incubator/felix/trunk/ipojo/src/main/java/org/apache/felix/ipojo/handlers/providedservice/ProvidedServiceDescription.java?view=diff&rev=529623&r1=529622&r2=529623
==============================================================================
--- incubator/felix/trunk/ipojo/src/main/java/org/apache/felix/ipojo/handlers/providedservice/ProvidedServiceDescription.java (original)
+++ incubator/felix/trunk/ipojo/src/main/java/org/apache/felix/ipojo/handlers/providedservice/ProvidedServiceDescription.java Tue Apr 17 07:31:35 2007
@@ -20,34 +20,29 @@
import java.util.Properties;
-import org.apache.felix.ipojo.handlers.dependency.DependencyDescription;
import org.osgi.framework.ServiceReference;
/**
* Provided Service Description.
+ *
* @author <a href="mailto:felix-dev@incubator.apache.org">Felix Project Team</a>
*/
public class ProvidedServiceDescription {
-
- /**
- * State : the service is unregistered.
- */
- public static final int UNREGISTERED = 0;
-
- /**
- * State : the service is registered.
- */
- public static final int REGISTERED = 1;
/**
- * Provided Service Specification.
+ * State : the service is unregistered.
*/
- private String[] m_serviceSpecification;
+ public static final int UNREGISTERED = 0;
+
+ /**
+ * State : the service is registered.
+ */
+ public static final int REGISTERED = 1;
/**
- * Dependency of the service.
+ * Provided Service Specification.
*/
- private DependencyDescription[] m_dependencies = new DependencyDescription[0];
+ private String[] m_serviceSpecification;
/**
* State.
@@ -59,31 +54,33 @@
*/
private ServiceReference m_serviceReference;
-// /**
-// * Handler on the component description who contains this description.
-// */
-// private InstanceDescription m_parent;
+ // /**
+ // * Handler on the component description who contains this description.
+ // */
+ // private InstanceDescription m_parent;
/**
* Properties of the provided service.
*/
private Properties m_properties = new Properties();
-
/**
* Constructor.
+ *
* @param serviceSpecification : the provided contract
* @param state : state (UNREGITRED | REGISTRED)
- * @param sr : Service Registration (to obtain the reference), or null if state is UNREGISTRED
+ * @param sr : Service Registration (to obtain the reference), or null if
+ * state is UNREGISTRED
*/
public ProvidedServiceDescription(String[] serviceSpecification, int state, ServiceReference sr) {
m_serviceSpecification = serviceSpecification;
m_state = state;
m_serviceReference = sr;
- // m_parent = parent;
+ // m_parent = parent;
}
/**
+ * Get the list of provided service specifications.
* @return the provided contract name.
*/
public String[] getServiceSpecification() {
@@ -92,6 +89,7 @@
/**
* Add a property to the current provided service description.
+ *
* @param key : the key of the property
* @param value : the value of the property
*/
@@ -101,6 +99,7 @@
/**
* Set the set of properties. This function create a clone of the argument.
+ *
* @param props : the properties
*/
public void setProperty(Properties props) {
@@ -108,13 +107,7 @@
}
/**
- * @return the dependeny description list.
- */
- public DependencyDescription[] getDependencies() {
- return m_dependencies;
- }
-
- /**
+ * Get the list of properties.
* @return the properties.
*/
public Properties getProperties() {
@@ -122,13 +115,15 @@
}
/**
- * @return the state of the provided service (UNREGISTRED | REGISTRED).
+ * Get provided service state.
+ * @return the state of the provided service (UNREGISTERED | REGISTRED).
*/
public int getState() {
return m_state;
}
/**
+ * Get the service reference.
* @return the service reference (null if the service is unregistred).
*/
public ServiceReference getServiceReference() {
Modified: incubator/felix/trunk/ipojo/src/main/java/org/apache/felix/ipojo/handlers/providedservice/ProvidedServiceHandler.java
URL: http://svn.apache.org/viewvc/incubator/felix/trunk/ipojo/src/main/java/org/apache/felix/ipojo/handlers/providedservice/ProvidedServiceHandler.java?view=diff&rev=529623&r1=529622&r2=529623
==============================================================================
--- incubator/felix/trunk/ipojo/src/main/java/org/apache/felix/ipojo/handlers/providedservice/ProvidedServiceHandler.java (original)
+++ incubator/felix/trunk/ipojo/src/main/java/org/apache/felix/ipojo/handlers/providedservice/ProvidedServiceHandler.java Tue Apr 17 07:31:35 2007
@@ -32,11 +32,12 @@
import org.osgi.framework.Constants;
/**
+ * Composite PRovided Service Handler.
+ * This handler maange the service providing for a composition.
* @author <a href="mailto:felix-dev@incubator.apache.org">Felix Project Team</a>
*/
public class ProvidedServiceHandler extends Handler {
-
/**
* The list of the provided service.
*/
@@ -49,12 +50,15 @@
/**
* Add a provided service to the list .
+ *
* @param ps : the provided service to add
*/
private void addProvidedService(ProvidedService ps) {
- // Verify that the provided service is not already in the array.
+ // Verify that the provided service is not already in the array.
for (int i = 0; (m_providedServices != null) && (i < m_providedServices.length); i++) {
- if (m_providedServices[i] == ps) { return; }
+ if (m_providedServices[i] == ps) {
+ return;
+ }
}
if (m_providedServices.length > 0) {
@@ -62,23 +66,33 @@
System.arraycopy(m_providedServices, 0, newPS, 0, m_providedServices.length);
newPS[m_providedServices.length] = ps;
m_providedServices = newPS;
- } else {
- m_providedServices = new ProvidedService[] {ps};
+ } else {
+ m_providedServices = new ProvidedService[] { ps };
}
}
/**
+ * Get the instance manager.
* @return the instance manager.
*/
- public InstanceManager getInstanceManager() { return m_manager; }
+ public InstanceManager getInstanceManager() {
+ return m_manager;
+ }
/**
+ * Get the array of provided service.
* @return the list of the provided service.
*/
- public ProvidedService[] getProvidedService() { return m_providedServices; }
+ public ProvidedService[] getProvidedService() {
+ return m_providedServices;
+ }
/**
- * @see org.apache.felix.ipojo.Handler#configure(org.apache.felix.ipojo.InstanceManager, org.apache.felix.ipojo.metadata.Element)
+ * Configure the handler.
+ * @param im : the instance manager
+ * @param componentMetadata : the component type metadata
+ * @param configuration : the instance configuration
+ * @see org.apache.felix.ipojo.Handler#configure(org.apache.felix.ipojo.InstanceManager, org.apache.felix.ipojo.metadata.Element, java.util.Dictionary)
*/
public void configure(InstanceManager im, Element componentMetadata, Dictionary configuration) {
// Fix the instance manager & clean the provided service list
@@ -97,7 +111,7 @@
String[] serviceSpecification = new String[0];
if (providedServices[i].containsAttribute("interface")) {
String serviceSpecificationStr = providedServices[i].getAttribute("interface");
- //Get serviceSpecification if exist in the metadata
+ // Get serviceSpecification if exist in the metadata
serviceSpecification = ParseUtils.parseArrays(serviceSpecificationStr);
} else {
serviceSpecification = new String[manipulation.getElements("Interface").length];
@@ -105,11 +119,17 @@
serviceSpecification[j] = manipulation.getElements("Interface")[j].getAttribute("name");
}
}
- if (serviceSpecification.length == 0) { m_manager.getFactory().getLogger().log(Logger.ERROR, "Cannot instantiate a provided service : no specifications found (no interfaces implemented by the pojo)"); return; }
+ if (serviceSpecification.length == 0) {
+ m_manager.getFactory().getLogger().log(Logger.ERROR,
+ "Cannot instantiate a provided service : no specifications found (no interfaces implemented by the pojo)");
+ return;
+ }
// Get the factory policy
int factory = ProvidedService.SINGLETON_FACTORY;
- if (providedServices[i].containsAttribute("factory") && providedServices[i].getAttribute("factory").equals("service")) { factory = ProvidedService.SERVICE_FACTORY; }
+ if (providedServices[i].containsAttribute("factory") && providedServices[i].getAttribute("factory").equals("service")) {
+ factory = ProvidedService.SERVICE_FACTORY;
+ }
// Then create the provided service
ProvidedService ps = new ProvidedService(this, serviceSpecification, factory);
@@ -118,20 +138,28 @@
Property[] properties = new Property[props.length];
for (int j = 0; j < props.length; j++) {
String name = null;
- if (props[j].containsAttribute("name")) { name = props[j].getAttribute("name"); }
+ if (props[j].containsAttribute("name")) {
+ name = props[j].getAttribute("name");
+ }
String value = null;
- if (props[j].containsAttribute("value")) { value = props[j].getAttribute("value"); }
+ if (props[j].containsAttribute("value")) {
+ value = props[j].getAttribute("value");
+ }
String type = null;
- if (props[j].containsAttribute("type")) { type = props[j].getAttribute("type"); }
+ if (props[j].containsAttribute("type")) {
+ type = props[j].getAttribute("type");
+ }
String field = null;
- if (props[j].containsAttribute("field")) { field = props[j].getAttribute("field"); }
+ if (props[j].containsAttribute("field")) {
+ field = props[j].getAttribute("field");
+ }
- if (name != null && configuration.get(name) != null && configuration.get(name) instanceof String) {
- value = (String) configuration.get(name);
- } else {
- if (field != null && configuration.get(field) != null && configuration.get(field) instanceof String) {
- value = (String) configuration.get(field);
- }
+ if (name != null && configuration.get(name) != null && configuration.get(name) instanceof String) {
+ value = (String) configuration.get(name);
+ } else {
+ if (field != null && configuration.get(field) != null && configuration.get(field) instanceof String) {
+ value = (String) configuration.get(field);
+ }
}
Property prop = new Property(ps, name, field, type, value, manipulation);
@@ -140,22 +168,26 @@
// Attached to properties to the provided service
ps.setProperties(properties);
-
+
if (checkProvidedService(ps, manipulation)) {
addProvidedService(ps);
// Change ComponentInfo
- for (int k = 0; k < ps.getServiceSpecification().length; k++) { cd.addProvidedServiceSpecification(ps.getServiceSpecification()[k]); }
- for (int k = 0; k < ps.getProperties().length; k++) {
- if (!ps.getProperties()[k].getName().equals(Constants.SERVICE_PID) && !ps.getProperties()[k].getName().equals("factory.pid")) {
- cd.addProperty(new PropertyDescription(ps.getProperties()[k].getName(), ps.getProperties()[k].getType(), ps.getProperties()[k].getInitialValue()));
- }
+ for (int k = 0; k < ps.getServiceSpecification().length; k++) {
+ cd.addProvidedServiceSpecification(ps.getServiceSpecification()[k]);
+ }
+ for (int k = 0; k < ps.getProperties().length; k++) {
+ if (!ps.getProperties()[k].getName().equals(Constants.SERVICE_PID) && !ps.getProperties()[k].getName().equals("factory.pid")) {
+ cd.addProperty(new PropertyDescription(ps.getProperties()[k].getName(), ps.getProperties()[k].getType(), ps.getProperties()[k]
+ .getInitialValue()));
+ }
}
} else {
String itfs = "";
for (int j = 0; j < serviceSpecification.length; j++) {
itfs = itfs + " " + serviceSpecification[j];
}
- m_manager.getFactory().getLogger().log(Logger.ERROR, "[" + m_manager.getClassName() + "] The provided service" + itfs + " is not valid, it will be removed");
+ m_manager.getFactory().getLogger().log(Logger.ERROR,
+ "[" + m_manager.getClassName() + "] The provided service" + itfs + " is not valid, it will be removed");
ps = null;
}
@@ -168,13 +200,14 @@
for (int j = 0; j < ps.getProperties().length; j++) {
Property prop = ps.getProperties()[j];
- // Check if the instance configuration has a value for this property
- if (prop.getName() != null && configuration.get(prop.getName()) != null && !(configuration.get(prop.getName()) instanceof String)) {
- prop.set(configuration.get(prop.getName()));
- } else {
- if (prop.getField() != null && configuration.get(prop.getField()) != null && !(configuration.get(prop.getField()) instanceof String)) {
- prop.set(configuration.get(prop.getField()));
- }
+ // Check if the instance configuration has a value for this
+ // property
+ if (prop.getName() != null && configuration.get(prop.getName()) != null && !(configuration.get(prop.getName()) instanceof String)) {
+ prop.set(configuration.get(prop.getName()));
+ } else {
+ if (prop.getField() != null && configuration.get(prop.getField()) != null && !(configuration.get(prop.getField()) instanceof String)) {
+ prop.set(configuration.get(prop.getField()));
+ }
}
if (prop.getField() != null) {
String[] newFields = new String[fields.length + 1];
@@ -185,28 +218,34 @@
}
}
- m_manager.register(this, fields);
+ m_manager.register(this, fields);
}
}
/**
- * Check the provided service given in argument in the sense that the metadata are consistent.
- * @param ps : the provided service to check
+ * Check the provided service given in argument in the sense that the
+ * metadata are consistent.
+ *
+ * @param ps : the provided service to check.
+ * @param manipulation : componenet-type manipulation metadata.
* @return true if the provided service is correct
*/
private boolean checkProvidedService(ProvidedService ps, Element manipulation) {
for (int i = 0; i < ps.getServiceSpecification().length; i++) {
- boolean b = false;
- for (int ii = 0; ii < manipulation.getElements("Interface").length; ii++) {
+ boolean b = false;
+ for (int ii = 0; ii < manipulation.getElements("Interface").length; ii++) {
if (manipulation.getElements("Interface")[ii].getAttribute("name").equals(ps.getServiceSpecification()[i])) {
b = true;
}
}
- if (!b) {
- m_manager.getFactory().getLogger().log(Logger.ERROR, "[" + m_manager.getClassName() + "] The service specification " + ps.getServiceSpecification()[i] + " is not implemented by the component class");
- return false;
- }
+ if (!b) {
+ m_manager.getFactory().getLogger().log(
+ Logger.ERROR,
+ "[" + m_manager.getClassName() + "] The service specification " + ps.getServiceSpecification()[i]
+ + " is not implemented by the component class");
+ return false;
+ }
}
@@ -226,10 +265,11 @@
}
}
if (type == null) {
- m_manager.getFactory().getLogger().log(Logger.ERROR, "[" + m_manager.getClassName() + "] A declared property was not found in the class : " + prop.getField());
+ m_manager.getFactory().getLogger().log(Logger.ERROR,
+ "[" + m_manager.getClassName() + "] A declared property was not found in the class : " + prop.getField());
return false;
}
- prop.setType(type); //Set the type
+ prop.setType(type); // Set the type
}
}
return true;
@@ -237,18 +277,27 @@
/**
* Stop the provided service handler.
+ *
* @see org.apache.felix.ipojo.Handler#stop()
*/
- public void stop() { }
+ public void stop() {
+ }
/**
* Start the provided service handler.
+ *
* @see org.apache.felix.ipojo.Handler#start()
*/
- public void start() { }
+ public void start() {
+ }
- /**
- * @see org.apache.felix.ipojo.Handler#setterCallback(java.lang.String, java.lang.Object)
+ /**
+ * Setter Callback Method.
+ * Check if the modified field is a property to update the value.
+ * @param fieldName : field name
+ * @param value : new value
+ * @see org.apache.felix.ipojo.Handler#setterCallback(java.lang.String,
+ * java.lang.Object)
*/
public void setterCallback(String fieldName, Object value) {
// Verify that the field name coreespond to a dependency
@@ -263,13 +312,21 @@
update = true;
}
}
- if (update) { ps.update(); }
+ if (update) {
+ ps.update();
+ }
}
- //Else do nothing
+ // Else do nothing
}
/**
- * @see org.apache.felix.ipojo.Handler#getterCallback(java.lang.String, java.lang.Object)
+ * Getter Callback Method.
+ * Check if the field is a property to push the stored value.
+ * @param fieldName : field name
+ * @param value : value pushed by the previous handler
+ * @return the stored value or the previous value.
+ * @see org.apache.felix.ipojo.Handler#getterCallback(java.lang.String,
+ * java.lang.Object)
*/
public Object getterCallback(String fieldName, Object value) {
for (int i = 0; i < m_providedServices.length; i++) {
@@ -287,14 +344,16 @@
}
/**
- * Register the services if the new state is VALID.
- * Unregister the services if the new state is UNRESOLVED.
- * @see org.apache.felix.ipojo.Handler#stateChanged(int)
+ * Register the services if the new state is VALID. Unregister the services
+ * if the new state is UNRESOLVED.
+ *
+ * @param state : the new instance state.
+ * @see org.apache.felix.ipojo.CompositeHandler#stateChanged(int)
*/
public void stateChanged(int state) {
// If the new state is UNRESOLVED => unregister all the services
if (state == InstanceManager.INVALID) {
- for (int i = 0; i < m_providedServices.length; i++) {
+ for (int i = 0; i < m_providedServices.length; i++) {
m_providedServices[i].unregisterService();
}
return;
@@ -302,7 +361,7 @@
// If the new state is VALID => regiter all the services
if (state == InstanceManager.VALID) {
- for (int i = 0; i < m_providedServices.length; i++) {
+ for (int i = 0; i < m_providedServices.length; i++) {
m_providedServices[i].registerService();
}
return;
@@ -312,6 +371,7 @@
/**
* Add properties to all provided services.
+ *
* @param dict : dictionary fo properties to add
*/
public void addProperties(Dictionary dict) {
@@ -323,6 +383,7 @@
/**
* Remove properties form all provided services.
+ *
* @param dict : dictionary of properties to delete.
*/
public void removeProperties(Dictionary dict) {
@@ -331,46 +392,56 @@
m_providedServices[i].update();
}
}
-
- /**
- * @see org.apache.felix.ipojo.Handler#getDescription()
- */
- public HandlerDescription getDescription() {
- ProvidedServiceHandlerDescription pshd = new ProvidedServiceHandlerDescription(this.isValid());
-
- for (int j = 0; j < getProvidedService().length; j++) {
- ProvidedService ps = getProvidedService()[j];
- ProvidedServiceDescription psd = new ProvidedServiceDescription(ps.getServiceSpecification(), ps.getState(), ps.getServiceReference());
-
- Properties props = new Properties();
- for (int k = 0; k < ps.getProperties().length; k++) {
- Property prop = ps.getProperties()[k];
- if (prop.getValue() != null) { props.put(prop.getName(), prop.getValue().toString()); }
- }
- psd.setProperty(props);
- pshd.addProvidedService(psd);
- }
- return pshd;
- }
-
- /**
- * @see org.apache.felix.ipojo.Handler#reconfigure(java.util.Dictionary)
- */
- public void reconfigure(Dictionary dict) {
- for (int j = 0; j < getProvidedService().length; j++) {
- ProvidedService ps = getProvidedService()[j];
- Property[] props = ps.getProperties();
- boolean update = false;
- for (int k = 0; k < props.length; k++) {
- if (dict.get(props[k].getName()) != null) {
- update = true;
- if (dict.get(props[k].getName()) instanceof String) {
- props[k].set((String) dict.get(props[k].getName()));
- } else { props[k].set(dict.get(props[k].getName())); }
- }
- }
- if (update) { ps.update(); }
- }
- }
+
+ /**
+ * Build the provided service description.
+ * @return the handler description.
+ * @see org.apache.felix.ipojo.Handler#getDescription()
+ */
+ public HandlerDescription getDescription() {
+ ProvidedServiceHandlerDescription pshd = new ProvidedServiceHandlerDescription(this.isValid());
+
+ for (int j = 0; j < getProvidedService().length; j++) {
+ ProvidedService ps = getProvidedService()[j];
+ ProvidedServiceDescription psd = new ProvidedServiceDescription(ps.getServiceSpecification(), ps.getState(), ps.getServiceReference());
+
+ Properties props = new Properties();
+ for (int k = 0; k < ps.getProperties().length; k++) {
+ Property prop = ps.getProperties()[k];
+ if (prop.getValue() != null) {
+ props.put(prop.getName(), prop.getValue().toString());
+ }
+ }
+ psd.setProperty(props);
+ pshd.addProvidedService(psd);
+ }
+ return pshd;
+ }
+
+ /**
+ * Reconfigure provided service.
+ * @param dict : the new instance configuration.
+ * @see org.apache.felix.ipojo.Handler#reconfigure(java.util.Dictionary)
+ */
+ public void reconfigure(Dictionary dict) {
+ for (int j = 0; j < getProvidedService().length; j++) {
+ ProvidedService ps = getProvidedService()[j];
+ Property[] props = ps.getProperties();
+ boolean update = false;
+ for (int k = 0; k < props.length; k++) {
+ if (dict.get(props[k].getName()) != null) {
+ update = true;
+ if (dict.get(props[k].getName()) instanceof String) {
+ props[k].set((String) dict.get(props[k].getName()));
+ } else {
+ props[k].set(dict.get(props[k].getName()));
+ }
+ }
+ }
+ if (update) {
+ ps.update();
+ }
+ }
+ }
}
Modified: incubator/felix/trunk/ipojo/src/main/java/org/apache/felix/ipojo/handlers/providedservice/ProvidedServiceHandlerDescription.java
URL: http://svn.apache.org/viewvc/incubator/felix/trunk/ipojo/src/main/java/org/apache/felix/ipojo/handlers/providedservice/ProvidedServiceHandlerDescription.java?view=diff&rev=529623&r1=529622&r2=529623
==============================================================================
--- incubator/felix/trunk/ipojo/src/main/java/org/apache/felix/ipojo/handlers/providedservice/ProvidedServiceHandlerDescription.java (original)
+++ incubator/felix/trunk/ipojo/src/main/java/org/apache/felix/ipojo/handlers/providedservice/ProvidedServiceHandlerDescription.java Tue Apr 17 07:31:35 2007
@@ -21,9 +21,12 @@
import java.util.Iterator;
import org.apache.felix.ipojo.architecture.HandlerDescription;
+import org.apache.felix.ipojo.metadata.Attribute;
+import org.apache.felix.ipojo.metadata.Element;
/**
* Provided Service Handler Description.
+ *
* @author <a href="mailto:felix-dev@incubator.apache.org">Felix Project Team</a>
*/
public class ProvidedServiceHandlerDescription extends HandlerDescription {
@@ -33,9 +36,9 @@
*/
private ProvidedServiceDescription[] m_providedServices = new ProvidedServiceDescription[0];
-
/**
* Constructor.
+ *
* @param isValid : the validity of the provided service handler.
*/
public ProvidedServiceHandlerDescription(boolean isValid) {
@@ -43,19 +46,25 @@
}
/**
+ * Get the provided service descriptions.
* @return the provided service description list.
*/
- public ProvidedServiceDescription[] getProvidedServices() { return m_providedServices; }
+ public ProvidedServiceDescription[] getProvidedServices() {
+ return m_providedServices;
+ }
/**
* Add a provided service.
+ *
* @param pds : the provided service to add
*/
public void addProvidedService(ProvidedServiceDescription pds) {
- //Verify that the provided service description is not already in the array.
- for (int i = 0; (i < m_providedServices.length); i++) {
+ // Verify that the provided service description is not already in the
+ // array.
+ for (int i = 0; i < m_providedServices.length; i++) {
if (m_providedServices[i] == pds) {
- return; //NOTHING DO DO, the description is already in the array
+ return; // NOTHING DO DO, the description is already in the
+ // array
}
}
// The component Description is not in the array, add it
@@ -66,27 +75,40 @@
}
/**
+ * Build the provided service handler description.
+ * @return the handler description.
* @see org.apache.felix.ipojo.architecture.HandlerDescription#getHandlerInfo()
*/
- public String getHandlerInfo() {
- String info = "";
+ public Element getHandlerInfo() {
+ Element services = super.getHandlerInfo();
for (int i = 0; i < m_providedServices.length; i++) {
+ Element service = new Element("service", "");
String state = "unregistered";
- if (m_providedServices[i].getState() == ProvidedService.REGISTERED) { state = "registered"; }
- String spec = "";
+ if (m_providedServices[i].getState() == ProvidedService.REGISTERED) {
+ state = "registered";
+ }
+ String spec = "[";
for (int j = 0; j < m_providedServices[i].getServiceSpecification().length; j++) {
- spec += m_providedServices[i].getServiceSpecification()[j] + " ";
+ if (j == 0) {
+ spec += m_providedServices[i].getServiceSpecification()[j];
+ } else {
+ spec += ", " + m_providedServices[i].getServiceSpecification()[j];
+ }
}
- info += "\t Provided Service [" + spec + "] is " + state;
+ spec += "]";
+ service.addAttribute(new Attribute("specifications", spec));
+ service.addAttribute(new Attribute("state", state));
Iterator it = m_providedServices[i].getProperties().keySet().iterator();
while (it.hasNext()) {
+ Element prop = new Element("property", "");
String k = (String) it.next();
- info += "\n\t\t Service Property : " + k + " = " + m_providedServices[i].getProperties().getProperty(k);
+ prop.addAttribute(new Attribute("name", k));
+ prop.addAttribute(new Attribute("value", m_providedServices[i].getProperties().getProperty(k).toString()));
+ service.addElement(prop);
}
+ services.addElement(service);
}
- return info;
+ return services;
}
-
-
}
Modified: incubator/felix/trunk/ipojo/src/main/java/org/apache/felix/ipojo/parser/ManifestMetadataParser.java
URL: http://svn.apache.org/viewvc/incubator/felix/trunk/ipojo/src/main/java/org/apache/felix/ipojo/parser/ManifestMetadataParser.java?view=diff&rev=529623&r1=529622&r2=529623
==============================================================================
--- incubator/felix/trunk/ipojo/src/main/java/org/apache/felix/ipojo/parser/ManifestMetadataParser.java (original)
+++ incubator/felix/trunk/ipojo/src/main/java/org/apache/felix/ipojo/parser/ManifestMetadataParser.java Tue Apr 17 07:31:35 2007
@@ -25,8 +25,8 @@
import org.apache.felix.ipojo.metadata.Element;
/**
- * Manifest Metadata parser.
- * Read a manifest file and construct metadata
+ * Manifest Metadata parser. Read a manifest file and construct metadata
+ *
* @author <a href="mailto:felix-dev@incubator.apache.org">Felix Project Team</a>
*/
public class ManifestMetadataParser {
@@ -42,6 +42,7 @@
private Element[] m_elements = new Element[0];
/**
+ * Get the array of component type metadata.
* @return the component metadata (composite & component).
* @throws ParseException when a parsing error occurs
*/
@@ -51,17 +52,18 @@
Element[] all = new Element[components.length + composites.length];
int l = 0;
for (int i = 0; i < components.length; i++) {
- all[l] = components[i];
- l++;
+ all[l] = components[i];
+ l++;
}
for (int i = 0; i < composites.length; i++) {
- all[l] = composites[i];
- l++;
+ all[l] = composites[i];
+ l++;
}
return all;
}
/**
+ * Get the array of instance configuration described in the metadata.
* @return the instances list.
* @throws ParseException : if the metadata cannot be parsed successfully
*/
@@ -73,53 +75,64 @@
}
return dicts;
}
-
+
/**
* Parse an Element to get a dictionary.
+ *
* @param instance : the Element describing an instance.
* @return : the resulting dictionary
- * @throws ParseException
+ * @throws ParseException : occurs when a configuration cannot be parse correctly.
*/
private Dictionary parseInstance(Element instance) throws ParseException {
- Dictionary dict = new Properties();
- if (!instance.containsAttribute("name")) { throw new ParseException("An instance does not have the 'name' attribute"); }
- if (!instance.containsAttribute("component")) { throw new ParseException("An instance does not have the 'component' attribute"); }
- dict.put("name", instance.getAttribute("name"));
- dict.put("component", instance.getAttribute("component"));
-
- for (int i = 0; i < instance.getElements("property").length; i++) {
- parseProperty(instance.getElements("property")[i], dict);
- }
-
- return dict;
- }
-
- /**
- * @param prop
- * @param dict
- * @throws ParseException
+ Dictionary dict = new Properties();
+ if (!instance.containsAttribute("name")) {
+ throw new ParseException("An instance does not have the 'name' attribute");
+ }
+ if (!instance.containsAttribute("component")) {
+ throw new ParseException("An instance does not have the 'component' attribute");
+ }
+ dict.put("name", instance.getAttribute("name"));
+ dict.put("component", instance.getAttribute("component"));
+
+ for (int i = 0; i < instance.getElements("property").length; i++) {
+ parseProperty(instance.getElements("property")[i], dict);
+ }
+
+ return dict;
+ }
+
+ /**
+ * Parse a property.
+ * @param prop : the current element to parse
+ * @param dict : the dictionary to populate
+ * @throws ParseException : occurs if the proeprty cannot be parsed correctly
*/
private void parseProperty(Element prop, Dictionary dict) throws ParseException {
- // Check that the property has a name
- if (!prop.containsAttribute("name")) { throw new ParseException("A property does not have the 'name' attribute"); }
- // Final case : the property element has a 'value' attribute
- if (prop.containsAttribute("value")) {
- dict.put(prop.getAttribute("name"), prop.getAttribute("value"));
- } else {
- // Recursive case
- // Check if there is 'property' element
- Element[] subProps = prop.getElements("property");
- if (subProps.length == 0) { throw new ParseException("A complex property must have at least one 'property' sub-element"); }
- Dictionary dict2 = new Properties();
- for (int i = 0; i < subProps.length; i++) {
- parseProperty(subProps[i], dict2);
- dict.put(prop.getAttribute("name"), dict2);
- }
- }
+ // Check that the property has a name
+ if (!prop.containsAttribute("name")) {
+ throw new ParseException("A property does not have the 'name' attribute");
+ }
+ // Final case : the property element has a 'value' attribute
+ if (prop.containsAttribute("value")) {
+ dict.put(prop.getAttribute("name"), prop.getAttribute("value"));
+ } else {
+ // Recursive case
+ // Check if there is 'property' element
+ Element[] subProps = prop.getElements("property");
+ if (subProps.length == 0) {
+ throw new ParseException("A complex property must have at least one 'property' sub-element");
+ }
+ Dictionary dict2 = new Properties();
+ for (int i = 0; i < subProps.length; i++) {
+ parseProperty(subProps[i], dict2);
+ dict.put(prop.getAttribute("name"), dict2);
+ }
+ }
}
/**
* Add an element to the list.
+ *
* @param elem : the element to add
*/
private void addElement(Element elem) {
@@ -128,11 +141,14 @@
System.arraycopy(m_elements, 0, newElementsList, 0, m_elements.length);
newElementsList[m_elements.length] = elem;
m_elements = newElementsList;
- } else { m_elements = new Element[] {elem}; }
+ } else {
+ m_elements = new Element[] { elem };
+ }
}
/**
* Remove an element to the list.
+ *
* @return an element to remove
*/
private Element removeLastElement() {
@@ -155,32 +171,37 @@
/**
* Parse the given dictionnary and create the instance managers.
+ *
* @param dict : the given headers of the manifest file
* @throws ParseException : if any error occurs
*/
public void parse(Dictionary dict) throws ParseException {
m_headers = dict;
String componentClassesStr = (String) m_headers.get("iPOJO-Components");
- //Add the ipojo element inside the element list
+ // Add the ipojo element inside the element list
addElement(new Element("iPOJO", ""));
parseElements(componentClassesStr.trim());
}
/**
* Parse the metadata from the string given in argument.
+ *
* @param metadata : the metadata to parse
* @return Element : the root element resulting of the parsing
* @throws ParseException : if any error occurs
*/
- public static Element parse(String metadata) throws ParseException {
+ public static Element parse(String metadata) throws ParseException {
ManifestMetadataParser parser = new ManifestMetadataParser();
parser.parseElements(metadata);
- if (parser.m_elements.length != 1) { throw new ParseException("Error in parsing, root element not found : " + metadata); }
+ if (parser.m_elements.length != 1) {
+ throw new ParseException("Error in parsing, root element not found : " + metadata);
+ }
return parser.m_elements[0];
}
/**
* Paser the given string.
+ *
* @param s : the string to parse
*/
private void parseElements(String s) {
@@ -189,9 +210,9 @@
for (int i = 0; i < string.length; i++) {
char c = string[i];
- switch(c) {
- // Beginning of an attribute.
- case '$' :
+ switch (c) {
+ // Beginning of an attribute.
+ case '$':
String attName = "";
String attValue = "";
String attNs = "";
@@ -201,7 +222,9 @@
if (c == ':') {
attNs = attName;
attName = "";
- } else { attName = attName + c; }
+ } else {
+ attName = attName + c;
+ }
i = i + 1;
c = string[i];
}
@@ -216,12 +239,12 @@
i++; // skip "
c = string[i];
- Attribute att = new Attribute(attName, attNs , attValue);
+ Attribute att = new Attribute(attName, attNs, attValue);
m_elements[m_elements.length - 1].addAttribute(att);
break;
- // End of an element
- case '}' :
+ // End of an element
+ case '}':
Element lastElement = removeLastElement();
if (m_elements.length != 0) {
Element newQueue = m_elements[m_elements.length - 1];
@@ -232,33 +255,35 @@
break;
// Space
- case ' ' :
- break; // do nothing;
-
+ case ' ':
+ break; // do nothing;
+
// Default case
- default :
+ default:
String name = "";
- String ns = "";
- c = string[i];
- while (c != ' ') {
- if (c == ':') {
- ns = name;
- name = "";
- i++;
- c = string[i];
- } else {
- name = name + c;
- i++;
- c = string[i];
- }
- }
- // Skip spaces
- while (string[i] == ' ') { i = i + 1; }
- i = i + 1; // skip {
- Element elem = new Element(name, ns);
- addElement(elem);
- break;
- }
+ String ns = "";
+ c = string[i];
+ while (c != ' ') {
+ if (c == ':') {
+ ns = name;
+ name = "";
+ i++;
+ c = string[i];
+ } else {
+ name = name + c;
+ i++;
+ c = string[i];
+ }
+ }
+ // Skip spaces
+ while (string[i] == ' ') {
+ i = i + 1;
+ }
+ i = i + 1; // skip {
+ Element elem = new Element(name, ns);
+ addElement(elem);
+ break;
+ }
}
}