Package org.jboss.shrinkwrap.impl.base
Class ArchiveBase<T extends Archive<T>>
- java.lang.Object
-
- org.jboss.shrinkwrap.impl.base.ArchiveBase<T>
-
- All Implemented Interfaces:
Archive<T>
,Assignable
,ArchiveFormatAssociable
,Configurable
,Identifiable
- Direct Known Subclasses:
MemoryMapArchiveBase
public abstract class ArchiveBase<T extends Archive<T>> extends Object implements Archive<T>, Configurable, ArchiveFormatAssociable, Identifiable
Base implementation ofArchive
. Contains support for operations (typically overloaded) that are not specific to any particular storage implementation, and may be delegated to other forms.- Version:
- $Revision: $
- Author:
- ALR, John Bailey
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
ArchiveBase(String name, Configuration configuration)
Constructor Creates a new Archive with the specified name
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description T
add(Archive<?> archive, ArchivePath path, Class<? extends StreamExporter> exporter)
Add an archive under a specific context and maintain the archive name as context path.T
add(Asset asset, String target)
Adds the specified resource under the context denoted by the specified targetT
add(Asset asset, String target, String name)
Adds the specified asset under the specified target (directory) using the specified name.T
add(Asset asset, ArchivePath path, String name)
Adds the specified asset under the specified target (directory) using the specified name.T
add(NamedAsset namedAsset)
Adds the asset encapsulated within the specifiedNamedAsset
under the encapsulated name and target (directory)T
addAsDirectories(String... paths)
Adds the specified directories.T
addAsDirectories(ArchivePath... paths)
Adds the specified directories.T
addAsDirectory(String path)
Adds the specified directory.<TYPE extends Assignable>
TYPEas(Class<TYPE> clazz)
Wraps an Archive in a different 'view'.protected T
covariantReturn()
Provides typesafe covariant return of this instanceboolean
equals(Object obj)
T
filter(Filter<ArchivePath> filter)
Obtains all assets matching given filter in this archive as a new Archive.
This is an alias for shallowCopy(Filter).Node
get(String path)
Obtains theNode
located at the specified pathprotected abstract Class<T>
getActualClass()
Exposes the actual class used in castingArchiveFormat
getArchiveFormat()
<X extends Archive<X>>
XgetAsType(Class<X> type, String path)
Get a nestedArchive
as a specific type.
The found Archives must have been added as a Archive, no import is performed.<X extends Archive<X>>
XgetAsType(Class<X> type, String path, ArchiveFormat archiveFormat)
Get a nestedArchive
as a specific type using the specifyArchiveFormat
<X extends Archive<X>>
XgetAsType(Class<X> type, ArchivePath path)
Get a nestedArchive
as a specific type.
The found Archives must have been added as a Archive, no import is performed.<X extends Archive<X>>
XgetAsType(Class<X> type, ArchivePath path, ArchiveFormat archiveFormat)
<X extends Archive<X>>
Collection<X>getAsType(Class<X> type, Filter<ArchivePath> filter)
Get all nestedArchive
matching the filter as a specific type.
The found Archives must have been added as a Archive, no import is performed.<X extends Archive<X>>
Collection<X>getAsType(Class<X> type, Filter<ArchivePath> filter, ArchiveFormat archiveFormat)
Get all nestedArchive
matching the filter as a specific type using the specifyArchiveFormat
.Configuration
getConfiguration()
Obtains theConfiguration
associated with thisArchive
String
getId()
Obtains a globally-unique identifier for thisArchive
String
getName()
Obtains the name of this archive (ie.int
hashCode()
T
merge(Archive<?> source)
Merge the contents from an existing archive without maintaining the archive name in the context path.T
merge(Archive<?> source, String path)
Merge the contents from an existing archive in a specific path without maintaining the archive name in the context path.T
merge(Archive<?> source, String path, Filter<ArchivePath> filter)
Merge the contents from an existing archive in a specific path without maintaining the archive name in the context path.T
merge(Archive<?> source, ArchivePath path)
Merge the contents from an existing archive in a specific path without maintaining the archive name in the context path.T
merge(Archive<?> source, ArchivePath path, Filter<ArchivePath> filter)
Merge the contents from an existing archive in a specific path without maintaining the archive name in the context path.T
merge(Archive<?> source, Filter<ArchivePath> filter)
Merge the contents from an existing archive without maintaining the archive name in the context path.T
move(String source, String target)
Moves the asset under the source path to the target path.T
move(ArchivePath source, ArchivePath target)
Moves the asset under the source path to the target path.void
setId(String id)
Sets the globally-unique identifierArchive<T>
shallowCopy()
Creates a shallow copy of thisArchive
.Archive<T>
shallowCopy(Filter<ArchivePath> filter)
Creates a shallow copy of thisArchive
based on given filter.Assets from this archive are made available under the same paths.String
toString()
Acts as a shorthand forArchive.toString(Formatter)
where theFormatters.SIMPLE
is leveraged.String
toString(boolean verbose)
If "true" is specified, acts as a shorthand forArchive.toString(Formatter)
where theFormatters.VERBOSE
is leveraged.String
toString(Formatter formatter)
void
writeTo(OutputStream outputStream, Formatter formatter)
Prints the content of thisArchive
to the specifiedOutputStream
on the format defined by the specifiedFormatter
.-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface org.jboss.shrinkwrap.api.Archive
add, add, addAsDirectory, addHandlers, contains, contains, delete, delete, get, getContent, getContent
-
-
-
-
Constructor Detail
-
ArchiveBase
protected ArchiveBase(String name, Configuration configuration) throws IllegalArgumentException
Constructor Creates a new Archive with the specified name- Parameters:
name
- Name of the archiveconfiguration
- The configuration for this archive- Throws:
IllegalArgumentException
- If the name was not specified
-
-
Method Detail
-
getArchiveFormat
public ArchiveFormat getArchiveFormat()
- Specified by:
getArchiveFormat
in interfaceArchiveFormatAssociable
- See Also:
ArchiveFormatAssociable.getArchiveFormat()
-
add
public T add(Asset asset, String target) throws IllegalArgumentException
Adds the specified resource under the context denoted by the specified target
-
add
public T add(Asset asset, String target, String name) 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.- Specified by:
add
in interfaceArchive<T extends Archive<T>>
target
- The context directory under which to add the assetname
- The name to assign the assent under the target namespace- Returns:
- Throws:
IllegalArgumentException
- If the target, name, or asset was not specified- See Also:
Archive.add(org.jboss.shrinkwrap.api.asset.Asset, java.lang.String, java.lang.String)
-
add
public T add(Asset asset, ArchivePath path, String name)
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.- Specified by:
add
in interfaceArchive<T extends Archive<T>>
path
- The context directory under which to add the assetname
- The name to assign the assent under the target namespace- Returns:
- See Also:
org.jboss.shrinkwrap.api.Archive#add(org.jboss.shrinkwrap.api.ArchivePath, java.lang.String, org.jboss.shrinkwrap.api.asset.Asset)
-
get
public Node get(String path) throws IllegalArgumentException
Obtains theNode
located at the specified path- Specified by:
get
in interfaceArchive<T extends Archive<T>>
- Returns:
- The
Node
, or null if nothing is found at the Path - Throws:
IllegalArgumentException
- If the path is not specified- See Also:
Archive.get(java.lang.String)
-
getAsType
public <X extends Archive<X>> X getAsType(Class<X> type, String path)
Get a nestedArchive
as a specific type.
The found Archives must have been added as a Archive, no import is performed.
-
getAsType
public <X extends Archive<X>> Collection<X> getAsType(Class<X> type, Filter<ArchivePath> filter)
Get all nestedArchive
matching the filter as a specific type.
The found Archives must have been added as a Archive, no import is performed.- Specified by:
getAsType
in interfaceArchive<T extends Archive<T>>
- Parameters:
type
- The Type to return the Archive asfilter
- Filter to match result- Returns:
- A
Collection
of found Archives matching given filter or emptyCollection
if non found. - See Also:
Archive.getAsType(java.lang.Class, org.jboss.shrinkwrap.api.Filter)
-
getAsType
public <X extends Archive<X>> X getAsType(Class<X> type, ArchivePath path)
Get a nestedArchive
as a specific type.
The found Archives must have been added as a Archive, no import is performed.- Specified by:
getAsType
in interfaceArchive<T extends Archive<T>>
- Parameters:
type
- The Type to return the Archive aspath
- The location of the Archive- Returns:
- The found Archive as given type or null if none found at given
ArchivePath
- See Also:
Archive.getAsType(java.lang.Class, org.jboss.shrinkwrap.api.ArchivePath)
-
getAsType
public <X extends Archive<X>> X getAsType(Class<X> type, String path, ArchiveFormat archiveFormat)
Get a nestedArchive
as a specific type using the specifyArchiveFormat
- Specified by:
getAsType
in interfaceArchive<T extends Archive<T>>
- Parameters:
type
- The Type to return the Archive aspath
- The location of the ArchivearchiveFormat
- The archive format- Returns:
- The found Archive as given type or null if none found at the given path
- See Also:
Archive.getAsType(java.lang.Class, java.lang.String, org.jboss.shrinkwrap.api.ArchiveFormat)
-
getAsType
public <X extends Archive<X>> X getAsType(Class<X> type, ArchivePath path, ArchiveFormat archiveFormat)
- Specified by:
getAsType
in interfaceArchive<T extends Archive<T>>
- Parameters:
type
- The Type to return the Archive aspath
- The location of the ArchivearchiveFormat
- The archive format- Returns:
- The found Archive as given type or null if none found at given
ArchivePath
- See Also:
Archive.getAsType(java.lang.Class, org.jboss.shrinkwrap.api.ArchivePath, org.jboss.shrinkwrap.api.ArchiveFormat)
-
getAsType
public <X extends Archive<X>> Collection<X> getAsType(Class<X> type, Filter<ArchivePath> filter, ArchiveFormat archiveFormat)
Get all nestedArchive
matching the filter as a specific type using the specifyArchiveFormat
.- Specified by:
getAsType
in interfaceArchive<T extends Archive<T>>
- Parameters:
type
- The Type to return the Archive asfilter
- Filter to match resultarchiveFormat
- The archive format- Returns:
- A
Collection
of found Archives matching given filter or emptyCollection
if non found. - See Also:
Archive.getAsType(java.lang.Class, org.jboss.shrinkwrap.api.Filter, org.jboss.shrinkwrap.api.ArchiveFormat)
-
filter
public T filter(Filter<ArchivePath> filter)
Obtains all assets matching given filter in this archive as a new Archive.
This is an alias for shallowCopy(Filter).
-
add
public T add(Archive<?> archive, ArchivePath path, Class<? extends StreamExporter> exporter)
Add an archive under a specific context and maintain the archive name as context path.- Specified by:
add
in interfaceArchive<T extends Archive<T>>
- Parameters:
archive
- to addpath
- to useexporter
- Exporter type to use in fulfilling theAsset.openStream()
contract for the added (nested) archive.- Returns:
- See Also:
Archive.add(org.jboss.shrinkwrap.api.Archive, org.jboss.shrinkwrap.api.ArchivePath, java.lang.Class)
-
add
public T add(NamedAsset namedAsset)
Adds the asset encapsulated within the specifiedNamedAsset
under the encapsulated name and target (directory)
-
addAsDirectory
public T addAsDirectory(String path) throws IllegalArgumentException
Adds the specified directory.- Specified by:
addAsDirectory
in interfaceArchive<T extends Archive<T>>
- Parameters:
path
- The path to add- Returns:
- This archive
- Throws:
IllegalArgumentException
- If no path was specified- See Also:
Archive.addAsDirectory(java.lang.String)
-
addAsDirectories
public T addAsDirectories(ArchivePath... paths) throws IllegalArgumentException
Adds the specified directories.- Specified by:
addAsDirectories
in interfaceArchive<T extends Archive<T>>
- Parameters:
paths
- The paths to add- Returns:
- This archive
- Throws:
IllegalArgumentException
- If no paths were specified- See Also:
Archive.addAsDirectories(org.jboss.shrinkwrap.api.ArchivePath[])
-
addAsDirectories
public T addAsDirectories(String... paths) throws IllegalArgumentException
Adds the specified directories.- Specified by:
addAsDirectories
in interfaceArchive<T extends Archive<T>>
- Parameters:
paths
- The paths to add- Returns:
- This archive
- Throws:
IllegalArgumentException
- If no paths were specified- See Also:
Archive.addAsDirectories(java.lang.String[])
-
getName
public final String getName()
Obtains the name of this archive (ie. myLibrary.jar)
-
getId
public String getId()
Obtains a globally-unique identifier for thisArchive
- Specified by:
getId
in interfaceArchive<T extends Archive<T>>
- Specified by:
getId
in interfaceIdentifiable
- Returns:
- See Also:
Archive.getId()
-
setId
public void setId(String id) throws IllegalArgumentException
Description copied from interface:Identifiable
Sets the globally-unique identifier- Specified by:
setId
in interfaceIdentifiable
- Throws:
IllegalArgumentException
- If the ID is not specified
-
merge
public T merge(Archive<?> source) throws IllegalArgumentException
Merge the contents from an existing archive without maintaining the archive name in the context path.- Specified by:
merge
in interfaceArchive<T extends Archive<T>>
- Parameters:
source
- Archive to add contents from- Returns:
- Throws:
IllegalArgumentException
- If the existing archive is not specified- See Also:
Archive.merge(org.jboss.shrinkwrap.api.Archive)
-
merge
public T merge(Archive<?> source, Filter<ArchivePath> filter) throws IllegalArgumentException
Merge the contents from an existing archive without maintaining the archive name in the context path. The filter control whichArchivePath
s to include form the sourceArchive
.- Specified by:
merge
in interfaceArchive<T extends Archive<T>>
- Parameters:
source
- Archive to add contents from- Returns:
- Throws:
IllegalArgumentException
- If the existing archive is not specified- See Also:
Archive.merge(org.jboss.shrinkwrap.api.Archive, org.jboss.shrinkwrap.api.Filter)
-
merge
public T merge(Archive<?> source, ArchivePath path) throws IllegalArgumentException
Merge the contents from an existing archive in a specific path without maintaining the archive name in the context path.- Specified by:
merge
in interfaceArchive<T extends Archive<T>>
- Parameters:
source
- Archive to add contents frompath
- Path to add contents to- Returns:
- Throws:
IllegalArgumentException
- If the path or existing archive is not specified- See Also:
org.jboss.shrinkwrap.api.Archive#merge(org.jboss.shrinkwrap.api.ArchivePath, org.jboss.shrinkwrap.api.Archive)
-
merge
public T merge(Archive<?> source, String path, Filter<ArchivePath> filter) throws IllegalArgumentException
Merge the contents from an existing archive in a specific path without maintaining the archive name in the context path. The filter control whichArchivePath
s to include form the sourceArchive
.- Specified by:
merge
in interfaceArchive<T extends Archive<T>>
- Parameters:
source
- Archive to add contents frompath
- Path to add contents tofilter
- Filter to use for includingAsset
s in the merge.- Returns:
- Throws:
IllegalArgumentException
- If the path or existing archive is not specified- See Also:
Archive.merge(org.jboss.shrinkwrap.api.Archive, java.lang.String, org.jboss.shrinkwrap.api.Filter)
-
merge
public T merge(Archive<?> source, String path) throws IllegalArgumentException
Merge the contents from an existing archive in a specific path without maintaining the archive name in the context path.- Specified by:
merge
in interfaceArchive<T extends Archive<T>>
- Parameters:
source
- Archive to add contents frompath
- Path to add contents to- Returns:
- Throws:
IllegalArgumentException
- If the path or existing archive is not specified- See Also:
Archive.merge(org.jboss.shrinkwrap.api.Archive, java.lang.String)
-
shallowCopy
public final Archive<T> shallowCopy()
Creates a shallow copy of thisArchive
. Assets from this archive are made available under the same paths. However, removing old assets or adding new assets on this archive affects does not affect the new archive.- Specified by:
shallowCopy
in interfaceArchive<T extends Archive<T>>
- Returns:
- a new archive with a copy of the pointers to the assets
- See Also:
Archive.shallowCopy()
-
shallowCopy
public final Archive<T> shallowCopy(Filter<ArchivePath> filter)
Creates a shallow copy of thisArchive
based on given filter.Assets from this archive are made available under the same paths. However, removing old assets or adding new assets on this archive affects does not affect the new archive.- Specified by:
shallowCopy
in interfaceArchive<T extends Archive<T>>
- Returns:
- a new archive with a copy of the pointers to the assets
- See Also:
Archive.shallowCopy(Filter)
-
merge
public T merge(Archive<?> source, ArchivePath path, Filter<ArchivePath> filter) throws IllegalArgumentException
Merge the contents from an existing archive in a specific path without maintaining the archive name in the context path. The filter control whichArchivePath
s to include form the sourceArchive
.- Specified by:
merge
in interfaceArchive<T extends Archive<T>>
- Parameters:
source
- Archive to add contents frompath
- Path to add contents tofilter
- Filter to use for includingAsset
s in the merge.- Returns:
- Throws:
IllegalArgumentException
- If the path or existing archive is not specified- See Also:
org.jboss.shrinkwrap.api.Archive#merge(org.jboss.shrinkwrap.api.Archive, org.jboss.shrinkwrap.api.Path, org.jboss.shrinkwrap.api.Filter)
-
move
public T move(ArchivePath source, ArchivePath target) throws IllegalArgumentException, IllegalArchivePathException
Moves the asset under the source path to the target path.- Specified by:
move
in interfaceArchive<T extends Archive<T>>
- Parameters:
source
- The context under which to remove the assetstarget
- The context under which to add the moved assets- Returns:
- the resulting archive with the moved assets
- Throws:
IllegalArgumentException
- If any of the paths is not specifiedIllegalArchivePathException
- If the source path is invalid.- See Also:
Archive.move(org.jboss.shrinkwrap.api.ArchivePath, org.jboss.shrinkwrap.api.ArchivePath)
-
move
public T move(String source, String target) throws IllegalArgumentException, IllegalArchivePathException
Moves the asset under the source path to the target path.- Specified by:
move
in interfaceArchive<T extends Archive<T>>
- Parameters:
source
- The context under which to remove the assetstarget
- The context under which to add the moved assets- Returns:
- the resulting archive with the moved assets
- Throws:
IllegalArgumentException
- If any of the paths is not specifiedIllegalArchivePathException
- If the source path is invalid.- See Also:
Archive.move(java.lang.String, java.lang.String)
-
as
public <TYPE extends Assignable> TYPE as(Class<TYPE> clazz)
Wraps an Archive in a different 'view'.- Specified by:
as
in interfaceAssignable
- Parameters:
clazz
- Extension interface to load- Returns:
- The Archive wrapped as TYPE
- See Also:
Assignable.as(java.lang.Class)
-
toString
public String toString()
Acts as a shorthand forArchive.toString(Formatter)
where theFormatters.SIMPLE
is leveraged.
-
toString
public String toString(boolean verbose)
If "true" is specified, acts as a shorthand forArchive.toString(Formatter)
where theFormatters.VERBOSE
is leveraged. Otherwise theFormatters.SIMPLE
will be used (equivalent toArchive.toString()
).
-
toString
public String toString(Formatter formatter) throws IllegalArgumentException
Returns a view of thisArchive
as returned from the specifiedFormatter
. Common options may be to use the predefined formatters located inFormatters
- Specified by:
toString
in interfaceArchive<T extends Archive<T>>
- Returns:
- Throws:
IllegalArgumentException
- If the formatter is not specified- See Also:
Archive.toString(org.jboss.shrinkwrap.api.formatter.Formatter)
-
writeTo
public void writeTo(OutputStream outputStream, Formatter formatter) throws IllegalArgumentException
Prints the content of thisArchive
to the specifiedOutputStream
on the format defined by the specifiedFormatter
. The caller is responsible for opening, flushing and eventually closing the stream.
-
hashCode
public int hashCode()
-
equals
public boolean equals(Object obj)
-
getConfiguration
public Configuration getConfiguration()
Obtains theConfiguration
associated with thisArchive
- Specified by:
getConfiguration
in interfaceConfigurable
- See Also:
Configurable.getConfiguration()
-
getActualClass
protected abstract Class<T> getActualClass()
Exposes the actual class used in casting- Returns:
-
covariantReturn
protected final T covariantReturn()
Provides typesafe covariant return of this instance
-
-