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