FileDocCategorySizeDatePackage
ResourceHelper.javaAPI DocGlassfish v2 API11176Sat Dec 24 18:48:22 GMT 2005com.sun.enterprise.config.serverbeans

ResourceHelper

public class ResourceHelper extends ReferenceHelperBase

Fields Summary
protected static final com.sun.enterprise.util.i18n.StringManager
_strMgr
private static ResourceHelper
_theInstance
Constructors Summary
public ResourceHelper()

    
    
      
        super();
    
Methods Summary
public static com.sun.enterprise.config.ConfigBeanfindResource(com.sun.enterprise.config.ConfigContext ctx, java.lang.String id)

        Resources root = ((Domain)ctx.getRootConfigBean()).getResources();
        return findResource(root, id);
    
public static com.sun.enterprise.config.ConfigBeanfindResource(Resources root, java.lang.String id)


        ConfigBean res = root.getJdbcResourceByJndiName(id);
        if ( res != null )
            return res;

        res = root.getMailResourceByJndiName(id);
        if( res != null )
            return res;

        res = root.getCustomResourceByJndiName(id);
        if( res != null )
            return res;

        res = root.getExternalJndiResourceByJndiName(id);
        if ( res != null )
            return res;

        res = root.getPersistenceManagerFactoryResourceByJndiName(id);
        if ( res != null)
            return res;

        res = root.getAdminObjectResourceByJndiName(id);
        if ( res != null )
            return res;

        res = root.getConnectorResourceByJndiName(id);
        if ( res != null )
            return res;

        res = root.getJdbcConnectionPoolByName(id);
        if ( res != null )
            return res;

        res = root.getConnectorConnectionPoolByName(id);
        if ( res != null )
            return res;

        res = root.getResourceAdapterConfigByResourceAdapterName(id);
        if ( res != null )
            return res;

        return null;
    
private static synchronized com.sun.enterprise.config.serverbeans.ResourceHelpergetInstance()

        if (_theInstance == null) {
            _theInstance = new ResourceHelper();
        }
        return _theInstance;
    
protected Cluster[]getReferencingClusters(com.sun.enterprise.config.ConfigContext configContext, java.lang.String name)

        return ClusterHelper.getClustersReferencingResource(configContext, name);        
    
protected Server[]getReferencingServers(com.sun.enterprise.config.ConfigContext configContext, java.lang.String name)

        return ServerHelper.getServersReferencingResource(configContext, name); 
    
public static java.lang.StringgetResourceReferenceesAsString(com.sun.enterprise.config.ConfigContext configContext, java.lang.String resourceName)
Find all the servers or clusters associated with the given configuration and return them as a comma separated list.

        
        return getInstance().getReferenceesAsString(configContext, resourceName);
    
public static java.lang.StringgetResourceType(com.sun.enterprise.config.ConfigContext ctx, java.lang.String id)
Returns the resource type of a given resource


        Resources root = ((Domain)ctx.getRootConfigBean()).getResources();

        ConfigBean res = root.getJdbcResourceByJndiName(id);
        if ( res != null )
            return Resources.JDBC_RESOURCE;

        res = root.getMailResourceByJndiName(id);
        if( res != null )
            return Resources.MAIL_RESOURCE;

        res = root.getCustomResourceByJndiName(id);
        if( res != null )
            return Resources.CUSTOM_RESOURCE;

        res = root.getExternalJndiResourceByJndiName(id);
        if ( res != null )
            return Resources.EXTERNAL_JNDI_RESOURCE;

        res = root.getPersistenceManagerFactoryResourceByJndiName(id);
        if ( res != null)
            return Resources.PERSISTENCE_MANAGER_FACTORY_RESOURCE;

        res = root.getAdminObjectResourceByJndiName(id);
        if ( res != null )
            return Resources.ADMIN_OBJECT_RESOURCE;

        res = root.getConnectorResourceByJndiName(id);
        if ( res != null )
            return Resources.CONNECTOR_RESOURCE;

        res = root.getJdbcConnectionPoolByName(id);
        if ( res != null )
            return Resources.JDBC_CONNECTION_POOL;

        res = root.getConnectorConnectionPoolByName(id);
        if ( res != null )
            return Resources.CONNECTOR_CONNECTION_POOL;

        res = root.getResourceAdapterConfigByResourceAdapterName(id);
        if ( res != null )
            return Resources.RESOURCE_ADAPTER_CONFIG;

        return null;
    
public static booleanisConnectorPoolReferenced(com.sun.enterprise.config.ConfigContext ctx, java.lang.String poolName, java.lang.String serverName)
Returns true if the named pool has a reference from a connector resource that is used by the given server instance.

param
ctx config context
param
poolName connector pool name
param
serverName name of the server instance
return
true if the pool is used by the server instance
throw
ConfigException if an error while parsing domain.xml


        if (ctx == null || poolName == null || serverName == null) {
            return false;
        }

        Resources rBean = ServerBeansFactory.getDomainBean(ctx).getResources();

        ConnectorResource[] conBeans = rBean.getConnectorResource();

        // no connector resource in the domain, so it is not possible 
        // for the connector pool to be in use by a server in this domain
        if (conBeans == null) { 
            return false;
        }

        for (int i = 0; i <conBeans.length; i++) {

            // connector resource is not referenced by the server instance
            if ( !ServerHelper.serverReferencesResource(
                    ctx, serverName, conBeans[i].getJndiName()) ) {

                continue;
            } else {
                String pool = conBeans[i].getPoolName();
                if ( (pool != null) && pool.equals(poolName) ) {
                    return true;
                }
            }
        }
        return false;
    
public static booleanisJdbcPoolReferenced(com.sun.enterprise.config.ConfigContext ctx, java.lang.String poolName, java.lang.String serverName)
Returns true if the named pool has a reference from a jdbc resource that is used by the given server instance.

param
ctx config context
param
poolName jdbc resource pool name
param
serverName name of the server instance
return
true if the pool is used by the server instance
throw
ConfigException if an error while parsing domain.xml


        if (ctx == null || poolName == null || serverName == null) {
            return false;
        }

        Resources rBean = ServerBeansFactory.getDomainBean(ctx).getResources();

        JdbcResource[] jdbcBeans = rBean.getJdbcResource();

        // no jdbc resource in the domain, so it is not possible 
        // for the jdbc pool to be in use by a server in this domain
        if (jdbcBeans == null) { 
            return false;
        }

        for (int i = 0; i <jdbcBeans.length; i++) {

            // jdbc resource is not referenced by the server instance
            if ( !ServerHelper.serverReferencesResource(
                    ctx, serverName, jdbcBeans[i].getJndiName()) ) {

                continue;
            } else {
                String pool = jdbcBeans[i].getPoolName();
                if ( (pool != null) && pool.equals(poolName) ) {
                    // jdbc pool is referenced by server (server->res->pool)
                    return true;
                }
            }
        }

        // no jdbc resource referred by this server is using this pool
        return false;
    
public static booleanisResourceReferenced(com.sun.enterprise.config.ConfigContext configContext, java.lang.String resourceName)
Is the configuration referenced by anyone (i.e. any server instance or cluster

        return getInstance().isReferenced(configContext, resourceName);
    
public static booleanisResourceReferencedByClusterOnly(com.sun.enterprise.config.ConfigContext configContext, java.lang.String resourceName, java.lang.String clusterName)
Return true if the configuration is referenced by no-one other than the given cluster.

                       
        return getInstance().isReferencedByClusterOnly(configContext, resourceName, clusterName);
    
public static booleanisResourceReferencedByServerOnly(com.sun.enterprise.config.ConfigContext configContext, java.lang.String resourceName, java.lang.String serverName)
Return true if the configuration is referenced by no-one other than the given server instance.

        
        return getInstance().isReferencedByServerOnly(configContext, resourceName, serverName);
    
public static booleanisSystemResource(com.sun.enterprise.config.ConfigContext ctx, java.lang.String resourceName)

        ConfigBean bean = findResource(ctx, resourceName);
        if (bean == null) {
            throw new ConfigException(_strMgr.getString("noSuchResource", 
                resourceName));
        } 
        String objectType = null;
        try {
            objectType = bean.getAttributeValue(ServerTags.OBJECT_TYPE);
        } catch (Exception ex) {
            //if the object-type attribute does not exist, then assume that
            //the resource is not a system resource.
            return false;
        }
        if (objectType.equals(IAdminConstants.SYSTEM_ALL) || 
            objectType.equals(IAdminConstants.SYSTEM_ADMIN) ||
            objectType.equals(IAdminConstants.SYSTEM_INSTANCE)) {
            return true;
        } else {
            return false;
        }