001: /**
002: * JOnAS: Java(TM) Open Application Server
003: * Copyright (C) 1999 Bull S.A.
004: * Contact: jonas-team@objectweb.org
005: *
006: * This library is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU Lesser General Public
008: * License as published by the Free Software Foundation; either
009: * version 2.1 of the License, or any later version.
010: *
011: * This library is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * Lesser General Public License for more details.
015: *
016: * You should have received a copy of the GNU Lesser General Public
017: * License along with this library; if not, write to the Free Software
018: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
019: * USA
020: *
021: * Initial Developer : Delplanque Xavier & Sauthier Guillaume
022: * --------------------------------------------------------------------------
023: * $Id: MappingFile.java 5766 2004-11-19 09:23:01Z sauthieg $
024: * --------------------------------------------------------------------------
025: */package org.objectweb.jonas_ws.deployment.api;
026:
027: import java.util.Hashtable;
028: import java.util.Iterator;
029: import java.util.List;
030: import java.util.Map;
031:
032: import javax.xml.namespace.QName;
033:
034: import org.objectweb.jonas_lib.deployment.xml.Qname;
035:
036: import org.objectweb.jonas_ws.deployment.xml.JavaWsdlMapping;
037: import org.objectweb.jonas_ws.deployment.xml.JavaXmlTypeMapping;
038: import org.objectweb.jonas_ws.deployment.xml.PackageMapping;
039:
040: /**
041: * this Class is used to manipulate jaxrpc-mapping-file. This file contains
042: * informations for mapping between XML namespaces and java packages. We
043: * actually support just a few part of this file. According with JSR 921, this
044: * file must contain class mapping information (exceptions/faults,
045: * types/classes, portTypes/interfaces ...).
046: *
047: * @author Guillaume Sauthier
048: * @author Xavier Delplanque
049: * @author Helene Joanin
050: */
051: public class MappingFile {
052:
053: /** Associates a namespace to its package. It's the cache. */
054: private Map namespacePackageMapping;
055:
056: /** Associates an XML QName to its java classname */
057: private Map xmlType2javaClassname;
058:
059: /** parsed object */
060: private JavaWsdlMapping javaWSDLMapping;
061:
062: /**
063: * Constructor : creates a MappingFile object.
064: *
065: * @param jwMapping XML Element java-wsdl-mapping
066: */
067: public MappingFile(JavaWsdlMapping jwMapping) {
068:
069: javaWSDLMapping = jwMapping;
070:
071: // init vars
072: namespacePackageMapping = new Hashtable();
073: xmlType2javaClassname = new Hashtable();
074:
075: fillPackageMapping(jwMapping);
076: fillXmlTypeMapping(jwMapping);
077:
078: }
079:
080: /**
081: * Fill up the package mapping hashtable
082: *
083: * @param mapping jaxrpc-mapping-file root element.
084: */
085: private void fillPackageMapping(JavaWsdlMapping mapping) {
086: List pml = mapping.getPackageMappingList();
087:
088: for (Iterator i = pml.iterator(); i.hasNext();) {
089: // get each mapping file package mappings
090: PackageMapping pm = (PackageMapping) i.next();
091:
092: String pt = pm.getPackageType();
093: String nuri = pm.getNamespaceURI();
094:
095: //add in the hashtable the namespace to package relation (cache)
096: namespacePackageMapping.put(nuri, pt);
097: }
098: }
099:
100: /**
101: * Fill up the xml type to java class map
102: *
103: * @param mapping jaxrpc-mapping-file root element.
104: */
105: private void fillXmlTypeMapping(JavaWsdlMapping mapping) {
106:
107: List jxml = mapping.getJavaXmlTypeMappingList();
108: for (Iterator i = jxml.iterator(); i.hasNext();) {
109: // get each java -> xml type mapping
110: JavaXmlTypeMapping jxtm = (JavaXmlTypeMapping) i.next();
111:
112: QName xmlName = null;
113: String javaName = jxtm.getJavaType();
114: Qname rootType = jxtm.getRootTypeQname();
115: if (rootType != null) {
116: xmlName = rootType.getQName();
117: } else {
118: xmlName = jxtm.getAnonymousTypeQname().getQName();
119: }
120:
121: xmlType2javaClassname.put(xmlName, javaName);
122: }
123: }
124:
125: /**
126: * @return Returns the XML Element representing this MappingFile (use only for Test).
127: */
128: public JavaWsdlMapping getXmlJavaWsdlMapping() {
129: return javaWSDLMapping;
130: }
131:
132: /**
133: * return the mapping between XML namespaces and Java packages defined in
134: * the jaxrpc-mapping file.
135: *
136: * @return the mapping between XML namespaces and Java packages
137: */
138: public Map getMappings() {
139: return namespacePackageMapping;
140: }
141:
142: /**
143: * Return the package associated with the specified namespaceURI (can be
144: * null).
145: *
146: * @param namespaceURI the namespace key to retrieve the package name
147: *
148: * @return the package associated with the specified namespaceURI. (null if
149: * namespace not present).
150: */
151: public String getMapping(String namespaceURI) {
152: return (String) namespacePackageMapping.get(namespaceURI);
153: }
154:
155: /**
156: * Return the Java classname representing the xml type.
157: *
158: * @param xmlType the QName of the xml type
159: *
160: * @return the Java classname representing the xml type.
161: */
162: public String getClassname(QName xmlType) {
163: return (String) xmlType2javaClassname.get(xmlType);
164: }
165:
166: /**
167: * Return an iterator traversing the list of xmlType mappings.
168: *
169: * @return an iterator traversing the list of xmlType mappings.
170: */
171: public Iterator getXmlTypeMappings() {
172: return xmlType2javaClassname.keySet().iterator();
173: }
174:
175: /**
176: * Build a string representation of MappingFile
177: *
178: * @return String representation of the mapping file.
179: */
180: public String toString() {
181: StringBuffer ret = new StringBuffer();
182:
183: ret.append("\n" + getClass().getName()); //$NON-NLS-1$
184: ret.append("\ngetMappings()=" + namespacePackageMapping); //$NON-NLS-1$
185: ret.append("\ngetXmlTypeMappings()=" + xmlType2javaClassname); //$NON-NLS-1$
186:
187: return ret.toString();
188: }
189:
190: /**
191: * @see java.lang.Object#hashCode()
192: */
193: public int hashCode() {
194: return this .namespacePackageMapping.hashCode()
195: + this .xmlType2javaClassname.hashCode();
196: }
197:
198: /**
199: * Return true if the 2 objects are equals in value.
200: *
201: * @param other the object to compare.
202: *
203: * @return true if objects are equals in value, else false.
204: */
205: public boolean equals(Object other) {
206: if (this == other) {
207: return true;
208: }
209: if (other == null) {
210: return false;
211: }
212: if (!(other instanceof MappingFile)) {
213: return false;
214: }
215: MappingFile ref = (MappingFile) other;
216: if (!namespacePackageMapping.equals(ref.getMappings())) {
217: return false;
218: }
219: // After all theses tests, the 2 objects are equals in value
220: return true;
221: }
222:
223: }
|