View Javadoc

1   /*******************************************************************************
2    *  Copyright (c) 2005, 2006, 2007 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   package it.imolinfo.jbi4ejb.jbi.endpoint;
9   
10  import it.imolinfo.jbi4ejb.exception.Jbi4EjbException;
11  import it.imolinfo.jbi4ejb.jbi.component.Jbi4EjbSUManager;
12  import it.imolinfo.jbi4ejb.processor.ExchangeProcessor;
13  
14  import java.io.File;
15  import java.io.Serializable;
16  
17  import javax.jbi.servicedesc.ServiceEndpoint;
18  import javax.wsdl.Definition;
19  import javax.xml.namespace.QName;
20  
21  import org.w3c.dom.Document;
22  
23  import com.sun.jbi.eManager.provider.EndpointStatus;
24  
25  /**
26   * Generic Jbi4Ejb endpoint.
27   * 
28   * @author <a href="mailto:mpiraccini@imolinfo.it">Marco Piraccini</a>
29   */
30  public abstract class Jbi4EjbEndpoint implements Serializable {
31      
32  
33      /** The Constant SHUTDOWN. */
34      public static final int SHUTDOWN = 0;
35      
36      /** The Constant STOPPED. */
37      public static final int STOPPED = 1;
38      
39      /** The Constant RUNNING. */
40      public static final int RUNNING = 2;
41                 
42      /** The service name. */
43      private QName serviceName = null;
44      
45      /** The endpoint name. */
46      private String endpointName = null;
47      
48      /** The definition. */
49      private Definition definition;
50  
51      /** The state. */
52      private int state;
53      
54      /** The endpoint status. */
55      private EndpointStatus endpointStatus = null;
56      
57      // JBI
58  
59      /** The service endpoint. */
60      private ServiceEndpoint serviceEndpoint = null;
61      
62      /** The service description. */
63      private Document serviceDescription = null;
64      
65      // The service unit name
66      /** The su name. */
67      private String suName = null;
68      
69      /** The su manager. */
70      private Jbi4EjbSUManager suManager = null;
71      
72      /** The exchange processor. */
73      private ExchangeProcessor exchangeProcessor = null;
74      
75      /** The endpoint WSDL. */
76      private File endpointWSDL = null;
77      
78          
79      /**
80       * Instantiates a new jbi4 ejb endpoint.
81       * 
82       * @param serviceName the service name
83       * @param endpointName the endpoint name
84       */
85      public Jbi4EjbEndpoint(QName serviceName, String endpointName) {
86          this.serviceName = serviceName;
87          this.endpointName = endpointName;
88      }    
89      
90      /**
91       * Utility method to create the unique names with explicit arguments.
92       * 
93       * @return the unoque name
94       */
95      public String getUniqueName() {
96          if ((serviceName != null) && (endpointName != null)) {
97              return serviceName + "," + endpointName;
98          } else {
99              return null;
100         }
101     }    
102 
103     /**
104      * Gets the service name.
105      * 
106      * @return the service name
107      */
108     public QName getServiceName() {
109         return serviceName;
110     }
111 
112     /**
113      * Gets the endpoint name.
114      * 
115      * @return the endpoint name
116      */
117     public String getEndpointName() {
118         return endpointName;
119     }
120 
121     /**
122      * Gets the definition.
123      * 
124      * @return the definition
125      */
126     public Definition getDefinition() {
127         return definition;
128     }
129 
130     /**
131      * Sets the definition.
132      * 
133      * @param definition
134      *            the new definition
135      */
136     public void setDefinition(Definition definition) {
137         this.definition = definition;
138     }
139 
140     /**
141      * Gets the state.
142      * 
143      * @return the state
144      */
145     public int getState() {
146         return state;
147     }
148 
149     /**
150      * Sets the state.
151      * 
152      * @param state
153      *            the new state
154      */
155     public void setState(int state) {
156         this.state = state;
157     }
158 
159     /**
160      * Gets the endpoint status.
161      * 
162      * @return the endpoint status
163      */
164     public EndpointStatus getEndpointStatus() {
165         return endpointStatus;
166     }
167 
168     /**
169      * Sets the endpoint status.
170      * 
171      * @param endpointStatus
172      *            the new endpoint status
173      */
174     public void setEndpointStatus(EndpointStatus endpointStatus) {
175         this.endpointStatus = endpointStatus;
176     }
177 
178     /**
179      * Gets the service endpoint.
180      * 
181      * @return the service endpoint
182      */
183     public ServiceEndpoint getServiceEndpoint() {
184         return serviceEndpoint;
185     }
186 
187     /**
188      * Sets the service endpoint.
189      * 
190      * @param serviceEndpoint
191      *            the new service endpoint
192      */
193     public void setServiceEndpoint(ServiceEndpoint serviceEndpoint) {
194         this.serviceEndpoint = serviceEndpoint;
195     }
196 
197     /**
198      * Gets the service description.
199      * 
200      * @return the service description
201      */
202     public Document getServiceDescription() {
203         return serviceDescription;
204     }
205 
206     /**
207      * Sets the service description.
208      * 
209      * @param serviceDescription
210      *            the new service description
211      */
212     public void setServiceDescription(Document serviceDescription) {
213         this.serviceDescription = serviceDescription;
214     }
215                
216     /**
217      * Gets the su name.
218      * 
219      * @return the su name
220      */
221     public String getSuName() {
222         return suName;
223     }
224 
225     /**
226      * Sets the su name.
227      * 
228      * @param suName
229      *            the new su name
230      */
231     public void setSuName(String suName) {
232         this.suName = suName;
233     }
234            
235     /**
236      * Gets the su manager.
237      * 
238      * @return the su manager
239      */
240     public Jbi4EjbSUManager getSuManager() {
241         return suManager;
242     }
243 
244 
245     /**
246      * Sets the su manager.
247      * 
248      * @param suManager
249      *            the new su manager
250      */
251     public void setSuManager(Jbi4EjbSUManager suManager) {
252         this.suManager = suManager;
253     }       
254 
255     /**
256      * Gets the exchange processor.
257      * 
258      * @return the exchange processor
259      */
260     public ExchangeProcessor getExchangeProcessor() {
261         return exchangeProcessor;
262     }
263 
264     /**
265      * Sets the exchange processor.
266      * 
267      * @param exchangeProcessor
268      *            the new exchange processor
269      */
270     public void setExchangeProcessor(ExchangeProcessor exchangeProcessor) {
271         this.exchangeProcessor = exchangeProcessor;
272     }
273         
274     /**
275      * Gets the endpoint WSDL.
276      * 
277      * @return the endpoint WSDL
278      */
279     public File getEndpointWSDL() {
280         return endpointWSDL;
281     }
282 
283     /**
284      * Sets the endpoint WSDL.
285      * 
286      * @param endpointWSDL
287      *            the new endpoint WSDL
288      */
289     public void setEndpointWSDL(File endpointWSDL) {
290         this.endpointWSDL = endpointWSDL;
291     }
292 
293     /* (non-Javadoc)
294      * 
295      */
296     
297     /**
298      * the endpoints are equals if the servicename and the endpointname is the same.
299      * @param obj the object to compare
300      * @see java.lang.Object#equals(java.lang.Object)
301      * @return true if the objects are equals
302      */
303     public boolean equals(Object obj) {
304         if (obj instanceof Jbi4EjbEndpoint) {
305             Jbi4EjbEndpoint c = (Jbi4EjbEndpoint) obj;
306             if ((this.serviceName.equals(c.serviceName)) &&                 
307             (this.endpointName.equals(c.endpointName))) {
308                 return true;
309             }
310           }
311           return false;
312     }
313     
314     /**
315      * hashcode implementation.
316      * @see java.lang.Object#hashCode()
317      * @return the object hashcode
318      */
319     public int hashCode() {
320         return this.serviceName.hashCode() ^ this.serviceEndpoint.hashCode();
321     }
322     
323     /**
324      * Register service.
325      * 
326      * @throws Jbi4EjbException if something go wrong
327      */
328     public abstract void registerService() throws Jbi4EjbException;
329     
330     /**
331      * Unregister service.
332      * 
333      * @throws Jbi4EjbException if something go wrong
334      */
335     public abstract void unregisterService() throws Jbi4EjbException;
336     
337     /**
338      * Validate.
339      * 
340      * @throws Jbi4EjbException if something go wrong
341      */
342     public abstract void validate() throws Jbi4EjbException;       
343 
344 }