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.xfire;
9   
10  import it.imolinfo.jbi4ejb.Logger;
11  import it.imolinfo.jbi4ejb.LoggerFactory;
12  
13  import org.codehaus.xfire.handler.LocateBindingHandler;
14  import org.codehaus.xfire.service.Service;
15  import org.codehaus.xfire.soap.SoapTransport;
16  import org.codehaus.xfire.soap.handler.SoapBodyHandler;
17  import org.codehaus.xfire.transport.AbstractTransport;
18  import org.codehaus.xfire.transport.Channel;
19  import org.codehaus.xfire.transport.DefaultEndpoint;
20  import org.codehaus.xfire.wsdl11.WSDL11Transport;
21  
22  /**
23   * Simple ejb transport, similar to local transport, but without soap encoding.
24   * 
25   * @author <a href="mailto:mpiraccini@imolinfo.it">Marco Piraccini</a>
26   */
27  public class EjbTransport extends AbstractTransport implements WSDL11Transport, SoapTransport {
28      
29      /** The Constant EJB_BINDING. */
30      public static final String EJB_BINDING = "uri://schemas.imola.it/jbi/wsdl-extensions/ejb/";
31  
32      private static final String KNOWN_URI_SCHEME = "ejb://";
33  
34      private static final String EJB = "EJB";
35  
36      /** The logger for this class and its instances. */
37      private static final Logger LOG
38              = LoggerFactory.getLogger(EjbTransport.class);   
39  
40      /** The Constant URI_PREFIX. */
41      private static final String URI_PREFIX = "urn:xfire:transport:ejb:";
42             
43      /**
44       * Instantiates a new ejb transport.
45       */
46      public EjbTransport() {
47          addInHandler(new LocateBindingHandler());
48          addInHandler(new SoapBodyHandler());   
49      }
50  
51      /**
52       * Returns the transport name.
53       * 
54       * @return the name (always <code>EJB</code> constant)
55       * 
56       * @see org.codehaus.xfire.wsdl11.WSDL11Transport#getName()
57       */
58      public String getName() {
59          return EJB;
60      }
61      
62      /**
63       * Returns the service URL.
64       * 
65       * @param service the service
66       * 
67       * @return the service url
68       * 
69       * @see org.codehaus.xfire.wsdl11.WSDL11Transport#getServiceURL(org.codehaus.xfire.service.Service)
70       */
71      public String getServiceURL(Service service) {
72          return KNOWN_URI_SCHEME + service.getName();
73      }
74  
75      
76      /**
77       * Creates a new Channel.
78       * 
79       * @param uri
80       *            the channel uri
81       * 
82       * @return the channel (always a <code>EjbChannel</code>
83       * 
84       * @see org.codehaus.xfire.transport.AbstractTransport#createNewChannel(java.lang.String)
85       */
86      protected Channel createNewChannel(String uri) {
87          LOG.debug("Creating new channel for uri: " + uri);
88          EjbChannel c = new EjbChannel(uri, this);
89          c.setEndpoint(new DefaultEndpoint());
90          return c;
91      }
92  
93      
94      /**
95       * Returns the prefix uri (the <code>URI_PREFIX</code> constant).
96       * 
97       * @return the prefix uri
98       * 
99       * @see org.codehaus.xfire.transport.AbstractTransport#getUriPrefix()
100      */
101     protected String getUriPrefix() {
102         return URI_PREFIX; 
103     }
104 
105     
106     /**
107      * Return the supported binding array. Supports only the
108      * <code>EJB_BINDING</code> binding
109      * 
110      * @return the supported binding array
111      * 
112      * @see org.codehaus.xfire.transport.AbstractTransport#getSupportedBindings()
113      */
114     public String[] getSupportedBindings()
115     {
116         return new String[] {EJB_BINDING};
117     }
118     
119     /**
120      * Return the known uri scheme (only the <code>KNOWN_URI_SCHEME</code> constant value.
121      * 
122      * @return the
123      * 
124      * @see org.codehaus.xfire.transport.AbstractTransport#getKnownUriSchemes()
125      */
126     public String[] getKnownUriSchemes() {
127         return new String[] { KNOWN_URI_SCHEME };
128     }
129 
130     /**
131      * True if the object is of the same instance (EjbTransport).
132      * 
133      * @param o the object
134      * 
135      * @return true  if the object is of the same instance. 
136      * 
137      * @see java.lang.Object#equals(java.lang.Object)
138      */
139     public boolean equals(Object o) {
140         return o instanceof EjbTransport;
141     }
142      
143 }