KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > deployment > client > ChangeStateAction


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.client;
25
26 import com.sun.appserv.management.client.ConnectionSource;
27 import com.sun.appserv.management.client.ProxyFactory;
28 import com.sun.enterprise.deployapi.ProgressObjectImpl;
29 import com.sun.enterprise.deployapi.SunTarget;
30 import com.sun.enterprise.deployapi.SunTargetModuleID;
31 import com.sun.enterprise.deployment.backend.DeploymentStatus;
32 import com.sun.enterprise.util.i18n.StringManager;
33
34 import java.io.IOException JavaDoc;
35 import java.util.ArrayList JavaDoc;
36
37 import javax.enterprise.deploy.shared.CommandType JavaDoc;
38 import javax.enterprise.deploy.shared.ModuleType JavaDoc;
39 import javax.enterprise.deploy.shared.StateType JavaDoc;
40 import javax.enterprise.deploy.spi.Target JavaDoc;
41 import javax.enterprise.deploy.spi.TargetModuleID JavaDoc;
42
43 public class ChangeStateAction extends ProgressObjectImpl {
44
45     public ChangeStateAction(SunTarget[] targets) {
46         super(targets);
47     }
48
49     public void run() {
50         ConnectionSource dasConnection= (ConnectionSource) args[0];
51         SunTarget[] targets = (SunTarget[]) args[1];
52         String JavaDoc moduleID = (String JavaDoc) args[2];
53         CommandType JavaDoc newState = (CommandType JavaDoc) args[3];
54         SunTarget domain = (SunTarget) args[4];
55         StringManager localStrings = StringManager.getManager(getClass());
56
57         ModuleType JavaDoc moduleType;
58         try {
59             moduleType = DeploymentClientUtils.getModuleType(
60                 dasConnection.getExistingMBeanServerConnection(), moduleID);
61         } catch (Throwable JavaDoc ioex) {
62             finalDeploymentStatus.setStageException(ioex);
63             setupForAbnormalExit(localStrings.getString("enterprise.deployment.client.unrecognized_module_type", moduleID ,ioex.getMessage()),
64                         domain);
65             return;
66         }
67         
68         boolean state = false;
69         String JavaDoc action = "Disable";
70         if (CommandType.START.equals(newState)) {
71             state = true;
72             action = "Enable";
73         }
74
75         // the target module ids in which the operation was successful
76
ArrayList JavaDoc resultTargetModuleIDs = new ArrayList JavaDoc();
77
78         for(int i=0; i<targets.length; i++) {
79             DeploymentStatus stat = new DeploymentStatus();
80             stat.setStageDescription(
81                 localStrings.getString("enterprise.deployment.client.state_change_desc", action, moduleID));
82             try {
83                 DeploymentClientUtils.changeStateOfModule(dasConnection.getExistingMBeanServerConnection(), moduleID,
84                                 ((moduleType == null) ? null : moduleType.toString()), targets[i], state);
85                 stat.setStageStatus(DeploymentStatus.SUCCESS);
86                 stat.setStageStatusMessage(
87                     localStrings.getString("enterprise.deployment.client.state_change_success", action, moduleID));
88             } catch (Throwable JavaDoc ex) {
89                 stat.setStageException(ex);
90                 stat.setStageStatus(DeploymentStatus.FAILURE);
91                 stat.setStageStatusMessage(ex.getMessage());
92             }
93             if(!checkStatusAndAddStage(targets[i], null,
94                             localStrings.getString("enterprise.deployment.client.change_state", action, moduleID, targets[i].getName()), dasConnection, stat, state)) {
95                 return;
96             }
97             resultTargetModuleIDs.add(new SunTargetModuleID(moduleID, targets[i]));
98         }
99
100         // initialize the instance variable targetModuleIDs using
101
// the successful module ids
102
this.targetModuleIDs = new TargetModuleID[resultTargetModuleIDs.size()];
103         this.targetModuleIDs =
104             (TargetModuleID[])resultTargetModuleIDs.toArray(this.targetModuleIDs);
105
106         setupForNormalExit(localStrings.getString("enterprise.deployment.client.change_state_all", action), domain);
107     }
108 }
109
Popular Tags