airavata-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From lah...@apache.org
Subject svn commit: r1468558 - in /airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/gfac: deployment/ deployment/classloaders/ utils/
Date Tue, 16 Apr 2013 18:57:43 GMT
Author: lahiru
Date: Tue Apr 16 18:57:42 2013
New Revision: 1468558

URL: http://svn.apache.org/r1468558
Log:
adding initial version of gfac-archives.

Added:
    airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/gfac/deployment/
    airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/gfac/deployment/DeploymentEngine.java
    airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/gfac/deployment/DeploymentException.java
    airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/gfac/deployment/ResourceFinder.java
    airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/gfac/deployment/classloaders/
    airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/gfac/deployment/classloaders/JarFileClassLoader.java
    airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/gfac/deployment/classloaders/MultiParentClassLoader.java
    airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/gfac/deployment/classloaders/ResourceHandle.java
    airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/gfac/deployment/classloaders/UrlResourceFinder.java
Modified:
    airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/gfac/utils/GFacUtils.java

Added: airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/gfac/deployment/DeploymentEngine.java
URL: http://svn.apache.org/viewvc/airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/gfac/deployment/DeploymentEngine.java?rev=1468558&view=auto
==============================================================================
--- airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/gfac/deployment/DeploymentEngine.java (added)
+++ airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/gfac/deployment/DeploymentEngine.java Tue Apr 16 18:57:42 2013
@@ -0,0 +1,54 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.airavata.gfac.deployment;
+
+import org.apache.airavata.gfac.GFacConfiguration;
+import org.apache.airavata.gfac.GFacException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.File;
+
+public class DeploymentEngine {
+    private static final Logger logger = LoggerFactory.getLogger(DeploymentEngine.class);
+
+    public static final String PLUGINS_DIR = "plugins";
+    private GFacConfiguration configuration = null;
+    private File repoPath = null;
+    private File extensionDirectory = null;
+    public DeploymentEngine(GFacConfiguration configuration) {
+        this.configuration = configuration;
+    }
+
+    public void loadRepository(String repoDir) throws DeploymentException {
+        repoPath = new File(repoDir);
+        if(!repoPath.exists()){
+            logger.error("repository path is missing");
+        }
+        if(extensionDirectory == null) {
+            extensionDirectory = new File(repoDir, PLUGINS_DIR);
+        }
+        if(!extensionDirectory.exists()){
+            logger.error("plugins directory is missing");
+        }
+    }
+
+}

Added: airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/gfac/deployment/DeploymentException.java
URL: http://svn.apache.org/viewvc/airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/gfac/deployment/DeploymentException.java?rev=1468558&view=auto
==============================================================================
--- airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/gfac/deployment/DeploymentException.java (added)
+++ airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/gfac/deployment/DeploymentException.java Tue Apr 16 18:57:42 2013
@@ -0,0 +1,34 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.airavata.gfac.deployment;
+
+import org.apache.airavata.gfac.GFacException;
+
+public class DeploymentException extends GFacException{
+    private static final long serialVersionUID = 1L;
+
+	public DeploymentException(String s) {
+        super(s);
+    }
+	public DeploymentException(String s, Throwable throwable) {
+        super(s, throwable);
+    }
+}

Added: airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/gfac/deployment/ResourceFinder.java
URL: http://svn.apache.org/viewvc/airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/gfac/deployment/ResourceFinder.java?rev=1468558&view=auto
==============================================================================
--- airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/gfac/deployment/ResourceFinder.java (added)
+++ airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/gfac/deployment/ResourceFinder.java Tue Apr 16 18:57:42 2013
@@ -0,0 +1,56 @@
+/**
+ *  Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  See the NOTICE file distributed with
+ *  this work for additional information regarding copyright ownership.
+ *  The ASF licenses this file to You 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.airavata.gfac.deployment;
+import org.apache.airavata.gfac.deployment.classloaders.ResourceHandle;
+
+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: 704201 $ $Date: 2008-10-13 14:52:25 -0400 (Mon, 13 Oct 2008) $
+ */
+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: airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/gfac/deployment/classloaders/JarFileClassLoader.java
URL: http://svn.apache.org/viewvc/airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/gfac/deployment/classloaders/JarFileClassLoader.java?rev=1468558&view=auto
==============================================================================
--- airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/gfac/deployment/classloaders/JarFileClassLoader.java (added)
+++ airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/gfac/deployment/classloaders/JarFileClassLoader.java Tue Apr 16 18:57:42 2013
@@ -0,0 +1,336 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.airavata.gfac.deployment.classloaders;
+
+import java.io.File;
+import java.io.IOException;
+import java.net.URI;
+import java.net.URL;
+import java.net.URLClassLoader;
+import java.security.*;
+import java.security.cert.Certificate;
+import java.util.Collection;
+import java.util.Enumeration;
+import java.util.jar.Attributes;
+import java.util.jar.Manifest;
+
+public class JarFileClassLoader extends MultiParentClassLoader{
+     private static final URL[] EMPTY_URLS = new URL[0];
+
+    private final UrlResourceFinder resourceFinder = new UrlResourceFinder();
+    private final AccessControlContext acc;
+
+    /**
+     * Creates a JarFileClassLoader that is a child of the system class loader.
+     * @param urls a list of URLs from which classes and resources should be loaded
+     */
+    public JarFileClassLoader(URL[] urls) {
+        super(EMPTY_URLS);
+        this.acc = AccessController.getContext();
+        addURLs(urls);
+    }
+
+    /**
+     * Creates a JarFileClassLoader that is a child of the specified class loader.
+     * @param urls a list of URLs from which classes and resources should be loaded
+     * @param parent the parent of this class loader
+     */
+    public JarFileClassLoader(URL[] urls, ClassLoader parent) {
+        super(EMPTY_URLS, parent);
+        this.acc = AccessController.getContext();
+        addURLs(urls);
+    }
+
+    public JarFileClassLoader(URL[] urls, ClassLoader parent, boolean inverseClassLoading, String[] hiddenClasses, String[] nonOverridableClasses) {
+        super(EMPTY_URLS, parent, inverseClassLoading, hiddenClasses, nonOverridableClasses);
+        this.acc = AccessController.getContext();
+        addURLs(urls);
+    }
+
+    /**
+     * Creates a named class loader as a child of the specified parents.
+     * @param urls the urls from which this class loader will classes and resources
+     * @param parents the parents of this class loader
+     */
+    public JarFileClassLoader(URL[] urls, ClassLoader[] parents) {
+        super(EMPTY_URLS, parents);
+        this.acc = AccessController.getContext();
+        addURLs(urls);
+    }
+
+    public JarFileClassLoader(URL[] urls, ClassLoader[] parents, boolean inverseClassLoading, Collection hiddenClasses, Collection nonOverridableClasses) {
+        super(EMPTY_URLS, parents, inverseClassLoading, hiddenClasses, nonOverridableClasses);
+        this.acc = AccessController.getContext();
+        addURLs(urls);
+    }
+
+    public JarFileClassLoader(URL[] urls, ClassLoader[] parents, boolean inverseClassLoading, String[] hiddenClasses, String[] nonOverridableClasses) {
+        super(EMPTY_URLS, parents, inverseClassLoading, hiddenClasses, nonOverridableClasses);
+        this.acc = AccessController.getContext();
+        addURLs(urls);
+    }
+
+    public JarFileClassLoader(JarFileClassLoader source) {
+        super(source);
+        this.acc = AccessController.getContext();
+        addURLs(source.getURLs());
+    }
+
+    public static ClassLoader copy(ClassLoader source) {
+        if (source instanceof JarFileClassLoader) {
+            return new JarFileClassLoader((JarFileClassLoader) source);
+        } else if (source instanceof org.apache.axis2.classloader.MultiParentClassLoader) {
+            return new org.apache.axis2.classloader.MultiParentClassLoader((org.apache.axis2.classloader.MultiParentClassLoader) source);
+        } else if (source instanceof URLClassLoader) {
+            return new URLClassLoader(((URLClassLoader)source).getURLs(), source.getParent());
+        } else {
+            return new URLClassLoader(new URL[0], source);
+        }
+    }
+
+    ClassLoader copy() {
+        return JarFileClassLoader.copy(this);
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public URL[] getURLs() {
+        return resourceFinder.getUrls();
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    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(final URL[] urls) {
+        AccessController.doPrivileged(new PrivilegedAction() {
+            public Object run() {
+                resourceFinder.addUrls(urls);
+                return null;
+            }
+        }, acc);
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public void destroy() {
+        resourceFinder.destroy();
+        super.destroy();
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public URL findResource(final String resourceName) {
+        return (URL) AccessController.doPrivileged(new PrivilegedAction() {
+            public Object run() {
+                return resourceFinder.findResource(resourceName);
+            }
+        }, acc);
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    protected Enumeration<URL> internalfindResources(final String name) throws IOException {
+        return  AccessController.doPrivileged(new PrivilegedAction<Enumeration<URL>>() {
+            public Enumeration<URL> run() {
+                return resourceFinder.findResources(name);
+            }
+        }, acc);
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    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);
+        }
+
+        // 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;
+        }
+
+        // the library must be accessable on the file system
+        URL url = resourceHandle.getUrl();
+        if (!"file".equals(url.getProtocol())) {
+            return null;
+        }
+
+        return new File(URI.create(url.toString())).getPath();
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    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);
+                        }
+                    }
+
+
+                    // 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);
+                    }
+
+                    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);
+                    }
+
+                    // 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
+                    return defineClass(className, bytes, 0, bytes.length, codeSource);
+                }
+            }, acc);
+        } catch (PrivilegedActionException e) {
+            throw (ClassNotFoundException) e.getException();
+        }
+    }
+
+    private void definePackage(String className, URL jarUrl, Manifest manifest) {
+        int packageEnd = className.lastIndexOf('.');
+        if (packageEnd < 0) {
+            return;
+        }
+
+        String packageName = className.substring(0, packageEnd);
+        String packagePath = packageName.replace('.', '/') + "/";
+
+        Attributes packageAttributes = null;
+        Attributes mainAttributes = null;
+        if (manifest != null) {
+            packageAttributes = manifest.getAttributes(packagePath);
+            mainAttributes = manifest.getMainAttributes();
+        }
+        Package pkg = getPackage(packageName);
+        if (pkg != null) {
+            if (pkg.isSealed()) {
+                if (!pkg.isSealed(jarUrl)) {
+                    throw new SecurityException("Package was already sealed with another URL: package=" + packageName + ", url=" + jarUrl);
+                }
+            } else {
+                if (isSealed(packageAttributes, mainAttributes)) {
+                    throw new SecurityException("Package was already been loaded and not sealed: package=" + packageName + ", url=" + jarUrl);
+                }
+            }
+        } else {
+            String specTitle = getAttribute(Attributes.Name.SPECIFICATION_TITLE, packageAttributes, mainAttributes);
+            String specVendor = getAttribute(Attributes.Name.SPECIFICATION_VENDOR, packageAttributes, mainAttributes);
+            String specVersion = getAttribute(Attributes.Name.SPECIFICATION_VERSION, packageAttributes, mainAttributes);
+            String implTitle = getAttribute(Attributes.Name.IMPLEMENTATION_TITLE, packageAttributes, mainAttributes);
+            String implVendor = getAttribute(Attributes.Name.IMPLEMENTATION_VENDOR, packageAttributes, mainAttributes);
+            String implVersion = getAttribute(Attributes.Name.IMPLEMENTATION_VERSION, packageAttributes, mainAttributes);
+
+            URL sealBase = null;
+            if (isSealed(packageAttributes, mainAttributes)) {
+                sealBase = jarUrl;
+            }
+
+            definePackage(packageName, specTitle, specVersion, specVendor, implTitle, implVersion, implVendor, sealBase);
+        }
+    }
+
+    private String getAttribute(Attributes.Name name, Attributes packageAttributes, Attributes mainAttributes) {
+        if (packageAttributes != null) {
+            String value = packageAttributes.getValue(name);
+            if (value != null) {
+                return value;
+            }
+        }
+        if (mainAttributes != null) {
+            return mainAttributes.getValue(name);
+        }
+        return null;
+    }
+
+    private boolean isSealed(Attributes packageAttributes, Attributes mainAttributes) {
+        String sealed = getAttribute(Attributes.Name.SEALED, packageAttributes, mainAttributes);
+        return sealed != null && "true".equalsIgnoreCase(sealed);
+    }
+}

Added: airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/gfac/deployment/classloaders/MultiParentClassLoader.java
URL: http://svn.apache.org/viewvc/airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/gfac/deployment/classloaders/MultiParentClassLoader.java?rev=1468558&view=auto
==============================================================================
--- airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/gfac/deployment/classloaders/MultiParentClassLoader.java (added)
+++ airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/gfac/deployment/classloaders/MultiParentClassLoader.java Tue Apr 16 18:57:42 2013
@@ -0,0 +1,485 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.airavata.gfac.deployment.classloaders;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.
+ */
+
+import org.apache.commons.logging.LogFactory;
+
+import java.beans.Introspector;
+import java.io.IOException;
+import java.net.URL;
+import java.net.URLClassLoader;
+import java.net.URLStreamHandlerFactory;
+import java.util.*;
+
+
+import org.apache.commons.logging.LogFactory;
+
+import java.beans.Introspector;
+import java.io.IOException;
+import java.net.URL;
+import java.net.URLClassLoader;
+import java.net.URLStreamHandlerFactory;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Enumeration;
+import java.util.List;
+
+/**
+ * A MultiParentClassLoader is a simple extension of the URLClassLoader that simply changes the single parent class
+ * loader model to support a list of parent class loaders.  Each operation that accesses a parent, has been replaced
+ * with a operation that checks each parent in order.  This getParent method of this class will always return null,
+ * which may be interpreted by the calling code to mean that this class loader is a direct child of the system class
+ * loader.
+ *
+ * @version $Rev$ $Date$
+ */
+public class MultiParentClassLoader extends URLClassLoader {
+    private final ClassLoader[] parents;
+    private final boolean inverseClassLoading;
+    private final String[] hiddenClasses;
+    private final String[] nonOverridableClasses;
+    private final String[] hiddenResources;
+    private final String[] nonOverridableResources;
+    private boolean destroyed = false;
+
+    /**
+     * Creates a named class loader with no parents.
+     *
+     * @param urls the urls from which this class loader will classes and resources
+     */
+    public MultiParentClassLoader(URL[] urls) {
+        super(urls);
+        parents = new ClassLoader[]{ClassLoader.getSystemClassLoader()};
+        inverseClassLoading = false;
+        hiddenClasses = new String[0];
+        nonOverridableClasses = new String[0];
+        hiddenResources = new String[0];
+        nonOverridableResources = new String[0];
+    }
+
+
+    /**
+     * Creates a named class loader as a child of the specified parent.
+     *
+     * @param urls   the urls from which this class loader will classes and resources
+     * @param parent the parent of this class loader
+     */
+    public MultiParentClassLoader(URL[] urls, ClassLoader parent) {
+        this(urls, new ClassLoader[]{parent});
+    }
+
+    public MultiParentClassLoader(URL[] urls, ClassLoader parent, boolean inverseClassLoading,
+                                  String[] hiddenClasses, String[] nonOverridableClasses) {
+        this(urls, new ClassLoader[]{parent}, inverseClassLoading, hiddenClasses,
+             nonOverridableClasses);
+    }
+
+    /**
+     * Creates a named class loader as a child of the specified parent and using the specified URLStreamHandlerFactory
+     * for accessing the urls..
+     *
+     * @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 MultiParentClassLoader(URL[] urls, ClassLoader parent, URLStreamHandlerFactory factory) {
+        this(urls, new ClassLoader[]{parent}, factory);
+    }
+
+    /**
+     * Creates a named class loader as a child of the specified parents.
+     *
+     * @param urls    the urls from which this class loader will classes and resources
+     * @param parents the parents of this class loader
+     */
+    public MultiParentClassLoader(URL[] urls, ClassLoader[] parents) {
+        super(urls);
+        this.parents = copyParents(parents);
+        inverseClassLoading = false;
+        hiddenClasses = new String[0];
+        nonOverridableClasses = new String[0];
+        hiddenResources = new String[0];
+        nonOverridableResources = new String[0];
+    }
+
+    public MultiParentClassLoader(URL[] urls, ClassLoader[] parents, boolean inverseClassLoading,
+                                  Collection hiddenClasses, Collection nonOverridableClasses) {
+        this(urls, parents, inverseClassLoading,
+             (String[]) hiddenClasses.toArray(new String[hiddenClasses.size()]),
+             (String[]) nonOverridableClasses.toArray(new String[nonOverridableClasses.size()]));
+    }
+
+    public MultiParentClassLoader(URL[] urls, ClassLoader[] parents, boolean inverseClassLoading,
+                                  String[] hiddenClasses, String[] nonOverridableClasses) {
+        super(urls);
+        this.parents = copyParents(parents);
+        this.inverseClassLoading = inverseClassLoading;
+        this.hiddenClasses = hiddenClasses;
+        this.nonOverridableClasses = nonOverridableClasses;
+        hiddenResources = toResources(hiddenClasses);
+        nonOverridableResources = toResources(nonOverridableClasses);
+    }
+
+    public MultiParentClassLoader(MultiParentClassLoader source) {
+        this(source.getURLs(), deepCopyParents(source.parents), source.inverseClassLoading, source.hiddenClasses, source.nonOverridableClasses);
+    }
+
+    static ClassLoader copy(ClassLoader source) {
+        if (source instanceof MultiParentClassLoader) {
+            return new MultiParentClassLoader((MultiParentClassLoader) source);
+        } else if (source instanceof URLClassLoader) {
+            return new URLClassLoader(((URLClassLoader) source).getURLs(), source.getParent());
+        } else {
+            return new URLClassLoader(new URL[0], source);
+        }
+    }
+
+    ClassLoader copy() {
+        return MultiParentClassLoader.copy(this);
+    }
+
+    private 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;
+    }
+
+    /**
+     * Creates a named class loader as a child of the specified parents and using the specified URLStreamHandlerFactory
+     * for accessing the urls..
+     *
+     * @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 MultiParentClassLoader(URL[] urls, ClassLoader[] parents,
+                                  URLStreamHandlerFactory factory) {
+        super(urls, null, factory);
+        this.parents = copyParents(parents);
+        inverseClassLoading = false;
+        hiddenClasses = new String[0];
+        nonOverridableClasses = new String[0];
+        hiddenResources = new String[0];
+        nonOverridableResources = new String[0];
+    }
+
+    private static ClassLoader[] copyParents(ClassLoader[] parents) {
+        ClassLoader[] newParentsArray = new ClassLoader[parents.length];
+        for (int i = 0; i < parents.length; i++) {
+            ClassLoader parent = parents[i];
+            if (parent == null) {
+                throw new RuntimeException("parent[" + i + "] is null");
+            }
+            newParentsArray[i] = parent;
+        }
+        return newParentsArray;
+    }
+
+    private static ClassLoader[] deepCopyParents(ClassLoader[] parents) {
+        ClassLoader[] newParentsArray = new ClassLoader[parents.length];
+        for (int i = 0; i < parents.length; i++) {
+            ClassLoader parent = parents[i];
+            if (parent == null) {
+                throw new RuntimeException("parent[" + i + "] is null");
+            }
+            if (parent instanceof MultiParentClassLoader) {
+                parent = ((MultiParentClassLoader) parent).copy();
+            }
+            newParentsArray[i] = parent;
+        }
+        return newParentsArray;
+    }
+
+    /**
+     * Gets the parents of this class loader.
+     *
+     * @return the parents of this class loader
+     */
+    public ClassLoader[] getParents() {
+        return parents;
+    }
+
+    public void addURL(URL url) {
+        // todo this needs a security check
+        super.addURL(url);
+    }
+
+    protected synchronized Class loadClass(String name, boolean resolve)
+            throws ClassNotFoundException {
+        //
+        // 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 {
+                Class clazz = findClass(name);
+                return resolveClass(clazz, resolve);
+            } catch (ClassNotFoundException ignored) {
+            }
+        }
+
+        //
+        // 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
+                    //  TODO REVIEW FOR JAVA 6
+                    // In Java 5, if you passed an array string such as "[Lcom.mypackage.MyClass;" to
+                    // loadClass, the class would indeed be loaded.
+                    // In JDK6, a ClassNotFoundException is thrown.
+                    // The work-around is to use code Class.forName instead.
+                    // Example:
+                    // try {
+                    //       classLoader.loadClass(name);
+                    //  } catch (ClassNotFoundException e) {
+                    //       Class.forName(name, false, loader);
+                    //  }
+                }
+            }
+        }
+
+        //
+        // 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);
+    }
+
+    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 false;
+    }
+
+    private Class resolveClass(Class clazz, boolean resolve) {
+        if (resolve) {
+            resolveClass(clazz);
+        }
+        return clazz;
+    }
+
+    public URL getResource(String name) {
+        if (isDestroyed()) {
+            return 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 findResource(name);
+        }
+
+        return null;
+    }
+
+    public Enumeration findResources(String name) throws IOException {
+        if (isDestroyed()) {
+            return Collections.enumeration(Collections.EMPTY_SET);
+        }
+
+        List resources = new ArrayList();
+
+        //
+        // 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);
+        }
+
+        //
+        // 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 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;
+    }
+
+    public String toString() {
+        return "[" + getClass().getName() + "]";
+    }
+
+    public synchronized boolean isDestroyed() {
+        return destroyed;
+    }
+
+    public void destroy() {
+        synchronized (this) {
+            if (destroyed) {
+                return;
+            }
+            destroyed = true;
+        }
+
+        LogFactory.release(this);
+//        clearSoftCache(ObjectInputStream.class, "subclassAudits");
+//        clearSoftCache(ObjectOutputStream.class, "subclassAudits");
+//        clearSoftCache(ObjectStreamClass.class, "localDescs");
+//        clearSoftCache(ObjectStreamClass.class, "reflectors");
+
+        // The beanInfoCache in java.beans.Introspector will hold on to Classes which
+        // it has introspected. If we don't flush the cache, we may run out of
+        // Permanent Generation space.
+        Introspector.flushCaches();
+    }
+
+//    private static final Object lock = new Object();
+//    private static boolean clearSoftCacheFailed = false;
+//
+//    private static void clearSoftCache(Class clazz, String fieldName) {
+//        Map cache = null;
+//        try {
+//            Field f = clazz.getDeclaredField(fieldName);
+//            f.setAccessible(true);
+//            cache = (Map) f.get(null);
+//        } catch (Throwable e) {
+//            synchronized (lock) {
+//                if (!clearSoftCacheFailed) {
+//                    clearSoftCacheFailed = true;
+//                    LogFactory.getLog(ConfigurationClassLoader.class).error("Unable to clear SoftCache field " + fieldName + " in class " + clazz);
+//                }
+//            }
+//        }
+//
+//        if (cache != null) {
+//            synchronized (cache) {
+//                cache.clear();
+//            }
+//        }
+//    }
+
+}

Added: airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/gfac/deployment/classloaders/ResourceHandle.java
URL: http://svn.apache.org/viewvc/airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/gfac/deployment/classloaders/ResourceHandle.java?rev=1468558&view=auto
==============================================================================
--- airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/gfac/deployment/classloaders/ResourceHandle.java (added)
+++ airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/gfac/deployment/classloaders/ResourceHandle.java Tue Apr 16 18:57:42 2013
@@ -0,0 +1,101 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.airavata.gfac.deployment.classloaders;
+
+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: 704201 $ $Date: 2008-10-13 14:52:25 -0400 (Mon, 13 Oct 2008) $
+ */
+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: airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/gfac/deployment/classloaders/UrlResourceFinder.java
URL: http://svn.apache.org/viewvc/airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/gfac/deployment/classloaders/UrlResourceFinder.java?rev=1468558&view=auto
==============================================================================
--- airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/gfac/deployment/classloaders/UrlResourceFinder.java (added)
+++ airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/gfac/deployment/classloaders/UrlResourceFinder.java Tue Apr 16 18:57:42 2013
@@ -0,0 +1,316 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.airavata.gfac.deployment.classloaders;
+
+
+import org.apache.airavata.gfac.deployment.ResourceFinder;
+import org.apache.axis2.classloader.DirectoryResourceLocation;
+import org.apache.axis2.classloader.JarResourceLocation;
+import org.apache.axis2.classloader.ResourceEnumeration;
+import org.apache.axis2.classloader.ResourceLocation;
+
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.*;
+import java.util.jar.Attributes;
+import java.util.jar.Manifest;
+
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.Enumeration;
+import java.util.LinkedHashMap;
+import java.util.LinkedHashSet;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+import java.util.StringTokenizer;
+import java.util.jar.Attributes;
+import java.util.jar.Manifest;
+
+/**
+ * @version $Rev: 704201 $ $Date: 2008-10-13 14:52:25 -0400 (Mon, 13 Oct 2008) $
+ */
+public class UrlResourceFinder implements ResourceFinder {
+    private final Object lock = new Object();
+    private final LinkedHashSet<URL> urls = new LinkedHashSet<URL>();
+    private final LinkedHashMap<URL, ResourceLocation> classPath = new LinkedHashMap<URL, ResourceLocation>();
+    private final LinkedHashSet<File> watchedFiles = new LinkedHashSet<File>();
+
+    private boolean destroyed = false;
+
+    public UrlResourceFinder() {
+    }
+
+    public UrlResourceFinder(URL[] urls) {
+        addUrls(urls);
+    }
+
+    public void destroy() {
+        synchronized (lock) {
+            if (destroyed) {
+                return;
+            }
+            destroyed = true;
+            urls.clear();
+            for (ResourceLocation resourceLocation : classPath.values()) {
+                resourceLocation.close();
+            }
+            classPath.clear();
+        }
+    }
+
+    public ResourceHandle getResource(String resourceName) {
+        synchronized (lock) {
+            if (destroyed) {
+                return null;
+            }
+            for (Map.Entry<URL, ResourceLocation> entry : getClassPath().entrySet()) {
+                ResourceLocation resourceLocation = entry.getValue();
+                ResourceHandle resourceHandle = (ResourceHandle) resourceLocation.getResourceHandle(resourceName);
+                if (resourceHandle != null && !resourceHandle.isDirectory()) {
+                    return resourceHandle;
+                }
+            }
+        }
+        return null;
+    }
+
+    public URL findResource(String resourceName) {
+        synchronized (lock) {
+            if (destroyed) {
+                return null;
+            }
+            for (Map.Entry<URL, ResourceLocation> entry : getClassPath().entrySet()) {
+                ResourceLocation resourceLocation = entry.getValue();
+                ResourceHandle resourceHandle = (ResourceHandle) resourceLocation.getResourceHandle(resourceName);
+                if (resourceHandle != null) {
+                    return resourceHandle.getUrl();
+                }
+            }
+        }
+        return null;
+    }
+
+    public Enumeration findResources(String resourceName) {
+        synchronized (lock) {
+            return new ResourceEnumeration(new ArrayList<ResourceLocation>(getClassPath().values()), resourceName);
+        }
+    }
+
+    public void addUrl(URL url) {
+        addUrls(Collections.singletonList(url));
+    }
+
+    public URL[] getUrls() {
+        synchronized (lock) {
+            return urls.toArray(new URL[urls.size()]);
+        }
+    }
+
+    /**
+     * 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));
+    }
+
+    /**
+     * Adds a list of urls to the end of this class loader.
+     *
+     * @param urls the URLs to add
+     */
+    protected void addUrls(List<URL> urls) {
+        synchronized (lock) {
+            if (destroyed) {
+                throw new IllegalStateException("UrlResourceFinder has been destroyed");
+            }
+
+            boolean shouldRebuild = this.urls.addAll(urls);
+            if (shouldRebuild) {
+                rebuildClassPath();
+            }
+        }
+    }
+
+    private LinkedHashMap<URL, ResourceLocation> getClassPath() {
+        assert Thread.holdsLock(lock) : "This method can only be called while holding the lock";
+
+        for (File file : watchedFiles) {
+            if (file.canRead()) {
+                rebuildClassPath();
+                break;
+            }
+        }
+
+        return classPath;
+    }
+
+    /**
+     * Rebuilds the entire class path.  This class is called when new URLs are added or one of the watched files
+     * becomes readable.  This method will not open jar files again, but will add any new entries not alredy open
+     * to the class path.  If any file based url is does not exist, we will watch for that file to appear.
+     */
+    private void rebuildClassPath() {
+        assert Thread.holdsLock(lock) : "This method can only be called while holding the lock";
+
+        // copy all of the existing locations into a temp map and clear the class path
+        Map<URL, ResourceLocation> existingJarFiles = new LinkedHashMap<URL, ResourceLocation>(classPath);
+        classPath.clear();
+
+        LinkedList<URL> locationStack = new LinkedList<URL>(urls);
+        try {
+            while (!locationStack.isEmpty()) {
+                URL url = locationStack.removeFirst();
+
+                // Skip any duplicate urls in the classpath
+                if (classPath.containsKey(url)) {
+                    continue;
+                }
+
+                // Check is this URL has already been opened
+                ResourceLocation resourceLocation = existingJarFiles.remove(url);
+
+                // If not opened, cache the url and wrap it with a resource location
+                if (resourceLocation == null) {
+                    try {
+                        File file = cacheUrl(url);
+                        resourceLocation = createResourceLocation(url, file);
+                    } catch (FileNotFoundException e) {
+                        // if this is a file URL, the file doesn't exist yet... watch to see if it appears later
+                        if ("file".equals(url.getProtocol())) {
+                            File file = new File(url.getPath());
+                            watchedFiles.add(file);
+                            continue;
+
+                        }
+                    } catch (IOException ignored) {
+                        // can't seem to open the file... this is most likely a bad jar file
+                        // so don't keep a watch out for it because that would require lots of checking
+                        // Dain: We may want to review this decision later
+                        continue;
+                    } catch (UnsupportedOperationException ex) {
+                        // the protocol for the JAR file's URL is not supported.  This can occur when
+                        // the jar file is embedded in an EAR or CAR file.  Proceed but log the message.
+                        System.out.println("The protocol for the JAR file's URL is not supported" + ex);
+                        continue;
+                    }
+                }
+
+                // add the jar to our class path
+                classPath.put(resourceLocation.getCodeSource(), resourceLocation);
+
+                // push the manifest classpath on the stack (make sure to maintain the order)
+                List<URL> manifestClassPath = getManifestClassPath(resourceLocation);
+                locationStack.addAll(0, manifestClassPath);
+            }
+        } catch (Error e) {
+            destroy();
+            throw e;
+        }
+
+        for (ResourceLocation resourceLocation : existingJarFiles.values()) {
+            resourceLocation.close();
+        }
+    }
+
+    protected File cacheUrl(URL url) throws IOException {
+        if (!"file".equals(url.getProtocol())) {
+            // download the jar
+            throw new UnsupportedOperationException("Only local file jars are supported " + url);
+        }
+
+        File file = new File(url.getPath());
+        if (!file.exists()) {
+            throw new FileNotFoundException(file.getAbsolutePath());
+        }
+        if (!file.canRead()) {
+            throw new IOException("File is not readable: " + file.getAbsolutePath());
+        }
+        return file;
+    }
+
+    protected ResourceLocation createResourceLocation(URL codeSource, File cacheFile) throws IOException {
+        if (!cacheFile.exists()) {
+            throw new FileNotFoundException(cacheFile.getAbsolutePath());
+        }
+        if (!cacheFile.canRead()) {
+            throw new IOException("File is not readable: " + cacheFile.getAbsolutePath());
+        }
+
+        ResourceLocation resourceLocation;
+        if (cacheFile.isDirectory()) {
+            // DirectoryResourceLocation will only return "file" URLs within this directory
+            // do not user the DirectoryResourceLocation for non file based urls
+            resourceLocation = new DirectoryResourceLocation(cacheFile);
+        } else {
+            resourceLocation = new JarResourceLocation(codeSource, cacheFile);
+        }
+        return resourceLocation;
+    }
+
+    private List<URL> getManifestClassPath(ResourceLocation resourceLocation) {
+        try {
+            // get the manifest, if possible
+            Manifest manifest = resourceLocation.getManifest();
+            if (manifest == null) {
+                // some locations don't have a manifest
+                return Collections.EMPTY_LIST;
+            }
+
+            // get the class-path attribute, if possible
+            String manifestClassPath = manifest.getMainAttributes().getValue(Attributes.Name.CLASS_PATH);
+            if (manifestClassPath == null) {
+                return Collections.EMPTY_LIST;
+            }
+
+            // build the urls...
+            // the class-path attribute is space delimited
+            URL codeSource = resourceLocation.getCodeSource();
+            LinkedList<URL> classPathUrls = new LinkedList<URL>();
+            for (StringTokenizer tokenizer = new StringTokenizer(manifestClassPath, " "); tokenizer.hasMoreTokens(); ) {
+                String entry = tokenizer.nextToken();
+                try {
+                    // the class path entry is relative to the resource location code source
+                    URL entryUrl = new URL(codeSource, entry);
+                    classPathUrls.addLast(entryUrl);
+                } catch (MalformedURLException ignored) {
+                    // most likely a poorly named entry
+                }
+            }
+            return classPathUrls;
+        } catch (IOException ignored) {
+            // error opening the manifest
+            return Collections.EMPTY_LIST;
+        }
+    }
+}
+

Modified: airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/gfac/utils/GFacUtils.java
URL: http://svn.apache.org/viewvc/airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/gfac/utils/GFacUtils.java?rev=1468558&r1=1468557&r2=1468558&view=diff
==============================================================================
--- airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/gfac/utils/GFacUtils.java (original)
+++ airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/gfac/utils/GFacUtils.java Tue Apr 16 18:57:42 2013
@@ -22,20 +22,16 @@ package org.apache.airavata.gfac.utils;
 
 import org.apache.airavata.commons.gfac.type.ActualParameter;
 import org.apache.airavata.gfac.Constants;
+import org.apache.airavata.gfac.deployment.classloaders.JarFileClassLoader;
 import org.apache.airavata.schemas.gfac.*;
 import org.apache.axiom.om.OMElement;
+import org.apache.axis2.deployment.DeploymentException;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 import java.io.*;
-import java.net.InetAddress;
-import java.net.URI;
-import java.net.URISyntaxException;
-import java.net.UnknownHostException;
-import java.util.Arrays;
-import java.util.Date;
-import java.util.Iterator;
-import java.util.UUID;
+import java.net.*;
+import java.util.*;
 
 public class GFacUtils {
     private final static Logger log = LoggerFactory.getLogger(GFacUtils.class);



Mime
View raw message