KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > launcher > PELaunchFilter


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 package com.sun.enterprise.launcher;
24
25 import java.util.HashMap JavaDoc;
26 import java.util.ArrayList JavaDoc;
27 import java.util.StringTokenizer JavaDoc;
28 import org.w3c.dom.*;
29 import java.io.File JavaDoc;
30 import javax.xml.parsers.*;
31 import com.sun.org.apache.commons.launcher.LaunchFilter;
32 import com.sun.org.apache.commons.launcher.LaunchCommand;
33 import org.apache.tools.ant.BuildException;
34
35 //The RelativePathResolver is used to translate relative paths containing
36
//embedded system properties (e.g. ${com.sun.aas.instanceRoot}/applications)
37
//into absolute paths
38
import com.sun.enterprise.util.RelativePathResolver;
39
40 import com.sun.enterprise.util.ASenvPropertyReader;
41 import com.sun.enterprise.util.SystemPropertyConstants;
42 import com.sun.enterprise.util.OS;
43
44
45 /**
46  * Create a filter for Appserver to use commons launcher. This filter is used
47  * to parse out the jvm-options from server.xml and use it to launch the vm.
48  *
49  * @author Ramesh Mandava (ramesh.mandava@sun.com)
50  * @author Sheetal Vartak (sheetalv@sun.com)
51  */

52
53 public class PELaunchFilter implements LaunchFilter {
54
55     public static final String JavaDoc DEBUG_OPTIONS = "com.sun.aas.jdwpOptions";
56     public static final String JavaDoc LOCALE = "locale";
57
58     ArrayList JavaDoc jvmArgsList = null;
59     HashMap JavaDoc sysProps = null;
60     String JavaDoc serverModeOrClientMode = null;
61
62
63     public static String JavaDoc getDebugProperty(String JavaDoc debug_options, String JavaDoc name) {
64         int nameIndex;
65         if ( (nameIndex = debug_options.indexOf(name)) != -1 ) {
66             // format is "name=value"
67
String JavaDoc value = debug_options.substring(nameIndex
68                                                    + name.length() + 1);
69             int commaIndex;
70             if ( (commaIndex = value.indexOf(",")) != -1 ) {
71                 value = value.substring(0, commaIndex);
72             }
73             return value;
74         }
75         return null;
76     }
77
78
79     public void filter(LaunchCommand command) throws BuildException {
80
81
82     try {
83             //Set system properties that correspond directly to asenv.conf/bat. This
84
//keeps us from having to pass them all from -D on the command line.
85
ASenvPropertyReader reader = new ASenvPropertyReader(
86                 System.getProperty(SystemPropertyConstants.CONFIG_ROOT_PROPERTY));
87             reader.setSystemProperties();
88
89             // Reset serverModeOrClientMode to null for each filter invocation
90
serverModeOrClientMode = null;
91
92             boolean stopOperation = false;
93             boolean waitForChild = command.getWaitforchild();
94             boolean debugOption = false;
95
96             ArrayList JavaDoc argsList = command.getArgs();
97             String JavaDoc[] args =(String JavaDoc[])argsList.toArray(new String JavaDoc[argsList.size()]);
98
99             for ( int ar=0; ar < args.length; ar++ ) {
100                 if ( "stop".equals( args[ar] ) ) {
101                 // When server need to be stopped keep the process in foreground
102
stopOperation = true;
103                      waitForChild = true;
104                     debugOption = false;
105                     break;
106                  }
107                 else if ( "debug".equals(args[ar]) ) {
108                     debugOption = true; // for "asadmin start-domain --debug"
109
}
110                 else if ( "verbose".equals(args[ar]) ) {
111                     waitForChild = true; // for "asadmin start-domain --verbose"
112
}
113             }
114
115
116             //ArrayList jvmArgsList = command.getJvmargs( );
117
jvmArgsList = command.getJvmargs( );
118             if ( jvmArgsList == null ) {
119                 jvmArgsList = new ArrayList JavaDoc();
120             }
121
122         if ( waitForChild ) {
123         // this is used in ServerLogManager to send logs to stderr
124
jvmArgsList.add("-Dcom.sun.aas.verboseMode=true");
125         }
126
127         //HashMap sysProps = command.getSysproperties();
128
sysProps = command.getSysproperties();
129         if ( sysProps == null ) {
130                 // We are relying on system propeties to be present with the
131
// required values
132
// It is FATAL error if execution come to this block
133
// PENDING : Logging and update the messages
134
System.out.println("[FATAL ERROR] System properties with S1AS"+
135                    " installation values doesn't present" );
136                 System.out.println("Please check <installtionDir>/lib/launcher.xml" );
137                 System.out.println( "Exiting out");
138                 System.exit(1);
139         }
140         DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
141         DocumentBuilder db = dbf.newDocumentBuilder();
142
143             // We must set up a custom entity resolver (the same used by the admin
144
// backend in the server). This is necessary to parse the DOCTYPE
145
// attribute in domain.xml which now contains ${com.sun.aas.installRoot}
146
db.setEntityResolver((org.xml.sax.helpers.DefaultHandler JavaDoc)Class.forName
147                 ("com.sun.enterprise.config.serverbeans.ServerValidationHandler").newInstance());
148
149             String JavaDoc instanceRoot =(String JavaDoc)sysProps.get("com.sun.aas.instanceRoot");
150             String JavaDoc serverName = (String JavaDoc)sysProps.get("com.sun.aas.instanceName");
151             // If for some reason com.sun.aas.instanceName property is not set,
152
// we are defaulting to "server"
153
if ( serverName == null ) {
154                 serverName="server";
155             }
156
157             String JavaDoc domainConfigFilePath = instanceRoot + File.separator +
158             "config" + File.separator +
159                 "domain.xml";
160
161         Document doc = db.parse(domainConfigFilePath );
162
163         Element root = doc.getDocumentElement();
164
165             //Set any system properties specified as domain properties first
166
//since these have the lowest precedence.
167
handleSystemProperties(root);
168
169             //set the default locale specified in domain.xml config file
170
if(root.hasAttribute(LOCALE)) {
171                 String JavaDoc locale = root.getAttribute(LOCALE);
172                 if(locale != null && !"".equals(locale)) {
173                     sysProps.put(SystemPropertyConstants.DEFAULT_LOCALE_PROPERTY, locale);
174                 }
175             } else {
176                 sysProps.put(SystemPropertyConstants.DEFAULT_LOCALE_PROPERTY,
177                         System.getProperty(SystemPropertyConstants.DEFAULT_LOCALE_PROPERTY));
178             }
179
180         //
181
// Get server element for the given server name
182
//
183

184             NodeList servers = root.getElementsByTagName("servers");
185
186         if (servers.getLength() < 1) {
187                 System.out.println("[FATAL ERROR] " +
188             " domain.xml doesn't have servers element");
189         System.exit(1);
190         }
191
192         Element serversElement = (Element) servers.item(0);
193
194             NodeList server = serversElement.getElementsByTagName("server");
195
196         if (server.getLength() < 1) {
197                 System.out.println("[FATAL ERROR] " +
198             " domain.xml doesn't have server element");
199         System.exit(1);
200         }
201
202         Element serverElement = null;
203
204         boolean foundMatchingServer = false;
205         for (int i=0; i<server.getLength(); i++) {
206         serverElement = (Element) server.item(i);
207         if ((serverElement.getAttribute("name")).equals(serverName)) {
208             foundMatchingServer = true;
209             break;
210         }
211         }
212
213         if (! foundMatchingServer) {
214                 System.out.println("[FATAL ERROR] " +
215             " domain.xml doesn't have the server element named: " + serverName);
216         System.exit(1);
217         }
218
219         //
220
// Get config element
221
//
222
// config is an attribute of server. So, use getAttribute
223
String JavaDoc configRef = serverElement.getAttribute("config-ref");
224
225         //Set the com.sun.aas.configName system property to hold the configName
226
sysProps.put(SystemPropertyConstants.CONFIG_NAME_PROPERTY ,
227             configRef);
228         System.setProperty(SystemPropertyConstants.CONFIG_NAME_PROPERTY,
229             configRef);
230
231         NodeList logServices = getNodeList(root, configRef, "log-service");
232
233         Element logServiceElement = null;
234         String JavaDoc logFileName = null;
235         String JavaDoc logToConsole = null;
236
237         // Only one log-service element would be there in domain.xml
238
// In case of more than one log-service element declaration is
239
// there, then the last one would be used
240
for ( int ls=0; ls<logServices.getLength(); ls++ ) {
241              logServiceElement = (Element)logServices.item(ls);
242              logFileName = RelativePathResolver.resolvePath(
243                 logServiceElement.getAttribute("file"));
244              logToConsole = logServiceElement.getAttribute("log-to-console");
245         }
246
247         if( (logToConsole != null )
248           &&(logToConsole.equals( "true" ) ) )
249         {
250             waitForChild = true;
251             jvmArgsList.add("-Dcom.sun.aas.verboseMode=true");
252         } else if ( logFileName != null ) {
253              command.setOutput( new File JavaDoc(logFileName) );
254         }
255         command.setWaitforchild ( waitForChild );
256
257         //
258
// Modified the code to get java-config for the given server
259
//
260
// NodeList javaConfigs = root.getElementsByTagName("java-config");
261

262             NodeList javaConfigs = getNodeList(root, configRef, "java-config");
263
264             //javaconfig attribute value holders declaration
265
Element javaConfigElement = null;
266             String JavaDoc debug_enabled = null;
267             String JavaDoc debug_options = null;
268             String JavaDoc rmic_options = null;
269             String JavaDoc javac_options = null;
270             String JavaDoc java_home = null;
271             String JavaDoc classpath_prefix = null;
272             String JavaDoc server_classpath = null;
273             String JavaDoc classpath_suffix = null;
274             String JavaDoc native_library_path_prefix = null;
275             String JavaDoc native_library_path_suffix = null;
276             String JavaDoc bytecode_preprocessors = null;
277             String JavaDoc env_classpath_ignored = "true";
278
279             // It seems that only one java-config element would be there as
280
// part of domain.xml. Shall we just use first occurence instead of
281
// for loop. PENDING : Error condition check
282
for ( int jc=0; jc<javaConfigs.getLength(); jc++ ) {
283                 javaConfigElement = (Element)javaConfigs.item(jc);
284
285                 debug_enabled = javaConfigElement.getAttribute
286                     ("debug-enabled");
287                 debug_options = javaConfigElement.getAttribute
288                     ("debug-options");
289                 rmic_options = javaConfigElement.getAttribute
290                     ("rmic-options");
291                 javac_options = javaConfigElement.getAttribute
292                     ("javac-options");
293                 if (OS.isDarwin()) {
294                     java_home = RelativePathResolver.resolvePath(
295                         javaConfigElement.getAttribute("java-home"));
296                 } else {
297                     java_home = RelativePathResolver.resolvePath(
298                         javaConfigElement.getAttribute("java-home") +
299                         File.separator + "jre");
300                 }
301                 classpath_prefix = RelativePathResolver.resolvePath(
302                     javaConfigElement.getAttribute("classpath-prefix"));
303             server_classpath = RelativePathResolver.resolvePath(
304                     javaConfigElement.getAttribute("server-classpath"));
305                 classpath_suffix = RelativePathResolver.resolvePath(
306                     javaConfigElement.getAttribute("classpath-suffix"));
307                 native_library_path_prefix = javaConfigElement.getAttribute
308                     ("native-library-path-prefix");
309                 native_library_path_suffix = javaConfigElement.getAttribute
310                     ("native-library-path-suffix");
311                 bytecode_preprocessors = javaConfigElement.getAttribute
312                     ("bytecode-preprocessors");
313                 env_classpath_ignored= javaConfigElement.getAttribute
314                     ("env-classpath-ignored");
315             }
316         if(java_home != null)
317                 System.setProperty("java.home", java_home );
318             String JavaDoc profilerClasspath = null;
319             String JavaDoc profilerNativeLibraryPath = null;
320             // Now handle profiler element
321

322         //
323
// Modified the code to get profiler for the given server
324
//
325
// NodeList profilers = root.getElementsByTagName("profiler");
326

327         NodeList profilers = javaConfigElement.getElementsByTagName("profiler");
328
329             int numberOfProfilerElements = profilers.getLength();
330             if ( numberOfProfilerElements > 0 ) {
331                 //According to DTD we should have only one or zero, but even if
332
// we have more than 1, just use first one
333
Element profilerElement = (Element)(profilers.item(0));
334                 String JavaDoc profilerEnabled=profilerElement.getAttribute("enabled");
335
336                 if ( (profilerEnabled != null ) &&
337                     ( profilerEnabled.equals("true") ) ) {
338                     //Now we need to take care of profiler options
339
String JavaDoc profilerName=profilerElement.getAttribute("name");
340                     if ( profilerName == null ) {
341                         //Send error message but continue
342
System.err.println("ERROR : Profiler is enabled. But Name is null");
343                         System.err.println("Profiler settings are ignored");
344                     } else {
345                         profilerClasspath =profilerElement.getAttribute(
346                             "classpath");
347                         profilerNativeLibraryPath =
348                             profilerElement.getAttribute("native-library-path");
349
350                         handleJvmOptions ( profilerElement );
351                         handleProperties ( profilerElement );
352
353                     }
354
355
356                 }
357
358
359             }
360
361             String JavaDoc requestedClasspath = server_classpath;
362
363         // Classpath set through launcher.xml launch task
364
String JavaDoc originalClasspath = command.getClasspath();
365
366             if ( originalClasspath != null ) {
367                 requestedClasspath = originalClasspath + File.pathSeparator +
368           requestedClasspath;
369             }
370
371             if (( classpath_prefix != null ) &&
372                 (!classpath_prefix.trim().equals("")) ) {
373                 requestedClasspath = classpath_prefix + File.pathSeparator +
374                     requestedClasspath;
375             }
376             if (( classpath_suffix != null ) &&
377                 (!classpath_suffix.trim().equals("")) ) {
378                 requestedClasspath = requestedClasspath + File.pathSeparator +
379                     classpath_suffix ;
380             }
381
382             if (( profilerClasspath != null)&&
383                 (!profilerClasspath.trim().equals("")) ) {
384                 requestedClasspath = requestedClasspath + File.pathSeparator +
385                     profilerClasspath;
386             }
387
388
389             String JavaDoc envClasspath = (String JavaDoc)sysProps.get("user.classpath");
390             sysProps.remove("user.classpath");
391
392             if ( env_classpath_ignored != null &&
393                 env_classpath_ignored.equals("false") &&
394                 (!envClasspath.equals("${env.CLASSPATH}") )) {
395                 requestedClasspath = requestedClasspath + File.pathSeparator +
396                     envClasspath;
397             }
398
399             command.setClasspath ( requestedClasspath );
400
401             handleJvmOptions ( javaConfigElement );
402
403             // Now set the remaining properties which we got from java-config
404
// We should n't set debugger for stop operation ( stop-domain)
405
if ( debug_enabled != null && debug_enabled.equals("true") ) {
406                 debugOption = true;
407             }
408             if ( debugOption && !stopOperation ) {
409
410                 // If debug is enabled, then we need to pass on -Xdebug option
411
jvmArgsList.add("-Xdebug");
412
413             // It seems that -Xdebug and other debug options shouldn't go
414
// as one argument So we will check if debug_options starts
415
// with that and give it as separate argument
416
debug_options=debug_options.trim();
417                 if ( debug_options.startsWith("-Xdebug") ) {
418                     debug_options =debug_options.substring("-Xdebug".length()).trim();
419                 }
420
421                 // Get the JPDA transport and address (port) from the
422
// debug_options. If address is not specified in debug_options
423
// for transport=dt_socket, we find a free port
424
// and add it to -Xrunjdwp.
425
//
426
// If address is specified in -Xrunjdwp, then the JVM
427
// does not print any debug message, so we need to print it for
428
// easy viewing by the user.
429
// If address is not specified in debug_options,
430
// then the JVM will print a message like:
431
// Listening for transport dt_socket at address: 33305
432
// This is only visible with "asadmin start-domain --verbose"
433
//
434
// The format of debug_options is:
435
// -Xrunjdwp:<name1>[=<value1>],<name2>[=<value2>]
436

437                 String JavaDoc transport = getDebugProperty(debug_options, "transport");
438                 String JavaDoc addr = getDebugProperty(debug_options, "address");
439
440                 if ( transport == null || transport.equals("") ) {
441                     // XXX I18N this
442
throw new BuildException("Cannot start server in debug mode: no transport specified in debug-options in domain.xml.");
443                 }
444
445                 if ( transport.equals("dt_socket") ) {
446                     if ( addr != null && !addr.equals("") ) {
447                         // XXX Should we check if the port is free using
448
// com.sun.enterprise.util.net.NetUtils.isPortFree(port)
449
}
450                     else {
451                         // Get a free port
452
int port =
453                             com.sun.enterprise.util.net.NetUtils.getFreePort();
454                         if ( port == 0 ) {
455                             // XXX I18N this
456
throw new BuildException("Cannot start server in debug mode: unable to obtain a free port for transport dt_socket.");
457                         }
458                         addr = String.valueOf(port);
459
460                         debug_options = debug_options + ",address=" + addr;
461                     }
462                 }
463
464                 jvmArgsList.add(debug_options);
465
466                 // Provide the actual JDWP options to the server using a
467
// system property. This allow the server to make it available
468
// to the debugger (e.g. S1 Studio) using an API.
469
String JavaDoc jdwpOptions = debug_options.substring(
470                    debug_options.indexOf("-Xrunjdwp:") + "-Xrunjdwp:".length());
471
472                 jvmArgsList.add("-D" + DEBUG_OPTIONS + "=" + jdwpOptions);
473             }
474
475         // Need to fix Launcher code to deal with this native_library_path
476

477             String JavaDoc javaLibPath = System.getProperty("java.library.path");
478
479             if ( (native_library_path_prefix != null ) &&
480                 (! native_library_path_prefix.trim().equals("") ) ) {
481                 if (javaLibPath != null ) {
482                     javaLibPath =native_library_path_prefix +
483                         File.pathSeparator + javaLibPath;
484                 } else {
485                     javaLibPath = native_library_path_prefix;
486                 }
487             }
488             if ( (native_library_path_suffix != null ) &&
489                 (! native_library_path_suffix.trim().equals("") ) ) {
490                 if (javaLibPath != null ) {
491                     javaLibPath =javaLibPath + File.pathSeparator +
492                         native_library_path_suffix ;
493                 } else {
494                     javaLibPath = native_library_path_suffix;
495                 }
496             }
497             if (( profilerNativeLibraryPath != null ) &&
498                 ( !profilerNativeLibraryPath.trim().equals("") ) ) {
499                 if (javaLibPath != null ) {
500                     javaLibPath =javaLibPath + File.pathSeparator +
501                         profilerNativeLibraryPath ;
502                 } else {
503                     javaLibPath = profilerNativeLibraryPath;
504                 }
505             }
506
507         /* windows appends the java.library.path sys property
508          with the %Path% value. We need to make sure that the %Path%
509          doesnot contain double quotes for path elements. Otherwise
510          server exits with error.
511         */

512         javaLibPath = normalize(javaLibPath);
513             sysProps.put("java.library.path" , javaLibPath);
514             System.setProperty("java.library.path", javaLibPath );
515
516             // Put vm mode -server or -client, only when user mention that as
517
// part of domain.xml as the first arg in jvmArgsList to give that
518
// as the first argument to VM
519

520             if ( serverModeOrClientMode != null ) {
521                 jvmArgsList.add( 0, "-" + serverModeOrClientMode );
522             }
523
524             //Set any server properties specified as configuration properties followeed
525
//by server instance specific properties since these have the highest precedence.
526
handleSystemProperties(getConfigElement(root, configRef));
527             //FIXTHIS:WARNING. Currently properties which are present in the cluster element
528
//referenced by the server element are not handled. This is not implemented for
529
//the following reasons:
530
//1)Currently commons-launcher is used to start the DAS only and the DAS can
531
//never be a cluster member
532
//2)It is not clear how long this code will stay around
533
handleSystemProperties(serverElement);
534             /* uncommment to enable a dump of the system properties
535             Object[] keys = sysProps.keySet().toArray();
536             for (int i = 0; i < keys.length; i++) {
537                 System.out.println("sysProp: " + (String)keys[i] + " " + sysProps.get((String)keys[i]));
538             }
539             */

540
541         command.setSysproperties(sysProps);
542     } catch(Exception JavaDoc e) {
543         e.printStackTrace();
544         throw new BuildException();
545     }
546     }
547
548     /* windows appends the java.library.path sys property
549        with the %Path% value. We need to make sure that the %Path%
550        doesnot contain double quotes for path elements. Otherwise
551        server exits with error.
552     */

553     private String JavaDoc normalize(String JavaDoc path) {
554     path = path.replaceAll("\"","");
555     path = path.replaceAll("\'","");
556     return path;
557     }
558
559     private void handleJvmOptions ( Element element ) {
560         NodeList jvmoptions = element.getChildNodes();
561         Element tmpElement = null;
562         Node tmpNode = null;
563         String JavaDoc systemProperty = null;
564         String JavaDoc property = null;
565         String JavaDoc value = null;
566         for (int i = 0; i < jvmoptions.getLength(); i++) {
567                 Node varNode = jvmoptions.item(i);
568                 if ( ( varNode.getNodeType()!= Node.ELEMENT_NODE ) ||
569                     (!varNode.getNodeName().equals("jvm-options") ) ) {
570                     continue;
571                 }
572             tmpElement = (Element) varNode;
573             tmpNode = tmpElement.getFirstChild();
574                 // If we encounter element like <jvm-options/> then ignore that
575
if ( tmpNode == null ) {
576                     continue;
577                 }
578
579                 // If we encounter <jvm-options> elements with just white space
580
// then ignore that
581
if(tmpNode instanceof Text) {
582             if(tmpNode.getNodeValue().equals("")) {
583                 continue;
584             }
585             }
586             systemProperty = (tmpNode.getNodeValue()).trim();
587
588                 // Allowing multiple options in one jvm-options element
589
// We also allow - to appear in any jvm-option content like
590
// -Dtest-name=test-value
591
StringTokenizer JavaDoc stk = new StringTokenizer JavaDoc(systemProperty,"-");
592                 String JavaDoc currentToken = null;
593                 String JavaDoc option = null;
594
595                 int tokenCount = 0;
596                 int numOfTokens = stk.countTokens();
597
598                 while ( stk.hasMoreTokens() ) {
599                     if ( currentToken != null ) {
600                         currentToken = currentToken + "-" + stk.nextToken();
601                     } else {
602                         currentToken = stk.nextToken();
603                     }
604                     tokenCount++;
605
606                     if ( ! currentToken.endsWith(" " ) ) {
607                         // if there are still tokens then try to augment them
608
// other wise the currentToken would be the last option
609
if ( tokenCount < numOfTokens ) {
610                             continue;
611                         }
612                     }
613
614                     option = currentToken.trim();
615                     currentToken = null;
616
617                     if ( option.startsWith("D") ) {
618                         option = option.substring(1, option.length() );
619
620                         int indexOfEqual= option.indexOf("=");
621                         if ( indexOfEqual > 0 ) {
622                             property = option.substring(0,indexOfEqual );
623                             value = option.substring(indexOfEqual+1 );
624                         sysProps.put(property,
625                                     RelativePathResolver.resolvePath(value));
626                         } else {
627                             //To allow options like -Djava.compiler without val
628
property = option;
629                     jvmArgsList.add( "-D" + property );
630                         }
631                     } else {
632                         if ( ( option.equals("client")) ||
633                             (option.equals("server")) ) {
634                             //If user mentions server or client mode for VM
635
// then use that over default which is "server"
636
// As we want to keep this as first arg don't add
637
// to the jvmArgsList yet
638
serverModeOrClientMode = option;
639                         } else {
640                     jvmArgsList.add( "-" + option );
641                         }
642                     }
643                 }
644
645         }
646
647     }
648
649     private void handleSystemProperties ( Element element ) {
650         handleProperties(element, "system-property");
651     }
652
653     private void handleProperties ( Element element ) {
654         handleProperties(element, "property");
655     }
656
657     private void handleProperties ( Element element, String JavaDoc elementName ) {
658         NodeList properties = element.getChildNodes();
659         Element propertyElement = null;
660         Node tmpNode = null;
661         String JavaDoc systemProperty = null;
662         String JavaDoc property = null;
663         String JavaDoc value = null;
664         for (int i = 0; i < properties.getLength(); i++) {
665            Node varNode = properties.item(i);
666            if ( ( varNode.getNodeType()!= Node.ELEMENT_NODE ) ||
667                 (!varNode.getNodeName().equals(elementName) ) ) {
668                 continue;
669             }
670             propertyElement = (Element)varNode;
671
672             String JavaDoc propertyName = propertyElement.getAttribute("name");
673             String JavaDoc propertyValue = propertyElement.getAttribute("value");
674
675             sysProps.put(propertyName, propertyValue);
676         }
677     }
678
679     private Element getConfigElement(Element root, String JavaDoc configRef)
680     {
681         Element configElement = null;
682         NodeList configs = root.getElementsByTagName("configs");
683         //will never enter this condition as dtd requires configs.
684
if (configs.getLength() < 1) {
685             System.out.println("[FATAL ERROR] " +
686             " domain.xml doesn't have configs element");
687             System.exit(1);
688         }
689
690         Element configsElement = (Element) configs.item(0);
691         NodeList config = configsElement.getElementsByTagName("config");
692         if (config.getLength() < 1) {
693             System.out.println("[FATAL ERROR] " +
694             " domain.xml doesn't have config element");
695             System.exit(1);
696         }
697
698         for (int j=0; j < config.getLength(); j++) {
699             configElement = (Element) config.item(j);
700             if ((configElement.getAttribute("name")).equals(configRef)) {
701                 return configElement;
702             }
703         }
704
705         //There better be a configuration matching the server's configuration ref
706
//or domain.xml is corrupt.
707
System.out.println("[FATAL ERROR] " +
708             " domain.xml doesn't have config element matching " + configRef);
709         System.exit(1);
710         return null;
711     }
712
713     private NodeList getNodeList(Element root, String JavaDoc configRef, String JavaDoc nlName) {
714         Element configElement = getConfigElement(root, configRef);
715         return configElement.getElementsByTagName(nlName);
716     }
717
718 }
719
Popular Tags