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: * @(#)BaseComponent.java
025: * Copyright 2004-2007 Sun Microsystems, Inc. All Rights Reserved.
026: *
027: * END_HEADER - DO NOT EDIT
028: */
029: package restart;
030:
031: import com.sun.jbi.framework.AbstractComponent;
032:
033: import java.util.logging.Logger;
034: import javax.jbi.component.Bootstrap;
035: import javax.jbi.component.ComponentContext;
036:
037: /**
038: * Base component implementation shared by restart test components.
039: *
040: * @author Sun Microsystems, Inc.
041: */
042: public class BaseComponent extends AbstractComponent implements
043: Bootstrap {
044:
045: /* ######### Component Life Cycle SPI Methods ########## */
046:
047: /**
048: * Initialize the Binding Component.
049: * @param context the JBI component context created by the JBI framework.
050: * @throws javax.jbi.JBIException if an error occurs.
051: */
052: public void init(ComponentContext context)
053: throws javax.jbi.JBIException {
054: mContext = context;
055: }
056:
057: /* ################# Bootstrap SPI Methods ################# */
058:
059: public void onUninstall() throws javax.jbi.JBIException {
060: }
061:
062: public void onInstall() throws javax.jbi.JBIException {
063:
064: }
065:
066: public void init(
067: javax.jbi.component.InstallationContext installationContext)
068: throws javax.jbi.JBIException {
069:
070: }
071:
072: public void cleanUp() throws javax.jbi.JBIException {
073:
074: }
075:
076: public javax.management.ObjectName getExtensionMBeanName() {
077: return null;
078: }
079:
080: /* ############# ServiceUnitManager SPI Methods ############# */
081:
082: /**
083: * Deploy a Service Unit.
084: * @param serviceUnitName the name of the Service Unit being deployed.
085: * @param serviceUnitRootPath the full path to the Service Unit artifact
086: * root directory.
087: * @return a deployment status message.
088: * @throws javax.jbi.management.DeploymentException if the deployment
089: * operation is unsuccessful.
090: */
091: public String deploy(String serviceUnitName,
092: String serviceUnitRootPath)
093: throws javax.jbi.management.DeploymentException {
094: return createDeployResult("deploy", true);
095: }
096:
097: /**
098: * Undeploy a Service Unit from the component.
099: * @param serviceUnitName the name of the Service Unit being undeployed.
100: * @param serviceUnitRootPath the full path to the Service Unit artifact
101: * root directory.
102: * @return an undeployment status message.
103: * @throws javax.jbi.management.DeploymentException if the undeployment
104: * operation is unsuccessful.
105: */
106: public String undeploy(String serviceUnitName,
107: String serviceUnitRootPath)
108: throws javax.jbi.management.DeploymentException {
109: return createDeployResult("undeploy", true);
110: }
111:
112: /* ##################### Utility Methods #################### */
113:
114: /** Creates a (un)deployment result string.
115: * @param task 'deploy' or 'undeploy'
116: */
117: protected String createDeployResult(String task, boolean isSuccess) {
118: return "<component-task-result xmlns=\"http://java.sun.com/xml/ns/jbi/management-message\">"
119: + "<component-name>"
120: + mComponentName
121: + "</component-name>"
122: + "<component-task-result-details>"
123: + "<task-result-details>"
124: + "<task-id>"
125: + task
126: + "</task-id>"
127: + "<task-result>"
128: + (isSuccess ? "SUCCESS" : "FAILED")
129: + "</task-result>"
130: + "</task-result-details>"
131: + "</component-task-result-details>"
132: + "</component-task-result>";
133: }
134:
135: /** Creates a component failure response with a configurable message.
136: * @param task 'deploy' or 'undeploy'
137: */
138: protected String createErrorResult(String task, String msg) {
139: return "<component-task-result xmlns=\"http://java.sun.com/xml/ns/jbi/management-message\">"
140: + "<component-name>"
141: + mComponentName
142: + "</component-name>"
143: + "<component-task-result-details>"
144: + "<task-result-details>"
145: + "<task-id>"
146: + task
147: + "</task-id>"
148: + "<task-result>"
149: + "FAILED"
150: + "</task-result>"
151: + "<message-type>ERROR</message-type>"
152: + "<task-status-msg>"
153: + "<msg-loc-info>"
154: + "<loc-token>JBIWHOOPS</loc-token>"
155: + "<loc-message>"
156: + msg
157: + "</loc-message>"
158: + "</msg-loc-info>"
159: + "</task-status-msg>"
160: + "</task-result-details>"
161: + "</component-task-result-details>"
162: + "</component-task-result>";
163: }
164: }
|