KickJava   Java API By Example, From Geeks To Geeks.

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


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

29
30 package com.sun.enterprise.tools.upgrade.transform.elements;
31 import com.sun.enterprise.tools.upgrade.common.UpgradeConstants;
32 import org.w3c.dom.Element JavaDoc;
33 import org.w3c.dom.NodeList JavaDoc;
34 import org.w3c.dom.Node JavaDoc;
35
36
37 public class JVMOptions extends BaseElement {
38     
39     /** Creates a new instance of Element */
40     public JVMOptions() {
41     }
42     /**
43      * element - jvm-options
44      * parentSource - parent of jvm-options
45      * parentResult - parent of jbm-options result
46      */

47     public void transform(Element JavaDoc element, Element JavaDoc parentSource, Element JavaDoc parentResult){
48         // There are no children for jvm-options, neither attributes.
49
// jvm-options has only #CDATA. Just need to transfer it, if not exists.
50
NodeList JavaDoc jvmOptions = parentResult.getElementsByTagName("jvm-options");
51         Element JavaDoc jvmOption = null;
52         String JavaDoc srcTxtDt = this.getTextNodeData(element);
53         String JavaDoc[] sourceTextData = this.parseTextData(srcTxtDt);
54         if(sourceTextData == null){
55             // jvm-options must be of type -X...
56
// will not transfer anything...
57
//start CR 6398609
58
logger.log(java.util.logging.Level.WARNING, stringManager.getString("upgrade.transform.jvmoptions.notTransferred", srcTxtDt));
59         //end CR 6398609
60
return;
61         }
62         //Added for CR 6363638
63
if(srcTxtDt.trim().equals("-Djdbc.drivers=com.pointbase.jdbc.jdbcUniversalDriver")) {
64             //JDBC Drivers should not be transformed as the universal driver is derby for 9.0
65
return;
66         }
67         if(!this.canTransfer(sourceTextData[0], sourceTextData[1])){
68         //start CR 6398609
69
logger.log(java.util.logging.Level.WARNING, stringManager.getString("upgrade.transform.jvmoptions.notTransferred", sourceTextData[0]));
70         //end CR 6398609
71
return;
72         }
73         for(int lh =0; lh < jvmOptions.getLength(); lh++){
74             // Compare text data
75
String JavaDoc tgTxtDt = this.getTextNodeData((Element JavaDoc)jvmOptions.item(lh));
76             if(srcTxtDt.equals(tgTxtDt)){
77                 jvmOption = (Element JavaDoc)jvmOptions.item(lh);
78                 // If both are same there is nothing to be done, just break.
79
break;
80             }
81             String JavaDoc[] targetTextData = this.parseTextData(tgTxtDt);
82             if(sourceTextData != null && targetTextData != null){
83                 if(sourceTextData[0].equals(targetTextData[0])){
84                     // If they both are same then Should I transfer any thing? Dont think so
85
// If this option is already defined in AS 81 then probably a specific one for 81 would have been defined.
86
jvmOption = (Element JavaDoc)jvmOptions.item(lh);
87                     break;
88                 }
89             }
90         }
91         if(jvmOption == null){
92             // If there isnt element -jvm-option in the result, add one. ....?
93
//System.out.println("JVMOptions::transform ok... jvmOption in target could not be found =");
94
if(this.canTransfer(sourceTextData[0], sourceTextData[1])){
95                 //System.out.println("JVMOptions::transform ok... Wow can transfer ....hurray.....");
96
// If the value of jvm-option contains source install directory path, then dont want to transfer it.
97
if(sourceTextData[1].indexOf(this.commonInfoModel.getSourceInstallDir()) == -1){
98                     //System.out.println("JVMOptions::transform ok... source data does not contain fine go");
99
jvmOption = parentResult.getOwnerDocument().createElement("jvm-options");
100                     Node JavaDoc textNode = jvmOption.getOwnerDocument().createTextNode(srcTxtDt);
101                     jvmOption.appendChild(textNode);
102                     parentResult.appendChild(jvmOption);
103                 }
104             } //start CR 6398609
105
else {
106             logger.log(java.util.logging.Level.WARNING, stringManager.getString("upgrade.transform.jvmoptions.notTransferred", sourceTextData[0]));
107         }
108         //end CR 6398609
109

110         }
111     }
112     private String JavaDoc[] parseTextData(String JavaDoc fullStr){
113         String JavaDoc[] parsedStrings = null;
114         java.util.StringTokenizer JavaDoc stk = new java.util.StringTokenizer JavaDoc(fullStr,"=");
115         if((stk.hasMoreTokens()) && (stk.countTokens() == 2)){
116             // There should be only two tokens typically.
117
parsedStrings = new String JavaDoc[2];
118             parsedStrings[0] = stk.nextToken();
119             parsedStrings[1] = stk.nextToken();
120         }
121         return parsedStrings;
122     }
123     private String JavaDoc getTextNodeData(Element JavaDoc element){
124         NodeList JavaDoc children = element.getChildNodes();
125         for(int index=0; index < children.getLength(); index++){
126             if(children.item(index).getNodeType() == Node.TEXT_NODE){
127                 return children.item(index).getNodeValue();
128             }
129         }
130         return "";
131     }
132     private boolean canTransfer(String JavaDoc optionName, String JavaDoc optionValue){
133         // This method should have a list of items that is not good to transfer to 81... Need to determine the list.
134
if((optionName.indexOf("Dorg.xml.sax.parser") != -1) ||
135                 (optionName.indexOf("Dorg.xml.sax.driver") != -1) ||
136                 (optionName.indexOf("Dcom.sun.jdo.api.persistence.model.multipleClassLoaders") != -1) ||
137                 (optionName.indexOf("Djava.util.logging.manager") != -1) ||
138                 (optionName.indexOf("Dcom.sun.aas.imqLib") != -1) ||
139                 (optionName.indexOf("Dcom.sun.aas.imqBin") != -1) ||
140                 (optionName.indexOf("Dcom.sun.aas.webServicesLib") != -1) ||
141                 (optionName.indexOf("Dcom.sun.aas.configRoot") != -1)){
142             return false;
143         }
144         //System.out.println("JVMOptions::canTransfer installa dir before transformation ="+this.commonInfoModel.getSourceInstallDir());
145
String JavaDoc repOpValue = this.commonInfoModel.getSourceInstallDir().replace('\\','/');
146         //System.out.println("JVMOptions::canTransfer installa dir after transformation ="+repOpValue);
147
//System.out.println("JVMOptions::canTransfer option value ="+optionValue);
148
if((optionValue.indexOf(repOpValue) != -1) || (optionValue.indexOf(this.commonInfoModel.getSourceInstallDir()) != -1)){
149             //System.out.println("JVMOptions::canTransfer yes index is not -1 so cannot transfer");
150
return false;
151         }
152         // Don't transfer javax.net.ssl.keyStore or javax.net.ssl.trustStore from PE
153
if(commonInfoModel.getTargetEdition().equals(UpgradeConstants.EDITION_EE) && optionName.indexOf("javax.net.ssl") != -1) {
154             return false;
155         }
156         return true;
157     }
158     
159 }
160
Popular Tags