FileDocCategorySizeDatePackage
ApplicationConfigHelper.javaAPI DocGlassfish v2 API19064Fri May 04 22:34:36 BST 2007com.sun.enterprise.deployment.phasing

ApplicationConfigHelper

public class ApplicationConfigHelper extends Object
This module provides helper methods for Application config element
author
alexkrav

Fields Summary
private static final String
CONTEXT_ROOTS_PROPERTY_NAME
private static final com.sun.enterprise.util.i18n.StringManager
_strMgr
private com.sun.enterprise.config.ConfigContext
_configContext
Constructors Summary
public ApplicationConfigHelper(com.sun.enterprise.config.ConfigContext configContext)
Creates a new instance of EEApplicationsConfigMBean


           
       
    
        _configContext = configContext;
    
Methods Summary
public static java.lang.StringcheckContextRootUniqueness(com.sun.enterprise.config.ConfigContext ctx, java.lang.String appId, java.lang.String targetName, java.lang.String virtualServerList)
Check the uniqueness of application's context-roots among applications deployed to the given server instance's virtual servers

param
appId - application name
param
targetName - server instance name or cluster name
param
virtualServerList coma separated list of virtual servers
throws
ConfigException
returns
conflicting context root and null is context roots are unique inside of virtual servers.

        ConfigBean appBean = ApplicationHelper.findApplication(ctx, appId);
        if(appBean==null)
        {
            throw new ConfigException(_strMgr.getString("applicationElementIsNotFoundForName", appId));
        }
        
        //get context roots for testing element
        String[] ctxRoots = getAppContextRoots(appBean);
        if(ctxRoots==null || ctxRoots.length<=0)
        	return null;

        //create target by name
        final Target target = TargetBuilder.INSTANCE.createTarget(
            new TargetType[]{TargetType.CLUSTER, TargetType.SERVER, TargetType.DAS}, targetName, ctx);            
        
        //get apprefs for target 
        ApplicationRef[] refs = null;
        if (target.getType() == TargetType.CLUSTER ||
            target.getType() == TargetType.STANDALONE_CLUSTER) 
        {
            refs = ClusterHelper.getApplicationReferences(ctx, targetName);
        }
        else
        {
            refs = ServerHelper.getApplicationReferences(ctx, targetName);
        }
            
        if(refs==null)
            return null;
        
        for(int i=0; i<refs.length; i++)
        {
            if(isVSListsIntersected(refs[i].getVirtualServers(), virtualServerList))
            {
                ConfigBean appBeanToCompare = ApplicationHelper.findApplication(ctx, refs[i].getRef());
                if(appBeanToCompare==null)
                {
                    throw new ConfigException(_strMgr.getString("applicationElementIsNotFoundForName", refs[i].getRef()));
                }   
                if(((Object)appBeanToCompare)!=((Object)appBean))
                {
                    String commonElement = (String)getFirstCommonElement(getAppContextRoots(appBeanToCompare), ctxRoots);
                    if(commonElement!=null)
                        return commonElement;
                }
 
            }
        }
        return null;
    
public static java.lang.String[]getAppContextRoots(com.sun.enterprise.config.ConfigBean appBean)
Get application context roots of standalone web-module or j2ee application

param
appBean - config bean representing standalone web-module or j2ee application
throws
ConfigException if data in trancient property has wrong type
returns
String array of context roots, or null - if inapropriate bean type

        if (appBean instanceof WebModule)
        {
            return new String[]{((WebModule)appBean).getContextRoot()};
        }
        if (appBean instanceof J2eeApplication)
        {
            Object roots = appBean.getTransientProperty(CONTEXT_ROOTS_PROPERTY_NAME);
            if(roots==null)
            {
                String appName = ((J2eeApplication)appBean).getName();

                //call deployment helper
                roots = DeploymentServiceUtils.getContextRootsForEmbeddedWebApp(appName);
                appBean.setTransientProperty(CONTEXT_ROOTS_PROPERTY_NAME, roots);
            }
            else
            {
                if(!(roots instanceof String[]))
                {
                    throw new ConfigException(_strMgr.getString("configRootsPropertyIsNotStringArray",
                        ((J2eeApplication)appBean).getName()));     
                }
            }
                
            return (String[])roots;
        }
        return null;
    
public static java.lang.String[]getAppContextRoots(com.sun.enterprise.config.ConfigContext ctx, java.lang.String appName)
Get application context roots of standalone web-module or j2ee application

param
ctx - config context containing application elements
param
appName - name of application element
throws
ConfigException if data in trancient property has wrong type
returns
String array of context roots, or null - if inapropriate bean type

        ConfigBean appBean = ApplicationHelper.findApplication(ctx, appName);
        if(appBean==null)
        {
            throw new ConfigException(_strMgr.getString("applicationElementIsNotFoundForName", appName));
        }
        return getAppContextRoots(appBean);
    
private com.sun.enterprise.config.ConfigContextgetConfigContext()

        return _configContext;
    
private static java.lang.ObjectgetFirstCommonElement(java.lang.Object[] arr1, java.lang.Object[] arr2)
returns null if arrays have equal elements

        if(arr1!=null && arr2!=null && arr1.length!=0 && arr2.length!=0)
        {
            for(int i=0; i<arr1.length; i++)
            {
                for(int j=0; j<arr2.length; j++)
                {
                    if( ((String)arr1[i]).startsWith("/") ) {
                        arr1[i] = ((String)arr1[i]).substring(1);
                    }
                    if( ((String)arr2[j]).startsWith("/") ) {
                        arr2[j] = ((String)arr2[j]).substring(1);
                    }
                    if(arr1[i].equals(arr2[j])) {
                        return arr1[i];
                    }
                }
            }
        }
        return null;
    
private static booleanisVSListsIntersected(java.lang.String vsList1, java.lang.String vsList2)
returns true if any of lists are empty or not intersected vsList1 is from existing application-ref and vsList2 is from the the application being deployed

        if (vsList1==null || vsList1.length()==0 ) {
            return true;
        }

        if (vsList2 == null || vsList2.length()==0 ) {
            String[] arr = vsList1.split(",");
            if (arr.length == 1 && arr[0].equals(
                com.sun.enterprise.web.VirtualServer.ADMIN_VS)) {
                return false;
            }
            return true;
        }

        String[] arr1 = vsList1.split(",");
        String[] arr2 = vsList2.split(",");
        if(arr1.length==0 || arr2.length==0)
            return true;
        return (getFirstCommonElement(arr1, arr2)!=null);
            
    
public static voidresetAppContextRoots(com.sun.enterprise.config.ConfigBean appBean, boolean bForceToSetActualValue)
Resets config bean context-roots transient property value (ingnored if not j2ee-application)

param
appBean - config bean representing j2ee-application
param
bForceToSetActualValue - if this parameter false, correspondent transient property will be just emptied, so reading of actual values from app desctriptor will be postponed until next "AppContextRoots" operation;
throws
ConfigException if data in trancient property has wrong type

        if (appBean instanceof J2eeApplication)
        {
            appBean.setTransientProperty(CONTEXT_ROOTS_PROPERTY_NAME, null);
            if(bForceToSetActualValue)
                getAppContextRoots(appBean); //forces to read descriptor xml
        }
    
public static voidresetAppContextRoots(com.sun.enterprise.config.ConfigContext ctx, java.lang.String appName, boolean bForceToSetActualValue)
Resets config bean context-roots transient property value (ingnored/no exception if not j2ee-application)

param
ctx - config context containing application elements
param
appName - name of application element
param
bForceToSetActualValue - if this parameter false, correspondent transient property will be just emptied, so reading of actual values from app desctriptor will be postponed until next "AppContextRoots" operation;
throws
ConfigException if data in trancient property has wrong type

        ConfigBean appBean = ApplicationHelper.findApplication(ctx, appName);
        if(appBean==null)
        {
            throw new ConfigException(_strMgr.getString("applicationElementIsNotFoundForName", appName));
        }
        resetAppContextRoots(appBean, bForceToSetActualValue);