FileDocCategorySizeDatePackage
Description.javaAPI DocGlassfish v2 API4872Fri May 04 22:35:10 BST 2007com.sun.enterprise.tools.upgrade.transform.elements

Description

public class Description extends BaseElement
author
prakash

Fields Summary
Constructors Summary
public Description()
Creates a new instance of Element

    
Methods Summary
private org.w3c.dom.NodegetTextNode(org.w3c.dom.Element element)

        NodeList children = element.getChildNodes();
        for(int index=0; index < children.getLength(); index++){
            if(children.item(index).getNodeType() == Node.TEXT_NODE){
                return children.item(index);
            }
        }
        return null;
    
private java.lang.StringgetTextNodeData(org.w3c.dom.Element element)

        NodeList children = element.getChildNodes();
        for(int index=0; index < children.getLength(); index++){
            if(children.item(index).getNodeType() == Node.TEXT_NODE){
                return children.item(index).getNodeValue();
            }
        }
        return "";
    
private voidsetTextNodeData(org.w3c.dom.Element element, java.lang.String textNodeData)

        NodeList children = element.getChildNodes();
        for(int index=0; index < children.getLength(); index++){
            if(children.item(index).getNodeType() == Node.TEXT_NODE){
                children.item(index).setNodeValue(textNodeData);
                return;
            }
        }        
    
public voidtransform(org.w3c.dom.Element element, org.w3c.dom.Element parentSource, org.w3c.dom.Element parentResult)
element - description parentSource - parent of description parentResult - result element to which description to be updated

        // description is updated if exists, else added if not exists.
        NodeList resultDescs = parentResult.getElementsByTagName("description");
        Element resultDesc = null;
        if(resultDescs.getLength() == 0){
            resultDesc = parentResult.getOwnerDocument().createElement("description");
            Node textNode = parentResult.getOwnerDocument().createTextNode(this.getTextNodeData(element));
            resultDesc.appendChild(textNode);
            parentResult.appendChild(resultDesc);
        }else {
            resultDesc = (Element)resultDescs.item(0);
            if((this.getTextNodeData(element)).equals(this.getTextNodeData((Element)resultDesc))){
                // If both are same there is nothing to be done, just break.
            }else if(this.getTextNode(resultDesc) == null){
                Node textNode = parentResult.getOwnerDocument().createTextNode(this.getTextNodeData(element));
                resultDesc.appendChild(textNode);
            }else{
                this.setTextNodeData(resultDesc, this.getTextNodeData(element));
            }
        }