[jboss-svn-commits] JBoss Common SVN: r3454 - declarchive/trunk/api/src/main/java/org/jboss/declarchive/api.

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Mon Aug 17 06:12:40 EDT 2009


Author: ALRubinger
Date: 2009-08-17 06:12:40 -0400 (Mon, 17 Aug 2009)
New Revision: 3454

Added:
   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
Modified:
   declarchive/trunk/api/src/main/java/org/jboss/declarchive/api/Archive.java
Log:
[TMPARCH-10] Create a generic archive API

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-17 09:57:19 UTC (rev 3453)
+++ declarchive/trunk/api/src/main/java/org/jboss/declarchive/api/Archive.java	2009-08-17 10:12:40 UTC (rev 3454)
@@ -16,7 +16,7 @@
  */
 package org.jboss.declarchive.api;
 
-import java.net.URL;
+import java.util.Map;
 
 /**
  * Archive
@@ -34,69 +34,102 @@
    //-------------------------------------------------------------------------------------||
 
    /**
-    * Adds the specified Class to the archive
+    * 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
     * 
-    * @param The class to add
-    * @return This virtual deployment
-    * @throws IllegalArgumentException If no class was specified
+    * @param target The context under which to add the assets 
+    * @param assets
+    * @return
+    * @throws IllegalArgumentException If no target or assets were specified
     */
-   T addClass(Class<?> clazz) throws IllegalArgumentException;
+   T add(Path target, Asset... assets) throws IllegalArgumentException;
 
    /**
-    * Adds the specified Classes to the archive.  
+    * 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.
     * 
-    * @param classes
-    * @return This virtual deployment
-    * @throws IllegalArgumentException If no classes were specified
+    * @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
     */
-   T addClasses(Class<?>... classes) throws IllegalArgumentException;
+   T add(Path target, String name, Asset asset) throws IllegalArgumentException;
 
    /**
-    * Adds the resource with the specified name to the 
-    * deployment.  The resource name must be visible to the ClassLoader
-    * of the archive
+    * Adds the specified resource under the context denoted by the specified target
     * 
-    * @param name
+    * @param target
+    * @param asset
     * @return
-    * @throws IllegalArgumentException If the name was not specified
+    * @throws IllegalArgumentException If either the target or asset is not specified 
     */
-   T addResource(String name) throws IllegalArgumentException;
+   T add(String target, Asset asset) throws IllegalArgumentException;
 
    /**
-    * Adds the specified resource to the archive, using the specified ClassLoader
-    * to load the resource
+    * Obtains the asset located at the specified path
     * 
-    * @param name
-    * @param cl
+    * @param path
     * @return
-    * @throws IllegalArgumentException If either the name or ClassLoader is not specified
+    * @throws AssetNotFoundException If the specified path does not 
+    *   point to any asset in the archive
+    * @throws IllegalArgumentException If the path is not specified
     */
-   T addResource(String name, ClassLoader cl) throws IllegalArgumentException;
+   Asset get(Path path) throws AssetNotFoundException, IllegalArgumentException;
 
    /**
-    * 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.
+    * Obtains the asset located at the specified path
     * 
-    * @param location
+    * @param path
     * @return
-    * @throws IllegalArgumentException If the location is not specified
+    * @throws AssetNotFoundException If the specified path does not 
+    *   point to any resource in the archive
+    * @throws IllegalArgumentException If the path is not specified
     */
-   T addResource(URL location) throws IllegalArgumentException;
+   Asset get(String path) throws AssetNotFoundException, IllegalArgumentException;
 
    /**
-    * Adds the resource located at the specified URL to
-    * the archive at the specified path.
+    * Denotes whether this archive contains a resource at the specified
+    * path
     * 
-    * @param location
-    * @param newPath The new path to assign, or null if 
-    *   the path portion of the location should be used
+    * @param path
     * @return
-    * @throws IllegalArgumentException If the location is not specified 
+    * @throws IllegalArgumentException If the path is not specified
     */
-   T addResource(URL location, String newPath) throws IllegalArgumentException;
+   boolean contains(Path path) 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

Added: declarchive/trunk/api/src/main/java/org/jboss/declarchive/api/Asset.java
===================================================================
--- declarchive/trunk/api/src/main/java/org/jboss/declarchive/api/Asset.java	                        (rev 0)
+++ declarchive/trunk/api/src/main/java/org/jboss/declarchive/api/Asset.java	2009-08-17 10:12:40 UTC (rev 3454)
@@ -0,0 +1,37 @@
+/*
+ * 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 a input stream for the resource content.
+    * The caller is responsible for closing the stream. 
+    * 
+    * @return A new open inputstream for each call.
+    */
+   InputStream getStream();
+}

Added: declarchive/trunk/api/src/main/java/org/jboss/declarchive/api/AssetNotFoundException.java
===================================================================
--- declarchive/trunk/api/src/main/java/org/jboss/declarchive/api/AssetNotFoundException.java	                        (rev 0)
+++ declarchive/trunk/api/src/main/java/org/jboss/declarchive/api/AssetNotFoundException.java	2009-08-17 10:12:40 UTC (rev 3454)
@@ -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.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);
+   }
+
+}

Added: declarchive/trunk/api/src/main/java/org/jboss/declarchive/api/Path.java
===================================================================
--- declarchive/trunk/api/src/main/java/org/jboss/declarchive/api/Path.java	                        (rev 0)
+++ declarchive/trunk/api/src/main/java/org/jboss/declarchive/api/Path.java	2009-08-17 10:12:40 UTC (rev 3454)
@@ -0,0 +1,36 @@
+/*
+ * 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();
+}



More information about the jboss-svn-commits mailing list