KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jonas_ws > deployment > api > MappingFile


1 /**
2  * JOnAS: Java(TM) Open Application Server
3  * Copyright (C) 1999 Bull S.A.
4  * Contact: jonas-team@objectweb.org
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
19  * USA
20  *
21  * Initial Developer : Delplanque Xavier & Sauthier Guillaume
22  * --------------------------------------------------------------------------
23  * $Id: MappingFile.java,v 1.13 2004/11/19 09:23:00 sauthieg Exp $
24  * --------------------------------------------------------------------------
25  */

26
27 package org.objectweb.jonas_ws.deployment.api;
28
29 import java.util.Hashtable JavaDoc;
30 import java.util.Iterator JavaDoc;
31 import java.util.List JavaDoc;
32 import java.util.Map JavaDoc;
33
34 import javax.xml.namespace.QName JavaDoc;
35
36 import org.objectweb.jonas_lib.deployment.xml.Qname;
37
38 import org.objectweb.jonas_ws.deployment.xml.JavaWsdlMapping;
39 import org.objectweb.jonas_ws.deployment.xml.JavaXmlTypeMapping;
40 import org.objectweb.jonas_ws.deployment.xml.PackageMapping;
41
42
43 /**
44  * this Class is used to manipulate jaxrpc-mapping-file. This file contains
45  * informations for mapping between XML namespaces and java packages. We
46  * actually support just a few part of this file. According with JSR 921, this
47  * file must contain class mapping information (exceptions/faults,
48  * types/classes, portTypes/interfaces ...).
49  *
50  * @author Guillaume Sauthier
51  * @author Xavier Delplanque
52  * @author Helene Joanin
53  */

54 public class MappingFile {
55
56     /** Associates a namespace to its package. It's the cache. */
57     private Map JavaDoc namespacePackageMapping;
58
59     /** Associates an XML QName to its java classname */
60     private Map JavaDoc xmlType2javaClassname;
61
62     /** parsed object */
63     private JavaWsdlMapping javaWSDLMapping;
64
65     /**
66      * Constructor : creates a MappingFile object.
67      *
68      * @param jwMapping XML Element java-wsdl-mapping
69      */

70     public MappingFile(JavaWsdlMapping jwMapping) {
71
72         javaWSDLMapping = jwMapping;
73
74         // init vars
75
namespacePackageMapping = new Hashtable JavaDoc();
76         xmlType2javaClassname = new Hashtable JavaDoc();
77
78         fillPackageMapping(jwMapping);
79         fillXmlTypeMapping(jwMapping);
80
81     }
82
83
84     /**
85      * Fill up the package mapping hashtable
86      *
87      * @param mapping jaxrpc-mapping-file root element.
88      */

89     private void fillPackageMapping(JavaWsdlMapping mapping) {
90         List JavaDoc pml = mapping.getPackageMappingList();
91
92         for (Iterator JavaDoc i = pml.iterator(); i.hasNext();) {
93             // get each mapping file package mappings
94
PackageMapping pm = (PackageMapping) i.next();
95
96             String JavaDoc pt = pm.getPackageType();
97             String JavaDoc nuri = pm.getNamespaceURI();
98
99             //add in the hashtable the namespace to package relation (cache)
100
namespacePackageMapping.put(nuri, pt);
101         }
102     }
103
104     /**
105      * Fill up the xml type to java class map
106      *
107      * @param mapping jaxrpc-mapping-file root element.
108      */

109     private void fillXmlTypeMapping(JavaWsdlMapping mapping) {
110
111         List JavaDoc jxml = mapping.getJavaXmlTypeMappingList();
112         for (Iterator JavaDoc i = jxml.iterator(); i.hasNext();) {
113             // get each java -> xml type mapping
114
JavaXmlTypeMapping jxtm = (JavaXmlTypeMapping) i.next();
115
116             QName JavaDoc xmlName = null;
117             String JavaDoc javaName = jxtm.getJavaType();
118             Qname rootType = jxtm.getRootTypeQname();
119             if (rootType != null) {
120                 xmlName = rootType.getQName();
121             } else {
122                 xmlName = jxtm.getAnonymousTypeQname().getQName();
123             }
124
125             xmlType2javaClassname.put(xmlName, javaName);
126         }
127     }
128
129     /**
130      * @return Returns the XML Element representing this MappingFile (use only for Test).
131      */

132     public JavaWsdlMapping getXmlJavaWsdlMapping() {
133         return javaWSDLMapping;
134     }
135
136     /**
137      * return the mapping between XML namespaces and Java packages defined in
138      * the jaxrpc-mapping file.
139      *
140      * @return the mapping between XML namespaces and Java packages
141      */

142     public Map JavaDoc getMappings() {
143         return namespacePackageMapping;
144     }
145
146     /**
147      * Return the package associated with the specified namespaceURI (can be
148      * null).
149      *
150      * @param namespaceURI the namespace key to retrieve the package name
151      *
152      * @return the package associated with the specified namespaceURI. (null if
153      * namespace not present).
154      */

155     public String JavaDoc getMapping(String JavaDoc namespaceURI) {
156         return (String JavaDoc) namespacePackageMapping.get(namespaceURI);
157     }
158
159     /**
160      * Return the Java classname representing the xml type.
161      *
162      * @param xmlType the QName of the xml type
163      *
164      * @return the Java classname representing the xml type.
165      */

166     public String JavaDoc getClassname(QName JavaDoc xmlType) {
167         return (String JavaDoc) xmlType2javaClassname.get(xmlType);
168     }
169
170     /**
171      * Return an iterator traversing the list of xmlType mappings.
172      *
173      * @return an iterator traversing the list of xmlType mappings.
174      */

175     public Iterator JavaDoc getXmlTypeMappings() {
176         return xmlType2javaClassname.keySet().iterator();
177     }
178
179     /**
180      * Build a string representation of MappingFile
181      *
182      * @return String representation of the mapping file.
183      */

184     public String JavaDoc toString() {
185         StringBuffer JavaDoc ret = new StringBuffer JavaDoc();
186
187         ret.append("\n" + getClass().getName()); //$NON-NLS-1$
188
ret.append("\ngetMappings()=" + namespacePackageMapping); //$NON-NLS-1$
189
ret.append("\ngetXmlTypeMappings()=" + xmlType2javaClassname); //$NON-NLS-1$
190

191         return ret.toString();
192     }
193
194     /**
195      * @see java.lang.Object#hashCode()
196      */

197     public int hashCode() {
198         return this.namespacePackageMapping.hashCode() + this.xmlType2javaClassname.hashCode();
199     }
200
201     /**
202      * Return true if the 2 objects are equals in value.
203      *
204      * @param other the object to compare.
205      *
206      * @return true if objects are equals in value, else false.
207      */

208     public boolean equals(Object JavaDoc other) {
209         if (this == other) {
210             return true;
211         }
212         if (other == null) {
213             return false;
214         }
215         if (!(other instanceof MappingFile)) {
216             return false;
217         }
218         MappingFile ref = (MappingFile) other;
219         if (!namespacePackageMapping.equals(ref.getMappings())) {
220             return false;
221         }
222         // After all theses tests, the 2 objects are equals in value
223
return true;
224     }
225
226 }
227
Popular Tags