View Javadoc

1    /****************************************************************************
2    * Copyright (c) 2005, 2006, 2007, 2008, 2009 Imola Informatica.
3    * All rights reserved. This program and the accompanying materials
4    * are made available under the terms of the LGPL License v2.1
5    * which accompanies this distribution, and is available at
6    * http://www.gnu.org/licenses/lgpl.html
7    ****************************************************************************/
8   /*
9    * ComponentRuntime.java
10   */
11  
12  package it.imolinfo.jbi4corba.jbi.component.runtime;
13  
14  import javax.jbi.component.Component;
15  import javax.jbi.component.ComponentLifeCycle;
16  import javax.jbi.component.ServiceUnitManager;
17  import javax.jbi.servicedesc.ServiceEndpoint;
18  
19  /**
20   * This is the Base implementation of the Component apis. Each component will
21   * extend this class to provide the component specific implemenation of the api
22   * by overriding the default implemenation or providing the implemenation of the
23   * create methods for ComponentLifecycle and ServiceUnitManager.
24   *
25   * @see javax.jbi.Component
26   *
27   * @author <a href="mailto:mpiraccini@imolinfo.it">Marco Piraccini</a>
28   */
29  public abstract class ComponentRuntime implements Component {
30      /** Component LifeCycle implemenation */
31      private ComponentLifeCycle mLifeCycle;
32      /** ServiceUnitManager implemenation */
33      private ServiceUnitManager mSUManager;
34      /**
35       * constructor
36       */
37      protected  ComponentRuntime() {
38          
39          // create default logger
40          RuntimeContext.getInstance().setLogger(this.getClass().getPackage().getName(), null);
41          // create component lifecycle implementation
42          this.mLifeCycle = createComponentLifeCycle();
43          
44          if ( this.mLifeCycle == null ) {
45              // can not have a null component lifecycle. so, create default one.
46              this.mLifeCycle = new DefaultComponentLifeCycle(this);
47              
48              RuntimeHelper.logDebug(
49                  "ComponentLifeCycle is not implemented by extended runtime." +
50                  " Default ComponentLifeCycle created");
51          }
52          // create service unit manager if supported.
53          this.mSUManager = createServiceUnitManager();
54          
55          if ( this.mSUManager == null ) {
56              RuntimeHelper.logDebug("ServiceUnit Deployment is not supported in the Component");
57          }
58      }
59      
60      ///////////////////////////////////////////////////////////////////////////
61      // Component interface implemenation
62      ///////////////////////////////////////////////////////////////////////////
63      
64      /**
65       * Get the life cycle control interface for this component.
66       *
67       * @return the life cycle control interface for this component
68       * @see javax.jbi.Component#getLifeCycle()
69       */
70      public final ComponentLifeCycle getLifeCycle() {
71          return this.mLifeCycle;
72      }
73      
74      /**
75       * Get the Service Unit manager for this component.
76       *
77       * @return the <code>ServiceUnitManager</code> for this component, or
78       *         <code>null</code> if there is none.
79       * @see javax.jbi.Component#getServiceUnitManager()
80       */
81      public final ServiceUnitManager getServiceUnitManager() {
82          return this.mSUManager;
83      }
84      
85      /**
86       * Retrieves a DOM representation containing metadata which describes the
87       * service provided by this component, through the given endpoint.
88       *
89       * @param endpoint the service endpoint.
90       * @return the description for the specified service endpoint.
91       * @see javax.jbi.Component#getServiceDescription(javax.jbi.servicedesc.ServiceEndpoint)
92       */
93      public org.w3c.dom.Document getServiceDescription(ServiceEndpoint ref) {        
94          return null;
95      }
96      
97      /**
98       * This method is called by JBI to check if this component, in the role of
99       * provider of the service indicated by the given exchange, can actually
100      * perform the operation desired.
101      *
102      * @param endpoint the endpoint to be used by the consumer; must be
103      *        non-null.
104      * @param exchange the proposed message exchange to be performed; must be
105      *        non-null.
106      * @return <code>true</code> if this provider component can perform the
107      *         given exchange with the described consumer.
108      */
109     public boolean isExchangeWithConsumerOkay(
110         javax.jbi.servicedesc.ServiceEndpoint endpoint,
111         javax.jbi.messaging.MessageExchange exchange) {
112         return true;
113     }
114     
115     /**
116      * This method is called by JBI to check if this component, in the role of
117      * consumer of the service indicated by the given exchange, can actually
118      * interact with the provider properly. The provider is described by the
119      * given endpoint and the service description supplied by that endpoint.
120      *
121      * @param endpoint the endpoint to be used by the provider; must be
122      *        non-null.
123      * @param exchange the proposed message exchange to be performed; must be
124      *        non-null.
125      * @return <code>true</code> if this consumer component can interact with
126      *         the described provider to perform the given exchange.
127      */
128     public boolean isExchangeWithProviderOkay(
129         javax.jbi.servicedesc.ServiceEndpoint endpoint,
130         javax.jbi.messaging.MessageExchange exchange) {
131         return true;
132     }
133     /**
134      * Resolve the given endpoint reference.
135      *
136      * @param epr the endpoint reference, in some XML dialect understood by
137      *        the appropriate component (usually a binding); must be non-null.
138      * @return the service endpoint for the EPR; <code>null</code> if the
139      *         EPR cannot be resolved by this component.
140      * @see javax.jbi.Component#resolveEndpointReference(org.w3c.dom.DocumentFragment)
141      */
142     public javax.jbi.servicedesc.ServiceEndpoint resolveEndpointReference(
143         org.w3c.dom.DocumentFragment epr) {
144         return null;
145     }
146     
147     ///////////////////////////////////////////////////////////////////////////
148     // Helper Methods
149     ///////////////////////////////////////////////////////////////////////////
150     /**
151      * return the ComponentLifeCycle implementaion. if returned null, the
152      * DefaultComponentLifeCycle will be used as the component lifecycle
153      */
154     protected abstract ComponentLifeCycle createComponentLifeCycle();
155     
156     /**
157      * if this component supports service unit deployment, then return the
158      * service unit manager, else return null
159      */
160     protected abstract ServiceUnitManager createServiceUnitManager();
161     
162 }