diff options
Diffstat (limited to 'tags/java-M1-20060518/java/sca/common/src/main/java/org/apache/tuscany/common/resource')
3 files changed, 0 insertions, 272 deletions
diff --git a/tags/java-M1-20060518/java/sca/common/src/main/java/org/apache/tuscany/common/resource/ResourceLoader.java b/tags/java-M1-20060518/java/sca/common/src/main/java/org/apache/tuscany/common/resource/ResourceLoader.java deleted file mode 100644 index 897c5e06c0..0000000000 --- a/tags/java-M1-20060518/java/sca/common/src/main/java/org/apache/tuscany/common/resource/ResourceLoader.java +++ /dev/null @@ -1,90 +0,0 @@ -/** - * - * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. - * - * 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; - -import java.io.IOException; -import java.net.URL; -import java.util.Iterator; -import java.util.List; - -/** - * Interface which abstracts the implementation of something that is able to - * load resources (such as a ClassLoader). All Tuscany code should use this - * API rather than a ClassLoader directly in order to reduce the risk of - * memory leaks due to ClassLoader references. - * - * @version $Rev: 379878 $ $Date: 2006-02-22 12:45:50 -0800 (Wed, 22 Feb 2006) $ - */ -public interface ResourceLoader { - - /** - * Returns the parent resource loaders. - * - * @return resource loaders that are parents to this one - */ - List<ResourceLoader> getParents(); - - /** - * Loads the class with the specified binary name. - * - * @param name the binary name of the class - * @return the resulting Class object - * @throws ClassNotFoundException if the class was not found - * @see ClassLoader#loadClass(String) - */ - Class<?> loadClass(String name) throws ClassNotFoundException; - - /** - * 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); - - /** - * Finds the first resource with the given name. - * <p/> - * Each parent is searched first (in the order returned by {@link #getParents()}) - * and the first resource located is found. If no parent returns a resource then - * the first resource defined by this ResourceLoader is returned. - * - * @param name the resource name - * @return a {@link URL} that can be used to read the resource, or null if no resource could be found - */ - URL getResource(String name); - - /** - * 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 {@link URL} objects for the resource - * @throws IOException if there was a problem locating the resources - */ - Iterator<URL> getResources(String name) throws IOException; - - //FIXME this is temporary to work around classloader problems with SDO when running in Tomcat - - /** - * Returns the underlying classloader this loader is wrapping. - * - * @return the underlying classloader this loader is wrapping - */ - ClassLoader getClassLoader(); - -} diff --git a/tags/java-M1-20060518/java/sca/common/src/main/java/org/apache/tuscany/common/resource/impl/GeneratedClassLoader.java b/tags/java-M1-20060518/java/sca/common/src/main/java/org/apache/tuscany/common/resource/impl/GeneratedClassLoader.java deleted file mode 100644 index 953908b9f2..0000000000 --- a/tags/java-M1-20060518/java/sca/common/src/main/java/org/apache/tuscany/common/resource/impl/GeneratedClassLoader.java +++ /dev/null @@ -1,45 +0,0 @@ -/** - * - * 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) $ - */ -@SuppressWarnings({"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); - } - -} diff --git a/tags/java-M1-20060518/java/sca/common/src/main/java/org/apache/tuscany/common/resource/impl/ResourceLoaderImpl.java b/tags/java-M1-20060518/java/sca/common/src/main/java/org/apache/tuscany/common/resource/impl/ResourceLoaderImpl.java deleted file mode 100644 index d306edf3b4..0000000000 --- a/tags/java-M1-20060518/java/sca/common/src/main/java/org/apache/tuscany/common/resource/impl/ResourceLoaderImpl.java +++ /dev/null @@ -1,137 +0,0 @@ -/** - * - * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. - * - * 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; - -import java.io.IOException; -import java.lang.ref.WeakReference; -import java.net.URL; -import java.util.Collections; -import java.util.Enumeration; -import java.util.Iterator; -import java.util.List; -import java.util.NoSuchElementException; - -import org.apache.tuscany.common.resource.ResourceLoader; - -/** - * Default implementation of the ResourceLoader interface - * - * @version $Rev: 369102 $ $Date: 2006-01-14 13:48:56 -0800 (Sat, 14 Jan 2006) $ - */ -@SuppressWarnings({"ClassLoader2Instantiation"}) -public class ResourceLoaderImpl implements ResourceLoader { - private final WeakReference<ClassLoader> classLoaderReference; - private WeakReference<GeneratedClassLoader> generatedClassLoaderReference; - private final List<ResourceLoader> parents; - - /** - * Constructs a new ResourceLoaderImpl to wrap a ClassLoader. - * - * @param classLoader the classloader to wrap - */ - public ResourceLoaderImpl(ClassLoader classLoader) { - classLoaderReference = new WeakReference<ClassLoader>(classLoader); - generatedClassLoaderReference = new WeakReference<GeneratedClassLoader>(new GeneratedClassLoader(classLoader)); - ClassLoader parentCL = classLoader.getParent(); - if (null == parentCL) { - parents = Collections.emptyList(); - } else { - parents = Collections.singletonList((ResourceLoader) new ResourceLoaderImpl(parentCL)); - } - } - - - public ClassLoader getClassLoader() throws IllegalStateException { - ClassLoader cl = classLoaderReference.get(); - if (cl == null) { - throw new IllegalStateException("Referenced ClassLoader has been garbage collected"); - } - return cl; - } - - public List<ResourceLoader> getParents() { - return parents; - } - - public Class<?> loadClass(String name) throws ClassNotFoundException { - GeneratedClassLoader cl = generatedClassLoaderReference.get(); - if (cl != null) { - return Class.forName(name, true, cl); - } else { - return Class.forName(name, true, getClassLoader()); - } - } - - public Class<?> addClass(byte[] bytes) { - GeneratedClassLoader cl = generatedClassLoaderReference.get(); - if (cl == null) { - cl = new GeneratedClassLoader(getClassLoader()); - generatedClassLoaderReference = new WeakReference<GeneratedClassLoader>(cl); - } - return cl.addClass(bytes); - } - - public Iterator<URL> getResources(String name) throws IOException { - return new EnumerationIterator<URL>(getClassLoader().getResources(name)); - } - - public URL getResource(String name) { - return getClassLoader().getResource(name); - } - - public boolean equals(Object obj) { - if (obj == this) { - return true; - } - if (!(obj instanceof ResourceLoaderImpl)) { - return false; - } - final ResourceLoaderImpl other = (ResourceLoaderImpl) obj; - return getClassLoader() == other.getClassLoader(); - } - - public int hashCode() { - return getClassLoader().hashCode(); - } - - private static class EnumerationIterator<E> implements Iterator<E> { - private final Enumeration<E> e; - - public EnumerationIterator(Enumeration<E> e) { - this.e = e; - } - - public boolean hasNext() { - return e.hasMoreElements(); - } - - public E next() { - // 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() { - throw new UnsupportedOperationException(); - } - } -} |