FileDocCategorySizeDatePackage
ResourcePhase.javaAPI DocGlassfish v2 API9845Fri May 04 22:34:38 BST 2007com.sun.enterprise.deployment.phasing

ResourcePhase

public abstract class ResourcePhase extends DeploymentPhase
This class is the base class for resource phases

Fields Summary
protected static final String
resourcesMBeanName
protected static final String
CREATE_RESOURCE
protected static final String
CREATE_RESOURCE_REF
protected static final String
CREATE_RESOURCE_AND_REF
protected static final String
DELETE_RESOURCE
protected static final String
DELETE_RESOURCE_REF
protected static final String
DELETE_RESOURCE_AND_REF
protected static final String
DOMAIN_TARGET
protected MBeanServer
mbs
private static final Logger
sLogger
Deployment Logger object for this class
Constructors Summary
Methods Summary
protected voiddoResourceOperation(com.sun.enterprise.deployment.backend.DeploymentRequest req)


          
        String targetListString = req.getResourceTargetList();
        List<String> targetList = DeploymentServiceUtils.getTargetNamesFromTargetString(targetListString);

        String resourceAction = req.getResourceAction();
        if (resourceAction == null || 
            getActualAction(resourceAction).equals(
                DeploymentProperties.RES_NO_OP)) {
            return;
        }

        if (targetList == null || targetList.isEmpty()) {
            return;
        }

        List<Resource> resourceList = DeploymentServiceUtils.getResourceList(
            req, getForceParsing(resourceAction), deploymentCtx);

        // empty resource list, no resource to process
        if (resourceList.size() == 0) {
            return;
        }

        handleResources(resourceAction, targetList, 
            getRelevantResources(resourceList)); 
    
protected java.lang.StringgetActualAction(java.lang.String resAction)

        return resAction;
    
protected booleangetForceParsing(java.lang.String resAction)

        return false;
    
protected abstract java.util.ListgetRelevantResources(java.util.List allResources)

protected voidhandleCreateApplicationRef(java.util.List targetList, java.util.List resourceList)

        ObjectName mbeanName = new ObjectName(resourcesMBeanName);
        String[] signature = new String[]{
            "java.util.List", "java.util.List", "java.lang.Boolean"};
        Object[] params = new Object[]{resourceList, targetList, 
            Boolean.TRUE};
        mbs.invoke(mbeanName, CREATE_RESOURCE_REF, params, signature);
    
protected voidhandleDeleteApplicationRef(java.util.List targetList, java.util.List resourceList)

        ObjectName mbeanName = new ObjectName(resourcesMBeanName);
        String[] signature = new String[]{
            "java.util.List", "java.util.List"};
        Object[] params = new Object[]{resourceList, targetList};
        mbs.invoke(mbeanName, DELETE_RESOURCE_REF, params, signature);
    
protected voidhandleDeployment(java.util.List targetList, java.util.List resourceList)

        ObjectName mbeanName = new ObjectName(resourcesMBeanName);

        // if target is domain, only create resource
        if (targetList.size() == 1 &&
            targetList.get(0).equals(DOMAIN_TARGET)) {
            String[] signature = new String[]{
                "java.util.List", "java.lang.Boolean"};
            Object[] params = new Object[]{resourceList, Boolean.TRUE};
            mbs.invoke(mbeanName, CREATE_RESOURCE, params, signature);
        } else {
            String[] signature = new String[]{
                "java.util.List", "java.util.List", "java.lang.Boolean"};
            Object[] params = new Object[]{resourceList, targetList, 
                Boolean.TRUE};
            mbs.invoke(mbeanName, CREATE_RESOURCE_AND_REF, params, signature);
        }
    
protected abstract voidhandleRedeployment(java.util.List targetList, java.util.List resourceList)

protected voidhandleResources(java.lang.String resourceAction, java.util.List targetList, java.util.List resourceList)


        // empty sub resource list, no resource to process
        if (resourceList.size() == 0) {
            return;
        }

        if (resourceAction.equals(DeploymentProperties.RES_DEPLOYMENT)) {
            handleDeployment(targetList, resourceList);
        } else if (resourceAction.equals(DeploymentProperties.RES_CREATE_REF)){
            handleCreateApplicationRef(targetList, resourceList);
        } else if (resourceAction.equals(DeploymentProperties.RES_DELETE_REF)){
            handleDeleteApplicationRef(targetList, resourceList);
        } else if (resourceAction.equals(
            DeploymentProperties.RES_UNDEPLOYMENT)){
            handleUndeployment(targetList, resourceList);
        } else if (resourceAction.equals(
            DeploymentProperties.RES_REDEPLOYMENT)){
            handleRedeployment(targetList, resourceList);
        }

        // flush the config and send the events here
        DeploymentServiceUtils.flushConfigAndSendEvents();
    
protected voidhandleUndeployment(java.util.List targetList, java.util.List resourceList)

        try {
            ObjectName mbeanName = new ObjectName(resourcesMBeanName);

            // if target is domain, only delete resource
            if (targetList.size() == 1 &&
                targetList.get(0).equals(DOMAIN_TARGET)) {
                String[] signature = new String[]{"java.util.List"};
                Object[] params = new Object[]{resourceList};
                mbs.invoke(mbeanName,DELETE_RESOURCE, params, signature);
            } else {
                String[] signature = new String[]{
                    "java.util.List", "java.util.List"};
                Object[] params = new Object[]{resourceList, targetList};
                mbs.invoke(mbeanName, DELETE_RESOURCE_AND_REF, params, signature);
            }
        } catch (Exception e) {
            // we will just log the exception as warning message and will not 
            // fail undeployment
            sLogger.log(Level.WARNING, e.getMessage(), e);
        }