KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > tools > upgrade > miscconfig > InitConfTransfer


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  * InitConfTransfer.java
26  *
27  * Created on June 8, 2004, 2:32 PM
28  */

29
30 package com.sun.enterprise.tools.upgrade.miscconfig;
31
32 import java.io.*;
33 import com.sun.enterprise.tools.upgrade.common.*;
34 import com.sun.enterprise.util.i18n.StringManager;
35 import com.sun.enterprise.tools.upgrade.logging.*;
36 import java.util.logging.*;
37 import java.util.*;
38 import java.lang.reflect.*;
39 import javax.xml.parsers.DocumentBuilder JavaDoc;
40 import javax.xml.parsers.DocumentBuilderFactory JavaDoc;
41 import javax.xml.parsers.FactoryConfigurationError JavaDoc;
42 import javax.xml.parsers.ParserConfigurationException JavaDoc;
43 import org.xml.sax.SAXException JavaDoc;
44 import org.xml.sax.SAXParseException JavaDoc;
45 import org.w3c.dom.Document JavaDoc;
46 import org.w3c.dom.DOMException JavaDoc;
47 import org.w3c.dom.Element JavaDoc;
48 import org.w3c.dom.Node JavaDoc;
49 import org.w3c.dom.NodeList JavaDoc;
50 import org.w3c.dom.NamedNodeMap JavaDoc;
51 import javax.xml.transform.Transformer JavaDoc;
52 import javax.xml.transform.TransformerFactory JavaDoc;
53 import javax.xml.transform.TransformerException JavaDoc;
54 import javax.xml.transform.TransformerConfigurationException JavaDoc;
55 import javax.xml.transform.dom.DOMSource JavaDoc;
56 import javax.xml.transform.stream.StreamResult JavaDoc;
57 import javax.xml.transform.OutputKeys JavaDoc;
58
59 /**
60  *
61  * @author hans
62  */

63 public class InitConfTransfer {
64     private CommonInfoModel commonInfo;
65     private StringManager stringManager = StringManager.getManager("com.sun.enterprise.tools.upgrade.miscconfig");
66     private Logger logger = CommonInfoModel.getDefaultLogger();
67     
68     /** Creates a new instance of InitConfTransfer */
69     public InitConfTransfer(CommonInfoModel cim) {
70         commonInfo = cim;
71     }
72     
73     public void transform() {
74         logger.log(Level.INFO, stringManager.getString("upgrade.configTransfers.initconf.startMessage"));
75         
76         String JavaDoc fileName = commonInfo.getSourceInitConfFileName();
77         BufferedReader reader = null;
78         DocumentBuilderFactory JavaDoc factory = DocumentBuilderFactory.newInstance();
79         //factory.setValidating(true);
80
factory.setNamespaceAware(true);
81         try {
82             DocumentBuilder JavaDoc builderDomainXml = factory.newDocumentBuilder();
83             builderDomainXml.setEntityResolver((org.xml.sax.helpers.DefaultHandler JavaDoc)Class.forName
84             ("com.sun.enterprise.config.serverbeans.ServerValidationHandler").newInstance());
85             Document JavaDoc resultDoc = builderDomainXml.parse( new File(commonInfo.getTargetConfigXMLFile()) );
86             reader = new BufferedReader(new FileReader(fileName));
87             while (reader.ready()) {
88                 String JavaDoc line = reader.readLine();
89                 String JavaDoc key = null;
90                 String JavaDoc value = null;
91                 StringTokenizer st = new StringTokenizer(line, " ", false);
92                 if ( st.hasMoreTokens() ) {
93                     key = st.nextToken();
94                 } else {
95                     continue;
96                 }
97                 if ( st.hasMoreTokens() ) {
98                     value = st.nextToken();
99                 } else {
100                     continue;
101                 }
102                 try {
103                     Method m = getClass().getMethod("transform" + key, new Class JavaDoc [] { Document JavaDoc.class, String JavaDoc.class });
104                     m.invoke(this, new Object JavaDoc [] { resultDoc, value } );
105                 } catch (NoSuchMethodException JavaDoc nsm) {
106                     logger.log(Level.WARNING, stringManager.getString("upgrade.configTransfers.initconf.unsupportedElement") + key);
107                 } catch (Exception JavaDoc e) {
108                     logger.log(Level.WARNING, stringManager.getString("upgrade.configTransfers.initconf.exception") + e.getLocalizedMessage());
109                 }
110             }
111             // write out the resultDoc to destination file.
112
// Use a Transformer for output
113
TransformerFactory JavaDoc tFactory = TransformerFactory.newInstance();
114             Transformer JavaDoc transformer = tFactory.newTransformer();
115             if (resultDoc.getDoctype() != null){
116                 String JavaDoc systemValue = resultDoc.getDoctype().getSystemId();
117                 transformer.setOutputProperty(OutputKeys.DOCTYPE_SYSTEM, systemValue);
118                 String JavaDoc pubValue = resultDoc.getDoctype().getPublicId();
119                 transformer.setOutputProperty(OutputKeys.DOCTYPE_PUBLIC, pubValue);
120             }
121             DOMSource JavaDoc source = new DOMSource JavaDoc(resultDoc);
122             StreamResult JavaDoc result = new StreamResult JavaDoc(new FileOutputStream(commonInfo.getTargetConfigXMLFile()));
123             transformer.transform(source, result);
124         } catch (IOException ioe) {
125             logger.log(Level.WARNING, stringManager.getString("upgrade.configTransfers.initconf.iofailure") + ioe.getLocalizedMessage());
126         } catch (Exception JavaDoc e) {
127             logger.log(Level.WARNING, stringManager.getString("upgrade.configTransfers.initconf.exception") + e.getLocalizedMessage());
128         }
129         if (reader != null) {
130             try {
131                 reader.close();
132             } catch (Exception JavaDoc e) {
133                 logger.log(Level.WARNING, stringManager.getString("upgrade.configTransfers.initconf.iofailure") + e.getLocalizedMessage());
134             }
135         }
136     }
137     
138     public void transformServerName(Document JavaDoc domainXML, String JavaDoc value) {
139         
140     }
141     
142     public void transformServerID(Document JavaDoc domainXML, String JavaDoc value) {
143         
144     }
145     
146     public void transformExtraPath(Document JavaDoc domainXML, String JavaDoc value) {
147         
148     }
149     
150     public void transformInit(Document JavaDoc domainXML, String JavaDoc value) {
151         //NSAPI no longer supported
152
}
153     
154     public void transformNetsiteRoot(Document JavaDoc domainXML, String JavaDoc value) {
155         
156     }
157     
158     public void transformDNS(Document JavaDoc domainXML, String JavaDoc value) {
159         logger.finest("DNS = " + value);
160         Element JavaDoc docEle = domainXML.getDocumentElement();
161         NodeList JavaDoc nodeList = docEle.getElementsByTagName("config");
162         for (int i=0; i < nodeList.getLength(); i++) {
163             Element JavaDoc configElement = (Element JavaDoc)nodeList.item(i);
164             String JavaDoc attrValue = configElement.getAttribute("name");
165             if (attrValue.equals(commonInfo.getCurrentSourceInstance() + "-config")) {
166                 NodeList JavaDoc httpServiceNodes = configElement.getElementsByTagName("http-service");
167                 //there is only one http-service element
168
Element JavaDoc httpServiceElement = (Element JavaDoc)httpServiceNodes.item(0);
169                 NodeList JavaDoc httpList = httpServiceElement.getElementsByTagName("http-protocol");
170                 // There should be only one http-protocol element.
171
Element JavaDoc element = (Element JavaDoc)httpList.item(0);
172                 //If the element exists in the target, do the transformation
173
if (element != null) {
174                     if (value.equalsIgnoreCase("off")) {
175                         element.setAttribute("dns-lookup-enabled", "false");
176                     } else {
177                         element.setAttribute("dns-lookup-enabled", "true");
178                     }
179                 }
180             }
181         }
182     }
183     
184     public void transformAsyncDNS(Document JavaDoc domainXML, String JavaDoc value) {
185         //TO DO - don't know what this translates to?
186
}
187     
188     public void transformConnQueueSize(Document JavaDoc domainXML, String JavaDoc value) {
189         //http-service/connection-pool:queue-size-bytes
190
logger.finest("ConnQueueSize = " + value);
191         Element JavaDoc docEle = domainXML.getDocumentElement();
192         NodeList JavaDoc nodeList = docEle.getElementsByTagName("config");
193         for (int i=0; i < nodeList.getLength(); i++) {
194             Element JavaDoc configElement = (Element JavaDoc)nodeList.item(i);
195             String JavaDoc attrValue = configElement.getAttribute("name");
196             if (attrValue.equals(commonInfo.getCurrentSourceInstance() + "-config")) {
197                 NodeList JavaDoc httpServiceNodes = configElement.getElementsByTagName("http-service");
198                 //there is only one http-service element
199
Element JavaDoc httpServiceElement = (Element JavaDoc)httpServiceNodes.item(0);
200                 NodeList JavaDoc subList = httpServiceElement.getElementsByTagName("connection-pool");
201                 // There can be only one connection-pool element.
202
Element JavaDoc element = (Element JavaDoc)subList.item(0);
203                 //If the element exists in the target, do the transformation
204
if (element != null) {
205                     element.setAttribute("queue-size-bytes", value);
206                 }
207             }
208         }
209     }
210     
211     public void transformHeaderBufferSize(Document JavaDoc domainXML, String JavaDoc value) {
212         //http-service/request-processing:header-buffer-size-bytes
213
logger.finest("HeaderBufferSize = " + value);
214         Element JavaDoc docEle = domainXML.getDocumentElement();
215         NodeList JavaDoc nodeList = docEle.getElementsByTagName("config");
216         for (int i=0; i < nodeList.getLength(); i++) {
217             Element JavaDoc configElement = (Element JavaDoc)nodeList.item(i);
218             String JavaDoc attrValue = configElement.getAttribute("name");
219             if (attrValue.equals(commonInfo.getCurrentSourceInstance() + "-config")) {
220                 NodeList JavaDoc httpServiceNodes = configElement.getElementsByTagName("http-service");
221                 //there is only one http-service element
222
Element JavaDoc httpServiceElement = (Element JavaDoc)httpServiceNodes.item(0);
223                 NodeList JavaDoc subList = httpServiceElement.getElementsByTagName("request-processing");
224                 // There can be only one request-processing element.
225
Element JavaDoc element = (Element JavaDoc)subList.item(0);
226                 //If the element exists in the target, do the transformation
227
if (element != null) {
228                     element.setAttribute("header-buffer-size-bytes", value);
229                 }
230             }
231         }
232     }
233     
234     public void transformIOTimeout(Document JavaDoc domainXML, String JavaDoc value) {
235         //http-service/request-processing:request-timeout-in-seconds
236
logger.finest("IOTimeout = " + value);
237         Element JavaDoc docEle = domainXML.getDocumentElement();
238         NodeList JavaDoc nodeList = docEle.getElementsByTagName("config");
239         for (int i=0; i < nodeList.getLength(); i++) {
240             Element JavaDoc configElement = (Element JavaDoc)nodeList.item(i);
241             String JavaDoc attrValue = configElement.getAttribute("name");
242             if (attrValue.equals(commonInfo.getCurrentSourceInstance() + "-config")) {
243                 NodeList JavaDoc httpServiceNodes = configElement.getElementsByTagName("http-service");
244                 //there is only one http-service element.
245
Element JavaDoc httpServiceElement = (Element JavaDoc)httpServiceNodes.item(0);
246                 NodeList JavaDoc subList = httpServiceElement.getElementsByTagName("request-processing");
247                 // There can be only one request-processing element.
248
Element JavaDoc element = (Element JavaDoc)subList.item(0);
249                 //If the element exists in the target, do the transformation
250
if (element != null) {
251                     element.setAttribute("request-timeout-in-seconds", value);
252                 }
253             }
254         }
255     }
256     
257     public void transformKeepAliveThreads(Document JavaDoc domainXML, String JavaDoc value) {
258         //http-service/keep-alive:keep-alive-thread-count
259
logger.finest("KeepAliveThreads = " + value);
260         Element JavaDoc docEle = domainXML.getDocumentElement();
261         NodeList JavaDoc nodeList = docEle.getElementsByTagName("config");
262         for (int i=0; i < nodeList.getLength(); i++) {
263             Element JavaDoc configElement = (Element JavaDoc)nodeList.item(i);
264             String JavaDoc attrValue = configElement.getAttribute("name");
265             if (attrValue.equals(commonInfo.getCurrentSourceInstance() + "-config")) {
266                 NodeList JavaDoc httpServiceNodes = configElement.getElementsByTagName("http-service");
267                 //there is only one http-service element
268
Element JavaDoc httpServiceElement = (Element JavaDoc)httpServiceNodes.item(0);
269                 NodeList JavaDoc subList = httpServiceElement.getElementsByTagName("keep-alive");
270                 // There can be only one request-processing element.
271
Element JavaDoc element = (Element JavaDoc)subList.item(0);
272                 //If the element exists in the target, do the transformation
273
if (element != null) {
274                     element.setAttribute("keep-alive-thread-count", value);
275                 }
276             }
277         }
278     }
279     
280     public void transformKeepAliveTimeout(Document JavaDoc domainXML, String JavaDoc value) {
281         //http-service/keep-alive:timeout-in-seconds
282
logger.finest("KeepAliveTimeout = " + value);
283         Element JavaDoc docEle = domainXML.getDocumentElement();
284         NodeList JavaDoc nodeList = docEle.getElementsByTagName("config");
285         for (int i=0; i < nodeList.getLength(); i++) {
286             Element JavaDoc configElement = (Element JavaDoc)nodeList.item(i);
287             String JavaDoc attrValue = configElement.getAttribute("name");
288             if (attrValue.equals(commonInfo.getCurrentSourceInstance() + "-config")) {
289                 NodeList JavaDoc httpServiceNodes = configElement.getElementsByTagName("http-service");
290                 //there is only one http-service element
291
Element JavaDoc httpServiceElement = (Element JavaDoc)httpServiceNodes.item(0);
292                 NodeList JavaDoc subList = httpServiceElement.getElementsByTagName("keep-alive");
293                 // There can be only one request-processing element.
294
Element JavaDoc element = (Element JavaDoc)subList.item(0);
295                 //If the element exists in the target, do the transformation
296
if (element != null) {
297                     element.setAttribute("timeout-in-seconds", value);
298                 }
299             }
300         }
301     }
302     
303     public void transformKernelThreads(Document JavaDoc domainXML, String JavaDoc value) {
304         //unsupported
305
}
306     
307     public void transformListenQ(Document JavaDoc domainXML, String JavaDoc value) {
308         //http-service/connection-pool:max-pending-count
309
logger.finest("ListenQ = " + value);
310         Element JavaDoc docEle = domainXML.getDocumentElement();
311         NodeList JavaDoc nodeList = docEle.getElementsByTagName("config");
312         for (int i=0; i < nodeList.getLength(); i++) {
313             Element JavaDoc configElement = (Element JavaDoc)nodeList.item(i);
314             String JavaDoc attrValue = configElement.getAttribute("name");
315             if (attrValue.equals(commonInfo.getCurrentSourceInstance() + "-config")) {
316                 NodeList JavaDoc httpServiceNodes = configElement.getElementsByTagName("http-service");
317                 //there is only one http-service element
318
Element JavaDoc httpServiceElement = (Element JavaDoc)httpServiceNodes.item(0);
319                 NodeList JavaDoc subList = httpServiceElement.getElementsByTagName("connection-pool");
320                 // There can be only one connection-pool element.
321
Element JavaDoc element = (Element JavaDoc)subList.item(0);
322                 //If the element exists in the target, do the transformation
323
if (element != null) {
324                     element.setAttribute("max-pending-count", value);
325                 }
326             }
327         }
328     }
329     
330     public void transformRcvBufSize(Document JavaDoc domainXML, String JavaDoc value) {
331         //http-service/connection-pool:receive-buffer-size-bytes
332
logger.finest("RcvBufSize = " + value);
333         Element JavaDoc docEle = domainXML.getDocumentElement();
334         NodeList JavaDoc nodeList = docEle.getElementsByTagName("config");
335         for (int i=0; i < nodeList.getLength(); i++) {
336             Element JavaDoc configElement = (Element JavaDoc)nodeList.item(i);
337             String JavaDoc attrValue = configElement.getAttribute("name");
338             if (attrValue.equals(commonInfo.getCurrentSourceInstance() + "-config")) {
339                 NodeList JavaDoc httpServiceNodes = configElement.getElementsByTagName("http-service");
340                 //there is only one http-service element
341
Element JavaDoc httpServiceElement = (Element JavaDoc)httpServiceNodes.item(0);
342                 NodeList JavaDoc subList = httpServiceElement.getElementsByTagName("connection-pool");
343                 // There can be only one connection-pool element.
344
Element JavaDoc element = (Element JavaDoc)subList.item(0);
345                 //If the element exists in the target, do the transformation
346
if (element != null) {
347                     element.setAttribute("receive-buffer-size-bytes", value);
348                 }
349             }
350         }
351     }
352     
353     public void transformMaxKeepAliveConnections(Document JavaDoc domainXML, String JavaDoc value) {
354         //http-service/keep-alive:timeout-in-seconds
355
logger.finest("MaxKeepAliveConnections = " + value);
356         Element JavaDoc docEle = domainXML.getDocumentElement();
357         NodeList JavaDoc nodeList = docEle.getElementsByTagName("config");
358         for (int i=0; i < nodeList.getLength(); i++) {
359             Element JavaDoc configElement = (Element JavaDoc)nodeList.item(i);
360             String JavaDoc attrValue = configElement.getAttribute("name");
361             if (attrValue.equals(commonInfo.getCurrentSourceInstance() + "-config")) {
362                 NodeList JavaDoc httpServiceNodes = configElement.getElementsByTagName("http-service");
363                 //there is only one http-service element
364
Element JavaDoc httpServiceElement = (Element JavaDoc)httpServiceNodes.item(0);
365                 NodeList JavaDoc subList = httpServiceElement.getElementsByTagName("keep-alive");
366                 // There can be only one request-processing element.
367
Element JavaDoc element = (Element JavaDoc)subList.item(0);
368                 //If the element exists in the target, do the transformation
369
if (element != null) {
370                     element.setAttribute("max-keep-alive-connections", value);
371                 }
372             }
373         }
374     }
375     
376     public void transformRqThrottle(Document JavaDoc domainXML, String JavaDoc value) {
377         //http-service/request-processing:thread-count
378
logger.finest("RqThrottle = " + value);
379         Element JavaDoc docEle = domainXML.getDocumentElement();
380         NodeList JavaDoc nodeList = docEle.getElementsByTagName("config");
381         for (int i=0; i < nodeList.getLength(); i++) {
382             Element JavaDoc configElement = (Element JavaDoc)nodeList.item(i);
383             String JavaDoc attrValue = configElement.getAttribute("name");
384             if (attrValue.equals(commonInfo.getCurrentSourceInstance() + "-config")) {
385                 NodeList JavaDoc httpServiceNodes = configElement.getElementsByTagName("http-service");
386                 //there is only one http-service element
387
Element JavaDoc httpServiceElement = (Element JavaDoc)httpServiceNodes.item(0);
388                 NodeList JavaDoc subList = httpServiceElement.getElementsByTagName("request-processing");
389                 // There can be only one request-processing element.
390
Element JavaDoc element = (Element JavaDoc)subList.item(0);
391                 //If the element exists in the target, do the transformation
392
if (element != null) {
393                     element.setAttribute("thread-count", value);
394                 }
395             }
396         }
397     }
398     
399     public void transformRqThrottleMin(Document JavaDoc domainXML, String JavaDoc value) {
400         //http-service/request-processing:initial-thread-count
401
logger.finest("RqThrottleMin = " + value);
402         Element JavaDoc docEle = domainXML.getDocumentElement();
403         NodeList JavaDoc nodeList = docEle.getElementsByTagName("config");
404         for (int i=0; i < nodeList.getLength(); i++) {
405             Element JavaDoc configElement = (Element JavaDoc)nodeList.item(i);
406             String JavaDoc attrValue = configElement.getAttribute("name");
407             if (attrValue.equals(commonInfo.getCurrentSourceInstance() + "-config")) {
408                 NodeList JavaDoc httpServiceNodes = configElement.getElementsByTagName("http-service");
409                 //there is only one http-service element
410
Element JavaDoc httpServiceElement = (Element JavaDoc)httpServiceNodes.item(0);
411                 NodeList JavaDoc subList = httpServiceElement.getElementsByTagName("request-processing");
412                 // There can be only one request-processing element.
413
Element JavaDoc element = (Element JavaDoc)subList.item(0);
414                 //If the element exists in the target, do the transformation
415
if (element != null) {
416                     element.setAttribute("initial-thread-count", value);
417                 }
418             }
419         }
420     }
421     
422     public void transformSndBufSize(Document JavaDoc domainXML, String JavaDoc value) {
423         //http-service/connection-pool:send-buffer-size-bytes
424
logger.finest("SndBufSize = " + value);
425         Element JavaDoc docEle = domainXML.getDocumentElement();
426         NodeList JavaDoc nodeList = docEle.getElementsByTagName("config");
427         for (int i=0; i < nodeList.getLength(); i++) {
428             Element JavaDoc configElement = (Element JavaDoc)nodeList.item(i);
429             String JavaDoc attrValue = configElement.getAttribute("name");
430             if (attrValue.equals(commonInfo.getCurrentSourceInstance() + "-config")) {
431                 NodeList JavaDoc httpServiceNodes = configElement.getElementsByTagName("http-service");
432                 //there is only one http-service element
433
Element JavaDoc httpServiceElement = (Element JavaDoc)httpServiceNodes.item(0);
434                 NodeList JavaDoc subList = httpServiceElement.getElementsByTagName("connection-pool");
435                 // There can be only one connection-pool element.
436
Element JavaDoc element = (Element JavaDoc)subList.item(0);
437                 //If the element exists in the target, do the transformation
438
if (element != null) {
439                     element.setAttribute("send-buffer-size-bytes", value);
440                 }
441             }
442         }
443     }
444     
445     public void transformStackSize(Document JavaDoc domainXML, String JavaDoc value) {
446         //http-service
447
//property "stack-size"
448
//specified as a name value pair in the property element under http-service.
449
String JavaDoc name = "stack-size";
450         logger.finest("StackSize = " + value);
451         Element JavaDoc docEle = domainXML.getDocumentElement();
452         NodeList JavaDoc nodeList = docEle.getElementsByTagName("config");
453         for (int i=0; i < nodeList.getLength(); i++) {
454             Element JavaDoc configElement = (Element JavaDoc)nodeList.item(i);
455             String JavaDoc attrValue = configElement.getAttribute("name");
456             if (attrValue.equals(commonInfo.getCurrentSourceInstance() + "-config")) {
457                 NodeList JavaDoc httpServiceNodes = configElement.getElementsByTagName("http-service");
458                 //there is only one http-service element
459
Element JavaDoc httpServiceElement = (Element JavaDoc)httpServiceNodes.item(0);
460                 NodeList JavaDoc resultProperties = httpServiceElement.getElementsByTagName("property");
461                 Element JavaDoc resultProperty = null;
462                 if(resultProperties != null){
463                     for(int index=0; index < resultProperties.getLength(); index++){
464                         if(((Element JavaDoc)resultProperties.item(index)).getAttribute("name").equals(name)){
465                             resultProperty = (Element JavaDoc)resultProperties.item(index);
466                             resultProperty.getAttributeNode("value").setValue(value);
467                             //this.handleSpecialCases(element, resultProperty, parentSource, parentResult);
468
break;
469                         }
470                     }
471                 }
472                 if(resultProperty == null){
473                     resultProperty = httpServiceElement.getOwnerDocument().createElement("property");
474                     resultProperty.setAttribute("name", name);
475                     resultProperty.setAttribute("value", value);
476                     httpServiceElement.appendChild(resultProperty);
477                 }
478             }
479         }
480     }
481     
482     public void transformStrictHttpHeaders(Document JavaDoc domainXML, String JavaDoc value) {
483         //not exposed in domain.xml
484
}
485     
486     public void transformTerminateTimeout(Document JavaDoc domainXML, String JavaDoc value) {
487         //not supported
488
}
489     
490     public void transformUser(Document JavaDoc domainXML, String JavaDoc value) {
491         //not supported
492
}
493     
494     public void transformTempDir(Document JavaDoc domainXML, String JavaDoc value) {
495         //not supported
496
}
497     
498     public void transformThreadIncrement(Document JavaDoc domainXML, String JavaDoc value) {
499         //http-service/request-processing:thread-increment
500
logger.finest("ThreadIncrement = " + value);
501         Element JavaDoc docEle = domainXML.getDocumentElement();
502         NodeList JavaDoc nodeList = docEle.getElementsByTagName("config");
503         for (int i=0; i < nodeList.getLength(); i++) {
504             Element JavaDoc configElement = (Element JavaDoc)nodeList.item(i);
505             String JavaDoc attrValue = configElement.getAttribute("name");
506             if (attrValue.equals(commonInfo.getCurrentSourceInstance() + "-config")) {
507                 NodeList JavaDoc httpServiceNodes = configElement.getElementsByTagName("http-service");
508                 //there is only one http-service element
509
Element JavaDoc httpServiceElement = (Element JavaDoc)httpServiceNodes.item(0);
510                 NodeList JavaDoc subList = httpServiceElement.getElementsByTagName("request-processing");
511                 // There can be only one request-processing element.
512
Element JavaDoc element = (Element JavaDoc)subList.item(0);
513                 //If the element exists in the target, do the transformation
514
if (element != null) {
515                     element.setAttribute("thread-increment", value);
516                 }
517             }
518         }
519     }
520     
521     public void transformNativePoolStackSize(Document JavaDoc domainXML, String JavaDoc value) {
522     }
523     
524     public void transformNativePoolMaxThreads(Document JavaDoc domainXML, String JavaDoc value) {
525     }
526     
527     public void transformNativePoolMinThreads(Document JavaDoc domainXML, String JavaDoc value) {
528     }
529     
530     public void transformNativePoolQueueSize(Document JavaDoc domainXML, String JavaDoc value) {
531     }
532     
533     public void transformErrorLogDateFormat(Document JavaDoc domainXML, String JavaDoc value) {
534     }
535     
536     public void transformLogFlushInterval(Document JavaDoc domainXML, String JavaDoc value) {
537     }
538     
539     public void transformPidLog(Document JavaDoc domainXML, String JavaDoc value) {
540     }
541     
542     public void transformSecurity(Document JavaDoc domainXML, String JavaDoc value) {
543         //http-service/http-protocol:ssl-enabled
544
logger.finest("Security = " + value);
545         Element JavaDoc docEle = domainXML.getDocumentElement();
546         NodeList JavaDoc nodeList = docEle.getElementsByTagName("config");
547         for (int i=0; i < nodeList.getLength(); i++) {
548             Element JavaDoc configElement = (Element JavaDoc)nodeList.item(i);
549             String JavaDoc attrValue = configElement.getAttribute("name");
550             if (attrValue.equals(commonInfo.getCurrentSourceInstance() + "-config")) {
551                 NodeList JavaDoc httpServiceNodes = configElement.getElementsByTagName("http-service");
552                 //there is only one http-service element
553
Element JavaDoc httpServiceElement = (Element JavaDoc)httpServiceNodes.item(0);
554                 NodeList JavaDoc httpList = httpServiceElement.getElementsByTagName("http-protocol");
555                 // There should be only one http-protocol element.
556
Element JavaDoc element = (Element JavaDoc)httpList.item(0);
557                 //If the element exists in the target, do the transformation
558
if (element != null) {
559                     if (value.equalsIgnoreCase("off")) {
560                         element.setAttribute("ssl-enabled", "false");
561                     } else {
562                         element.setAttribute("ssl-enabled", "true");
563                     }
564                 }
565             }
566         }
567     }
568     
569     public void transformSSLCacheEntries(Document JavaDoc domainXML, String JavaDoc value) {
570         //http-service
571
//property "ssl-cache-entries"
572
//specified as a name value pair in the property element under http-service.
573
String JavaDoc name = "ssl-cache-entries";
574         logger.finest("SSLCacheEntries = " + value);
575         Element JavaDoc docEle = domainXML.getDocumentElement();
576         NodeList JavaDoc nodeList = docEle.getElementsByTagName("config");
577         for (int i=0; i < nodeList.getLength(); i++) {
578             Element JavaDoc configElement = (Element JavaDoc)nodeList.item(i);
579             String JavaDoc attrValue = configElement.getAttribute("name");
580             if (attrValue.equals(commonInfo.getCurrentSourceInstance() + "-config")) {
581                 NodeList JavaDoc httpServiceNodes = configElement.getElementsByTagName("http-service");
582                 //there is only one http-service element
583
Element JavaDoc httpServiceElement = (Element JavaDoc)httpServiceNodes.item(0);
584                 NodeList JavaDoc resultProperties = httpServiceElement.getElementsByTagName("property");
585                 Element JavaDoc resultProperty = null;
586                 if(resultProperties != null){
587                     for(int index=0; index < resultProperties.getLength(); index++){
588                         if(((Element JavaDoc)resultProperties.item(index)).getAttribute("name").equals(name)){
589                             resultProperty = (Element JavaDoc)resultProperties.item(index);
590                             resultProperty.getAttributeNode("value").setValue(value);
591                             //this.handleSpecialCases(element, resultProperty, parentSource, parentResult);
592
break;
593                         }
594                     }
595                 }
596                 if(resultProperty == null){
597                     resultProperty = httpServiceElement.getOwnerDocument().createElement("property");
598                     resultProperty.setAttribute("name", name);
599                     resultProperty.setAttribute("value", value);
600                     httpServiceElement.appendChild(resultProperty);
601                 }
602             }
603         }
604     }
605     
606     public void transformSSLClientAuthDataLimit(Document JavaDoc domainXML, String JavaDoc value) {
607         //http-service
608
//property "ssl-client-auth-data-limit"
609
//specified as a name value pair in the property element under http-service.
610
String JavaDoc name = "ssl-client-auth-data-limit";
611         logger.finest("SSLClientAuthDataLimit = " + value);
612         Element JavaDoc docEle = domainXML.getDocumentElement();
613         NodeList JavaDoc nodeList = docEle.getElementsByTagName("config");
614         for (int i=0; i < nodeList.getLength(); i++) {
615             Element JavaDoc configElement = (Element JavaDoc)nodeList.item(i);
616             String JavaDoc attrValue = configElement.getAttribute("name");
617             if (attrValue.equals(commonInfo.getCurrentSourceInstance() + "-config")) {
618                 NodeList JavaDoc httpServiceNodes = configElement.getElementsByTagName("http-service");
619                 //there is only one http-service element
620
Element JavaDoc httpServiceElement = (Element JavaDoc)httpServiceNodes.item(0);
621                 NodeList JavaDoc resultProperties = httpServiceElement.getElementsByTagName("property");
622                 Element JavaDoc resultProperty = null;
623                 if(resultProperties != null){
624                     for(int index=0; index < resultProperties.getLength(); index++){
625                         if(((Element JavaDoc)resultProperties.item(index)).getAttribute("name").equals(name)){
626                             resultProperty = (Element JavaDoc)resultProperties.item(index);
627                             resultProperty.getAttributeNode("value").setValue(value);
628                             //this.handleSpecialCases(element, resultProperty, parentSource, parentResult);
629
break;
630                         }
631                     }
632                 }
633                 if(resultProperty == null){
634                     resultProperty = httpServiceElement.getOwnerDocument().createElement("property");
635                     resultProperty.setAttribute("name", name);
636                     resultProperty.setAttribute("value", value);
637                     httpServiceElement.appendChild(resultProperty);
638                 }
639             }
640         }
641     }
642     
643     public void transformSSLClientAuthTimeout(Document JavaDoc domainXML, String JavaDoc value) {
644         //http-service
645
//property "ssl-client-auth-timeout"
646
//specified as a name value pair in the property element under http-service.
647
String JavaDoc name = "ssl-client-auth-timeout";
648         logger.finest("SSLClientAuthTimeout = " + value);
649         Element JavaDoc docEle = domainXML.getDocumentElement();
650         NodeList JavaDoc nodeList = docEle.getElementsByTagName("config");
651         for (int i=0; i < nodeList.getLength(); i++) {
652             Element JavaDoc configElement = (Element JavaDoc)nodeList.item(i);
653             String JavaDoc attrValue = configElement.getAttribute("name");
654             if (attrValue.equals(commonInfo.getCurrentSourceInstance() + "-config")) {
655                 NodeList JavaDoc httpServiceNodes = configElement.getElementsByTagName("http-service");
656                 //there is only one http-service element
657
Element JavaDoc httpServiceElement = (Element JavaDoc)httpServiceNodes.item(0);
658                 NodeList JavaDoc resultProperties = httpServiceElement.getElementsByTagName("property");
659                 Element JavaDoc resultProperty = null;
660                 if(resultProperties != null){
661                     for(int index=0; index < resultProperties.getLength(); index++){
662                         if(((Element JavaDoc)resultProperties.item(index)).getAttribute("name").equals(name)){
663                             resultProperty = (Element JavaDoc)resultProperties.item(index);
664                             resultProperty.getAttributeNode("value").setValue(value);
665                             //this.handleSpecialCases(element, resultProperty, parentSource, parentResult);
666
break;
667                         }
668                     }
669                 }
670                 if(resultProperty == null){
671                     resultProperty = httpServiceElement.getOwnerDocument().createElement("property");
672                     resultProperty.setAttribute("name", name);
673                     resultProperty.setAttribute("value", value);
674                     httpServiceElement.appendChild(resultProperty);
675                 }
676             }
677         }
678     }
679     
680     public void transformSSLSessionTimeout(Document JavaDoc domainXML, String JavaDoc value) {
681         //http-service
682
//property "ssl-session-timeout"
683
//specified as a name value pair in the property element under http-service.
684
String JavaDoc name = "ssl-session-timeout";
685         logger.finest("SSLSessionTimeout = " + value);
686         Element JavaDoc docEle = domainXML.getDocumentElement();
687         NodeList JavaDoc nodeList = docEle.getElementsByTagName("config");
688         for (int i=0; i < nodeList.getLength(); i++) {
689             Element JavaDoc configElement = (Element JavaDoc)nodeList.item(i);
690             String JavaDoc attrValue = configElement.getAttribute("name");
691             if (attrValue.equals(commonInfo.getCurrentSourceInstance() + "-config")) {
692                 NodeList JavaDoc httpServiceNodes = configElement.getElementsByTagName("http-service");
693                 //there is only one http-service element
694
Element JavaDoc httpServiceElement = (Element JavaDoc)httpServiceNodes.item(0);
695                 NodeList JavaDoc resultProperties = httpServiceElement.getElementsByTagName("property");
696                 Element JavaDoc resultProperty = null;
697                 if(resultProperties != null){
698                     for(int index=0; index < resultProperties.getLength(); index++){
699                         if(((Element JavaDoc)resultProperties.item(index)).getAttribute("name").equals(name)){
700                             resultProperty = (Element JavaDoc)resultProperties.item(index);
701                             resultProperty.getAttributeNode("value").setValue(value);
702                             //this.handleSpecialCases(element, resultProperty, parentSource, parentResult);
703
break;
704                         }
705                     }
706                 }
707                 if(resultProperty == null){
708                     resultProperty = httpServiceElement.getOwnerDocument().createElement("property");
709                     resultProperty.setAttribute("name", name);
710                     resultProperty.setAttribute("value", value);
711                     httpServiceElement.appendChild(resultProperty);
712                 }
713             }
714         }
715     }
716     
717     public void transformSSL3SessionTimeout(Document JavaDoc domainXML, String JavaDoc value) {
718         //http-service
719
//property "ssl3-session-timeout"
720
//specified as a name value pair in the property element under http-service.
721
String JavaDoc name = "ssl3-session-timeout";
722         logger.finest("SSL3SessionTimeout = " + value);
723         Element JavaDoc docEle = domainXML.getDocumentElement();
724         NodeList JavaDoc nodeList = docEle.getElementsByTagName("config");
725         for (int i=0; i < nodeList.getLength(); i++) {
726             Element JavaDoc configElement = (Element JavaDoc)nodeList.item(i);
727             String JavaDoc attrValue = configElement.getAttribute("name");
728             if (attrValue.equals(commonInfo.getCurrentSourceInstance() + "-config")) {
729                 NodeList JavaDoc httpServiceNodes = configElement.getElementsByTagName("http-service");
730                 //there is only one http-service element
731
Element JavaDoc httpServiceElement = (Element JavaDoc)httpServiceNodes.item(0);
732                 NodeList JavaDoc resultProperties = httpServiceElement.getElementsByTagName("property");
733                 Element JavaDoc resultProperty = null;
734                 if(resultProperties != null){
735                     for(int index=0; index < resultProperties.getLength(); index++){
736                         if(((Element JavaDoc)resultProperties.item(index)).getAttribute("name").equals(name)){
737                             resultProperty = (Element JavaDoc)resultProperties.item(index);
738                             resultProperty.getAttributeNode("value").setValue(value);
739                             //this.handleSpecialCases(element, resultProperty, parentSource, parentResult);
740
break;
741                         }
742                     }
743                 }
744                 if(resultProperty == null){
745                     resultProperty = httpServiceElement.getOwnerDocument().createElement("property");
746                     resultProperty.setAttribute("name", name);
747                     resultProperty.setAttribute("value", value);
748                     httpServiceElement.appendChild(resultProperty);
749                 }
750             }
751         }
752     }
753     
754     public void transformHTTPVersion(Document JavaDoc domainXML, String JavaDoc value) {
755         //http-service/http-protocol:http-version
756
logger.finest("HTTPVersion = " + value);
757         Element JavaDoc docEle = domainXML.getDocumentElement();
758         NodeList JavaDoc nodeList = docEle.getElementsByTagName("config");
759         for (int i=0; i < nodeList.getLength(); i++) {
760             Element JavaDoc configElement = (Element JavaDoc)nodeList.item(i);
761             String JavaDoc attrValue = configElement.getAttribute("name");
762             if (attrValue.equals(commonInfo.getCurrentSourceInstance() + "-config")) {
763                 NodeList JavaDoc httpServiceNodes = configElement.getElementsByTagName("http-service");
764                 //there is only one http-service element
765
Element JavaDoc httpServiceElement = (Element JavaDoc)httpServiceNodes.item(0);
766                 NodeList JavaDoc httpList = httpServiceElement.getElementsByTagName("http-protocol");
767                 // There should be only one http-protocol element.
768
Element JavaDoc element = (Element JavaDoc)httpList.item(0);
769                 //If the element exists in the target, do the transformation
770
if (element != null) {
771                     element.setAttribute("http-version", value);
772                 }
773             }
774         }
775     }
776     
777  /*
778     public static void main(String [] args) {
779         try{
780             com.sun.enterprise.tools.upgrade.logging.LogService.initialize("upgradetest.log");
781         
782         }catch(Exception e){
783             e.printStackTrace();
784         }
785         CommonInfoModel cim = new CommonInfoModel();
786         cim.setSourceInstallDir("C:\\Sun\\AppServer7");
787         cim.setTargetInstallDir("C:\\Sun\\AppServer81ee");
788         cim.setCurrentDomain("domain1");
789         cim.setCurrentSourceInstance("server1");
790         cim.setTargetDomainRoot("C:\\Sun\\AppServer81ee\\domains");
791         java.util.Hashtable ht = new java.util.Hashtable();
792         ht.put("domain1", "C:\\Sun\\AppServer7\\domains\\domain1");
793         cim.setDomainMapping(ht);
794         cim.enlistDomainsFromSource();
795         cim.setAdminPassword("adminadmin");
796         new InitConfTransfer(cim).transform();
797     }
798   */

799  
800 }
801
Popular Tags