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   * ComponentRuntime.java
27   */
28  
29  package it.imolinfo.jbi4ejb.jbi.component.runtime;
30  
31  import javax.jbi.component.Component;
32  import javax.jbi.component.ComponentLifeCycle;
33  import javax.jbi.component.ServiceUnitManager;
34  import javax.jbi.servicedesc.ServiceEndpoint;
35  
36  /**
37   * This is the Base implementation of the Component apis. Each component will
38   * extend this class to provide the component specific implemenation of the api
39   * by overriding the default implemenation or providing the implemenation of the
40   * create methods for ComponentLifecycle and ServiceUnitManager.
41   *
42   * @see javax.jbi.Component
43   *
44   * @author Sun Microsystems, Inc.
45   */
46  public abstract class ComponentRuntime implements Component {
47      /** Component LifeCycle implemenation */
48      private ComponentLifeCycle mLifeCycle;
49      /** ServiceUnitManager implemenation */
50      private ServiceUnitManager mSUManager;
51      /**
52       * constructor
53       */
54      protected  ComponentRuntime() {
55          
56          // create default logger
57          RuntimeContext.getInstance().setLogger(this.getClass().getPackage().getName(), null);
58          // create component lifecycle implementation
59          this.mLifeCycle = createComponentLifeCycle();
60          
61          if ( this.mLifeCycle == null ) {
62              // can not have a null component lifecycle. so, create default one.
63              this.mLifeCycle = new DefaultComponentLifeCycle(this);
64              
65              RuntimeHelper.logDebug(
66                  "ComponentLifeCycle is not implemented by extended runtime." +
67                  " Default ComponentLifeCycle created");
68          }
69          // create service unit manager if supported.
70          this.mSUManager = createServiceUnitManager();
71          
72          if ( this.mSUManager == null ) {
73              RuntimeHelper.logDebug("ServiceUnit Deployment is not supported in the Component");
74          }
75      }
76      
77      ///////////////////////////////////////////////////////////////////////////
78      // Component interface implemenation
79      ///////////////////////////////////////////////////////////////////////////
80      
81      /**
82       * Get the life cycle control interface for this component.
83       *
84       * @return the life cycle control interface for this component
85       * @see javax.jbi.Component#getLifeCycle()
86       */
87      public final ComponentLifeCycle getLifeCycle() {
88          return this.mLifeCycle;
89      }
90      
91      /**
92       * Get the Service Unit manager for this component.
93       *
94       * @return the <code>ServiceUnitManager</code> for this component, or
95       *         <code>null</code> if there is none.
96       * @see javax.jbi.Component#getServiceUnitManager()
97       */
98      public final ServiceUnitManager getServiceUnitManager() {
99          return this.mSUManager;
100     }
101     
102     /**
103      * Retrieves a DOM representation containing metadata which describes the
104      * service provided by this component, through the given endpoint.
105      *
106      * @param endpoint the service endpoint.
107      * @return the description for the specified service endpoint.
108      * @see javax.jbi.Component#getServiceDescription(javax.jbi.servicedesc.ServiceEndpoint)
109      */
110     public org.w3c.dom.Document getServiceDescription(ServiceEndpoint ref) {
111         return null;
112     }
113     
114     /**
115      * This method is called by JBI to check if this component, in the role of
116      * provider of the service indicated by the given exchange, can actually
117      * perform the operation desired.
118      *
119      * @param endpoint the endpoint to be used by the consumer; must be
120      *        non-null.
121      * @param exchange the proposed message exchange to be performed; must be
122      *        non-null.
123      * @return <code>true</code> if this provider component can perform the
124      *         given exchange with the described consumer.
125      */
126     public boolean isExchangeWithConsumerOkay(
127         javax.jbi.servicedesc.ServiceEndpoint endpoint,
128         javax.jbi.messaging.MessageExchange exchange) {
129         return true;
130     }
131     
132     /**
133      * This method is called by JBI to check if this component, in the role of
134      * consumer of the service indicated by the given exchange, can actually
135      * interact with the provider properly. The provider is described by the
136      * given endpoint and the service description supplied by that endpoint.
137      *
138      * @param endpoint the endpoint to be used by the provider; must be
139      *        non-null.
140      * @param exchange the proposed message exchange to be performed; must be
141      *        non-null.
142      * @return <code>true</code> if this consumer component can interact with
143      *         the described provider to perform the given exchange.
144      */
145     public boolean isExchangeWithProviderOkay(
146         javax.jbi.servicedesc.ServiceEndpoint endpoint,
147         javax.jbi.messaging.MessageExchange exchange) {
148         return true;
149     }
150     /**
151      * Resolve the given endpoint reference.
152      *
153      * @param epr the endpoint reference, in some XML dialect understood by
154      *        the appropriate component (usually a binding); must be non-null.
155      * @return the service endpoint for the EPR; <code>null</code> if the
156      *         EPR cannot be resolved by this component.
157      * @see javax.jbi.Component#resolveEndpointReference(org.w3c.dom.DocumentFragment)
158      */
159     public javax.jbi.servicedesc.ServiceEndpoint resolveEndpointReference(
160         org.w3c.dom.DocumentFragment epr) {
161         return null;
162     }
163     
164     ///////////////////////////////////////////////////////////////////////////
165     // Helper Methods
166     ///////////////////////////////////////////////////////////////////////////
167     /**
168      * return the ComponentLifeCycle implementaion. if returned null, the
169      * DefaultComponentLifeCycle will be used as the component lifecycle
170      */
171     protected abstract ComponentLifeCycle createComponentLifeCycle();
172     
173     /**
174      * if this component supports service unit deployment, then return the
175      * service unit manager, else return null
176      */
177     protected abstract ServiceUnitManager createServiceUnitManager();
178     
179 }