1 23 24 33 34 35 36 package com.sun.enterprise.tools.upgrade.common; 37 38 39 40 47 48 import java.net.URL ; 49 50 import java.io.*; 51 52 import java.util.*; 53 54 import java.util.logging.*; 55 56 import java.net.URLClassLoader ; 57 58 import java.lang.reflect.*; 59 60 import java.util.Hashtable ; 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 classLoader; 79 80 private Class domainRegistryClass; 81 82 private Object domainRegistryObject; 83 84 private static final String ASADMINUNIX = "asadmin"; 85 86 private static final String ASADMINWIN = "asadmin.bat"; 87 88 private static final String BIN = "bin"; 89 90 91 92 public Appserver70DomainNamesResolver(String appserverRoot) { 93 94 try{ 95 96 File jarFile = new File(appserverRoot+File.separator+"lib"+File.separator+"appserv-admin.jar"); 97 98 100 102 System.setProperty("com.sun.aas.configRoot", getConfigDir70(appserverRoot)); 103 104 URL [] jars = {jarFile.toURL()}; 105 106 classLoader = new URLClassLoader (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 ex){ 115 116 _logger.log(Level.WARNING,sm.getString("enterprise.tools.upgrade.unknownError"),ex); 117 118 } 119 120 } 121 122 123 124 public Hashtable getDomainNamesPathMapping(){ 125 126 Hashtable mapping = new Hashtable (); 127 128 try{ 129 130 Method iteratorMethod = domainRegistryClass.getMethod("iterator", null); 131 132 java.util.Iterator domainNameIterator = (java.util.Iterator )iteratorMethod.invoke(domainRegistryObject, null); 133 134 for(;domainNameIterator.hasNext();){ 135 136 Object obj = domainNameIterator.next(); 137 138 Method dName = obj.getClass().getMethod("getName",null); 139 140 String name = (String )dName.invoke(obj, null); 141 142 Method dPath = obj.getClass().getMethod("getPath",null); 143 144 String path = (String )dPath.invoke(obj, null); 145 146 148 mapping.put(name, new DomainInfo(name,path)); 149 150 } 151 152 }catch(Exception 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 getConfigDir70(String source) { 165 166 String osName = System.getProperty("os.name"); 167 168 String asenv = null; 169 170 String 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 readString =reader.readLine(); 185 186 while(readString != null) { 187 188 if(readString.indexOf("asenv") != -1) { 189 190 StringTokenizer st = new StringTokenizer(readString); 191 192 194 st.nextToken(); 195 196 String 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 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 227 228 public static void main(String [] args) { 229 230 Appserver70DomainNamesResolver as =new Appserver70DomainNamesResolver(args[0]); 231 232 as.getDomainNamesPathMapping(); 233 234 } 235 236 237 238 } 239 240 | Popular Tags |