KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > webservice > metadata > jaxrpcmapping > JavaWsdlMapping


1 /*
2  * JBoss, the OpenSource J2EE webOS
3  *
4  * Distributable under LGPL license.
5  * See terms of license at gnu.org.
6  */

7 package org.jboss.webservice.metadata.jaxrpcmapping;
8
9 // $Id: JavaWsdlMapping.java,v 1.7.2.4 2005/06/17 22:31:50 tdiesler Exp $
10

11 import org.jboss.logging.Logger;
12
13 import javax.xml.namespace.QName JavaDoc;
14 import java.util.ArrayList JavaDoc;
15 import java.util.Iterator JavaDoc;
16
17 /**
18  * XML mapping of the java-wsdl-mapping root element in jaxrpc-mapping.xml
19  *
20  * @author Thomas.Diesler@jboss.org
21  * @since 14-May-2004
22  */

23 public class JavaWsdlMapping
24 {
25    // provide logging
26
private final Logger log = Logger.getLogger(JavaWsdlMapping.class);
27
28    // One or more <package-mapping> elements
29
private ArrayList JavaDoc packageMappings = new ArrayList JavaDoc();
30    // Zero or more <java-xml-type-mapping> elements
31
private ArrayList JavaDoc javaXmlTypeMappings = new ArrayList JavaDoc();
32    // Zero or more <exception-mapping> elements
33
private ArrayList JavaDoc exceptionMappings = new ArrayList JavaDoc();
34    // Zero or more <service-interface-mapping> elements
35
private ArrayList JavaDoc serviceInterfaceMappings = new ArrayList JavaDoc();
36    // Zero or more <service-endpoint-interface-mapping> elements
37
private ArrayList JavaDoc serviceEndpointInterfaceMappings = new ArrayList JavaDoc();
38
39    public PackageMapping[] getPackageMappings()
40    {
41       PackageMapping[] arr = new PackageMapping[packageMappings.size()];
42       packageMappings.toArray(arr);
43       return arr;
44    }
45
46    public JavaXmlTypeMapping[] getJavaXmlTypeMappings()
47    {
48       JavaXmlTypeMapping[] arr = new JavaXmlTypeMapping[javaXmlTypeMappings.size()];
49       javaXmlTypeMappings.toArray(arr);
50       return arr;
51    }
52
53    public ExceptionMapping[] getExceptionMappings()
54    {
55       ExceptionMapping[] arr = new ExceptionMapping[exceptionMappings.size()];
56       exceptionMappings.toArray(arr);
57       return arr;
58    }
59
60    public ServiceInterfaceMapping[] getServiceInterfaceMappings()
61    {
62       ServiceInterfaceMapping[] arr = new ServiceInterfaceMapping[serviceInterfaceMappings.size()];
63       serviceInterfaceMappings.toArray(arr);
64       return arr;
65    }
66
67    public ServiceEndpointInterfaceMapping[] getServiceEndpointInterfaceMappings()
68    {
69       ServiceEndpointInterfaceMapping[] arr = new ServiceEndpointInterfaceMapping[serviceEndpointInterfaceMappings.size()];
70       serviceEndpointInterfaceMappings.toArray(arr);
71       return arr;
72    }
73
74    // convenience methods ********************************************************************
75

76    /** Get the package string for a given URI
77     */

78    public String JavaDoc getPackageTypeForURI(String JavaDoc uri)
79    {
80       String JavaDoc packageStr = null;
81       for (int i = 0; packageStr == null && i < packageMappings.size(); i++)
82       {
83          PackageMapping mapping = (PackageMapping)packageMappings.get(i);
84          if (mapping.getNamespaceURI().equals(uri))
85             packageStr = mapping.getPackageType();
86       }
87       return packageStr;
88    }
89
90
91    /** Get the type mapping fo a given root-type-qname
92     */

93    public JavaXmlTypeMapping getTypeMappingForQName(QName JavaDoc xmlType)
94    {
95       JavaXmlTypeMapping typeMapping = null;
96
97       if (xmlType != null)
98       {
99          // Check the <root-type-qname>
100
Iterator JavaDoc it = javaXmlTypeMappings.iterator();
101          while (typeMapping == null && it.hasNext())
102          {
103             JavaXmlTypeMapping mapping = (JavaXmlTypeMapping)it.next();
104             if (xmlType.equals(mapping.getRootTypeQName()))
105                typeMapping = mapping;
106          }
107
108          // Check the <anonymous-type-qname>
109
it = javaXmlTypeMappings.iterator();
110          while (typeMapping == null && it.hasNext())
111          {
112             JavaXmlTypeMapping mapping = (JavaXmlTypeMapping)it.next();
113             QName JavaDoc anonymousQName = mapping.getAnonymousTypeQName();
114             if (anonymousQName != null)
115             {
116                if (xmlType.getNamespaceURI().equals(anonymousQName.getNamespaceURI()))
117                {
118                   String JavaDoc localPart = xmlType.getLocalPart();
119                   if (anonymousQName.getLocalPart().equals(localPart))
120                      typeMapping = mapping;
121                   if (anonymousQName.getLocalPart().equals(">" + localPart))
122                      typeMapping = mapping;
123                }
124             }
125          }
126
127          if (typeMapping == null)
128             log.warn("Cannot find jaxrpc-mapping for type: " + xmlType);
129       }
130
131       return typeMapping;
132    }
133
134    /** Get the exception mapping fo a given wsdl message
135     */

136    public ExceptionMapping getExceptionMappingForMessageQName(QName JavaDoc wsdlMessage)
137    {
138       ExceptionMapping exMapping = null;
139
140       if (wsdlMessage != null)
141       {
142          Iterator JavaDoc it = exceptionMappings.iterator();
143          while (it.hasNext())
144          {
145             ExceptionMapping mapping = (ExceptionMapping)it.next();
146             if (wsdlMessage.equals(mapping.getWsdlMessage()))
147                exMapping = mapping;
148          }
149       }
150
151       return exMapping;
152    }
153
154    /** Get the port type qname for a given service endpoint infterface
155     */

156    public QName JavaDoc getPortTypeQNameForServiceEndpointInterface(String JavaDoc seiName)
157    {
158       QName JavaDoc portTypeQName = null;
159
160       ServiceEndpointInterfaceMapping[] seiMappings = getServiceEndpointInterfaceMappings();
161       for (int i = 0; i < seiMappings.length; i++)
162       {
163          ServiceEndpointInterfaceMapping aux = seiMappings[i];
164          if (aux.getServiceEndpointInterface().equals(seiName))
165             portTypeQName = aux.getWsdlPortType();
166       }
167
168       return portTypeQName;
169    }
170
171    /** Get the service endpoint infterfacemapping for a given port type qname
172     */

173    public ServiceEndpointInterfaceMapping getServiceEndpointInterfaceMappingByPortType(QName JavaDoc portType)
174    {
175       ServiceEndpointInterfaceMapping seiMapping = null;
176
177       ServiceEndpointInterfaceMapping[] seiMappings = getServiceEndpointInterfaceMappings();
178       for (int i = 0; seiMapping == null && i < seiMappings.length; i++)
179       {
180          ServiceEndpointInterfaceMapping aux = seiMappings[i];
181          if (aux.getWsdlPortType().equals(portType))
182             seiMapping = aux;
183       }
184
185       return seiMapping;
186    }
187
188    /** Get the service endpoint infterface mapping for a service endpoint infterface
189     */

190    public ServiceEndpointInterfaceMapping getServiceEndpointInterfaceMapping(String JavaDoc seiName)
191    {
192       ServiceEndpointInterfaceMapping seiMapping = null;
193
194       ServiceEndpointInterfaceMapping[] seiMappings = getServiceEndpointInterfaceMappings();
195       for (int i = 0; seiMapping == null && i < seiMappings.length; i++)
196       {
197          ServiceEndpointInterfaceMapping aux = seiMappings[i];
198          if (aux.getServiceEndpointInterface().equals(seiName))
199             seiMapping = aux;
200       }
201
202       return seiMapping;
203    }
204
205    // factory methods ********************************************************************
206

207    public void addPackageMapping(PackageMapping packageMapping)
208    {
209       packageMappings.add(packageMapping);
210    }
211
212    public void addJavaXmlTypeMappings(JavaXmlTypeMapping typeMapping)
213    {
214       javaXmlTypeMappings.add(typeMapping);
215    }
216
217    public void addExceptionMappings(ExceptionMapping exceptionMapping)
218    {
219       exceptionMappings.add(exceptionMapping);
220    }
221
222    public void addServiceInterfaceMappings(ServiceInterfaceMapping serviceInterfaceMapping)
223    {
224       serviceInterfaceMappings.add(serviceInterfaceMapping);
225    }
226
227    public void addServiceEndpointInterfaceMappings(ServiceEndpointInterfaceMapping serviceEndpointInterfaceMapping)
228    {
229       serviceEndpointInterfaceMappings.add(serviceEndpointInterfaceMapping);
230    }
231 }
232
Popular Tags