KickJava   Java API By Example, From Geeks To Geeks.

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


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  * Server.java
26  *
27  * Created on August 4, 2003, 3:27 PM
28  */

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

36 import org.w3c.dom.Element JavaDoc;
37 import org.w3c.dom.NodeList JavaDoc;
38 import org.w3c.dom.Node JavaDoc;
39 import org.w3c.dom.Attr JavaDoc;
40 import java.util.logging.Level JavaDoc;
41
42 public class Server extends BaseElement {
43     
44     /** Creates a new instance of Server */
45     public Server() {
46     }
47     
48     /**
49      * element - server
50      * parentSource - server
51      * parentResult - domain for as7x. server for as80
52      */

53     public void transform(Element JavaDoc element, Element JavaDoc parentSource, Element JavaDoc parentResult) {
54         // Attributes of server element: name, locale, log-root, application-root, session-store
55
// application-root and log-root will not be transferred, as they are different for 8.0 appserver.
56
// May be application-root need to be saved to migrate applications from the source directory.
57
// session-store attribute should be stored in ejb-container element
58
// Fetch data from server.xml and update it to domain.xml
59
//
60
if(commonInfoModel.getSourceVersion().equals(com.sun.enterprise.tools.upgrade.common.UpgradeConstants.VERSION_7X)){
61             if(commonInfoModel.getSourceEdition().equals(com.sun.enterprise.tools.upgrade.common.UpgradeConstants.EDITION_PE)){
62                 // PE
63
String JavaDoc locale = element.getAttribute("locale");
64                 Element JavaDoc resDocEle = parentResult;
65                 resDocEle.setAttribute("locale", locale);
66                 if(commonInfoModel.getTargetEdition().equals(com.sun.enterprise.tools.upgrade.common.UpgradeConstants.EDITION_PE)){
67                     super.transform(element, parentSource, parentResult);
68                 }else{
69                     // Obtain the config named as server_config and pass that as the parent config
70
NodeList JavaDoc configEles = parentResult.getElementsByTagName("config");
71                     Element JavaDoc configEle = null;
72                     String JavaDoc configToUpgrade = element.getAttribute("name")+"-config";
73                     for(int lh =0; lh < configEles.getLength(); lh++){
74                         String JavaDoc configName = ((Element JavaDoc)configEles.item(lh)).getAttribute("name");
75                         if(configName.equals(configToUpgrade)){
76                             configEle = (Element JavaDoc)configEles.item(lh);
77                             parentResult = configEle;
78                             break;
79                          }
80                     }
81                     if(configEle == null){
82                         // This is cannot be possible. If so... must be domain.xml is corrupt. Log error and fail transofmration.
83
// FIXME
84
}
85                     super.transform(element, parentSource, configEle);
86                 }
87             }else{
88                 // SE or EE
89
// Assumptions.... server1 of SE/EE would be treated as default 'server' in 80 se/ee
90
// NEED TO DISCUSS THIS. Should WE CREATE A new CONFIG for EACH SERVER or, Should we use DAS
91
/*if(element.getAttribute("name").equals("server1")){
92                     String locale = element.getAttribute("locale");
93                     Element resDocEle = parentResult;
94                     resDocEle.setAttribute("locale", locale);
95                     
96                     // Obtain the config named as server_config and pass that as the parent config
97                     NodeList configEles = parentResult.getElementsByTagName("config");
98                     Element configEle = null;
99                     for(int lh =0; lh < configEles.getLength(); lh++){
100                         String configName = ((Element)configEles.item(lh)).getAttribute("name");
101                         if(configName.equals("server-config")){
102                             configEle = (Element)configEles.item(lh);
103                             parentResult = configEle;
104                             break;
105                          }
106                     }
107                     if(configEle == null){
108                         // This is cannot be possible. If so... must be domain.xml is corrupt. Log error and fail transofmration.
109                         // FIXME
110                     }
111                     super.transform(element, parentSource, configEle);
112                     
113                 }else{*/

114                     String JavaDoc configToUpgrade = null;
115                     if(commonInfoModel.getCurrentCluster() == null){
116                         // This must be a SE instance or stand alone instance of EE
117
configToUpgrade = element.getAttribute("name")+"-config";
118                     }else{
119                         configToUpgrade = commonInfoModel.getCurrentCluster()+"-config";
120                     }
121                     // Harness would have created a new serverName_config for a new server element.
122
NodeList JavaDoc configs = parentResult.getElementsByTagName("configs");
123                     // There is a promise of one and only one configs element in 8.x
124
Element JavaDoc configsEle = (Element JavaDoc)configs.item(0);
125                     
126                     // Obtain the config named as serverName_config and pass that as the parent config
127
NodeList JavaDoc configEles = configsEle.getElementsByTagName("config");
128                     Element JavaDoc configEle = null;
129                     for(int lh =0; lh < configEles.getLength(); lh++){
130                         String JavaDoc configName = ((Element JavaDoc)configEles.item(lh)).getAttribute("name");
131                         if(configName.equals(configToUpgrade)){
132                             configEle = (Element JavaDoc)configEles.item(lh);
133                             parentResult = configEle;
134                             break;
135                          }
136                     }
137                     if(configEle == null){
138                         // This is cannot be possible. If so... domain processor must have not finished successfully Log error and fail transofmration.
139
// FIXME
140
Exception JavaDoc ex = new Exception JavaDoc("Could not find Config Element - "+configToUpgrade+" in target domain ");
141                         logger.log(Level.SEVERE, stringManager.getString("upgrade.transform.startFailureMessage",ex.getMessage()),ex);
142                         return;
143                     }
144                     //Element configElement = parentResult.getOwnerDocument().createElement("config");
145

146                     // Set the name attribute to this 'server element name'_config.
147
//configElement.setAttribute("name", element.getAttribute("name")+"_config");
148
//configsEle.appendChild(configElement);
149
// Now pass this newly found config element as the parent result. That takes care of automatic trnasofrmation of elements under server
150
super.transform(element, parentSource, configEle);
151                 //}
152
}
153         }else{
154             // AS 80
155
NodeList JavaDoc servers = parentResult.getElementsByTagName("server");
156             Element JavaDoc server = null;
157             for(int lh =0; lh < servers.getLength(); lh++){
158                 String JavaDoc resultElementID = ((Element JavaDoc)servers.item(lh)).getAttribute("name");
159                 if((element.getAttribute("name")).equals(resultElementID)){
160                     server = (Element JavaDoc)servers.item(lh);
161                     this.transferAttributes(element, server,null);
162                     if(commonInfoModel.getSourceVersion().equals(com.sun.enterprise.tools.upgrade.common.UpgradeConstants.VERSION_80)){
163                         if(element.hasAttribute("node-controller-ref")){
164                             server.setAttribute("node-agent-ref", element.getAttribute("node-controller-ref"));
165                         }
166                     }
167                     break;
168                  }
169             }
170             if(server == null){
171                 server = parentResult.getOwnerDocument().createElement("server");
172                 this.transferAttributes(element, server,null);
173                 this.appendElementToParent(parentResult,server);
174             }
175             super.transform(element, parentSource, server);
176             return;
177         }
178         //super.transform(element, parentSource, parentResult);
179
}
180     
181 }
182
Popular Tags