KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > deployment > phasing > UndeployFromDomainPhase


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the License). You may not use this file except in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * Header Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

23
24 /*
25  * UndeployFromDomainPhase.java
26  *
27  * Created on June 10, 2003, 1:37 PM
28  * @author sandhyae
29  * <BR> <I>$Source: /cvs/glassfish/appserv-core/src/java/com/sun/enterprise/deployment/phasing/UndeployFromDomainPhase.java,v $
30  *
31  */

32
33 package com.sun.enterprise.deployment.phasing;
34
35 import javax.management.MBeanServer JavaDoc;
36 import javax.management.ObjectName JavaDoc;
37 import com.sun.enterprise.admin.util.Assert;
38 import com.sun.enterprise.admin.common.exception.DeploymentException;
39 import com.sun.enterprise.admin.common.constant.DeploymentConstants;
40 import com.sun.enterprise.deployment.backend.Deployer;
41 import com.sun.enterprise.deployment.backend.DeployerFactory;
42 import com.sun.enterprise.deployment.backend.DeploymentRequest;
43 import com.sun.enterprise.deployment.backend.DeployableObjectType;
44 import com.sun.enterprise.deployment.backend.DeploymentEvent;
45 import com.sun.enterprise.deployment.backend.DeploymentEventType;
46 import com.sun.enterprise.deployment.backend.DeploymentEventInfo;
47 import com.sun.enterprise.deployment.backend.DeploymentLogger;
48 import com.sun.enterprise.deployment.backend.DeploymentStatus;
49 import com.sun.enterprise.admin.common.MBeanServerFactory;
50 import com.sun.enterprise.admin.common.ObjectNames;
51 import com.sun.enterprise.util.i18n.StringManager;
52
53 import java.util.logging.Level JavaDoc;
54 import java.util.logging.Logger JavaDoc;
55
56
57 /**
58  * This phase is responsible for undeploying a application/module
59  * from domain. It uses AppUndeployer, ModuleUnDeplyer[EjbModuleDeployer..etc] to
60  * undeploy and also unregisters the mbeans
61  * @author Sandhya E
62  */

63 public class UndeployFromDomainPhase extends DeploymentPhase {
64     
65     /** Deployment Logger object for this class */
66     public static final Logger sLogger = DeploymentLogger.get();
67     
68     /** string manager */
69     private static StringManager localStrings =
70         StringManager.getManager( UndeployFromDomainPhase.class );
71     
72     /**
73      * Creates a new instance of Class
74      * @param deploymentCtx DeploymentContext object
75      */

76     public UndeployFromDomainPhase(DeploymentContext deploymentCtx)
77     {
78         this.deploymentCtx = deploymentCtx;
79         this.name=UNDEPLOY;
80     }
81     
82     /**
83      * Undeploys the application using App/ModuleUnDeployers
84      * unregisters the application for domain.xml
85      * @param phaseCtx the DeploymentPhaseCtx object
86      * @throws DeploymentPhaseException
87      */

88     public void runPhase(DeploymentPhaseContext phaseCtx)
89     {
90         DeploymentStatus status = phaseCtx.getDeploymentStatus();
91         
92         DeploymentRequest req = phaseCtx.getDeploymentRequest();
93         DeploymentTarget target = (DeploymentTarget)req.getTarget();
94         String JavaDoc type = null;
95         Deployer deployer = null;
96         try{
97             if(!req.isApplication())
98             {
99                 type = DeploymentServiceUtils.getModuleTypeString(req.getType());
100             }
101             deployer = DeployerFactory.getDeployer(req);
102             deployer.doRequest();
103             
104             // create a DeploymentStatus for cleanup stage, it is a
105
// substatus of current (UndeployFromDomainPhase) deployment status
106
DeploymentStatus cleanupStatus =
107                 new DeploymentStatus(status);
108             req.setCurrentDeploymentStatus(cleanupStatus);
109
110             deployer.cleanup();
111
112             DeploymentServiceUtils.removeFromConfig(req.getName(),
113                 req.getType());
114
115             status.setStageStatus(DeploymentStatus.SUCCESS);
116
117             postPhaseNotify(getPostPhaseEvent(req));
118             
119         }catch(Throwable JavaDoc t){
120             status.setStageStatus(DeploymentStatus.FAILURE);
121             status.setStageException(t);
122             status.setStageStatusMessage(t.getMessage());
123
124             // Clean up domain.xml so that the system config is clean after the undeploy
125
try {
126                 if (deployer != null) {
127                     deployer.removePolicy();
128                 }
129                 DeploymentServiceUtils.removeFromConfig(req.getName(), req.getType());
130             } catch (Exception JavaDoc eee){}
131         }
132     }
133     
134     /**
135      * Event that will be broadcasted at the start of the phase
136      * @param req Deployment request object
137      * @return DeploymentEvent
138      */

139     protected DeploymentEvent getPrePhaseEvent(DeploymentRequest req)
140     {
141         return new DeploymentEvent(DeploymentEventType.PRE_UNDEPLOY, new DeploymentEventInfo(req));
142     }
143     
144     /**
145      * Event that will be broadcasted at the end of the phase
146      * @param req Deployment request object
147      * @return DeploymentEvent
148      */

149    protected DeploymentEvent getPostPhaseEvent(DeploymentRequest req)
150    {
151         return new DeploymentEvent(DeploymentEventType.POST_UNDEPLOY, new DeploymentEventInfo(req));
152    }
153    
154 }
155
Popular Tags