KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > j2ee > websphere6 > ui > ServerProperties


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19 package org.netbeans.modules.j2ee.websphere6.ui;
20
21 import java.util.*;
22 import java.io.*;
23 import java.awt.*;
24 import java.awt.event.*;
25 import javax.swing.*;
26 import javax.swing.event.*;
27 import javax.xml.parsers.*;
28 import org.netbeans.modules.j2ee.websphere6.ui.wizard.WSInstantiatingIterator;
29 import org.w3c.dom.*;
30 import org.xml.sax.*;
31 import org.openide.*;
32 import org.openide.util.*;
33 import org.netbeans.modules.j2ee.websphere6.util.WSDebug;
34
35 /**
36  *
37  * @author dlm198383
38  */

39 public class ServerProperties {
40
41     private JComboBox serverTypeCombo;
42     private JComboBox localInstancesCombo;
43     private JTextField domainPathField;
44     private JTextField hostField;
45     private JTextField portField;
46     ServerTypeActionListener serverTypeActionListener=null;
47     InstanceSelectionListener instanceSelectionListener=null;
48     WSInstantiatingIterator instantiatingIterator;
49     
50     /** Creates a new instance of ServerProperties */
51     public ServerProperties() {
52         serverTypeCombo=null;
53         localInstancesCombo=null;
54         domainPathField=null;
55         hostField=null;
56         portField=null;
57     }
58     /** Creates a new instance of ServerProperties */
59     public ServerProperties(JComboBox serverCombobox,
60             JComboBox localInstancesCombobox,
61             JTextField domainPathField,
62             JTextField hostField,
63             JTextField portField) {
64         
65         
66         this.serverTypeCombo=serverCombobox;
67         this.localInstancesCombo=localInstancesCombobox;
68         this.domainPathField=domainPathField;
69         this.hostField=hostField;
70         this.portField=portField;
71         
72     }
73     public void setVariables(JComboBox serverCombobox,
74             JComboBox localInstancesCombobox,
75             JTextField domainPathField,
76             JTextField hostField,
77             JTextField portField,
78             WSInstantiatingIterator instantiatingIterator) {
79         
80         
81         if(this.serverTypeCombo==null) this.serverTypeCombo=serverCombobox;
82         if(this.localInstancesCombo==null) this.localInstancesCombo=localInstancesCombobox;
83         if(this.domainPathField==null) this.domainPathField=domainPathField;
84         if(this.hostField==null) this.hostField=hostField;
85         if(this.portField==null) this.portField=portField;
86         if(this.instantiatingIterator==null) this.instantiatingIterator=instantiatingIterator;
87     }
88     
89     /**
90      * Gets the list of registered domains according to the given server
91      * installation root
92      *
93      * @param serverRoot the server's installation location
94      *
95      * @return an array if strings with the domains' paths
96      */

97     public static String JavaDoc[] getRegisteredDomains(String JavaDoc serverRoot) {
98         // init the resulting vector
99
Vector result = new Vector();
100         
101         // is the server root was not defined, return an empty array of domains
102
if (serverRoot == null) {
103             return new String JavaDoc[0];
104         }
105         
106         // the relative path to the domains list file
107
String JavaDoc domainListFile = "/properties/profileRegistry.xml"; // NOI18N
108

109         // init the input stream for the file and the w3c document object
110
InputStream inputStream = null;
111         Document document = null;
112         
113         try {
114             // open the stream to the domains list file
115
inputStream = new FileInputStream(new File(serverRoot +
116                     domainListFile));
117             
118             // create a document from the input stream
119
document = DocumentBuilderFactory.newInstance().
120                     newDocumentBuilder().parse(inputStream);
121             
122             // get the root element
123
Element root = document.getDocumentElement();
124             
125             // get its children
126
NodeList children = root.getChildNodes();
127             
128             // for each child
129
for (int i = 0; i < children.getLength(); i++) {
130                 Node child = children.item(i);
131                 // if the child's name equals 'profile' add its 'path' attribute
132
// to the resulting vector
133
if (child.getNodeName().equals("profile")) { // NOI18N
134
String JavaDoc path = child.getAttributes().
135                             getNamedItem("path").getNodeValue(); // NOI18N
136
result.add(path);
137                 }
138             }
139         } catch (FileNotFoundException e) {
140             ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, e);
141         } catch (ParserConfigurationException e) {
142             ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, e);
143         } catch (SAXException e) {
144             ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, e);
145         } catch (IOException e) {
146             ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, e);
147         } finally {
148             // close the input stream
149
try {
150                 if (inputStream != null) {
151                     inputStream.close();
152                 }
153             } catch (IOException e) {
154                 ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, e);
155             }
156         }
157         
158         // convert the vector to an array and return
159
return (String JavaDoc[]) result.toArray(new String JavaDoc[result.size()]);
160     }
161     /**
162      * Gets the port for a given cell basing on the cell's root directory.
163      *
164      * @param cellPath the root directory of the cell
165      *
166      * @return the cell's port
167      */

168     
169     public static String JavaDoc getCellPort(String JavaDoc cellPath) {
170         // get the list of files under the nodes subfolder
171
String JavaDoc[] files = new File(cellPath + "/nodes").list();
172         
173         // for each file check whether it is a directory and there exists
174
// serverindex.xml, if it does, remember the path and break the loop
175
for (int i = 0; i < files.length; i++) {
176             String JavaDoc path = cellPath + "/nodes/" + files[i] + "/serverindex.xml";
177             if (new File(path).exists()) { // NOI18N
178
cellPath = path; // NOI18N
179
break;
180             }
181         }
182         
183         // init the input stream for the file and the w3c document object
184
InputStream inputStream = null;
185         Document document = null;
186         
187         try {
188             // open the stream to the cell properties file
189
inputStream = new FileInputStream(new File(cellPath));
190             
191             // create a document from the input stream
192
document = DocumentBuilderFactory.newInstance().
193                     newDocumentBuilder().parse(inputStream);
194             
195             // get the root element
196
Element root = document.getDocumentElement();
197             
198             // get the child nodes
199
NodeList children = root.getChildNodes();
200             
201             // for each child
202
for (int i = 0; i < children.getLength(); i++) {
203                 Node child = children.item(i);
204                 // if the child's name equals 'serverEntries' get its children
205
// and iterate over them
206
if (child.getNodeName().equals("serverEntries")) { // NOI18N
207
NodeList nl = child.getChildNodes();
208                     for (int j = 0; j < nl.getLength(); j++){
209                         Node ch = nl.item(j);
210                         // if the grandchild's name equals specialEndpoints, and
211
// it has the SOAP_CONNECTOR_ADDRESS attribute
212
if (ch.getNodeName().equals(
213                                 "specialEndpoints") && ch. // NOI18N
214
getAttributes().getNamedItem
215                                 ("endPointName").getNodeValue(). // NOI18N
216
equals("SOAP_CONNECTOR_ADDRESS")) { // NOI18N
217
NodeList nl2 = ch.getChildNodes();
218                             // iterate over its children (the
219
// grandgrandchildren of the root node) and get the
220
// one the the name 'endPoint', from it get the
221
// port attribute
222
for (int k = 0; k < nl2.getLength(); k++) {
223                                 Node ch2 = nl2.item(k);
224                                 if (ch2.getNodeName().equals(
225                                         "endPoint")) { // NOI18N
226
String JavaDoc port = ch2.getAttributes().
227                                             getNamedItem("port"). // NOI18N
228
getNodeValue();
229                                     return port;
230                                 }
231                             }
232                         }
233                     }
234                 }
235             }
236         } catch (FileNotFoundException e) {
237             ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, e);
238         } catch (ParserConfigurationException e) {
239             ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, e);
240         } catch (SAXException e) {
241             ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, e);
242         } catch (IOException e) {
243             ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, e);
244         } finally {
245             // close the input stream
246
try {
247                 if (inputStream != null) {
248                     inputStream.close();
249                 }
250             } catch (IOException e) {
251                 ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, e);
252             }
253         }
254         
255         // if nothing is found - return an empty string
256
return ""; // NOI18N
257

258     }
259     
260     public static String JavaDoc getCellAdminPort(String JavaDoc cellPath) {
261         // get the list of files under the nodes subfolder
262
String JavaDoc[] files = new File(cellPath + "/nodes").list();
263         
264         // for each file check whether it is a directory and there exists
265
// serverindex.xml, if it does, remember the path and break the loop
266
for (int i = 0; i < files.length; i++) {
267             String JavaDoc path = cellPath + "/nodes/" + files[i] + "/serverindex.xml";
268             if (new File(path).exists()) { // NOI18N
269
cellPath = path; // NOI18N
270
break;
271             }
272         }
273         
274         // init the input stream for the file and the w3c document object
275
InputStream inputStream = null;
276         Document document = null;
277         
278         try {
279             // open the stream to the cell properties file
280
inputStream = new FileInputStream(new File(cellPath));
281             
282             // create a document from the input stream
283
document = DocumentBuilderFactory.newInstance().
284                     newDocumentBuilder().parse(inputStream);
285             
286             // get the root element
287
Element root = document.getDocumentElement();
288             
289             // get the child nodes
290
NodeList children = root.getChildNodes();
291             
292             // for each child
293
for (int i = 0; i < children.getLength(); i++) {
294                 Node child = children.item(i);
295                 // if the child's name equals 'serverEntries' get its children
296
// and iterate over them
297
if (child.getNodeName().equals("serverEntries")) { // NOI18N
298
NodeList nl = child.getChildNodes();
299                     for (int j = 0; j < nl.getLength(); j++){
300                         Node ch = nl.item(j);
301                         // if the grandchild's name equals specialEndpoints, and
302
// it has the SOAP_CONNECTOR_ADDRESS attribute
303
if (ch.getNodeName().equals(
304                                 "specialEndpoints") && ch. // NOI18N
305
getAttributes().getNamedItem
306                                 ("endPointName").getNodeValue(). // NOI18N
307
equals("WC_adminhost")) { // NOI18N
308
NodeList nl2 = ch.getChildNodes();
309                             // iterate over its children (the
310
// grandgrandchildren of the root node) and get the
311
// one the the name 'endPoint', from it get the
312
// port attribute
313
for (int k = 0; k < nl2.getLength(); k++) {
314                                 Node ch2 = nl2.item(k);
315                                 if (ch2.getNodeName().equals(
316                                         "endPoint")) { // NOI18N
317
String JavaDoc port = ch2.getAttributes().
318                                             getNamedItem("port"). // NOI18N
319
getNodeValue();
320                                     return port;
321                                 }
322                             }
323                         }
324                     }
325                 }
326             }
327         } catch (FileNotFoundException e) {
328             ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, e);
329         } catch (ParserConfigurationException e) {
330             ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, e);
331         } catch (SAXException e) {
332             ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, e);
333         } catch (IOException e) {
334             ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, e);
335         } finally {
336             // close the input stream
337
try {
338                 if (inputStream != null) {
339                     inputStream.close();
340                 }
341             } catch (IOException e) {
342                 ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, e);
343             }
344         }
345         
346         // if nothing is found - return an empty string
347
return ""; // NOI18N
348

349     }
350      public static String JavaDoc getCellDefaultHostPort(String JavaDoc cellPath) {
351         // get the list of files under the nodes subfolder
352
String JavaDoc[] files = new File(cellPath + "/nodes").list();
353         
354         // for each file check whether it is a directory and there exists
355
// serverindex.xml, if it does, remember the path and break the loop
356
for (int i = 0; i < files.length; i++) {
357             String JavaDoc path = cellPath + "/nodes/" + files[i] + "/serverindex.xml";
358             if (new File(path).exists()) { // NOI18N
359
cellPath = path; // NOI18N
360
break;
361             }
362         }
363         
364         // init the input stream for the file and the w3c document object
365
InputStream inputStream = null;
366         Document document = null;
367         
368         try {
369             // open the stream to the cell properties file
370
inputStream = new FileInputStream(new File(cellPath));
371             
372             // create a document from the input stream
373
document = DocumentBuilderFactory.newInstance().
374                     newDocumentBuilder().parse(inputStream);
375             
376             // get the root element
377
Element root = document.getDocumentElement();
378             
379             // get the child nodes
380
NodeList children = root.getChildNodes();
381             
382             // for each child
383
for (int i = 0; i < children.getLength(); i++) {
384                 Node child = children.item(i);
385                 // if the child's name equals 'serverEntries' get its children
386
// and iterate over them
387
if (child.getNodeName().equals("serverEntries")) { // NOI18N
388
NodeList nl = child.getChildNodes();
389                     for (int j = 0; j < nl.getLength(); j++){
390                         Node ch = nl.item(j);
391                         // if the grandchild's name equals specialEndpoints, and
392
// it has the SOAP_CONNECTOR_ADDRESS attribute
393
if (ch.getNodeName().equals(
394                                 "specialEndpoints") && ch. // NOI18N
395
getAttributes().getNamedItem
396                                 ("endPointName").getNodeValue(). // NOI18N
397
equals("WC_defaulthost")) { // NOI18N
398
NodeList nl2 = ch.getChildNodes();
399                             // iterate over its children (the
400
// grandgrandchildren of the root node) and get the
401
// one the the name 'endPoint', from it get the
402
// port attribute
403
for (int k = 0; k < nl2.getLength(); k++) {
404                                 Node ch2 = nl2.item(k);
405                                 if (ch2.getNodeName().equals(
406                                         "endPoint")) { // NOI18N
407
String JavaDoc port = ch2.getAttributes().
408                                             getNamedItem("port"). // NOI18N
409
getNodeValue();
410                                     return port;
411                                 }
412                             }
413                         }
414                     }
415                 }
416             }
417         } catch (FileNotFoundException e) {
418             ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, e);
419         } catch (ParserConfigurationException e) {
420             ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, e);
421         } catch (SAXException e) {
422             ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, e);
423         } catch (IOException e) {
424             ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, e);
425         } finally {
426             // close the input stream
427
try {
428                 if (inputStream != null) {
429                     inputStream.close();
430                 }
431             } catch (IOException e) {
432                 ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, e);
433             }
434         }
435         
436         // if nothing is found - return an empty string
437
return ""; // NOI18N
438

439     }
440     
441     public static String JavaDoc getCellHttpPort(String JavaDoc cellPath) {
442         // get the list of files under the nodes subfolder
443
String JavaDoc[] files = new File(cellPath + "/nodes").list();
444         
445         // for each file check whether it is a directory and there exists
446
// serverindex.xml, if it does, remember the path and break the loop
447
for (int i = 0; i < files.length; i++) {
448             String JavaDoc path = cellPath + "/nodes/" + files[i] + "/serverindex.xml";
449             if (new File(path).exists()) { // NOI18N
450
cellPath = path; // NOI18N
451
break;
452             }
453         }
454         
455         // init the input stream for the file and the w3c document object
456
InputStream inputStream = null;
457         Document document = null;
458         
459         try {
460             // open the stream to the cell properties file
461
inputStream = new FileInputStream(new File(cellPath));
462             
463             // create a document from the input stream
464
document = DocumentBuilderFactory.newInstance().
465                     newDocumentBuilder().parse(inputStream);
466             
467             // get the root element
468
Element root = document.getDocumentElement();
469             
470             // get the child nodes
471
NodeList children = root.getChildNodes();
472             
473             // for each child
474
for (int i = 0; i < children.getLength(); i++) {
475                 Node child = children.item(i);
476                 // if the child's name equals 'serverEntries' get its children
477
// and iterate over them
478
if (child.getNodeName().equals("serverEntries")) { // NOI18N
479
NodeList nl = child.getChildNodes();
480                     for (int j = 0; j < nl.getLength(); j++){
481                         Node ch = nl.item(j);
482                         // if the grandchild's name equals specialEndpoints, and
483
// it has the SOAP_CONNECTOR_ADDRESS attribute
484
if (ch.getNodeName().equals(
485                                 "specialEndpoints") && ch. // NOI18N
486
getAttributes().getNamedItem
487                                 ("endPointName").getNodeValue(). // NOI18N
488
equals("WC_defaulthost")) { // NOI18N
489
NodeList nl2 = ch.getChildNodes();
490                             // iterate over its children (the
491
// grandgrandchildren of the root node) and get the
492
// one the the name 'endPoint', from it get the
493
// port attribute
494
for (int k = 0; k < nl2.getLength(); k++) {
495                                 Node ch2 = nl2.item(k);
496                                 if (ch2.getNodeName().equals(
497                                         "endPoint")) { // NOI18N
498
String JavaDoc port = ch2.getAttributes().
499                                             getNamedItem("port"). // NOI18N
500
getNodeValue();
501                                     return port;
502                                 }
503                             }
504                         }
505                     }
506                 }
507             }
508         } catch (FileNotFoundException e) {
509             ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, e);
510         } catch (ParserConfigurationException e) {
511             ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, e);
512         } catch (SAXException e) {
513             ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, e);
514         } catch (IOException e) {
515             ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, e);
516         } finally {
517             // close the input stream
518
try {
519                 if (inputStream != null) {
520                     inputStream.close();
521                 }
522             } catch (IOException e) {
523                 ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, e);
524             }
525         }
526         
527         // if nothing is found - return an empty string
528
return ""; // NOI18N
529

530     }
531     /**
532      * Gets the path to the server's server.xml file
533      *
534      * @param cellPath the root directory of the cell
535      *
536      * @return the path to the cell's server.xml
537      */

538     public static String JavaDoc getConfigXmlPath(String JavaDoc cellPath) {
539         // get the list of files under the nodes subfolder
540
String JavaDoc[] files = new File(cellPath + "/nodes").list(); // NOI18N
541

542         // get the server name
543
String JavaDoc serverName = getServerName(cellPath);
544         
545         // for each file check whether it is a directory and there exists
546
// serverindex.xml, if it does, remember the path and break the loop
547
for (int i = 0; i < files.length; i++) {
548             String JavaDoc path = cellPath + "/nodes/" + files[i] + // NOI18N
549
"/servers/" + serverName + "/server.xml"; // NOI18N
550
if (new File(path).exists()) {
551                 if (WSDebug.isEnabled())
552                     WSDebug.notify(path);
553                 return path;
554             }
555         }
556         
557         return "";
558     }
559     
560     /**
561      * Gets the server's name for a given cell basing on the cell's root
562      * directory.
563      *
564      * @param cellPath the root directory of the cell
565      *
566      * @return the server's name
567      */

568     public static String JavaDoc getServerName(String JavaDoc cellPath) {
569         // get the list of files under the nodes subfolder
570
String JavaDoc[] files = new File(cellPath + "/nodes").list(); // NOI18N
571

572         // for each file check whether it is a directory and there exists
573
// serverindex.xml, if it does, remember the path and break the loop
574
for (int i = 0; i < files.length; i++) {
575             String JavaDoc path = cellPath + "/nodes/" + files[i] + // NOI18N
576
"/serverindex.xml"; // NOI18N
577
if (new File(path).exists()) {
578                 cellPath = path; // NOI18N
579
break;
580             }
581         }
582         
583         // init the input stream for the file and the w3c document object
584
InputStream inputStream = null;
585         Document document = null;
586         
587         try {
588             inputStream = new FileInputStream(new File(cellPath));
589             document = DocumentBuilderFactory.newInstance().
590                     newDocumentBuilder().parse(inputStream);
591             
592             // get the root element
593
Element root = document.getDocumentElement();
594             
595             // get the child nodes
596
NodeList children = root.getChildNodes();
597             
598             for (int i = 0; i < children.getLength(); i++) {
599                 // if the child's name equals 'serverEntries' get its children
600
// and iterate over them
601
Node child = children.item(i);
602                 
603                 // if the child's name is serverEntries, get its serverName
604
// attribute
605
if (child.getNodeName().equals("serverEntries")) { // NOI18N
606
return child.getAttributes().getNamedItem(
607                             "serverName").getNodeValue(); // NOI18N
608
}
609             }
610         } catch (FileNotFoundException e) {
611             ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, e);
612         } catch (ParserConfigurationException e) {
613             ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, e);
614         } catch (SAXException e) {
615             ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, e);
616         } catch (IOException e) {
617             ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, e);
618         } finally {
619             // close the input stream
620
try {
621                 if (inputStream != null) {
622                     inputStream.close();
623                 }
624             } catch (IOException e) {
625                 ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, e);
626             }
627         }
628         
629         // if nothing is found - return an empty string
630
return ""; // NOI18N
631
}
632     
633     
634     /**
635      * Gets the list of local server instances.
636      *
637      * @return a vector with the local instances
638      */

639     
640     public static Vector getServerInstances(String JavaDoc serverRoot){
641         // initialize the resulting vector
642
Vector result = new Vector();
643         
644         // get the list of registered profiles
645
String JavaDoc[] domains = ServerProperties.getRegisteredDomains(
646                 serverRoot);
647         
648         // for each domain get the list of cells
649
for (int i = 0; i < domains.length; i++) {
650             // get the cells root directory
651
File file = new File(domains[i] + "/config/cells"); // NOI18N
652

653             // get the cells directories list
654
String JavaDoc[] files = file.list(new DirectoryFilter());
655             
656             // for each cell get all the required information and add to the
657
// resulting vector
658
for (int j = 0; j < files.length; j++){
659                 String JavaDoc nextCellPath = file.getAbsolutePath() + File.separator +
660                         files[j];
661                 String JavaDoc address = "localhost"; // NOI18N
662
String JavaDoc port = ServerProperties.getCellPort(nextCellPath);
663                 String JavaDoc adminPort = ServerProperties.getCellAdminPort(nextCellPath);
664                 String JavaDoc httpPort = ServerProperties.getCellAdminPort(nextCellPath);
665                 String JavaDoc serverName = ServerProperties.getServerName(nextCellPath);
666                 String JavaDoc configXmlPath = ServerProperties.getConfigXmlPath(nextCellPath);
667                 String JavaDoc defaultHostPort = ServerProperties.getCellDefaultHostPort(nextCellPath);
668                 result.add(new Instance(serverName, address, port, domains[i],
669                         configXmlPath, adminPort,httpPort,defaultHostPort));
670             }
671         }
672         
673         // return the vector
674
return result;
675     }
676     /**
677      * Checks whether the specified path is the valid domain root directory.
678      *
679      * @return true if the path is the valid domain root, false otherwise
680      */

681     public static boolean isValidDomainRoot(String JavaDoc path) {
682         // set the child directories/files that should be present and validate
683
// the directory as the domain root
684
String JavaDoc[] children = {
685             "config/cells", // NOI18N
686
"etc/ws-security", // NOI18N
687
"properties/soap.client.props", // NOI18N
688
"properties/wsadmin.properties", // NOI18N
689
};
690         return ServerProperties.hasChildren(path, children);
691     }
692     
693     /**
694      * Checks whether the supplied directory has the required children
695      *
696      * @return true if the directory contains all the children, false otherwise
697      */

698     public static boolean hasChildren(String JavaDoc parent, String JavaDoc[] children) {
699         // if parent is null, it cannot contain any children
700
if (parent == null) {
701             return false;
702         }
703         
704         // if the children array is null, then the condition is fullfilled
705
if (children == null) {
706             return true;
707         }
708         
709         // for each child check whether it is contained and if it is not,
710
// return false
711
for (int i = 0; i < children.length; i++) {
712             if (!(new File(parent + File.separator + children[i]).exists())) {
713                 return false;
714             }
715         }
716         
717         // all is good
718
return true;
719     }
720     
721     
722     
723     
724     
725     
726     /**
727      * An extension of the FileNameFilter class that is setup to accept only
728      * directories.
729      *
730      * @author Kirill Sorokin
731      */

732     
733     private static class DirectoryFilter implements FilenameFilter {
734         /**
735          * This method is called when it is needed to decide whether a chosen
736          * file meets the filter's requirements
737          *
738          * @return true if the file meets the requirements, false otherwise
739          */

740         public boolean accept(File dir, String JavaDoc name) {
741             // if the file exists and it's a directory - accept it
742
if ((new File(dir.getAbsolutePath()+File.separator+name)).
743                     isDirectory()) {
744                 return true;
745             }
746             
747             // in all other cases - refuse
748
return false;
749         }
750     }
751     /**
752      * A listener that reacts to the change of the server type combobox,
753      * is the local server type is selected we should disable several fields
754      * and enable some others instead.
755      *
756      * @author Kirill Sorokin
757      */

758     public class ServerTypeActionListener implements ActionListener {
759         /**
760          * The main action handler. This method is called when the combobox
761          * value changes
762          */

763         
764         public void actionPerformed(ActionEvent e) {
765             // if the selected type is local
766
if (serverTypeCombo.getSelectedItem().equals(NbBundle.
767                     getMessage(ServerProperties.class,
768                     "TXT_ServerTypeLocal"))) { // NOI18N
769
Instance instance = (Instance) localInstancesCombo.
770                         getSelectedItem();
771                 
772                 // enable the local instances combo
773
localInstancesCombo.setEnabled(true);
774                 
775                 // enable and set as read-only the domain path field
776
domainPathField.setEnabled(true);
777                 domainPathField.setEditable(false);
778                 
779                 // enable and set as read-only the host field
780
hostField.setEnabled(true);
781                 hostField.setEditable(false);
782                 hostField.setText(instance.getHost());
783                 
784                 // enable and set as read-only the port field
785
//portField.setEnabled(true);
786
portField.setEnabled(true);
787                 portField.setEditable(false);
788                 //portField.setValue(new Integer(instance.getPort()));
789
portField.setText(instance.getPort());
790             } else {
791                 // disable the local instances combo
792
localInstancesCombo.setEnabled(false);
793                 
794                 // disable the domain path field
795
domainPathField.setEnabled(false);
796                 domainPathField.setEditable(false);
797                 
798                 // enable and set as read-write the host field
799
hostField.setEnabled(true);
800                 hostField.setEditable(true);
801                 
802                 // enable and set as read-write the port field
803
portField.setEnabled(true);
804                 portField.setEditable(true);
805             }
806         }
807     }
808     public ServerTypeActionListener getServerTypeActionListener() {
809         if(serverTypeActionListener==null) {
810             serverTypeActionListener=new ServerTypeActionListener();
811         }
812         
813         return serverTypeActionListener;
814     }
815     ////////////////////////////////////////////////////////////////////////////
816
// Listeners section
817
////////////////////////////////////////////////////////////////////////////
818
/**
819      * The registrered listeners vector
820      */

821     private Vector listeners = new Vector();
822     
823     /**
824      * Removes a registered listener
825      *
826      * @param listener the listener to be removed
827      */

828     public void removeChangeListener(ChangeListener listener) {
829         if (listeners != null) {
830             synchronized (listeners) {
831                 listeners.remove(listener);
832             }
833         }
834     }
835     
836     /**
837      * Adds a listener
838      *
839      * @param listener the listener to be added
840      */

841     public void addChangeListener(ChangeListener listener) {
842         synchronized (listeners) {
843             listeners.add(listener);
844         }
845     }
846     
847     /**
848      * Fires a change event originating from this panel
849      */

850     private void fireChangeEvent() {
851         ChangeEvent event = new ChangeEvent(this);
852         fireChangeEvent(event);
853     }
854     
855     /**
856      * Fires a custom change event
857      *
858      * @param event the event
859      */

860     private void fireChangeEvent(ChangeEvent event) {
861         Vector targetListeners;
862         synchronized (listeners) {
863             targetListeners = (Vector) listeners.clone();
864         }
865         
866         for (int i = 0; i < targetListeners.size(); i++) {
867             ChangeListener listener =
868                     (ChangeListener) targetListeners.elementAt(i);
869             listener.stateChanged(event);
870         }
871     }
872     ////////////////////////////////////////////////////////////////////////////
873
// Inner classes
874
////////////////////////////////////////////////////////////////////////////
875
/**
876      * Simple key listener that delegates the event to its parent's listeners
877      *
878      * @author Kirill Sorokin
879      */

880     public class KeyListener extends KeyAdapter {
881         /**
882          * This method is called when a user presses a key on the keyboard
883          */

884         public void keyTyped(KeyEvent event) {
885             fireChangeEvent();
886         }
887         
888         /**
889          * This method is called when a user releases a key on the keyboard
890          */

891         public void keyReleased(KeyEvent event) {
892             fireChangeEvent();
893         }
894     }
895     
896     
897     /**
898      * Updates the local instances combobox model with the fresh local
899      * instances list
900      */

901     public void updateInstancesList(String JavaDoc serverRoot) {
902         localInstancesCombo.setModel(
903                 new InstancesModel(
904                 getServerInstances(serverRoot)));
905         
906         updateInstanceInfo();
907     }
908     
909     /**
910      * Updates the selected local instance information, i.e. profile path,
911      * host, port.
912      */

913     private void updateInstanceInfo() {
914         // get the selected local instance
915
Instance instance = (Instance) localInstancesCombo.getSelectedItem();
916         
917         // set the fields' values
918
domainPathField.setText(instance.getDomainPath());
919         hostField.setText(instance.getHost());
920         //portField.setValue(new Integer(instance.getPort()));
921
portField.setText(instance.getPort());
922         if(instantiatingIterator!=null) {
923             instantiatingIterator.setHost(instance.getHost());
924             instantiatingIterator.setPort(instance.getPort());
925             instantiatingIterator.setAdminPort(instance.getAdminPort());
926             instantiatingIterator.setConfigXmlPath(instance.getConfigXmlPath());
927             instantiatingIterator.setDefaultHostPort(instance.getDefaultHostPort());
928             instantiatingIterator.setDomainRoot(instance.getDomainPath());
929             instantiatingIterator.setServerName(instance.getName());
930         }
931     }
932     /**
933      * A simple listeners that reacts to user's selectin a local instance. It
934      * updates the selected instance info.
935      *
936      * @author Kirill Sorokin
937      */

938     public class InstanceSelectionListener implements ActionListener {
939         /**
940          * The main action handler. This method is called when a new local
941          * instance is selected
942          */

943         public void actionPerformed(ActionEvent e) {
944             updateInstanceInfo();
945         }
946     }
947     /**
948      * Create new or get existing InstanceSelectionListener
949      */

950     public InstanceSelectionListener getInstanceSelectionListener() {
951         if(instanceSelectionListener==null) {
952             instanceSelectionListener=new InstanceSelectionListener();
953         }
954         return instanceSelectionListener;
955     }
956 }
957
958
Popular Tags