KickJava   Java API By Example, From Geeks To Geeks.

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


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  
26  * Appserver70DomainNamesResolver.java
27  
28  *
29  
30  * Created on September 11, 2003, 2:32 PM
31  
32  */

33
34
35
36 package com.sun.enterprise.tools.upgrade.common;
37
38
39
40 /**
41  *
42  *
43  *
44  * @author prakash
45  *
46  */

47
48 import java.net.URL JavaDoc;
49
50 import java.io.*;
51
52 import java.util.*;
53
54 import java.util.logging.*;
55
56 import java.net.URLClassLoader JavaDoc;
57
58 import java.lang.reflect.*;
59
60 import java.util.Hashtable JavaDoc;
61
62 import com.sun.enterprise.tools.upgrade.logging.*;
63
64 import com.sun.enterprise.tools.upgrade.logging.*;
65
66 import com.sun.enterprise.util.i18n.StringManager;
67
68
69
70 public class Appserver70DomainNamesResolver {
71     
72     
73     
74     private static Logger _logger = LogService.getLogger(LogService.UPGRADE_LOGGER);
75     
76     private StringManager sm = StringManager.getManager(LogService.UPGRADE_LOGGER);
77     
78     private URLClassLoader JavaDoc classLoader;
79     
80     private Class JavaDoc domainRegistryClass;
81     
82     private Object JavaDoc domainRegistryObject;
83     
84     private static final String JavaDoc ASADMINUNIX = "asadmin";
85     
86     private static final String JavaDoc ASADMINWIN = "asadmin.bat";
87     
88     private static final String JavaDoc BIN = "bin";
89     
90     /** Creates a new instance of Appserver70DomainNamesResolver */
91     
92     public Appserver70DomainNamesResolver(String JavaDoc appserverRoot) {
93         
94         try{
95             
96             File jarFile = new File(appserverRoot+File.separator+"lib"+File.separator+"appserv-admin.jar");
97             
98             //System.setProperty("com.sun.aas.configRoot", "C:\\Softwares\\Sun\\AppServer7\\config");
99

100             //System.setProperty("com.sun.aas.configRoot", appserverRoot+File.separator+"config");
101

102             System.setProperty("com.sun.aas.configRoot", getConfigDir70(appserverRoot));
103             
104             URL JavaDoc[] jars = {jarFile.toURL()};
105             
106             classLoader = new URLClassLoader JavaDoc(jars,this.getClass().getClassLoader());
107             
108             domainRegistryClass = classLoader.loadClass("com.iplanet.ias.admin.common.domains.registry.DomainRegistry");
109             
110             Method newInstanceMethod = domainRegistryClass.getMethod( "newInstance", null );
111             
112             domainRegistryObject = newInstanceMethod.invoke(null, null);
113             
114         }catch(Exception JavaDoc ex){
115             
116             _logger.log(Level.WARNING,sm.getString("enterprise.tools.upgrade.unknownError"),ex);
117             
118         }
119         
120     }
121     
122     
123     
124     public Hashtable JavaDoc getDomainNamesPathMapping(){
125         
126         Hashtable JavaDoc mapping = new Hashtable JavaDoc();
127         
128         try{
129             
130             Method iteratorMethod = domainRegistryClass.getMethod("iterator", null);
131             
132             java.util.Iterator JavaDoc domainNameIterator = (java.util.Iterator JavaDoc)iteratorMethod.invoke(domainRegistryObject, null);
133             
134             for(;domainNameIterator.hasNext();){
135                 
136                 Object JavaDoc obj = domainNameIterator.next();
137                 
138                 Method dName = obj.getClass().getMethod("getName",null);
139                 
140                 String JavaDoc name = (String JavaDoc)dName.invoke(obj, null);
141                 
142                 Method dPath = obj.getClass().getMethod("getPath",null);
143                 
144                 String JavaDoc path = (String JavaDoc)dPath.invoke(obj, null);
145                 
146                 //dEntry = (com.iplanet.ias.admin.common.domains.registry.DomainEntry)obj;
147

148                 mapping.put(name, new DomainInfo(name,path));
149                 
150             }
151             
152         }catch(Exception JavaDoc ex){
153             
154             _logger.log(Level.WARNING,sm.getString("enterprise.tools.upgrade.unknownError"),ex);
155             
156         }
157         
158         return mapping;
159         
160     }
161     
162     
163     
164     public String JavaDoc getConfigDir70(String JavaDoc source) {
165         
166         String JavaDoc osName = System.getProperty("os.name");
167         
168         String JavaDoc asenv = null;
169         
170         String JavaDoc asadmin = null;
171         
172         if(osName.indexOf("Windows") != -1)
173             
174             asadmin = source + File.separator + BIN + File.separator + ASADMINWIN;
175         
176         else
177             
178             asadmin = source + File.separator + BIN + File.separator + ASADMINUNIX;
179         
180         try {
181             
182             BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(asadmin)));
183             
184             String JavaDoc readString =reader.readLine();
185             
186             while(readString != null) {
187                 
188                 if(readString.indexOf("asenv") != -1) {
189                     
190                     StringTokenizer st = new StringTokenizer(readString);
191                     
192                     //Read String is like . /etc/appserver/asenv.conf
193

194                     st.nextToken();
195                     
196                     String JavaDoc asenvStr = st.nextToken();
197                     
198                     int index = asenvStr.indexOf("asenv");
199                     
200                     asenv = asenvStr.substring(0,index);
201                     
202                     break;
203                     
204                 }
205                 
206                 readString =reader.readLine();
207                 
208             }
209             
210         }catch (Exception JavaDoc e) {
211             
212             _logger.log(Level.WARNING,sm.getString("enterprise.tools.upgrade.unknownError"),e);
213             
214         }
215         
216         return asenv;
217         
218     }
219     
220     
221     
222     /**
223      *
224      * @param args the command line arguments
225      *
226      */

227     
228     public static void main(String JavaDoc[] args) {
229         
230         Appserver70DomainNamesResolver as =new Appserver70DomainNamesResolver(args[0]);
231         
232         as.getDomainNamesPathMapping();
233         
234     }
235     
236     
237     
238 }
239
240
Popular Tags