[jboss-svn-commits] JBoss Common SVN: r3451 - in declarchive/trunk: api/src/main/java/org/jboss/declarchive/api and 10 other directories.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Mon Aug 17 05:41:50 EDT 2009
Author: ALRubinger
Date: 2009-08-17 05:41:49 -0400 (Mon, 17 Aug 2009)
New Revision: 3451
Added:
declarchive/trunk/impl-base/src/main/java/org/jboss/declarchive/impl/base/ArchiveBase.java
declarchive/trunk/impl-base/src/main/java/org/jboss/declarchive/impl/base/ResourceNotFoundException.java
declarchive/trunk/impl-base/src/main/java/org/jboss/declarchive/impl/base/resource/
declarchive/trunk/impl-base/src/main/java/org/jboss/declarchive/impl/base/resource/ClassResource.java
declarchive/trunk/impl-base/src/main/java/org/jboss/declarchive/impl/base/resource/ClassloaderResource.java
declarchive/trunk/impl-base/src/main/java/org/jboss/declarchive/impl/base/resource/FileResource.java
declarchive/trunk/impl-base/src/main/java/org/jboss/declarchive/impl/base/resource/SecurityActions.java
declarchive/trunk/impl-base/src/main/java/org/jboss/declarchive/impl/base/resource/URLResource.java
declarchive/trunk/spi/src/main/java/org/jboss/declarchive/spi/Resource.java
Removed:
declarchive/trunk/api/src/main/java/org/jboss/declarchive/api/ArchiveFactory.java
declarchive/trunk/api/src/main/java/org/jboss/declarchive/api/Asset.java
declarchive/trunk/api/src/main/java/org/jboss/declarchive/api/AssetNotFoundException.java
declarchive/trunk/api/src/main/java/org/jboss/declarchive/api/Path.java
declarchive/trunk/api/src/main/java/org/jboss/declarchive/api/ResourceNotFoundException.java
declarchive/trunk/api/src/main/java/org/jboss/declarchive/api/container/
declarchive/trunk/api/src/main/java/org/jboss/declarchive/api/jar/WebArchive.java
declarchive/trunk/impl-base/src/main/java/org/jboss/declarchive/impl/base/GenericArchive.java
declarchive/trunk/impl-base/src/main/java/org/jboss/declarchive/impl/base/URLPackageScanner.java
declarchive/trunk/impl-base/src/main/java/org/jboss/declarchive/impl/base/Validate.java
declarchive/trunk/impl-base/src/main/java/org/jboss/declarchive/impl/base/asset/
declarchive/trunk/impl-base/src/main/java/org/jboss/declarchive/impl/base/jar/WebArchiveImpl.java
declarchive/trunk/impl-base/src/main/java/org/jboss/declarchive/impl/base/path/
declarchive/trunk/impl-base/src/main/java/org/jboss/declarchive/impl/base/resource/ClassResource.java
declarchive/trunk/impl-base/src/main/java/org/jboss/declarchive/impl/base/resource/ClassloaderResource.java
declarchive/trunk/impl-base/src/main/java/org/jboss/declarchive/impl/base/resource/FileResource.java
declarchive/trunk/impl-base/src/main/java/org/jboss/declarchive/impl/base/resource/SecurityActions.java
declarchive/trunk/impl-base/src/main/java/org/jboss/declarchive/impl/base/resource/URLResource.java
declarchive/trunk/impl-base/src/test/java/org/jboss/declarchive/impl/base/jar/
declarchive/trunk/impl-base/src/test/java/org/jboss/declarchive/impl/base/path/
Modified:
declarchive/trunk/api/pom.xml
declarchive/trunk/api/src/main/java/org/jboss/declarchive/api/Archive.java
declarchive/trunk/api/src/main/java/org/jboss/declarchive/api/jar/JavaArchive.java
declarchive/trunk/impl-base/src/main/java/org/jboss/declarchive/impl/base/jar/JavaArchiveImpl.java
declarchive/trunk/impl-base/src/test/java/org/jboss/declarchive/impl/base/resource/ClassResourceTestCase.java
declarchive/trunk/impl-base/src/test/java/org/jboss/declarchive/impl/base/resource/ClassloaderResourceTestCase.java
declarchive/trunk/impl-base/src/test/java/org/jboss/declarchive/impl/base/resource/FileResourceTestCase.java
declarchive/trunk/impl-base/src/test/java/org/jboss/declarchive/impl/base/resource/URLResourceTestCase.java
declarchive/trunk/impl-jdkfile/src/main/java/org/jboss/declarchive/impl/jdkfile/TempFileArchiveImpl.java
declarchive/trunk/impl-vfs/src/main/java/org/jboss/declarchive/impl/vfs/MemoryArchiveImpl.java
declarchive/trunk/impl-vfs/src/main/java/org/jboss/declarchive/impl/vfs/VfsArchiveBase.java
declarchive/trunk/impl-vfs/src/test/java/org/jboss/declarchive/impl/vfs/VfsMemoryArchiveFactoryTestCase.java
declarchive/trunk/impl-vfs/src/test/java/org/jboss/declarchive/impl/vfs/VfsMemoryArchiveTestCase.java
Log:
[TMPARCH-8] Revert r3450 and we will go with smaller steps
Modified: declarchive/trunk/api/pom.xml
===================================================================
--- declarchive/trunk/api/pom.xml 2009-08-15 10:26:34 UTC (rev 3450)
+++ declarchive/trunk/api/pom.xml 2009-08-17 09:41:49 UTC (rev 3451)
@@ -33,14 +33,6 @@
<!-- Dependencies -->
<dependencies>
- <!--
- External Projects
- -->
- <dependency>
- <groupId>junit</groupId>
- <artifactId>junit</artifactId>
- <scope>test</scope>
- </dependency>
</dependencies>
</project>
Modified: declarchive/trunk/api/src/main/java/org/jboss/declarchive/api/Archive.java
===================================================================
--- declarchive/trunk/api/src/main/java/org/jboss/declarchive/api/Archive.java 2009-08-15 10:26:34 UTC (rev 3450)
+++ declarchive/trunk/api/src/main/java/org/jboss/declarchive/api/Archive.java 2009-08-17 09:41:49 UTC (rev 3451)
@@ -16,7 +16,7 @@
*/
package org.jboss.declarchive.api;
-import java.util.Map;
+import java.net.URL;
/**
* Archive
@@ -25,112 +25,78 @@
* be constructed declaratively / programmatically.
*
* @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
- * @author <a href="mailto:aslak at conduct.no">Aslak Knutsen</a>
* @version $Revision: $
*/
-public interface Archive<T extends Archive<T>>
+public interface Archive<T extends Archive<?>>
{
//-------------------------------------------------------------------------------------||
// Contracts --------------------------------------------------------------------------||
//-------------------------------------------------------------------------------------||
/**
- * Obtains the name of this archive (ie. myLibrary.jar)
- */
- String getName();
-
- /**
- * Adds the specified assets to the archive and returns this reference
- *
- * @param assets
- * @return
- * @throws IllegalArgumentException If no assets were specified
- */
- T add(Asset... assets) throws IllegalArgumentException;
-
- /**
- * Adds the specified assets under the specified path into the
- * target context
+ * Adds the specified Class to the archive
*
- * @param target The context under which to add the assets
- * @param assets
- * @return
- * @throws IllegalArgumentException If no target or assets were specified
+ * @param The class to add
+ * @return This virtual deployment
+ * @throws IllegalArgumentException If no class was specified
*/
- T add(Path target, Asset... assets) throws IllegalArgumentException;
+ T addClass(Class<?> clazz) throws IllegalArgumentException;
/**
- * Adds the specified asset under the specified target (directory)
- * using the specified name. The resultant path will be treating
- * the specified path as a prefix namespace, then appending the name.
+ * Adds the specified Classes to the archive.
*
- * @param target The context directory under which to add the asset
- * @param name The name to assign the assent under the target namespace
- * @param asset
- * @return
- * @throws IllegalArgumentException If the target, name, or asset was not specified
+ * @param classes
+ * @return This virtual deployment
+ * @throws IllegalArgumentException If no classes were specified
*/
- T add(Path target, String name, Asset asset) throws IllegalArgumentException;
+ T addClasses(Class<?>... classes) throws IllegalArgumentException;
/**
- * Adds the specified resource under the context denoted by the specified target
+ * Adds the resource with the specified name to the
+ * deployment. The resource name must be visible to the ClassLoader
+ * of the archive
*
- * @param target
- * @param asset
+ * @param name
* @return
- * @throws IllegalArgumentException If either the target or asset is not specified
+ * @throws IllegalArgumentException If the name was not specified
*/
- T add(String target, Asset asset) throws IllegalArgumentException;
+ T addResource(String name) throws IllegalArgumentException;
/**
- * Obtains the asset located at the specified path
+ * Adds the specified resource to the archive, using the specified ClassLoader
+ * to load the resource
*
- * @param path
+ * @param name
+ * @param cl
* @return
- * @throws AssetNotFoundException If the specified path does not
- * point to any asset in the archive
- * @throws IllegalArgumentException If the path is not specified
+ * @throws IllegalArgumentException If either the name or ClassLoader is not specified
*/
- Asset get(Path path) throws AssetNotFoundException, IllegalArgumentException;
+ T addResource(String name, ClassLoader cl) throws IllegalArgumentException;
/**
- * Obtains the asset located at the specified path
+ * Adds the resource located at the specified URL to the archive. The
+ * location within the archive will be equal to the path portion of the
+ * specified URL.
*
- * @param path
+ * @param location
* @return
- * @throws AssetNotFoundException If the specified path does not
- * point to any resource in the archive
- * @throws IllegalArgumentException If the path is not specified
+ * @throws IllegalArgumentException If the location is not specified
*/
- Asset get(String path) throws AssetNotFoundException, IllegalArgumentException;
+ T addResource(URL location) throws IllegalArgumentException;
/**
- * Denotes whether this archive contains a resource at the specified
- * path
+ * Adds the resource located at the specified URL to
+ * the archive at the specified path.
*
- * @param path
+ * @param location
+ * @param newPath The new path to assign, or null if
+ * the path portion of the location should be used
* @return
- * @throws IllegalArgumentException If the path is not specified
+ * @throws IllegalArgumentException If the location is not specified
*/
- boolean contains(Path path) throws IllegalArgumentException;
+ T addResource(URL location, String newPath) throws IllegalArgumentException;
/**
- * Removes the asset in the archive at the specified Path. If the path
- * is a directory, recursively removes all contents.
- *
- * @param path
- * @return Whether or not a deletion was made
- */
- boolean delete(Path path) throws IllegalArgumentException;
-
- /**
- * Obtains all assets in this archive, along with its respective Path.
- * The returned Map will be an immutable view.
- * @return
- */
- Map<Path, Asset> getContent();
-
- /**
* Returns a multiline "ls -l"-equse output of the contents of
* this deployment and (recursively) its children if the verbosity
* flag is set to "true". Otherwise the no-arg version is invoked
Deleted: declarchive/trunk/api/src/main/java/org/jboss/declarchive/api/ArchiveFactory.java
===================================================================
--- declarchive/trunk/api/src/main/java/org/jboss/declarchive/api/ArchiveFactory.java 2009-08-15 10:26:34 UTC (rev 3450)
+++ declarchive/trunk/api/src/main/java/org/jboss/declarchive/api/ArchiveFactory.java 2009-08-17 09:41:49 UTC (rev 3451)
@@ -1,104 +0,0 @@
-package org.jboss.declarchive.api;
-
-import java.lang.reflect.Constructor;
-import java.util.logging.Logger;
-
-public class ArchiveFactory
-{
- /**
- * Logger
- */
- private static final Logger log = Logger.getLogger(ArchiveFactory.class.getName());
-
- private static final Class<?>[] ARCHIVE_IMPL_CONSTRUCTOR_ARGUMENTS = new Class[]{String.class};
-
- private ArchiveFactory() { }
-
- public static Archive createTmpArchive(String name)
- {
- Class<? extends Archive> implClass = null;
- try
- {
- implClass = getClass("org.jboss.declarchive.impl.jdkfile.TempFileArchiveImpl")
- .asSubclass(Archive.class);
- }
- catch (ClassNotFoundException e)
- {
- throw new RuntimeException(
- "Declarative Archives implementation \"JDK File\" not in classpath",
- e);
- }
- return createArchive(
- name,
- Archive.class,
- implClass);
- }
-
- public static Archive createVirtualArchive(String name)
- {
- Class<? extends Archive> implClass = null;
- try
- {
- implClass = getClass("org.jboss.declarchive.impl.vfs.MemoryArchiveImpl")
- .asSubclass(Archive.class);
- }
- catch (ClassNotFoundException e)
- {
- throw new RuntimeException(
- "Declarative Archives implementation \"Virtual File System\" not in classpath",
- e);
- }
- return createArchive(
- name,
- Archive.class,
- implClass);
- }
-
- public static <T extends Archive> T createArchive(final String name, final Class<T> archiveType, final Class<? extends T> archiveImpl)
- {
- if(archiveType == null) {
- throw new IllegalArgumentException("ArchiveType can not be null");
- }
- if(archiveImpl == null) {
- throw new IllegalArgumentException("ArchiveImpl can not be null");
- }
-
- Constructor<?> implConstructor = findConstructor(archiveImpl, ARCHIVE_IMPL_CONSTRUCTOR_ARGUMENTS);
-
- Object archive = null;
- try
- {
- archive = implConstructor.newInstance(name);
- }
- catch (Exception e) {
- throw new RuntimeException("Error in creating new " + archiveImpl.getName(), e);
- }
-
- return archiveType.cast(archive);
- }
-
- private static Constructor<?> findConstructor(final Class<?> implClass, final Class<?>[] arguments)
- {
- try
- {
- return SecurityActions.getConstructor(implClass, arguments);
- }
- catch (NoSuchMethodException e)
- {
- throw new RuntimeException("Could not find constructor to be used in factory creation of a new "
- + Archive.class.getSimpleName(), e);
- }
- }
-
- /**
- * Obtains the class with the specified name from the TCCL
- *
- * @param className
- * @return
- */
- static Class<?> getClass(final String className) throws ClassNotFoundException
- {
- final ClassLoader cl = SecurityActions.getThreadContextClassLoader();
- return Class.forName(className, false, cl);
- }
-}
Deleted: declarchive/trunk/api/src/main/java/org/jboss/declarchive/api/Asset.java
===================================================================
--- declarchive/trunk/api/src/main/java/org/jboss/declarchive/api/Asset.java 2009-08-15 10:26:34 UTC (rev 3450)
+++ declarchive/trunk/api/src/main/java/org/jboss/declarchive/api/Asset.java 2009-08-17 09:41:49 UTC (rev 3451)
@@ -1,56 +0,0 @@
-/*
- * 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.declarchive.api;
-
-import java.io.InputStream;
-
-/**
- * Represents a Class, file, or any other collection
- * of bytes stored under some context within an {@link Archive}
- *
- * @author <a href="mailto:aslak at conduct.no">Aslak Knutsen</a>
- * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
- */
-public interface Asset
-{
-
- /**
- * Get the default name for this resource, which will
- * be the name under with the resource is placed into
- * an archive unless explicitly specified otherwise.
- *
- * @return A name for this Resource
- */
- String getDefaultName();
-
- /**
- * Get the default path for this resource, which will
- * be the context under with the resource is placed into
- * an archive unless explicitly specified otherwise.
- *
- * @return A path for this Resource
- */
- Path getDefaultPath();
-
- /**
- * Get a open stream for the resource content.
- * The caller is responsible for closing the stream.
- *
- * @return A new open inputstream for each call.
- */
- InputStream getStream();
-}
Deleted: declarchive/trunk/api/src/main/java/org/jboss/declarchive/api/AssetNotFoundException.java
===================================================================
--- declarchive/trunk/api/src/main/java/org/jboss/declarchive/api/AssetNotFoundException.java 2009-08-15 10:26:34 UTC (rev 3450)
+++ declarchive/trunk/api/src/main/java/org/jboss/declarchive/api/AssetNotFoundException.java 2009-08-17 09:41:49 UTC (rev 3451)
@@ -1,63 +0,0 @@
-/*
- * 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.declarchive.api;
-
-/**
- * AssetNotFoundException
- *
- * Thrown when an asset is requested, but could not be found
- * within the context of the given archive at the specified path
- *
- * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
- * @version $Revision: $
- */
-public class AssetNotFoundException extends IllegalArgumentException
-{
- //-------------------------------------------------------------------------------------||
- // Class Members ----------------------------------------------------------------------||
- //-------------------------------------------------------------------------------------||
-
- /**
- * serialVersionUID
- */
- private static final long serialVersionUID = 1L;
-
- //-------------------------------------------------------------------------------------||
- // Constructors -----------------------------------------------------------------------||
- //-------------------------------------------------------------------------------------||
-
- public AssetNotFoundException()
- {
- super();
- }
-
- public AssetNotFoundException(final String message, final Throwable cause)
- {
- super(message, cause);
- }
-
- public AssetNotFoundException(final String s)
- {
- super(s);
- }
-
- public AssetNotFoundException(final Throwable cause)
- {
- super(cause);
- }
-
-}
Deleted: declarchive/trunk/api/src/main/java/org/jboss/declarchive/api/Path.java
===================================================================
--- declarchive/trunk/api/src/main/java/org/jboss/declarchive/api/Path.java 2009-08-15 10:26:34 UTC (rev 3450)
+++ declarchive/trunk/api/src/main/java/org/jboss/declarchive/api/Path.java 2009-08-17 09:41:49 UTC (rev 3451)
@@ -1,36 +0,0 @@
-/*
- * 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.declarchive.api;
-
-/**
- * Path
- *
- * Represents a target context within an {@link Archive} under
- * which an {@link Asset} may be found.
- *
- * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
- * @version $Revision: $
- */
-public interface Path
-{
- /**
- * Obtains the context which this Path represents
- *
- * @return
- */
- String get();
-}
Deleted: declarchive/trunk/api/src/main/java/org/jboss/declarchive/api/ResourceNotFoundException.java
===================================================================
--- declarchive/trunk/api/src/main/java/org/jboss/declarchive/api/ResourceNotFoundException.java 2009-08-15 10:26:34 UTC (rev 3450)
+++ declarchive/trunk/api/src/main/java/org/jboss/declarchive/api/ResourceNotFoundException.java 2009-08-17 09:41:49 UTC (rev 3451)
@@ -1,62 +0,0 @@
-/*
- * 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.declarchive.api;
-
-/**
- * ResourceNotFoundException
- *
- * Thrown when a ClassLoader resource is requested, but could not be found
- *
- * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
- * @version $Revision: $
- */
-public class ResourceNotFoundException extends IllegalArgumentException
-{
- //-------------------------------------------------------------------------------------||
- // Class Members ----------------------------------------------------------------------||
- //-------------------------------------------------------------------------------------||
-
- /**
- * serialVersionUID
- */
- private static final long serialVersionUID = 1L;
-
- //-------------------------------------------------------------------------------------||
- // Constructors -----------------------------------------------------------------------||
- //-------------------------------------------------------------------------------------||
-
- public ResourceNotFoundException()
- {
- super();
- }
-
- public ResourceNotFoundException(final String message, final Throwable cause)
- {
- super(message, cause);
- }
-
- public ResourceNotFoundException(final String s)
- {
- super(s);
- }
-
- public ResourceNotFoundException(final Throwable cause)
- {
- super(cause);
- }
-
-}
Modified: declarchive/trunk/api/src/main/java/org/jboss/declarchive/api/jar/JavaArchive.java
===================================================================
--- declarchive/trunk/api/src/main/java/org/jboss/declarchive/api/jar/JavaArchive.java 2009-08-15 10:26:34 UTC (rev 3450)
+++ declarchive/trunk/api/src/main/java/org/jboss/declarchive/api/jar/JavaArchive.java 2009-08-17 09:41:49 UTC (rev 3451)
@@ -16,24 +16,56 @@
*/
package org.jboss.declarchive.api.jar;
+import java.io.File;
+import java.net.URL;
+
import org.jboss.declarchive.api.Archive;
-import org.jboss.declarchive.api.container.ClassContainer;
-import org.jboss.declarchive.api.container.ManifestContainer;
-import org.jboss.declarchive.api.container.ResourceContainer;
/**
* JavaArchive
*
- * Traditional JAR (Java Archive) structure. Used in
+ * Traditional JAR (Java ARchive) structure. Used in
* construction of libraries and applications.
*
* @see http://java.sun.com/j2se/1.5.0/docs/guide/jar/jar.html
* @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
- * @author <a href="mailto:aslak at conduct.no">Aslak Knutsen</a>
* @version $Revision: $
*/
-public interface JavaArchive extends Archive<JavaArchive>,
- ResourceContainer<JavaArchive>, ManifestContainer<JavaArchive>, ClassContainer<JavaArchive>
+public interface JavaArchive extends Archive<JavaArchive>
{
+ //-------------------------------------------------------------------------------------||
+ // Contracts --------------------------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ /**
+ * Adds the File with the specified path as the JAR Manifest. This will
+ * be placed into the archive as <code>META-INF/MANIFEST.MF</code>
+ *
+ * @param manifestFilePath The path to the file file to use as the JAR Manifest.
+ * @throws IllegalArgumentException If the path does not point to a valid file
+ * or was not specified
+ */
+ JavaArchive addManifest(String manifestFilePath) throws IllegalArgumentException;
+
+ /**
+ * Adds the specified File as the JAR Manifest. This will
+ * be placed into the archive as <code>META-INF/MANIFEST.MF</code>
+ *
+ * @param manifestFile The file to use as the JAR Manifest.
+ * @throws IllegalArgumentException If the file does not exist or
+ * was not specified
+ */
+ JavaArchive addManifest(File manifestFile) throws IllegalArgumentException;
+
+ /**
+ * Adds the specified URL as the JAR Manifest. This will
+ * be placed into the archive as <code>META-INF/MANIFEST.MF</code>
+ *
+ * @param manifestFile The file to use as the JAR Manifest.
+ * @throws IllegalArgumentException If the URL could not be obtained or
+ * was not specified
+ */
+ JavaArchive addManifest(URL manifestFile) throws IllegalArgumentException;
+
}
Deleted: declarchive/trunk/api/src/main/java/org/jboss/declarchive/api/jar/WebArchive.java
===================================================================
--- declarchive/trunk/api/src/main/java/org/jboss/declarchive/api/jar/WebArchive.java 2009-08-15 10:26:34 UTC (rev 3450)
+++ declarchive/trunk/api/src/main/java/org/jboss/declarchive/api/jar/WebArchive.java 2009-08-17 09:41:49 UTC (rev 3451)
@@ -1,31 +0,0 @@
-/*
- * 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.declarchive.api.jar;
-
-import org.jboss.declarchive.api.Archive;
-import org.jboss.declarchive.api.container.ManifestContainer;
-import org.jboss.declarchive.api.container.WebContainer;
-
-/**
- * WebArchive
- *
- * @author <a href="mailto:aslak at conduct.no">Aslak Knutsen</a>
- * @version $Revision: $
- */
-public interface WebArchive extends Archive<WebArchive>, ManifestContainer<WebArchive>, WebContainer<WebArchive>
-{
-}
Copied: declarchive/trunk/impl-base/src/main/java/org/jboss/declarchive/impl/base/ArchiveBase.java (from rev 3449, declarchive/trunk/impl-base/src/main/java/org/jboss/declarchive/impl/base/ArchiveBase.java)
===================================================================
--- declarchive/trunk/impl-base/src/main/java/org/jboss/declarchive/impl/base/ArchiveBase.java (rev 0)
+++ declarchive/trunk/impl-base/src/main/java/org/jboss/declarchive/impl/base/ArchiveBase.java 2009-08-17 09:41:49 UTC (rev 3451)
@@ -0,0 +1,492 @@
+/*
+ * 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.declarchive.impl.base;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.net.URLConnection;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+import org.jboss.declarchive.api.Archive;
+
+/**
+ * ArchiveBase
+ *
+ * Base implementation of {@link Archive}
+ *
+ * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
+ * @version $Revision: $
+ */
+public abstract class ArchiveBase<T extends Archive<?>> implements Archive<T>
+{
+
+ //-------------------------------------------------------------------------------------||
+ // Class Members ----------------------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ /**
+ * Logger
+ */
+ private static final Logger log = Logger.getLogger(ArchiveBase.class.getName());
+
+ /**
+ * Extension for Java Archives
+ */
+ public static final String EXTENSION_JAR = ".jar";
+
+ /**
+ * Delimiter for paths while looking for resources
+ */
+ private static final char DELIMITER_RESOURCE_PATH = '/';
+
+ /**
+ * Delimiter for paths in fully-qualified class names
+ */
+ private static final char DELIMITER_CLASS_NAME_PATH = '.';
+
+ /**
+ * The filename extension appended to classes
+ */
+ private static final String EXTENSION_CLASS = ".class";
+
+ //-------------------------------------------------------------------------------------||
+ // Instance Members -------------------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ /**
+ * The ClassLoader used in loading resources and classes into the virtual deployment
+ */
+ private final ClassLoader classLoader;
+
+ //-------------------------------------------------------------------------------------||
+ // Constructors -----------------------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ /**
+ * Constructor
+ *
+ * Creates a new instance using the Thread Context ClassLoader
+ * from which we'll load resources by default
+ */
+ protected ArchiveBase()
+ {
+ // Use the TCCL
+ this(SecurityActions.getThreadContextClassLoader());
+ }
+
+ /**
+ * Constructor
+ *
+ * Creates a new instance using the specified ClassLoader
+ * from which we'll load resources by default
+ *
+ * @param The ClassLoader to use by default
+ */
+ protected ArchiveBase(final ClassLoader cl)
+ {
+ // Invoke super
+ super();
+
+ // Precondition check
+ if (cl == null)
+ {
+ throw new IllegalArgumentException("ClassLoader must be specified");
+ }
+
+ // Set properties
+ this.classLoader = cl;
+ }
+
+ //-------------------------------------------------------------------------------------||
+ // Required Implementations -----------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ /**
+ * @see org.jboss.declarchive.api.Archive#addClass(java.lang.Class)
+ */
+ @Override
+ public T addClass(final Class<?> clazz) throws IllegalArgumentException
+ {
+ // Precondition check
+ if (clazz == null)
+ {
+ throw new IllegalArgumentException("Class must be specified");
+ }
+
+ // Get the resource name of the class
+ final String name = this.getResourceNameOfClass(clazz);
+
+ // Get the CL of the Class
+ final ClassLoader cl = clazz.getClassLoader();
+
+ // Add it as a resource
+ if (log.isLoggable(Level.FINER))
+ {
+ log.log(Level.FINER, "Adding class as resource: " + clazz);
+ }
+ return this.addResource(name, cl);
+ }
+
+ /**
+ * @see org.jboss.declarchive.api.Archive#addClasses(java.lang.Class<?>[])
+ */
+ @Override
+ public T addClasses(final Class<?>... classes) throws IllegalArgumentException
+ {
+ // Precondition check
+ if (classes == null || classes.length == 0)
+ {
+ throw new IllegalArgumentException("At least one class must be specified");
+ }
+
+ // For each class
+ for (final Class<?> clazz : classes)
+ {
+ this.addClass(clazz);
+ }
+
+ // Return
+ return this.covarientReturn();
+ }
+
+ /**
+ * @see org.jboss.declarchive.api.Archive#addResource(java.lang.String)
+ */
+ @Override
+ public T addResource(final String name) throws IllegalArgumentException
+ {
+ return this.addResource(name, this.getClassLoader());
+ }
+
+ /**
+ * @see org.jboss.declarchive.api.Archive#addResource(java.net.URL)
+ */
+ @Override
+ public T addResource(final URL location) throws IllegalArgumentException
+ {
+ // Delegate to the other implementation
+ return this.addResource(location, null);
+ }
+
+ /**
+ * @see org.jboss.declarchive.api.Archive#addResource(java.lang.String, java.lang.ClassLoader)
+ */
+ @Override
+ public final T addResource(final String name, final ClassLoader cl) throws IllegalArgumentException
+ {
+ // Precondition check
+ if (name == null || name.length() == 0)
+ {
+ throw new IllegalArgumentException("name must be specified");
+ }
+ if (cl == null)
+ {
+ throw new IllegalArgumentException("ClassLoader must be specified");
+ }
+
+ // Get the content of the resource
+ byte[] content = null;
+ try
+ {
+ content = this.getBytesOfResource(name, cl);
+ }
+ catch (final IOException ioe)
+ {
+ throw new RuntimeException("Could not add resource \"" + name + "\" to " + this, ioe);
+ }
+
+ // Add
+ this.addContent(content, name);
+
+ // Return
+ return this.covarientReturn();
+ }
+
+ /**
+ * @see org.jboss.declarchive.api.Archive#addResource(java.net.URL, java.lang.String)
+ */
+ @Override
+ public T addResource(final URL location, final String newPath) throws IllegalArgumentException
+ {
+ // Precondition check
+ if (location == null)
+ {
+ throw new IllegalArgumentException("location must be specified");
+ }
+
+ // Get the content of the location
+ byte[] content = null;
+ try
+ {
+ content = this.getBytesOfResource(location);
+ }
+ catch (final IOException ioe)
+ {
+ throw new RuntimeException("Could not add location \"" + location + "\" to " + this, ioe);
+ }
+
+ // Adjust the path if not explicitly defined
+ String path = newPath;
+ if (path == null)
+ {
+ path = location.getPath();
+ if (log.isLoggable(Level.FINER))
+ {
+ log.log(Level.FINER, "Implicitly set new path to \"" + path + "\" while adding: " + location);
+ }
+ }
+
+ // Add
+ this.addContent(content, path);
+
+ // Return
+ return this.covarientReturn();
+ }
+
+ //-------------------------------------------------------------------------------------||
+ // Contracts --------------------------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ /**
+ * Adds the specified content to the archive at the specified location
+ *
+ * @param content
+ * @param location
+ * @throws IllegalArgumentException
+ */
+ protected abstract void addContent(final byte[] content, final String location) throws IllegalArgumentException;
+
+ /**
+ * Returns the actual typed class for this instance, used in safe casting
+ * for covarient return types
+ *
+ * @return
+ */
+ protected abstract Class<T> getActualClass();
+
+ //-------------------------------------------------------------------------------------||
+ // Internal Helper Methods ------------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ /**
+ * Provides typesafe covarient return of this instance
+ */
+ protected final T covarientReturn()
+ {
+ try
+ {
+ return this.getActualClass().cast(this);
+ }
+ catch (final ClassCastException cce)
+ {
+ log.log(Level.SEVERE,
+ "The class specified by getActualClass is not a valid assignment target for this instance;"
+ + " developer error");
+ throw cce;
+ }
+ }
+
+ /**
+ * Returns the name of the class such that it may be accessed via ClassLoader.getResource()
+ *
+ * @param clazz The class
+ * @throws IllegalArgumentException If the class was not specified
+ */
+ private String getResourceNameOfClass(final Class<?> clazz) throws IllegalArgumentException
+ {
+ // Precondition check
+ if (clazz == null)
+ {
+ throw new IllegalArgumentException("Class must be specified");
+ }
+
+ // Build the name
+ final String fqn = clazz.getName();
+ final String nameAsResourcePath = fqn.replace(DELIMITER_CLASS_NAME_PATH, DELIMITER_RESOURCE_PATH);
+ final String resourceName = nameAsResourcePath + EXTENSION_CLASS;
+
+ // Return
+ return resourceName;
+ }
+
+ /**
+ * Copies and returns the specified URL. Used
+ * to ensure we don't export mutable URLs
+ *
+ * @param url
+ * @return
+ */
+ protected final URL copyURL(final URL url)
+ {
+ // If null, return
+ if (url == null)
+ {
+ return url;
+ }
+
+ try
+ {
+ // Copy
+ return new URL(url.toExternalForm());
+ }
+ catch (MalformedURLException e)
+ {
+ throw new RuntimeException("Error in copying URL", e);
+ }
+ }
+
+ /**
+ * Obtains the contents (bytes) of the specified location
+ *
+ * @param location
+ * @return
+ * @throws IOException
+ * @throws IllegalArgumentException If the location is not specified
+ */
+ private byte[] getBytesOfResource(final URL location) throws IOException, IllegalArgumentException
+ {
+ // Precondition check
+ if (location == null)
+ {
+ throw new IllegalArgumentException("location must be specified");
+ }
+
+ // Open a connection and read in all the bytes
+ final URLConnection connection = location.openConnection();
+ final int length = connection.getContentLength();
+ assert length > -1 : "Content length is not known";
+ final InputStream in = connection.getInputStream();
+ final byte[] contents;
+ try
+ {
+ contents = new byte[length];
+ int offset = 0;
+ while (offset < length)
+ {
+ final int readLength = length - offset;
+ int bytesRead = in.read(contents, offset, readLength);
+ if (bytesRead == -1)
+ {
+ break; // EOF
+ }
+ offset += bytesRead;
+ }
+ }
+ finally
+ {
+ try
+ {
+ // Close up the stream
+ in.close();
+ }
+ catch (final IOException ignore)
+ {
+
+ }
+ }
+
+ // Return the byte array
+ if (log.isLoggable(Level.FINER))
+ {
+ log.log(Level.FINER, "Read " + length + " bytes for: " + location);
+ }
+ return contents;
+ }
+
+ /**
+ * Obtains the contents (bytes) of the specified resource using the
+ * specified ClassLoader
+ *
+ * @param name
+ * @param cl
+ * @return
+ * @throws IOException
+ * @throws IllegalArgumentException If the name or ClassLoader is not specified
+ */
+ private byte[] getBytesOfResource(final String name, final ClassLoader cl) throws IOException,
+ IllegalArgumentException
+ {
+ // Precondition check
+ if (name == null || name.length() == 0)
+ {
+ throw new IllegalArgumentException("name must be specified");
+ }
+ if (cl == null)
+ {
+ throw new IllegalArgumentException("ClassLoader must be specified");
+ }
+
+ // Get the URL
+ final URL resourceUrl = this.getResourceUrl(name, cl);
+
+ // Return
+ return this.getBytesOfResource(resourceUrl);
+ }
+
+ /**
+ * Obtains the URL of the resource with the requested name.
+ * The search order is described by {@link ClassLoader#getResource(String)}
+ *
+ * @param name
+ * @return
+ * @throws IllegalArgumentException If name is not specified or could not be found,
+ * or if the ClassLoader is not specified
+ */
+ private URL getResourceUrl(final String name, final ClassLoader cl) throws IllegalArgumentException
+ {
+ // Precondition check
+ if (name == null || name.length() == 0)
+ {
+ throw new IllegalArgumentException("name must be specified");
+ }
+ if (cl == null)
+ {
+ throw new IllegalArgumentException("ClassLoader must be specified");
+ }
+
+ // Find
+ final URL url = cl.getResource(name);
+
+ // Ensure found
+ if (url == null)
+ {
+ throw new ResourceNotFoundException("Could not find resource with name \"" + name + "\" in: " + cl);
+ }
+
+ // Return
+ return url;
+ }
+
+ //-------------------------------------------------------------------------------------||
+ // Accessors / Mutators ---------------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ /**
+ * Returns the ClassLoader used to load classes
+ * and resources into this virtual deployment
+ *
+ * @return
+ */
+ protected final ClassLoader getClassLoader()
+ {
+ return this.classLoader;
+ }
+
+}
Deleted: declarchive/trunk/impl-base/src/main/java/org/jboss/declarchive/impl/base/GenericArchive.java
===================================================================
--- declarchive/trunk/impl-base/src/main/java/org/jboss/declarchive/impl/base/GenericArchive.java 2009-08-15 10:26:34 UTC (rev 3450)
+++ declarchive/trunk/impl-base/src/main/java/org/jboss/declarchive/impl/base/GenericArchive.java 2009-08-17 09:41:49 UTC (rev 3451)
@@ -1,842 +0,0 @@
-/*
- * 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.declarchive.impl.base;
-
-import java.net.MalformedURLException;
-import java.net.URL;
-import java.util.Collections;
-import java.util.HashSet;
-import java.util.Map;
-import java.util.Set;
-import java.util.TreeMap;
-import java.util.concurrent.ConcurrentHashMap;
-import java.util.logging.Level;
-import java.util.logging.Logger;
-
-import org.jboss.declarchive.api.Archive;
-import org.jboss.declarchive.api.Asset;
-import org.jboss.declarchive.api.AssetNotFoundException;
-import org.jboss.declarchive.api.Path;
-import org.jboss.declarchive.api.container.ClassContainer;
-import org.jboss.declarchive.api.container.ManifestContainer;
-import org.jboss.declarchive.api.container.ResourceContainer;
-import org.jboss.declarchive.api.container.WebContainer;
-import org.jboss.declarchive.impl.base.asset.ClassAsset;
-import org.jboss.declarchive.impl.base.asset.ClassloaderAsset;
-import org.jboss.declarchive.impl.base.path.BasePath;
-import org.jboss.declarchive.impl.base.path.RelativePath;
-
-/**
- * GenericArchive
- *
- * Base implementation of {@link Archive}. Provides support
- * for various container types out of the box. Subclasses
- * may expose a limited number of container interfaces as
- * appropriate.
- *
- * This implementation will store all {@link Asset}s in
- * an internal map accessible in immutable form by calling
- * {@link Archive#getContent()}. For custom behaviour,
- * subclasses may override
- * TODO add ?
- * TODO remove ?
- * ...in order to take custom action (ie. represent the assets
- * as backing files, etc).
- *
- * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
- * @version $Revision: $
- */
-public class GenericArchive<T extends Archive<T>>
- implements
- Archive<T>,
- ResourceContainer<T>,
- ClassContainer<T>,
- ManifestContainer<T>,
- WebContainer<T>
-{
-
- //-------------------------------------------------------------------------------------||
- // Class Members ----------------------------------------------------------------------||
- //-------------------------------------------------------------------------------------||
-
- /**
- * Logger
- */
- private static final Logger log = Logger.getLogger(GenericArchive.class.getName());
-
- /**
- * Extension for Java Archives
- */
- public static final String EXTENSION_JAR = ".jar";
-
- // /**
- // * Delimiter for paths while looking for resources
- // */
- // private static final char DELIMITER_RESOURCE_PATH = '/';
- //
- // /**
- // * Delimiter for paths in fully-qualified class names
- // */
- // private static final char DELIMITER_CLASS_NAME_PATH = '.';
- //
- // /**
- // * The filename extension appended to classes
- // */
- // private static final String EXTENSION_CLASS = ".class";
-
- /**
- * Newline character
- */
- private static final char CHAR_NEWLINE = '\n';
-
- //-------------------------------------------------------------------------------------||
- // Instance Members -------------------------------------------------------------------||
- //-------------------------------------------------------------------------------------||
-
- /**
- * Name of the archive
- */
- private final String name;
-
- /**
- * The ClassLoader used in loading resources and classes into the archive
- */
- private final ClassLoader classLoader;
-
- /**
- * Underlying contents of the archive; must
- * be a Thread-safe implementation
- */
- private final Map<Path, Asset> content;
-
- /**
- * Actual Class used in casting
- */
- private final Class<T> actualClass;
-
- //-------------------------------------------------------------------------------------||
- // Constructors -----------------------------------------------------------------------||
- //-------------------------------------------------------------------------------------||
-
- /**
- * Constructor
- *
- * Creates a new instance using the Thread Context ClassLoader
- * from which we'll load resources by default
- *
- * @param name Name of the archive
- * @param actualClass Actual Class used in casting
- * @throws IllegalArgumentException
- */
- protected GenericArchive(final String name, final Class<T> actualClass) throws IllegalArgumentException
- {
- // Use the TCCL
- this(name, SecurityActions.getThreadContextClassLoader(), actualClass);
- }
-
- /**
- * Constructor
- *
- * Creates a new instance using the specified ClassLoader
- * from which we'll load resources by default
- *
- * @param name Name of the archive
- * @param cl The ClassLoader to use by default
- * @param actualClass Actual Class used in casting
- */
- protected GenericArchive(final String name, final ClassLoader cl, final Class<T> actualClass)
- {
- // Invoke super
- super();
-
- // Precondition check
- Validate.notNull(cl, "ClassLoader must be specified");
- // Precondition check
- Validate.notNull(name, "name must be specified");
-
- // Set properties
- this.classLoader = cl;
- this.name = name;
- this.content = new ConcurrentHashMap<Path, Asset>();
- this.actualClass = actualClass;
- }
-
- //-------------------------------------------------------------------------------------||
- // Required Implementations -----------------------------------------------------------||
- //-------------------------------------------------------------------------------------||
-
- /**
- * @see org.jboss.declarchive.api.Archive#addClasses(java.lang.Class<?>[])
- */
- @Override
- public T add(final Class<?>... classes) throws IllegalArgumentException
- {
- // Precondition check
- if (classes == null || classes.length == 0)
- {
- throw new IllegalArgumentException("At least one class must be specified");
- }
-
- // For each class
- for (final Class<?> clazz : classes)
- {
- // Add it as a resource
- if (log.isLoggable(Level.FINER))
- {
- log.log(Level.FINER, "Adding class as resource: " + clazz);
- }
- final Asset asset = new ClassAsset(clazz);
- this.add(asset);
- }
-
- // Return
- return this.covarientReturn();
- }
-
- // /**
- // * @see org.jboss.declarchive.api.Archive#addResource(java.lang.String)
- // */
- // @Override
- // public T addResource(final String name) throws IllegalArgumentException
- // {
- // return this.addResource(name, this.getClassLoader());
- // }
- //
- // /**
- // * @see org.jboss.declarchive.api.Archive#addResource(java.net.URL)
- // */
- // @Override
- // public T addResource(final URL location) throws IllegalArgumentException
- // {
- // // Delegate to the other implementation
- // return this.addResource(location, null);
- // }
- //
- // /**
- // * @see org.jboss.declarchive.api.Archive#addResource(java.lang.String, java.lang.ClassLoader)
- // */
- // @Override
- // public final T addResource(final String name, final ClassLoader cl) throws IllegalArgumentException
- // {
- // // Precondition check
- // if (name == null || name.length() == 0)
- // {
- // throw new IllegalArgumentException("name must be specified");
- // }
- // if (cl == null)
- // {
- // throw new IllegalArgumentException("ClassLoader must be specified");
- // }
- //
- // // Get the content of the resource
- // byte[] content = null;
- // try
- // {
- // content = this.getBytesOfResource(name, cl);
- // }
- // catch (final IOException ioe)
- // {
- // throw new RuntimeException("Could not add resource \"" + name + "\" to " + this, ioe);
- // }
- //
- // // Add
- // this.addContent(content, name);
- //
- // // Return
- // return this.covarientReturn();
- // }
- //
- // /**
- // * @see org.jboss.declarchive.api.Archive#addResource(java.net.URL, java.lang.String)
- // */
- // @Override
- // public T addResource(final URL location, final String newPath) throws IllegalArgumentException
- // {
- // // Precondition check
- // if (location == null)
- // {
- // throw new IllegalArgumentException("location must be specified");
- // }
- //
- // // Get the content of the location
- // byte[] content = null;
- // try
- // {
- // content = this.getBytesOfResource(location);
- // }
- // catch (final IOException ioe)
- // {
- // throw new RuntimeException("Could not add location \"" + location + "\" to " + this, ioe);
- // }
- //
- // // Adjust the path if not explicitly defined
- // String path = newPath;
- // if (path == null)
- // {
- // path = location.getPath();
- // if (log.isLoggable(Level.FINER))
- // {
- // log.log(Level.FINER, "Implicitly set new path to \"" + path + "\" while adding: " + location);
- // }
- // }
- //
- // // Add
- // this.addContent(content, path);
- //
- // // Return
- // return this.covarientReturn();
- // }
- //
- // /**
- // * @see org.jboss.declarchive.api.container.ResourceContainer#addResource(java.lang.String, java.lang.String)
- // */
- // @Override
- // public T addResource(final String name, final String locationWithinContainer) throws IllegalArgumentException
- // {
- // // Make a resource
- // final Asset resource = new ClassloaderResource(name);
- //
- // // Make a Path
- // final Path path = new BasePath(locationWithinContainer);
- //
- // // Add and Return
- // return this.add(path, resource);
- // }
-
- /**
- * @see org.jboss.declarchive.api.container.ClassContainer#add(java.lang.Package[])
- */
- @Override
- public T add(final Package... packages) throws IllegalArgumentException
- {
- // Precondition check
- Validate.notNull(packages, "At least one package must be specified");
-
- // Define the classes we'll add
- final Set<Class<?>> classes = new HashSet<Class<?>>();
-
- // Get the CL
- final ClassLoader cl = this.getClassLoader();
-
- // For each package specified
- for (final Package pkg : packages)
- {
- // Make a scanner to get the classes out of the package
- final URLPackageScanner scanner = new URLPackageScanner(pkg, false, cl);
- // Add the Classes in the package to the Set
- classes.addAll(scanner.getClasses());
- }
-
- // Add classes to the archive and return
- return this.add(classes.toArray(new Class<?>[]
- {}));
- }
-
- /**
- * @see org.jboss.declarchive.api.Archive#add(org.jboss.declarchive.api.Asset[])
- */
- @Override
- public T add(final Asset... assets) throws IllegalArgumentException
- {
- // Add and return
- return this.add(new BasePath(), assets);
- }
-
- /**
- * @see org.jboss.declarchive.api.Archive#getName()
- */
- @Override
- public String getName()
- {
- return this.name;
- }
-
- /**
- * @see org.jboss.declarchive.api.Archive#toString(boolean)
- */
- @Override
- public String toString(final boolean verbose)
- {
- // If not verbose, use the normal toString
- if (!verbose)
- {
- return this.toString();
- }
-
- // Order
- final Map<Path, Asset> orderedMap = new TreeMap<Path, Asset>();
- orderedMap.putAll(this.getContent());
-
- // Get builder
- final StringBuilder sb = new StringBuilder();
- sb.append(this.getName());
-
- // Get keys
- final Set<Path> paths = orderedMap.keySet();
- for (final Path path : paths)
- {
- sb.append(CHAR_NEWLINE);
- sb.append(path);
- }
-
- // Return
- return sb.toString();
- }
-
- /**
- * @see org.jboss.declarchive.api.container.ManifestContainer#addManifestResource(java.lang.String, java.lang.String, java.lang.String)
- */
- @Override
- public T addManifestResource(String resourceName, String newName, String path)
- {
- // TODO Auto-generated method stub
- throw new UnsupportedOperationException("Not Yet Implemented");
- }
-
- /**
- * @see org.jboss.declarchive.api.container.ManifestContainer#addManifestResource(java.lang.String, java.lang.String)
- */
- @Override
- public T addManifestResource(String resourceName, String newName)
- {
- // TODO Auto-generated method stub
- throw new UnsupportedOperationException("Not Yet Implemented");
- }
-
- /**
- * @see org.jboss.declarchive.api.container.ManifestContainer#addManifestResource(java.lang.String)
- */
- @Override
- public T addManifestResource(String resourceName)
- {
- // TODO Auto-generated method stub
- throw new UnsupportedOperationException("Not Yet Implemented");
- }
-
- /**
- * @see org.jboss.declarchive.api.container.ManifestContainer#setManifest(java.lang.String)
- */
- @Override
- public T setManifest(String resourceName)
- {
- // TODO Auto-generated method stub
- throw new UnsupportedOperationException("Not Yet Implemented");
- }
-
- /**
- * @see org.jboss.declarchive.api.container.WebContainer#setWebXML(java.lang.String)
- */
- @Override
- public T setWebXML(String resourceName)
- {
- // TODO Auto-generated method stub
- throw new UnsupportedOperationException("Not Yet Implemented");
- }
-
- /**
- * @see org.jboss.declarchive.api.Archive#add(org.jboss.declarchive.api.Path, org.jboss.declarchive.api.Asset[])
- */
- @Override
- public T add(final Path path, final Asset... assets) throws IllegalArgumentException
- {
- // Precondition check
- Validate.notNull(assets, "At least one resource must be specified");
-
- // Add each resource
- for (final Asset resource : assets)
- {
- this.add(path, resource);
- }
-
- // Return
- return this.covarientReturn();
- }
-
- /**
- * @see org.jboss.declarchive.api.Archive#add(org.jboss.declarchive.api.Path, java.lang.String, org.jboss.declarchive.api.Asset)
- */
- @Override
- public T add(final Path path, final String name, final Asset asset) throws IllegalArgumentException
- {
- // Precondition checks
- Validate.notNull(path, "path must be specified");
- Validate.notNullOrEmpty(name, "name must be specified");
-
- // Construct a new path using the prefix context and name
- final Path newPath = new RelativePath(path, name);
-
- // Add and return
- return this.add(newPath, asset);
- }
-
- /**
- * @see org.jboss.declarchive.api.Archive#add(java.lang.String, org.jboss.declarchive.api.Asset)
- */
- @Override
- public T add(final String path, final Asset asset) throws IllegalArgumentException
- {
- // Precondition checks
- Validate.notNull(path, "path must be specified");
- Validate.notNull(asset, "resource must be specified");
-
- // Construct a Path
- final Path realPath = new BasePath(path);
-
- // Add and return
- return this.add(realPath, asset);
- }
-
- /**
- * @see org.jboss.declarchive.api.Archive#contains(org.jboss.declarchive.api.Path)
- */
- @Override
- public boolean contains(final Path path) throws IllegalArgumentException
- {
- // Return whether this path exists
- return this.getContent().containsKey(path);
- }
-
- /**
- * @see org.jboss.declarchive.api.Archive#delete(org.jboss.declarchive.api.Path)
- */
- @Override
- public boolean delete(final Path path) throws IllegalArgumentException
- {
- // Determine if this path directly exists
- if (this.contains(path))
- {
- final Asset deleted = this.content.remove(path);
- return deleted != null;
- }
-
- // Recurse
- //TODO
-
- // Nothing deleted
- return false;
- }
-
- /**
- * @see org.jboss.declarchive.api.Archive#get(org.jboss.declarchive.api.Path)
- */
- @Override
- public Asset get(final Path path) throws AssetNotFoundException, IllegalArgumentException
- {
- final Asset asset = this.getContent().get(path);
- if (asset == null)
- {
- throw new AssetNotFoundException("No resource exists at " + path);
- }
- return asset;
- }
-
- /**
- * @see org.jboss.declarchive.api.Archive#get(java.lang.String)
- */
- @Override
- public Asset get(final String path) throws AssetNotFoundException, IllegalArgumentException
- {
- final Path realPath = new BasePath(path);
- return this.get(realPath);
- }
-
- /**
- * @see org.jboss.declarchive.api.Archive#getContent()
- */
- @Override
- public Map<Path, Asset> getContent()
- {
- // Return an immutable view
- return Collections.unmodifiableMap(this.content);
- }
-
- /**
- * @see org.jboss.declarchive.api.container.ResourceContainer#addResource(org.jboss.declarchive.api.Path, java.lang.String, java.lang.ClassLoader)
- */
- @Override
- public T addResource(Path target, String name, ClassLoader cl) throws IllegalArgumentException
- {
- // Precondition checks
- Validate.notNull(target, "target must be specified");
- Validate.notNullOrEmpty(name, "name must be specified");
-
- // Make an assert
- final Asset asset = new ClassloaderAsset(name, cl);
-
- // Add and return
- return this.add(target, asset);
- }
-
- /**
- * @see org.jboss.declarchive.api.container.ResourceContainer#addResource(org.jboss.declarchive.api.Path, java.lang.String)
- */
- @Override
- public T addResource(final Path target, final String resourceName) throws IllegalArgumentException
- {
- // Add and return
- return this.addResource(target, resourceName, SecurityActions.getThreadContextClassLoader());
- }
-
- /**
- * @see org.jboss.declarchive.api.container.ResourceContainer#addResource(java.lang.String, java.lang.String)
- */
- @Override
- public T addResource(final String target, final String resourceName) throws IllegalArgumentException
- {
- // Precondition check
- Validate.notNullOrEmpty(target, "target must be specified");
-
- // Make a path
- final Path path = new BasePath(target);
-
- // Add and return
- return this.addResource(path, resourceName);
- }
-
- /**
- * @see org.jboss.declarchive.api.container.ResourceContainer#addResource(java.lang.String)
- */
- @Override
- public T addResource(final String resourceName) throws IllegalArgumentException
- {
- // Precondition check
- Validate.notNullOrEmpty(resourceName, "resourceName must be specified");
-
- // Target is the resource name
- final Path path = new BasePath(resourceName);
-
- // Add and return
- return this.addResource(path, resourceName);
- }
-
- /**
- * @see org.jboss.declarchive.api.container.ResourceContainer#addResource(java.net.URL, java.lang.String)
- */
- @Override
- public T addResource(URL location, String newPath) throws IllegalArgumentException
- {
- // TODO Auto-generated method stub
- throw new UnsupportedOperationException("Not Yet Implemented");
- }
-
- /**
- * @see org.jboss.declarchive.api.container.ResourceContainer#addResource(java.net.URL)
- */
- @Override
- public T addResource(URL location) throws IllegalArgumentException
- {
- // TODO Auto-generated method stub
- throw new UnsupportedOperationException("Not Yet Implemented");
- }
-
- //-------------------------------------------------------------------------------------||
- // Internal Helper Methods ------------------------------------------------------------||
- //-------------------------------------------------------------------------------------||
-
- /**
- * Provides typesafe covarient return of this instance
- */
- protected final T covarientReturn()
- {
- try
- {
- return this.getActualClass().cast(this);
- }
- catch (final ClassCastException cce)
- {
- log.log(Level.SEVERE,
- "The class specified by getActualClass is not a valid assignment target for this instance;"
- + " developer error");
- throw cce;
- }
- }
-
- /**
- * Returns the actual typed class for this instance, used in safe casting
- * for covarient return types
- *
- * @return
- */
- private Class<T> getActualClass()
- {
- return this.actualClass;
- }
-
- /**
- * Copies and returns the specified URL. Used
- * to ensure we don't export mutable URLs
- *
- * @param url
- * @return
- */
- protected final URL copyURL(final URL url)
- {
- // If null, return
- if (url == null)
- {
- return url;
- }
-
- try
- {
- // Copy
- return new URL(url.toExternalForm());
- }
- catch (MalformedURLException e)
- {
- throw new RuntimeException("Error in copying URL", e);
- }
- }
-
- // /**
- // * Obtains the contents (bytes) of the specified location
- // *
- // * @param location
- // * @return
- // * @throws IOException
- // * @throws IllegalArgumentException If the location is not specified
- // */
- // private byte[] getBytesOfResource(final URL location) throws IOException, IllegalArgumentException
- // {
- // // Precondition check
- // if (location == null)
- // {
- // throw new IllegalArgumentException("location must be specified");
- // }
- //
- // // Open a connection and read in all the bytes
- // final URLConnection connection = location.openConnection();
- // final int length = connection.getContentLength();
- // assert length > -1 : "Content length is not known";
- // final InputStream in = connection.getInputStream();
- // final byte[] contents;
- // try
- // {
- // contents = new byte[length];
- // int offset = 0;
- // while (offset < length)
- // {
- // final int readLength = length - offset;
- // int bytesRead = in.read(contents, offset, readLength);
- // if (bytesRead == -1)
- // {
- // break; // EOF
- // }
- // offset += bytesRead;
- // }
- // }
- // finally
- // {
- // try
- // {
- // // Close up the stream
- // in.close();
- // }
- // catch (final IOException ignore)
- // {
- //
- // }
- // }
- //
- // // Return the byte array
- // if (log.isLoggable(Level.FINER))
- // {
- // log.log(Level.FINER, "Read " + length + " bytes for: " + location);
- // }
- // return contents;
- // }
- //
- // /**
- // * Obtains the contents (bytes) of the specified resource using the
- // * specified ClassLoader
- // *
- // * @param name
- // * @param cl
- // * @return
- // * @throws IOException
- // * @throws IllegalArgumentException If the name or ClassLoader is not specified
- // */
- // private byte[] getBytesOfResource(final String name, final ClassLoader cl) throws IOException,
- // IllegalArgumentException
- // {
- // // Precondition check
- // if (name == null || name.length() == 0)
- // {
- // throw new IllegalArgumentException("name must be specified");
- // }
- // if (cl == null)
- // {
- // throw new IllegalArgumentException("ClassLoader must be specified");
- // }
- //
- // // Get the URL
- // final URL resourceUrl = this.getResourceUrl(name, cl);
- //
- // // Return
- // return this.getBytesOfResource(resourceUrl);
- // }
- //
- // /**
- // * Obtains the URL of the resource with the requested name.
- // * The search order is described by {@link ClassLoader#getResource(String)}
- // *
- // * @param name
- // * @return
- // * @throws IllegalArgumentException If name is not specified or could not be found,
- // * or if the ClassLoader is not specified
- // */
- // private URL getResourceUrl(final String name, final ClassLoader cl) throws IllegalArgumentException
- // {
- // // Precondition check
- // if (name == null || name.length() == 0)
- // {
- // throw new IllegalArgumentException("name must be specified");
- // }
- // if (cl == null)
- // {
- // throw new IllegalArgumentException("ClassLoader must be specified");
- // }
- //
- // // Find
- // final URL url = cl.getResource(name);
- //
- // // Ensure found
- // if (url == null)
- // {
- // throw new AssetNotFoundException("Could not find resource with name \"" + name + "\" in: " + cl);
- // }
- //
- // // Return
- // return url;
- // }
-
- //-------------------------------------------------------------------------------------||
- // Accessors / Mutators ---------------------------------------------------------------||
- //-------------------------------------------------------------------------------------||
-
- /**
- * Returns the ClassLoader used to load classes
- * and resources into this virtual deployment
- *
- * @return
- */
- protected final ClassLoader getClassLoader()
- {
- return this.classLoader;
- }
-
-}
Copied: declarchive/trunk/impl-base/src/main/java/org/jboss/declarchive/impl/base/ResourceNotFoundException.java (from rev 3449, declarchive/trunk/impl-base/src/main/java/org/jboss/declarchive/impl/base/ResourceNotFoundException.java)
===================================================================
--- declarchive/trunk/impl-base/src/main/java/org/jboss/declarchive/impl/base/ResourceNotFoundException.java (rev 0)
+++ declarchive/trunk/impl-base/src/main/java/org/jboss/declarchive/impl/base/ResourceNotFoundException.java 2009-08-17 09:41:49 UTC (rev 3451)
@@ -0,0 +1,63 @@
+/*
+ * 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.declarchive.impl.base;
+
+/**
+ * ResourceNotFoundException
+ *
+ * Thrown when a resource is requested, but could not be found
+ * within the context of the given ClassLoader
+ *
+ * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
+ * @version $Revision: $
+ */
+public class ResourceNotFoundException extends IllegalArgumentException
+{
+ //-------------------------------------------------------------------------------------||
+ // Class Members ----------------------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ /**
+ * serialVersionUID
+ */
+ private static final long serialVersionUID = 1L;
+
+ //-------------------------------------------------------------------------------------||
+ // Constructors -----------------------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ public ResourceNotFoundException()
+ {
+ super();
+ }
+
+ public ResourceNotFoundException(final String message, final Throwable cause)
+ {
+ super(message, cause);
+ }
+
+ public ResourceNotFoundException(final String s)
+ {
+ super(s);
+ }
+
+ public ResourceNotFoundException(final Throwable cause)
+ {
+ super(cause);
+ }
+
+}
Deleted: declarchive/trunk/impl-base/src/main/java/org/jboss/declarchive/impl/base/URLPackageScanner.java
===================================================================
--- declarchive/trunk/impl-base/src/main/java/org/jboss/declarchive/impl/base/URLPackageScanner.java 2009-08-15 10:26:34 UTC (rev 3450)
+++ declarchive/trunk/impl-base/src/main/java/org/jboss/declarchive/impl/base/URLPackageScanner.java 2009-08-17 09:41:49 UTC (rev 3451)
@@ -1,175 +0,0 @@
-/*
- * 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.declarchive.impl.base;
-
-import java.io.File;
-import java.io.IOException;
-import java.net.URL;
-import java.net.URLClassLoader;
-import java.net.URLDecoder;
-import java.util.Collections;
-import java.util.Enumeration;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Set;
-import java.util.logging.Level;
-import java.util.logging.Logger;
-import java.util.zip.ZipEntry;
-import java.util.zip.ZipException;
-import java.util.zip.ZipFile;
-
-/**
- * Implementation of scanner which can scan a {@link URLClassLoader}
- *
- * @author Thomas Heute
- * @author Gavin King
- * @author Norman Richards
- * @author Pete Muir
- * @author <a href="mailto:aslak at conduct.no">Aslak Knutsen</a>
- */
-public class URLPackageScanner
-{
-
- private static final Logger log = Logger.getLogger(URLPackageScanner.class.getName());
-
- private final String packageName;
-
- private final String packageNamePath;
-
- private final boolean addRecursively;
-
- private final ClassLoader classLoader;
-
- private final Set<Class<?>> classes = new HashSet<Class<?>>();
-
- public URLPackageScanner(Package pkg, boolean addRecursively, ClassLoader classLoader)
- {
- this(pkg.getName(), addRecursively, classLoader);
- }
-
- public URLPackageScanner(String packageName, boolean addRecursively, ClassLoader classLoader)
- {
- Validate.notNull(packageName, "PackageName must be specified");
- Validate.notNull(addRecursively, "AddRecursively must be specified");
- Validate.notNull(classLoader, "ClassLoader must be specified");
-
- this.packageName = packageName;
- this.packageNamePath = packageName.replace(".", "/");
- this.addRecursively = addRecursively;
- this.classLoader = classLoader;
- }
-
- private void scanPackage()
- {
- try
- {
- Set<String> paths = new HashSet<String>();
-
- for (URL url : loadResources(packageNamePath))
- {
- String urlPath = url.getFile();
- urlPath = URLDecoder.decode(urlPath, "UTF-8");
- if (urlPath.startsWith("file:"))
- {
- urlPath = urlPath.substring(5);
- }
- if (urlPath.indexOf('!') > 0)
- {
- urlPath = urlPath.substring(0, urlPath.indexOf('!'));
- }
- paths.add(urlPath);
- }
- handle(paths);
- }
- catch (IOException ioe)
- {
- log.log(Level.WARNING, "could not read: " + packageName, ioe);
- }
- catch (ClassNotFoundException ioe)
- {
- log.log(Level.WARNING, "Class coud not be loaded in package: " + packageName, ioe);
- }
- }
-
- private void handleArchiveByFile(File file) throws IOException, ClassNotFoundException
- {
- try
- {
- log.fine("archive: " + file);
- ZipFile zip = new ZipFile(file);
- Enumeration<? extends ZipEntry> entries = zip.entries();
- while (entries.hasMoreElements())
- {
- ZipEntry entry = entries.nextElement();
- String name = entry.getName();
- if (name.startsWith(packageNamePath) && name.endsWith(".class")
- && (addRecursively || !name.substring(packageNamePath.length() + 1).contains("/")))
- {
- String className = name.replace("/", ".").replace(".class", "");
- classes.add(classLoader.loadClass(className));
- }
- }
- }
- catch (ZipException e)
- {
- throw new RuntimeException("Error handling file " + file, e);
- }
- }
-
- private void handle(Set<String> paths) throws IOException, ClassNotFoundException
- {
- for (String urlPath : paths)
- {
- log.fine("scanning: " + urlPath);
- File file = new File(urlPath);
- if (file.isDirectory())
- {
- handle(file, packageName);
- }
- else
- {
- handleArchiveByFile(file);
- }
- }
- }
-
- private void handle(File file, String packageName) throws ClassNotFoundException
- {
- for (File child : file.listFiles())
- {
- if (!child.isDirectory() && child.getName().endsWith(".class"))
- {
- classes.add(classLoader.loadClass(packageName + "." + child.getName().substring(0, child.getName().lastIndexOf(".class"))));
- }
- else if (child.isDirectory() && addRecursively)
- {
- handle(child, packageName + "." + child.getName());
- }
- }
- }
-
- public List<URL> loadResources(String name) throws IOException
- {
- return Collections.list(classLoader.getResources(name));
- }
-
- public Set<Class<?>> getClasses()
- {
- scanPackage();
- return classes;
- }
-}
\ No newline at end of file
Deleted: declarchive/trunk/impl-base/src/main/java/org/jboss/declarchive/impl/base/Validate.java
===================================================================
--- declarchive/trunk/impl-base/src/main/java/org/jboss/declarchive/impl/base/Validate.java 2009-08-15 10:26:34 UTC (rev 3450)
+++ declarchive/trunk/impl-base/src/main/java/org/jboss/declarchive/impl/base/Validate.java 2009-08-17 09:41:49 UTC (rev 3451)
@@ -1,63 +0,0 @@
-/*
- * 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.declarchive.impl.base;
-
-/**
- * Validate
- *
- * Validation utility
- *
- * @author <a href="mailto:aslak at conduct.no">Aslak Knutsen</a>
- * @version $Revision: $
- */
-public class Validate
-{
- private Validate()
- {
- }
-
- /**
- * Checks that object is not null, throws exception if it is.
- *
- * @param obj The object to check
- * @param message The exception message
- * @throws IllegalArgumentException Thrown if obj is null
- */
- public static void notNull(final Object obj, final String message) throws IllegalArgumentException
- {
- if (obj == null)
- {
- throw new IllegalArgumentException(message);
- }
- }
-
- /**
- * Checks that the specified String is not null or empty,
- * throws exception if it is.
- *
- * @param string The object to check
- * @param message The exception message
- * @throws IllegalArgumentException Thrown if obj is null
- */
- public static void notNullOrEmpty(final String string, final String message) throws IllegalArgumentException
- {
- if (string == null || string.length() == 0)
- {
- throw new IllegalArgumentException(message);
- }
- }
-}
Modified: declarchive/trunk/impl-base/src/main/java/org/jboss/declarchive/impl/base/jar/JavaArchiveImpl.java
===================================================================
--- declarchive/trunk/impl-base/src/main/java/org/jboss/declarchive/impl/base/jar/JavaArchiveImpl.java 2009-08-15 10:26:34 UTC (rev 3450)
+++ declarchive/trunk/impl-base/src/main/java/org/jboss/declarchive/impl/base/jar/JavaArchiveImpl.java 2009-08-17 09:41:49 UTC (rev 3451)
@@ -16,24 +16,21 @@
*/
package org.jboss.declarchive.impl.base.jar;
+import java.io.File;
+import java.net.MalformedURLException;
import java.net.URL;
-import java.util.Map;
import java.util.logging.Logger;
-import org.jboss.declarchive.api.Asset;
-import org.jboss.declarchive.api.AssetNotFoundException;
-import org.jboss.declarchive.api.Path;
+import org.jboss.declarchive.api.Archive;
import org.jboss.declarchive.api.jar.JavaArchive;
-import org.jboss.declarchive.impl.base.GenericArchive;
-import org.jboss.declarchive.impl.base.path.BasePath;
/**
* JavaArchiveImpl
*
- * Implementation of an archive with JAR-specific support.
+ * Implementation of an archive with JAR-specific
+ * support.
*
* @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
- * @author <a href="mailto:aslak at conduct.no">Aslak Knutsen</a>
* @version $Revision: $
*/
public final class JavaArchiveImpl implements JavaArchive
@@ -49,28 +46,18 @@
private static final Logger log = Logger.getLogger(JavaArchiveImpl.class.getName());
/**
- * Path to the manifest inside of the Archive.
+ * Path to the manifest inside of a JAR
*/
- private static final Path PATH_MANIFEST = new BasePath("META-INF");
+ private static final String PATH_MANIFEST = "META-INF/MANIFEST.MF";
- /**
- * Path to the resources inside of the Archive.
- */
- private static final Path PATH_RESOURCE = new BasePath("/");
-
- /**
- * Path to the classes inside of the Archive.
- */
- private static final Path PATH_CLASSES = new BasePath("/");
-
//-------------------------------------------------------------------------------------||
// Instance Members -------------------------------------------------------------------||
//-------------------------------------------------------------------------------------||
/**
- * The underlying storage implementation of an archive
+ * Underlying delegate
*/
- private final GenericArchive<?> archive;
+ private final Archive<?> delegate;
//-------------------------------------------------------------------------------------||
// Constructor ------------------------------------------------------------------------||
@@ -79,34 +66,39 @@
/**
* Constructor
*
- * @param archive The underlying archive storage implementation
+ * @param The underlying archive storage implementation
* to which the convenience methods of this archive
* will delegate
* @throws IllegalArgumentException If the delegate is not specified
*/
- public JavaArchiveImpl(final GenericArchive<?> archive)
+ public JavaArchiveImpl(final Archive<?> delegate)
{
- this.archive = archive;
+ // Precondition check
+ if (delegate == null)
+ {
+ throw new IllegalArgumentException("delegate must be specified");
+ }
+
+ // Set properties
+ this.delegate = delegate;
+
+ // Log
+ log.fine("Created new Java Archive from backing delegate: " + delegate);
}
//-------------------------------------------------------------------------------------||
// Required Implementations -----------------------------------------------------------||
//-------------------------------------------------------------------------------------||
- /*
- * All methods below this line are delegates
- */
-
/**
- * @param assets
+ * @param clazz
* @return
* @throws IllegalArgumentException
- * @see org.jboss.declarchive.impl.base.GenericArchive#add(org.jboss.declarchive.api.Asset[])
+ * @see org.jboss.declarchive.api.Archive#addClass(java.lang.Class)
*/
- @Override
- public JavaArchive add(final Asset... assets) throws IllegalArgumentException
+ public JavaArchive addClass(final Class<?> clazz) throws IllegalArgumentException
{
- archive.add(assets);
+ delegate.addClass(clazz);
return this;
}
@@ -114,311 +106,139 @@
* @param classes
* @return
* @throws IllegalArgumentException
- * @see org.jboss.declarchive.impl.base.GenericArchive#add(java.lang.Class<?>[])
+ * @see org.jboss.declarchive.api.Archive#addClasses(java.lang.Class<?>[])
*/
- @Override
- public JavaArchive add(Class<?>... classes) throws IllegalArgumentException
+ public JavaArchive addClasses(final Class<?>... classes) throws IllegalArgumentException
{
- archive.add(classes);
+ delegate.addClasses(classes);
return this;
}
/**
- * @param packages
- * @return
- * @throws IllegalArgumentException
- * @see org.jboss.declarchive.impl.base.GenericArchive#add(java.lang.Package[])
- */
- @Override
- public JavaArchive add(Package... packages) throws IllegalArgumentException
- {
- archive.add(packages);
- return this;
- }
-
- /**
- * @param path
- * @param assets
- * @return
- * @throws IllegalArgumentException
- * @see org.jboss.declarchive.impl.base.GenericArchive#add(org.jboss.declarchive.api.Path, org.jboss.declarchive.api.Asset[])
- */
- @Override
- public JavaArchive add(Path path, Asset... assets) throws IllegalArgumentException
- {
- archive.add(path, assets);
- return this;
- }
-
- /**
- * @param path
* @param name
- * @param asset
+ * @param cl
* @return
* @throws IllegalArgumentException
- * @see org.jboss.declarchive.impl.base.GenericArchive#add(org.jboss.declarchive.api.Path, java.lang.String, org.jboss.declarchive.api.Asset)
+ * @see org.jboss.declarchive.api.Archive#addResource(java.lang.String, java.lang.ClassLoader)
*/
- @Override
- public JavaArchive add(Path path, String name, Asset asset) throws IllegalArgumentException
+ public JavaArchive addResource(final String name, final ClassLoader cl) throws IllegalArgumentException
{
- archive.add(path, name, asset);
+ delegate.addResource(name, cl);
return this;
}
/**
- * @param path
- * @param asset
- * @return
- * @throws IllegalArgumentException
- * @see org.jboss.declarchive.impl.base.GenericArchive#add(java.lang.String, org.jboss.declarchive.api.Asset)
- */
- @Override
- public JavaArchive add(String path, Asset asset) throws IllegalArgumentException
- {
- archive.add(path, asset);
- return this;
- }
-
- /**
- * @param resourceName
- * @param newName
- * @param path
- * @return
- * @see org.jboss.declarchive.impl.base.GenericArchive#addManifestResource(java.lang.String, java.lang.String, java.lang.String)
- */
- @Override
- public JavaArchive addManifestResource(String resourceName, String newName, String path)
- {
- archive.addManifestResource(resourceName, newName, path);
- return this;
- }
-
- /**
- * @param resourceName
- * @param newName
- * @return
- * @see org.jboss.declarchive.impl.base.GenericArchive#addManifestResource(java.lang.String, java.lang.String)
- */
- @Override
- public JavaArchive addManifestResource(String resourceName, String newName)
- {
- archive.addManifestResource(resourceName, newName);
- return this;
- }
-
- /**
- * @param resourceName
- * @return
- * @see org.jboss.declarchive.impl.base.GenericArchive#addManifestResource(java.lang.String)
- */
- @Override
- public JavaArchive addManifestResource(String resourceName)
- {
- archive.addManifestResource(resourceName);
- return this;
- }
-
- /**
- * @param target
* @param name
- * @param cl
* @return
* @throws IllegalArgumentException
- * @see org.jboss.declarchive.impl.base.GenericArchive#addResource(org.jboss.declarchive.api.Path, java.lang.String, java.lang.ClassLoader)
+ * @see org.jboss.declarchive.api.Archive#addResource(java.lang.String)
*/
- @Override
- public JavaArchive addResource(Path target, String name, ClassLoader cl) throws IllegalArgumentException
+ public JavaArchive addResource(final String name) throws IllegalArgumentException
{
- archive.addResource(target, name, cl);
+ delegate.addResource(name);
return this;
}
/**
- * @param target
- * @param resourceName
- * @return
- * @throws IllegalArgumentException
- * @see org.jboss.declarchive.impl.base.GenericArchive#addResource(org.jboss.declarchive.api.Path, java.lang.String)
- */
- @Override
- public JavaArchive addResource(Path target, String resourceName) throws IllegalArgumentException
- {
- archive.addResource(target, resourceName);
- return this;
- }
-
- /**
- * @param resourceName
- * @return
- * @throws IllegalArgumentException
- * @see org.jboss.declarchive.impl.base.GenericArchive#addResource(java.lang.String)
- */
- @Override
- public JavaArchive addResource(String resourceName) throws IllegalArgumentException
- {
- archive.addResource(resourceName);
- return this;
- }
-
- /**
* @param location
* @param newPath
* @return
* @throws IllegalArgumentException
- * @see org.jboss.declarchive.impl.base.GenericArchive#addResource(java.net.URL, java.lang.String)
+ * @see org.jboss.declarchive.api.Archive#addResource(java.net.URL, java.lang.String)
*/
- @Override
- public JavaArchive addResource(URL location, String newPath) throws IllegalArgumentException
+ public JavaArchive addResource(final URL location, final String newPath) throws IllegalArgumentException
{
- archive.addResource(location, newPath);
+ delegate.addResource(location, newPath);
return this;
}
/**
- * @see org.jboss.declarchive.api.container.ResourceContainer#addResource(java.lang.String, java.lang.String)
- */
- @Override
- public JavaArchive addResource(final String target, final String resourceName) throws IllegalArgumentException
- {
- archive.addResource(target, resourceName);
- return this;
- }
-
- /**
* @param location
* @return
* @throws IllegalArgumentException
- * @see org.jboss.declarchive.impl.base.GenericArchive#addResource(java.net.URL)
+ * @see org.jboss.declarchive.api.Archive#addResource(java.net.URL)
*/
- @Override
- public JavaArchive addResource(URL location) throws IllegalArgumentException
+ public JavaArchive addResource(final URL location) throws IllegalArgumentException
{
- archive.addResource(location);
+ delegate.addResource(location);
return this;
}
/**
- * @param path
+ * @param verbose
* @return
- * @throws IllegalArgumentException
- * @see org.jboss.declarchive.impl.base.GenericArchive#contains(org.jboss.declarchive.api.Path)
+ * @see org.jboss.declarchive.api.Archive#toString(boolean)
*/
- @Override
- public boolean contains(Path path) throws IllegalArgumentException
+ public String toString(final boolean verbose)
{
- return archive.contains(path);
+ return "Java Archive (JAR): " + delegate.toString(verbose);
}
/**
- * @param path
- * @return
- * @throws IllegalArgumentException
- * @see org.jboss.declarchive.impl.base.GenericArchive#delete(org.jboss.declarchive.api.Path)
+ * @throws MalformedURLException
+ * @see org.jboss.declarchive.api.jar.JavaArchive#addManifest(java.io.File)
*/
@Override
- public boolean delete(Path path) throws IllegalArgumentException
+ public JavaArchive addManifest(final File manifestFile) throws IllegalArgumentException
{
- return archive.delete(path);
- }
+ // Precondition checks
+ if (manifestFile == null)
+ {
+ throw new IllegalArgumentException("Manifest file must be specified");
+ }
+ if (!manifestFile.exists())
+ {
+ throw new IllegalArgumentException("Specified manifest file does not exist: " + manifestFile.getAbsolutePath());
+ }
- /**
- * @param obj
- * @return
- * @see java.lang.Object#equals(java.lang.Object)
- */
- @Override
- public boolean equals(Object obj)
- {
- return archive.equals(obj);
- }
+ // Get a URL
+ final URL url;
+ try
+ {
+ url = manifestFile.toURI().toURL();
+ }
+ catch (final MalformedURLException murle)
+ {
+ throw new RuntimeException("Unexpected error in obtaining URL from File reference: "
+ + manifestFile.getAbsolutePath(), murle);
+ }
- /**
- * @param path
- * @return
- * @throws AssetNotFoundException
- * @throws IllegalArgumentException
- * @see org.jboss.declarchive.impl.base.GenericArchive#get(org.jboss.declarchive.api.Path)
- */
- @Override
- public Asset get(Path path) throws AssetNotFoundException, IllegalArgumentException
- {
- return archive.get(path);
+ // Return
+ return this.addManifest(url);
}
/**
- * @param path
- * @return
- * @throws AssetNotFoundException
- * @throws IllegalArgumentException
- * @see org.jboss.declarchive.impl.base.GenericArchive#get(java.lang.String)
+ * @see org.jboss.declarchive.api.jar.JavaArchive#addManifest(java.lang.String)
*/
@Override
- public Asset get(String path) throws AssetNotFoundException, IllegalArgumentException
+ public JavaArchive addManifest(final String manifestFilePath) throws IllegalArgumentException
{
- return archive.get(path);
- }
+ // Precondition check
+ if (manifestFilePath == null || manifestFilePath.length() == 0)
+ {
+ throw new IllegalArgumentException("path must be specified");
+ }
- /**
- * @return
- * @see org.jboss.declarchive.impl.base.GenericArchive#getContent()
- */
- @Override
- public Map<Path, Asset> getContent()
- {
- return archive.getContent();
- }
+ // Get a File
+ final File file = new File(manifestFilePath);
- /**
- * @return
- * @see org.jboss.declarchive.impl.base.GenericArchive#getName()
- */
- @Override
- public String getName()
- {
- return archive.getName();
+ // Return
+ return this.addManifest(file);
}
/**
- * @return
- * @see java.lang.Object#hashCode()
+ * @see org.jboss.declarchive.api.jar.JavaArchive#addManifest(java.net.URL)
*/
@Override
- public int hashCode()
+ public JavaArchive addManifest(final URL manifestFile) throws IllegalArgumentException
{
- return archive.hashCode();
- }
+ // Precondition checks
+ if (manifestFile == null)
+ {
+ throw new IllegalArgumentException("Manifest file must be specified");
+ }
- /**
- * @param resourceName
- * @return
- * @see org.jboss.declarchive.impl.base.GenericArchive#setManifest(java.lang.String)
- */
- @Override
- public JavaArchive setManifest(String resourceName)
- {
- archive.setManifest(resourceName);
- return this;
+ // Add the resource and return
+ return this.addResource(manifestFile, PATH_MANIFEST);
}
-
- /**
- * @return
- * @see java.lang.Object#toString()
- */
- @Override
- public String toString()
- {
- return archive.toString();
- }
-
- /**
- * @param verbose
- * @return
- * @see org.jboss.declarchive.impl.base.GenericArchive#toString(boolean)
- */
- @Override
- public String toString(boolean verbose)
- {
- return archive.toString(verbose);
- }
-
}
Deleted: declarchive/trunk/impl-base/src/main/java/org/jboss/declarchive/impl/base/jar/WebArchiveImpl.java
===================================================================
--- declarchive/trunk/impl-base/src/main/java/org/jboss/declarchive/impl/base/jar/WebArchiveImpl.java 2009-08-15 10:26:34 UTC (rev 3450)
+++ declarchive/trunk/impl-base/src/main/java/org/jboss/declarchive/impl/base/jar/WebArchiveImpl.java 2009-08-17 09:41:49 UTC (rev 3451)
@@ -1,113 +0,0 @@
-//package org.jboss.declarchive.impl.base.jar;
-//
-//import java.util.logging.Logger;
-//
-//import org.jboss.declarchive.api.Archive;
-//import org.jboss.declarchive.api.Path;
-//import org.jboss.declarchive.api.jar.WebArchive;
-//import org.jboss.declarchive.impl.base.ArchiveBaseSupport;
-//import org.jboss.declarchive.impl.base.path.BasePath;
-//import org.jboss.declarchive.impl.base.path.RelativePath;
-//import org.jboss.declarchive.impl.base.resource.ClassloaderResource;
-//
-//public class WebArchiveImpl extends ArchiveBaseSupport<WebArchive> implements WebArchive
-//{
-// //-------------------------------------------------------------------------------------||
-// // Class Members ----------------------------------------------------------------------||
-// //-------------------------------------------------------------------------------------||
-//
-// /**
-// * Logger
-// */
-// private static final Logger log = Logger.getLogger(WebArchiveImpl.class.getName());
-//
-// /**
-// * Path to the web resource inside of the Archive.
-// */
-// private static final Path PATH_WEB = new BasePath("WEB-INF");
-//
-// /**
-// * Path to the manifest resources inside of the Archive.
-// */
-// private static final Path PATH_MANIFEST = new RelativePath(PATH_WEB, "META-INF");
-//
-// /**
-// * Path to the class resources inside of the Archive.
-// */
-// private static final Path PATH_CLASSES = new RelativePath(PATH_WEB, "classes");
-//
-// /**
-// * Path to the library resources inside of the Archive.
-// */
-// private static final Path PATH_LIBRARY = new RelativePath(PATH_WEB, "lib");
-//
-// /**
-// * Path to the library resources inside of the Archive.
-// */
-// private static final Path PATH_RESOURCE = new BasePath("/");
-//
-// //-------------------------------------------------------------------------------------||
-// // Instance Members -------------------------------------------------------------------||
-// //-------------------------------------------------------------------------------------||
-//
-// //-------------------------------------------------------------------------------------||
-// // Constructor ------------------------------------------------------------------------||
-// //-------------------------------------------------------------------------------------||
-//
-// /**
-// * Constructor
-// *
-// * @param The underlying archive storage implementation
-// * to which the convenience methods of this archive
-// * will delegate
-// * @throws IllegalArgumentException If the delegate is not specified
-// */
-// public WebArchiveImpl(final Archive<?> delegate)
-// {
-// super(delegate);
-// }
-//
-// //-------------------------------------------------------------------------------------||
-// // Required Implementations -----------------------------------------------------------||
-// //-------------------------------------------------------------------------------------||
-//
-// /* (non-Javadoc)
-// * @see org.jboss.declarchive.impl.base.ArchiveBaseSupport#getManinfestPath()
-// */
-// @Override
-// protected Path getManinfestPath()
-// {
-// return PATH_MANIFEST;
-// }
-//
-// /* (non-Javadoc)
-// * @see org.jboss.declarchive.impl.base.ArchiveBaseSupport#getResourcePath()
-// */
-// @Override
-// protected Path getResourcePath()
-// {
-// return PATH_RESOURCE;
-// }
-//
-// /* (non-Javadoc)
-// * @see org.jboss.declarchive.impl.base.ArchiveBaseSupport#getClassesPath()
-// */
-// @Override
-// protected Path getClassesPath()
-// {
-// return PATH_CLASSES;
-// }
-//
-// //-------------------------------------------------------------------------------------||
-// // Required Implementations - WebContainer ---------------------------------------||
-// //-------------------------------------------------------------------------------------||
-//
-// /* (non-Javadoc)
-// * @see org.jboss.declarchive.api.container.WebContainer#setWebXML(java.lang.String)
-// */
-// @Override
-// public WebArchive setWebXML(String resourceName)
-// {
-// return add(PATH_WEB, "web.xml", new ClassloaderResource(resourceName));
-// }
-//}
Copied: declarchive/trunk/impl-base/src/main/java/org/jboss/declarchive/impl/base/resource (from rev 3449, declarchive/trunk/impl-base/src/main/java/org/jboss/declarchive/impl/base/resource)
Deleted: declarchive/trunk/impl-base/src/main/java/org/jboss/declarchive/impl/base/resource/ClassResource.java
===================================================================
--- declarchive/trunk/impl-base/src/main/java/org/jboss/declarchive/impl/base/resource/ClassResource.java 2009-08-13 06:01:04 UTC (rev 3449)
+++ declarchive/trunk/impl-base/src/main/java/org/jboss/declarchive/impl/base/resource/ClassResource.java 2009-08-17 09:41:49 UTC (rev 3451)
@@ -1,99 +0,0 @@
-/*
- * 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.declarchive.impl.base.resource;
-
-import java.io.InputStream;
-
-import org.jboss.declarchive.spi.Resource;
-
-/**
- * Loads the given class using the class's ClassLoader.
- *
- * @author <a href="mailto:aslak at conduct.no">Aslak Knutsen</a>
- *
- */
-public class ClassResource implements Resource
-{
- /**
- * Delimiter for paths while looking for resources
- */
- private static final char DELIMITER_RESOURCE_PATH = '/';
-
- /**
- * Delimiter for paths in fully-qualified class names
- */
- private static final char DELIMITER_CLASS_NAME_PATH = '.';
-
- /**
- * The filename extension appended to classes
- */
- private static final String EXTENSION_CLASS = ".class";
-
- private Class<?> clazz;
-
- /**
- * Load any class as a resource.
- *
- * @param clazz The class to load
- * @throws IllegalArgumentException Class can not be null
- */
- public ClassResource(Class<?> clazz)
- {
- // Precondition check
- if (clazz == null)
- {
- throw new IllegalArgumentException("Class must be specified");
- }
- this.clazz = clazz;
- }
-
- /**
- * Get the default name using Class.getSimpleName().
- */
- @Override
- public String getDefaultName()
- {
- return getResourceNameOfClass(clazz);
- }
-
- /**
- * Converts the Class name into a Resource URL and uses the
- * ClassloaderResource for loading the Class.
- */
- @Override
- public InputStream getStream()
- {
- return new ClassloaderResource(getResourceNameOfClass(clazz), clazz.getClassLoader()).getStream();
- }
-
- /**
- * Returns the name of the class such that it may be accessed via ClassLoader.getResource()
- *
- * @param clazz The class
- * @throws IllegalArgumentException If the class was not specified
- */
- private String getResourceNameOfClass(final Class<?> clazz) throws IllegalArgumentException
- {
- // Build the name
- final String fqn = clazz.getName();
- final String nameAsResourcePath = fqn.replace(DELIMITER_CLASS_NAME_PATH, DELIMITER_RESOURCE_PATH);
- final String resourceName = nameAsResourcePath + EXTENSION_CLASS;
-
- // Return
- return resourceName;
- }
-}
Copied: declarchive/trunk/impl-base/src/main/java/org/jboss/declarchive/impl/base/resource/ClassResource.java (from rev 3449, declarchive/trunk/impl-base/src/main/java/org/jboss/declarchive/impl/base/resource/ClassResource.java)
===================================================================
--- declarchive/trunk/impl-base/src/main/java/org/jboss/declarchive/impl/base/resource/ClassResource.java (rev 0)
+++ declarchive/trunk/impl-base/src/main/java/org/jboss/declarchive/impl/base/resource/ClassResource.java 2009-08-17 09:41:49 UTC (rev 3451)
@@ -0,0 +1,99 @@
+/*
+ * 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.declarchive.impl.base.resource;
+
+import java.io.InputStream;
+
+import org.jboss.declarchive.spi.Resource;
+
+/**
+ * Loads the given class using the class's ClassLoader.
+ *
+ * @author <a href="mailto:aslak at conduct.no">Aslak Knutsen</a>
+ *
+ */
+public class ClassResource implements Resource
+{
+ /**
+ * Delimiter for paths while looking for resources
+ */
+ private static final char DELIMITER_RESOURCE_PATH = '/';
+
+ /**
+ * Delimiter for paths in fully-qualified class names
+ */
+ private static final char DELIMITER_CLASS_NAME_PATH = '.';
+
+ /**
+ * The filename extension appended to classes
+ */
+ private static final String EXTENSION_CLASS = ".class";
+
+ private Class<?> clazz;
+
+ /**
+ * Load any class as a resource.
+ *
+ * @param clazz The class to load
+ * @throws IllegalArgumentException Class can not be null
+ */
+ public ClassResource(Class<?> clazz)
+ {
+ // Precondition check
+ if (clazz == null)
+ {
+ throw new IllegalArgumentException("Class must be specified");
+ }
+ this.clazz = clazz;
+ }
+
+ /**
+ * Get the default name using Class.getSimpleName().
+ */
+ @Override
+ public String getDefaultName()
+ {
+ return getResourceNameOfClass(clazz);
+ }
+
+ /**
+ * Converts the Class name into a Resource URL and uses the
+ * ClassloaderResource for loading the Class.
+ */
+ @Override
+ public InputStream getStream()
+ {
+ return new ClassloaderResource(getResourceNameOfClass(clazz), clazz.getClassLoader()).getStream();
+ }
+
+ /**
+ * Returns the name of the class such that it may be accessed via ClassLoader.getResource()
+ *
+ * @param clazz The class
+ * @throws IllegalArgumentException If the class was not specified
+ */
+ private String getResourceNameOfClass(final Class<?> clazz) throws IllegalArgumentException
+ {
+ // Build the name
+ final String fqn = clazz.getName();
+ final String nameAsResourcePath = fqn.replace(DELIMITER_CLASS_NAME_PATH, DELIMITER_RESOURCE_PATH);
+ final String resourceName = nameAsResourcePath + EXTENSION_CLASS;
+
+ // Return
+ return resourceName;
+ }
+}
Deleted: declarchive/trunk/impl-base/src/main/java/org/jboss/declarchive/impl/base/resource/ClassloaderResource.java
===================================================================
--- declarchive/trunk/impl-base/src/main/java/org/jboss/declarchive/impl/base/resource/ClassloaderResource.java 2009-08-13 06:01:04 UTC (rev 3449)
+++ declarchive/trunk/impl-base/src/main/java/org/jboss/declarchive/impl/base/resource/ClassloaderResource.java 2009-08-17 09:41:49 UTC (rev 3451)
@@ -1,109 +0,0 @@
-/*
- * 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.declarchive.impl.base.resource;
-
-import java.io.InputStream;
-import java.net.URL;
-
-import org.jboss.declarchive.spi.Resource;
-
-/**
- * Loads the content of any resource located in the Classloader.
- *
- * @author <a href="mailto:aslak at conduct.no">Aslak Knutsen</a>
- *
- */
-public class ClassloaderResource implements Resource
-{
- private String resourceName;
-
- private ClassLoader classLoader;
-
- /**
- * Load a named resource using the current threads context classloader.
- *
- * @param resourceName The name of the resource to load
- * @throws IllegalArgumentException resourceName can not be null
- * @throws IllegalArgumentException resourceName must be found in given classloader
- */
- public ClassloaderResource(String resourceName)
- {
- this(resourceName, SecurityActions.getThreadContextClassLoader());
- }
-
- /**
- * Load a named resource using the given classloader.
- *
- * @param resourceName The name of the resource to load
- * @param classLoader The ClassLoader to use
- * @throws IllegalArgumentException resourceName can not be null
- * @throws IllegalArgumentException classloader can not be null
- * @throws IllegalArgumentException resourceName must be found in given classloader
- */
- public ClassloaderResource(String resourceName, ClassLoader classLoader)
- {
- if (resourceName == null)
- {
- throw new IllegalArgumentException("ResourceName must be specified");
- }
- if (classLoader == null)
- {
- throw new IllegalArgumentException("ClassLoader must be specified");
- }
- if (classLoader.getResource(resourceName) == null)
- {
- throw new IllegalArgumentException(resourceName + " not found in classloader " + classLoader);
- }
- this.resourceName = resourceName;
- this.classLoader = classLoader;
- }
-
- /**
- * Get the default name using Resource URL.getFile().
- *
- * @return Returns only the file name part of a URL, not the absolute path.
- */
- @Override
- public String getDefaultName()
- {
- return extractFileName(classLoader.getResource(resourceName));
- }
-
- /**
- * Opens up the given resource as a stream.
- *
- */
- @Override
- public InputStream getStream()
- {
- return classLoader.getResourceAsStream(resourceName);
- }
-
- /*
- * Extract the file name part of a URL excluding the directory structure.
- * ie: /user/test/file.properties = file.properties
- */
- private String extractFileName(URL url)
- {
- String fileName = url.getFile();
- if (fileName.indexOf('/') != -1)
- {
- return fileName.substring(fileName.lastIndexOf('/') + 1, fileName.length());
- }
- return fileName;
- }
-}
Copied: declarchive/trunk/impl-base/src/main/java/org/jboss/declarchive/impl/base/resource/ClassloaderResource.java (from rev 3449, declarchive/trunk/impl-base/src/main/java/org/jboss/declarchive/impl/base/resource/ClassloaderResource.java)
===================================================================
--- declarchive/trunk/impl-base/src/main/java/org/jboss/declarchive/impl/base/resource/ClassloaderResource.java (rev 0)
+++ declarchive/trunk/impl-base/src/main/java/org/jboss/declarchive/impl/base/resource/ClassloaderResource.java 2009-08-17 09:41:49 UTC (rev 3451)
@@ -0,0 +1,109 @@
+/*
+ * 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.declarchive.impl.base.resource;
+
+import java.io.InputStream;
+import java.net.URL;
+
+import org.jboss.declarchive.spi.Resource;
+
+/**
+ * Loads the content of any resource located in the Classloader.
+ *
+ * @author <a href="mailto:aslak at conduct.no">Aslak Knutsen</a>
+ *
+ */
+public class ClassloaderResource implements Resource
+{
+ private String resourceName;
+
+ private ClassLoader classLoader;
+
+ /**
+ * Load a named resource using the current threads context classloader.
+ *
+ * @param resourceName The name of the resource to load
+ * @throws IllegalArgumentException resourceName can not be null
+ * @throws IllegalArgumentException resourceName must be found in given classloader
+ */
+ public ClassloaderResource(String resourceName)
+ {
+ this(resourceName, SecurityActions.getThreadContextClassLoader());
+ }
+
+ /**
+ * Load a named resource using the given classloader.
+ *
+ * @param resourceName The name of the resource to load
+ * @param classLoader The ClassLoader to use
+ * @throws IllegalArgumentException resourceName can not be null
+ * @throws IllegalArgumentException classloader can not be null
+ * @throws IllegalArgumentException resourceName must be found in given classloader
+ */
+ public ClassloaderResource(String resourceName, ClassLoader classLoader)
+ {
+ if (resourceName == null)
+ {
+ throw new IllegalArgumentException("ResourceName must be specified");
+ }
+ if (classLoader == null)
+ {
+ throw new IllegalArgumentException("ClassLoader must be specified");
+ }
+ if (classLoader.getResource(resourceName) == null)
+ {
+ throw new IllegalArgumentException(resourceName + " not found in classloader " + classLoader);
+ }
+ this.resourceName = resourceName;
+ this.classLoader = classLoader;
+ }
+
+ /**
+ * Get the default name using Resource URL.getFile().
+ *
+ * @return Returns only the file name part of a URL, not the absolute path.
+ */
+ @Override
+ public String getDefaultName()
+ {
+ return extractFileName(classLoader.getResource(resourceName));
+ }
+
+ /**
+ * Opens up the given resource as a stream.
+ *
+ */
+ @Override
+ public InputStream getStream()
+ {
+ return classLoader.getResourceAsStream(resourceName);
+ }
+
+ /*
+ * Extract the file name part of a URL excluding the directory structure.
+ * ie: /user/test/file.properties = file.properties
+ */
+ private String extractFileName(URL url)
+ {
+ String fileName = url.getFile();
+ if (fileName.indexOf('/') != -1)
+ {
+ return fileName.substring(fileName.lastIndexOf('/') + 1, fileName.length());
+ }
+ return fileName;
+ }
+}
Deleted: declarchive/trunk/impl-base/src/main/java/org/jboss/declarchive/impl/base/resource/FileResource.java
===================================================================
--- declarchive/trunk/impl-base/src/main/java/org/jboss/declarchive/impl/base/resource/FileResource.java 2009-08-13 06:01:04 UTC (rev 3449)
+++ declarchive/trunk/impl-base/src/main/java/org/jboss/declarchive/impl/base/resource/FileResource.java 2009-08-17 09:41:49 UTC (rev 3451)
@@ -1,86 +0,0 @@
-/*
- * 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.declarchive.impl.base.resource;
-
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileNotFoundException;
-import java.io.InputStream;
-
-import org.jboss.declarchive.spi.Resource;
-
-/**
- * Loads any File.
- *
- * @author <a href="mailto:aslak at conduct.no">Aslak Knutsen</a>
- *
- */
-public class FileResource implements Resource
-{
- private File file;
-
- /**
- * Load the specified File.
- *
- * @param file The file to load
- * @throws IllegalArgumentException File can not be null
- * @throws IllegalArgumentException File must exist
- */
- public FileResource(File file)
- {
- // Precondition check
- if (file == null)
- {
- throw new IllegalArgumentException("File must be specified");
- }
- if (!file.exists())
- {
- throw new IllegalArgumentException("File must exist: " + file.getAbsolutePath());
- }
- this.file = file;
- }
-
- /**
- * Get the default name using File.getName();
- */
- @Override
- public String getDefaultName()
- {
- return file.getName();
- }
-
- /**
- * Opens a new FileInputStream for the given File.
- *
- * Can throw a Runtime exception if the file has been deleted inbetween
- * the FileResource was created and the stream is opened.
- *
- * @throws RuntimeException If the file is not found.
- */
- @Override
- public InputStream getStream()
- {
- try
- {
- return new FileInputStream(file);
- }
- catch (FileNotFoundException e)
- {
- throw new RuntimeException("Could not open file " + file, e);
- }
- }
-}
Copied: declarchive/trunk/impl-base/src/main/java/org/jboss/declarchive/impl/base/resource/FileResource.java (from rev 3449, declarchive/trunk/impl-base/src/main/java/org/jboss/declarchive/impl/base/resource/FileResource.java)
===================================================================
--- declarchive/trunk/impl-base/src/main/java/org/jboss/declarchive/impl/base/resource/FileResource.java (rev 0)
+++ declarchive/trunk/impl-base/src/main/java/org/jboss/declarchive/impl/base/resource/FileResource.java 2009-08-17 09:41:49 UTC (rev 3451)
@@ -0,0 +1,86 @@
+/*
+ * 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.declarchive.impl.base.resource;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.InputStream;
+
+import org.jboss.declarchive.spi.Resource;
+
+/**
+ * Loads any File.
+ *
+ * @author <a href="mailto:aslak at conduct.no">Aslak Knutsen</a>
+ *
+ */
+public class FileResource implements Resource
+{
+ private File file;
+
+ /**
+ * Load the specified File.
+ *
+ * @param file The file to load
+ * @throws IllegalArgumentException File can not be null
+ * @throws IllegalArgumentException File must exist
+ */
+ public FileResource(File file)
+ {
+ // Precondition check
+ if (file == null)
+ {
+ throw new IllegalArgumentException("File must be specified");
+ }
+ if (!file.exists())
+ {
+ throw new IllegalArgumentException("File must exist: " + file.getAbsolutePath());
+ }
+ this.file = file;
+ }
+
+ /**
+ * Get the default name using File.getName();
+ */
+ @Override
+ public String getDefaultName()
+ {
+ return file.getName();
+ }
+
+ /**
+ * Opens a new FileInputStream for the given File.
+ *
+ * Can throw a Runtime exception if the file has been deleted inbetween
+ * the FileResource was created and the stream is opened.
+ *
+ * @throws RuntimeException If the file is not found.
+ */
+ @Override
+ public InputStream getStream()
+ {
+ try
+ {
+ return new FileInputStream(file);
+ }
+ catch (FileNotFoundException e)
+ {
+ throw new RuntimeException("Could not open file " + file, e);
+ }
+ }
+}
Deleted: declarchive/trunk/impl-base/src/main/java/org/jboss/declarchive/impl/base/resource/SecurityActions.java
===================================================================
--- declarchive/trunk/impl-base/src/main/java/org/jboss/declarchive/impl/base/resource/SecurityActions.java 2009-08-13 06:01:04 UTC (rev 3449)
+++ declarchive/trunk/impl-base/src/main/java/org/jboss/declarchive/impl/base/resource/SecurityActions.java 2009-08-17 09:41:49 UTC (rev 3451)
@@ -1,63 +0,0 @@
-/*
- * 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.declarchive.impl.base.resource;
-
-import java.security.AccessController;
-import java.security.PrivilegedAction;
-
-/**
- * SecurityActions
- *
- * A set of privileged actions that are not to leak out
- * of this package
- *
- * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
- * @version $Revision: $
- */
-class SecurityActions
-{
-
- //-------------------------------------------------------------------------------||
- // Constructor ------------------------------------------------------------------||
- //-------------------------------------------------------------------------------||
-
- /**
- * No external instantiation
- */
- private SecurityActions()
- {
-
- }
-
- //-------------------------------------------------------------------------------||
- // Utility Methods --------------------------------------------------------------||
- //-------------------------------------------------------------------------------||
-
- /**
- * Obtains the Thread Context ClassLoader
- */
- static ClassLoader getThreadContextClassLoader()
- {
- return AccessController.doPrivileged(new PrivilegedAction<ClassLoader>()
- {
- public ClassLoader run()
- {
- return Thread.currentThread().getContextClassLoader();
- }
- });
- }
-}
Copied: declarchive/trunk/impl-base/src/main/java/org/jboss/declarchive/impl/base/resource/SecurityActions.java (from rev 3449, declarchive/trunk/impl-base/src/main/java/org/jboss/declarchive/impl/base/resource/SecurityActions.java)
===================================================================
--- declarchive/trunk/impl-base/src/main/java/org/jboss/declarchive/impl/base/resource/SecurityActions.java (rev 0)
+++ declarchive/trunk/impl-base/src/main/java/org/jboss/declarchive/impl/base/resource/SecurityActions.java 2009-08-17 09:41:49 UTC (rev 3451)
@@ -0,0 +1,63 @@
+/*
+ * 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.declarchive.impl.base.resource;
+
+import java.security.AccessController;
+import java.security.PrivilegedAction;
+
+/**
+ * SecurityActions
+ *
+ * A set of privileged actions that are not to leak out
+ * of this package
+ *
+ * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
+ * @version $Revision: $
+ */
+class SecurityActions
+{
+
+ //-------------------------------------------------------------------------------||
+ // Constructor ------------------------------------------------------------------||
+ //-------------------------------------------------------------------------------||
+
+ /**
+ * No external instantiation
+ */
+ private SecurityActions()
+ {
+
+ }
+
+ //-------------------------------------------------------------------------------||
+ // Utility Methods --------------------------------------------------------------||
+ //-------------------------------------------------------------------------------||
+
+ /**
+ * Obtains the Thread Context ClassLoader
+ */
+ static ClassLoader getThreadContextClassLoader()
+ {
+ return AccessController.doPrivileged(new PrivilegedAction<ClassLoader>()
+ {
+ public ClassLoader run()
+ {
+ return Thread.currentThread().getContextClassLoader();
+ }
+ });
+ }
+}
Deleted: declarchive/trunk/impl-base/src/main/java/org/jboss/declarchive/impl/base/resource/URLResource.java
===================================================================
--- declarchive/trunk/impl-base/src/main/java/org/jboss/declarchive/impl/base/resource/URLResource.java 2009-08-13 06:01:04 UTC (rev 3449)
+++ declarchive/trunk/impl-base/src/main/java/org/jboss/declarchive/impl/base/resource/URLResource.java 2009-08-17 09:41:49 UTC (rev 3451)
@@ -1,90 +0,0 @@
-/*
- * 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.declarchive.impl.base.resource;
-
-import java.io.InputStream;
-import java.net.URL;
-
-import org.jboss.declarchive.spi.Resource;
-
-/**
- * Loads the content of any URL supported by the runtime.
- *
- * @author <a href="mailto:aslak at conduct.no">Aslak Knutsen</a>
- *
- */
-public class URLResource implements Resource
-{
- private URL url;
-
- /**
- * Create a new resource with a URL source.
- *
- * @param url A valid URL
- * @throws IllegalArgumentException URL can not be null
- */
- public URLResource(URL url)
- {
- // Precondition check
- if (url == null)
- {
- throw new IllegalArgumentException("URL must be specified");
- }
- this.url = url;
- }
-
- /**
- * Get the default name using URL.getFile().
- */
- @Override
- public String getDefaultName()
- {
- return extractFileName(url);
- }
-
- /**
- * Open the URL stream.
- *
- * @return A open stream with the content of the URL
- */
- @Override
- public InputStream getStream()
- {
- try
- {
- return url.openStream();
- }
- catch (Exception e)
- {
- throw new RuntimeException("Could not open stream for url " + url.toExternalForm(), e);
- }
- }
-
- /*
- * Extract the file name part of a URL excluding the directory structure.
- * ie: /user/test/file.properties = file.properties
- */
- private String extractFileName(URL url)
- {
- String fileName = url.getFile();
- if (fileName.indexOf('/') != -1)
- {
- return fileName.substring(fileName.lastIndexOf('/') + 1, fileName.length());
- }
- return fileName;
- }
-}
Copied: declarchive/trunk/impl-base/src/main/java/org/jboss/declarchive/impl/base/resource/URLResource.java (from rev 3449, declarchive/trunk/impl-base/src/main/java/org/jboss/declarchive/impl/base/resource/URLResource.java)
===================================================================
--- declarchive/trunk/impl-base/src/main/java/org/jboss/declarchive/impl/base/resource/URLResource.java (rev 0)
+++ declarchive/trunk/impl-base/src/main/java/org/jboss/declarchive/impl/base/resource/URLResource.java 2009-08-17 09:41:49 UTC (rev 3451)
@@ -0,0 +1,90 @@
+/*
+ * 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.declarchive.impl.base.resource;
+
+import java.io.InputStream;
+import java.net.URL;
+
+import org.jboss.declarchive.spi.Resource;
+
+/**
+ * Loads the content of any URL supported by the runtime.
+ *
+ * @author <a href="mailto:aslak at conduct.no">Aslak Knutsen</a>
+ *
+ */
+public class URLResource implements Resource
+{
+ private URL url;
+
+ /**
+ * Create a new resource with a URL source.
+ *
+ * @param url A valid URL
+ * @throws IllegalArgumentException URL can not be null
+ */
+ public URLResource(URL url)
+ {
+ // Precondition check
+ if (url == null)
+ {
+ throw new IllegalArgumentException("URL must be specified");
+ }
+ this.url = url;
+ }
+
+ /**
+ * Get the default name using URL.getFile().
+ */
+ @Override
+ public String getDefaultName()
+ {
+ return extractFileName(url);
+ }
+
+ /**
+ * Open the URL stream.
+ *
+ * @return A open stream with the content of the URL
+ */
+ @Override
+ public InputStream getStream()
+ {
+ try
+ {
+ return url.openStream();
+ }
+ catch (Exception e)
+ {
+ throw new RuntimeException("Could not open stream for url " + url.toExternalForm(), e);
+ }
+ }
+
+ /*
+ * Extract the file name part of a URL excluding the directory structure.
+ * ie: /user/test/file.properties = file.properties
+ */
+ private String extractFileName(URL url)
+ {
+ String fileName = url.getFile();
+ if (fileName.indexOf('/') != -1)
+ {
+ return fileName.substring(fileName.lastIndexOf('/') + 1, fileName.length());
+ }
+ return fileName;
+ }
+}
Modified: declarchive/trunk/impl-base/src/test/java/org/jboss/declarchive/impl/base/resource/ClassResourceTestCase.java
===================================================================
--- declarchive/trunk/impl-base/src/test/java/org/jboss/declarchive/impl/base/resource/ClassResourceTestCase.java 2009-08-15 10:26:34 UTC (rev 3450)
+++ declarchive/trunk/impl-base/src/test/java/org/jboss/declarchive/impl/base/resource/ClassResourceTestCase.java 2009-08-17 09:41:49 UTC (rev 3451)
@@ -18,8 +18,7 @@
import java.io.InputStream;
-import org.jboss.declarchive.api.Asset;
-import org.jboss.declarchive.impl.base.asset.ClassAsset;
+import org.jboss.declarchive.spi.Resource;
import org.junit.Assert;
import org.junit.Test;
@@ -37,7 +36,7 @@
@Test
public void shouldBeAbleToReadThisClass() throws Exception
{
- Asset resource = new ClassAsset(ClassResourceTestCase.class);
+ Resource resource = new ClassResource(ClassResourceTestCase.class);
InputStream io = resource.getStream();
Assert.assertNotNull(io);
@@ -48,25 +47,17 @@
@Test
public void shouldBeAbleToReadDefaultName() throws Exception
{
- Asset resource = new ClassAsset(ClassResourceTestCase.class);
- Assert.assertEquals("A Class resource should use class simple name + '.class' as default name",
- "ClassResourceTestCase.class", resource.getDefaultName());
+ Resource resource = new ClassResource(ClassResourceTestCase.class);
+ Assert.assertEquals("A Class resource should use class name + '.class' as default name",
+ "org/jboss/declarchive/impl/base/resource/ClassResourceTestCase.class", resource.getDefaultName());
}
@Test
- public void shouldBeAbleToReadPathName() throws Exception
- {
- Asset resource = new ClassAsset(ClassResourceTestCase.class);
- Assert.assertEquals("A Class resource should use class package name as default path",
- "/org/jboss/declarchive/impl/base/resource/", resource.getDefaultPath().get());
- }
-
- @Test
public void shouldThrowExceptionOnNullClass() throws Exception
{
try
{
- new ClassAsset(null);
+ new ClassResource(null);
Assert.fail("Should have thrown IllegalArgumentException");
}
catch (Exception e)
Modified: declarchive/trunk/impl-base/src/test/java/org/jboss/declarchive/impl/base/resource/ClassloaderResourceTestCase.java
===================================================================
--- declarchive/trunk/impl-base/src/test/java/org/jboss/declarchive/impl/base/resource/ClassloaderResourceTestCase.java 2009-08-15 10:26:34 UTC (rev 3450)
+++ declarchive/trunk/impl-base/src/test/java/org/jboss/declarchive/impl/base/resource/ClassloaderResourceTestCase.java 2009-08-17 09:41:49 UTC (rev 3451)
@@ -20,8 +20,7 @@
import junit.framework.Assert;
-import org.jboss.declarchive.api.Asset;
-import org.jboss.declarchive.impl.base.asset.ClassloaderAsset;
+import org.jboss.declarchive.spi.Resource;
import org.junit.Test;
/**
@@ -41,7 +40,7 @@
@Test
public void shouldBeAbleToReadResource() throws Exception
{
- Asset resource = new ClassloaderAsset(EXISTING_RESOURCE);
+ Resource resource = new ClassloaderResource(EXISTING_RESOURCE);
InputStream io = resource.getStream();
Assert.assertNotNull(io);
@@ -52,25 +51,17 @@
@Test
public void shouldBeAbleToReadDefaultName() throws Exception
{
- Asset resource = new ClassloaderAsset(EXISTING_RESOURCE);
+ Resource resource = new ClassloaderResource(EXISTING_RESOURCE);
Assert.assertEquals("A Classloader resource should use file name as default name, not absolute path",
"Test.properties", resource.getDefaultName());
}
@Test
- public void shouldBeAbleToReadDefaultPath() throws Exception
- {
- Asset resource = new ClassloaderAsset(EXISTING_RESOURCE);
- Assert.assertEquals("A Classloader resource should use given resource path as default path",
- "/org/jboss/declarchive/impl/base/resource/", resource.getDefaultPath().get());
- }
-
- @Test
public void shouldThrowExceptionOnNullName()
{
try
{
- new ClassloaderAsset(null);
+ new ClassloaderResource(null);
Assert.fail("Should have thrown IllegalArgumentException");
}
catch (Exception e)
@@ -85,7 +76,7 @@
{
try
{
- new ClassloaderAsset(EXISTING_RESOURCE, null);
+ new ClassloaderResource(EXISTING_RESOURCE, null);
Assert.fail("Should have thrown IllegalArgumentException");
}
catch (Exception e)
@@ -100,7 +91,7 @@
{
try
{
- new ClassloaderAsset(NON_EXISTING_RESOURCE);
+ new ClassloaderResource(NON_EXISTING_RESOURCE);
Assert.fail("Should have thrown IllegalArgumentException");
}
catch (Exception e)
Modified: declarchive/trunk/impl-base/src/test/java/org/jboss/declarchive/impl/base/resource/FileResourceTestCase.java
===================================================================
--- declarchive/trunk/impl-base/src/test/java/org/jboss/declarchive/impl/base/resource/FileResourceTestCase.java 2009-08-15 10:26:34 UTC (rev 3450)
+++ declarchive/trunk/impl-base/src/test/java/org/jboss/declarchive/impl/base/resource/FileResourceTestCase.java 2009-08-17 09:41:49 UTC (rev 3451)
@@ -21,8 +21,7 @@
import junit.framework.Assert;
-import org.jboss.declarchive.api.Asset;
-import org.jboss.declarchive.impl.base.asset.FileAsset;
+import org.jboss.declarchive.spi.Resource;
import org.junit.Test;
/**
@@ -44,36 +43,28 @@
@Test
public void shouldBeAbleToReadFile() throws Exception
{
- Asset resource = new FileAsset(new File(EXISTING_FILE));
+ Resource resource = new FileResource(new File(EXISTING_FILE));
InputStream io = resource.getStream();
Assert.assertNotNull(io);
- Assert.assertEquals("Should be able to read the content of the resource", "declarch=true",
- TestUtils.convertToString(io));
+ Assert.assertEquals("Should be able to read the content of the resource", "declarch=true", TestUtils
+ .convertToString(io));
}
@Test
public void shouldBeAbleToReadDefaultName() throws Exception
{
- Asset resource = new FileAsset(new File(EXISTING_FILE));
+ Resource resource = new FileResource(new File(EXISTING_FILE));
Assert.assertEquals("A File resource should use the file name as default name, not absolute path",
"Test.properties", resource.getDefaultName());
}
@Test
- public void shouldBeAbleToReadDefaultPath() throws Exception
- {
- Asset resource = new FileAsset(new File(EXISTING_FILE));
- Assert.assertEquals("A File resource should use the file parent name as default path",
- "/src/test/resources/org/jboss/declarchive/impl/base/resource/", resource.getDefaultPath().get());
- }
-
- @Test
public void shouldThrowExceptionOnNullFile() throws Exception
{
try
{
- new FileAsset(null);
+ new FileResource(null);
Assert.fail("Should have thrown IllegalArgumentException");
}
catch (Exception e)
@@ -88,7 +79,7 @@
{
try
{
- new FileAsset(new File(NON_EXISTING_FILE));
+ new FileResource(new File(NON_EXISTING_FILE));
Assert.fail("Should have thrown IllegalArgumentException");
}
catch (Exception e)
Modified: declarchive/trunk/impl-base/src/test/java/org/jboss/declarchive/impl/base/resource/URLResourceTestCase.java
===================================================================
--- declarchive/trunk/impl-base/src/test/java/org/jboss/declarchive/impl/base/resource/URLResourceTestCase.java 2009-08-15 10:26:34 UTC (rev 3450)
+++ declarchive/trunk/impl-base/src/test/java/org/jboss/declarchive/impl/base/resource/URLResourceTestCase.java 2009-08-17 09:41:49 UTC (rev 3451)
@@ -20,8 +20,7 @@
import junit.framework.Assert;
-import org.jboss.declarchive.api.Asset;
-import org.jboss.declarchive.impl.base.asset.UrlAsset;
+import org.jboss.declarchive.spi.Resource;
import org.junit.Test;
/**
@@ -39,8 +38,7 @@
@Test
public void shouldBeAbleToReadURL() throws Exception
{
- Asset resource = new UrlAsset(
- Thread.currentThread().getContextClassLoader().getResource(EXISTING_RESOURCE));
+ Resource resource = new URLResource(Thread.currentThread().getContextClassLoader().getResource(EXISTING_RESOURCE));
InputStream io = resource.getStream();
@@ -52,29 +50,18 @@
@Test
public void shouldBeAbleToReadDefaultName() throws Exception
{
- Asset resource = new UrlAsset(
- Thread.currentThread().getContextClassLoader().getResource(EXISTING_RESOURCE));
+ Resource resource = new URLResource(Thread.currentThread().getContextClassLoader().getResource(EXISTING_RESOURCE));
Assert.assertEquals("A URL resource should use the file name as default name, not absolute path",
"Test.properties", resource.getDefaultName());
}
@Test
- public void shouldBeAbleToReadDefaultPath() throws Exception
- {
- Asset resource = new UrlAsset(
- Thread.currentThread().getContextClassLoader().getResource(EXISTING_RESOURCE));
-
- Assert.assertEquals("A URL resource should use / as default path",
- "/", resource.getDefaultPath().get());
- }
-
- @Test
public void shouldThrowExceptionOnNullURL() throws Exception
{
try
{
- new UrlAsset(null);
+ new URLResource(null);
Assert.fail("Should have thrown IllegalArgumentException");
}
catch (Exception e)
Modified: declarchive/trunk/impl-jdkfile/src/main/java/org/jboss/declarchive/impl/jdkfile/TempFileArchiveImpl.java
===================================================================
--- declarchive/trunk/impl-jdkfile/src/main/java/org/jboss/declarchive/impl/jdkfile/TempFileArchiveImpl.java 2009-08-15 10:26:34 UTC (rev 3450)
+++ declarchive/trunk/impl-jdkfile/src/main/java/org/jboss/declarchive/impl/jdkfile/TempFileArchiveImpl.java 2009-08-17 09:41:49 UTC (rev 3451)
@@ -25,7 +25,7 @@
import java.util.logging.Logger;
import org.jboss.declarchive.api.Archive;
-import org.jboss.declarchive.impl.base.GenericArchive;
+import org.jboss.declarchive.impl.base.ArchiveBase;
import org.jboss.declarchive.spi.jdk.file.FileArchive;
/**
@@ -37,7 +37,7 @@
* @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
* @version $Revision: $
*/
-public class TempFileArchiveImpl extends GenericArchive<FileArchive> implements FileArchive
+public class TempFileArchiveImpl extends ArchiveBase<FileArchive> implements FileArchive
{
//-------------------------------------------------------------------------------------||
@@ -132,7 +132,7 @@
public TempFileArchiveImpl(final String name, final ClassLoader cl) throws IllegalArgumentException
{
// Invoke super
- super(name,cl,FileArchive.class);
+ super(cl);
// Precondition Check
if (name == null || name.length() == 0)
@@ -167,9 +167,9 @@
//-------------------------------------------------------------------------------------||
/**
- * @see org.jboss.declarchive.impl.base.GenericArchive#addContent(byte[], java.lang.String)
+ * @see org.jboss.declarchive.impl.base.ArchiveBase#addContent(byte[], java.lang.String)
*/
-// @Override
+ @Override
protected void addContent(final byte[] content, final String location) throws IllegalArgumentException
{
// Make the new pointer
@@ -257,6 +257,15 @@
return this.root;
}
+ /**
+ * @see org.jboss.declarchive.impl.base.ArchiveBase#getActualClass()
+ */
+ @Override
+ protected Class<FileArchive> getActualClass()
+ {
+ return FileArchive.class;
+ }
+
//-------------------------------------------------------------------------------------||
// Internal Helper Methods ------------------------------------------------------------||
//-------------------------------------------------------------------------------------||
Modified: declarchive/trunk/impl-vfs/src/main/java/org/jboss/declarchive/impl/vfs/MemoryArchiveImpl.java
===================================================================
--- declarchive/trunk/impl-vfs/src/main/java/org/jboss/declarchive/impl/vfs/MemoryArchiveImpl.java 2009-08-15 10:26:34 UTC (rev 3450)
+++ declarchive/trunk/impl-vfs/src/main/java/org/jboss/declarchive/impl/vfs/MemoryArchiveImpl.java 2009-08-17 09:41:49 UTC (rev 3451)
@@ -90,7 +90,7 @@
public MemoryArchiveImpl(final String name, final ClassLoader cl) throws IllegalArgumentException
{
// Invoke super
- super(name,cl);
+ super(cl);
// Precondition Check
if (name == null || name.length() == 0)
@@ -152,9 +152,9 @@
}
/**
- * @see org.jboss.declarchive.impl.base.GenericArchive#addContent(byte[], java.lang.String)
+ * @see org.jboss.declarchive.impl.base.ArchiveBase#addContent(byte[], java.lang.String)
*/
-// @Override
+ @Override
protected void addContent(final byte[] content, final String location) throws IllegalArgumentException
{
// Precondition check
@@ -189,4 +189,13 @@
this.addContent(content, url);
}
+ /**
+ * @see org.jboss.declarchive.impl.base.ArchiveBase#getActualClass()
+ */
+ @Override
+ protected Class<VfsArchive> getActualClass()
+ {
+ return VfsArchive.class;
+ }
+
}
Modified: declarchive/trunk/impl-vfs/src/main/java/org/jboss/declarchive/impl/vfs/VfsArchiveBase.java
===================================================================
--- declarchive/trunk/impl-vfs/src/main/java/org/jboss/declarchive/impl/vfs/VfsArchiveBase.java 2009-08-15 10:26:34 UTC (rev 3450)
+++ declarchive/trunk/impl-vfs/src/main/java/org/jboss/declarchive/impl/vfs/VfsArchiveBase.java 2009-08-17 09:41:49 UTC (rev 3451)
@@ -22,7 +22,7 @@
import java.util.logging.Logger;
import org.jboss.declarchive.api.Archive;
-import org.jboss.declarchive.impl.base.GenericArchive;
+import org.jboss.declarchive.impl.base.ArchiveBase;
import org.jboss.declarchive.spi.vfs.VfsArchive;
import org.jboss.virtual.VirtualFile;
@@ -34,7 +34,7 @@
* @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
* @version $Revision: $
*/
-abstract class VfsArchiveBase extends GenericArchive<VfsArchive> implements VfsArchive
+abstract class VfsArchiveBase extends ArchiveBase<VfsArchive>
{
//-------------------------------------------------------------------------------------||
@@ -72,15 +72,16 @@
/**
* Constructor
*
- * Creates a new instance with the specified name and ClassLoader
+ * Creates a new instance with the specified root and rootURL
*
- * @param name
+ * @param root
+ * @param rootUrl
* @param cl
*/
- public VfsArchiveBase(final String name, final ClassLoader cl)
+ public VfsArchiveBase(final ClassLoader cl)
{
// Invoke super
- super(name, cl, VfsArchive.class);
+ super(cl);
}
//-------------------------------------------------------------------------------------||
Modified: declarchive/trunk/impl-vfs/src/test/java/org/jboss/declarchive/impl/vfs/VfsMemoryArchiveFactoryTestCase.java
===================================================================
--- declarchive/trunk/impl-vfs/src/test/java/org/jboss/declarchive/impl/vfs/VfsMemoryArchiveFactoryTestCase.java 2009-08-15 10:26:34 UTC (rev 3450)
+++ declarchive/trunk/impl-vfs/src/test/java/org/jboss/declarchive/impl/vfs/VfsMemoryArchiveFactoryTestCase.java 2009-08-17 09:41:49 UTC (rev 3451)
@@ -21,7 +21,7 @@
import junit.framework.Assert;
import org.jboss.declarchive.api.VfsMemoryArchiveFactory;
-import org.jboss.declarchive.api.jar.JavaArchive;
+import org.jboss.declarchive.spi.vfs.VfsArchive;
import org.jboss.virtual.VFS;
import org.junit.BeforeClass;
import org.junit.Test;
@@ -72,18 +72,17 @@
@Test
public void testVirtualArchiveFactory() throws Exception
{
- //TODO Put back
-// // Log
-// log.info("testVirtualArchiveFactory");
-//
-// // Make an archive
-// final JavaArchive archive = VfsMemoryArchiveFactory.createArchive("testArchive.jar", JavaArchive.class);
-// archive.add(VfsMemoryArchiveFactory.class);
-// log.info("Archive: " + archive.toString(true));
-//
-// // Ensure exists
-// Assert.assertNotNull("Archive was not created/null", archive);
-// // Ensure of expected type
-// Assert.assertTrue("Created archive was not of expected type", archive instanceof JavaArchive);
+ // Log
+ log.info("testVirtualArchiveFactory");
+
+ // Make an archive
+ final VfsArchive archive = VfsMemoryArchiveFactory.createArchive("testArchive.jar", VfsArchive.class);
+ archive.addClass(VfsMemoryArchiveFactory.class);
+ log.info("Archive: " + archive.toString(true));
+
+ // Ensure exists
+ Assert.assertNotNull("Archive was not created/null", archive);
+ // Ensure of expected type
+ Assert.assertTrue("Created archive was not of expected type", archive instanceof VfsArchive);
}
}
Modified: declarchive/trunk/impl-vfs/src/test/java/org/jboss/declarchive/impl/vfs/VfsMemoryArchiveTestCase.java
===================================================================
--- declarchive/trunk/impl-vfs/src/test/java/org/jboss/declarchive/impl/vfs/VfsMemoryArchiveTestCase.java 2009-08-15 10:26:34 UTC (rev 3450)
+++ declarchive/trunk/impl-vfs/src/test/java/org/jboss/declarchive/impl/vfs/VfsMemoryArchiveTestCase.java 2009-08-17 09:41:49 UTC (rev 3451)
@@ -98,24 +98,23 @@
@Test
public void testAddResourceExplicitPathNameMemory() throws Exception
{
- //TODO Put back
-// // Log
-// log.info("testAddResourceExplicitPathNameMemory");
-//
-// // Get the base
-// final URL base = this.getBase();
-//
-// // Get the path to the test XML file
-// final URL location = new URL(base, PATH_SOMETHING_XML);
-//
-// // Define the new path
-// final String newPath = PATH_WEB_INF + SEPARATOR + FILENAME_WEB_XML;
-//
-// // Make a virtual archive
-// final Archive archive = new MemoryArchiveImpl("something.war").addResource(location, newPath);
-// log.info(archive.toString(true));
-//
-// //TODO Actually test something when we have better hooks to examine archive contents
+ // Log
+ log.info("testAddResourceExplicitPathNameMemory");
+
+ // Get the base
+ final URL base = this.getBase();
+
+ // Get the path to the test XML file
+ final URL location = new URL(base, PATH_SOMETHING_XML);
+
+ // Define the new path
+ final String newPath = PATH_WEB_INF + SEPARATOR + FILENAME_WEB_XML;
+
+ // Make a virtual archive
+ final Archive archive = new MemoryArchiveImpl("something.war").addResource(location, newPath);
+ log.info(archive.toString(true));
+
+ //TODO Actually test something when we have better hooks to examine archive contents
}
//-------------------------------------------------------------------------------------||
Copied: declarchive/trunk/spi/src/main/java/org/jboss/declarchive/spi/Resource.java (from rev 3449, declarchive/trunk/spi/src/main/java/org/jboss/declarchive/spi/Resource.java)
===================================================================
--- declarchive/trunk/spi/src/main/java/org/jboss/declarchive/spi/Resource.java (rev 0)
+++ declarchive/trunk/spi/src/main/java/org/jboss/declarchive/spi/Resource.java 2009-08-17 09:41:49 UTC (rev 3451)
@@ -0,0 +1,46 @@
+/*
+ * 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.declarchive.spi;
+
+import java.io.InputStream;
+
+/**
+ * Generic interface for resource loading.
+ *
+ * Used to move the resource loading logic out of the archive backends.
+ *
+ * @author <a href="mailto:aslak at conduct.no">Aslak Knutsen</a>
+ *
+ */
+public interface Resource
+{
+
+ /**
+ * Get the default name for this resource, can be overriden by the user.
+ *
+ * @return A name for this Resource
+ */
+ String getDefaultName();
+
+ /**
+ * Get a open stream for the resource content.
+ * The caller is responsible for closing the stream.
+ *
+ * @return A new open inputstream for each call.
+ */
+ InputStream getStream();
+}
More information about the jboss-svn-commits
mailing list