Author: clement
Date: Tue Oct 2 06:09:34 2007
New Revision: 581223
URL: http://svn.apache.org/viewvc?rev=581223&view=rev
Log:
Fix a bug if the property has no field.
Modified:
felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/ComponentFactory.java
felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/handlers/configuration/ConfigurationHandler.java
felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/handlers/dependency/DependencyHandler.java
Modified:
felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/ComponentFactory.java
URL:
http://svn.apache.org/viewvc/felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/ComponentFactory.java?rev=581223&r1=581222&r2=581223&view=diff
==============================================================================
---
felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/ComponentFactory.java
(original)
+++
felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/ComponentFactory.java
Tue Oct 2 06:09:34 2007
@@ -19,6 +19,7 @@
package org.apache.felix.ipojo;
import java.net.URL;
+import java.security.ProtectionDomain;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Dictionary;
@@ -112,6 +113,11 @@
* Component Type Name.
*/
protected String m_typeName = null;
+
+ /**
+ * Class loader to delegate loading.
+ */
+ private FactoryClassloader m_classLoader = null;
/**
* Component Implementation class.
@@ -297,6 +303,21 @@
instance.start();
return instance;
}
+
+ /**
+ * Define a class.
+ * @param name : qualified name of the class
+ * @param b : byte array of the class
+ * @param domain : protection domain of the class
+ * @return the defined class object
+ * @throws Exception : an exception occur during the definition
+ */
+ public Class defineClass(String name, byte[] b, ProtectionDomain domain)
throws Exception {
+ if (m_classLoader == null) {
+ m_classLoader = new FactoryClassloader();
+ }
+ return m_classLoader.defineClass(name, b, domain);
+ }
/**
* Delete an instance.
@@ -420,18 +441,17 @@
* @throws ClassNotFoundException : happen when the class is not found
*/
public Class loadClass(String className) throws ClassNotFoundException {
- if (m_clazz != null) {
- // Used the factory classloader to load the component
implementation class
- ClassLoader cl = new ClassLoader() {
- public Class loadClass(String name) throws
ClassNotFoundException {
- if (name.equals(m_componentClassName)) {
- return defineClass(name, m_clazz, 0, m_clazz.length,
null);
- } else {
- return m_context.getBundle().loadClass(name);
- }
- }
- };
- return cl.loadClass(m_componentClassName);
+ if (m_clazz != null && className.equals(m_componentClassName)) {
+ // Used the factory classloader to load the component
implementation
+ // class
+ if (m_classLoader == null) {
+ m_classLoader = new FactoryClassloader();
+ }
+ try {
+ return m_classLoader.defineClass(m_componentClassName,
m_clazz, null);
+ } catch (Exception e) {
+ throw new ClassNotFoundException("[Bundle " +
m_context.getBundle().getBundleId() + "] Cannot define the class : " +
className, e);
+ }
}
return m_context.getBundle().loadClass(className);
}
@@ -566,6 +586,7 @@
m_tracker = null;
m_componentDesc = null;
+ m_classLoader = null;
m_clazz = null;
m_state = INVALID;
}
@@ -985,21 +1006,55 @@
}
}
-// /**
-// * FactoryClassloader.
-// */
-// private class FactoryClassloader extends ClassLoader {
-// /**
-// * The defineClass method.
-// *
-// * @param name : name of the class
-// * @param b : the byte array of the class
-// * @param domain : the protection domain
-// * @return : the defined class.
-// * @throws Exception : if a problem is detected during the loading
-// */
-// public Class defineClass(String name, byte[] b, ProtectionDomain
domain) throws Exception {
-// return super.defineClass(name, b, 0, b.length, domain);
-// }
-// }
+ /**
+ * FactoryClassloader.
+ */
+ private class FactoryClassloader extends ClassLoader {
+
+ /**
+ * Map of defined classes [Name, Class Object].
+ */
+ private Map m_definedClasses = new HashMap();
+
+ /**
+ * The defineClass method.
+ *
+ * @param name : name of the class
+ * @param b : the byte array of the class
+ * @param domain : the protection domain
+ * @return : the defined class.
+ * @throws Exception : if a problem is detected during the loading
+ */
+ public Class defineClass(String name, byte[] b, ProtectionDomain
domain) throws Exception {
+ if (m_definedClasses.containsKey(name)) {
+ return (Class) m_definedClasses.get(name);
+ }
+ final Class c = super.defineClass(name, b, 0, b.length, domain);
+ m_definedClasses.put(name, c);
+ return c;
+ }
+
+ /**
+ * Return the URL of the asked resource.
+ *
+ * @param arg : the name of the resource to find.
+ * @return the URL of the resource.
+ * @see java.lang.ClassLoader#getResource(java.lang.String)
+ */
+ public URL getResource(String arg) {
+ return m_context.getBundle().getResource(arg);
+ }
+
+ /**
+ * Load the class.
+ * @see java.lang.ClassLoader#loadClass(java.lang.String, boolean)
+ * @param name : the name of the class
+ * @param resolve : should be the class resolve now ?
+ * @return : the loaded class
+ * @throws ClassNotFoundException : the class to load is not found
+ */
+ protected Class loadClass(final String name, final boolean resolve)
throws ClassNotFoundException {
+ return m_context.getBundle().loadClass(name);
+ }
+ }
}
Modified:
felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/handlers/configuration/ConfigurationHandler.java
URL:
http://svn.apache.org/viewvc/felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/handlers/configuration/ConfigurationHandler.java?rev=581223&r1=581222&r2=581223&view=diff
==============================================================================
---
felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/handlers/configuration/ConfigurationHandler.java
(original)
+++
felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/handlers/configuration/ConfigurationHandler.java
Tue Oct 2 06:09:34 2007
@@ -337,7 +337,7 @@
public Object getterCallback(String fieldName, Object value) {
// Check if the field is a configurable property
for (int i = 0; i < m_configurableProperties.length; i++) {
- if (m_configurableProperties[i].getField().equals(fieldName)) {
return m_configurableProperties[i].getValue(); }
+ if (m_configurableProperties[i].hasField() &&
m_configurableProperties[i].getField().equals(fieldName)) { return
m_configurableProperties[i].getValue(); }
}
return value;
}
Modified:
felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/handlers/dependency/DependencyHandler.java
URL:
http://svn.apache.org/viewvc/felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/handlers/dependency/DependencyHandler.java?rev=581223&r1=581222&r2=581223&view=diff
==============================================================================
---
felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/handlers/dependency/DependencyHandler.java
(original)
+++
felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/handlers/dependency/DependencyHandler.java
Tue Oct 2 06:09:34 2007
@@ -339,24 +339,15 @@
// dep.getMetadata().getServiceSpecification().split("[.]");
// String className = "org/apache/felix/ipojo/" +
segment[segment.length
// - 1] + "Nullable";
- final String className = dep.getSpecification() + "Nullable";
+ String className = dep.getSpecification() + "Nullable";
String resource = dep.getSpecification().replace('.', '/') + ".class";
URL url =
getInstanceManager().getContext().getBundle().getResource(resource);
try {
- final byte[] b = NullableObjectWriter.dump(url,
dep.getSpecification());
+ byte[] b = NullableObjectWriter.dump(url, dep.getSpecification());
Class c = null;
try {
- ClassLoader cl = new ClassLoader() {
- public Class loadClass(String name) throws
ClassNotFoundException {
- if (name.equals(className)) {
- return defineClass(name, b, 0, b.length, null);
- } else {
- return
getInstanceManager().getContext().getBundle().loadClass(name);
- }
- }
- };
- c = cl.loadClass(className);
+ c = getInstanceManager().getFactory().defineClass(className,
b, null);
} catch (Exception e) {
log(Logger.ERROR, "Cannot define the nullable class : " +
e.getMessage());
e.printStackTrace();