FileDocCategorySizeDatePackage
ResourceReferenceHelper.javaAPI DocGlassfish v2 API16934Fri May 04 22:24:06 BST 2007com.sun.enterprise.admin.configbeans

ResourceReferenceHelper

public class ResourceReferenceHelper extends BaseConfigBean
author
kebbs

Fields Summary
private static final com.sun.enterprise.admin.target.TargetType[]
VALID_CREATE_DELETE_TYPES
private static final com.sun.enterprise.util.i18n.StringManager
_strMgr
Constructors Summary
public ResourceReferenceHelper(com.sun.enterprise.config.ConfigContext configContext)

     

       
    
        super(configContext);
    
Methods Summary
private voidaddResourceReferenceToCluster(com.sun.enterprise.config.serverbeans.Cluster cluster, boolean enabled, java.lang.String referenceName)
Add the resource reference to the cluster (not its server instances). NOTE: Much of this functionality is duplicated in ApplicationReferenceHelper. As such be aware that bugs fixed here should be fixed there as well.

        
        ResourceRef ref = cluster.getResourceRefByRef(referenceName);
        if (ref != null) {
            //Resource ref already exists in cluster         
            throw new ConfigException(_strMgr.getString("clusterResourceRefAlreadyExists",
                referenceName, cluster.getName()));     
        }
        ref = new ResourceRef();
        ref.setEnabled(enabled);
        ref.setRef(referenceName);
        cluster.addResourceRef(ref, OVERWRITE);        
    
private voidaddResourceReferenceToClusteredServers(com.sun.enterprise.config.serverbeans.Cluster cluster, com.sun.enterprise.config.serverbeans.Server[] servers, boolean enabled, java.lang.String referenceName)
Add the resource reference to the instances belonging to a cluster NOTE: Much of this functionality is duplicated in ApplicationReferenceHelper. As such be aware that bugs fixed here should be fixed there as well.

        for (int i = 0; i < servers.length; i++) {
            final ResourceRef ref = servers[i].getResourceRefByRef(referenceName);
            if (ref != null) {
                //This indicates that the cluster is in an inconsistent state. Some of the 
                //instances in the cluster have the ref and some do not.
                throw new ConfigException(_strMgr.getString("clusterResourceRefInconsistency",
                    referenceName, cluster.getName(), servers[i].getName()));
            }
            addResourceReferenceToServer(servers[i], enabled, referenceName);
        }        
    
private voidaddResourceReferenceToServer(com.sun.enterprise.config.serverbeans.Server server, boolean enabled, java.lang.String referenceName)
Add the resource reference to a single server instance. NOTE: Much of this functionality is duplicated in ApplicationReferenceHelper. As such be aware that bugs fixed here should be fixed there as well.

        
        ResourceRef ref = server.getResourceRefByRef(referenceName);
        if (ref != null) {
            //Resource ref already exists in server         
            throw new ConfigException(_strMgr.getString("serverResourceRefAlreadyExists",
                referenceName, server.getName()));         
        }
        ref = new ResourceRef();
        ref.setEnabled(enabled);
        ref.setRef(referenceName);
        server.addResourceRef(ref, OVERWRITE);        
    
public voidcreateResourceReference(com.sun.enterprise.admin.target.TargetType[] validTypes, java.lang.String targetName, boolean enabled, java.lang.String referenceName, boolean allowSystemRefs)

        //Validate that there is indeed a resource with the specified name and
        //check to see whether we are creating or deleting a system resource
        //reference.
        final String type = validateResourceAndGetType(referenceName,
            allowSystemRefs);             
        final ConfigContext configContext = getConfigContext();
        final Target target = TargetBuilder.INSTANCE.createTarget(
            validTypes, targetName, configContext);            
        if (target.getType() == TargetType.CLUSTER) {
            final Cluster cluster = ClusterHelper.getClusterByName(configContext, target.getName());
            addResourceReferenceToCluster(cluster, enabled, referenceName);
            final Server[] servers = ServerHelper.getServersInCluster(configContext, target.getName());
            addResourceReferenceToClusteredServers(cluster, servers, enabled, referenceName);            
        } else if (target.getType() == TargetType.SERVER ||
            target.getType() == TargetType.DAS) {
            final Server server = ServerHelper.getServerByName(configContext, target.getName());
            addResourceReferenceToServer(server, enabled, referenceName);
        } else {
            throw new ConfigException(_strMgr.getString("invalidClusterOrServerTarget",
                target.getName()));
        }      
    
public voidcreateResourceReference(java.lang.String targetName, boolean enabled, java.lang.String referenceName, boolean allowSystemRefs)
Add the resource reference to the specified target (cluster or unclustered server). NOTE: Much of this functionality is duplicated in ApplicationReferenceHelper. As such be aware that bugs fixed here should be fixed there as well.

        createResourceReference(VALID_CREATE_DELETE_TYPES, targetName, enabled,
            referenceName, allowSystemRefs);
    
public voidcreateResourceReference(java.lang.String targetName, boolean enabled, java.lang.String referenceName)

        createResourceReference(targetName, enabled, referenceName, false);
    
public voidcreateResourceReference(com.sun.enterprise.admin.target.TargetType[] validTypes, java.lang.String targetName, boolean enabled, java.lang.String referenceName)

        createResourceReference(validTypes, targetName, enabled, referenceName, false);
    
public voiddeleteResourceReference(java.lang.String targetName, java.lang.String referenceName, boolean allowSystemRefs)
Delete the resource reference from the specified target (cluster or or unclustered server). NOTE: Much of this functionality is duplicated in ApplicationReferenceHelper. As such be aware that bugs fixed here should be fixed there as well.

        deleteResourceReference(VALID_CREATE_DELETE_TYPES, targetName,
            referenceName, allowSystemRefs);
    
public voiddeleteResourceReference(java.lang.String targetName, java.lang.String referenceName)

        deleteResourceReference(targetName, referenceName, false);
    
public voiddeleteResourceReference(com.sun.enterprise.admin.target.TargetType[] validTypes, java.lang.String targetName, java.lang.String referenceName)

        deleteResourceReference(validTypes, targetName, referenceName, false);
    
public voiddeleteResourceReference(com.sun.enterprise.admin.target.TargetType[] validTypes, java.lang.String targetName, java.lang.String referenceName, boolean allowSystemRefs)

                        
        //Validate that there is indeed a resource with the specified name and
        //check to see whether we are creating or deleting a system resource
        //reference.
        final String type = validateResourceAndGetType(referenceName, 
            allowSystemRefs);        
        final ConfigContext configContext = getConfigContext();
        final Target target = TargetBuilder.INSTANCE.createTarget(
            validTypes, targetName, configContext);            
        
        if (target.getType() == TargetType.SERVER ||
            target.getType() == TargetType.DAS) {
            final Server server = ServerHelper.getServerByName(configContext, target.getName());
            deleteResourceReferenceFromServer(server, referenceName);
        } else if (target.getType().equals(TargetType.CLUSTER)) {
            final Cluster cluster = ClusterHelper.getClusterByName(configContext, target.getName());
            deleteResourceReferenceFromCluster(cluster, referenceName);
            final Server[] servers = ServerHelper.getServersInCluster(configContext, target.getName());
            deleteResourceReferenceFromClusteredServers(cluster, servers, referenceName);            
        } else {
            throw new ConfigException(_strMgr.getString("invalidClusterOrServerTarget",
                target.getName()));
        }      

    
private voiddeleteResourceReferenceFromCluster(com.sun.enterprise.config.serverbeans.Cluster cluster, java.lang.String referenceName)
Delete resource reference from the cluster. NOTE: Much of this functionality is duplicated in ApplicationReferenceHelper. As such be aware that bugs fixed here should be fixed there as well.

        final ResourceRef ref = cluster.getResourceRefByRef(referenceName);
        if (ref == null) {
            //Resource ref already exists in cluster         
            throw new ConfigException(_strMgr.getString("clusterResourceRefDoesNotExist",
                cluster.getName(), referenceName));     
        }
        cluster.removeResourceRef(ref, OVERWRITE);        
    
private voiddeleteResourceReferenceFromClusteredServers(com.sun.enterprise.config.serverbeans.Cluster cluster, com.sun.enterprise.config.serverbeans.Server[] servers, java.lang.String referenceName)
Delete resource reference from the server instances that are part of the cluster. NOTE: Much of this functionality is duplicated in ApplicationReferenceHelper. As such be aware that bugs fixed here should be fixed there as well.

        for (int i = 0; i < servers.length; i++) {
            final ResourceRef ref = servers[i].getResourceRefByRef(referenceName);
            if (ref == null) {
                //This indicates that the cluster is in an inconsistent state. Some of the 
                //instances in the cluster have the ref and some do not.
                throw new ConfigException(_strMgr.getString("clusterResourceRefInconsistency",
                    referenceName, cluster.getName(), servers[i].getName()));
            }
            deleteResourceReferenceFromServer(servers[i], referenceName);
        }        
    
private voiddeleteResourceReferenceFromServer(com.sun.enterprise.config.serverbeans.Server server, java.lang.String referenceName)
Delete resource reference from a single server instance. NOTE: Much of this functionality is duplicated in ApplicationReferenceHelper. As such be aware that bugs fixed here should be fixed there as well.

        
        final ResourceRef ref = server.getResourceRefByRef(referenceName);
        if (ref == null) {
            //Resource ref already exists in server         
            throw new ConfigException(_strMgr.getString("serverResourceRefDoesNotExist",
                 server.getName(), referenceName));         
        }         
        server.removeResourceRef(ref, OVERWRITE);
    
public java.lang.StringgetResourceType(java.lang.String resourceName)
Return the resource type given the resource name. The assumption is that all resource names are unique.

        final ConfigContext configContext = getConfigContext();
        final Domain domain = ConfigAPIHelper.getDomainConfigBean(configContext);
        final Resources resources = domain.getResources();
        if (resources.getAdminObjectResourceByJndiName(resourceName) != null) {
            return ServerTags.ADMIN_OBJECT_RESOURCE;
        } else if (resources.getConnectorConnectionPoolByName(resourceName) != null) {
            return ServerTags.CONNECTOR_CONNECTION_POOL;
        } else if (resources.getConnectorResourceByJndiName(resourceName) != null) {
            return ServerTags.CONNECTOR_RESOURCE;
        } else if (resources.getCustomResourceByJndiName(resourceName) != null) {
            return ServerTags.CUSTOM_RESOURCE;
        } else if (resources.getExternalJndiResourceByJndiName(resourceName) != null) {
            return ServerTags.EXTERNAL_JNDI_RESOURCE;
        } else if (resources.getJdbcConnectionPoolByName(resourceName) != null) {
            return ServerTags.JDBC_CONNECTION_POOL;
        } else if (resources.getJdbcResourceByJndiName(resourceName) != null) {
            return ServerTags.JDBC_RESOURCE_JNDI_NAME;
        } else if (resources.getMailResourceByJndiName(resourceName) != null) {
            return ServerTags.MAIL_RESOURCE;
        } else if (resources.getPersistenceManagerFactoryResourceByJndiName(resourceName) != null) {
            return ServerTags.PERSISTENCE_MANAGER_FACTORY_RESOURCE;
        } else if (resources.getResourceAdapterConfigByResourceAdapterName(resourceName) != null) {
            return ServerTags.RESOURCE_ADAPTER_CONFIG;
        } else {            
            throw new ConfigException(_strMgr.getString("resourceDoesNotExist",
                resourceName));             
        }        
    
private java.lang.StringvalidateResourceAndGetType(java.lang.String referenceName, boolean allowSystemRefs)

        //Validate that there is indeed a resource with the specified name.  
        final String type = getResourceType(referenceName);     
        //Check to see whether we are creating or deleting a system resource
        //reference.
        if (!allowSystemRefs) {
            if (ResourceHelper.isSystemResource(getConfigContext(), referenceName)) {
                throw new ConfigException(_strMgr.getString("systemResourceRefNotAllowed",
                    referenceName));
            }
        }
        return type;