FileDocCategorySizeDatePackage
BaseElement.javaAPI DocGlassfish v2 API9768Wed Jul 11 10:00:58 BST 2007com.sun.enterprise.tools.upgrade.transform.elements

BaseElement

public class BaseElement extends Object
author
prakash

Fields Summary
protected com.sun.enterprise.util.i18n.StringManager
stringManager
protected Logger
logger
protected static com.sun.enterprise.tools.upgrade.common.CommonInfoModel
commonInfoModel
Constructors Summary
public BaseElement()
Creates a new instance of Element

    
           
      
    
Methods Summary
public voidappendElementToParent(org.w3c.dom.Element parentEle, org.w3c.dom.Element element)

        java.util.List eleStructureList = this.getInsertElementStructure(element,parentEle);
        if(eleStructureList == null){
            // insert the element at the end
            parentEle.appendChild(element);
            return;
        }
        if(eleStructureList.isEmpty()){
            // insert the element in the beginning.
            parentEle.insertBefore(element, parentEle.getFirstChild());
            return;
        }
        String insertBeforeElementName = null;
        Node insertBeforeNode = null;            
        for(int eleIndex =0; eleIndex < eleStructureList.size(); eleIndex++){
            insertBeforeElementName = (String)eleStructureList.get(eleIndex);
            Node lNode=parentEle.getFirstChild();
            while (lNode != null) {
                if (lNode instanceof Element) {
                    Element lElement=(Element)lNode;
                    if (lElement.getNodeName().equals(insertBeforeElementName)) {
                        // if match is found, break and insert
                        insertBeforeNode = lNode;
                        break;
                    }
                }                
                // go to next sibling in order
                lNode=lNode.getNextSibling();
            } 
            if(insertBeforeNode != null){
                break;
            }            
        }
        // if match is not found, node will be place at the end
        parentEle.insertBefore(element,insertBeforeNode);
    
private booleancanTransferAttribute(java.lang.String attr, java.util.List attrList)

        if(attrList == null || attrList.isEmpty())
            return true;
        for(java.util.Iterator it = attrList.iterator(); it.hasNext(); ){
            if(it.next().equals(attr))
                return false;
        }
        return true;
    
protected java.util.ListgetAttributeListForElement(java.lang.String elementName)

        //String dtdFileName = this.commonInfoModel.getTargetInstallDir()+File.separator+"lib"+File.separator+"dtds"+File.separator+"sun-domain_1_1.dtd";
        // Domain dtd changed for AS9.0
        String dtdName = null;
        if(UpgradeConstants.VERSION_91.equals(commonInfoModel.getTargetVersion())) { 
            dtdName = "sun-domain_1_3.dtd";
        } else {
            dtdName = "sun-domain_1_2.dtd";
        }	    
        String dtdFileName = this.commonInfoModel.getTargetInstallDir()+File.separator+"lib"+File.separator+"dtds"+File.separator+dtdName;
        return AttributeExtracter.getExtracter(dtdFileName).getAttributeList(elementName);        
    
protected java.util.ListgetInsertElementStructure(org.w3c.dom.Element element, org.w3c.dom.Element parentEle)

        // Sub classes can override this method to return a different list if needed.
        // parentEle is not used in this method.  But sub classes can use it to make certain decision on structure
        return ElementToObjectMapper.getMapper().getInsertElementStructure(element.getTagName());
    
protected java.lang.StringgetKeyToCompare(java.lang.String elementTagName)

        return ElementToObjectMapper.getMapper().getKeyForElement(elementTagName);
    
protected booleanisValidAttributeToTransfer(java.lang.String attrName, java.util.List attrList)

        for(java.util.Iterator it = attrList.iterator(); it.hasNext();){
            if(((String)it.next()).equals(attrName)){
                return true;
            }
        }
        return false;
    
public static voidsetCommonInfoModel(com.sun.enterprise.tools.upgrade.common.CommonInfoModel cim)

        commonInfoModel = cim;
    
protected voidtransferAttributes(org.w3c.dom.Element source, org.w3c.dom.Element result, java.util.List nonTransferList)

        boolean debug = false;
        NamedNodeMap sourceAttrNodeMap = source.getAttributes();
         if(sourceAttrNodeMap == null) return;
        
        NamedNodeMap resultAttrNodeMap = result.getAttributes();
         
         
         for(int index=0; index < sourceAttrNodeMap.getLength(); index++){
             Node sourceAttrNode = sourceAttrNodeMap.item(index);
             if(!this.canTransferAttribute(sourceAttrNode.getNodeName(), nonTransferList)) continue;
             if(!isValidAttributeToTransfer(sourceAttrNode.getNodeName(),getAttributeListForElement(result.getTagName()))) continue;
             if(resultAttrNodeMap == null){
                 Attr addAttr = result.getOwnerDocument().createAttribute(sourceAttrNode.getNodeName());
                 addAttr.setValue(sourceAttrNode.getNodeValue());
                 result.setAttributeNode(addAttr);
             }else{
                 Node resultAttrNode = resultAttrNodeMap.getNamedItem(sourceAttrNode.getNodeName());
                 if(resultAttrNode != null){
                     resultAttrNode.setNodeValue(sourceAttrNode.getNodeValue());
                     //result.setAttributeNode((Attr)resultAttrNode);
                 }else {
                     Attr addAttr = result.getOwnerDocument().createAttribute(sourceAttrNode.getNodeName());
                     addAttr.setValue(sourceAttrNode.getNodeValue());
                     result.setAttributeNode(addAttr);
                 }
             }
         }
    
public voidtransform(org.w3c.dom.Element element, org.w3c.dom.Element parentSource, org.w3c.dom.Element parentResult)

        NodeList childNodes = element.getChildNodes();
		logger.log(Level.FINE, stringManager.getString("upgrade.transform.baseelemnt.transformingMSG",element.getTagName()));
        for(int index=0; index < childNodes.getLength(); index++){
            Node aNode = childNodes.item(index);
            try{
                if(aNode.getNodeType() == Node.ELEMENT_NODE){
                    BaseElement baseElement = ElementToObjectMapper.getMapper().getElementObject(aNode.getNodeName());
                    baseElement.transform((Element)aNode, element, parentResult);
                }
            }catch(Exception ex){
                // ****** LOG MESSAGE *************
                ex.printStackTrace();
                logger.log(Level.WARNING, stringManager.getString("upgrade.transform.baseelement.transformexception",new String[]{element.getTagName(),ex.getMessage()}));
                //-logger.log(Level.WARNING, stringManager.getString("upgrade.transform.baseelement.transformexception"), ex);
            }
        }