org.objectweb.jonas_ws.wsgen.jarfile
Class JarManager

java.lang.Object
  extended byorg.objectweb.jonas_ws.wsgen.jarfile.JarManager
Direct Known Subclasses:
EarManager, WsJarManager

public class JarManager
extends java.lang.Object

Manage a jar file.

Author:
Xavier Delplanque

Field Summary
protected  java.lang.String filename
          original jar filename
protected static org.objectweb.util.monolog.api.Logger logger
          The logger to use
protected  java.util.Map newEntries
          Map (Entry->File)
protected  java.lang.String outDir
          output directory
 
Constructor Summary
JarManager(java.lang.String jarFilename)
          Build a new instance of a JarManager.
JarManager(java.lang.String jarFilename, java.lang.String destDir)
          Build an instance of JarManager.
 
Method Summary
 void addDir(java.io.File dir)
          Add all Files contained in a directory in the current jar file.
 void addDir(java.lang.String base, java.io.File dir)
          Add all Files contained in a directory in the current jar file.
 void addDir(java.lang.String base, java.io.File dir, java.lang.String ends)
          Add Files contained in a directory in the current jar file at the specified entryName location.
 void addFile(java.lang.String entryName, java.io.File file)
          Add a new File in the current jar file.
protected  void addXml(java.lang.String name, org.objectweb.jonas_ws.wsgen.xml.Xml xml)
          Add an Xml object to be marshalled when saving.
 void close()
          Delete the copy
 void finalize()
          When instance destructed, close the Streams.
 java.lang.String getFilename()
          Return the filename managed.
 java.lang.String getOutFilename()
          Return the filename of the destination file.
protected static java.lang.String getSAXMsg(java.lang.String fileName, org.xml.sax.SAXParseException exception, java.lang.String msg)
          build a message from SAX Exception in a consistent style, consistent with emacs compile mode (same as grep, cc, javac, etc).
protected  boolean isNewFile()
          Return true if a new jar file has been created.
protected  boolean omit(java.lang.String name)
          Omit filename yes/no ?.
 void save()
          Add all jar entries in the jar file.
 void setOutputDir(java.lang.String dir)
           
protected static void writeEntry(java.lang.String en, java.io.InputStream is, java.util.jar.JarOutputStream jos)
          write a new entry in the jar output stream.
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

filename

protected java.lang.String filename
original jar filename


outDir

protected java.lang.String outDir
output directory


newEntries

protected java.util.Map newEntries
Map (Entry->File)


logger

protected static org.objectweb.util.monolog.api.Logger logger
The logger to use

Constructor Detail

JarManager

public JarManager(java.lang.String jarFilename,
                  java.lang.String destDir)
           throws WsGenException
Build an instance of JarManager.

Parameters:
jarFilename - the name of the jar file that we want to manage.
destDir - the name of the directory where final file will be created.
Throws:
WsGenException - if the jar cannot be created

JarManager

public JarManager(java.lang.String jarFilename)
           throws WsGenException
Build a new instance of a JarManager. Create the file if it doesn't exists. By default, modify the file.

Parameters:
jarFilename - the name of the jar file that we want to manage.
Throws:
WsGenException - if jar cannot be created
Method Detail

getFilename

public java.lang.String getFilename()
Return the filename managed.

Returns:
the filename managed.

getOutFilename

public java.lang.String getOutFilename()
Return the filename of the destination file.

Returns:
the filename of the destination file.

setOutputDir

public void setOutputDir(java.lang.String dir)
                  throws WsGenException
Throws:
WsGenException

addDir

public void addDir(java.io.File dir)
            throws WsGenException
Add all Files contained in a directory in the current jar file. This adding keep the same file structure (directory & subdir).

Parameters:
dir - the directory to add
Throws:
WsGenException - when IOExceptio occurs?

addDir

public void addDir(java.lang.String base,
                   java.io.File dir)
            throws WsGenException
Add all Files contained in a directory in the current jar file. This adding keep the same file structure (directory & subdir).

Parameters:
base - entry base name.
dir - the directory to add.
Throws:
WsGenException - when IOException occurs

addDir

public void addDir(java.lang.String base,
                   java.io.File dir,
                   java.lang.String ends)
            throws WsGenException
Add Files contained in a directory in the current jar file at the specified entryName location. This adding keep the same file structure (directory & subdir).

Parameters:
base - where to put directory files in the jar
dir - the directory to add
ends - the filename accept pattern
Throws:
WsGenException - when IOException occurs

addFile

public void addFile(java.lang.String entryName,
                    java.io.File file)
             throws WsGenException
Add a new File in the current jar file.

Parameters:
entryName - where to put the file in the jar
file - the file to add
Throws:
WsGenException - when IOException occurs

getSAXMsg

protected static java.lang.String getSAXMsg(java.lang.String fileName,
                                            org.xml.sax.SAXParseException exception,
                                            java.lang.String msg)
build a message from SAX Exception in a consistent style, consistent with emacs compile mode (same as grep, cc, javac, etc).

Parameters:
fileName - name of the file
exception - the SAX exception
msg - the string message
Returns:
a message which is in a consistent style

isNewFile

protected boolean isNewFile()
Return true if a new jar file has been created.

Returns:
true if a new jar file has been created.

writeEntry

protected static void writeEntry(java.lang.String en,
                                 java.io.InputStream is,
                                 java.util.jar.JarOutputStream jos)
                          throws WsGenException
write a new entry in the jar output stream.

Parameters:
en - the entry name
is - the input stream to read.
jos - the output stream to write.
Throws:
WsGenException - when writing entry fails.

save

public void save()
          throws WsGenException
Add all jar entries in the jar file. Save the file on the disk.

Throws:
WsGenException - when save fails.

close

public void close()
Delete the copy


finalize

public void finalize()
When instance destructed, close the Streams.


omit

protected boolean omit(java.lang.String name)
Omit filename yes/no ?. Need to be overridden in sub classes.

Parameters:
name - name of entry to be tested
Returns:
true if file must be omitted, otherwise false

addXml

protected void addXml(java.lang.String name,
                      org.objectweb.jonas_ws.wsgen.xml.Xml xml)
Add an Xml object to be marshalled when saving.

Parameters:
name - entry name.
xml - the Xml object.