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: * @(#)DeployBinding.java
025: * Copyright 2004-2007 Sun Microsystems, Inc. All Rights Reserved.
026: *
027: * END_HEADER - DO NOT EDIT
028: */
029: package deploytest;
030:
031: import java.util.logging.Logger;
032:
033: import javax.jbi.component.Bootstrap;
034: import javax.jbi.component.Component;
035: import javax.jbi.component.ComponentContext;
036: import javax.jbi.component.ComponentLifeCycle;
037: import javax.jbi.component.ServiceUnitManager;
038:
039: /**
040: * Dummy binding component used to test deployment.
041: *
042: * @author Sun Microsystems, Inc.
043: */
044: public class DeployBinding implements Component, ComponentLifeCycle,
045: ServiceUnitManager, Bootstrap {
046: /**
047: * Local copy of the component name.
048: */
049: protected String mComponentName;
050:
051: /**
052: * Type of component.
053: */
054: protected String mComponentType = "Binding";
055:
056: /**
057: * Local handle to the ComponentContext.
058: */
059: protected ComponentContext mContext;
060:
061: /**
062: * Logger instance.
063: */
064: protected Logger mLog = Logger.getLogger("com.sun.jbi.management");
065:
066: //
067: // Component methods
068: //
069:
070: /**
071: * Get the ComponentLifeCycle implementation instance for this Binding
072: * Component.
073: * @return the life cycle implementation instance.
074: */
075: public ComponentLifeCycle getLifeCycle() {
076: mLog.info(mComponentType + " getLifeCycle called");
077: return this ;
078: }
079:
080: /**
081: * Get the ServiceUnitManager implementation instance for this Binding
082: * Component.
083: * @return the Service Unit manager implementation instance.
084: */
085: public ServiceUnitManager getServiceUnitManager() {
086: mLog.info(mComponentType + " " + mComponentName
087: + " getServiceUnitManager called");
088: return this ;
089: }
090:
091: /**
092: * Resolve descriptor details for the specified reference, which is for a
093: * service provided by this component.
094: * @param ref the endpoint reference to be resolved.
095: * @return the description for the specified reference.
096: */
097: public org.w3c.dom.Document getServiceDescription(
098: javax.jbi.servicedesc.ServiceEndpoint ref) {
099: mLog.info(mComponentType + " " + mComponentName
100: + " getServiceDescription called");
101: return null;
102: }
103:
104: /**
105: * This method is called by JBI to check if this component, in the role of
106: * provider of the service indicated by the given exchange, can actually
107: * perform the operation desired.
108: */
109: public boolean isExchangeWithConsumerOkay(
110: javax.jbi.servicedesc.ServiceEndpoint endpoint,
111: javax.jbi.messaging.MessageExchange exchange) {
112: mLog.info(mComponentType + " " + mComponentName
113: + " isExchangeWithConsumerOkay called");
114: return true;
115: }
116:
117: /**
118: * This method is called by JBI to check if this component, in the role of
119: * consumer of the service indicated by the given exchange, can actually
120: * interact with the the provider completely.
121: */
122: public boolean isExchangeWithProviderOkay(
123: javax.jbi.servicedesc.ServiceEndpoint endpoint,
124: javax.jbi.messaging.MessageExchange exchange) {
125: mLog.info(mComponentType + " " + mComponentName
126: + " isExchangeWithProviderOkay called");
127: return true;
128: }
129:
130: /**
131: * Resolve the given endpoint reference, given the capabilities of the
132: * given consumer. This is called by JBI when it is attempting to resolve
133: * the given endpoint reference on behalf of a component.
134: * @param epr the endpoint reference, in some XML dialect understood by the
135: * appropriate component (usually a Binding Component).
136: * @return the service endpoint for the endpoint reference;
137: * <code>null</code> if the endpoint reference cannot be resolved.
138: */
139: public javax.jbi.servicedesc.ServiceEndpoint resolveEndpointReference(
140: org.w3c.dom.DocumentFragment epr) {
141: mLog.info(mComponentType + " " + mComponentName
142: + " resolveEndpointReference called");
143: return null;
144: }
145:
146: //
147: // ComponentLifeCycle methods
148: //
149:
150: /**
151: * Initialize the Binding Component.
152: * @param context the JBI component context created by the JBI framework.
153: * @throws javax.jbi.JBIException if an error occurs.
154: */
155: public void init(ComponentContext context)
156: throws javax.jbi.JBIException {
157: mComponentName = context.getComponentName();
158: }
159:
160: /**
161: * Get the JMX ObjectName for any additional MBean for this BC. This
162: * implementation always returns null.
163: * @return javax.management.ObjectName is always null.
164: */
165: public javax.management.ObjectName getExtensionMBeanName() {
166: mLog.info(mComponentType + " " + mComponentName
167: + " getExtensionMBeanName called");
168: return null;
169: }
170:
171: /**
172: * Start the Binding Component.
173: * @throws javax.jbi.JBIException if an error occurs.
174: */
175: public void start() throws javax.jbi.JBIException {
176: mLog.info(mComponentType + " " + mComponentName
177: + " start called");
178: }
179:
180: /**
181: * Stop the Binding Component.
182: * @throws javax.jbi.JBIException if an error occurs.
183: */
184: public void stop() throws javax.jbi.JBIException {
185: mLog.info(mComponentType + " " + mComponentName
186: + " stop called");
187: }
188:
189: /**
190: * Shut down the Binding Component.
191: * @throws javax.jbi.JBIException if an error occurs.
192: */
193: public void shutDown() throws javax.jbi.JBIException {
194: mLog.info(mComponentType + " " + mComponentName
195: + " shutDown called");
196: }
197:
198: //
199: // ServiceUnitManager methods
200: //
201:
202: /**
203: * Deploy a Service Unit.
204: * @param serviceUnitName the name of the Service Unit being deployed.
205: * @param serviceUnitRootPath the full path to the Service Unit artifact
206: * root directory.
207: * @return a deployment status message.
208: * @throws javax.jbi.management.DeploymentException if the deployment
209: * operation is unsuccessful.
210: */
211: public String deploy(String serviceUnitName,
212: String serviceUnitRootPath)
213: throws javax.jbi.management.DeploymentException {
214: mLog.info(mComponentType + " " + mComponentName
215: + " deployed Service Unit " + serviceUnitName);
216:
217: return createDeployResult("deploy", true);
218: }
219:
220: /**
221: * Initialize the deployment.
222: * @param serviceUnitName the name of the Service Unit being initialized.
223: * @param serviceUnitRootPath the full path to the Service Unit artifact
224: * root directory.
225: * @throws javax.jbi.management.DeploymentException if the Service Unit is
226: * not deployed, or is in an incorrect state.
227: */
228: public void init(String serviceUnitName, String serviceUnitRootPath)
229: throws javax.jbi.management.DeploymentException {
230: mLog.info(mComponentType + " " + mComponentName
231: + " initialized Service Unit " + serviceUnitName);
232: }
233:
234: /**
235: * Shut down the deployment.
236: * @param serviceUnitName the name of the Service Unit being shut down.
237: * @throws javax.jbi.management.DeploymentException if the Service Unit
238: * is not deployed, or is in an incorrect state.
239: */
240: public void shutDown(String serviceUnitName)
241: throws javax.jbi.management.DeploymentException {
242: mLog.info(mComponentType + " " + mComponentName
243: + " shut down Service Unit " + serviceUnitName);
244: }
245:
246: /**
247: * Start the deployment.
248: * @param serviceUnitName the name of the Service Unit being started.
249: * @throws javax.jbi.management.DeploymentException if the Service Unit
250: * is not deployed, or is in an incorrect state.
251: */
252: public void start(String serviceUnitName)
253: throws javax.jbi.management.DeploymentException {
254: mLog.info(mComponentType + " " + mComponentName
255: + " started Service Unit " + serviceUnitName);
256: }
257:
258: /**
259: * Stop the deployment.
260: * @param serviceUnitName the name of the Service Unit being stopped.
261: * @throws javax.jbi.management.DeploymentException if the Service Unit
262: * is not deployed, or is in an incorrect state.
263: */
264: public void stop(String serviceUnitName)
265: throws javax.jbi.management.DeploymentException {
266: mLog.info(mComponentType + " " + mComponentName
267: + " stopped Service Unit " + serviceUnitName);
268: }
269:
270: /**
271: * Undeploy a Service Unit from the component.
272: * @param serviceUnitName the name of the Service Unit being undeployed.
273: * @param serviceUnitRootPath the full path to the Service Unit artifact
274: * root directory.
275: * @return an undeployment status message.
276: * @throws javax.jbi.management.DeploymentException if the undeployment
277: * operation is unsuccessful.
278: */
279: public String undeploy(String serviceUnitName,
280: String serviceUnitRootPath)
281: throws javax.jbi.management.DeploymentException {
282: mLog.info(mComponentType + " " + mComponentName
283: + " undeployed Service Unit " + serviceUnitName);
284: return createDeployResult("undeploy", true);
285: }
286:
287: public void onUninstall() throws javax.jbi.JBIException {
288: }
289:
290: public void onInstall() throws javax.jbi.JBIException {
291:
292: }
293:
294: public void init(
295: javax.jbi.component.InstallationContext installationContext)
296: throws javax.jbi.JBIException {
297:
298: }
299:
300: public void cleanUp() throws javax.jbi.JBIException {
301:
302: }
303:
304: /** Creates a (un)deployment result string.
305: * @param task 'deploy' or 'undeploy'
306: */
307: private String createDeployResult(String task, boolean isSuccess) {
308: return "<component-task-result xmlns=\"http://java.sun.com/xml/ns/jbi/management-message\">"
309: + "<component-name>"
310: + mComponentName
311: + "</component-name>"
312: + "<component-task-result-details>"
313: + "<task-result-details>"
314: + "<task-id>"
315: + task
316: + "</task-id>"
317: + "<task-result>"
318: + (isSuccess ? "SUCCESS" : "FAILURE")
319: + "</task-result>"
320: + "</task-result-details>"
321: + "</component-task-result-details>"
322: + "</component-task-result>";
323: }
324: }
|