FileDocCategorySizeDatePackage
PEDomainsManager.javaAPI DocGlassfish v2 API30445Mon Jul 30 15:00:38 BST 2007com.sun.enterprise.admin.servermgmt.pe

PEDomainsManager

public class PEDomainsManager extends com.sun.enterprise.admin.servermgmt.RepositoryManager implements com.sun.enterprise.admin.servermgmt.DomainsManager

Fields Summary
private static final com.sun.enterprise.util.i18n.StringManager
strMgr
i18n strings manager object
private static final String
NAME_DELIMITER
public static final String
PROFILEPROPERTY_DOMAINXML_STYLESHEETS
public static final String
PROFILEPROPERTY_DOMAINXML_TOKENVALUES
Constructors Summary
public PEDomainsManager()

    /* These properties are public interfaces, handle with care */
    
     
    
        super();
    
Methods Summary
private static voidaddTokenValuesIfAny(com.sun.enterprise.admin.util.TokenValueSet tokens, PEFileLayout layout, java.lang.String profileName, java.lang.String propName)

        final File propsFile      = layout.getProfilePropertiesFile(profileName);
        final String tvsAsString  = readProfilePropertyValue(propsFile, propName);
        final Set<TokenValue> tvs = s2TV(tvsAsString);
        tokens.addAll(tvs);
    
public voidchangeMasterPassword(com.sun.enterprise.admin.servermgmt.DomainConfig config)
Changes the master password for the domain

                                      
        try {
            //Ensure that the entity is stopped
            final int status = getInstancesManager(config).getInstanceStatus();
            if (status != Status.kInstanceNotRunningCode) {
                throw new DomainException(
                    strMgr.getString("cannotChangePassword_invalidState",
                        config.getDisplayName(), Status.getStatusString(status)));
            }
        
            String oldPass = getMasterPasswordClear(config);
            String newPass = getNewMasterPasswordClear(config);                        
            
            //Change the password of the keystore alias file
            changePasswordAliasKeystorePassword(config, oldPass, newPass);
            
            //Change the password of the keystore and truststore
            changeSSLCertificateDatabasePassword(config, oldPass, newPass);

            //Change the password in the masterpassword file or delete the file if it is 
            //not to be saved.
            changeMasterPasswordInMasterPasswordFile(config, newPass, saveMasterPassword(config));
        } catch (Exception ex) {
            throw new DomainException(
                strMgr.getString("masterPasswordNotChanged"), ex);
        }
    
protected voidcreateAppClientContainerXml(com.sun.enterprise.admin.servermgmt.DomainConfig domainConfig)

        try
        {
            final PEFileLayout layout = getFileLayout(domainConfig);
            final File accXmlTemplate = 
                layout.getAppClientContainerXmlTemplate();
            final File accXml = layout.getAppClientContainerXml();
            TokenValueSet tokens = PEAccXmlTokens.getTokenValueSet(domainConfig);
            generateFromTemplate(tokens, accXmlTemplate, accXml);
        }
        catch(Exception e)
        {
            throw new DomainException(strMgr.getString("accXmlNotCreated"), e);
        }
    
protected voidcreateDefaultWebXml(com.sun.enterprise.admin.servermgmt.DomainConfig domainConfig)

        final PEFileLayout layout = getFileLayout(domainConfig);
        final File src = layout.getDefaultWebXmlTemplate();
        final File dest = layout.getDefaultWebXml();
        try
        {
            FileUtils.copy(src, dest);
        }
        catch (IOException ioe)
        {
            throw new DomainException(
                strMgr.getString("defaultWebXmlNotCreated"), ioe);
        }
    
public voidcreateDomain(com.sun.enterprise.admin.servermgmt.DomainConfig domainConfig)

        PEFileLayout layout = getFileLayout(domainConfig);
        
        try {
            new RepositoryNameValidator(strMgr.getString("domainsRoot")).
                    checkValidXmlToken(
                        layout.getRepositoryRootDir().getAbsolutePath());
            layout.createRepositoryRoot();        
            new PEDomainConfigValidator().validate(domainConfig);
            checkRepository(domainConfig, false);
        } catch (Exception ex) {
            throw new DomainException(ex);
        }
        
        try {            
            String masterPassword = getMasterPasswordClear(domainConfig);
            layout.createRepositoryDirectories();
            createDomainXml(domainConfig);
            createDomainXmlEvents(domainConfig);
            createScripts(domainConfig);
            createServerPolicyFile(domainConfig);
            createAdminKeyFile(domainConfig, getDomainUser(domainConfig), 
                getDomainPasswordClear(domainConfig));
            createKeyFile(domainConfig, getDomainUser(domainConfig),
                getDomainPasswordClear(domainConfig));
            createAppClientContainerXml(domainConfig);
            createIndexFile(domainConfig);
            createDefaultWebXml(domainConfig);
            createLoginConf(domainConfig);
            createWssServerConfig(domainConfig);
            createWssServerConfigOld(domainConfig);
            createSSLCertificateDatabase(domainConfig, masterPassword);                                     
            changeMasterPasswordInMasterPasswordFile(domainConfig, masterPassword, 
                saveMasterPassword(domainConfig));
            createPasswordAliasKeystore(domainConfig, masterPassword);        
            createTimerWal(domainConfig);
            createTimerDbn(domainConfig);
            createMQInstance(domainConfig);
            createJBIInstance(getDefaultInstance(), domainConfig);
            if (layout.getDerbyEjbTimerSqlFile().exists()) //will be cleaned up once derby integrates, 05/19/2005
                handleDerby(domainConfig);
            setPermissions(domainConfig);
        } catch (DomainException de) {
            //rollback
            FileUtils.liquidate(getDomainDir(domainConfig));
            throw de;
        } catch (Exception ex) {
            //rollback
            FileUtils.liquidate(getDomainDir(domainConfig));
            throw new DomainException(ex);
        }
    
protected voidcreateDomainXml(com.sun.enterprise.admin.servermgmt.DomainConfig domainConfig)

        try
        {
            final PEFileLayout layout = getFileLayout(domainConfig);
            final File dx = layout.getDomainConfigFile();
            final File dxt, tr;
            TokenValueSet tokens = getDomainXmlTokens(domainConfig);
            String tn = (String)domainConfig.get(DomainConfig.K_TEMPLATE_NAME);
            if((tn == null)||(tn.equals(""))) {
                //use profiles in this case
                dxt = layout.getDomainXmlTemplate();
                final String p = domainConfig.getProfile();
                final File pf = layout.getProfileFolder(p);
                if (!pf.exists()) {
                    final String key = "profileNotFound";
                    final String path = pf.getAbsolutePath();
                    final String name = domainConfig.getRepositoryName();
                    final String msg = strMgr.getString(key, p, path, name);
                    throw new IllegalArgumentException(msg);
                }
                if (new File(pf, layout.DOMAIN_XML_FILE).exists()) {
                // takes care of the default profiles that we bundle.
                    tr = new File(pf, layout.DOMAIN_XML_FILE);
                }
                else { //now transform for generic xsl
                    tr = invokeGenericXmlTemplateProcessing(dxt, domainConfig, 
                        PROFILEPROPERTY_DOMAINXML_STYLESHEETS, layout.getConfigRoot());
                    addTokenValuesIfAny(tokens, layout, p, this.PROFILEPROPERTY_DOMAINXML_TOKENVALUES);
                }
                generateFromTemplate(tokens, tr, dx);
            }
            else {
                dxt = layout.getDomainXmlTemplate(tn);
                generateFromTemplate(tokens, dxt, dx);
            }
        }
        catch(Exception e)
        {
            throw new DomainException(
                strMgr.getString("domainXmlNotCreated"), e);
        }
    
protected voidcreateDomainXmlEvents(com.sun.enterprise.admin.servermgmt.DomainConfig domainConfig)

            try {
                final PEFileLayout layout = getFileLayout(domainConfig);
                final File domainXml = layout.getDomainConfigFile();
                DomainXmlSAXParser parser = new DomainXmlSAXParser();
                try {
                    parser.parse(domainXml,layout.getDtdFile());
                }
                catch(Exception e) {
                    throw new DomainException(
                        strMgr.getString("domainXmlNotParsed"), e);
                }
                String className = parser.getDomainXmlEventListenerClass();
                if(className!=null) {
                    DomainXmlEventListener listener = (DomainXmlEventListener) Class.forName(className).newInstance();
                    listener.handleCreateEvent(domainConfig);
                }
            }
            catch(Exception e) {
                throw new DomainException(
                    strMgr.getString("domainXmlEventsNotCreated"), e);
            }
    
protected voidcreateIndexFile(com.sun.enterprise.admin.servermgmt.DomainConfig domainConfig)

        final PEFileLayout layout = getFileLayout(domainConfig);
        final File src = layout.getIndexFileTemplate();
        final File dest = layout.getIndexFile();
        try
        {
            final TokenValueSet tokens = IndexHtmlTokens.getTokenValueSet(domainConfig);
            generateFromTemplate(tokens, src, dest);
            handleLocalizedIndexHtmls(layout, tokens);
        }
        catch (IOException ioe)
        {
            throw new DomainException(
                strMgr.getString("indexFileNotCreated"), ioe);
        }
    
protected voidcreateJBIInstance(java.lang.String instanceName, com.sun.enterprise.admin.servermgmt.DomainConfig domainConfig)

        
        try {
            getFileLayout(domainConfig).createJBIDomainDirectories();
            super.createJBIInstance(instanceName, domainConfig);

        } catch (Exception ex) {
            throw new DomainException(ex);
        }
    
protected voidcreateLoginConf(com.sun.enterprise.admin.servermgmt.RepositoryConfig config)

        final PEFileLayout layout = getFileLayout(config);
        final File src = layout.getLoginConfTemplate();
        final File dest = layout.getLoginConf();
        try
        {
            FileUtils.copy(src, dest);
        }
        catch (IOException ioe)
        {
            throw new DomainException(
                strMgr.getString("loginConfNotCreated"), ioe);
        }
    
protected voidcreateScripts(com.sun.enterprise.admin.servermgmt.DomainConfig domainConfig)

        final TokenValueSet tokens = PEScriptsTokens.getTokenValueSet(domainConfig);
        createStartServ(domainConfig, tokens);
        createStopServ(domainConfig, tokens);
    
voidcreateStartServ(com.sun.enterprise.admin.servermgmt.DomainConfig domainConfig, com.sun.enterprise.admin.util.TokenValueSet tokens)

        try
        {
            final PEFileLayout  layout = getFileLayout(domainConfig);
            final File startServTemplate = layout.getStartServTemplate();
            final File startServ = layout.getStartServ();
            generateFromTemplate(tokens, startServTemplate, startServ);
        }
        catch (Exception e)
        {
            throw new DomainException(
                strMgr.getString("startServNotCreated"), e);
        }
    
voidcreateStopServ(com.sun.enterprise.admin.servermgmt.DomainConfig domainConfig, com.sun.enterprise.admin.util.TokenValueSet tokens)

        try
        {
            final PEFileLayout  layout = getFileLayout(domainConfig);
            final File stopServTemplate = layout.getStopServTemplate();
            final File stopServ = layout.getStopServ();
            generateFromTemplate(tokens, stopServTemplate, stopServ);
            //final File killServ = layout.getKillServTemplate();
            //generateFromTemplate(new TokenValueSet(), 
		//layout.getKillServTemplate(), layout.getKillServ());
        }
        catch (Exception e)
        {
            throw new DomainException(
                strMgr.getString("stopServNotCreated"), e);
        }
    
protected voidcreateWssServerConfig(com.sun.enterprise.admin.servermgmt.RepositoryConfig config)

        final PEFileLayout layout = getFileLayout(config);
        final File src = layout.getWssServerConfigTemplate();
        final File dest = layout.getWssServerConfig();
        try
        {
            FileUtils.copy(src, dest);
        }
        catch (IOException ioe)
        {
            throw new DomainException(
                strMgr.getString("wssserverconfignotcreated"), ioe);
        }

    
protected voidcreateWssServerConfigOld(com.sun.enterprise.admin.servermgmt.RepositoryConfig config)

        final PEFileLayout layout = getFileLayout(config);
        final File src = layout.getWssServerConfigOldTemplate();
        final File dest = layout.getWssServerConfigOld();
        try
        {
            FileUtils.copy(src, dest);
        }
        catch (IOException ioe)
        {
            throw new DomainException(
                strMgr.getString("wssserverconfignotcreated"), ioe);
        }

    
public voiddeleteDomain(com.sun.enterprise.admin.servermgmt.DomainConfig domainConfig)

               
        try {
            deleteRepository(domainConfig);
        } catch (Exception e) {
            throw new DomainException(e);
        }
    
java.lang.StringgetDefaultInstance()

        return PEFileLayout.DEFAULT_INSTANCE_NAME;
    
protected java.io.FilegetDomainDir(com.sun.enterprise.admin.servermgmt.DomainConfig domainConfig)

        return getRepositoryDir(domainConfig);
    
public java.util.BitSetgetDomainFlags()

        BitSet bs = new BitSet();        
        bs.set(DomainConfig.K_FLAG_START_DOMAIN_NEEDS_ADMIN_USER, false);
        return bs;
    
protected static java.lang.StringgetDomainPasswordClear(com.sun.enterprise.admin.servermgmt.DomainConfig domainConfig)
Returns the domain user's password in cleartext from the domainConfig.

param
Map that represents the domain configuration
return
String representing the domain user password if the given map contains it, null otherwise

        return ( (String) domainConfig.get(DomainConfig.K_PASSWORD) );
    
protected java.io.FilegetDomainRoot(com.sun.enterprise.admin.servermgmt.DomainConfig domainConfig)

        return getRepositoryRootDir(domainConfig);
    
protected static java.lang.StringgetDomainUser(com.sun.enterprise.admin.servermgmt.DomainConfig domainConfig)
Returns the domain user from the domainConfig.

param
Map that represents the domain configuration
return
String representing the domain user if the given map contains it, null otherwise

        return ( (String) domainConfig.get(DomainConfig.K_USER) );
    
protected com.sun.enterprise.admin.util.TokenValueSetgetDomainXmlTokens(com.sun.enterprise.admin.servermgmt.DomainConfig domainConfig)
The EEDomains manager needs to have an augmented set of tokens

        return PEDomainXmlTokens.getTokenValueSet(domainConfig);
    
protected java.util.PropertiesgetEnvProps(com.sun.enterprise.admin.servermgmt.DomainConfig dc)

        Properties p = new Properties();

        p.setProperty(SystemPropertyConstants.INSTANCE_ROOT_PROPERTY,
                    dc.getRepositoryRoot() + File.separator + dc.getRepositoryName());
        
        // this will be set again by ASLauncher.  It doesn't hurt to do it here too
        p.setProperty("domain.name", dc.getRepositoryName());
      
        p.setProperty(LaunchConstants.PROCESS_NAME_PROP, "as9-server");
        
        return p;
    
public java.lang.String[]getExtraPasswordOptions(com.sun.enterprise.admin.servermgmt.DomainConfig config)

        return null;
    
protected static java.lang.StringgetMasterPasswordClear(com.sun.enterprise.admin.servermgmt.DomainConfig domainConfig)

        return ((String)domainConfig.get(DomainConfig.K_MASTER_PASSWORD));
    
protected static java.lang.StringgetNewMasterPasswordClear(com.sun.enterprise.admin.servermgmt.DomainConfig domainConfig)

        return ((String)domainConfig.get(DomainConfig.K_NEW_MASTER_PASSWORD));
    
private static java.util.ListgetStyleSheetList(java.io.File pf, java.io.File propsFile, java.lang.String p)

        /* Implementation note: I have chosen to throw a runtime exception here
         * because if this fails, there is no way to recover. It almost
         * certainly means that there is something wrong with the installation.
         */
        if (! propsFile.exists() || ! propsFile.canRead()) {
            final String msg = strMgr.getString("profilePropertiesMissing", propsFile.getAbsolutePath());
            throw new IllegalArgumentException(msg);
        }
        try {
            final String ssNames    = readProfilePropertyValue(propsFile, p);
            final StringTokenizer tk = new StringTokenizer(ssNames, NAME_DELIMITER);
            final List<File> list    = new ArrayList<File>(tk.countTokens());
            while (tk.hasMoreTokens()) {
                final File ss = new File(pf, tk.nextToken().trim());
                if (! ss.exists()) {
                    final String msg = strMgr.getString("styleSheetNotFound", ss.getAbsolutePath());
                    throw new RuntimeException(msg);
                }
                list.add(ss);
            }
            return ( list );
        } catch (final IOException e) {
            throw new RuntimeException(e);
        }
    
private voidhandleLocalizedIndexHtmls(PEFileLayout layout, com.sun.enterprise.admin.util.TokenValueSet tokens)

        Locale locale = Locale.getDefault();
        if (Locale.ENGLISH.getLanguage().equals(locale.getLanguage()))
            return; //don't do anything in the case of English "language", not just locale
        //rename the existing index.file first
        File src  = layout.getNonEnglishIndexFileTemplate(locale);
        File dest = layout.getIndexFile();
        if (src.exists()) {
            dest.renameTo(layout.getEnglishIndexFile());
            dest = layout.getIndexFile();
            try {
                generateFromTemplate(tokens, src, dest);
            } catch(IOException e) {
                String one = strMgr.getString("problemCopyingIndexHtml", src.getAbsolutePath(), dest.getAbsolutePath());
                System.out.println(one);
            }
        } else {
            String two = strMgr.getString("localeFileNotFound", locale, src.getAbsolutePath());
            System.out.println(two);
        }
    
private java.io.FileinvokeGenericXmlTemplateProcessing(java.io.File base, com.sun.enterprise.admin.servermgmt.DomainConfig dc, java.lang.String propName, java.io.File destDir)

        final PEFileLayout layout                 = getFileLayout(dc);
        final String profileName                  = dc.getProfile();
        final File profileFolder                  = layout.getProfileFolder(profileName);
        String msg = strMgr.getString("genericProfileHandlingStarts", profileFolder.getName());
        System.out.println(msg);
        msg = strMgr.getString("genericXmlProcessing", base, profileFolder.getName(), propName);
        System.out.println(msg);
        final File propsFile = layout.getProfilePropertiesFile(profileName);
        final List<File> styleSheets = getStyleSheetList(profileFolder, propsFile, propName);
        final Properties p = new Properties();
        p.setProperty(OutputKeys.DOCTYPE_PUBLIC, ServerValidationHandler.SERVER_DTD_PUBLIC_ID);
        p.setProperty(OutputKeys.DOCTYPE_SYSTEM, ServerValidationHandler.SERVER_DTD_SYSTEM_ID);
        final EntityResolver er = new ServerValidationHandler();
        final ProfileTransformer px = new ProfileTransformer(base, styleSheets, destDir, er, p);
        final File transformed = px.transform();
        return ( transformed );
    
private booleanisDomainNotRunning(com.sun.enterprise.admin.servermgmt.DomainConfig domainConfig)

        InstancesManager instMgr = getInstancesManager(domainConfig);
        
        return (Status.kInstanceNotRunningCode ==
                instMgr.getInstanceStatus());
    
public java.lang.String[]listDomains(com.sun.enterprise.admin.servermgmt.DomainConfig domainConfig)
Lists all the domains.

        
        try {
            return listRepository(domainConfig); 
        } catch (Exception e) {
            throw new DomainException(e);
        }        
    
public java.lang.String[]listDomainsAndStatus(com.sun.enterprise.admin.servermgmt.DomainConfig domainConfig)

        try {
            return listDomainsAndStatusAsString(domainConfig);
        } catch (Exception e) {
            throw new DomainException(e);
        }        
    
private static java.lang.StringreadProfilePropertyValue(java.io.File propsFile, java.lang.String propName)

        /* Could be optimized, but it should not be done prematurely. This
         * method could be called multiple times while doing profile processing,
         * but it is OK to load the properties every time, because I don't have
         * data to suggest that that should not be done. I don't think we will
         * run into performance issues with respect to this.
         */
        final Properties ps = new Properties();
        String propValue = null;
        BufferedInputStream bis = new BufferedInputStream(new FileInputStream(propsFile));
        try {
            ps.load(bis);
            propValue = ps.getProperty(propName);
            if (propValue == null) {
                propValue = "";
            }
        } finally {
            if (bis != null) {
                try {
                    bis.close();
                } catch (final IOException ee) {
                    // Have to squelch
                }
            }
        }
        return ( propValue ); 
    
private static java.util.Sets2TV(java.lang.String nvpairs)

        final Set<TokenValue> set = new HashSet<TokenValue>();
        final StringTokenizer st = new StringTokenizer(nvpairs, NAME_DELIMITER);
        String msg;
        while (st.hasMoreTokens()) {
            String tvs = st.nextToken();
            if (tvs == null || tvs.indexOf("=") == -1 || tvs.length() < 3) {
                msg = strMgr.getString("invalidToken", tvs);
            }
            tvs = tvs.trim();
            final int e2 = tvs.indexOf("=");
            final String t = tvs.substring(0, e2);
            final String v = tvs.substring(e2+1);
            msg = strMgr.getString("processingToken", new String[] {t, v});
            System.out.println(msg);
            final TokenValue tv = new TokenValue(t, v); //default delimiter
            set.add(tv);
        }
        return ( set );
    
protected static booleansaveMasterPassword(com.sun.enterprise.admin.servermgmt.DomainConfig domainConfig)

        Boolean b = (Boolean)domainConfig.get(DomainConfig.K_SAVE_MASTER_PASSWORD);
        return b.booleanValue();
    
protected voidsetPermissions(com.sun.enterprise.admin.servermgmt.DomainConfig domainConfig)
Sets the permissions for the domain directory, its config directory, startserv/stopserv scripts etc.

        
        final PEFileLayout layout = getFileLayout(domainConfig);
        try {
            //4958533
            chmod("-R u+x ", layout.getBinDir());
            chmod("-R g-rwx,o-rwx ", layout.getConfigRoot());
            //4958533
        } catch (Exception e) {
            throw new DomainException(
                strMgr.getString("setPermissionError"), e);
        }   
    
public voidstartDomain(com.sun.enterprise.admin.servermgmt.DomainConfig domainConfig)

                        
        try {
            checkRepository(domainConfig);            
            String[] options = getInteractiveOptions(
                (String)domainConfig.get(DomainConfig.K_USER), 
                (String)domainConfig.get(DomainConfig.K_PASSWORD),
                (String)domainConfig.get(DomainConfig.K_MASTER_PASSWORD),
                (HashMap)domainConfig.get(DomainConfig.K_EXTRA_PASSWORDS));            
            getInstancesManager(domainConfig).startInstance(options, (String[])null, getEnvProps(domainConfig));            
        } catch (Exception e) {
            throw new DomainException(e);
        }
    
public voidstopDomain(com.sun.enterprise.admin.servermgmt.DomainConfig domainConfig)

                        
        try {
            checkRepository(domainConfig);            
            getInstancesManager(domainConfig).stopInstance();
        } catch (Exception e) {
            throw new DomainException(e);
        }
    
public voidstopDomainForcibly(com.sun.enterprise.admin.servermgmt.DomainConfig domainConfig, int timeout)

        try {
            checkRepository(domainConfig);
            InstancesManager domainMgr = getInstancesManager(domainConfig);

            boolean stopped = false;
            
            if(timeout > 0)
                stopped = domainMgr.stopInstanceWithinTime(timeout);
            
            if (!stopped) domainMgr.killRelatedProcesses(); 
        } catch (Exception e) {
            throw new DomainException(e);
        }        
    
public voidvalidateAdminUserAndPassword(com.sun.enterprise.admin.servermgmt.DomainConfig domainConfig)

        try {
            validateAdminUserAndPassword(domainConfig, getDomainUser(domainConfig),
                getDomainPasswordClear(domainConfig));
        } catch (RepositoryException ex) {
            throw new DomainException(ex);
        }
    
public voidvalidateDomain(com.sun.enterprise.admin.servermgmt.DomainConfig domainConfig, boolean domainExists)

        try {
            checkRepository(domainConfig, domainExists, domainExists);
        } catch (RepositoryException ex) {
            throw new DomainException(ex);
        }
    
public voidvalidateMasterPassword(com.sun.enterprise.admin.servermgmt.DomainConfig domainConfig)

        try {
            validateMasterPassword(domainConfig, getMasterPasswordClear(domainConfig));
        } catch (RepositoryException ex) {
            throw new DomainException(ex);
        }