Author: jboynes
Date: Fri Mar 24 17:28:26 2006
New Revision: 388686
URL: http://svn.apache.org/viewcvs?rev=388686&view=rev
Log:
fix for TUSCANY-6 making names in ResourceLoader match ClassLoader
Added:
incubator/tuscany/java/sca/common/src/main/java/org/apache/tuscany/common/resource/impl/GeneratedClassLoader.java
(with props)
Modified:
incubator/tuscany/java/sca/common/src/main/java/org/apache/tuscany/common/resource/ResourceLoader.java
incubator/tuscany/java/sca/common/src/main/java/org/apache/tuscany/common/resource/impl/ResourceLoaderImpl.java
incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/config/impl/AbstractModuleComponentConfigurationLoader.java
Modified:
incubator/tuscany/java/sca/common/src/main/java/org/apache/tuscany/common/resource/ResourceLoader.java
URL:
http://svn.apache.org/viewcvs/incubator/tuscany/java/sca/common/src/main/java/org/apache/tuscany/common/resource/ResourceLoader.java?rev=388686&r1=388685&r2=388686&view=diff
==============================================================================
---
incubator/tuscany/java/sca/common/src/main/java/org/apache/tuscany/common/resource/ResourceLoader.java
(original)
+++
incubator/tuscany/java/sca/common/src/main/java/org/apache/tuscany/common/resource/ResourceLoader.java
Fri Mar 24 17:28:26 2006
@@ -50,11 +50,12 @@
/**
* Converts an array of bytes into a Class.
- * @param bytes
- * @return
+ *
+ * @param bytes the bytecode for the class; must match the class file
format
+ * @return a Class defined from the supplied bytecode
*/
Class<?> addClass(byte[] bytes);
-
+
/**
* Finds the first resource with the given name.
* <p/>
@@ -69,8 +70,8 @@
URL getResource(String name) throws IOException;
/**
- * Find resources with the given name that are available directly from this
- * ResourceLoader. Resources from parent ResourceLoaders are not returned.
+ * Find resources with the given name that are available from this
+ * ResourceLoader or any of its parents.
*
* @param name the resource name
* @return an Iterator of [EMAIL PROTECTED] URL} objects for the resource
@@ -78,17 +79,13 @@
*/
Iterator<URL> getResources(String name) throws IOException;
+ //FIXME this is temporary to work around classloader problems with SDO
when running in Tomcat
+
/**
- * Find resources with the given name that are available from this
- * ResourceLoader or any of its parents.
+ * Returns the underlying classloader this loader is wrapping.
*
- * @param name the resource name
- * @return an Iterator of [EMAIL PROTECTED] URL} objects for the resource
- * @throws IOException if there was a problem locating the resources
+ * @return the underlying classloader this loader is wrapping
*/
- Iterator<URL> getAllResources(String name) throws IOException;
-
- //FIXME this is temporary to work around classloader problems with SDO
when running in Tomcat
ClassLoader getClassLoader();
-
+
}
Added:
incubator/tuscany/java/sca/common/src/main/java/org/apache/tuscany/common/resource/impl/GeneratedClassLoader.java
URL:
http://svn.apache.org/viewcvs/incubator/tuscany/java/sca/common/src/main/java/org/apache/tuscany/common/resource/impl/GeneratedClassLoader.java?rev=388686&view=auto
==============================================================================
---
incubator/tuscany/java/sca/common/src/main/java/org/apache/tuscany/common/resource/impl/GeneratedClassLoader.java
(added)
+++
incubator/tuscany/java/sca/common/src/main/java/org/apache/tuscany/common/resource/impl/GeneratedClassLoader.java
Fri Mar 24 17:28:26 2006
@@ -0,0 +1,45 @@
+/**
+ *
+ * Copyright 2006 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.tuscany.common.resource.impl;
+
+/**
+ * A class loader that allows new classes to be defined from an array of bytes.
+ *
+ * @version $Rev: 369102 $ $Date: 2006-01-14 13:48:56 -0800 (Sat, 14 Jan 2006)
$
+ */
[EMAIL PROTECTED]({"CustomClassloader"})
+class GeneratedClassLoader extends ClassLoader {
+
+ /**
+ * Constructs a new GeneratedClassLoader.
+ * @param classLoader the parent classloader
+ */
+ GeneratedClassLoader(ClassLoader classLoader) {
+ super(classLoader);
+ }
+
+ /**
+ * Converts an array of bytes into a Class.
+ *
+ * @param bytes the bytecode for the class; must match the class file
format
+ * @return a Class defined from the supplied bytecode
+ */
+ Class<?> addClass(byte[] bytes) {
+ return defineClass(null, bytes, 0, bytes.length);
+ }
+
+}
Propchange:
incubator/tuscany/java/sca/common/src/main/java/org/apache/tuscany/common/resource/impl/GeneratedClassLoader.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
incubator/tuscany/java/sca/common/src/main/java/org/apache/tuscany/common/resource/impl/GeneratedClassLoader.java
------------------------------------------------------------------------------
svn:keywords = Rev,Date
Modified:
incubator/tuscany/java/sca/common/src/main/java/org/apache/tuscany/common/resource/impl/ResourceLoaderImpl.java
URL:
http://svn.apache.org/viewcvs/incubator/tuscany/java/sca/common/src/main/java/org/apache/tuscany/common/resource/impl/ResourceLoaderImpl.java?rev=388686&r1=388685&r2=388686&view=diff
==============================================================================
---
incubator/tuscany/java/sca/common/src/main/java/org/apache/tuscany/common/resource/impl/ResourceLoaderImpl.java
(original)
+++
incubator/tuscany/java/sca/common/src/main/java/org/apache/tuscany/common/resource/impl/ResourceLoaderImpl.java
Fri Mar 24 17:28:26 2006
@@ -21,10 +21,9 @@
import java.net.URL;
import java.util.Collections;
import java.util.Enumeration;
-import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
-import java.util.Set;
+import java.util.NoSuchElementException;
import org.apache.tuscany.common.resource.ResourceLoader;
@@ -33,37 +32,16 @@
*
* @version $Rev: 369102 $ $Date: 2006-01-14 13:48:56 -0800 (Sat, 14 Jan 2006)
$
*/
[EMAIL PROTECTED]({"ClassLoader2Instantiation"})
public class ResourceLoaderImpl implements ResourceLoader {
private final WeakReference<ClassLoader> classLoaderReference;
private WeakReference<GeneratedClassLoader> generatedClassLoaderReference;
private final List<ResourceLoader> parents;
/**
- * A class loader that allows new classes to be defined from an array of
bytes
- */
- private class GeneratedClassLoader extends ClassLoader {
-
- /**
- * Constructs a new ResourceLoaderImpl.GeneratedClassLoader.
- */
- public GeneratedClassLoader(ClassLoader classLoader) {
- super(classLoader);
- }
-
- /**
- * Converts an array of bytes into a Class.
- * @param bytes
- * @return
- */
- private Class<?> addClass(byte[] bytes) {
- return defineClass(null, bytes, 0, bytes.length);
- }
-
- }
-
- /**
- * Constructs a new ResourceLoaderImpl.
- * @param classLoader
+ * Constructs a new ResourceLoaderImpl to wrap a ClassLoader.
+ *
+ * @param classLoader the classloader to wrap
*/
public ResourceLoaderImpl(ClassLoader classLoader) {
classLoaderReference = new WeakReference<ClassLoader>(classLoader);
@@ -72,18 +50,11 @@
if (null == parentCL) {
parents = Collections.emptyList();
} else {
- parents = Collections.singletonList((ResourceLoader)new
ResourceLoaderImpl(parentCL));
+ parents = Collections.singletonList((ResourceLoader) new
ResourceLoaderImpl(parentCL));
}
}
- /**
- * Return the classloader backing this resource loader.
- *
- * @return the classloader that backs this resource loader
- * @throws IllegalStateException if the classloader has been garbage
collected
- */
- //FIXME Temporary used to set the classloader on the thread context, need
to changed to private
public ClassLoader getClassLoader() throws IllegalStateException {
ClassLoader cl = classLoaderReference.get();
if (cl == null) {
@@ -104,37 +75,17 @@
return Class.forName(name, true, getClassLoader());
}
}
-
+
public Class<?> addClass(byte[] bytes) {
GeneratedClassLoader cl = generatedClassLoaderReference.get();
if (cl == null) {
- cl=new GeneratedClassLoader(getClassLoader());
+ cl = new GeneratedClassLoader(getClassLoader());
generatedClassLoaderReference = new
WeakReference<GeneratedClassLoader>(cl);
}
return cl.addClass(bytes);
}
public Iterator<URL> getResources(String name) throws IOException {
- // This implementation used to cache but users are not likely
- // to ask for the same resource multiple times.
-
- // Create a new set, add all the resources visible from the current
ClassLoader
- Set<URL> set = new HashSet<URL>();
- ClassLoader classLoader = getClassLoader();
- for (Enumeration<URL> e = classLoader.getResources(name);
e.hasMoreElements();) {
- set.add(e.nextElement());
- }
-
- // Remove the resources visible from the parent ClassLoaders
- for (ResourceLoader parent : getParents()) {
- for (Iterator<URL> i = parent.getAllResources(name); i.hasNext();)
{
- set.remove(i.next());
- }
- }
- return set.iterator();
- }
-
- public Iterator<URL> getAllResources(String name) throws IOException {
return new
EnumerationIterator<URL>(getClassLoader().getResources(name));
}
@@ -169,7 +120,14 @@
}
public E next() {
- return e.nextElement();
+ // the try/catch is needed here to get IDEA to shut up
+ // there should be no performance overhead here except when the
Exception is thrown
+ // so I am going to leave it in - feel free to remove if there is
any issue
+ try {
+ return e.nextElement();
+ } catch (NoSuchElementException e1) {
+ throw e1;
+ }
}
public void remove() {
Modified:
incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/config/impl/AbstractModuleComponentConfigurationLoader.java
URL:
http://svn.apache.org/viewcvs/incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/config/impl/AbstractModuleComponentConfigurationLoader.java?rev=388686&r1=388685&r2=388686&view=diff
==============================================================================
---
incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/config/impl/AbstractModuleComponentConfigurationLoader.java
(original)
+++
incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/config/impl/AbstractModuleComponentConfigurationLoader.java
Fri Mar 24 17:28:26 2006
@@ -77,7 +77,7 @@
// Load the sca.fragment files
Iterator<URL> i;
try {
- i = resourceLoader.getAllResources(fragmentFileName);
+ i = resourceLoader.getResources(fragmentFileName);
} catch (IOException e) {
throw new ConfigurationLoadException(fragmentFileName, e);
}