1 23 24 29 30 package com.sun.enterprise.tools.upgrade.transform.elements; 31 32 36 import org.w3c.dom.Document ; 37 import org.w3c.dom.Element ; 38 import org.w3c.dom.NodeList ; 39 import org.w3c.dom.Node ; 40 import com.sun.enterprise.tools.upgrade.transform.ElementToObjectMapper; 41 import com.sun.enterprise.tools.upgrade.common.DomainsProcessor; 42 import com.sun.enterprise.tools.upgrade.common.UpgradeUtils; 43 44 public class HttpListener extends BaseElement { 45 46 private static java.util.logging.Logger log = com.sun.enterprise.tools.upgrade.common.CommonInfoModel.getDefaultLogger(); 47 private final String HTTP_LISTENER_PORT_PROPERTY_NAME="HTTP_LISTENER_PORT"; 48 49 50 public HttpListener() { 51 } 52 57 public void transform(Element element, Element parentSource, Element parentResult){ 58 61 NodeList resultHttpListeners = parentResult.getElementsByTagName("http-listener"); 65 Element resultHttpListener = null; 66 java.util.Vector notToTransferAttrList = new java.util.Vector (); 67 for(int lh =0; lh < resultHttpListeners.getLength(); lh++){ 68 String resultElementID = ((Element )resultHttpListeners.item(lh)).getAttribute("id"); 70 if((element.getAttribute("id")).equals(resultElementID)){ 71 resultHttpListener = (Element )resultHttpListeners.item(lh); 72 String propertyName = this.getHttpListenerPortProperty(resultElementID,resultHttpListener); 74 if(this.commonInfoModel.getCurrentCluster() != null){ 75 notToTransferAttrList.add("port"); 76 if(propertyName != null){ 77 String propertyValue = null; 79 if(!resultElementID.equals("http-listener-1")){ 80 propertyValue = element.getAttribute("port"); 81 } 82 UpgradeUtils.getUpgradeUtils(this.commonInfoModel).updateListenerPortsForClusteredInstances(parentResult.getOwnerDocument().getDocumentElement(), 83 propertyName, propertyValue, this); 84 } 85 }else{ 86 if(!this.commonInfoModel.getTargetEdition().equals(com.sun.enterprise.tools.upgrade.common.UpgradeConstants.EDITION_PE)){ 88 String instanceName = commonInfoModel.getCurrentSourceInstance(); 89 if((instanceName != null) &&(!("".equals(instanceName.trim())))){ 90 notToTransferAttrList.add("port"); 91 String propertyValue = element.getAttribute("port"); 92 NodeList servers = parentResult.getOwnerDocument().getDocumentElement().getElementsByTagName("servers"); 93 NodeList serverList = ((Element )servers.item(0)).getElementsByTagName("server"); 94 UpgradeUtils.getUpgradeUtils(this.commonInfoModel).addOrUpdateSystemPropertyToServer(instanceName, serverList, propertyName, propertyValue, this); 95 } 96 } 97 } 98 this.transferAttributes(element, resultHttpListener,notToTransferAttrList); 99 } 100 if(resultElementID.equals("admin-listener")){ 101 String adminPort = DomainsProcessor.getSourceAdminPort(); 102 String adminSecurity = DomainsProcessor.getSourceAdminSecurity(); 103 ((Element )resultHttpListeners.item(lh)).setAttribute("port", adminPort); 104 ((Element )resultHttpListeners.item(lh)).setAttribute("security-enabled", adminSecurity); 105 } 106 } 107 if(resultHttpListener == null){ 108 resultHttpListener = parentResult.getOwnerDocument().createElement("http-listener"); 110 if(this.commonInfoModel.getCurrentCluster() != null){ 112 notToTransferAttrList.add("port"); 113 String propertyName = element.getAttribute("id")+"_HTTP_LISTENER_PORT"; 114 UpgradeUtils.getUpgradeUtils(this.commonInfoModel).updateListenerPortsForClusteredInstances(parentResult.getOwnerDocument().getDocumentElement(), 115 propertyName, element.getAttribute("port"), this); 116 resultHttpListener.setAttribute("port", "${"+propertyName+"}"); 117 } 118 this.transferAttributes(element, resultHttpListener,notToTransferAttrList); 119 this.appendElementToParent(parentResult,resultHttpListener); 120 } 121 super.transform(element, parentSource, resultHttpListener); 122 } 123 public void transferAttributes(Element sourceEle, Element targetEle, java.util.List notToTransferAttrList){ 124 notToTransferAttrList.add("acceptor-threads"); 127 128 super.transferAttributes(sourceEle, targetEle, notToTransferAttrList); 129 if(this.commonInfoModel.getSourceVersion().equals(com.sun.enterprise.tools.upgrade.common.UpgradeConstants.VERSION_7X)){ 130 String serverID = sourceEle.getOwnerDocument().getDocumentElement().getAttribute("name"); 131 if(targetEle.getAttribute("default-virtual-server").equals(serverID)){ 132 targetEle.setAttribute("default-virtual-server","server"); 133 } 134 } 135 136 } 145 private void printAttrs(Element ele){ 146 org.w3c.dom.NamedNodeMap sourceAttrNodeMap = ele.getAttributes(); 147 for(int index=0; index < sourceAttrNodeMap.getLength(); index++){ 148 Node sourceAttrNode = sourceAttrNodeMap.item(index); 149 log.info("******\n attr name="+sourceAttrNode.getNodeName()+" attrValue="+sourceAttrNode.getNodeValue()); 150 } 151 } 152 private String getHttpListenerPortProperty(String id, Element resultHttpListener){ 153 if(id.equals("http-listener-1")){ 154 return this.HTTP_LISTENER_PORT_PROPERTY_NAME; 155 } 156 String portValue = resultHttpListener.getAttribute("port"); 157 if((portValue != null) && portValue.trim().startsWith("${")){ 158 return portValue.substring(2,portValue.length()-1); 159 } 160 return null; 161 } 162 163 } 164 | Popular Tags |