Invalidate instance instead of stopping them after InvocationTargetException (which allow to restart automatically after an external event)
Add a better error message when an invocation target exception occurs.
Fix bundle names to follow the same pattern
Fix a bug when a property have a method but no String default value.
git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@590028 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/ipojo/ant/pom.xml b/ipojo/ant/pom.xml
index 4f376ca..333c39f 100644
--- a/ipojo/ant/pom.xml
+++ b/ipojo/ant/pom.xml
@@ -43,7 +43,7 @@
<extensions>true</extensions>
<configuration>
<instructions>
- <Bundle-Name>Apache Felix iPOJO Ant Task</Bundle-Name>
+ <Bundle-Name>iPOJO Ant Task</Bundle-Name>
<Bundle-Vendor>Clement ESCOFFIER</Bundle-Vendor>
<Bundle-Description> iPOJO Ant Task </Bundle-Description>
<Private-Package>org.apache.felix.ipojo.metadata, org.apache.felix.ipojo.manipulator, org.apache.felix.ipojo.xml.parser, org.apache.felix.ipojo.manipulation*, org.objectweb.asm;-split-package:=merge-first, org.objectweb.asm.commons;-split-package:=merge-first, org.apache.xerces.parsers, org.apache.xerces.xni*, org.apache.xerces.impl*, org.apache.xerces.util.*</Private-Package>
diff --git a/ipojo/arch/pom.xml b/ipojo/arch/pom.xml
index b113c3c..7c791a4 100644
--- a/ipojo/arch/pom.xml
+++ b/ipojo/arch/pom.xml
@@ -36,6 +36,7 @@
<extensions>true</extensions>
<configuration>
<instructions>
+ <Bundle-Name>iPOJO Arch Command</Bundle-Name>
<Bundle-SymbolicName>${pom.artifactId}</Bundle-SymbolicName>
<Private-Package>org.apache.felix.ipojo.arch</Private-Package>
</instructions>
diff --git a/ipojo/core/src/main/java/org/apache/felix/ipojo/InstanceManager.java b/ipojo/core/src/main/java/org/apache/felix/ipojo/InstanceManager.java
index 03bfa83..febf36e 100644
--- a/ipojo/core/src/main/java/org/apache/felix/ipojo/InstanceManager.java
+++ b/ipojo/core/src/main/java/org/apache/felix/ipojo/InstanceManager.java
@@ -504,7 +504,7 @@
m_factory.getLogger().log(Logger.ERROR, "[" + m_name + "] createInstance -> The Component Instance is not accessible (security reason) : " + e.getMessage());
stop();
} catch (InvocationTargetException e) {
- m_factory.getLogger().log(Logger.ERROR, "[" + m_name + "] createInstance -> Cannot invoke the constructor method (illegal target) : " + e.getMessage());
+ m_factory.getLogger().log(Logger.ERROR, "[" + m_name + "] createInstance -> Cannot invoke the constructor method (illegal target) : " + e.getTargetException().getMessage());
e.printStackTrace();
stop();
} catch (NoSuchMethodException e) {
@@ -786,6 +786,15 @@
for (int i = 0; i < m_handlers.length; i++) {
m_handlers[i].getHandler().reconfigure(configuration);
}
+ if (m_state == INVALID) {
+ // Try to revalidate the instance ofter reconfiguration
+ for (int i = 0; i < m_handlers.length; i++) {
+ if (m_handlers[i].getState() != VALID) {
+ return;
+ }
+ }
+ setState(VALID);
+ }
}
/**
diff --git a/ipojo/core/src/main/java/org/apache/felix/ipojo/handlers/configuration/ConfigurableProperty.java b/ipojo/core/src/main/java/org/apache/felix/ipojo/handlers/configuration/ConfigurableProperty.java
index 56882c4..1ce6c98 100644
--- a/ipojo/core/src/main/java/org/apache/felix/ipojo/handlers/configuration/ConfigurableProperty.java
+++ b/ipojo/core/src/main/java/org/apache/felix/ipojo/handlers/configuration/ConfigurableProperty.java
@@ -22,6 +22,7 @@
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
+import org.apache.felix.ipojo.ComponentInstance;
import org.apache.felix.ipojo.ConfigurationException;
import org.apache.felix.ipojo.parser.ParseUtils;
import org.apache.felix.ipojo.util.Callback;
@@ -94,6 +95,8 @@
if (value != null) {
setValue(value, type);
+ } else {
+ setType(type);
}
if (method != null) {
@@ -101,12 +104,123 @@
}
}
+
+ /**
+ * The set type method fix the property type according to the given type name.
+ * @param type : the type name
+ * @throws ConfigurationException if an error occurs when loading the type class for non-primitive types.
+ */
+ private void setType(String type) throws ConfigurationException {
+ // Syntactic sugar to avoid writing java.lang.String
+ if ("string".equals(type) || "String".equals(type)) {
+ m_type = java.lang.String.class;
+ return;
+ }
+ if (type.equals("boolean")) {
+ m_type = Boolean.TYPE;
+ return;
+ }
+ if ("byte".equals(type)) {
+ m_type = Byte.TYPE;
+ return;
+ }
+ if ("short".equals(type)) {
+ m_type = Short.TYPE;
+ return;
+ }
+ if ("int".equals(type)) {
+ m_type = Integer.TYPE;
+ return;
+ }
+ if ("long".equals(type)) {
+ m_type = Long.TYPE;
+ return;
+ }
+ if ("float".equals(type)) {
+ m_type = Float.TYPE;
+ return;
+ }
+ if ("double".equals(type)) {
+ m_type = Double.TYPE;
+ return;
+ }
+ if ("char".equals(type)) {
+ m_type = Character.TYPE;
+ return;
+ }
+
+ // Array :
+ if (type.endsWith("[]")) {
+ String internalType = type.substring(0, type.length() - 2);
+ if ("string".equals(internalType) || "String".equals(internalType)) {
+ m_type = new String[0].getClass();
+ return;
+ }
+ if ("boolean".equals(internalType)) {
+ m_type = new boolean[0].getClass();
+ return;
+ }
+ if ("byte".equals(internalType)) {
+ m_type = new byte[0].getClass();
+ return;
+ }
+ if ("short".equals(internalType)) {
+ m_type = new short[0].getClass();
+ return;
+ }
+ if ("int".equals(internalType)) {
+ m_type = new int[0].getClass();
+ return;
+ }
+ if ("long".equals(internalType)) {
+ m_type = new long[0].getClass();
+ return;
+ }
+ if ("float".equals(internalType)) {
+ m_type = new float[0].getClass();
+ return;
+ }
+ if ("double".equals(internalType)) {
+ m_type = new double[0].getClass();
+ return;
+ }
+ if ("char".equals(internalType)) {
+ m_type = new char[0].getClass();
+ return;
+ }
+
+ // Complex array type.
+ try {
+ Class c = m_handler.getInstanceManager().getContext().getBundle().loadClass(internalType);
+ Object[] ob = (Object[]) Array.newInstance(c, 0);
+ m_type = ob.getClass();
+ return;
+ } catch (ClassNotFoundException e) {
+ throw new ConfigurationException("Class not found exception in setValue on " + internalType);
+ } catch (SecurityException e) {
+ throw new ConfigurationException("Secutiry Exception in setValue on " + internalType);
+ } catch (IllegalArgumentException e) {
+ throw new ConfigurationException("Argument problem to call the constructor of the type " + internalType);
+ }
+ }
+
+ // Non array, complex type.
+ try {
+ m_type = m_handler.getInstanceManager().getContext().getBundle().loadClass(type);
+ } catch (ClassNotFoundException e) {
+ throw new ConfigurationException("Class not found exception in setValue on " + type + " : " + e.getMessage());
+ } catch (SecurityException e) {
+ throw new ConfigurationException("Security excption in setValue on " + type + " : " + e.getMessage());
+ } catch (IllegalArgumentException e) {
+ throw new ConfigurationException("Argument problem to call the constructor of the type " + type);
+ }
+ }
/**
* Set the value of the property.
* @param strValue : value of the property (String)
* @param type : type of the property
- * @throws ConfigurationException : occurs when the property value cannot be initialized.
+ * @throws ConfigurationException : occurs when the property value cannot be initialized.
*/
private void setValue(String strValue, String type) throws ConfigurationException {
Object value = null;
@@ -176,7 +290,7 @@
} catch (IllegalAccessException e) {
throw new ConfigurationException("Illegal Access " + type);
} catch (InvocationTargetException e) {
- throw new ConfigurationException("Invocation problem " + type);
+ throw new ConfigurationException("Invocation problem " + type + " : " + e.getTargetException().getMessage());
}
}
@@ -299,7 +413,7 @@
} catch (IllegalAccessException e) {
throw new ConfigurationException("Illegal Access Exception in " + internalType);
} catch (InvocationTargetException e) {
- throw new ConfigurationException("Invocation problem " + internalType);
+ throw new ConfigurationException("Invocation problem " + internalType + " : " + e.getTargetException().getMessage());
}
}
@@ -342,7 +456,6 @@
/**
* Fix the value of the property.
- *
* @param value : the new value.
*/
public void setValue(Object value) {
@@ -363,8 +476,8 @@
m_handler.log(Logger.ERROR, "The method " + m_method + " is not accessible in the class " + m_handler.getInstanceManager().getClassName());
m_handler.getInstanceManager().stop();
} catch (InvocationTargetException e) {
- m_handler.log(Logger.ERROR, "The method " + m_method + " in the class " + m_handler.getInstanceManager().getClassName() + "thorws an exception : " + e.getMessage());
- m_handler.getInstanceManager().stop();
+ m_handler.log(Logger.ERROR, "The method " + m_method + " in the class " + m_handler.getInstanceManager().getClassName() + "throws an exception : " + e.getTargetException().getMessage());
+ m_handler.getInstanceManager().setState(ComponentInstance.INVALID);
}
}
@@ -384,8 +497,8 @@
m_handler.getInstanceManager().getFactory().getLogger().log(Logger.ERROR, "The method " + m_method + " is not accessible in the class " + m_handler.getInstanceManager().getClassName());
m_handler.getInstanceManager().stop();
} catch (InvocationTargetException e) {
- m_handler.getInstanceManager().getFactory().getLogger().log(Logger.ERROR, "The method " + m_method + " in the class " + m_handler.getInstanceManager().getClassName() + "throws an exception : " + e.getMessage());
- m_handler.getInstanceManager().stop();
+ m_handler.getInstanceManager().getFactory().getLogger().log(Logger.ERROR, "The method " + m_method + " in the class " + m_handler.getInstanceManager().getClassName() + "throws an exception : " + e.getTargetException().getMessage());
+ m_handler.getInstanceManager().setState(ComponentInstance.INVALID);
}
}
}
diff --git a/ipojo/core/src/main/java/org/apache/felix/ipojo/handlers/dependency/Dependency.java b/ipojo/core/src/main/java/org/apache/felix/ipojo/handlers/dependency/Dependency.java
index 6b343d9..3acc54f 100644
--- a/ipojo/core/src/main/java/org/apache/felix/ipojo/handlers/dependency/Dependency.java
+++ b/ipojo/core/src/main/java/org/apache/felix/ipojo/handlers/dependency/Dependency.java
@@ -24,6 +24,7 @@
import java.util.Collections;
import java.util.List;
+import org.apache.felix.ipojo.ComponentInstance;
import org.apache.felix.ipojo.IPojoContext;
import org.apache.felix.ipojo.InstanceManager;
import org.apache.felix.ipojo.PolicyServiceContext;
@@ -359,7 +360,7 @@
m_handler.log(Logger.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.log(Logger.ERROR, "The method " + m_callbacks[i].getMethodName() + " in the class " + m_handler.getInstanceManager().getClassName() + "throws an exception : " + e.getMessage());
+ m_handler.log(Logger.ERROR, "The method " + m_callbacks[i].getMethodName() + " in the class " + m_handler.getInstanceManager().getClassName() + "throws an exception : " + e.getTargetException().getMessage());
m_handler.getInstanceManager().stop();
}
}
@@ -410,8 +411,8 @@
m_handler.log(Logger.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.log(Logger.ERROR, "The method " + m_callbacks[j].getMethodName() + " in the class " + m_handler.getInstanceManager().getClassName() + "thorws an exception : " + e.getMessage());
- m_handler.getInstanceManager().stop();
+ m_handler.log(Logger.ERROR, "The method " + m_callbacks[j].getMethodName() + " in the class " + m_handler.getInstanceManager().getClassName() + "throws an exception : " + e.getTargetException().getMessage());
+ m_handler.getInstanceManager().setState(ComponentInstance.INVALID);
}
}
}
@@ -431,8 +432,8 @@
m_handler.log(Logger.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.log(Logger.ERROR, "The method " + m_callbacks[j].getMethodName() + " in the class " + m_handler.getInstanceManager().getClassName() + "throws an exception : " + e.getMessage());
- m_handler.getInstanceManager().stop();
+ m_handler.log(Logger.ERROR, "The method " + m_callbacks[j].getMethodName() + " in the class " + m_handler.getInstanceManager().getClassName() + "throws an exception : " + e.getTargetException().getMessage());
+ m_handler.getInstanceManager().setState(ComponentInstance.INVALID);
}
}
}
@@ -459,8 +460,8 @@
m_handler.log(Logger.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.log(Logger.ERROR, "The method " + m_callbacks[i].getMethodName() + " in the class " + m_handler.getInstanceManager().getClassName() + "throws an exception : " + e.getMessage());
- m_handler.getInstanceManager().stop();
+ m_handler.log(Logger.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);
}
}
}
@@ -594,7 +595,7 @@
* @see org.osgi.util.tracker.ServiceTrackerCustomizer#addingService(org.osgi.framework.ServiceReference)
*/
public boolean addingService(ServiceReference ref) {
- if (! m_activated && m_filter.match(ref)) {
+ if (! m_activated) {
return true;
}
return false;
diff --git a/ipojo/core/src/main/java/org/apache/felix/ipojo/handlers/dependency/DependencyCallback.java b/ipojo/core/src/main/java/org/apache/felix/ipojo/handlers/dependency/DependencyCallback.java
index d354456..cb47c30 100644
--- a/ipojo/core/src/main/java/org/apache/felix/ipojo/handlers/dependency/DependencyCallback.java
+++ b/ipojo/core/src/main/java/org/apache/felix/ipojo/handlers/dependency/DependencyCallback.java
@@ -214,7 +214,6 @@
* @throws NoSuchMethodException : the method is not found
* @throws IllegalAccessException : the method could not be called
* @throws InvocationTargetException : an error happens in the called method
- * @throws InvocationTargetException
*/
protected void callOnInstance(Object instance, ServiceReference ref, Object obj) throws NoSuchMethodException, IllegalAccessException, InvocationTargetException {
if (m_methodObj == null) {
diff --git a/ipojo/core/src/main/java/org/apache/felix/ipojo/handlers/dependency/DependencyHandler.java b/ipojo/core/src/main/java/org/apache/felix/ipojo/handlers/dependency/DependencyHandler.java
index 275f265..130f17c 100644
--- a/ipojo/core/src/main/java/org/apache/felix/ipojo/handlers/dependency/DependencyHandler.java
+++ b/ipojo/core/src/main/java/org/apache/felix/ipojo/handlers/dependency/DependencyHandler.java
@@ -330,10 +330,10 @@
m_nullableObjects.put(dep, o);
} catch (InstantiationException e) {
log(Logger.ERROR, "The nullable object for " + dep.getSpecification() + " cannot be instantiate : " + e.getMessage());
- getInstanceManager().stop();
+ getInstanceManager().setState(ComponentInstance.INVALID);
} catch (IllegalAccessException e) {
log(Logger.ERROR, "The nullable object for " + dep.getSpecification() + " cannot be instantiate : " + e.getMessage());
- getInstanceManager().stop();
+ getInstanceManager().setState(ComponentInstance.INVALID);
}
}
@@ -354,14 +354,14 @@
} catch (ClassNotFoundException e) {
// A default-implementation class cannot be loaded
log(Logger.ERROR, "The default-implementation class " + obj + " cannot be loaded : " + e.getMessage());
- getInstanceManager().stop();
+ getInstanceManager().setState(ComponentInstance.INVALID);
return null;
} catch (InstantiationException e) {
log(Logger.ERROR, "The default-implementation class " + obj + " cannot be instantiated : " + e.getMessage());
- getInstanceManager().stop();
+ getInstanceManager().setState(ComponentInstance.INVALID);
} catch (IllegalAccessException e) {
log(Logger.ERROR, "The default-implementation class " + obj + " cannot be instantiated : " + e.getMessage());
- getInstanceManager().stop();
+ getInstanceManager().setState(ComponentInstance.INVALID);
}
return null;
} else {
diff --git a/ipojo/core/src/main/java/org/apache/felix/ipojo/handlers/lifecycle/callback/LifecycleCallbackHandler.java b/ipojo/core/src/main/java/org/apache/felix/ipojo/handlers/lifecycle/callback/LifecycleCallbackHandler.java
index 7214d83..ebb9497 100644
--- a/ipojo/core/src/main/java/org/apache/felix/ipojo/handlers/lifecycle/callback/LifecycleCallbackHandler.java
+++ b/ipojo/core/src/main/java/org/apache/felix/ipojo/handlers/lifecycle/callback/LifecycleCallbackHandler.java
@@ -168,8 +168,8 @@
log(Logger.ERROR, "[" + getInstanceManager().getInstanceName() + "] The callback method " + m_callbacks[i].getMethod() + " is not accessible", e);
getInstanceManager().stop();
} catch (InvocationTargetException e) {
- log(Logger.ERROR, "[" + getInstanceManager().getInstanceName() + "] The callback method " + m_callbacks[i].getMethod() + " has throws an exception : " + e.getMessage());
- getInstanceManager().stop();
+ log(Logger.ERROR, "[" + getInstanceManager().getInstanceName() + "] The callback method " + m_callbacks[i].getMethod() + " has throws an exception : " + e.getTargetException().getMessage());
+ getInstanceManager().setState(ComponentInstance.INVALID);
}
}
}
diff --git a/ipojo/core/src/main/java/org/apache/felix/ipojo/handlers/providedservice/Property.java b/ipojo/core/src/main/java/org/apache/felix/ipojo/handlers/providedservice/Property.java
index c54e47f..20488bb 100644
--- a/ipojo/core/src/main/java/org/apache/felix/ipojo/handlers/providedservice/Property.java
+++ b/ipojo/core/src/main/java/org/apache/felix/ipojo/handlers/providedservice/Property.java
@@ -22,6 +22,7 @@
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
+import org.apache.felix.ipojo.ComponentInstance;
import org.apache.felix.ipojo.parser.ParseUtils;
import org.apache.felix.ipojo.util.Logger;
@@ -218,8 +219,8 @@
m_providedService.getInstanceManager().getFactory().getLogger().log(Logger.ERROR, "Illegal Access Exception in setValue on " + m_type);
m_providedService.getInstanceManager().stop();
} catch (InvocationTargetException e) {
- m_providedService.getInstanceManager().getFactory().getLogger().log(Logger.ERROR, "Invocation problem " + m_type);
- m_providedService.getInstanceManager().stop();
+ m_providedService.getInstanceManager().getFactory().getLogger().log(Logger.ERROR, "Invocation problem " + m_type + " : " + e.getTargetException().getMessage());
+ m_providedService.getInstanceManager().setState(ComponentInstance.INVALID);
}
}
@@ -321,8 +322,8 @@
m_providedService.getInstanceManager().getFactory().getLogger().log(Logger.ERROR, "Illegal Access Exception in setArrayValue on " + internalType);
m_providedService.getInstanceManager().stop();
} catch (InvocationTargetException e) {
- m_providedService.getInstanceManager().getFactory().getLogger().log(Logger.ERROR, "Invocation problem " + internalType);
- m_providedService.getInstanceManager().stop();
+ m_providedService.getInstanceManager().getFactory().getLogger().log(Logger.ERROR, "Invocation problem " + internalType + " : " + e.getTargetException().getMessage());
+ m_providedService.getInstanceManager().setState(ComponentInstance.INVALID);
}
}
diff --git a/ipojo/plugin/pom.xml b/ipojo/plugin/pom.xml
index 8e65fe2..a861d01 100644
--- a/ipojo/plugin/pom.xml
+++ b/ipojo/plugin/pom.xml
@@ -6,7 +6,6 @@
<relativePath>../../pom/pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
- <!-- <artifactId>org.apache.felix.ipojo.plugin</artifactId> -->
<artifactId>maven-ipojo-plugin</artifactId>
<version>0.7.5-SNAPSHOT</version>
<name>Apache Felix iPOJO Maven Plugin</name>
@@ -40,7 +39,7 @@
<dependency>
<groupId>${pom.groupId}</groupId>
<artifactId>org.apache.felix.ipojo.metadata</artifactId>
- <version>${pom.version}</version>
+ <version>0.7.5-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>${pom.groupId}</groupId>
diff --git a/ipojo/plugin/src/main/resources/archetype-resources/pom.xml b/ipojo/plugin/src/main/resources/archetype-resources/pom.xml
index 4f9683c..94e900f 100644
--- a/ipojo/plugin/src/main/resources/archetype-resources/pom.xml
+++ b/ipojo/plugin/src/main/resources/archetype-resources/pom.xml
@@ -6,6 +6,22 @@
<version>${version}</version>
<name>$YOUR_PROJECT_NAME</name>
+ <pluginRepositories>
+ <pluginRepository>
+ <id>apache.snapshots</id>
+ <name>snapshot plugins</name>
+ <url>
+ http://people.apache.org/repo/m2-snapshot-repository
+ </url>
+ <releases>
+ <enabled>false</enabled>
+ </releases>
+ <snapshots>
+ <enabled>true</enabled>
+ </snapshots>
+ </pluginRepository>
+ </pluginRepositories>
+
<build>
<plugins>
<plugin>