FileDocCategorySizeDatePackage
J2EEDocumentBuilder.javaAPI DocGlassfish v2 API7830Mon Jul 02 09:41:02 BST 2007com.sun.enterprise.deployment.node

J2EEDocumentBuilder

public class J2EEDocumentBuilder extends Object
This class is responsible for producing DOM document instances from the descriptor classes
author
Jerome Dochez
version

Fields Summary
Constructors Summary
public J2EEDocumentBuilder()
Creates new J2EEDocumentBuilder

    
Methods Summary
public static java.lang.StringdescriptorToString(com.sun.enterprise.deployment.Descriptor descriptor, com.sun.enterprise.deployment.io.DeploymentDescriptorFile ddFile)

        java.io.StringWriter sw = new java.io.StringWriter();
        StreamResult sr = new StreamResult(sw);
	if (descriptor != null) {
	    write(descriptor, ddFile.getRootXMLNode(descriptor), sr);
	}
        return sw.toString();        
    
public static org.w3c.dom.DocumentgetDocument(com.sun.enterprise.deployment.Descriptor descriptor, XMLNode node)
Return a document containing a result node based on the given result descriptor.

        try {
            Node domNode = node.writeDescriptor(newDocument(), descriptor);
            if (domNode instanceof Document) 
                return (Document) domNode;
            else 
                return domNode.getOwnerDocument();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    
public static org.w3c.dom.DocumentnewDocument()
Creates and Return a new DOM document based on the current configuration

return
the new DOM Document object

        try {
            // always use system default
            System.setProperty("javax.xml.parsers.DocumentBuilderFactory", "com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderFactoryImpl");
            DocumentBuilderFactory factory = 
                DocumentBuilderFactory.newInstance();
            System.clearProperty("javax.xml.parsers.DocumentBuilderFactory");

            DocumentBuilder builder = factory.newDocumentBuilder();
            
            DOMImplementation domImplementation = 
                builder.getDOMImplementation();
            
            Document document = builder.newDocument();
            return document;
        } catch (Exception e) {
            DOLUtils.getDefaultLogger().log(Level.SEVERE, "enterprise.deployment.backend.saxParserError",
                    new Object[] {"JAXP configuration error"});
            e.printStackTrace();
        } 
        return null;
    
private static voidsetTransformerProperties(RootXMLNode node, javax.xml.transform.Transformer transformer)

        if (node.getDocType()!=null) {
            transformer.setOutputProperty(
                OutputKeys.DOCTYPE_PUBLIC, node.getDocType());
            if (node.getSystemID()!=null) {
                transformer.setOutputProperty(
                    OutputKeys.DOCTYPE_SYSTEM, node.getSystemID());
            }
        }            
        transformer.setOutputProperty(OutputKeys.METHOD, "xml");        
        transformer.setOutputProperty(OutputKeys.INDENT, "yes");
        transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "2");
        transformer.setOutputProperty(OutputKeys.ENCODING, "UTF-8");
    
public static voidwrite(com.sun.enterprise.deployment.Descriptor descriptor, RootXMLNode node, java.io.File resultFile)

        if (node==null) {
            DOLUtils.getDefaultLogger().log(Level.SEVERE, "enterprise.deployment.backend.invalidDescriptorMappingFailure",
                new Object[] {descriptor, null});
            return;
        }
        if (resultFile.getParent() != null)
            (new File(resultFile.getParent())).mkdirs();
        FileOutputStream out = new FileOutputStream(resultFile);
        write(descriptor, node, out);
        out.close();
    
public static voidwrite(com.sun.enterprise.deployment.Descriptor descriptor, RootXMLNode node, java.io.OutputStream os)

        Result output = new StreamResult(os);
        write(descriptor, node, output);
    
public static voidwrite(com.sun.enterprise.deployment.Descriptor descriptor, RootXMLNode node, javax.xml.transform.Result output)

        if (node==null) {
            DOLUtils.getDefaultLogger().log(Level.SEVERE, "enterprise.deployment.backend.invalidDescriptorMappingFailure",
                new Object[] {descriptor, null});
            return;
        }
        try {
            Document document = getDocument(descriptor, node);
            Source source = new DOMSource(document);
            System.setProperty("javax.xml.transform.TransformerFactory", "com.sun.org.apache.xalan.internal.xsltc.trax.TransformerFactoryImpl");
            TransformerFactory factory =  TransformerFactory.newInstance();
            System.clearProperty("javax.xml.transform.TransformerFactory");
            Transformer transformer = factory.newTransformer();
            setTransformerProperties(node, transformer);
            transformer.transform(source, output);
        } catch(Exception e) {
            e.printStackTrace();
            throw e;
        }