Class ArchiveBase<T extends Archive<T>>

    • Field Summary

      Fields 
      Modifier and Type Field Description
      private Configuration configuration
      Configuration for this archive
      private java.lang.String id
      Globally-unique ID for this archive
      private static java.util.logging.Logger log
      Logger
      private java.lang.String name
      Name of the archive
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      protected ArchiveBase​(java.lang.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, 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, java.lang.String target)
      Adds the specified resource under the context denoted by the specified target
      T add​(Asset asset, java.lang.String target, java.lang.String name)
      Adds the specified asset under the specified target (directory) using the specified name.
      T add​(Asset asset, ArchivePath path, java.lang.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 specified NamedAsset under the encapsulated name and target (directory)
      T addAsDirectories​(java.lang.String... paths)
      Adds the specified directories.
      T addAsDirectories​(ArchivePath... paths)
      Adds the specified directories.
      T addAsDirectory​(java.lang.String path)
      Adds the specified directory.
      <TYPE extends Assignable>
      TYPE
      as​(java.lang.Class<TYPE> clazz)
      Wraps an Archive in a different 'view'.
      protected T covariantReturn()
      Provides typesafe covariant return of this instance
      boolean equals​(java.lang.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​(java.lang.String path)
      Obtains the Node located at the specified path
      protected abstract java.lang.Class<T> getActualClass()
      Exposes the actual class used in casting
      ArchiveFormat getArchiveFormat()
      <X extends Archive<X>>
      X
      getAsType​(java.lang.Class<X> type, java.lang.String path)
      Get a nested Archive as a specific type.

      The found Archives must have been added as a Archive, no import is performed.
      <X extends Archive<X>>
      X
      getAsType​(java.lang.Class<X> type, java.lang.String path, ArchiveFormat archiveFormat)
      Get a nested Archive as a specific type using the specify ArchiveFormat
      <X extends Archive<X>>
      X
      getAsType​(java.lang.Class<X> type, ArchivePath path)
      Get a nested Archive as a specific type.

      The found Archives must have been added as a Archive, no import is performed.
      <X extends Archive<X>>
      X
      getAsType​(java.lang.Class<X> type, ArchivePath path, ArchiveFormat archiveFormat)
      Get a nested Archive located in a ArchivePath as a specific type using the specify ArchiveFormat
      <X extends Archive<X>>
      java.util.Collection<X>
      getAsType​(java.lang.Class<X> type, Filter<ArchivePath> filter)
      Get all nested Archive 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>>
      java.util.Collection<X>
      getAsType​(java.lang.Class<X> type, Filter<ArchivePath> filter, ArchiveFormat archiveFormat)
      Get all nested Archive matching the filter as a specific type using the specify ArchiveFormat.
      Configuration getConfiguration()
      Obtains the Configuration associated with this Archive
      java.lang.String getId()
      Obtains a globally-unique identifier for this Archive
      java.lang.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, java.lang.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, java.lang.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​(java.lang.String source, java.lang.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​(java.lang.String id)
      Sets the globally-unique identifier
      Archive<T> shallowCopy()
      Creates a shallow copy of this Archive.
      Archive<T> shallowCopy​(Filter<ArchivePath> filter)
      Creates a shallow copy of this Archive based on given filter.Assets from this archive are made available under the same paths.
      java.lang.String toString()
      Acts as a shorthand for Archive.toString(Formatter) where the Formatters.SIMPLE is leveraged.
      java.lang.String toString​(boolean verbose)
      If "true" is specified, acts as a shorthand for Archive.toString(Formatter) where the Formatters.VERBOSE is leveraged.
      java.lang.String toString​(Formatter formatter)
      Returns a view of this Archive as returned from the specified Formatter.
      void writeTo​(java.io.OutputStream outputStream, Formatter formatter)
      Prints the content of this Archive to the specified OutputStream on the format defined by the specified Formatter.
      • Methods inherited from class java.lang.Object

        clone, finalize, getClass, notify, notifyAll, wait, wait, wait
    • Field Detail

      • log

        private static final java.util.logging.Logger log
        Logger
      • name

        private final java.lang.String name
        Name of the archive
      • configuration

        private final Configuration configuration
        Configuration for this archive
      • id

        private java.lang.String id
        Globally-unique ID for this archive
    • Constructor Detail

      • ArchiveBase

        protected ArchiveBase​(java.lang.String name,
                              Configuration configuration)
                       throws java.lang.IllegalArgumentException
        Constructor Creates a new Archive with the specified name
        Parameters:
        name - Name of the archive
        configuration - The configuration for this archive
        Throws:
        java.lang.IllegalArgumentException - If the name was not specified
    • Method Detail

      • add

        public T add​(Asset asset,
                     java.lang.String target)
              throws java.lang.IllegalArgumentException
        Adds the specified resource under the context denoted by the specified target
        Specified by:
        add in interface Archive<T extends Archive<T>>
        Returns:
        Throws:
        java.lang.IllegalArgumentException - If either the target or asset is not specified
        See Also:
        org.jboss.shrinkwrap.api.Archive#add(java.lang.String, org.jboss.shrinkwrap.api.asset.Asset)
      • add

        public T add​(Asset asset,
                     java.lang.String target,
                     java.lang.String name)
              throws java.lang.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 interface Archive<T extends Archive<T>>
        target - The context directory under which to add the asset
        name - The name to assign the assent under the target namespace
        Returns:
        Throws:
        java.lang.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,
                     java.lang.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 interface Archive<T extends Archive<T>>
        path - The context directory under which to add the asset
        name - 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​(java.lang.String path)
                 throws java.lang.IllegalArgumentException
        Obtains the Node located at the specified path
        Specified by:
        get in interface Archive<T extends Archive<T>>
        Returns:
        The Node, or null if nothing is found at the Path
        Throws:
        java.lang.IllegalArgumentException - If the path is not specified
        See Also:
        Archive.get(java.lang.String)
      • getAsType

        public <X extends Archive<X>> X getAsType​(java.lang.Class<X> type,
                                                  java.lang.String path)
        Get a nested Archive as a specific type.

        The found Archives must have been added as a Archive, no import is performed.
        Specified by:
        getAsType in interface Archive<T extends Archive<T>>
        Parameters:
        type - The Type to return the Archive as
        path - The location of the Archive
        Returns:
        The found Archive as given type or null if none found at given path
        See Also:
        Archive.getAsType(java.lang.Class, java.lang.String)
      • add

        public T add​(NamedAsset namedAsset)
        Adds the asset encapsulated within the specified NamedAsset under the encapsulated name and target (directory)
        Specified by:
        add in interface Archive<T extends Archive<T>>
        Returns:
      • addAsDirectory

        public T addAsDirectory​(java.lang.String path)
                         throws java.lang.IllegalArgumentException
        Adds the specified directory.
        Specified by:
        addAsDirectory in interface Archive<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(java.lang.String)
      • addAsDirectories

        public T addAsDirectories​(java.lang.String... paths)
                           throws java.lang.IllegalArgumentException
        Adds the specified directories.
        Specified by:
        addAsDirectories in interface Archive<T extends Archive<T>>
        Parameters:
        paths - The paths to add
        Returns:
        This archive
        Throws:
        java.lang.IllegalArgumentException - If no paths were specified
        See Also:
        Archive.addAsDirectories(java.lang.String[])
      • setId

        public void setId​(java.lang.String id)
                   throws java.lang.IllegalArgumentException
        Description copied from interface: Identifiable
        Sets the globally-unique identifier
        Specified by:
        setId in interface Identifiable
        Throws:
        java.lang.IllegalArgumentException - If the ID is not specified
      • merge

        public T merge​(Archive<?> source)
                throws java.lang.IllegalArgumentException
        Merge the contents from an existing archive without maintaining the archive name in the context path.
        Specified by:
        merge in interface Archive<T extends Archive<T>>
        Parameters:
        source - Archive to add contents from
        Returns:
        Throws:
        java.lang.IllegalArgumentException - If the existing archive is not specified
        See Also:
        Archive.merge(org.jboss.shrinkwrap.api.Archive)
      • merge

        public T merge​(Archive<?> source,
                       ArchivePath path)
                throws java.lang.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 interface Archive<T extends Archive<T>>
        Parameters:
        source - Archive to add contents from
        path - Path to add contents to
        Returns:
        Throws:
        java.lang.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,
                       java.lang.String path)
                throws java.lang.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 interface Archive<T extends Archive<T>>
        Parameters:
        source - Archive to add contents from
        path - Path to add contents to
        Returns:
        Throws:
        java.lang.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 this Archive. 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 interface Archive<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 this Archive 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 interface Archive<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 java.lang.IllegalArgumentException
        Merge the contents from an existing archive in a specific path without maintaining the archive name in the context path. The filter control which ArchivePaths to include form the source Archive.
        Specified by:
        merge in interface Archive<T extends Archive<T>>
        Parameters:
        source - Archive to add contents from
        path - Path to add contents to
        filter - Filter to use for including Assets in the merge.
        Returns:
        Throws:
        java.lang.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​(java.lang.String source,
                      java.lang.String target)
               throws java.lang.IllegalArgumentException,
                      IllegalArchivePathException
        Moves the asset under the source path to the target path.
        Specified by:
        move in interface Archive<T extends Archive<T>>
        Parameters:
        source - The context under which to remove the assets
        target - The context under which to add the moved assets
        Returns:
        the resulting archive with the moved assets
        Throws:
        java.lang.IllegalArgumentException - If any of the paths is not specified
        IllegalArchivePathException - If the source path is invalid.
        See Also:
        Archive.move(java.lang.String, java.lang.String)
      • as

        public <TYPE extends Assignable> TYPE as​(java.lang.Class<TYPE> clazz)
        Wraps an Archive in a different 'view'.
        Specified by:
        as in interface Assignable
        Parameters:
        clazz - Extension interface to load
        Returns:
        The Archive wrapped as TYPE
        See Also:
        Assignable.as(java.lang.Class)
      • writeTo

        public void writeTo​(java.io.OutputStream outputStream,
                            Formatter formatter)
                     throws java.lang.IllegalArgumentException
        Prints the content of this Archive to the specified OutputStream on the format defined by the specified Formatter. The caller is responsible for opening, flushing and eventually closing the stream.
        Specified by:
        writeTo in interface Archive<T extends Archive<T>>
        Parameters:
        outputStream - the stream to print the archive contents to
        formatter - the output format
        Throws:
        java.lang.IllegalArgumentException - if an exceptions occur when writing the archive contents.
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class java.lang.Object
        See Also:
        org.jboss.shrinkwrap.api.Archive#hashCode()
      • equals

        public boolean equals​(java.lang.Object obj)
        Overrides:
        equals in class java.lang.Object
        See Also:
        org.jboss.shrinkwrap.api.Archive#equals(Object)
      • getActualClass

        protected abstract java.lang.Class<T> getActualClass()
        Exposes the actual class used in casting
        Returns:
      • covariantReturn

        protected final T covariantReturn()
        Provides typesafe covariant return of this instance