FileDocCategorySizeDatePackage
Appserver70DomainNamesResolver.javaAPI DocGlassfish v2 API9720Fri May 04 22:35:04 BST 2007com.sun.enterprise.tools.upgrade.common

Appserver70DomainNamesResolver

public class Appserver70DomainNamesResolver extends Object
author
prakash

Fields Summary
private static Logger
_logger
private com.sun.enterprise.util.i18n.StringManager
sm
private URLClassLoader
classLoader
private Class
domainRegistryClass
private Object
domainRegistryObject
private static final String
ASADMINUNIX
private static final String
ASADMINWIN
private static final String
BIN
Constructors Summary
public Appserver70DomainNamesResolver(String appserverRoot)
Creates a new instance of Appserver70DomainNamesResolver

    
           
    
       
        
        try{
            
            File jarFile = new File(appserverRoot+File.separator+"lib"+File.separator+"appserv-admin.jar");
            
            //System.setProperty("com.sun.aas.configRoot", "C:\\Softwares\\Sun\\AppServer7\\config");
            
            //System.setProperty("com.sun.aas.configRoot", appserverRoot+File.separator+"config");
            
            System.setProperty("com.sun.aas.configRoot", getConfigDir70(appserverRoot));
            
            URL[] jars = {jarFile.toURL()};
            
            classLoader = new URLClassLoader(jars,this.getClass().getClassLoader());
            
            domainRegistryClass = classLoader.loadClass("com.iplanet.ias.admin.common.domains.registry.DomainRegistry");
            
            Method newInstanceMethod = domainRegistryClass.getMethod( "newInstance", null );
            
            domainRegistryObject = newInstanceMethod.invoke(null, null);
            
        }catch(Exception ex){
            
            _logger.log(Level.WARNING,sm.getString("enterprise.tools.upgrade.unknownError"),ex);
            
        }
        
    
Methods Summary
public java.lang.StringgetConfigDir70(java.lang.String source)

        
        String osName = System.getProperty("os.name");
        
        String asenv = null;
        
        String asadmin = null;
        
        if(osName.indexOf("Windows") != -1)
            
            asadmin = source + File.separator + BIN + File.separator + ASADMINWIN;
        
        else
            
            asadmin = source + File.separator + BIN + File.separator + ASADMINUNIX;
        
        try {
            
            BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(asadmin)));
            
            String readString =reader.readLine();
            
            while(readString != null) {
                
                if(readString.indexOf("asenv") != -1) {
                    
                    StringTokenizer st = new StringTokenizer(readString);
                    
                    //Read String is like . /etc/appserver/asenv.conf
                    
                    st.nextToken();
                    
                    String asenvStr = st.nextToken();
                    
                    int index = asenvStr.indexOf("asenv");
                    
                    asenv = asenvStr.substring(0,index);
                    
                    break;
                    
                }
                
                readString =reader.readLine();
                
            }
            
        }catch (Exception e) {
            
            _logger.log(Level.WARNING,sm.getString("enterprise.tools.upgrade.unknownError"),e);
            
        }
        
        return asenv;
        
    
public java.util.HashtablegetDomainNamesPathMapping(CommonInfoModel commonInfoModel)

        Hashtable mapping = new Hashtable();
        String profile = UpgradeUtils.getUpgradeUtils(commonInfoModel).getProfileInfoFromSourceInput();	
        try{
            Method iteratorMethod = domainRegistryClass.getMethod("iterator", null);
            java.util.Iterator domainNameIterator = (java.util.Iterator)iteratorMethod.invoke(domainRegistryObject, null);
            for(;domainNameIterator.hasNext();){
                Object obj = domainNameIterator.next();
                Method dName = obj.getClass().getMethod("getName",null);
                String name = (String)dName.invoke(obj, null);
                Method dPath = obj.getClass().getMethod("getPath",null);
                String path = (String)dPath.invoke(obj, null);
                //dEntry = (com.iplanet.ias.admin.common.domains.registry.DomainEntry)obj;
    
                if(commonInfoModel.getSourceVersion().equals(UpgradeConstants.VERSION_7X)) {
                    DomainInfo dInfo = new DomainInfo(name, path, profile);
                    //Retrieve values from commonInfoModel object and set in domainInfo object
                    String dValues = commonInfoModel.getDomValuesFromPasswordFile(name);
                    if(dValues != null && !("".equals(dValues))) {
                        String dAdminUser = dValues.substring(0, dValues.indexOf(";"));
                        String dAdminPassword = dValues.substring(dValues.indexOf(";")+1, dValues.length());
                        dInfo.setDomainAdminUser(dAdminUser);
                        dInfo.setDomainAdminPassword(dAdminPassword);
                    }
                    mapping.put(name, dInfo);
                }
                //mapping.put(name, new DomainInfo(name,path));
            }
        }catch(Exception ex){
            _logger.log(Level.WARNING,sm.getString("enterprise.tools.upgrade.unknownError"),ex);
        }
        return mapping;
    
public java.util.HashtablegetDomainNamesPathMapping()

        
        Hashtable mapping = new Hashtable();
        
        try{
            
            Method iteratorMethod = domainRegistryClass.getMethod("iterator", null);
            
            java.util.Iterator domainNameIterator = (java.util.Iterator)iteratorMethod.invoke(domainRegistryObject, null);
            
            for(;domainNameIterator.hasNext();){
                
                Object obj = domainNameIterator.next();
                
                Method dName = obj.getClass().getMethod("getName",null);
                
                String name = (String)dName.invoke(obj, null);
                
                Method dPath = obj.getClass().getMethod("getPath",null);
                
                String path = (String)dPath.invoke(obj, null);
                
                //dEntry = (com.iplanet.ias.admin.common.domains.registry.DomainEntry)obj;
                                
                mapping.put(name, new DomainInfo(name,path));
                
            }
            
        }catch(Exception ex){
            
            _logger.log(Level.WARNING,sm.getString("enterprise.tools.upgrade.unknownError"),ex);
            
        }
        
        return mapping;
        
    
public static voidmain(java.lang.String[] args)

param
args the command line arguments

        
        Appserver70DomainNamesResolver as =new Appserver70DomainNamesResolver(args[0]);
        
        as.getDomainNamesPathMapping();