Author: gnodet
Date: Tue Aug 1 08:15:02 2006
New Revision: 427602
URL: http://svn.apache.org/viewvc?rev=427602&view=rev
Log:
XBEAN-22: Support for inverse class loading, exclusions and non overridable classes
Merge from Dain's work on Geronimo classloaders
Added:
geronimo/xbean/trunk/xbean-server/src/main/java/org/apache/xbean/server/classloader/AbstractResourceHandle.java
geronimo/xbean/trunk/xbean-server/src/main/java/org/apache/xbean/server/classloader/AbstractUrlResourceLocation.java
geronimo/xbean/trunk/xbean-server/src/main/java/org/apache/xbean/server/classloader/DirectoryResourceHandle.java
geronimo/xbean/trunk/xbean-server/src/main/java/org/apache/xbean/server/classloader/DirectoryResourceLocation.java
geronimo/xbean/trunk/xbean-server/src/main/java/org/apache/xbean/server/classloader/IoUtil.java
geronimo/xbean/trunk/xbean-server/src/main/java/org/apache/xbean/server/classloader/JarFileUrlConnection.java
geronimo/xbean/trunk/xbean-server/src/main/java/org/apache/xbean/server/classloader/JarFileUrlStreamHandler.java
geronimo/xbean/trunk/xbean-server/src/main/java/org/apache/xbean/server/classloader/JarResourceHandle.java
geronimo/xbean/trunk/xbean-server/src/main/java/org/apache/xbean/server/classloader/JarResourceLocation.java
geronimo/xbean/trunk/xbean-server/src/main/java/org/apache/xbean/server/classloader/ResourceEnumeration.java
geronimo/xbean/trunk/xbean-server/src/main/java/org/apache/xbean/server/classloader/ResourceFinder.java
geronimo/xbean/trunk/xbean-server/src/main/java/org/apache/xbean/server/classloader/ResourceHandle.java
geronimo/xbean/trunk/xbean-server/src/main/java/org/apache/xbean/server/classloader/ResourceLocation.java
geronimo/xbean/trunk/xbean-server/src/main/java/org/apache/xbean/server/classloader/UnionEnumeration.java
geronimo/xbean/trunk/xbean-server/src/main/java/org/apache/xbean/server/classloader/UrlResourceFinder.java
Modified:
geronimo/xbean/trunk/xbean-server/src/main/java/org/apache/xbean/server/classloader/ClassLoaderUtil.java
geronimo/xbean/trunk/xbean-server/src/main/java/org/apache/xbean/server/classloader/JarFileClassLoader.java
geronimo/xbean/trunk/xbean-server/src/main/java/org/apache/xbean/server/classloader/MultiParentClassLoader.java
geronimo/xbean/trunk/xbean-server/src/main/java/org/apache/xbean/server/classloader/NamedClassLoader.java
Added: geronimo/xbean/trunk/xbean-server/src/main/java/org/apache/xbean/server/classloader/AbstractResourceHandle.java
URL: http://svn.apache.org/viewvc/geronimo/xbean/trunk/xbean-server/src/main/java/org/apache/xbean/server/classloader/AbstractResourceHandle.java?rev=427602&view=auto
==============================================================================
--- geronimo/xbean/trunk/xbean-server/src/main/java/org/apache/xbean/server/classloader/AbstractResourceHandle.java (added)
+++ geronimo/xbean/trunk/xbean-server/src/main/java/org/apache/xbean/server/classloader/AbstractResourceHandle.java Tue Aug 1 08:15:02 2006
@@ -0,0 +1,63 @@
+/**
+ *
+ * Copyright 2005 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.xbean.server.classloader;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.security.cert.Certificate;
+import java.util.jar.Attributes;
+import java.util.jar.Manifest;
+
+/**
+ * @version $Rev: 410741 $ $Date: 2006-06-01 06:35:48 +0200 (Thu, 01 Jun 2006) $
+ */
+public abstract class AbstractResourceHandle implements ResourceHandle {
+ public byte[] getBytes() throws IOException {
+ InputStream in = getInputStream();
+ try {
+ byte[] bytes = IoUtil.getBytes(in);
+ return bytes;
+ } finally {
+ IoUtil.close(in);
+ }
+ }
+
+ public Manifest getManifest() throws IOException {
+ return null;
+ }
+
+ public Certificate[] getCertificates() {
+ return null;
+ }
+
+ public Attributes getAttributes() throws IOException {
+ Manifest m = getManifest();
+ if (m == null) {
+ return null;
+ }
+
+ String entry = getUrl().getFile();
+ return m.getAttributes(entry);
+ }
+
+ public void close() {
+ }
+
+ public String toString() {
+ return "[" + getName() + ": " + getUrl() + "; code source: " + getCodeSourceUrl() + "]";
+ }
+}
Added: geronimo/xbean/trunk/xbean-server/src/main/java/org/apache/xbean/server/classloader/AbstractUrlResourceLocation.java
URL: http://svn.apache.org/viewvc/geronimo/xbean/trunk/xbean-server/src/main/java/org/apache/xbean/server/classloader/AbstractUrlResourceLocation.java?rev=427602&view=auto
==============================================================================
--- geronimo/xbean/trunk/xbean-server/src/main/java/org/apache/xbean/server/classloader/AbstractUrlResourceLocation.java (added)
+++ geronimo/xbean/trunk/xbean-server/src/main/java/org/apache/xbean/server/classloader/AbstractUrlResourceLocation.java Tue Aug 1 08:15:02 2006
@@ -0,0 +1,53 @@
+/**
+ *
+ * Copyright 2005 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.xbean.server.classloader;
+
+import java.net.URL;
+
+/**
+ * @version $Rev: 410741 $ $Date: 2006-06-01 06:35:48 +0200 (Thu, 01 Jun 2006) $
+ */
+public abstract class AbstractUrlResourceLocation implements ResourceLocation {
+ private final URL codeSource;
+
+ public AbstractUrlResourceLocation(URL codeSource) {
+ this.codeSource = codeSource;
+ }
+
+ public final URL getCodeSource() {
+ return codeSource;
+ }
+
+ public void close() {
+ }
+
+ public final boolean equals(Object o) {
+ if (this == o) return true;
+ if (o == null || getClass() != o.getClass()) return false;
+
+ AbstractUrlResourceLocation that = (AbstractUrlResourceLocation) o;
+ return codeSource.equals(that.codeSource);
+ }
+
+ public final int hashCode() {
+ return codeSource.hashCode();
+ }
+
+ public final String toString() {
+ return "[" + getClass().getName() + ": " + codeSource + "]";
+ }
+}
Modified: geronimo/xbean/trunk/xbean-server/src/main/java/org/apache/xbean/server/classloader/ClassLoaderUtil.java
URL: http://svn.apache.org/viewvc/geronimo/xbean/trunk/xbean-server/src/main/java/org/apache/xbean/server/classloader/ClassLoaderUtil.java?rev=427602&r1=427601&r2=427602&view=diff
==============================================================================
--- geronimo/xbean/trunk/xbean-server/src/main/java/org/apache/xbean/server/classloader/ClassLoaderUtil.java (original)
+++ geronimo/xbean/trunk/xbean-server/src/main/java/org/apache/xbean/server/classloader/ClassLoaderUtil.java Tue Aug 1 08:15:02 2006
@@ -19,6 +19,7 @@
import java.util.Map;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
+import java.beans.Introspector;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.ObjectStreamClass;
@@ -46,6 +47,7 @@
clearSunSoftCache(ObjectOutputStream.class, "subclassAudits");
clearSunSoftCache(ObjectStreamClass.class, "localDescs");
clearSunSoftCache(ObjectStreamClass.class, "reflectors");
+ Introspector.flushCaches();
}
/**
Added: geronimo/xbean/trunk/xbean-server/src/main/java/org/apache/xbean/server/classloader/DirectoryResourceHandle.java
URL: http://svn.apache.org/viewvc/geronimo/xbean/trunk/xbean-server/src/main/java/org/apache/xbean/server/classloader/DirectoryResourceHandle.java?rev=427602&view=auto
==============================================================================
--- geronimo/xbean/trunk/xbean-server/src/main/java/org/apache/xbean/server/classloader/DirectoryResourceHandle.java (added)
+++ geronimo/xbean/trunk/xbean-server/src/main/java/org/apache/xbean/server/classloader/DirectoryResourceHandle.java Tue Aug 1 08:15:02 2006
@@ -0,0 +1,97 @@
+/**
+ *
+ * Copyright 2005 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.xbean.server.classloader;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.File;
+import java.io.FileInputStream;
+import java.net.URL;
+import java.net.MalformedURLException;
+import java.security.cert.Certificate;
+import java.util.jar.Attributes;
+import java.util.jar.Manifest;
+
+/**
+ * @version $Rev: 410741 $ $Date: 2006-06-01 06:35:48 +0200 (Thu, 01 Jun 2006) $
+ */
+public class DirectoryResourceHandle extends AbstractResourceHandle {
+ private final String name;
+ private final File file;
+ private final Manifest manifest;
+ private final URL url;
+ private final URL codeSource;
+
+ public DirectoryResourceHandle(String name, File file, File codeSource, Manifest manifest) throws MalformedURLException {
+ this.name = name;
+ this.file = file;
+ this.codeSource = codeSource.toURL();
+ this.manifest = manifest;
+ url = file.toURL();
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public URL getUrl() {
+ return url;
+ }
+
+ public URL getCodeSourceUrl() {
+ return codeSource;
+ }
+
+ public boolean isDirectory() {
+ return file.isDirectory();
+ }
+
+ public InputStream getInputStream() throws IOException {
+ if (file.isDirectory()) {
+ return new IoUtil.EmptyInputStream();
+ }
+ return new FileInputStream(file);
+ }
+
+ public int getContentLength() {
+ if (file.isDirectory() || file.length() > Integer.MAX_VALUE) {
+ return -1;
+ } else {
+ return (int) file.length();
+ }
+ }
+
+ public Manifest getManifest() throws IOException {
+ return manifest;
+ }
+
+ public Attributes getAttributes() throws IOException {
+ if (manifest == null) {
+ return null;
+ }
+ return manifest.getAttributes(getName());
+ }
+
+ /**
+ * Always return null. This could be implementd by verifing the signatures
+ * in the manifest file against the actual file, but we don't need this right now.
+ * @return null
+ */
+ public Certificate[] getCertificates() {
+ return null;
+ }
+}
Added: geronimo/xbean/trunk/xbean-server/src/main/java/org/apache/xbean/server/classloader/DirectoryResourceLocation.java
URL: http://svn.apache.org/viewvc/geronimo/xbean/trunk/xbean-server/src/main/java/org/apache/xbean/server/classloader/DirectoryResourceLocation.java?rev=427602&view=auto
==============================================================================
--- geronimo/xbean/trunk/xbean-server/src/main/java/org/apache/xbean/server/classloader/DirectoryResourceLocation.java (added)
+++ geronimo/xbean/trunk/xbean-server/src/main/java/org/apache/xbean/server/classloader/DirectoryResourceLocation.java Tue Aug 1 08:15:02 2006
@@ -0,0 +1,79 @@
+/**
+ *
+ * Copyright 2005 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.xbean.server.classloader;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.net.MalformedURLException;
+import java.util.jar.Manifest;
+
+/**
+ * @version $Rev: 410741 $ $Date: 2006-06-01 06:35:48 +0200 (Thu, 01 Jun 2006) $
+ */
+public class DirectoryResourceLocation extends AbstractUrlResourceLocation {
+ private final File baseDir;
+ private boolean manifestLoaded = false;
+ private Manifest manifest;
+
+ public DirectoryResourceLocation(File baseDir) throws MalformedURLException {
+ super(baseDir.toURL());
+ this.baseDir = baseDir;
+ }
+
+ public ResourceHandle getResourceHandle(String resourceName) {
+ File file = new File(baseDir, resourceName);
+ if (!file.exists()) {
+ return null;
+ }
+
+ try {
+ ResourceHandle resourceHandle = new DirectoryResourceHandle(resourceName, file, baseDir, getManifestSafe());
+ return resourceHandle;
+ } catch (MalformedURLException e) {
+ return null;
+ }
+ }
+
+ public Manifest getManifest() throws IOException {
+ if (!manifestLoaded) {
+ File manifestFile = new File(baseDir, "META-INF/MANIFEST.MF");
+
+ if (manifestFile.isFile() && manifestFile.canRead()) {
+ FileInputStream in = null;
+ try {
+ in = new FileInputStream(manifestFile);
+ manifest = new Manifest(in);
+ } finally {
+ IoUtil.close(in);
+ }
+ }
+ manifestLoaded = true;
+ }
+ return manifest;
+ }
+
+ private Manifest getManifestSafe() {
+ Manifest manifest = null;
+ try {
+ manifest = getManifest();
+ } catch (IOException e) {
+ // ignore
+ }
+ return manifest;
+ }
+}
Added: geronimo/xbean/trunk/xbean-server/src/main/java/org/apache/xbean/server/classloader/IoUtil.java
URL: http://svn.apache.org/viewvc/geronimo/xbean/trunk/xbean-server/src/main/java/org/apache/xbean/server/classloader/IoUtil.java?rev=427602&view=auto
==============================================================================
--- geronimo/xbean/trunk/xbean-server/src/main/java/org/apache/xbean/server/classloader/IoUtil.java (added)
+++ geronimo/xbean/trunk/xbean-server/src/main/java/org/apache/xbean/server/classloader/IoUtil.java Tue Aug 1 08:15:02 2006
@@ -0,0 +1,145 @@
+/**
+ *
+ * Copyright 2004 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.xbean.server.classloader;
+
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.io.Reader;
+import java.io.Writer;
+import java.util.jar.JarFile;
+
+/**
+ * @version $Rev: 410741 $ $Date: 2006-06-01 06:35:48 +0200 (Thu, 01 Jun 2006) $
+ */
+public final class IoUtil {
+ private IoUtil() {
+ }
+
+ public static byte[] getBytes(InputStream inputStream) throws IOException {
+ try {
+ byte[] buffer = new byte[4096];
+ ByteArrayOutputStream out = new ByteArrayOutputStream();
+ for (int count = inputStream.read(buffer); count >= 0; count = inputStream.read(buffer)) {
+ out.write(buffer, 0, count);
+ }
+ byte[] bytes = out.toByteArray();
+ return bytes;
+ } finally {
+ close(inputStream);
+ }
+ }
+
+ public static void flush(OutputStream thing) {
+ if (thing != null) {
+ try {
+ thing.flush();
+ } catch(Exception ignored) {
+ }
+ }
+ }
+
+ public static void flush(Writer thing) {
+ if (thing != null) {
+ try {
+ thing.flush();
+ } catch(Exception ignored) {
+ }
+ }
+ }
+
+ public static void close(JarFile thing) {
+ if (thing != null) {
+ try {
+ thing.close();
+ } catch(Exception ignored) {
+ }
+ }
+ }
+
+ public static void close(InputStream thing) {
+ if (thing != null) {
+ try {
+ thing.close();
+ } catch(Exception ignored) {
+ }
+ }
+ }
+
+ public static void close(OutputStream thing) {
+ if (thing != null) {
+ try {
+ thing.close();
+ } catch(Exception ignored) {
+ }
+ }
+ }
+
+ public static void close(Reader thing) {
+ if (thing != null) {
+ try {
+ thing.close();
+ } catch(Exception ignored) {
+ }
+ }
+ }
+
+ public static void close(Writer thing) {
+ if (thing != null) {
+ try {
+ thing.close();
+ } catch(Exception ignored) {
+ }
+ }
+ }
+
+ public static final class EmptyInputStream extends InputStream {
+ public int read() {
+ return -1;
+ }
+
+ public int read(byte b[]) {
+ return -1;
+ }
+
+ public int read(byte b[], int off, int len) {
+ return -1;
+ }
+
+ public long skip(long n) {
+ return 0;
+ }
+
+ public int available() {
+ return 0;
+ }
+
+ public void close() {
+ }
+
+ public synchronized void mark(int readlimit) {
+ }
+
+ public synchronized void reset() {
+ }
+
+ public boolean markSupported() {
+ return false;
+ }
+ }
+}
Modified: geronimo/xbean/trunk/xbean-server/src/main/java/org/apache/xbean/server/classloader/JarFileClassLoader.java
URL: http://svn.apache.org/viewvc/geronimo/xbean/trunk/xbean-server/src/main/java/org/apache/xbean/server/classloader/JarFileClassLoader.java?rev=427602&r1=427601&r2=427602&view=diff
==============================================================================
--- geronimo/xbean/trunk/xbean-server/src/main/java/org/apache/xbean/server/classloader/JarFileClassLoader.java (original)
+++ geronimo/xbean/trunk/xbean-server/src/main/java/org/apache/xbean/server/classloader/JarFileClassLoader.java Tue Aug 1 08:15:02 2006
@@ -16,28 +16,20 @@
*/
package org.apache.xbean.server.classloader;
-import java.io.ByteArrayOutputStream;
-import java.io.File;
import java.io.IOException;
-import java.io.InputStream;
-import java.net.MalformedURLException;
+import java.io.File;
import java.net.URL;
-import java.net.URLStreamHandlerFactory;
+import java.net.URI;
+import java.security.AccessControlContext;
+import java.security.AccessController;
import java.security.CodeSource;
+import java.security.PrivilegedAction;
+import java.security.PrivilegedExceptionAction;
+import java.security.PrivilegedActionException;
import java.security.cert.Certificate;
-import java.util.Collections;
+import java.util.Collection;
import java.util.Enumeration;
-import java.util.Iterator;
-import java.util.LinkedHashMap;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Map;
-import java.util.StringTokenizer;
-import java.util.Arrays;
-import java.util.ArrayList;
import java.util.jar.Attributes;
-import java.util.jar.JarEntry;
-import java.util.jar.JarFile;
import java.util.jar.Manifest;
/**
@@ -50,14 +42,14 @@
* replacement for the jar url handler must be written.
*
* @author Dain Sundstrom
- * @version $Id$
+ * @version $Id: JarFileClassLoader.java 410741 2006-06-01 04:35:48Z jsisson $
* @since 2.0
*/
public class JarFileClassLoader extends MultiParentClassLoader {
private static final URL[] EMPTY_URLS = new URL[0];
- private final Object lock = new Object();
- private final LinkedHashMap classPath = new LinkedHashMap();
- private boolean destroyed = false;
+
+ private final UrlResourceFinder resourceFinder = new UrlResourceFinder();
+ private final AccessControlContext acc;
/**
* Creates a JarFileClassLoader that is a child of the system class loader.
@@ -66,6 +58,7 @@
*/
public JarFileClassLoader(String name, URL[] urls) {
super(name, EMPTY_URLS);
+ this.acc = AccessController.getContext();
addURLs(urls);
}
@@ -76,19 +69,15 @@
* @param parent the parent of this class loader
*/
public JarFileClassLoader(String name, URL[] urls, ClassLoader parent) {
- this(name, urls, new ClassLoader[] {parent});
+ super(name, EMPTY_URLS, parent);
+ this.acc = AccessController.getContext();
+ addURLs(urls);
}
- /**
- * Creates a named class loader as a child of the specified parent and using the specified URLStreamHandlerFactory
- * for accessing the urls..
- * @param name the name of this class loader
- * @param urls the urls from which this class loader will classes and resources
- * @param parent the parent of this class loader
- * @param factory the URLStreamHandlerFactory used to access the urls
- */
- public JarFileClassLoader(String name, URL[] urls, ClassLoader parent, URLStreamHandlerFactory factory) {
- this(name, urls, new ClassLoader[] {parent}, factory);
+ public JarFileClassLoader(String name, URL[] urls, ClassLoader parent, boolean inverseClassLoading, String[] hiddenClasses, String[] nonOverridableClasses) {
+ super(name, EMPTY_URLS, parent, inverseClassLoading, hiddenClasses, nonOverridableClasses);
+ this.acc = AccessController.getContext();
+ addURLs(urls);
}
/**
@@ -99,19 +88,19 @@
*/
public JarFileClassLoader(String name, URL[] urls, ClassLoader[] parents) {
super(name, EMPTY_URLS, parents);
+ this.acc = AccessController.getContext();
addURLs(urls);
}
- /**
- * Creates a named class loader as a child of the specified parents and using the specified URLStreamHandlerFactory
- * for accessing the urls..
- * @param name the name of this class loader
- * @param urls the urls from which this class loader will classes and resources
- * @param parents the parents of this class loader
- * @param factory the URLStreamHandlerFactory used to access the urls
- */
- public JarFileClassLoader(String name, URL[] urls, ClassLoader[] parents, URLStreamHandlerFactory factory) {
- super(name, EMPTY_URLS, parents, factory);
+ public JarFileClassLoader(String name, URL[] urls, ClassLoader[] parents, boolean inverseClassLoading, Collection hiddenClasses, Collection nonOverridableClasses) {
+ super(name, EMPTY_URLS, parents, inverseClassLoading, hiddenClasses, nonOverridableClasses);
+ this.acc = AccessController.getContext();
+ addURLs(urls);
+ }
+
+ public JarFileClassLoader(String name, URL[] urls, ClassLoader[] parents, boolean inverseClassLoading, String[] hiddenClasses, String[] nonOverridableClasses) {
+ super(name, EMPTY_URLS, parents, inverseClassLoading, hiddenClasses, nonOverridableClasses);
+ this.acc = AccessController.getContext();
addURLs(urls);
}
@@ -119,230 +108,174 @@
* {@inheritDoc}
*/
public URL[] getURLs() {
- return (URL[]) classPath.keySet().toArray(new URL[classPath.keySet().size()]);
+ return resourceFinder.getUrls();
}
/**
* {@inheritDoc}
*/
- protected void addURL(URL url) {
- addURLs(Collections.singletonList(url));
+ public void addURL(final URL url) {
+ AccessController.doPrivileged(new PrivilegedAction() {
+ public Object run() {
+ resourceFinder.addUrl(url);
+ return null;
+ }
+ }, acc);
}
/**
* Adds an array of urls to the end of this class loader.
* @param urls the URLs to add
*/
- protected void addURLs(URL[] urls) {
- addURLs(Arrays.asList(urls));
+ protected void addURLs(final URL[] urls) {
+ AccessController.doPrivileged(new PrivilegedAction() {
+ public Object run() {
+ resourceFinder.addUrls(urls);
+ return null;
+ }
+ }, acc);
}
/**
- * Adds a list of urls to the end of this class loader.
- * @param urls the URLs to add
+ * {@inheritDoc}
*/
- protected void addURLs(List urls) {
- LinkedList locationStack = new LinkedList(urls);
- try {
- while (!locationStack.isEmpty()) {
- URL url = (URL) locationStack.removeFirst();
-
- if (!"file".equals(url.getProtocol())) {
- // download the jar
- throw new Error("Only local file jars are supported " + url);
- }
-
- String path = url.getPath();
- if (classPath.containsKey(path)) {
- continue;
- }
-
- File file = new File(path);
- if (!file.canRead()) {
- // can't read file...
- continue;
- }
-
- // open the jar file
- JarFile jarFile;
- try {
- jarFile = new JarFile(file);
- } catch (IOException e) {
- // can't seem to open the file
- continue;
- }
- classPath.put(url, jarFile);
-
- // push the manifest classpath on the stack (make sure to maintain the order)
- Manifest manifest = null;
- try {
- manifest = jarFile.getManifest();
- } catch (IOException ignored) {
- }
+ public void destroy() {
+ resourceFinder.destroy();
+ super.destroy();
+ }
- if (manifest != null) {
- Attributes mainAttributes = manifest.getMainAttributes();
- String manifestClassPath = mainAttributes.getValue(Attributes.Name.CLASS_PATH);
- if (manifestClassPath != null) {
- LinkedList classPathUrls = new LinkedList();
- for (StringTokenizer tokenizer = new StringTokenizer(manifestClassPath, " "); tokenizer.hasMoreTokens();) {
- String entry = tokenizer.nextToken();
- File parentDir = file.getParentFile();
- File entryFile = new File(parentDir, entry);
- // manifest entries are optional... if they aren't there it is ok
- if (entryFile.canRead()) {
- classPathUrls.addLast(entryFile.getAbsolutePath());
- }
- }
- locationStack.addAll(0, classPathUrls);
- }
- }
+ /**
+ * {@inheritDoc}
+ */
+ public URL findResource(final String resourceName) {
+ return (URL) AccessController.doPrivileged(new PrivilegedAction() {
+ public Object run() {
+ return resourceFinder.findResource(resourceName);
}
- } catch (Error e) {
- destroy();
- throw e;
- }
+ }, acc);
}
/**
* {@inheritDoc}
*/
- public void destroy() {
- synchronized (lock) {
- if (destroyed) {
- return;
- }
- destroyed = true;
- for (Iterator iterator = classPath.values().iterator(); iterator.hasNext();) {
- JarFile jarFile = (JarFile) iterator.next();
- try {
- jarFile.close();
- } catch (IOException ignored) {
- }
- }
- classPath.clear();
- }
- super.destroy();
+ public Enumeration findResources(final String resourceName) throws IOException {
+ // todo this is not right
+ // first get the resources from the parent classloaders
+ Enumeration parentResources = super.findResources(resourceName);
+
+ // get the classes from my urls
+ Enumeration myResources = (Enumeration) AccessController.doPrivileged(new PrivilegedAction() {
+ public Object run() {
+ return resourceFinder.findResources(resourceName);
+ }
+ }, acc);
+
+ // join the two together
+ Enumeration resources = new UnionEnumeration(parentResources, myResources);
+ return resources;
}
/**
* {@inheritDoc}
*/
- public URL findResource(String resourceName) {
- URL jarUrl = null;
- synchronized (lock) {
- if (destroyed) {
- return null;
- }
- for (Iterator iterator = classPath.entrySet().iterator(); iterator.hasNext() && jarUrl == null;) {
- Map.Entry entry = (Map.Entry) iterator.next();
- JarFile jarFile = (JarFile) entry.getValue();
- JarEntry jarEntry = jarFile.getJarEntry(resourceName);
- if (jarEntry != null && !jarEntry.isDirectory()) {
- jarUrl = (URL) entry.getKey();
- }
- }
+ protected String findLibrary(String libraryName) {
+ // if the libraryName is actually a directory it is invalid
+ int pathEnd = libraryName.lastIndexOf('/');
+ if (pathEnd == libraryName.length() - 1) {
+ throw new IllegalArgumentException("libraryName ends with a '/' character: " + libraryName);
}
+ // get the name if the library file
+ final String resourceName;
+ if (pathEnd < 0) {
+ resourceName = System.mapLibraryName(libraryName);
+ } else {
+ String path = libraryName.substring(0, pathEnd + 1);
+ String file = libraryName.substring(pathEnd + 1);
+ resourceName = path + System.mapLibraryName(file);
+ }
- try {
- String urlString = "jar:" + jarUrl + "!/" + resourceName;
- return new URL(jarUrl, urlString);
- } catch (MalformedURLException e) {
+ // get a resource handle to the library
+ ResourceHandle resourceHandle = (ResourceHandle) AccessController.doPrivileged(new PrivilegedAction() {
+ public Object run() {
+ return resourceFinder.getResource(resourceName);
+ }
+ }, acc);
+
+ if (resourceHandle == null) {
return null;
}
- }
- /**
- * {@inheritDoc}
- */
- public Enumeration findResources(String resourceName) throws IOException {
- List resources = new ArrayList();
- List superResources = Collections.list(super.findResources(resourceName));
- resources.addAll(superResources);
-
- synchronized (lock) {
- if (destroyed) {
- return Collections.enumeration(Collections.EMPTY_LIST);
- }
- for (Iterator iterator = classPath.entrySet().iterator(); iterator.hasNext();) {
- Map.Entry entry = (Map.Entry) iterator.next();
- JarFile jarFile = (JarFile) entry.getValue();
- JarEntry jarEntry = jarFile.getJarEntry(resourceName);
- if (jarEntry != null && !jarEntry.isDirectory()) {
- try {
- URL url = (URL) entry.getKey();
- String urlString = "jar:" + url + "!/" + resourceName;
- resources.add(new URL(url, urlString));
- } catch (MalformedURLException e) {
- }
- }
- }
+ // the library must be accessable on the file system
+ URL url = resourceHandle.getUrl();
+ if (!"file".equals(url.getProtocol())) {
+ return null;
}
- return Collections.enumeration(resources);
+ String path = new File(URI.create(url.toString())).getPath();
+ return path;
}
/**
* {@inheritDoc}
*/
- protected Class findClass(String className) throws ClassNotFoundException {
- SecurityManager securityManager = System.getSecurityManager();
- if (securityManager != null) {
- String packageName;
- int packageEnd = className.lastIndexOf('.');
- if (packageEnd >= 0) {
- packageName = className.substring(0, packageEnd);
- securityManager.checkPackageDefinition(packageName);
- }
- }
+ protected Class findClass(final String className) throws ClassNotFoundException {
+ try {
+ return (Class) AccessController.doPrivileged(new PrivilegedExceptionAction() {
+ public Object run() throws ClassNotFoundException {
+ // first think check if we are allowed to define the package
+ SecurityManager securityManager = System.getSecurityManager();
+ if (securityManager != null) {
+ String packageName;
+ int packageEnd = className.lastIndexOf('.');
+ if (packageEnd >= 0) {
+ packageName = className.substring(0, packageEnd);
+ securityManager.checkPackageDefinition(packageName);
+ }
+ }
- Certificate[] certificates = null;
- URL jarUrl = null;
- Manifest manifest = null;
- byte[] bytes;
- synchronized (lock) {
- if (destroyed) {
- throw new ClassNotFoundException("Class loader has been destroyed: " + className);
- }
- try {
- String entryName = className.replace('.', '/') + ".class";
- InputStream inputStream = null;
- for (Iterator iterator = classPath.entrySet().iterator(); iterator.hasNext() && inputStream == null;) {
- Map.Entry entry = (Map.Entry) iterator.next();
- jarUrl = (URL) entry.getKey();
- JarFile jarFile = (JarFile) entry.getValue();
- JarEntry jarEntry = jarFile.getJarEntry(entryName);
- if (jarEntry != null && !jarEntry.isDirectory()) {
- inputStream = jarFile.getInputStream(jarEntry);
- certificates = jarEntry.getCertificates();
- manifest = jarFile.getManifest();
+ // convert the class name to a file name
+ String resourceName = className.replace('.', '/') + ".class";
+
+ // find the class file resource
+ ResourceHandle resourceHandle = resourceFinder.getResource(resourceName);
+ if (resourceHandle == null) {
+ throw new ClassNotFoundException(className);
}
- }
- if (inputStream == null) {
- throw new ClassNotFoundException(className);
- }
- try {
- byte[] buffer = new byte[4096];
- ByteArrayOutputStream out = new ByteArrayOutputStream();
- for (int count = inputStream.read(buffer); count >= 0; count = inputStream.read(buffer)) {
- out.write(buffer, 0, count);
+ byte[] bytes;
+ Manifest manifest;
+ try {
+ // get the bytes from the class file
+ bytes = resourceHandle.getBytes();
+
+ // get the manifest for defining the packages
+ manifest = resourceHandle.getManifest();
+ } catch (IOException e) {
+ throw new ClassNotFoundException(className, e);
}
- bytes = out.toByteArray();
- } finally {
- inputStream.close();
+
+ // get the certificates for the code source
+ Certificate[] certificates = resourceHandle.getCertificates();
+
+ // the code source url is used to define the package and as the security context for the class
+ URL codeSourceUrl = resourceHandle.getCodeSourceUrl();
+
+ // define the package (required for security)
+ definePackage(className, codeSourceUrl, manifest);
+
+ // this is the security context of the class
+ CodeSource codeSource = new CodeSource(codeSourceUrl, certificates);
+
+ // load the class into the vm
+ Class clazz = defineClass(className, bytes, 0, bytes.length, codeSource);
+ return clazz;
}
- } catch (IOException e) {
- throw new ClassNotFoundException(className, e);
- }
+ }, acc);
+ } catch (PrivilegedActionException e) {
+ throw (ClassNotFoundException) e.getException();
}
-
- definePackage(className, jarUrl, manifest);
- CodeSource codeSource = new CodeSource(jarUrl, certificates);
- Class clazz = defineClass(className, bytes, 0, bytes.length, codeSource);
- return clazz;
}
private void definePackage(String className, URL jarUrl, Manifest manifest) {
@@ -408,4 +341,4 @@
}
return "true".equalsIgnoreCase(sealed);
}
-}
\ No newline at end of file
+}
Added: geronimo/xbean/trunk/xbean-server/src/main/java/org/apache/xbean/server/classloader/JarFileUrlConnection.java
URL: http://svn.apache.org/viewvc/geronimo/xbean/trunk/xbean-server/src/main/java/org/apache/xbean/server/classloader/JarFileUrlConnection.java?rev=427602&view=auto
==============================================================================
--- geronimo/xbean/trunk/xbean-server/src/main/java/org/apache/xbean/server/classloader/JarFileUrlConnection.java (added)
+++ geronimo/xbean/trunk/xbean-server/src/main/java/org/apache/xbean/server/classloader/JarFileUrlConnection.java Tue Aug 1 08:15:02 2006
@@ -0,0 +1,132 @@
+/**
+ *
+ * Copyright 2005 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.xbean.server.classloader;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.JarURLConnection;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.net.URLConnection;
+import java.net.URLStreamHandler;
+import java.security.Permission;
+import java.security.cert.Certificate;
+import java.util.jar.Attributes;
+import java.util.jar.JarEntry;
+import java.util.jar.JarFile;
+import java.util.jar.Manifest;
+
+/**
+ * @version $Rev: 410741 $ $Date: 2006-06-01 06:35:48 +0200 (Thu, 01 Jun 2006) $
+ */
+public class JarFileUrlConnection extends JarURLConnection {
+ public static final URL DUMMY_JAR_URL;
+ static {
+ try {
+ DUMMY_JAR_URL = new URL("jar", "", -1, "file:dummy!/", new URLStreamHandler() {
+ protected URLConnection openConnection(URL u) {
+ throw new UnsupportedOperationException();
+ }
+ });
+ } catch (Exception e) {
+ throw new ExceptionInInitializerError(e);
+ }
+ }
+
+ private final URL url;
+ private final JarFile jarFile;
+ private final JarEntry jarEntry;
+ private final URL jarFileUrl;
+
+ public JarFileUrlConnection(URL url, JarFile jarFile, JarEntry jarEntry) throws MalformedURLException {
+ super(DUMMY_JAR_URL);
+
+ if (url == null) throw new NullPointerException("url is null");
+ if (jarFile == null) throw new NullPointerException("jarFile is null");
+ if (jarEntry == null) throw new NullPointerException("jarEntry is null");
+
+ this.url = url;
+ this.jarFile = jarFile;
+ this.jarEntry = jarEntry;
+ jarFileUrl = new File(jarFile.getName()).toURL();
+ }
+
+ public JarFile getJarFile() throws IOException {
+ return jarFile;
+ }
+
+ public synchronized void connect() {
+ }
+
+ public URL getJarFileURL() {
+ return jarFileUrl;
+ }
+
+ public String getEntryName() {
+ return getJarEntry().getName();
+ }
+
+ public Manifest getManifest() throws IOException {
+ return jarFile.getManifest();
+ }
+
+ public JarEntry getJarEntry() {
+ return jarEntry;
+ }
+
+ public Attributes getAttributes() throws IOException {
+ return getJarEntry().getAttributes();
+ }
+
+ public Attributes getMainAttributes() throws IOException {
+ return getManifest().getMainAttributes();
+ }
+
+ public Certificate[] getCertificates() throws IOException {
+ return getJarEntry().getCertificates();
+ }
+
+ public URL getURL() {
+ return url;
+ }
+
+ public int getContentLength() {
+ long size = getJarEntry().getSize();
+ if (size > Integer.MAX_VALUE) {
+ return -1;
+ }
+ return (int) size;
+ }
+
+ public long getLastModified() {
+ return getJarEntry().getTime();
+ }
+
+ public synchronized InputStream getInputStream() throws IOException {
+ return jarFile.getInputStream(jarEntry);
+ }
+
+ public Permission getPermission() throws IOException {
+ URL jarFileUrl = new File(jarFile.getName()).toURL();
+ return jarFileUrl.openConnection().getPermission();
+ }
+
+ public String toString() {
+ return JarFileUrlConnection.class.getName() + ":" + url;
+ }
+}
Added: geronimo/xbean/trunk/xbean-server/src/main/java/org/apache/xbean/server/classloader/JarFileUrlStreamHandler.java
URL: http://svn.apache.org/viewvc/geronimo/xbean/trunk/xbean-server/src/main/java/org/apache/xbean/server/classloader/JarFileUrlStreamHandler.java?rev=427602&view=auto
==============================================================================
--- geronimo/xbean/trunk/xbean-server/src/main/java/org/apache/xbean/server/classloader/JarFileUrlStreamHandler.java (added)
+++ geronimo/xbean/trunk/xbean-server/src/main/java/org/apache/xbean/server/classloader/JarFileUrlStreamHandler.java Tue Aug 1 08:15:02 2006
@@ -0,0 +1,67 @@
+/**
+ *
+ * Copyright 2005 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.xbean.server.classloader;
+
+import java.net.URL;
+import java.net.URLConnection;
+import java.net.URLStreamHandler;
+import java.net.MalformedURLException;
+import java.util.jar.JarEntry;
+import java.util.jar.JarFile;
+import java.io.File;
+
+/**
+ * @version $Rev: 410741 $ $Date: 2006-06-01 06:35:48 +0200 (Thu, 01 Jun 2006) $
+ */
+public class JarFileUrlStreamHandler extends URLStreamHandler {
+ public static URL createUrl(JarFile jarFile, JarEntry jarEntry) throws MalformedURLException {
+ return createUrl(jarFile, jarEntry, new File(jarFile.getName()).toURL());
+ }
+
+ public static URL createUrl(JarFile jarFile, JarEntry jarEntry, URL codeSource) throws MalformedURLException {
+ JarFileUrlStreamHandler handler = new JarFileUrlStreamHandler(jarFile, jarEntry);
+ URL url = new URL("jar", "", -1, codeSource + "!/" + jarEntry.getName(), handler);
+ handler.setExpectedUrl(url);
+ return url;
+ }
+
+ private URL expectedUrl;
+ private final JarFile jarFile;
+ private final JarEntry jarEntry;
+
+ public JarFileUrlStreamHandler(JarFile jarFile, JarEntry jarEntry) {
+ if (jarFile == null) throw new NullPointerException("jarFile is null");
+ if (jarEntry == null) throw new NullPointerException("jarEntry is null");
+
+ this.jarFile = jarFile;
+ this.jarEntry = jarEntry;
+ }
+
+ public void setExpectedUrl(URL expectedUrl) {
+ if (expectedUrl == null) throw new NullPointerException("expectedUrl is null");
+ this.expectedUrl = expectedUrl;
+ }
+
+ public URLConnection openConnection(URL url) throws MalformedURLException {
+ if (expectedUrl == null) throw new IllegalStateException("expectedUrl was not set");
+
+ // alternatively we could return a connection using the normal jar url connection
+ if (!expectedUrl.equals(url)) throw new IllegalArgumentException("Expected url [" + expectedUrl + "], but was [" + url + "]");
+
+ return new JarFileUrlConnection(url, jarFile, jarEntry);
+ }
+}
Added: geronimo/xbean/trunk/xbean-server/src/main/java/org/apache/xbean/server/classloader/JarResourceHandle.java
URL: http://svn.apache.org/viewvc/geronimo/xbean/trunk/xbean-server/src/main/java/org/apache/xbean/server/classloader/JarResourceHandle.java?rev=427602&view=auto
==============================================================================
--- geronimo/xbean/trunk/xbean-server/src/main/java/org/apache/xbean/server/classloader/JarResourceHandle.java (added)
+++ geronimo/xbean/trunk/xbean-server/src/main/java/org/apache/xbean/server/classloader/JarResourceHandle.java Tue Aug 1 08:15:02 2006
@@ -0,0 +1,80 @@
+/**
+ *
+ * Copyright 2005 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.xbean.server.classloader;
+
+import java.util.jar.JarFile;
+import java.util.jar.JarEntry;
+import java.util.jar.Manifest;
+import java.util.jar.Attributes;
+import java.net.URL;
+import java.net.MalformedURLException;
+import java.io.InputStream;
+import java.io.IOException;
+import java.security.cert.Certificate;
+
+/**
+ * @version $Rev: 410741 $ $Date: 2006-06-01 06:35:48 +0200 (Thu, 01 Jun 2006) $
+ */
+public class JarResourceHandle extends AbstractResourceHandle {
+ private final JarFile jarFile;
+ private final JarEntry jarEntry;
+ private final URL url;
+ private final URL codeSource;
+
+ public JarResourceHandle(JarFile jarFile, JarEntry jarEntry, URL codeSource) throws MalformedURLException {
+ this.jarFile = jarFile;
+ this.jarEntry = jarEntry;
+ this.url = JarFileUrlStreamHandler.createUrl(jarFile, jarEntry, codeSource);
+ this.codeSource = codeSource;
+ }
+
+ public String getName() {
+ return jarEntry.getName();
+ }
+
+ public URL getUrl() {
+ return url;
+ }
+
+ public URL getCodeSourceUrl() {
+ return codeSource;
+ }
+
+ public boolean isDirectory() {
+ return jarEntry.isDirectory();
+ }
+
+ public InputStream getInputStream() throws IOException {
+ return jarFile.getInputStream(jarEntry);
+ }
+
+ public int getContentLength() {
+ return (int) jarEntry.getSize();
+ }
+
+ public Manifest getManifest() throws IOException {
+ return jarFile.getManifest();
+ }
+
+ public Attributes getAttributes() throws IOException {
+ return jarEntry.getAttributes();
+ }
+
+ public Certificate[] getCertificates() {
+ return jarEntry.getCertificates();
+ }
+}
Added: geronimo/xbean/trunk/xbean-server/src/main/java/org/apache/xbean/server/classloader/JarResourceLocation.java
URL: http://svn.apache.org/viewvc/geronimo/xbean/trunk/xbean-server/src/main/java/org/apache/xbean/server/classloader/JarResourceLocation.java?rev=427602&view=auto
==============================================================================
--- geronimo/xbean/trunk/xbean-server/src/main/java/org/apache/xbean/server/classloader/JarResourceLocation.java (added)
+++ geronimo/xbean/trunk/xbean-server/src/main/java/org/apache/xbean/server/classloader/JarResourceLocation.java Tue Aug 1 08:15:02 2006
@@ -0,0 +1,56 @@
+/**
+ *
+ * Copyright 2005 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.xbean.server.classloader;
+
+import java.util.jar.Manifest;
+import java.util.jar.JarFile;
+import java.util.jar.JarEntry;
+import java.net.URL;
+import java.net.MalformedURLException;
+import java.io.IOException;
+
+/**
+ * @version $Rev: 410741 $ $Date: 2006-06-01 06:35:48 +0200 (Thu, 01 Jun 2006) $
+ */
+public class JarResourceLocation extends AbstractUrlResourceLocation {
+ private final JarFile jarFile;
+
+ public JarResourceLocation(URL codeSource, JarFile jarFile) {
+ super(codeSource);
+ this.jarFile = jarFile;
+ }
+
+ public ResourceHandle getResourceHandle(String resourceName) {
+ JarEntry jarEntry = jarFile.getJarEntry(resourceName);
+ if (jarEntry != null) {
+ try {
+ URL url = new URL(getCodeSource(), resourceName);
+ return new JarResourceHandle(jarFile, jarEntry, getCodeSource());
+ } catch (MalformedURLException e) {
+ }
+ }
+ return null;
+ }
+
+ public Manifest getManifest() throws IOException {
+ return jarFile.getManifest();
+ }
+
+ public void close() {
+ IoUtil.close(jarFile);
+ }
+}
Modified: geronimo/xbean/trunk/xbean-server/src/main/java/org/apache/xbean/server/classloader/MultiParentClassLoader.java
URL: http://svn.apache.org/viewvc/geronimo/xbean/trunk/xbean-server/src/main/java/org/apache/xbean/server/classloader/MultiParentClassLoader.java?rev=427602&r1=427601&r2=427602&view=diff
==============================================================================
--- geronimo/xbean/trunk/xbean-server/src/main/java/org/apache/xbean/server/classloader/MultiParentClassLoader.java (original)
+++ geronimo/xbean/trunk/xbean-server/src/main/java/org/apache/xbean/server/classloader/MultiParentClassLoader.java Tue Aug 1 08:15:02 2006
@@ -21,6 +21,7 @@
import java.net.URLStreamHandlerFactory;
import java.util.ArrayList;
import java.util.Arrays;
+import java.util.Collection;
import java.util.Collections;
import java.util.Enumeration;
import java.util.List;
@@ -38,6 +39,11 @@
*/
public class MultiParentClassLoader extends NamedClassLoader {
private final ClassLoader[] parents;
+ private final boolean inverseClassLoading;
+ private final String[] hiddenClasses;
+ private final String[] nonOverridableClasses;
+ private final String[] hiddenResources;
+ private final String[] nonOverridableResources;
/**
* Creates a named class loader with no parents.
@@ -45,8 +51,7 @@
* @param urls the urls from which this class loader will classes and resources
*/
public MultiParentClassLoader(String name, URL[] urls) {
- super(name, urls);
- parents = new ClassLoader[0];
+ this(name, urls, ClassLoader.getSystemClassLoader());
}
/**
@@ -78,10 +83,13 @@
* @param parents the parents of this class loader
*/
public MultiParentClassLoader(String name, URL[] urls, ClassLoader[] parents) {
- super(name, urls);
- this.parents = copyParents(parents);
+ this(name, urls, parents, false, new String[0], new String[0]);
}
+ public MultiParentClassLoader(String name, URL[] urls, ClassLoader parent, boolean inverseClassLoading, String[] hiddenClasses, String[] nonOverridableClasses) {
+ this(name, urls, new ClassLoader[]{parent}, inverseClassLoading, hiddenClasses, nonOverridableClasses);
+ }
+
/**
* Creates a named class loader as a child of the specified parents and using the specified URLStreamHandlerFactory
* for accessing the urls..
@@ -93,8 +101,36 @@
public MultiParentClassLoader(String name, URL[] urls, ClassLoader[] parents, URLStreamHandlerFactory factory) {
super(name, urls, null, factory);
this.parents = copyParents(parents);
+ this.inverseClassLoading = false;
+ this.hiddenClasses = new String[0];
+ this.nonOverridableClasses = new String[0];
+ this.hiddenResources = new String[0];
+ this.nonOverridableResources = new String[0];
}
+ public MultiParentClassLoader(String name, URL[] urls, ClassLoader[] parents, boolean inverseClassLoading, Collection hiddenClasses, Collection nonOverridableClasses) {
+ this(name, urls, parents, inverseClassLoading, (String[]) hiddenClasses.toArray(new String[hiddenClasses.size()]), (String[]) nonOverridableClasses.toArray(new String[nonOverridableClasses.size()]));
+ }
+
+ public MultiParentClassLoader(String name, URL[] urls, ClassLoader[] parents, boolean inverseClassLoading, String[] hiddenClasses, String[] nonOverridableClasses) {
+ super(name, urls);
+ this.parents = copyParents(parents);
+ this.inverseClassLoading = inverseClassLoading;
+ this.hiddenClasses = hiddenClasses;
+ this.nonOverridableClasses = nonOverridableClasses;
+ hiddenResources = toResources(hiddenClasses);
+ nonOverridableResources = toResources(nonOverridableClasses);
+ }
+
+ private static String[] toResources(String[] classes) {
+ String[] resources = new String[classes.length];
+ for (int i = 0; i < classes.length; i++) {
+ String className = classes[i];
+ resources[i] = className.replace('.', '/');
+ }
+ return resources;
+ }
+
private static ClassLoader[] copyParents(ClassLoader[] parents) {
ClassLoader[] newParentsArray = new ClassLoader[parents.length];
for (int i = 0; i < parents.length; i++) {
@@ -119,65 +155,181 @@
* {@inheritDoc}
*/
protected synchronized Class loadClass(String name, boolean resolve) throws ClassNotFoundException {
- Class clazz = findLoadedClass(name);
- for (int i = 0; i < parents.length && clazz == null; i++) {
- ClassLoader parent = parents[i];
+ //
+ // Check if class is in the loaded classes cache
+ //
+ Class cachedClass = findLoadedClass(name);
+ if (cachedClass != null) {
+ return resolveClass(cachedClass, resolve);
+ }
+
+ //
+ // if we are using inverse class loading, check local urls first
+ //
+ if (inverseClassLoading && !isDestroyed() && !isNonOverridableClass(name)) {
try {
- clazz = parent.loadClass(name);
+ Class clazz = findClass(name);
+ return resolveClass(clazz, resolve);
} catch (ClassNotFoundException ignored) {
- // this parent didn't have the class; try the next one
}
}
- if (clazz == null) {
- // parents didn't have the class; attempt to load from my urls
- return super.loadClass(name, resolve);
- } else {
- // we found the class; resolve it if requested
- if (resolve) {
- resolveClass(clazz);
+ //
+ // Check parent class loaders
+ //
+ if (!isHiddenClass(name)) {
+ for (int i = 0; i < parents.length; i++) {
+ ClassLoader parent = parents[i];
+ try {
+ Class clazz = parent.loadClass(name);
+ return resolveClass(clazz, resolve);
+ } catch (ClassNotFoundException ignored) {
+ // this parent didn't have the class; try the next one
+ }
+ }
+ }
+
+ //
+ // if we are not using inverse class loading, check local urls now
+ //
+ // don't worry about excluding non-overridable classes here... we
+ // have alredy checked he parent and the parent didn't have the
+ // class, so we can override now
+ if (!isDestroyed()) {
+ try {
+ Class clazz = findClass(name);
+ return resolveClass(clazz, resolve);
+ } catch (ClassNotFoundException ignored) {
+ }
+ }
+
+ throw new ClassNotFoundException(name + " in classloader " + name);
+ }
+
+ private boolean isNonOverridableClass(String name) {
+ for (int i = 0; i < nonOverridableClasses.length; i++) {
+ if (name.startsWith(nonOverridableClasses[i])) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ private boolean isHiddenClass(String name) {
+ for (int i = 0; i < hiddenClasses.length; i++) {
+ if (name.startsWith(hiddenClasses[i])) {
+ return true;
}
- return clazz;
}
+ return false;
+ }
+
+ private Class resolveClass(Class clazz, boolean resolve) {
+ if (resolve) {
+ resolveClass(clazz);
+ }
+ return clazz;
}
/**
* {@inheritDoc}
*/
public URL getResource(String name) {
- URL url = null;
- for (int i = 0; i < parents.length && url == null; i++) {
- ClassLoader parent = parents[i];
- url = parent.getResource(name);
+ if (isDestroyed()) {
+ return null;
}
- if (url == null) {
+ //
+ // if we are using inverse class loading, check local urls first
+ //
+ if (inverseClassLoading && !isDestroyed() && !isNonOverridableResource(name)) {
+ URL url = findResource(name);
+ if (url != null) {
+ return url;
+ }
+ }
+
+ //
+ // Check parent class loaders
+ //
+ if (!isHiddenResource(name)) {
+ for (int i = 0; i < parents.length; i++) {
+ ClassLoader parent = parents[i];
+ URL url = parent.getResource(name);
+ if (url != null) {
+ return url;
+ }
+ }
+ }
+
+ //
+ // if we are not using inverse class loading, check local urls now
+ //
+ // don't worry about excluding non-overridable resources here... we
+ // have alredy checked he parent and the parent didn't have the
+ // resource, so we can override now
+ if (!isDestroyed()) {
// parents didn't have the resource; attempt to load it from my urls
- return super.getResource(name);
- } else {
- return url;
+ return findResource(name);
}
+
+ return null;
}
/**
* {@inheritDoc}
*/
public Enumeration findResources(String name) throws IOException {
+ if (isDestroyed()) {
+ return Collections.enumeration(Collections.EMPTY_SET);
+ }
+
List resources = new ArrayList();
- // Add resources from all parents
+ //
+ // if we are using inverse class loading, add the resources from local urls first
+ //
+ if (inverseClassLoading && !isDestroyed()) {
+ List myResources = Collections.list(super.findResources(name));
+ resources.addAll(myResources);
+ }
+
+ //
+ // Add parent resources
+ //
for (int i = 0; i < parents.length; i++) {
ClassLoader parent = parents[i];
List parentResources = Collections.list(parent.getResources(name));
resources.addAll(parentResources);
}
- // Add the resources from my urls
- List myResources = Collections.list(super.findResources(name));
- resources.addAll(myResources);
+ //
+ // if we are not using inverse class loading, add the resources from local urls now
+ //
+ if (!inverseClassLoading && !isDestroyed()) {
+ List myResources = Collections.list(super.findResources(name));
+ resources.addAll(myResources);
+ }
- // return an enumeration over the list
return Collections.enumeration(resources);
+ }
+
+ private boolean isNonOverridableResource(String name) {
+ for (int i = 0; i < nonOverridableResources.length; i++) {
+ if (name.startsWith(nonOverridableResources[i])) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ private boolean isHiddenResource(String name) {
+ for (int i = 0; i < hiddenResources.length; i++) {
+ if (name.startsWith(hiddenResources[i])) {
+ return true;
+ }
+ }
+ return false;
}
/**
Modified: geronimo/xbean/trunk/xbean-server/src/main/java/org/apache/xbean/server/classloader/NamedClassLoader.java
URL: http://svn.apache.org/viewvc/geronimo/xbean/trunk/xbean-server/src/main/java/org/apache/xbean/server/classloader/NamedClassLoader.java?rev=427602&r1=427601&r2=427602&view=diff
==============================================================================
--- geronimo/xbean/trunk/xbean-server/src/main/java/org/apache/xbean/server/classloader/NamedClassLoader.java (original)
+++ geronimo/xbean/trunk/xbean-server/src/main/java/org/apache/xbean/server/classloader/NamedClassLoader.java Tue Aug 1 08:15:02 2006
@@ -32,6 +32,7 @@
*/
public class NamedClassLoader extends URLClassLoader implements DestroyableClassLoader {
private final String name;
+ private boolean destroyed = false;
/**
* Creates a named class loader with no parents.
@@ -68,9 +69,21 @@
}
/**
+ * Check if this classloader has been destroyed
+ * @return
+ */
+ public synchronized boolean isDestroyed() {
+ return destroyed;
+ }
+
+ /**
* {@inheritDoc}
*/
public void destroy() {
+ synchronized(this) {
+ if (destroyed) return;
+ destroyed = true;
+ }
ClassLoaderUtil.destroy(this);
}
Added: geronimo/xbean/trunk/xbean-server/src/main/java/org/apache/xbean/server/classloader/ResourceEnumeration.java
URL: http://svn.apache.org/viewvc/geronimo/xbean/trunk/xbean-server/src/main/java/org/apache/xbean/server/classloader/ResourceEnumeration.java?rev=427602&view=auto
==============================================================================
--- geronimo/xbean/trunk/xbean-server/src/main/java/org/apache/xbean/server/classloader/ResourceEnumeration.java (added)
+++ geronimo/xbean/trunk/xbean-server/src/main/java/org/apache/xbean/server/classloader/ResourceEnumeration.java Tue Aug 1 08:15:02 2006
@@ -0,0 +1,83 @@
+/**
+ *
+ * Copyright 2005 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.xbean.server.classloader;
+
+import java.util.Enumeration;
+import java.util.Iterator;
+import java.util.Collection;
+import java.util.NoSuchElementException;
+
+/**
+ * @version $Rev: 410741 $ $Date: 2006-06-01 06:35:48 +0200 (Thu, 01 Jun 2006) $
+ */
+public class ResourceEnumeration implements Enumeration {
+ private Iterator iterator;
+ private final String resourceName;
+ private Object next;
+
+ public ResourceEnumeration(Collection resourceLocations, String resourceName) {
+ this.iterator = resourceLocations.iterator();
+ this.resourceName = resourceName;
+ }
+
+ public boolean hasMoreElements() {
+ fetchNext();
+ return (next != null);
+ }
+
+ public Object nextElement() {
+ fetchNext();
+
+ // save next into a local variable and clear the next field
+ Object next = this.next;
+ this.next = null;
+
+ // if we didn't have a next throw an exception
+ if (next == null) {
+ throw new NoSuchElementException();
+ }
+ return next;
+ }
+
+ private void fetchNext() {
+ if (iterator == null) {
+ return;
+ }
+ if (next != null) {
+ return;
+ }
+
+ try {
+ while (iterator.hasNext()) {
+ ResourceLocation resourceLocation = (ResourceLocation) iterator.next();
+ ResourceHandle resourceHandle = resourceLocation.getResourceHandle(resourceName);
+ if (resourceHandle != null) {
+ next = resourceHandle.getUrl();
+ return;
+ }
+ }
+ // no more elements
+ // clear the iterator so it can be GCed
+ iterator = null;
+ } catch (IllegalStateException e) {
+ // Jar file was closed... this means the resource finder was destroyed
+ // clear the iterator so it can be GCed
+ iterator = null;
+ throw e;
+ }
+ }
+}
Added: geronimo/xbean/trunk/xbean-server/src/main/java/org/apache/xbean/server/classloader/ResourceFinder.java
URL: http://svn.apache.org/viewvc/geronimo/xbean/trunk/xbean-server/src/main/java/org/apache/xbean/server/classloader/ResourceFinder.java?rev=427602&view=auto
==============================================================================
--- geronimo/xbean/trunk/xbean-server/src/main/java/org/apache/xbean/server/classloader/ResourceFinder.java (added)
+++ geronimo/xbean/trunk/xbean-server/src/main/java/org/apache/xbean/server/classloader/ResourceFinder.java Tue Aug 1 08:15:02 2006
@@ -0,0 +1,55 @@
+/**
+ *
+ * Copyright 2005 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.xbean.server.classloader;
+
+import java.net.URL;
+import java.util.Enumeration;
+
+/**
+ * Abstraction of resource searching policy. Given resource name, the resource
+ * finder performs implementation-specific lookup, and, if it is able to locate
+ * the resource, returns the {@link AbstractResourceHandle handle(s)} or URL(s) of it.
+ *
+ * @version $Rev: 410741 $ $Date: 2006-06-01 06:35:48 +0200 (Thu, 01 Jun 2006) $
+ */
+public interface ResourceFinder {
+ /**
+ * Find the resource by name and return URL of it if found.
+ *
+ * @param name the resource name
+ * @return resource URL or null if resource was not found
+ */
+ public URL findResource(String name);
+
+ /**
+ * Find all resources with given name and return enumeration of their URLs.
+ *
+ * @param name the resource name
+ * @return enumeration of resource URLs (possibly empty).
+ */
+ public Enumeration findResources(String name);
+
+ /**
+ * Get the resource by name and, if found, open connection to it and return
+ * the {@link AbstractResourceHandle handle} of it.
+ *
+ * @param name the resource name
+ * @return resource handle or null if resource was not found
+ */
+ public ResourceHandle getResource(String name);
+
+}
Added: geronimo/xbean/trunk/xbean-server/src/main/java/org/apache/xbean/server/classloader/ResourceHandle.java
URL: http://svn.apache.org/viewvc/geronimo/xbean/trunk/xbean-server/src/main/java/org/apache/xbean/server/classloader/ResourceHandle.java?rev=427602&view=auto
==============================================================================
--- geronimo/xbean/trunk/xbean-server/src/main/java/org/apache/xbean/server/classloader/ResourceHandle.java (added)
+++ geronimo/xbean/trunk/xbean-server/src/main/java/org/apache/xbean/server/classloader/ResourceHandle.java Tue Aug 1 08:15:02 2006
@@ -0,0 +1,97 @@
+/**
+ *
+ * Copyright 2005 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.xbean.server.classloader;
+
+import java.net.URL;
+import java.io.InputStream;
+import java.io.IOException;
+import java.util.jar.Manifest;
+import java.util.jar.Attributes;
+import java.security.cert.Certificate;
+
+/**
+ * This is a handle (a connection) to some resource, which may
+ * be a class, native library, text file, image, etc. Handles are returned
+ * by a ResourceFinder. A resource handle allows easy access to the resource data
+ * (using methods {@link #getInputStream} or {@link #getBytes}) as well as
+ * access resource metadata, such as attributes, certificates, etc.
+ * <p/>
+ * As soon as the handle is no longer in use, it should be explicitly
+ * {@link #close}d, similarly to I/O streams.
+ *
+ * @version $Rev: 410741 $ $Date: 2006-06-01 06:35:48 +0200 (Thu, 01 Jun 2006) $
+ */
+public interface ResourceHandle {
+ /**
+ * Return the name of the resource. The name is a "/"-separated path
+ * name that identifies the resource.
+ */
+ String getName();
+
+ /**
+ * Returns the URL of the resource.
+ */
+ URL getUrl();
+
+ /**
+ * Does this resource refer to a directory. Directory resources are commly used
+ * as the basis for a URL in client application. A directory resource has 0 bytes for it's content.
+ */
+ boolean isDirectory();
+
+ /**
+ * Returns the CodeSource URL for the class or resource.
+ */
+ URL getCodeSourceUrl();
+
+ /**
+ * Returns and InputStream for reading this resource data.
+ */
+ InputStream getInputStream() throws IOException;
+
+ /**
+ * Returns the length of this resource data, or -1 if unknown.
+ */
+ int getContentLength();
+
+ /**
+ * Returns this resource data as an array of bytes.
+ */
+ byte[] getBytes() throws IOException;
+
+ /**
+ * Returns the Manifest of the JAR file from which this resource
+ * was loaded, or null if none.
+ */
+ Manifest getManifest() throws IOException;
+
+ /**
+ * Return the Certificates of the resource, or null if none.
+ */
+ Certificate[] getCertificates();
+
+ /**
+ * Return the Attributes of the resource, or null if none.
+ */
+ Attributes getAttributes() throws IOException;
+
+ /**
+ * Closes a connection to the resource indentified by this handle. Releases
+ * any I/O objects associated with the handle.
+ */
+ void close();
+}
Added: geronimo/xbean/trunk/xbean-server/src/main/java/org/apache/xbean/server/classloader/ResourceLocation.java
URL: http://svn.apache.org/viewvc/geronimo/xbean/trunk/xbean-server/src/main/java/org/apache/xbean/server/classloader/ResourceLocation.java?rev=427602&view=auto
==============================================================================
--- geronimo/xbean/trunk/xbean-server/src/main/java/org/apache/xbean/server/classloader/ResourceLocation.java (added)
+++ geronimo/xbean/trunk/xbean-server/src/main/java/org/apache/xbean/server/classloader/ResourceLocation.java Tue Aug 1 08:15:02 2006
@@ -0,0 +1,32 @@
+/**
+ *
+ * Copyright 2005 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.xbean.server.classloader;
+
+import java.util.jar.Manifest;
+import java.io.IOException;
+import java.net.URL;
+
+/**
+ * This is a location which is searched by
+ * @version $Rev: 410741 $ $Date: 2006-06-01 06:35:48 +0200 (Thu, 01 Jun 2006) $
+ */
+public interface ResourceLocation {
+ URL getCodeSource();
+ ResourceHandle getResourceHandle(String resourceName);
+ Manifest getManifest() throws IOException;
+ void close();
+}
Added: geronimo/xbean/trunk/xbean-server/src/main/java/org/apache/xbean/server/classloader/UnionEnumeration.java
URL: http://svn.apache.org/viewvc/geronimo/xbean/trunk/xbean-server/src/main/java/org/apache/xbean/server/classloader/UnionEnumeration.java?rev=427602&view=auto
==============================================================================
--- geronimo/xbean/trunk/xbean-server/src/main/java/org/apache/xbean/server/classloader/UnionEnumeration.java (added)
+++ geronimo/xbean/trunk/xbean-server/src/main/java/org/apache/xbean/server/classloader/UnionEnumeration.java Tue Aug 1 08:15:02 2006
@@ -0,0 +1,63 @@
+/**
+ *
+ * Copyright 2005 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.xbean.server.classloader;
+
+import java.util.Enumeration;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.NoSuchElementException;
+
+/**
+ * @version $Rev: 410741 $ $Date: 2006-06-01 06:35:48 +0200 (Thu, 01 Jun 2006) $
+ */
+public final class UnionEnumeration implements Enumeration {
+ private final LinkedList enumerations = new LinkedList();
+
+ public UnionEnumeration(List enumerations) {
+ this.enumerations.addAll(enumerations);
+ }
+
+ public UnionEnumeration(Enumeration first, Enumeration second) {
+ if (first == null) throw new NullPointerException("first is null");
+ if (second == null) throw new NullPointerException("second is null");
+
+ enumerations.add(first);
+ enumerations.add(second);
+ }
+
+ public boolean hasMoreElements() {
+ while (!enumerations.isEmpty()) {
+ Enumeration enumeration = (Enumeration) enumerations.getFirst();
+ if (enumeration.hasMoreElements()) {
+ return true;
+ }
+ enumerations.removeFirst();
+ }
+ return false;
+ }
+
+ public Object nextElement() {
+ while (!enumerations.isEmpty()) {
+ Enumeration enumeration = (Enumeration) enumerations.getFirst();
+ if (enumeration.hasMoreElements()) {
+ return enumeration.nextElement();
+ }
+ enumerations.removeFirst();
+ }
+ throw new NoSuchElementException();
+ }
+}
|