FileDocCategorySizeDatePackage
DependencyResolver.javaAPI DocGlassfish v2 API16144Fri May 04 22:33:34 BST 2007com.sun.enterprise.admin.event

DependencyResolver

public class DependencyResolver extends Object
Returns config change elements for dependent resources. This is a helper class that makes an event self contained.

Example: If a resource references a connection pool, corresponding config change elements for that pool is sent as dependent config changes in the event. If the pool is not initialized by the targeted server already, it is initialized based on the dependent change list.

author
Nazrul Islam
since
JDK1.4

Fields Summary
private com.sun.enterprise.config.ConfigContext
_ctx
private String
_target
Constructors Summary
DependencyResolver(com.sun.enterprise.config.ConfigContext ctx, String target)
Constructor

        _ctx    = ctx;
        _target = target;
    
Methods Summary
private java.util.ListaddConfigChangeForResource(com.sun.enterprise.config.ConfigBean res)
Returns config change for the given config bean.

param
res config bean
return
config change for the given bean
throws
ConfigException if a configuration parsing error

        
        List list = new ArrayList();
        if (res == null) {
            return list;
        }

        String xpath = res.getXPath();
        ConfigAdd configAdd = ConfigChangeFactory.createConfigAdd(_ctx, xpath);
        list.add(configAdd);

        return list;
    
com.sun.enterprise.config.ConfigBeanfindResource(java.lang.String resName, java.lang.String type)
Locates a resource based on name and type.

param
resName name of resource
param
type type of resource
return
config bean for the resource
throws
ConfigException if a configuration parsing error


        ConfigBean res = null;
        Resources root = ((Domain)_ctx.getRootConfigBean()).getResources();

        if (ResourceDeployEvent.RES_TYPE_JDBC.equals(type)) {
            res = root.getJdbcResourceByJndiName(resName);
        } else if (ResourceDeployEvent.RES_TYPE_MAIL.equals(type)) {
            res = root.getMailResourceByJndiName(resName);
        } else if (ResourceDeployEvent.RES_TYPE_CUSTOM.equals(type)) {
            res = root.getCustomResourceByJndiName(resName);
        } else if (ResourceDeployEvent.RES_TYPE_EXTERNAL_JNDI.equals(type)) {
            res = root.getExternalJndiResourceByJndiName(resName);
        } else if (ResourceDeployEvent.RES_TYPE_PMF.equals(type)) {
            res = root.getPersistenceManagerFactoryResourceByJndiName(resName);
        } else if (ResourceDeployEvent.RES_TYPE_AOR.equals(type)) {
            res = root.getAdminObjectResourceByJndiName(resName);
        } else if (ResourceDeployEvent.RES_TYPE_CR.equals(type)) {
            res = root.getConnectorResourceByJndiName(resName);
        } else if (ResourceDeployEvent.RES_TYPE_JCP.equals(type)) {
            res = root.getJdbcConnectionPoolByName(resName);
        } else if (ResourceDeployEvent.RES_TYPE_CCP.equals(type)) {
            res = root.getConnectorConnectionPoolByName(resName);
        } else if (ResourceDeployEvent.RES_TYPE_RAC.equals(type)) {
            res = root.getResourceAdapterConfigByResourceAdapterName(resName);
        }

        return res;
    
com.sun.enterprise.config.serverbeans.ResourceAdapterConfigfindResourceAdapterConfigByName(java.lang.String name)
Returns the resource adapter config if it matches the given application name. RA in an EAR is defined as AppName#RAName. This method matches with the AppName.

param
name application name
throws
ConfigException if an error while parsing the config


        // all resources
        Resources root = ((Domain)_ctx.getRootConfigBean()).getResources();

        // all resource adapter configs in the system
        ResourceAdapterConfig[] configs = root.getResourceAdapterConfig();


        if (configs != null) {
            for (int i=0; i<configs.length; i++) {
                String fullRAName  = configs[i].getResourceAdapterName();
                String raName = getApplicationNameFromRAName(fullRAName);

                if (raName.equals(name)) {
                    return configs[i];
                }
            }
        }

        // did not find any RA config that matches the name
        return null;
    
java.lang.StringgetApplicationNameFromRAName(java.lang.String fullRAName)
Returns the application name from a RA name. RA name is defined as AppName#RAName. This method returns the AppName.

param
fullRAName name of a resource adapter
return
application name


        String appName      = null;

        // strip off the portion after #
        int idx = fullRAName.indexOf("#");
        if (idx > 0) {
            appName = fullRAName.substring(0, idx);
        } else {
            appName = fullRAName;
        }

        return appName;
    
java.util.ListgetConfigDeleteForApplication(java.lang.String applicationName)
Returns the config delete change objects for an application.

param
applicationName name of the application
return
config delete objects for the given application
throws
ConfigException if an error while parsing the config

        
        List list = new ArrayList();

        if (applicationName != null) {
            ConfigBean app =
                ApplicationHelper.findApplication(_ctx,applicationName);
            String xpath = app.getXPath();
            ConfigDelete configDelete =
                ConfigChangeFactory.createConfigDelete(xpath);
            list.add(configDelete);
        }
        return list;
    
java.util.ListgetConfigDeleteForResource(java.lang.String resName, java.lang.String resTypeInEvent)
Returns the config delete objects for the given resource.

param
resName name of the resource
param
resTypeInEvent tyep of the resource defined in ResourceDeployEvent
return
returns the config delete objects for a resource
throws
ConfigException if an error while parsing config


        // type is used in finding resource since resource 
        // name space is not flat
        ConfigBean res = findResource(resName, resTypeInEvent); 
        return getConfigDeleteForResource(res);
    
java.util.ListgetConfigDeleteForResource(com.sun.enterprise.config.ConfigBean res)
Creates ConfigDelete change object for referenced resource.

param
res config bean
return
list containing config delete for the given bean
throws
ConfigException if an error while parsing config

        
        List list = new ArrayList();
        if (res == null) {
            return list;
        }
        String xpath = res.getXPath();
        ConfigDelete configDelete=ConfigChangeFactory.createConfigDelete(xpath);
        list.add(configDelete);
        return list;
    
java.util.ListresolveApplications(java.lang.String applicationName, java.lang.String action)
Resolves application dependencies.

param
applicationName name of the application
param
action type of event (example, deploy, undeploy, redeploy)
return
a list of dependent config change objects
throws
ConfigException if an error while parsing configuration


        List list = new ArrayList();

        if (applicationName == null 
                || BaseDeployEvent.REMOVE_REFERENCE.equals(action)
                || BaseDeployEvent.REDEPLOY.equals(action)
                || BaseDeployEvent.UNDEPLOY.equals(action)) {
            return list;
        }
        ConfigBean app=ApplicationHelper.findApplication(_ctx,applicationName);
        if (app == null) {
            return list;
        }
        // xpath for this application
        String xpath = app.getXPath();

        // config change object for the application entry
        ConfigAdd configAdd = ConfigChangeFactory.createConfigAdd(_ctx, xpath);
        list.add(configAdd);

        // add resource adapter config
        ResourceAdapterConfig raConfig = 
            findResourceAdapterConfigByName(applicationName);

        // if resource adapter config is found
        if (raConfig != null) {
            ConfigAdd raConfigChange = 
                ConfigChangeFactory.createConfigAdd(_ctx, raConfig.getXPath());

            // add the resource adapter config to the dependent config changes
            list.add(raConfigChange);
        }

        return list;
    
private java.util.ListresolveConnectorConnectionPool(java.lang.String poolName)
Returns dependency list for a connector connection pool.

param
poolName name of connector connection pool
return
dependency list for connector connection pool
throws
ConfigException if a configuration parsing error


        List list  = new ArrayList();

        if (poolName == null) {
            return list;
        }

        Resources root = ((Domain)_ctx.getRootConfigBean()).getResources();
        ConnectorConnectionPool pool = 
            root.getConnectorConnectionPoolByName(poolName);

        if (pool == null) {
            return list;
        }

        list.addAll( addConfigChangeForResource(pool) );

        return list;
    
private java.util.ListresolveJdbcConnectionPool(java.lang.String poolName)
Returns dependency list for jdbc connection pool.

param
poolName name of jdbc connection pool
return
dependency list for jdbc connection pool
throws
ConfigException if a configuration parsing error


        List list  = new ArrayList();

        if (poolName == null) {
            return list;
        }

        Resources root = ((Domain)_ctx.getRootConfigBean()).getResources();
        JdbcConnectionPool pool = root.getJdbcConnectionPoolByName(poolName);

        // no pool found 
        if (pool == null) {
            return list;
        }
        list.addAll( addConfigChangeForResource(pool) );

        return list;
    
java.util.ListresolveResources(java.lang.String resName, java.lang.String action, java.lang.String typeInEvent)
Resolves resource dependencies for resource creation.
Dependencies:
JDBC Resource - Depends on JDBC connection pool.
Persistence Manager Factory - Depends on JDBC resource.
Connector Resource - Depends on Connector connection pool.

param
resName name of the resource
param
action type of event (example, deploy, undeploy, redeploy)
param
typeInEvent resource type as defined in ResourceDeployEvent
return
a list of dependent config change objects
throws
ConfigException if an error while parsing configuration


        List list = new ArrayList();
        if (resName == null 
                //|| BaseDeployEvent.REDEPLOY.equals(action)
                || BaseDeployEvent.REMOVE_REFERENCE.equals(action)
                || BaseDeployEvent.UNDEPLOY.equals(action)) {
            return list;
        }
            
        ConfigBean res = findResource(resName, typeInEvent); 
        if (res == null) {
            return list;
        }
        /*
        else if (BaseDeployEvent.REMOVE_REFERENCE.equals(action))
        {
            // add ConfigDelete change element for referenced resource 
            // it will not harm config because applying of changes 
            // will be done over runtime config
            list.addAll( getConfigDeleteForResource(res) );
            return list;
        }
        */
        
        // JDBC resource
        if (ResourceDeployEvent.RES_TYPE_JDBC.equals(typeInEvent)) {

            String poolName = ((JdbcResource) res).getPoolName();
            list.addAll(resolveJdbcConnectionPool(poolName));

        // Connector resource
        } else if (ResourceDeployEvent.RES_TYPE_CR.equals(typeInEvent)) {

            String poolName = ((ConnectorResource) res).getPoolName();
            list.addAll(resolveConnectorConnectionPool(poolName));

        // PMF resource
        } else if (ResourceDeployEvent.RES_TYPE_PMF.equals(typeInEvent)) {

            String jdbcResName = ((PersistenceManagerFactoryResource) res).
                                                    getJdbcResourceJndiName();
            list.addAll( resolveResources(jdbcResName, action, 
                                ResourceDeployEvent.RES_TYPE_JDBC) );
        }

        list.addAll( addConfigChangeForResource(res) );

        return list;