org.codehaus.cargo.module
Class AbstractDescriptorIo

java.lang.Object
  extended by org.codehaus.cargo.module.AbstractDescriptorIo
All Implemented Interfaces:
DescriptorIo
Direct Known Subclasses:
ApplicationXmlIo, EjbJarXmlIo, IbmEjbJarBndXmiIo, IbmWebBndXmiIo, JBossWebXmlIo, JBossXmlIo, OrionEjbJarXmlIo, OrionWebXmlIo, ResinWebXmlIo, TomcatContextXmlIo, WeblogicEjbJarXmlIo, WeblogicXmlIo, WebXmlIo

public abstract class AbstractDescriptorIo
extends Object
implements DescriptorIo

Provides convenience methods for reading and writing descriptors.

Version:
$Id: AbstractDescriptorIo.java 1705 2008-09-02 13:14:55Z adriana $

Constructor Summary
protected AbstractDescriptorIo(DescriptorType descriptorType)
          Constructor.
 
Method Summary
 org.jdom.input.SAXBuilder createDocumentBuilder()
          Create a document builder.
 org.jdom.input.SAXBuilder createDocumentBuilder(EntityResolver theEntityResolver)
           
protected  EntityResolver getEntityResolver()
          Get the default entity resolver for this type.
 org.jdom.Document parseXml(InputStream input)
          Parse XML into a document.
 org.jdom.Document parseXml(InputStream input, EntityResolver resolver)
          Create a document from the input stream and resolver.
static File[] writeAll(J2eeDescriptor descriptor, String dir)
          Writes the WebXml and its associated vendor descriptors to the specified directory.
static void writeDescriptor(Descriptor descriptor, File file)
          Writes the specified document to a file.
static void writeDescriptor(Descriptor descriptor, File file, String encoding)
          Writes the specified document to a file.
static void writeDescriptor(Descriptor descriptor, File file, String encoding, boolean isIndent)
          Writes the specified document to a file.
static void writeDescriptor(Descriptor descriptor, OutputStream out, String encoding, boolean isIndent)
          Writes the specified document to an output stream.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AbstractDescriptorIo

protected AbstractDescriptorIo(DescriptorType descriptorType)
Constructor.

Parameters:
descriptorType - the descriptor type.
Method Detail

createDocumentBuilder

public org.jdom.input.SAXBuilder createDocumentBuilder()
Create a document builder.

Specified by:
createDocumentBuilder in interface DescriptorIo
Returns:
new document builder

createDocumentBuilder

public org.jdom.input.SAXBuilder createDocumentBuilder(EntityResolver theEntityResolver)
Specified by:
createDocumentBuilder in interface DescriptorIo
Parameters:
theEntityResolver - entity resolver or null
Returns:
a new non-validating, non-namespace-aware DocumentBuilder instance

getEntityResolver

protected EntityResolver getEntityResolver()
Get the default entity resolver for this type.

Returns:
default resolver, or null if none

parseXml

public org.jdom.Document parseXml(InputStream input)
                           throws org.jdom.JDOMException,
                                  IOException
Description copied from interface: DescriptorIo
Parse XML into a document.

Specified by:
parseXml in interface DescriptorIo
Parameters:
input - the input stream
Returns:
JDOM Document
Throws:
IOException - if problem reading the stream
org.jdom.JDOMException - if problem parsing the stream

parseXml

public org.jdom.Document parseXml(InputStream input,
                                  EntityResolver resolver)
                           throws org.jdom.JDOMException,
                                  IOException
Create a document from the input stream and resolver.

Specified by:
parseXml in interface DescriptorIo
Parameters:
input - the input stream
resolver - entity resolver, or null
Returns:
JDOM Document
Throws:
IOException - if problem reading the stream
org.jdom.JDOMException - if problem parsing the stream

writeDescriptor

public static void writeDescriptor(Descriptor descriptor,
                                   File file)
                            throws IOException
Writes the specified document to a file.

Parameters:
descriptor - The descriptor to serialize
file - The file to write to
Throws:
IOException - If an I/O error occurs

writeDescriptor

public static void writeDescriptor(Descriptor descriptor,
                                   File file,
                                   String encoding)
                            throws IOException
Writes the specified document to a file.

Parameters:
descriptor - The descriptor to serialize
file - The file to write to
encoding - The character encoding to use
Throws:
IOException - If an I/O error occurs

writeDescriptor

public static void writeDescriptor(Descriptor descriptor,
                                   File file,
                                   String encoding,
                                   boolean isIndent)
                            throws IOException
Writes the specified document to a file.

Parameters:
descriptor - The descriptor to serialize
file - The file to write to
encoding - The character encoding to use
isIndent - Whether the written XML should be indented
Throws:
IOException - If an I/O error occurs

writeDescriptor

public static void writeDescriptor(Descriptor descriptor,
                                   OutputStream out,
                                   String encoding,
                                   boolean isIndent)
                            throws IOException
Writes the specified document to an output stream.

Parameters:
descriptor - The descriptor to serialize
out - The output stream to write to
encoding - The character encoding to use
isIndent - Whether the written XML should be indented
Throws:
IOException - If an I/O error occurs

writeAll

public static File[] writeAll(J2eeDescriptor descriptor,
                              String dir)
                       throws IOException
Writes the WebXml and its associated vendor descriptors to the specified directory.

Parameters:
descriptor - The descriptor to serialize
dir - Directory to store the descriptors in
Returns:
Array of files for every created file
Throws:
IOException - if a I/O error occurs


Copyright © 2004-2012 Codehaus. All Rights Reserved.