001: /*
002: * BEGIN_HEADER - DO NOT EDIT
003: *
004: * The contents of this file are subject to the terms
005: * of the Common Development and Distribution License
006: * (the "License"). You may not use this file except
007: * in compliance with the License.
008: *
009: * You can obtain a copy of the license at
010: * https://open-esb.dev.java.net/public/CDDLv1.0.html.
011: * See the License for the specific language governing
012: * permissions and limitations under the License.
013: *
014: * When distributing Covered Code, include this CDDL
015: * HEADER in each file and include the License file at
016: * https://open-esb.dev.java.net/public/CDDLv1.0.html.
017: * If applicable add the following below this CDDL HEADER,
018: * with the fields enclosed by brackets "[]" replaced with
019: * your own identifying information: Portions Copyright
020: * [year] [name of copyright owner]
021: */
022:
023: /*
024: * @(#)Binding2Deployer.java
025: * Copyright 2004-2007 Sun Microsystems, Inc. All Rights Reserved.
026: *
027: * END_HEADER - DO NOT EDIT
028: */
029: package com.sun.jbi.ui.cli.test.binding2.rt;
030:
031: import com.sun.jbi.management.ComponentMessageHolder;
032: import java.util.HashMap;
033: import java.util.Map;
034: import java.util.logging.Level;
035: import javax.jbi.component.ServiceUnitManager;
036: import javax.jbi.management.DeploymentException;
037:
038: /**
039: * fix it
040: * @author Sun Microsystems, Inc.
041: */
042: public class Binding2Deployer implements ServiceUnitManager {
043: /**
044: * fix it
045: */
046: private Binding2Runtime mContext;
047: /**
048: * fix it
049: */
050: private Map mDeployMap;
051:
052: /**
053: * Creates a new instance of Binding1Deployer
054: * @param ctx fix it
055: */
056: public Binding2Deployer(Binding2Runtime ctx) {
057: this .mDeployMap = new HashMap();
058:
059: this .mContext = ctx;
060: }
061:
062: /**
063: * fix it
064: * @param asaId fix it
065: * @param asaJarPath fix it
066: * @throws DeploymentException fix it
067: * @return fix it
068: */
069: public String deploy(String asaId, String asaJarPath)
070: throws DeploymentException {
071: String asaInfo = (String) this .mDeployMap.get(asaId);
072: if (asaInfo != null) {
073: // throw already exists
074: String exMsg = createExceptionMessage(
075: this .mContext.getId(), "deploy", "FAILED",
076: "cli_B2_0001", asaId, "ASA " + asaId
077: + " Already Exists", null);
078: throw new DeploymentException(exMsg);
079: } else {
080: this .mDeployMap.put(asaId, asaJarPath);
081: // return "Deployed " + asaId;
082: try {
083: ComponentMessageHolder compMsgHolder = new ComponentMessageHolder(
084: "STATUS_MSG");
085: compMsgHolder.setComponentName(this .mContext.getId());
086: compMsgHolder.setTaskName("deploy");
087: compMsgHolder.setTaskResult("SUCCESS");
088:
089: return this .mContext.getMgmtMsgBuilder()
090: .buildComponentMessage(compMsgHolder);
091:
092: } catch (Exception ex) {
093: ex.printStackTrace();
094: return null;
095: }
096: }
097: }
098:
099: /**
100: * fix it
101: * @param asaId fix it
102: * @return fix it
103: */
104: public String getDeploymentInfo(String asaId) {
105: // Should throw exception if asaId not exists
106: return (String) this .mDeployMap.get(asaId);
107: }
108:
109: /**
110: * fix it
111: * @return fix it
112: */
113: public String[] getDeployments() {
114: return (String[]) this .mDeployMap.keySet().toArray(
115: new String[0]);
116: }
117:
118: /**
119: * fix it
120: * @param asaId fix it
121: * @return fix it
122: */
123: public boolean isDeployed(String asaId) {
124: return (this .mDeployMap.get(asaId) != null);
125: }
126:
127: /**
128: * fix it
129: * @param asaId fix it
130: * @throws DeploymentException fix it
131: * @return fix it
132: */
133: public String undeploy(String asaId, String asaJarPath)
134: throws DeploymentException {
135: String asaInfo = (String) this .mDeployMap.remove(asaId);
136: if (asaInfo == null) {
137: // throw exception
138: String exMsg = createExceptionMessage(
139: this .mContext.getId(), "undeploy", "FAILED",
140: "cli_B2_0002", asaId, "ASA with " + asaId
141: + " Not Found", null);
142: throw new DeploymentException(exMsg);
143: } else {
144: // return "Undeployed " + asaId;
145: try {
146: ComponentMessageHolder compMsgHolder = new ComponentMessageHolder(
147: "STATUS_MSG");
148: compMsgHolder.setComponentName(this .mContext.getId());
149: compMsgHolder.setTaskName("undeploy");
150: compMsgHolder.setTaskResult("SUCCESS");
151:
152: return this .mContext.getMgmtMsgBuilder()
153: .buildComponentMessage(compMsgHolder);
154:
155: /*
156: return this.mContext.getMgmtMsgBuilder().buildComponentTaskStatusMessage(
157: this.mContext.getId(),
158: "undeploy","SUCCESS", null
159: );
160: */
161: } catch (Exception ex) {
162: ex.printStackTrace();
163: return null;
164: }
165: }
166: }
167:
168: /**
169: * helper method to create XML exception string.
170: *
171: * @param compid Component id.
172: * @param oper operation like deploy or undeploy
173: * @param status success r failure
174: * @param loctoken some failure string token like SEQ_300001
175: * @param locparam parameters for error message.
176: * @param locmessage error message.
177: * @param stckTrElem stack trace of exception.
178: *
179: * @return XML string.
180: */
181: private String createExceptionMessage(String compid, String oper,
182: String status, String loctoken, String locparam,
183: String locmessage, Throwable exObj) {
184: String[] locParams = new String[1];
185: locParams[0] = locparam;
186:
187: ComponentMessageHolder msgMap = new ComponentMessageHolder(
188: "EXCEPTION_MSG");
189:
190: msgMap.setComponentName(compid);
191: msgMap.setTaskName(oper);
192: msgMap.setTaskResult(status);
193: msgMap.setLocToken(1, loctoken);
194: msgMap.setLocParam(1, locParams);
195: msgMap.setLocMessage(1, locmessage);
196: msgMap.setExceptionObject(exObj);
197:
198: /*
199: msgMap.put("COMPONENTID", compid);
200: msgMap.put("TASKIDENTIFIER", oper);
201: msgMap.put("TASKRSLTSTATUS", status);
202: msgMap.put("COMPONENTEXLOCTOKEN", loctoken);
203: msgMap.put("COMPONENTEXLOCPARAM", locparam);
204: msgMap.put("COMPONENTEXLOCMESSAGE", locmessage);
205: msgMap.put("COMPONENTEXSTACKTRACE", sb.toString());
206: */
207:
208: String retMsg = null;
209:
210: try {
211: retMsg = this .mContext.getMgmtMsgBuilder()
212: .buildComponentMessage(msgMap);
213: } catch (Exception e) {
214: this .mContext.getLogger().log(Level.INFO,
215: "Failed to create Mgmt Msg", e);
216: }
217:
218: return retMsg;
219: }
220:
221: /**
222: * Initialize the deployment. This is the first phase of a two-phase
223: * start, where the component must prepare to receive service requests
224: * related to the deployment (if any).
225: * @param serviceUnitName the name of the Service Unit being initialized.
226: * @param serviceUnitRootPath the full path to the Service Unit artifact
227: * root directory.
228: * @throws javax.jbi.management.DeploymentException if the Service Unit is
229: * not deployed, or is in an incorrect state.
230: */
231: public void init(String serviceUnitName, String serviceUnitRootPath)
232: throws javax.jbi.management.DeploymentException {
233: }
234:
235: /**
236: * Shut down the deployment. This causes the deployment to return to the
237: * state it was in after <code>deploy()</code> and before <code>init()</code>.
238: * @param serviceUnitName the name of the Service Unit being shut down.
239: * @throws javax.jbi.management.DeploymentException if the Service Unit
240: * is not deployed, or is in an incorrect state.
241: */
242: public void shutDown(String serviceUnitName)
243: throws javax.jbi.management.DeploymentException {
244: }
245:
246: /**
247: * Start the deployment. This is the second phase of a two-phase start,
248: * where the component can now initiate service requests related to the
249: * deployment.
250: * @param serviceUnitName the name of the Service Unit being started.
251: * @throws javax.jbi.management.DeploymentException if the Service Unit
252: * is not deployed, or is in an incorrect state.
253: */
254: public void start(String serviceUnitName)
255: throws javax.jbi.management.DeploymentException {
256: }
257:
258: /**
259: * Stop the deployment. This causes the component to cease generating
260: * service requests related to the deployment. This returns the deployment
261: * to a state equivalent to after <code>init()</code> was called.
262: * @param serviceUnitName the name of the Service Unit being stopped.
263: * @throws javax.jbi.management.DeploymentException if the Service Unit
264: * is not deployed, or is in an incorrect state.
265: */
266: public void stop(String serviceUnitName)
267: throws javax.jbi.management.DeploymentException {
268: }
269:
270: }
|