KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * Copyright 2001-2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 package org.apache.axis.deployment.wsdd;
17
18 import org.apache.axis.Constants;
19 import org.apache.axis.encoding.SerializationContext;
20 import org.apache.axis.utils.ClassUtils;
21 import org.apache.axis.utils.JavaUtils;
22 import org.apache.axis.utils.Messages;
23 import org.apache.axis.utils.XMLUtils;
24 import org.w3c.dom.Attr JavaDoc;
25 import org.w3c.dom.Element JavaDoc;
26 import org.xml.sax.helpers.AttributesImpl JavaDoc;
27
28 import javax.xml.namespace.QName JavaDoc;
29 import java.io.IOException JavaDoc;
30
31
32 /**
33  *
34  */

35 public class WSDDTypeMapping
36     extends WSDDElement
37 {
38     protected QName JavaDoc qname = null;
39     protected String JavaDoc serializer = null;
40     protected String JavaDoc deserializer = null;
41     protected QName JavaDoc typeQName = null;
42     protected String JavaDoc ref = null;
43     protected String JavaDoc encodingStyle = null;
44     
45     /**
46      * Default constructor
47      *
48      */

49     public WSDDTypeMapping()
50     {
51     }
52     
53     /**
54      *
55      * @param e (Element) XXX
56      * @throws WSDDException XXX
57      */

58     public WSDDTypeMapping(Element JavaDoc e)
59         throws WSDDException
60     {
61         serializer = e.getAttribute(ATTR_SERIALIZER);
62         deserializer = e.getAttribute(ATTR_DESERIALIZER);
63         Attr JavaDoc attrNode = e.getAttributeNode(ATTR_ENCSTYLE);
64
65         if (attrNode == null) {
66             encodingStyle = Constants.URI_DEFAULT_SOAP_ENC;
67         } else {
68             encodingStyle = attrNode.getValue();
69         }
70
71         String JavaDoc qnameStr = e.getAttribute(ATTR_QNAME);
72         qname = XMLUtils.getQNameFromString(qnameStr, e);
73
74         // JSR 109 v0.093 indicates that this attribute is named "type"
75

76         String JavaDoc typeStr = e.getAttribute(ATTR_TYPE);
77         typeQName = XMLUtils.getQNameFromString(typeStr, e);
78         if (typeStr == null || typeStr.equals("")) {
79             typeStr = e.getAttribute(ATTR_LANG_SPEC_TYPE);
80             typeQName = XMLUtils.getQNameFromString(typeStr, e);
81         }
82     }
83
84     /**
85      * Write this element out to a SerializationContext
86      */

87     public void writeToContext(SerializationContext context)
88             throws IOException JavaDoc {
89         AttributesImpl JavaDoc attrs = new AttributesImpl JavaDoc();
90         attrs.addAttribute("", ATTR_ENCSTYLE, ATTR_ENCSTYLE, "CDATA", encodingStyle);
91         attrs.addAttribute("", ATTR_SERIALIZER, ATTR_SERIALIZER, "CDATA", serializer);
92         attrs.addAttribute("", ATTR_DESERIALIZER, ATTR_DESERIALIZER, "CDATA", deserializer);
93
94         String JavaDoc typeStr = context.qName2String(typeQName);
95         // JSR 109 indicates that the name of this field is type
96
attrs.addAttribute("", ATTR_TYPE, ATTR_TYPE,
97                            "CDATA", typeStr);
98         
99         String JavaDoc qnameStr = context.attributeQName2String(qname);
100         attrs.addAttribute("", ATTR_QNAME, ATTR_QNAME, "CDATA", qnameStr);
101         
102         context.startElement(QNAME_TYPEMAPPING, attrs);
103         context.endElement();
104     }
105
106     protected QName JavaDoc getElementName() {
107         return QNAME_TYPEMAPPING;
108     }
109
110     /**
111      *
112      * @return XXX
113      */

114     public String JavaDoc getRef()
115     {
116         return ref;
117     }
118
119     /**
120      *
121      * @param ref XXX
122      */

123     public void setRef(String JavaDoc ref)
124     {
125         this.ref = ref;
126     }
127
128     /**
129      *
130      * @return XXX
131      */

132     public String JavaDoc getEncodingStyle()
133     {
134         return encodingStyle;
135     }
136
137     /**
138      *
139      * @param es XXX
140      */

141     public void setEncodingStyle(String JavaDoc es)
142     {
143         encodingStyle = es;
144     }
145
146     /**
147      *
148      * @return XXX
149      */

150     public QName JavaDoc getQName()
151     {
152         return qname;
153     }
154
155     /**
156      *
157      * @param name XXX
158      */

159     public void setQName(QName JavaDoc name)
160     {
161         qname = name;
162     }
163
164     /**
165      *
166      * @return XXX
167      * @throws ClassNotFoundException XXX
168      */

169     public Class JavaDoc getLanguageSpecificType()
170         throws ClassNotFoundException JavaDoc
171     {
172         if (typeQName != null) {
173             if (!URI_WSDD_JAVA.equals(typeQName.getNamespaceURI())) {
174                 throw new ClassNotFoundException JavaDoc(Messages.getMessage("badTypeNamespace00",
175                                         typeQName.getNamespaceURI(),
176                                         URI_WSDD_JAVA));
177             }
178             String JavaDoc loadName = JavaUtils.getLoadableClassName(typeQName.getLocalPart());
179             if (JavaUtils.getWrapper(loadName) != null) {
180                 // in case of a primitive type by use its corresponding wrapper class.
181
loadName = "java.lang." + JavaUtils.getWrapper(loadName);
182             }
183             return ClassUtils.forName(loadName);
184         }
185         
186         throw new ClassNotFoundException JavaDoc(Messages.getMessage("noTypeQName00"));
187     }
188
189     /**
190      * Set javaType (type= attribute or languageSpecificType= attribute)
191      * @param javaType the class of the javaType
192      */

193     public void setLanguageSpecificType(Class JavaDoc javaType)
194     {
195         String JavaDoc type = javaType.getName();
196         typeQName = new QName JavaDoc(URI_WSDD_JAVA, type);
197     }
198
199     /**
200      * Set javaType (type= attribute or languageSpecificType= attribute)
201      * @param javaType is the name of the class. (For arrays this
202      * could be the form my.Foo[] or could be in the form [Lmy.Foo;
203      */

204     public void setLanguageSpecificType(String JavaDoc javaType)
205     {
206         typeQName = new QName JavaDoc(URI_WSDD_JAVA, javaType);
207     }
208
209     /**
210      *
211      * @return XXX
212      * @throws ClassNotFoundException XXX
213      */

214     public Class JavaDoc getSerializer()
215         throws ClassNotFoundException JavaDoc
216     {
217         return ClassUtils.forName(serializer);
218     }
219
220     /**
221      *
222      * @return serializer factory name
223      */

224     public String JavaDoc getSerializerName()
225     {
226         return serializer;
227     }
228     /**
229      *
230      * @param ser XXX
231      */

232     public void setSerializer(Class JavaDoc ser)
233     {
234         serializer = ser.getName();
235     }
236
237     /**
238      * Set the serializer factory name
239      * @param ser name of the serializer factory class
240      */

241     public void setSerializer(String JavaDoc ser)
242     {
243         serializer = ser;
244     }
245
246     /**
247      *
248      * @return XXX
249      * @throws ClassNotFoundException XXX
250      */

251     public Class JavaDoc getDeserializer()
252         throws ClassNotFoundException JavaDoc
253     {
254         return ClassUtils.forName(deserializer);
255     }
256
257     /**
258      *
259      * @return deserializer factory name
260      */

261     public String JavaDoc getDeserializerName()
262     {
263         return deserializer;
264     }
265
266     /**
267      *
268      * @param deser XXX
269      */

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

279     public void setDeserializer(String JavaDoc deser)
280     {
281         deserializer = deser;
282     }
283 }
284
285
286
287
Popular Tags