KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > tools > upgrade > common > DomainInfo


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  * DomainInfo.java
26  *
27  * Created on April 27, 2004, 3:46 PM
28  */

29
30 package com.sun.enterprise.tools.upgrade.common;
31
32 /**
33  *
34  * @author prakash
35  */

36 import java.util.*;
37 import java.io.*;
38
39 //start CR 6396940
40
import org.w3c.dom.NodeList JavaDoc;
41 import javax.xml.parsers.DocumentBuilder JavaDoc;
42 import org.w3c.dom.Element JavaDoc;
43 import org.w3c.dom.Document JavaDoc;
44 import javax.xml.parsers.DocumentBuilderFactory JavaDoc;
45 //end CR 6396940
46

47 public class DomainInfo {
48     
49     private String JavaDoc domainName;
50     private String JavaDoc domainPath;
51     private List JavaDoc instanceNames;
52     private Hashtable instancePathMapping;
53     
54     //private CommonInfoModel commonInfo;
55
/** Creates a new instance of DomainInfo */
56     public DomainInfo(String JavaDoc dName,String JavaDoc dPath) {
57         this.domainName = dName;
58         this.domainPath = dPath;
59         //this.commonInfo = cInfo;
60
}
61     
62     /** Getter for property domainName.
63      * @return Value of property domainName.
64      *
65      */

66     public java.lang.String JavaDoc getDomainName() {
67         return domainName;
68     }
69     
70     /** Setter for property domainName.
71      * @param domainName New value of property domainName.
72      *
73      */

74     public void setDomainName(java.lang.String JavaDoc domainName) {
75         this.domainName = domainName;
76     }
77     
78     /** Getter for property domainPath.
79      * @return Value of property domainPath.
80      *
81      */

82     public java.lang.String JavaDoc getDomainPath() {
83         return domainPath;
84     }
85     
86     /** Setter for property domainPath.
87      * @param domainPath New value of property domainPath.
88      *
89      */

90     public void setDomainPath(java.lang.String JavaDoc domainPath) {
91         this.domainPath = domainPath;
92     }
93     
94     /** Getter for property instanceNames.
95      * @return Value of property instanceNames.
96      * This method is only for appserver 7
97      */

98     public java.util.List JavaDoc getInstanceNames() {
99         //System.out.println("DomainInfo::getInstanceNames method called. Should be called only for source=7.x");
100
if(this.instanceNames == null){
101             // Only for appserver 7.x
102
// Should I be getting server instance name from server.xml ???????????
103
// The directory name for server instance is the name of server ?????????
104
//if(commonInfo.getSourceVersion().equals(UpgradeConstants.VERSION_7X)){
105
instanceNames = new ArrayList();
106                 instancePathMapping = new Hashtable();
107                 File domainDir = new File(this.domainPath);
108                 String JavaDoc [] instanceDirs = domainDir.list();
109                 for (int i=0 ; i<instanceDirs.length ; i++) {
110                     instanceNames.add(instanceDirs[i]);
111                     String JavaDoc instancePath= this.domainPath + File.separator + instanceDirs[i];
112                     instancePathMapping.put(instanceDirs[i],instancePath);
113                 }
114             //}else{
115
// If it is 8.x should get the server instance names from domain.xml file.
116
// Is it required now? Only required for 8.x SE to 8.x EE upgrade
117
//}
118
}
119         return instanceNames;
120     }
121     
122     public String JavaDoc getInstancePath(String JavaDoc instanceName) {
123         if(this.instancePathMapping == null){
124             this.getInstanceNames();
125         }
126         // if instance path is null or "" return the domain path itself. In case of 8.x PE
127
if(instanceName == null || "".equals(instanceName.trim())){
128             return this.domainPath;
129         }
130         return (String JavaDoc)this.instancePathMapping.get(instanceName);
131     }
132    
133     //start CR 6396940
134
public String JavaDoc getDomainApplicationRoot() {
135         String JavaDoc configFileName = domainPath + File.separator + "config" + File.separator + "domain.xml";
136     String JavaDoc applRoot = null;
137         DocumentBuilderFactory JavaDoc factory = DocumentBuilderFactory.newInstance();
138         factory.setNamespaceAware(true);
139         try {
140             DocumentBuilder JavaDoc builder = factory.newDocumentBuilder();
141             builder.setEntityResolver((org.xml.sax.helpers.DefaultHandler JavaDoc)Class.forName("com.sun.enterprise.config.serverbeans.ServerValidationHandler").newInstance());
142             Document JavaDoc adminServerDoc = builder.parse( new File(configFileName));
143         NodeList JavaDoc domainElements = adminServerDoc.getElementsByTagName("domain");
144         //There is only one domain element
145
Element JavaDoc domainElement = (Element JavaDoc)domainElements.item(0);
146         if(domainElement != null) {
147         String JavaDoc attrValue = domainElement.getAttribute("application-root");
148                 StringTokenizer attrTokens = new StringTokenizer(attrValue, "/");
149         attrTokens.nextToken();
150         applRoot = attrTokens.nextToken();
151         }
152         }catch (Exception JavaDoc ex){
153         }
154         return applRoot;
155     }
156     //end CR 6396940
157
}
158
Popular Tags