KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > axis > encoding > ser > castor > CastorEnumTypeDeserializer


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
17 package org.apache.axis.encoding.ser.castor;
18
19 import org.apache.axis.encoding.DeserializationContext;
20 import org.apache.axis.encoding.Deserializer;
21 import org.apache.axis.encoding.DeserializerImpl;
22 import org.apache.axis.message.MessageElement;
23 import org.apache.axis.utils.Messages;
24 import org.xml.sax.SAXException JavaDoc;
25
26 import javax.xml.namespace.QName JavaDoc;
27 import java.lang.reflect.Method JavaDoc;
28
29 /**
30  * Castor deserializer
31  *
32  * @author Ozzie Gurkan
33  * @version 1.0
34  */

35 public class CastorEnumTypeDeserializer
36         extends DeserializerImpl
37         implements Deserializer {
38
39     public QName JavaDoc xmlType;
40     public Class JavaDoc javaType;
41
42     public CastorEnumTypeDeserializer(Class JavaDoc javaType, QName JavaDoc xmlType) {
43         this.xmlType = xmlType;
44         this.javaType = javaType;
45     }
46
47     public void onEndElement(
48             String JavaDoc namespace,
49             String JavaDoc localName,
50             DeserializationContext context)
51             throws SAXException JavaDoc {
52
53         try {
54             MessageElement msgElem = context.getCurElement();
55             if (msgElem != null) {
56                 Method JavaDoc method = javaType.getMethod("valueOf", new Class JavaDoc[]{String JavaDoc.class});
57                 value = method.invoke(null, new Object JavaDoc[]{msgElem.getValue()});
58             }
59         } catch (Exception JavaDoc exp) {
60             log.error(Messages.getMessage("exception00"), exp);
61             throw new SAXException JavaDoc(exp);
62         }
63
64     }
65 }
66
Popular Tags