KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > tools > upgrade > cluster > LBInfo


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  * LBInfo.java
26  *
27  * Created on June 21, 2004, 4:52 PM
28  */

29
30 package com.sun.enterprise.tools.upgrade.cluster;
31
32 /**
33  * This class represents Loadbalancer.xml file
34  * @author prakash
35  */

36 import java.util.*;
37 import java.io.File JavaDoc;
38 import java.io.IOException JavaDoc;
39
40 import javax.xml.parsers.DocumentBuilder JavaDoc;
41 import javax.xml.parsers.DocumentBuilderFactory JavaDoc;
42 import javax.xml.parsers.FactoryConfigurationError JavaDoc;
43 import javax.xml.parsers.ParserConfigurationException JavaDoc;
44
45 import org.xml.sax.SAXException JavaDoc;
46 import org.xml.sax.SAXParseException JavaDoc;
47
48 import org.w3c.dom.Document JavaDoc;
49 import org.w3c.dom.DOMException JavaDoc;
50 import org.w3c.dom.Element JavaDoc;
51 import org.w3c.dom.Node JavaDoc;
52 import org.w3c.dom.NodeList JavaDoc;
53 import com.sun.enterprise.util.i18n.StringManager;
54
55 public class LBInfo {
56     
57     private List JavaDoc clusters;
58     private Properties lbProperties;
59     private static java.util.logging.Logger JavaDoc log = com.sun.enterprise.tools.upgrade.common.CommonInfoModel.getDefaultLogger();
60     private StringManager stringManager = StringManager.getManager("com.sun.enterprise.tools.upgrade.gui");
61
62     /** Creates a new instance of LBInfo */
63     public LBInfo() {
64         clusters = new ArrayList();
65         lbProperties = new Properties();
66     }
67     public boolean processLoadBalancerFile(String JavaDoc lbFile){
68         DocumentBuilderFactory JavaDoc factory = DocumentBuilderFactory.newInstance();
69         //factory.setValidating(false);
70
factory.setNamespaceAware(true);
71         try {
72            DocumentBuilder JavaDoc builder = factory.newDocumentBuilder();
73            DocumentBuilder JavaDoc builderDomainXml = factory.newDocumentBuilder();
74            builderDomainXml.setEntityResolver((org.xml.sax.helpers.DefaultHandler JavaDoc)Class.forName
75                 ("com.sun.enterprise.config.serverbeans.ServerValidationHandler").newInstance());
76            Element JavaDoc docEle = builderDomainXml.parse(new File JavaDoc(lbFile)).getDocumentElement();
77            NodeList JavaDoc clEles = docEle.getElementsByTagName("cluster");
78            for(int lh =0; lh < clEles.getLength(); lh++){
79                clusters.add(new LBCluster((Element JavaDoc)clEles.item(lh)));
80            }
81            NodeList JavaDoc propEles = docEle.getElementsByTagName("cluster");
82            for(int ph =0; ph < propEles.getLength(); ph++){
83                Element JavaDoc propsEle = (Element JavaDoc)propEles.item(ph);
84                lbProperties.setProperty(propsEle.getAttribute("name"),propsEle.getAttribute("value"));
85            }
86         }catch (Exception JavaDoc ex){
87             log.severe(stringManager.getString("upgrade.transform.startFailureMessage", ex.getMessage()));
88             log.severe(stringManager.getString("upgrade.transform.startFailureCheckAccessMessage"));
89             //ex.printStackTrace();
90
return false;
91         }
92         return true;
93     }
94     public java.util.List JavaDoc getClusters() {
95         return clusters;
96     }
97     public java.util.Properties JavaDoc getLbProperties() {
98         return lbProperties;
99     }
100     
101 }
102
Popular Tags