KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > tools > upgrade > transform > elements > VirtualServer


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the License). You may not use this file except in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * Header Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

23
24 /*
25  * VirtualServer.java
26  *
27  * Created on August 4, 2003, 2:04 PM
28  */

29
30 package com.sun.enterprise.tools.upgrade.transform.elements;
31
32 /**
33  *
34  * @author prakash
35  */

36 import org.w3c.dom.Document JavaDoc;
37 import org.w3c.dom.Element JavaDoc;
38 import org.w3c.dom.NodeList JavaDoc;
39 import org.w3c.dom.Node JavaDoc;
40 import com.sun.enterprise.tools.upgrade.transform.ElementToObjectMapper;
41
42 public class VirtualServer extends BaseElement {
43     
44     private static java.util.logging.Logger JavaDoc log = com.sun.enterprise.tools.upgrade.common.CommonInfoModel.getDefaultLogger();
45
46     /** Creates a new instance of Element */
47     public VirtualServer() {
48     }
49     /**
50      * element - virtual server
51      * parentSource - parent virtual-server-class of element for as7, virtual-server for as8
52      * parentResult - parent http-service of result
53      */

54     public void transform(Element JavaDoc element, Element JavaDoc parentSource, Element JavaDoc parentResult){
55         // In domain.xml http-service is /domain/configs/config/http-service/viertual-server-class/virtual-server
56
// in server.xml http-service is /server/http-service/virtual-server-class/virtual-server
57

58         // Obtain a list of virtual-server from the result. IF the passed in element is not the one in the list then add it.
59
// If its the one existing then update it.
60
// There should be either one or zero http-service and zero or more vertual-server-class
61

62         NodeList JavaDoc resultVirtualServers = parentResult.getElementsByTagName("virtual-server");
63         Element JavaDoc resultVirtualServer = null;
64         String JavaDoc serverID = "server1";
65         if(this.commonInfoModel.getSourceVersion().equals(com.sun.enterprise.tools.upgrade.common.UpgradeConstants.VERSION_7X)){
66             serverID = element.getOwnerDocument().getDocumentElement().getAttribute("name");
67         }
68         for(int lh =0; lh < resultVirtualServers.getLength(); lh++){
69             if(element.getAttribute("id").equals(serverID) &&
70             ((Element JavaDoc)resultVirtualServers.item(lh)).getAttribute("id").equals("server")){
71                 resultVirtualServer = (Element JavaDoc)resultVirtualServers.item(lh);
72                 java.util.Vector JavaDoc notToTransferAttrList = new java.util.Vector JavaDoc();
73                 // http-listeners, its possible that the 7.0 config would have added more http-listeners....
74
// FIX, http-listeners to compare and add http-listeners to the list.
75

76                 // If the source server name is different from server1 then the id should represent the server name.
77
//if(serverID.equals("server1"))
78
notToTransferAttrList.add("id");
79                 notToTransferAttrList.add("http-listeners");
80                 notToTransferAttrList.add("config-file");
81                 this.transferAttributes(element, resultVirtualServer, notToTransferAttrList);
82                 break;
83             }else if((element.getAttribute("id")).equals(((Element JavaDoc)resultVirtualServers.item(lh)).getAttribute("id"))){
84                 resultVirtualServer = (Element JavaDoc)resultVirtualServers.item(lh);
85                 java.util.Vector JavaDoc notToTransferAttrList = new java.util.Vector JavaDoc();
86                 // http-listeners, its possible that the 7.0 config would have added more http-listeners....
87
// FIX, http-listeners to compare and add http-listeners to the list.
88
if(commonInfoModel.getSourceVersion().equals(com.sun.enterprise.tools.upgrade.common.UpgradeConstants.VERSION_7X)){
89                     notToTransferAttrList.add("http-listeners");
90                     notToTransferAttrList.add("config-file");
91                 }
92                 this.transferAttributes(element, resultVirtualServer, notToTransferAttrList);
93                 break;
94              }
95         }
96         if(resultVirtualServer == null){
97             // Add element - virtual server to result virtual-server-class.
98
resultVirtualServer = parentResult.getOwnerDocument().createElement("virtual-server");
99             this.transferAttributes(element, resultVirtualServer, null);
100             this.appendElementToParent(parentResult,resultVirtualServer);
101         }
102         //this.printAttrs(resultVirtualServer);
103
// There are few property elements like docroot, accesslog those pointing to directory/file in the current intallation.
104
/****** NEED TO FIX....Should avoid those properties being invoked by the below method. may be override the super method...*/
105         super.transform(element, parentSource, resultVirtualServer);
106     }
107      private void printAttrs(Element JavaDoc ele){
108          log.info(" ____________ prinint virtual-server attributes");
109         org.w3c.dom.NamedNodeMap JavaDoc sourceAttrNodeMap = ele.getAttributes();
110         for(int index=0; index < sourceAttrNodeMap.getLength(); index++){
111              Node JavaDoc sourceAttrNode = sourceAttrNodeMap.item(index);
112              log.info("******\n attr name="+sourceAttrNode.getNodeName()+" attrValue="+sourceAttrNode.getNodeValue());
113         }
114     }
115     
116 }
117
Popular Tags