Oracle Fusion Middleware Java API Reference for Oracle Extension SDK Reference
11g Release 1 (11.1.1)

E13403-03

oracle.jdeveloper.deploy
Class DefaultArchive

java.lang.Object
  extended by oracle.jdeveloper.deploy.DefaultArchive
All Implemented Interfaces:
Copyable, Archive
Direct Known Subclasses:
DeploymentModule

public class DefaultArchive
extends java.lang.Object
implements Archive

Utility class used to build a jar file.


Field Summary
 
Fields inherited from interface oracle.jdeveloper.deploy.Archive
ARCHIVE_ENTRY_NAME_COMPARATOR, BUFFER_SIZE
 
Constructor Summary
protected DefaultArchive(boolean forceRewrite)
          Creates a new instance of DefaultArchive and initializes it to omit the Created-By line in the manifest file.
 
Method Summary
 void addContents(ArchiveEntry cdaPacket)
           
 void addContents(ArchiveEntry[] cdaPackets)
          Fills in the manifest with all necessary information provided by the ArchiveEntry array passed in.
 void addContents(java.util.Collection cdaPackets)
          Fills in the manifest with all necessary information provided by the Collection of ArchiveEntry instances passed in.
 void addContents(java.util.Collection cdaPackets, java.lang.String entryNamePrefix)
          Fills in the manifest with all necessary information provided by the Collection of ArchiveEntry instances passed in.
 void addDirectoryTrees(java.net.URL[] dirs, java.lang.String entryNamePrefix)
           
 boolean containsEntry(java.lang.String entryName)
           
 java.lang.Object copyTo(java.lang.Object target)
          Copies the internal state of this object to the specified copy.
protected  void copyToImpl(DefaultArchive copy)
           
static DefaultArchive create(boolean includeManifest, boolean forceRewrite)
          Convenience method.
 java.util.Iterator<ArchiveEntry> getArchiveEntries()
          Returns an iterator to the contents that have been added to the Archive instance so far.
 oracle.jdevimpl.deploy.CdaPacket[] getCdaPackets()
          Deprecated. Use getArchiveEntries() instead.
 java.util.ArrayList<ArchiveEntry[]> getCollisions()
           
 int getCompressionLevel()
          Return the desired compression level.
 ArchiveEntry getEntryByName(java.lang.String entryName)
          Get a handle to an ArchiveEntry by its name.
protected static java.lang.String getJarFileCreatedBy()
          Returns the string that should be used in the manifest file's Created-By main attribute.
 java.lang.String getMainAttribute(java.lang.String attrName)
          Returns the specified main attribute from the jar's manifest file.
 java.util.jar.Manifest getManifest()
          Returns the current Manifest.
 java.lang.String getManifestAsString()
          Returns the current Manfiest as a String.
 java.util.SortedSet getMissingEntryNames()
          Returns a SortedSet of entry names corresponding to entries which could not be found (i.e.
 boolean hasContents()
          Returns whether the written jar file had any contents.
 boolean isCompressed()
           
 boolean isIncludeManifest()
           
 void mergeManifest(java.util.jar.Manifest manifest)
          Merges the given Manifest with the manifest currently held by DefaultArchive.
 void mergeManifest(java.net.URL manifestURL)
          Merge the manifest at the specified URL.
 ArchiveEntry removeEntry(java.lang.String entryName)
           
 ArchiveEntry renameEntry(java.lang.String fromName, java.lang.String toName)
          Change the name of an ArchiveEntry.
 void setCompressed(boolean compressed)
          Sets whether the jar file that is written out should be compressed.
 void setCompressionLevel(int level)
          Set the desired compression level.
 void setCreatedBy(java.lang.String creator)
          Sets the Created-By main attribute for the manifest file.
 void setIncludeManifest(boolean includeManifest)
           
 void setMainAttribute(java.lang.String attrName, java.lang.String attrValue)
          Sets the specified main attribute for the jar's manifest file.
 void setMainClass(java.lang.String mainClass)
          Sets the Main-Class main attribute for the manifest file.
 void setReportNameCollisions(boolean reportNameCollisions)
          Deprecated. 
static boolean writeJarFile(Archive archive, java.net.URL outputURL, java.io.PrintWriter printWriter, boolean forceRewrite, boolean compressed)
          Utility method to write out a Jar file given an Archive.
 boolean writeJarFile(java.net.URL outputURL, java.io.PrintWriter printWriter)
          Writes out the jar file according to all of the ArchiveEntrys, manifests, and attributes that have been set on this DefaultArchive instance.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DefaultArchive

protected DefaultArchive(boolean forceRewrite)
Creates a new instance of DefaultArchive and initializes it to omit the Created-By line in the manifest file.

Method Detail

create

public static DefaultArchive create(boolean includeManifest,
                                    boolean forceRewrite)
Convenience method. Returns a new DefaultArchive instance. If includeManifest is true, a manifest file will be produced by the DefaultArchive instance, and the manifest file's Created-By attribute will be set to the appropriate value automatically.


getJarFileCreatedBy

protected static java.lang.String getJarFileCreatedBy()
Returns the string that should be used in the manifest file's Created-By main attribute.


getManifest

public java.util.jar.Manifest getManifest()
Returns the current Manifest.

Specified by:
getManifest in interface Archive

getManifestAsString

public java.lang.String getManifestAsString()
                                     throws java.io.IOException
Returns the current Manfiest as a String. If there is no manifest, null is returned.

Specified by:
getManifestAsString in interface Archive
Throws:
java.io.IOException - if an I/O exception occurs while converting the manifest contents to String.

setCreatedBy

public void setCreatedBy(java.lang.String creator)
Sets the Created-By main attribute for the manifest file.

If creator is null, then the Created-By attribute is removed from the manifest.

Specified by:
setCreatedBy in interface Archive

getMainAttribute

public java.lang.String getMainAttribute(java.lang.String attrName)
Returns the specified main attribute from the jar's manifest file. Returns null if the attribute does not exist. Throws IllegalArgumentException if the attribute name is not formatted properly.

Specified by:
getMainAttribute in interface Archive

setMainAttribute

public void setMainAttribute(java.lang.String attrName,
                             java.lang.String attrValue)
Sets the specified main attribute for the jar's manifest file. If attrName is null this method does nothing. If attrValue is null then the specified attribute is removed from the manifest's main attributes section.

Specified by:
setMainAttribute in interface Archive

setMainClass

public void setMainClass(java.lang.String mainClass)
Sets the Main-Class main attribute for the manifest file. The Main-Class attribute allows a jar file to be used on the command line to launch an application, so that you can launch the application with a command like java -jar MyApp.jar.

If mainClass is null, then the Main-Class attribute is removed from the manifest.

Specified by:
setMainClass in interface Archive

setCompressed

public void setCompressed(boolean compressed)
Sets whether the jar file that is written out should be compressed.

Specified by:
setCompressed in interface Archive

setCompressionLevel

public void setCompressionLevel(int level)
Description copied from interface: Archive
Set the desired compression level.

Specified by:
setCompressionLevel in interface Archive
Parameters:
level - the compression level, -1 or 0-9
See Also:
Deflater

isCompressed

public boolean isCompressed()
Specified by:
isCompressed in interface Archive

getCompressionLevel

public int getCompressionLevel()
Description copied from interface: Archive
Return the desired compression level.

Specified by:
getCompressionLevel in interface Archive
Returns:
See Also:
Deflater

isIncludeManifest

public boolean isIncludeManifest()
Specified by:
isIncludeManifest in interface Archive

setIncludeManifest

public void setIncludeManifest(boolean includeManifest)
Specified by:
setIncludeManifest in interface Archive

setReportNameCollisions

@Deprecated
public void setReportNameCollisions(boolean reportNameCollisions)
Deprecated. 

Specified by:
setReportNameCollisions in interface Archive

getCollisions

public java.util.ArrayList<ArchiveEntry[]> getCollisions()

mergeManifest

public void mergeManifest(java.util.jar.Manifest manifest)
Merges the given Manifest with the manifest currently held by DefaultArchive.

Specified by:
mergeManifest in interface Archive

mergeManifest

public void mergeManifest(java.net.URL manifestURL)
                   throws java.io.IOException
Merge the manifest at the specified URL.

Specified by:
mergeManifest in interface Archive
Throws:
java.io.IOException

addContents

public void addContents(java.util.Collection cdaPackets,
                        java.lang.String entryNamePrefix)
Fills in the manifest with all necessary information provided by the Collection of ArchiveEntry instances passed in. This Collection is traversed in the order provided by its Iterator. Before the collection of ArchiveEntrys is processed, the given entryNamePrefix is prepended to each ArchiveEntry's entryName. This provides a convenient way of adding a collection of content to a particular directory tree within the archive (e.g. "WEB-INF/classes/"). If the entryNamePrefix represents a directory, it must end with a forward-slash ("/"), because there is no automatic insertion of any intermediate character during the prepending.

Specified by:
addContents in interface Archive

addContents

public void addContents(java.util.Collection cdaPackets)
Fills in the manifest with all necessary information provided by the Collection of ArchiveEntry instances passed in. This Collection is traversed in the order provided by its Iterator.

Specified by:
addContents in interface Archive

addContents

public void addContents(ArchiveEntry cdaPacket)
Specified by:
addContents in interface Archive

containsEntry

public boolean containsEntry(java.lang.String entryName)
Specified by:
containsEntry in interface Archive

removeEntry

public ArchiveEntry removeEntry(java.lang.String entryName)
Specified by:
removeEntry in interface Archive

addContents

public void addContents(ArchiveEntry[] cdaPackets)
Fills in the manifest with all necessary information provided by the ArchiveEntry array passed in.

Specified by:
addContents in interface Archive

addDirectoryTrees

public void addDirectoryTrees(java.net.URL[] dirs,
                              java.lang.String entryNamePrefix)
Specified by:
addDirectoryTrees in interface Archive

getCdaPackets

@Deprecated
public oracle.jdevimpl.deploy.CdaPacket[] getCdaPackets()
Deprecated. Use getArchiveEntries() instead.

Returns an array of CdaPacket objects corresponding to the contents that have been added to the DefaultArchive instance so far.


getMissingEntryNames

public java.util.SortedSet getMissingEntryNames()
Returns a SortedSet of entry names corresponding to entries which could not be found (i.e. their URL is null). This information is based on the entries that have been added through one of the addContent() methods up to the point in time that getMissingEntryNames() is called. If no entries are missing, an empty SortedSet is returned.

Specified by:
getMissingEntryNames in interface Archive

hasContents

public boolean hasContents()
Returns whether the written jar file had any contents. If the jar file has not yet been written (via one of the writeJarFile() methods), then this will return false.

Specified by:
hasContents in interface Archive

writeJarFile

public boolean writeJarFile(java.net.URL outputURL,
                            java.io.PrintWriter printWriter)
                     throws java.io.IOException
Writes out the jar file according to all of the ArchiveEntrys, manifests, and attributes that have been set on this DefaultArchive instance.

Parameters:
outputURL - The URL where the jar file will be written.
printWriter - A PrintWriter where any output messages will be written. This parameter can be null which means that any output messages will not be printed at all.
Throws:
java.io.IOException

writeJarFile

public static boolean writeJarFile(Archive archive,
                                   java.net.URL outputURL,
                                   java.io.PrintWriter printWriter,
                                   boolean forceRewrite,
                                   boolean compressed)
                            throws java.io.IOException
Utility method to write out a Jar file given an Archive.

Parameters:
archive - the Archive to write out.
outputURL - the file to write to.
printWriter - print writer for log messages
forceRewrite - whether the jar should be re-written if one already exists at outputURL and if it is up-to-date. A timestamp comparision is done of the files within the jar and its Manifest.
compressed - if the file should be compressed
Returns:
true if the jar was successfully written.
Throws:
DeployException
java.io.IOException

getArchiveEntries

public java.util.Iterator<ArchiveEntry> getArchiveEntries()
Description copied from interface: Archive
Returns an iterator to the contents that have been added to the Archive instance so far.

Specified by:
getArchiveEntries in interface Archive

copyTo

public java.lang.Object copyTo(java.lang.Object target)
Description copied from interface: Copyable
Copies the internal state of this object to the specified copy. If copy is null, then this method should create a new instance of this class and proceed to copy the internal state to the newly created object. Generally, only the persistent state of the object should be copied, but whether or not it is appropriate to copy transient properties is at the discretion of the individual implementor.

Regardless of whether the copy occurs to an existing object or to a newly created object, the return value is object to which this object's state was copied.

There is a standard implementation pattern for the copyTo method that helps avoid problems that arise when a Copyable object is subclassed. The pattern is:


    public Object copyTo( Object target )
    {
      final <this_class> copy =
        target != null ? (<this_class>) target : new <this_class>();
      copyToImpl( copy );
      return copy;
    }

    protected final void copyToImpl( <this_class> copy )
    {
      super.copyToImpl( copy );  //  if necessary
      //  put code here for copying the properties of <this_class>
    }
  
The parameter passed into the copyToImpl method is the same type of this class. The responsibility of copyToImpl is to copy the state of this class through direct access of the fields. The copyToImpl method should not use getters and setters since these may be overridden, causing the state of this class to be incompletely copied.

Specified by:
copyTo in interface Copyable
Parameters:
target - The target object to which the state of this object should be copied. If target is null, then the copyTo method will return a new instance of this class.
Returns:
The object to which the state of this object was copied. If the target was non-null, then the return value is the same as the target object that was passed in; otherwise, the return value is a new instance of this class.

copyToImpl

protected void copyToImpl(DefaultArchive copy)

getEntryByName

public ArchiveEntry getEntryByName(java.lang.String entryName)
Description copied from interface: Archive
Get a handle to an ArchiveEntry by its name. Example; ArchiveEntry e = archive.getEntryByName("WEB-INF/web.xml");

Specified by:
getEntryByName in interface Archive
Returns:
ArchiveEntry if found, null if not found.

renameEntry

public ArchiveEntry renameEntry(java.lang.String fromName,
                                java.lang.String toName)
Description copied from interface: Archive
Change the name of an ArchiveEntry. This may be equivalent to doing a removeEntry(String) and an addContents(ArchiveEntry) depending on the implementation.

Specified by:
renameEntry in interface Archive
Returns:
the new ArchiveEntry if successfully renamed, null if fromName not found, or if fromName and toName are equal. For performance reasons, this method will not check if toName already exists, it will be silently overwritten.

Oracle Fusion Middleware Java API Reference for Oracle Extension SDK Reference
11g Release 1 (11.1.1)

E13403-03

Copyright © 1997, 2009, Oracle. All rights reserved.