View Javadoc

1   package org.codehaus.xfire.service.object;
2   
3   import java.util.ArrayList;
4   import java.util.Collection;
5   import java.util.Hashtable;
6   import java.util.List;
7   import java.util.Map;
8   
9   import javax.wsdl.WSDLException;
10  
11  import org.codehaus.xfire.service.MessageService;
12  import org.codehaus.xfire.type.TypeMapping;
13  import org.codehaus.xfire.wsdl.WSDLWriter;
14  import org.codehaus.xfire.wsdl11.builder.WSDLBuilder;
15  
16  /***
17   * @author <a href="mailto:dan@envoisolutions.com">Dan Diephouse </a>
18   */
19  public class DefaultObjectService
20      extends MessageService
21      implements ObjectService
22  {
23      private TypeMapping typeMapping;
24  
25      private List allowedMethods;
26  
27      private Class serviceClass;
28  
29      private Hashtable operations;
30  
31      private WSDLBuilder wsdlBuilder;
32  
33      private boolean autoTyped = false;
34  
35      private int scope = ObjectService.SCOPE_APPLICATION;
36  
37      private String encodingStyleURI;
38  
39      public DefaultObjectService()
40      {
41          super();
42          this.allowedMethods = new ArrayList();
43          this.operations = new Hashtable();
44      }
45  
46      /***
47       * @param className
48       */
49      public void setServiceClass(final String className)
50          throws ClassNotFoundException
51      {
52          setServiceClass(loadClass(className));
53      }
54  
55      /***
56       * @param serviceClass
57       */
58      public void setServiceClass(final Class serviceClass)
59      {
60          this.serviceClass = serviceClass;
61      }
62  
63      public void addOperation(final Operation op)
64      {
65          operations.put(op.getName(), op);
66      }
67  
68      /***
69       * Determines whether or not to expose the specified method.
70       * 
71       * @param methodName
72       */
73      private boolean isAllowed(final String methodName)
74      {
75          return (allowedMethods.isEmpty() || allowedMethods.contains(methodName));
76      }
77  
78      public Operation getOperation(final String localName)
79      {
80          return (Operation) operations.get(localName);
81      }
82  
83      public Collection getOperations()
84      {
85          return operations.values();
86      }
87  
88      protected Map getOperationsMap()
89      {
90          return operations;
91      }
92  
93      public List getAllowedMethods()
94      {
95          return allowedMethods;
96      }
97  
98      /***
99       * @param allowedMethods
100      *            The allowedMethods to set.
101      */
102     public void setAllowedMethods(final List allowedMethods)
103     {
104         this.allowedMethods = allowedMethods;
105     }
106 
107     public TypeMapping getTypeMapping()
108     {
109         return typeMapping;
110     }
111 
112     /***
113      * @param typeMapping
114      *            The typeMapping to set.
115      */
116     public void setTypeMapping(final TypeMapping typeMapping)
117     {
118         this.typeMapping = typeMapping;
119     }
120 
121     /***
122      * @return
123      */
124     public Class getServiceClass()
125     {
126         return serviceClass;
127     }
128 
129     /***
130      * Load a class from the class loader.
131      * 
132      * @param className
133      *            The name of the class.
134      * 
135      * @return The class.
136      */
137     protected Class loadClass(final String className)
138         throws ClassNotFoundException
139     {
140         try
141         {
142             return getClass().getClassLoader().loadClass(className);
143         }
144         catch (ClassNotFoundException cnfe)
145         {
146             try
147             {
148                 return Class.forName(className);
149             }
150             catch (ClassNotFoundException cnf2)
151             {
152                 return Thread.currentThread().getContextClassLoader().loadClass(className);
153             }
154         }
155     }
156 
157     public WSDLWriter getWSDLWriter()
158         throws WSDLException
159     {
160         final WSDLWriter writer = super.getWSDLWriter();
161 
162         if (writer == null)
163         {
164             final WSDLBuilder b = getWSDLBuilder();
165 
166             if (b != null)
167                 return getWSDLBuilder().createWSDLWriter(this);
168         }
169 
170         return writer;
171     }
172 
173     public boolean isAutoTyped()
174     {
175         return autoTyped;
176     }
177 
178     public void setAutoTyped(final boolean autoTyped)
179     {
180         this.autoTyped = autoTyped;
181     }
182 
183     public int getScope()
184     {
185         return scope;
186     }
187 
188     public void setScope(final int scope)
189     {
190         this.scope = scope;
191     }
192 
193     public WSDLBuilder getWSDLBuilder()
194     {
195         return wsdlBuilder;
196     }
197 
198     public void setWSDLBuilder(final WSDLBuilder wsdlBuilder)
199     {
200         this.wsdlBuilder = wsdlBuilder;
201     }
202 
203     public String getEncodingStyleURI()
204     {
205         return encodingStyleURI;
206     }
207 
208     public void setEncodingStyleURI(final String encodingStyleURI)
209     {
210         this.encodingStyleURI = encodingStyleURI;
211     }
212 }