Package org.jboss.shrinkwrap.impl.base
Class MemoryMapArchiveBase<T extends Archive<T>>
- java.lang.Object
-
- org.jboss.shrinkwrap.impl.base.ArchiveBase<T>
-
- org.jboss.shrinkwrap.impl.base.MemoryMapArchiveBase<T>
-
- Type Parameters:
T
-
- All Implemented Interfaces:
Archive<T>
,Assignable
,ArchiveFormatAssociable
,Configurable
,Identifiable
- Direct Known Subclasses:
MemoryMapArchiveImpl
public abstract class MemoryMapArchiveBase<T extends Archive<T>> extends ArchiveBase<T> implements Archive<T>
MemoryMapArchiveBase A base implementation for all MemoryMap archives. Thread-safe.- Version:
- $Revision: $
-
-
Field Summary
Fields Modifier and Type Field Description private java.util.Map<ArchivePath,NodeImpl>
content
Storage for theNode
s.private java.util.List<ArchiveEventHandler>
handlers
private java.util.Map<ArchivePath,ArchiveAsset>
nestedArchives
Storage for theArchiveAsset
s.
-
Constructor Summary
Constructors Constructor Description MemoryMapArchiveBase(java.lang.String archiveName, Configuration configuration)
Constructor This constructor will generate anArchive
with the provided name.MemoryMapArchiveBase(Configuration configuration)
Constructor This constructor will generate a uniqueArchive.getName()
per instance.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description T
add(Archive<?> archive, java.lang.String path, java.lang.Class<? extends StreamExporter> exporter)
Add an archive under a specific context and maintain the archive name as context path.T
add(Archive<?> archive, ArchivePath path, java.lang.Class<? extends StreamExporter> exporter)
Add an archive under a specific context and maintain the archive name as context path.T
add(Asset asset, ArchivePath path)
Adds the specified asset under the specified path into the target contextT
addAsDirectory(ArchivePath path)
Adds the specified directory.private T
addAsset(ArchivePath path, Asset asset)
T
addHandlers(ArchiveEventHandler... handlers)
Add an array of listeners for call back based.private void
addNewNode(ArchivePath path, Asset handledAsset)
boolean
contains(java.lang.String path)
Denotes whether this archive contains a resource at the specified pathboolean
contains(ArchivePath path)
Denotes whether this archive contains a resource at the specified pathNode
delete(java.lang.String archivePath)
Node
delete(ArchivePath path)
Node
get(ArchivePath path)
Obtains theNode
located at the specified pathjava.util.Map<ArchivePath,Node>
getContent()
Obtains all assets in this archive, along with their respective paths.java.util.Map<ArchivePath,Node>
getContent(Filter<ArchivePath> filter)
Obtains all assets matching given filter in this archive, along with its respective Path.private Node
getNestedNode(ArchivePath path)
Attempt to get the asset from a nested archive.private ArchivePath
getNestedPath(ArchivePath fullPath, ArchivePath basePath)
Given a full path and a base path return a new path containing the full path with the base path removed from the beginning.private Asset
invokeHandlers(ArchivePath path, Asset asset)
private boolean
nestedContains(ArchivePath path)
Check to see if a path is found in a nested archiveprivate NodeImpl
obtainParent(ArchivePath path)
private Node
removeNodeRecursively(NodeImpl node, ArchivePath path)
Removes the specified node and its associated children from the contents of this archive.private boolean
startsWith(ArchivePath fullPath, ArchivePath startingPath)
Check to see if one path starts with another-
Methods inherited from class org.jboss.shrinkwrap.impl.base.ArchiveBase
add, add, add, add, addAsDirectories, addAsDirectories, addAsDirectory, as, covariantReturn, equals, filter, get, getActualClass, getArchiveFormat, getAsType, getAsType, getAsType, getAsType, getAsType, getAsType, getConfiguration, getId, getName, hashCode, merge, merge, merge, merge, merge, merge, move, move, setId, shallowCopy, shallowCopy, toString, toString, toString, writeTo
-
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, add, add, addAsDirectories, addAsDirectories, addAsDirectory, filter, get, getAsType, getAsType, getAsType, getAsType, getAsType, getAsType, getId, getName, merge, merge, merge, merge, merge, merge, move, move, shallowCopy, shallowCopy, toString, toString, toString, writeTo
-
Methods inherited from interface org.jboss.shrinkwrap.api.Assignable
as
-
-
-
-
Field Detail
-
content
private final java.util.Map<ArchivePath,NodeImpl> content
Storage for theNode
s.
-
nestedArchives
private final java.util.Map<ArchivePath,ArchiveAsset> nestedArchives
Storage for theArchiveAsset
s. Used to help get access to nested archive content.
-
handlers
private final java.util.List<ArchiveEventHandler> handlers
-
-
Constructor Detail
-
MemoryMapArchiveBase
public MemoryMapArchiveBase(Configuration configuration) throws java.lang.IllegalArgumentException
Constructor This constructor will generate a uniqueArchive.getName()
per instance.- Parameters:
configuration
- The configuration for this archive- Throws:
java.lang.IllegalArgumentException
- If the configuration is not specified
-
MemoryMapArchiveBase
public MemoryMapArchiveBase(java.lang.String archiveName, Configuration configuration) throws java.lang.IllegalArgumentException
Constructor This constructor will generate anArchive
with the provided name.- Parameters:
archiveName
-configuration
- The configuration for this archive- Throws:
java.lang.IllegalArgumentException
- If the name or configuration is not specified
-
-
Method Detail
-
add
public T add(Asset asset, ArchivePath path)
Adds the specified asset under the specified path into the target context
-
add
public T add(Archive<?> archive, java.lang.String path, java.lang.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, java.lang.String, java.lang.Class)
-
add
public T add(Archive<?> archive, ArchivePath path, java.lang.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>>
- Overrides:
add
in classArchiveBase<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:
ArchiveBase.add(org.jboss.shrinkwrap.api.Archive, org.jboss.shrinkwrap.api.ArchivePath, java.lang.Class)
-
addAsDirectory
public T addAsDirectory(ArchivePath path) throws java.lang.IllegalArgumentException
Adds the specified directory.- Specified by:
addAsDirectory
in interfaceArchive<T extends Archive<T>>
- Parameters:
path
- The path to add- Returns:
- This archive
- Throws:
java.lang.IllegalArgumentException
- If no path was specified- See Also:
Archive.addAsDirectory(org.jboss.shrinkwrap.api.ArchivePath)
-
addAsset
private T addAsset(ArchivePath path, Asset asset)
-
addNewNode
private void addNewNode(ArchivePath path, Asset handledAsset)
-
addHandlers
public T addHandlers(ArchiveEventHandler... handlers)
Add an array of listeners for call back based.- Specified by:
addHandlers
in interfaceArchive<T extends Archive<T>>
- Returns:
- This archive
- See Also:
org.jboss.shrinkwrap.api.Archive#addListener(org.jboss.shrinkwrap.api.Filter, org.jboss.shrinkwrap.api.ArchiveEventHandler)
-
invokeHandlers
private Asset invokeHandlers(ArchivePath path, Asset asset)
-
contains
public boolean contains(ArchivePath path)
Denotes whether this archive contains a resource at the specified path
-
contains
public boolean contains(java.lang.String path) throws java.lang.IllegalArgumentException
Denotes whether this archive contains a resource at the specified path
-
delete
public Node delete(ArchivePath path)
Removes theNode
in theArchive
at the specifiedArchivePath
. If the path is a directory, recursively removes all contents. If the path does not exist, return null.
-
removeNodeRecursively
private Node removeNodeRecursively(NodeImpl node, ArchivePath path)
Removes the specified node and its associated children from the contents of this archive.- Parameters:
node
- the node to remove recursivelypath
- the path denoting the specified node- Returns:
- the removed node itself
-
delete
public Node delete(java.lang.String archivePath)
Removes theNode
in theArchive
at theArchivePath
indicated by the specified String archivePath. If the path is a directory, recursively removes all contents. If the path does not exist, return null.
-
get
public Node get(ArchivePath path)
Obtains theNode
located at the specified path
-
getContent
public java.util.Map<ArchivePath,Node> getContent()
Obtains all assets in this archive, along with their respective paths. The returned Map will be an immutable view.- Specified by:
getContent
in interfaceArchive<T extends Archive<T>>
- Returns:
- See Also:
Archive.getContent()
-
getContent
public java.util.Map<ArchivePath,Node> getContent(Filter<ArchivePath> filter)
Obtains all assets matching given filter in this archive, along with its respective Path. The returned Map will be an immutable view.- Specified by:
getContent
in interfaceArchive<T extends Archive<T>>
- Returns:
- See Also:
Archive.getContent(org.jboss.shrinkwrap.api.Filter)
-
nestedContains
private boolean nestedContains(ArchivePath path)
Check to see if a path is found in a nested archive
-
getNestedNode
private Node getNestedNode(ArchivePath path)
Attempt to get the asset from a nested archive.- Parameters:
path
-- Returns:
-
startsWith
private boolean startsWith(ArchivePath fullPath, ArchivePath startingPath)
Check to see if one path starts with another- Parameters:
fullPath
-startingPath
-- Returns:
-
getNestedPath
private ArchivePath getNestedPath(ArchivePath fullPath, ArchivePath basePath)
Given a full path and a base path return a new path containing the full path with the base path removed from the beginning.- Parameters:
fullPath
-basePath
-- Returns:
-
obtainParent
private NodeImpl obtainParent(ArchivePath path)
Used to retrieve aNode
from the content of theArchive
. If theNode
doesn�t exists in the specified location, it is created and added to theArchive
. The same happens to all its non-existing parents. However, if theNode
is an asset, an IllegalArchivePathException is thrown.- Parameters:
path
- TheArchivePath
from which we are obtaining theNode
- Returns:
- The
Node
in the specified path - Throws:
IllegalArchivePathException
- if the node is anAsset
-
-