[jboss-svn-commits] JBoss Common SVN: r3442 - in declarchive/trunk: api/src/main/java/org/jboss/declarchive/api/moveout and 5 other directories.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Tue Aug 11 18:46:11 EDT 2009
Author: ALRubinger
Date: 2009-08-11 18:46:11 -0400 (Tue, 11 Aug 2009)
New Revision: 3442
Added:
declarchive/trunk/api/src/main/java/org/jboss/declarchive/api/moveout/
declarchive/trunk/api/src/main/java/org/jboss/declarchive/api/moveout/JavaArchive.java
Modified:
declarchive/trunk/api/src/main/java/org/jboss/declarchive/api/Archive.java
declarchive/trunk/api/src/main/java/org/jboss/declarchive/api/VfsMemoryArchiveFactory.java
declarchive/trunk/impl-base/src/main/java/org/jboss/declarchive/impl/base/ArchiveBase.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/spi-jdkfile/src/main/java/org/jboss/declarchive/spi/jdk/file/FileArchive.java
declarchive/trunk/spi-vfs/src/main/java/org/jboss/declarchive/spi/vfs/VfsArchive.java
Log:
[TMPARCH-3] Support for covarient return for Archives; will probably need to be reworked to allow for N extension points of Archive<T>
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-08 14:21:37 UTC (rev 3441)
+++ declarchive/trunk/api/src/main/java/org/jboss/declarchive/api/Archive.java 2009-08-11 22:46:11 UTC (rev 3442)
@@ -27,7 +27,7 @@
* @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
* @version $Revision: $
*/
-public interface Archive
+public interface Archive<T extends Archive<?>>
{
//-------------------------------------------------------------------------------------||
// Contracts --------------------------------------------------------------------------||
@@ -40,7 +40,7 @@
* @return This virtual deployment
* @throws IllegalArgumentException If no class was specified
*/
- Archive addClass(Class<?> clazz) throws IllegalArgumentException;
+ T addClass(Class<?> clazz) throws IllegalArgumentException;
/**
* Adds the specified Classes to the archive.
@@ -49,7 +49,7 @@
* @return This virtual deployment
* @throws IllegalArgumentException If no classes were specified
*/
- Archive addClasses(Class<?>... classes) throws IllegalArgumentException;
+ T addClasses(Class<?>... classes) throws IllegalArgumentException;
/**
* Adds the resource with the specified name to the
@@ -60,7 +60,7 @@
* @return
* @throws IllegalArgumentException If the name was not specified
*/
- Archive addResource(String name) throws IllegalArgumentException;
+ T addResource(String name) throws IllegalArgumentException;
/**
* Adds the specified resource to the archive, using the specified ClassLoader
@@ -71,7 +71,7 @@
* @return
* @throws IllegalArgumentException If either the name or ClassLoader is not specified
*/
- Archive addResource(String name, ClassLoader cl) throws IllegalArgumentException;
+ T addResource(String name, ClassLoader cl) throws IllegalArgumentException;
/**
* Adds the resource located at the specified URL to the archive. The
@@ -82,7 +82,7 @@
* @return
* @throws IllegalArgumentException If the location is not specified
*/
- Archive addResource(URL location) throws IllegalArgumentException;
+ T addResource(URL location) throws IllegalArgumentException;
/**
* Adds the resource located at the specified URL to
@@ -94,7 +94,7 @@
* @return
* @throws IllegalArgumentException If the location is not specified
*/
- Archive addResource(URL location, String newPath) throws IllegalArgumentException;
+ T addResource(URL location, String newPath) throws IllegalArgumentException;
/**
* Returns a multiline "ls -l"-equse output of the contents of
Modified: declarchive/trunk/api/src/main/java/org/jboss/declarchive/api/VfsMemoryArchiveFactory.java
===================================================================
--- declarchive/trunk/api/src/main/java/org/jboss/declarchive/api/VfsMemoryArchiveFactory.java 2009-08-08 14:21:37 UTC (rev 3441)
+++ declarchive/trunk/api/src/main/java/org/jboss/declarchive/api/VfsMemoryArchiveFactory.java 2009-08-11 22:46:11 UTC (rev 3442)
@@ -90,7 +90,7 @@
* @param name
* @throws IllegalArgumentException If the name is not specified
*/
- public static Archive createVirtualArchive(final String name) throws IllegalArgumentException
+ public static Archive<?> createVirtualArchive(final String name) throws IllegalArgumentException
{
// Precondition check
if (name == null || name.length() == 0)
@@ -121,7 +121,7 @@
}
// Cast
- final Archive archive;
+ final Archive<?> archive;
try
{
archive = Archive.class.cast(obj);
Added: declarchive/trunk/api/src/main/java/org/jboss/declarchive/api/moveout/JavaArchive.java
===================================================================
--- declarchive/trunk/api/src/main/java/org/jboss/declarchive/api/moveout/JavaArchive.java (rev 0)
+++ declarchive/trunk/api/src/main/java/org/jboss/declarchive/api/moveout/JavaArchive.java 2009-08-11 22:46:11 UTC (rev 3442)
@@ -0,0 +1,39 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.declarchive.api.moveout;
+
+import org.jboss.declarchive.api.Archive;
+
+
+/**
+ * JavaArchive
+ *
+ * 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>
+ * @version $Revision: $
+ */
+public interface JavaArchive extends Archive<JavaArchive>
+{
+}
Modified: 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 2009-08-08 14:21:37 UTC (rev 3441)
+++ declarchive/trunk/impl-base/src/main/java/org/jboss/declarchive/impl/base/ArchiveBase.java 2009-08-11 22:46:11 UTC (rev 3442)
@@ -34,7 +34,7 @@
* @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
* @version $Revision: $
*/
-public abstract class ArchiveBase implements Archive
+public abstract class ArchiveBase<T extends Archive<?>> implements Archive<T>
{
//-------------------------------------------------------------------------------------||
@@ -122,7 +122,7 @@
* @see org.jboss.declarchive.api.Archive#addClass(java.lang.Class)
*/
@Override
- public Archive addClass(final Class<?> clazz) throws IllegalArgumentException
+ public T addClass(final Class<?> clazz) throws IllegalArgumentException
{
// Precondition check
if (clazz == null)
@@ -148,7 +148,7 @@
* @see org.jboss.declarchive.api.Archive#addClasses(java.lang.Class<?>[])
*/
@Override
- public Archive addClasses(final Class<?>... classes) throws IllegalArgumentException
+ public T addClasses(final Class<?>... classes) throws IllegalArgumentException
{
// Precondition check
if (classes == null || classes.length == 0)
@@ -163,14 +163,14 @@
}
// Return
- return this;
+ return this.covarientReturn();
}
/**
* @see org.jboss.declarchive.api.Archive#addResource(java.lang.String)
*/
@Override
- public Archive addResource(final String name) throws IllegalArgumentException
+ public T addResource(final String name) throws IllegalArgumentException
{
return this.addResource(name, this.getClassLoader());
}
@@ -179,7 +179,7 @@
* @see org.jboss.declarchive.api.Archive#addResource(java.net.URL)
*/
@Override
- public Archive addResource(final URL location) throws IllegalArgumentException
+ public T addResource(final URL location) throws IllegalArgumentException
{
// Delegate to the other implementation
return this.addResource(location, null);
@@ -189,7 +189,7 @@
* @see org.jboss.declarchive.api.Archive#addResource(java.lang.String, java.lang.ClassLoader)
*/
@Override
- public final Archive addResource(final String name, final ClassLoader cl) throws IllegalArgumentException
+ public final T addResource(final String name, final ClassLoader cl) throws IllegalArgumentException
{
// Precondition check
if (name == null || name.length() == 0)
@@ -216,14 +216,14 @@
this.addContent(content, name);
// Return
- return this;
+ return this.covarientReturn();
}
/**
* @see org.jboss.declarchive.api.Archive#addResource(java.net.URL, java.lang.String)
*/
@Override
- public Archive addResource(final URL location, final String newPath) throws IllegalArgumentException
+ public T addResource(final URL location, final String newPath) throws IllegalArgumentException
{
// Precondition check
if (location == null)
@@ -257,7 +257,7 @@
this.addContent(content, path);
// Return
- return this;
+ return this.covarientReturn();
}
//-------------------------------------------------------------------------------------||
@@ -273,11 +273,37 @@
*/
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
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-08 14:21:37 UTC (rev 3441)
+++ declarchive/trunk/impl-jdkfile/src/main/java/org/jboss/declarchive/impl/jdkfile/TempFileArchiveImpl.java 2009-08-11 22:46:11 UTC (rev 3442)
@@ -37,7 +37,7 @@
* @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
* @version $Revision: $
*/
-public class TempFileArchiveImpl extends ArchiveBase implements FileArchive
+public class TempFileArchiveImpl extends ArchiveBase<FileArchive> implements FileArchive
{
//-------------------------------------------------------------------------------------||
@@ -166,9 +166,8 @@
// Required Implementations -----------------------------------------------------------||
//-------------------------------------------------------------------------------------||
- /*
- * (non-Javadoc)
- * @see org.jboss.embedded.core.incubation.virtual.impl.base.AbstractVirtualArchive#addContent(byte[], java.lang.String)
+ /**
+ * @see org.jboss.declarchive.impl.base.ArchiveBase#addContent(byte[], java.lang.String)
*/
@Override
protected void addContent(final byte[] content, final String location) throws IllegalArgumentException
@@ -220,9 +219,8 @@
}
}
- /*
- * (non-Javadoc)
- * @see org.jboss.embedded.core.incubation.virtual.api.VirtualArchive#toString(boolean)
+ /**
+ * @see org.jboss.declarchive.api.Archive#toString(boolean)
*/
@Override
public String toString(final boolean verbose)
@@ -241,7 +239,7 @@
}
}
- /* (non-Javadoc)
+ /**
* @see java.lang.Object#toString()
*/
@Override
@@ -250,9 +248,8 @@
return super.toString() + ": " + this.getRoot().getAbsolutePath();
}
- /*
- * (non-Javadoc)
- * @see org.jboss.embedded.core.incubation.virtual.spi.jdk.VirtualJdkArchive#getRoot()
+ /**
+ * @see org.jboss.declarchive.spi.jdk.file.FileArchive#getRoot()
*/
@Override
public File getRoot()
@@ -260,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-08 14:21:37 UTC (rev 3441)
+++ declarchive/trunk/impl-vfs/src/main/java/org/jboss/declarchive/impl/vfs/MemoryArchiveImpl.java 2009-08-11 22:46:11 UTC (rev 3442)
@@ -151,9 +151,8 @@
}
- /*
- * (non-Javadoc)
- * @see org.jboss.embedded.core.incubation.virtual.impl.base.AbstractVirtualArchive#addContent(byte[], java.lang.String)
+ /**
+ * @see org.jboss.declarchive.impl.base.ArchiveBase#addContent(byte[], java.lang.String)
*/
@Override
protected void addContent(final byte[] content, final String location) throws IllegalArgumentException
@@ -190,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-08 14:21:37 UTC (rev 3441)
+++ declarchive/trunk/impl-vfs/src/main/java/org/jboss/declarchive/impl/vfs/VfsArchiveBase.java 2009-08-11 22:46:11 UTC (rev 3442)
@@ -23,6 +23,7 @@
import org.jboss.declarchive.api.Archive;
import org.jboss.declarchive.impl.base.ArchiveBase;
+import org.jboss.declarchive.spi.vfs.VfsArchive;
import org.jboss.virtual.VirtualFile;
/**
@@ -33,7 +34,7 @@
* @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
* @version $Revision: $
*/
-abstract class VfsArchiveBase extends ArchiveBase
+abstract class VfsArchiveBase extends ArchiveBase<VfsArchive>
{
//-------------------------------------------------------------------------------------||
Modified: declarchive/trunk/spi-jdkfile/src/main/java/org/jboss/declarchive/spi/jdk/file/FileArchive.java
===================================================================
--- declarchive/trunk/spi-jdkfile/src/main/java/org/jboss/declarchive/spi/jdk/file/FileArchive.java 2009-08-08 14:21:37 UTC (rev 3441)
+++ declarchive/trunk/spi-jdkfile/src/main/java/org/jboss/declarchive/spi/jdk/file/FileArchive.java 2009-08-11 22:46:11 UTC (rev 3442)
@@ -32,7 +32,7 @@
* @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
* @version $Revision: $
*/
-public interface FileArchive extends Archive
+public interface FileArchive extends Archive<FileArchive>
{
//-------------------------------------------------------------------------------------||
// Contracts --------------------------------------------------------------------------||
@@ -45,4 +45,4 @@
* @return
*/
File getRoot();
-}
+}
\ No newline at end of file
Modified: declarchive/trunk/spi-vfs/src/main/java/org/jboss/declarchive/spi/vfs/VfsArchive.java
===================================================================
--- declarchive/trunk/spi-vfs/src/main/java/org/jboss/declarchive/spi/vfs/VfsArchive.java 2009-08-08 14:21:37 UTC (rev 3441)
+++ declarchive/trunk/spi-vfs/src/main/java/org/jboss/declarchive/spi/vfs/VfsArchive.java 2009-08-11 22:46:11 UTC (rev 3442)
@@ -30,7 +30,7 @@
* @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
* @version $Revision: $
*/
-public interface VfsArchive extends Archive
+public interface VfsArchive extends Archive<VfsArchive>
{
//-------------------------------------------------------------------------------------||
// Contracts --------------------------------------------------------------------------||
More information about the jboss-svn-commits
mailing list