/*
 * JBoss, Home of Professional Open Source
 * Copyright 2009, Red Hat Middleware LLC, and individual contributors
 * by the @authors tag. See the copyright.txt in the distribution for a
 * full listing of individual contributors.
 *
 * 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.jboss.shrinkwrap.api;

/**
 * A Factory for {@link ArchivePath} creation. Instances using this shorthand class will be created using the
 * {@link ClassLoader} associated with the default {@link Domain}'s {@link Configuration}.
 *
 * @author <a href="mailto:aslak@conduct.no">Aslak Knutsen</a>
 * @version $Revision: $
 */
public final class ArchivePaths {
    // -------------------------------------------------------------------------------------||
    // Class Members ----------------------------------------------------------------------||
    // -------------------------------------------------------------------------------------||

    private static final String PATH_IMPL = "org.jboss.shrinkwrap.impl.base.path.BasicPath";

    /**
     * Creates a new {@link ArchivePath} representing the root path (/).
     *
     * @return a new root path
     */
    public static ArchivePath root() {
        return RootPathWrapper.INSTANCE.getRoot();
    }

    /**
     * Creates a new {@link ArchivePath} with the specified context
     *
     * @param context
     *            The context which this path represents. Null or blank represents the root. Relative paths will be
     *            adjusted to absolute form.
     * @return a new path
     */
    public static ArchivePath create(String context) {
        return createInstance(new Class<?>[] { String.class }, new Object[] { context });
    }

    /**
     * Creates a new {@link ArchivePath} using the specified base and specified relative context.
     *
     * @param basePath
     *            A absolute path
     * @param context
     *            A relative path to basePath
     * @return a new path
     */
    public static ArchivePath create(String basePath, String context) {
        return createInstance(new Class<?>[] { String.class, String.class }, new Object[] { basePath, context });
    }

    /**
     * Creates a new {@link ArchivePath} using the specified base and specified relative context.
     *
     * @param basePath
     *            A absolute path
     * @param context
     *            A relative path to basePath
     * @return a new path
     */
    public static ArchivePath create(final String basePath, final ArchivePath context) {
        return createInstance(new Class<?>[] { String.class, ArchivePath.class }, new Object[] { basePath, context });
    }

    /**
     * Creates a new {@link ArchivePath} using the specified base and specified relative context.
     *
     * @param basePath
     *            A absolute path
     * @param context
     *            A relative path to basePath
     * @return a new path
     */
    public static ArchivePath create(ArchivePath basePath, String context) {
        return createInstance(new Class<?>[] { ArchivePath.class, String.class }, new Object[] { basePath, context });
    }

    /**
     * Creates a new {@link ArchivePath} using the specified base and specified relative context.
     *
     * @param basePath
     *            A absolute path
     * @param context
     *            A relative path to basePath
     * @return a new path
     */
    public static ArchivePath create(ArchivePath basePath, ArchivePath context) {
        return createInstance(new Class<?>[] { ArchivePath.class, ArchivePath.class },
            new Object[] { basePath, context });
    }

    // -------------------------------------------------------------------------------------||
    // Class Members - Internal Helpers ---------------------------------------------------||
    // -------------------------------------------------------------------------------------||

    private static ArchivePath createInstance(final Class<?>[] argumentTypes, final Object[] arguments) {
        // Get the impl class
        final Class<?> archivePathImplClass;
        try {
            archivePathImplClass = ClassLoaderSearchUtil.findClassFromClassLoaders(PATH_IMPL, ShrinkWrap
                .getDefaultDomain().getConfiguration().getClassLoaders());
        } catch (final ClassNotFoundException cnfe) {
            throw new IllegalStateException("Could not find the archive path implementation class " + PATH_IMPL
                + " in any configured ClassLoader", cnfe);
        }

        // Create and return
        return SecurityActions.newInstance(archivePathImplClass, argumentTypes, arguments, ArchivePath.class);
    }

    /**
     * Singleton wrapper to obtain a root {@link ArchivePath}
     *
     * @author <a href="mailto:andrew.rubinger@jboss.org">ALR</a>
     * @version $Revision: $
     */
    private enum RootPathWrapper {
        INSTANCE;
        private ArchivePath root = create(null);

        private ArchivePath getRoot() {
            return root;
        }
    }

    // -------------------------------------------------------------------------------------||
    // Constructor ------------------------------------------------------------------------||
    // -------------------------------------------------------------------------------------||

    /**
     * No instantiation
     */
    private ArchivePaths() {
    }

}

@@ -813,16 +813,74 @@
 p.api;%0A%0A
+import java.util.ArrayList;%0Aimport java.util.Collection;%0A%0A
 /**%0A * A
@@ -1150,444 +1150,799 @@
  * @
-version $Revision: $%0A */%0Apublic final class ArchivePaths %7B%0A    // -------------------------------------------------------------------------------------%7C%7C%0A    // Class Members ----------------------------------------------------------------------%7C%7C%0A    // -------------------------------------------------------------------------------------%7C%7C%0A%0A    private static final String PATH_IMPL = %22org.jboss.shrinkwrap.impl.base.path.BasicPath%22;
+author %3Ca href=%22mailto:alr@jboss.org%22%3EAndrew Lee Rubinger%3C/a%3E%0A */%0Apublic final class ArchivePaths %7B%0A%0A    private static final String PATH_IMPL = %22org.jboss.shrinkwrap.impl.base.path.BasicPath%22;%0A%0A    private static final Class%3C?%3E archivePathImplClass;%0A    static %7B%0A        final Collection%3CClassLoader%3E searchClassLoaders = new ArrayList%3CClassLoader%3E();%0A        searchClassLoaders.add(ArchivePaths.class.getClassLoader());%0A        try %7B%0A            archivePathImplClass = ClassLoaderSearchUtil.findClassFromClassLoaders(PATH_IMPL, searchClassLoaders);%0A        %7D catch (final ClassNotFoundException cnfe) %7B%0A            throw new IllegalStateException(%22Could not find the archive path implementation class %22 + PATH_IMPL%0A                + %22 in any configured ClassLoader%22, cnfe);%0A        %7D%0A    %7D
 %0A%0A  
@@ -4934,513 +4934,8 @@
 ) %7B%0A
-        // Get the impl class%0A        final Class%3C?%3E archivePathImplClass;%0A        try %7B%0A            archivePathImplClass = ClassLoaderSearchUtil.findClassFromClassLoaders(PATH_IMPL, ShrinkWrap%0A                .getDefaultDomain().getConfiguration().getClassLoaders());%0A        %7D catch (final ClassNotFoundException cnfe) %7B%0A            throw new IllegalStateException(%22Could not find the archive path implementation class %22 + PATH_IMPL%0A                + %22 in any configured ClassLoader%22, cnfe);%0A        %7D%0A%0A
     
@@ -4959,16 +4959,16 @@
  return%0A
+
         
@@ -5310,16 +5310,16 @@
 STANCE;%0A
-
         
@@ -5318,32 +5318,38 @@
         private 
+final 
 ArchivePath root

Add ArchivePaths.class.classloader to those CLs consulted in finding the ClassLoader to load the ArchivePath implementation class