org.jboss.shrinkwrap.api
Class ShrinkWrap

java.lang.Object
  extended by org.jboss.shrinkwrap.api.ShrinkWrap

public final class ShrinkWrap
extends Object

Main entry point into the ShrinkWrap system. Each Archive has an associated Configuration provided at construction by the Domain under which the archive was created. ShrinkWrap provides static access to the default Domain (and by extension the default Configuration), as well as a shortcut mechanism to create Archives under these defaults by way of create(Class, String). Additionally, this class is the hook to create new Domains via createDomain(), createDomain(ConfigurationBuilder) or createDomain(Configuration).

Version:
$Revision: $
Author:
ALR, Ken Gullaksen

Method Summary
static
<T extends Assignable>
T
create(Class<T> type)
          Creates a new archive of the specified type.
static
<T extends Assignable>
T
create(Class<T> type, String archiveName)
          Creates a new archive of the specified type.
static Domain createDomain()
          Creates a new Domain containing a default Configuration.
static Domain createDomain(Configuration configuration)
          Creates a new Domain containing configuration properties from the supplied Configuration.
static Domain createDomain(ConfigurationBuilder builder)
          Creates a new Domain containing configuration properties from the supplied ConfigurationBuilder.
static
<T extends Assignable>
T
createFromZipFile(Class<T> type, File archiveFile)
          Creates a new archive of the specified type as imported from the specified File.
static Domain getDefaultDomain()
          Returns a single domain with default configuration for use in applications with no explicit configuration or isolation requirements.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

createDomain

public static Domain createDomain()
Creates a new Domain containing a default Configuration. ArchiveFactorys created from this domain will have isolated configuration from archive factories created from other domains. Likewise, all ArchiveFactorys and Archives created from the returned domain will share the same configuration.

Returns:
A new Domain with default configuration

createDomain

public static Domain createDomain(ConfigurationBuilder builder)
                           throws IllegalArgumentException
Creates a new Domain containing configuration properties from the supplied ConfigurationBuilder. ArchiveFactorys created from this domain will have isolated configuration from archive factories created from other domains. Likewise, all ArchiveFactorys and Archives created from the returned domain will share the same configuration.

Parameters:
builder - Builder with which we should create a Configuration for this Domain
Returns:
A new Domain with default configuration
Throws:
IllegalArgumentException - If the builder is not supplied

createDomain

public static Domain createDomain(Configuration configuration)
                           throws IllegalArgumentException
Creates a new Domain containing configuration properties from the supplied Configuration. ArchiveFactorys created from this domain will have isolated configuration from archive factories created from other domains. Likewise, all ArchiveFactorys and Archives created from the returned domain will share the same configuration.

Parameters:
configuration - Configuration for this Domain
Returns:
A new Domain with default configuration
Throws:
IllegalArgumentException - If the configuration is not supplied

getDefaultDomain

public static Domain getDefaultDomain()
Returns a single domain with default configuration for use in applications with no explicit configuration or isolation requirements.

Returns:
default Domain

create

public static <T extends Assignable> T create(Class<T> type)
                                   throws IllegalArgumentException,
                                          UnknownExtensionTypeException
Creates a new archive of the specified type. The archive will be be backed by the default Configuration. specific to this ArchiveFactory. Generates a random name for the archive and adds proper extension based on the service descriptor properties file if extension property is present (e.g. shrinkwrap/impl-base/src/main/resources/META-INF/services/org.jboss.shrinkwrap.api.spec.JavaArchive) Invoking this method is functionally equivalent to calling ArchiveFactory.create(Class) upon Domain.getArchiveFactory() upon the domain returned by getDefaultDomain().

Parameters:
type - The type of the archive e.g. WebArchive
Returns:
An Assignable archive base
Throws:
IllegalArgumentException - if type is not specified
UnknownExtensionTypeException - If no extension mapping is found for the specified type

create

public static <T extends Assignable> T create(Class<T> type,
                                              String archiveName)
                                   throws IllegalArgumentException
Creates a new archive of the specified type. The archive will be be backed by the default Configuration. Invoking this method is functionally equivalent to calling ArchiveFactory.create(Class, String) upon Domain.getArchiveFactory() upon the domain returned by getDefaultDomain().

Parameters:
type - The type of the archive e.g. WebArchive
archiveName - The name of the archive
Returns:
An Assignable archive base
Throws:
IllegalArgumentException - either argument is not specified

createFromZipFile

public static <T extends Assignable> T createFromZipFile(Class<T> type,
                                                         File archiveFile)
                                              throws IllegalArgumentException,
                                                     ArchiveImportException
Creates a new archive of the specified type as imported from the specified File. The file is expected to be encoded as ZIP (ie. JAR/WAR/EAR). The name of the archive will be set to File.getName(). The archive will be be backed by the Configuration within the getDefaultDomain()

Parameters:
type - The type of the archive e.g. WebArchive
archiveFile - the archiveName to use
Returns:
An Assignable view
Throws:
IllegalArgumentException - If either argument is not supplied, if the specified File does not exist, or is not a valid ZIP file
ArchiveImportException - If an error occurred during the import process


Copyright © 2011 JBoss, a division of Red Hat, Inc.. All Rights Reserved.