KickJava   Java API By Example, From Geeks To Geeks.

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


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 package com.sun.enterprise.deployment.phasing;
25
26 import com.sun.enterprise.deployment.backend.DeploymentStatus;
27 import com.sun.enterprise.deployment.backend.DeploymentRequest;
28 import com.sun.enterprise.deployment.backend.DeploymentLogger;
29 import com.sun.enterprise.deployment.backend.DeploymentEventInfo;
30 import com.sun.enterprise.deployment.backend.DeploymentEvent;
31 import com.sun.enterprise.deployment.backend.DeploymentEventType;
32 import com.sun.enterprise.deployment.backend.IASDeploymentException;
33 import com.sun.enterprise.deployment.util.DeploymentProperties;
34
35 import com.sun.enterprise.util.i18n.StringManager;
36 import com.sun.enterprise.resource.Resource;
37 import com.sun.enterprise.resource.ResourcesXMLParser;
38
39 import java.util.List JavaDoc;
40 import java.util.ArrayList JavaDoc;
41 import java.util.logging.Level JavaDoc;
42 import java.util.logging.Logger JavaDoc;
43
44 /**
45  * This class manages the deletion of the resources from
46  * sun-resources.xml that need to deleted prior to resource adapter unloading
47  */

48 public class PostResDeletionPhase extends ResourcePhase {
49
50     /** Deployment Logger object for this class */
51     public static final Logger sLogger = DeploymentLogger.get();
52     
53     /** string manager */
54     private static StringManager localStrings =
55         StringManager.getManager(PostResDeletionPhase.class);
56    
57     /**
58      * Creates a new instance of PostResDeletionPhase
59      * @param deploymentCtx context object for the deployment
60      */

61     public PostResDeletionPhase(DeploymentContext deploymentCtx)
62     {
63         this.deploymentCtx = deploymentCtx;
64         this.name = POST_RES_DELETION;
65     }
66
67     /**
68      * Phase specific execution logic will go in this method.
69      * Any phase implementing
70      * this class will provide its implementation for this method.
71      * @param req Deployment request object
72      * @param phaseCtx the DeploymentPhaseContext object
73      */

74     public void runPhase(DeploymentPhaseContext phaseCtx)
75     {
76         try {
77             DeploymentRequest req = phaseCtx.getDeploymentRequest();
78                                                                       
79             prePhaseNotify(getPrePhaseEvent(req));
80             doResourceOperation(req);
81             postPhaseNotify(getPostPhaseEvent(req));
82                                                                       
83             phaseCtx.getDeploymentStatus().setStageStatus(DeploymentStatus.SUCCESS);
84         } catch(Exception JavaDoc e) {
85             // add rollback logic
86
phaseCtx.getDeploymentStatus().setStageStatus(DeploymentStatus.FAILURE);
87             if (e.getCause()!=null) {
88                 phaseCtx.getDeploymentStatus().setStageException(e.getCause());
89                 phaseCtx.getDeploymentStatus().setStageStatusMessage(e.getCause().getMessage());
90             }
91         }
92     }
93                                                                       
94     /**
95      * Event that will be broadcasted at the start of the phase
96      * @param req Deployment request object
97      * @return DeploymentEvent
98      */

99     private DeploymentEvent getPrePhaseEvent(DeploymentRequest req)
100     {
101         return new DeploymentEvent(DeploymentEventType.PRE_RES_DELETE, new DeploymentEventInfo(req));
102     }
103                                                                       
104     /**
105                                                                       
106      * Event that will be broadcasted at the end of the phase
107      * @return DeploymentEvent */

108     private DeploymentEvent getPostPhaseEvent(DeploymentRequest req) {
109         return new DeploymentEvent(DeploymentEventType.POST_RES_DELETE, new DeploymentEventInfo(req));
110     }
111                                                                       
112     // redeployment for resource deletion phase is same as undeployment
113
public void handleRedeployment(List JavaDoc<String JavaDoc> targetList,
114         List JavaDoc<Resource> resourceList) throws Exception JavaDoc {
115         handleUndeployment(targetList, resourceList);
116     }
117                                                                       
118     // no op if it's deployment
119
public void handleDeployment(List JavaDoc<String JavaDoc> targetList,
120         List JavaDoc<Resource> resourceList) throws Exception JavaDoc {
121     }
122                                                                       
123     public String JavaDoc getActualAction(String JavaDoc resAction) {
124         if (resAction.equals(DeploymentProperties.RES_DEPLOYMENT)) {
125             return DeploymentProperties.RES_NO_OP;
126         } else {
127             return resAction;
128         }
129     }
130
131     public List JavaDoc<Resource> getRelevantResources(List JavaDoc<Resource> allResources) {
132         return ResourcesXMLParser.getNonConnectorResourcesList(allResources, false);
133     }
134 }
135
Popular Tags