View Javadoc

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
5    * in compliance with the License.
6    *
7    * You can obtain a copy of the license at
8    * https://open-esb.dev.java.net/public/CDDLv1.0.html.
9    * See the License for the specific language governing
10   * permissions and limitations under the License.
11   *
12   * When distributing Covered Code, include this CDDL
13   * HEADER in each file and include the License file at
14   * https://open-esb.dev.java.net/public/CDDLv1.0.html.
15   * If applicable add the following below this CDDL HEADER,
16   * with the fields enclosed by brackets "[]" replaced with
17   * your own identifying information: Portions Copyright
18   * [year] [name of copyright owner]
19   */
20  
21  /*
22   * Copyright 2004-2006 Sun Microsystems, Inc. All Rights Reserved.
23   */
24  
25  /*
26   * DefaultServiceUnitManager.java
27   *
28   */
29  
30  package it.imolinfo.jbi4ejb.jbi.component.runtime;
31  
32  import it.imolinfo.jbi4ejb.Logger;
33  import it.imolinfo.jbi4ejb.LoggerFactory;
34  import it.imolinfo.jbi4ejb.jbi.Messages;
35  
36  import javax.jbi.component.ServiceUnitManager;
37  import javax.jbi.management.DeploymentException;
38  import javax.jbi.messaging.MessagingException;
39  
40  /**
41   * Default Service Unit Manager implementation. Component's supporting the
42   * deployment should extend this class to support the service unit deployment.
43   *
44   * @see javax.jbi.ServiceUnitManager
45   *
46   * @author Sun Microsystems, Inc.
47   */
48  public class DefaultServiceUnitManager implements ServiceUnitManager {
49  	/** The logger. */
50      private static final Logger LOG = LoggerFactory.getLogger( DefaultServiceUnitManager.class);    
51      private static final Messages MESSAGES = Messages.getMessages( DefaultServiceUnitManager.class);   
52      /**
53       * Component runtime as context
54       */
55      private ComponentRuntime mContext;
56      /** private constructor */
57      private DefaultServiceUnitManager() {}
58      /**
59       * constructor that takes the compoent runtime
60       */
61      public DefaultServiceUnitManager(ComponentRuntime ctx) {
62          this.mContext = ctx;
63      }
64      ///////////////////////////////////////////////////////////////////////////
65      // Service Unit Deployment methods implementation
66      ///////////////////////////////////////////////////////////////////////////
67      
68      /**
69       * Deploy a Service Unit to the component.
70       * @see javax.jbi.component.ServiceUnitManager#deploy(String, String);
71       */
72      public String deploy(String suName, String suZipPath) throws DeploymentException {
73          boolean isSuccess = false;
74          String msg=MESSAGES.getString("EJB000216_Service_unit_deployment_not_supported_for_this_component");
75          LOG.error(msg);
76          throw new DeploymentException(msg);
77          
78      }
79      /**
80       * Undeploy a service unit from the component.
81       * @see javax.jbi.component.ServiceUnitManager#undeploy(String, String);
82       */
83      public String undeploy(String suName, String suZipPath) throws DeploymentException {
84          boolean isSuccess = false;
85          String msg=MESSAGES.getString("EJB000216_Service_unit_deployment_not_supported_for_this_component");
86          LOG.error(msg);
87          throw new DeploymentException(msg);
88      }
89      
90      ///////////////////////////////////////////////////////////////////////////
91      // Service Unit Lifecycle Management methods implementation
92      ///////////////////////////////////////////////////////////////////////////
93      /**
94       * Initialize the given deployed service unit.
95       * @see javax.jbi.component.ServiceUnitManager#init(String, String);     */
96      public void init(String serviceUnitName, String serviceUnitRootPath)
97      throws javax.jbi.management.DeploymentException {
98          boolean isSuccess = false;
99          String msg=MESSAGES.getString("EJB000216_Service_unit_deployment_not_supported_for_this_component");
100         LOG.error(msg);
101         throw new DeploymentException(msg);
102     }
103     /**
104      * Shut down the deployment.
105      * @see javax.jbi.component.ServiceUnitManager#shutdown(String);
106      */
107     public void shutDown(String serviceUnitName)
108     throws javax.jbi.management.DeploymentException {
109         boolean isSuccess = false;
110         String msg=MESSAGES.getString("EJB000216_Service_unit_deployment_not_supported_for_this_component");
111         LOG.error(msg);
112         throw new DeploymentException(msg);
113     }
114     /**
115      * Start the deployed service unit.
116      * @see javax.jbi.component.ServiceUnitManager#start(String);
117      */
118     public void start(String serviceUnitName)
119     throws javax.jbi.management.DeploymentException {
120         boolean isSuccess = false;
121         String msg=MESSAGES.getString("EJB000216_Service_unit_deployment_not_supported_for_this_component");
122         LOG.error(msg);
123         throw new DeploymentException(msg);
124     }
125     /**
126      * Stop the deployed service unit.
127      * @see javax.jbi.component.ServiceUnitManager#stop(String);
128      */
129     public void stop(String serviceUnitName)
130     throws javax.jbi.management.DeploymentException {
131         boolean isSuccess = false;
132         String msg=MESSAGES.getString("EJB000216_Service_unit_deployment_not_supported_for_this_component");
133         LOG.error(msg);
134         throw new DeploymentException(msg);
135     }
136     
137     ///////////////////////////////////////////////////////////////////////////
138     // Helper methods
139     ///////////////////////////////////////////////////////////////////////////
140     
141     /**
142      * helper method to create result message in management message xml.
143      * @param message message string to return
144      * @param isSuccess true to format a sucess result, false to format a failed result.
145      * @return XML string.
146      */
147     protected String createComponentTaskResultXML(String message, boolean isSuccess) {
148         
149         String taskResult = isSuccess ? "SUCCESS" : "FAILED";
150         String msgType = isSuccess ? "INFO" : "ERROR";
151         String componentName = RuntimeHelper.getComponentName();
152         
153         String xmlResult =
154             "<component-task-result xmlns=\"http://java.sun.com/xml/ns/jbi/management-message\" >" +
155             "  <component-name>" + componentName + "</component-name>" +
156             "  <component-task-result-details >" +
157             "      <task-result-details>" +
158             "          <task-id>deployment</task-id>" +
159             "          <task-result>" + taskResult + "</task-result>" +
160             "          <message-type>" + msgType + "</message-type>" +
161             "          <task-status-msg>" +
162             "             <msg-loc-info>" +
163             "                <loc-token>MSG_ID_000</loc-token>" +
164             "                <loc-message>" + message + "</loc-message>" +
165             "              </msg-loc-info>" +
166             "          </task-status-msg>" +
167             "      </task-result-details>" +
168             "  </component-task-result-details>" +
169             "</component-task-result>";
170         
171         return xmlResult;
172     }
173     
174 }