KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > axis > deployment > wsdd > WSDDTypeMapping


1 /*
2  * The Apache Software License, Version 1.1
3  *
4  *
5  * Copyright (c) 2001-2003 The Apache Software Foundation. All rights
6  * reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  *
12  * 1. Redistributions of source code must retain the above copyright
13  * notice, this list of conditions and the following disclaimer.
14  *
15  * 2. Redistributions in binary form must reproduce the above copyright
16  * notice, this list of conditions and the following disclaimer in
17  * the documentation and/or other materials provided with the
18  * distribution.
19  *
20  * 3. The end-user documentation included with the redistribution,
21  * if any, must include the following acknowledgment:
22  * "This product includes software developed by the
23  * Apache Software Foundation (http://www.apache.org/)."
24  * Alternately, this acknowledgment may appear in the software itself,
25  * if and wherever such third-party acknowledgments normally appear.
26  *
27  * 4. The names "Axis" and "Apache Software Foundation" must
28  * not be used to endorse or promote products derived from this
29  * software without prior written permission. For written
30  * permission, please contact apache@apache.org.
31  *
32  * 5. Products derived from this software may not be called "Apache",
33  * nor may "Apache" appear in their name, without prior written
34  * permission of the Apache Software Foundation.
35  *
36  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
37  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
38  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
39  * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
40  * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
41  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
42  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
43  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
44  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
45  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
46  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
47  * SUCH DAMAGE.
48  * ====================================================================
49  *
50  * This software consists of voluntary contributions made by many
51  * individuals on behalf of the Apache Software Foundation. For more
52  * information on the Apache Software Foundation, please see
53  * <http://www.apache.org/>.
54  */

55 package org.jboss.axis.deployment.wsdd;
56
57 import org.jboss.axis.Constants;
58 import org.jboss.axis.encoding.SerializationContext;
59 import org.jboss.axis.utils.ClassUtils;
60 import org.jboss.axis.utils.JavaUtils;
61 import org.jboss.axis.utils.Messages;
62 import org.jboss.axis.utils.XMLUtils;
63 import org.w3c.dom.Attr JavaDoc;
64 import org.w3c.dom.Element JavaDoc;
65 import org.xml.sax.helpers.AttributesImpl JavaDoc;
66
67 import javax.xml.namespace.QName JavaDoc;
68 import java.io.IOException JavaDoc;
69
70
71 /**
72  *
73  */

74 public class WSDDTypeMapping
75         extends WSDDElement
76 {
77    protected QName JavaDoc qname = null;
78    protected String JavaDoc serializer = null;
79    protected String JavaDoc deserializer = null;
80    protected QName JavaDoc typeQName = null;
81    protected String JavaDoc ref = null;
82    protected String JavaDoc encodingStyle = null;
83
84    /**
85     * Default constructor
86     */

87    public WSDDTypeMapping()
88    {
89    }
90
91    /**
92     * @param e (Element) XXX
93     * @throws WSDDException XXX
94     */

95    public WSDDTypeMapping(Element JavaDoc e)
96            throws WSDDException
97    {
98       serializer = e.getAttribute(ATTR_SERIALIZER);
99       deserializer = e.getAttribute(ATTR_DESERIALIZER);
100       Attr JavaDoc attrNode = e.getAttributeNode(ATTR_ENCSTYLE);
101
102       if (attrNode == null)
103       {
104          encodingStyle = Constants.URI_DEFAULT_SOAP_ENC;
105       }
106       else
107       {
108          encodingStyle = attrNode.getValue();
109       }
110
111       String JavaDoc qnameStr = e.getAttribute(ATTR_QNAME);
112       qname = XMLUtils.getQNameFromString(qnameStr, e);
113
114       // JSR 109 v0.093 indicates that this attribute is named "type"
115

116       String JavaDoc typeStr = e.getAttribute(ATTR_TYPE);
117       typeQName = XMLUtils.getQNameFromString(typeStr, e);
118       if (typeStr == null || typeStr.equals(""))
119       {
120          typeStr = e.getAttribute(ATTR_LANG_SPEC_TYPE);
121          typeQName = XMLUtils.getQNameFromString(typeStr, e);
122       }
123    }
124
125    /**
126     * Write this element out to a SerializationContext
127     */

128    public void writeToContext(SerializationContext context)
129            throws IOException JavaDoc
130    {
131       AttributesImpl JavaDoc attrs = new AttributesImpl JavaDoc();
132       attrs.addAttribute("", ATTR_ENCSTYLE, ATTR_ENCSTYLE, "CDATA", encodingStyle);
133       attrs.addAttribute("", ATTR_SERIALIZER, ATTR_SERIALIZER, "CDATA", serializer);
134       attrs.addAttribute("", ATTR_DESERIALIZER, ATTR_DESERIALIZER, "CDATA", deserializer);
135
136       String JavaDoc typeStr = context.qName2String(typeQName);
137       // JSR 109 indicates that the name of this field is type
138
attrs.addAttribute("", ATTR_TYPE, ATTR_TYPE,
139               "CDATA", typeStr);
140
141       String JavaDoc qnameStr = context.qName2String(qname);
142       attrs.addAttribute("", ATTR_QNAME, ATTR_QNAME, "CDATA", qnameStr);
143
144       context.startElement(QNAME_TYPEMAPPING, attrs);
145       context.endElement();
146    }
147
148    protected QName JavaDoc getElementName()
149    {
150       return QNAME_TYPEMAPPING;
151    }
152
153    /**
154     * @return XXX
155     */

156    public String JavaDoc getRef()
157    {
158       return ref;
159    }
160
161    /**
162     * @param ref XXX
163     */

164    public void setRef(String JavaDoc ref)
165    {
166       this.ref = ref;
167    }
168
169    /**
170     * @return XXX
171     */

172    public String JavaDoc getEncodingStyle()
173    {
174       return encodingStyle;
175    }
176
177    /**
178     * @param es XXX
179     */

180    public void setEncodingStyle(String JavaDoc es)
181    {
182       encodingStyle = es;
183    }
184
185    /**
186     * @return XXX
187     */

188    public QName JavaDoc getQName()
189    {
190       return qname;
191    }
192
193    /**
194     * @param name XXX
195     */

196    public void setQName(QName JavaDoc name)
197    {
198       qname = name;
199    }
200
201    /**
202     * @return XXX
203     * @throws ClassNotFoundException XXX
204     */

205    public Class JavaDoc getLanguageSpecificType()
206            throws ClassNotFoundException JavaDoc
207    {
208       if (typeQName != null)
209       {
210          if (!URI_WSDD_JAVA.equals(typeQName.getNamespaceURI()))
211          {
212             throw new ClassNotFoundException JavaDoc(Messages.getMessage("badTypeNamespace00",
213                     typeQName.getNamespaceURI(),
214                     URI_WSDD_JAVA));
215          }
216          String JavaDoc loadName = JavaUtils.getLoadableClassName(typeQName.getLocalPart());
217          if (JavaUtils.getWrapper(loadName) != null)
218          {
219             // We're
220
}
221          return ClassUtils.forName(loadName);
222       }
223
224       throw new ClassNotFoundException JavaDoc(Messages.getMessage("noTypeQName00"));
225    }
226
227    /**
228     * Set javaType (type= attribute or languageSpecificType= attribute)
229     *
230     * @param javaType the class of the javaType
231     */

232    public void setLanguageSpecificType(Class JavaDoc javaType)
233    {
234       String JavaDoc type = javaType.getName();
235       typeQName = new QName JavaDoc(URI_WSDD_JAVA, type);
236    }
237
238    /**
239     * Set javaType (type= attribute or languageSpecificType= attribute)
240     *
241     * @param javaType is the name of the class. (For arrays this
242     * could be the form my.Foo[] or could be in the form [Lmy.Foo;
243     */

244    public void setLanguageSpecificType(String JavaDoc javaType)
245    {
246       typeQName = new QName JavaDoc(URI_WSDD_JAVA, javaType);
247    }
248
249    /**
250     * @return XXX
251     * @throws ClassNotFoundException XXX
252     */

253    public Class JavaDoc getSerializer()
254            throws ClassNotFoundException JavaDoc
255    {
256       return ClassUtils.forName(serializer);
257    }
258
259    /**
260     * @return serializer factory name
261     */

262    public String JavaDoc getSerializerName()
263    {
264       return serializer;
265    }
266
267    /**
268     * @param ser XXX
269     */

270    public void setSerializer(Class JavaDoc ser)
271    {
272       serializer = ser.getName();
273    }
274
275    /**
276     * Set the serializer factory name
277     *
278     * @param ser name of the serializer factory class
279     */

280    public void setSerializer(String JavaDoc ser)
281    {
282       serializer = ser;
283    }
284
285    /**
286     * @return XXX
287     * @throws ClassNotFoundException XXX
288     */

289    public Class JavaDoc getDeserializer()
290            throws ClassNotFoundException JavaDoc
291    {
292       return ClassUtils.forName(deserializer);
293    }
294
295    /**
296     * @return deserializer factory name
297     */

298    public String JavaDoc getDeserializerName()
299    {
300       return deserializer;
301    }
302
303    /**
304     * @param deser XXX
305     */

306    public void setDeserializer(Class JavaDoc deser)
307    {
308       deserializer = deser.getName();
309    }
310
311    /**
312     * Set the deserializer factory name
313     *
314     * @param deser name of the deserializer factory class
315     */

316    public void setDeserializer(String JavaDoc deser)
317    {
318       deserializer = deser;
319    }
320 }
321
322
323
324
Popular Tags