KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > axis > encoding > ser > EnumDeserializer


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;
18
19 import javax.xml.namespace.QName JavaDoc;
20 import java.beans.IntrospectionException JavaDoc;
21 import java.lang.reflect.Method JavaDoc;
22
23 import org.apache.axis.utils.cache.MethodCache;
24
25 /**
26  * Deserializer for a JAX-RPC enum.
27  *
28  * @author Rich Scheuerle <scheu@us.ibm.com>
29  * @author Sam Ruby <rubys@us.ibm.com>
30  */

31 public class EnumDeserializer extends SimpleDeserializer {
32
33     private Method JavaDoc fromStringMethod = null;
34
35     private static final Class JavaDoc[] STRING_CLASS = new Class JavaDoc[] { java.lang.String JavaDoc.class };
36
37     public EnumDeserializer(Class JavaDoc javaType, QName JavaDoc xmlType) {
38         super(javaType, xmlType);
39     }
40
41     public Object JavaDoc makeValue(String JavaDoc source) throws Exception JavaDoc
42     {
43         // Invoke the fromString static method to get the Enumeration value
44
if (isNil)
45             return null;
46         if (fromStringMethod == null) {
47             try {
48                 fromStringMethod = MethodCache.getInstance().getMethod(javaType, "fromString", STRING_CLASS);
49             } catch (Exception JavaDoc e) {
50                 throw new IntrospectionException JavaDoc(e.toString());
51             }
52         }
53         return fromStringMethod.invoke(null,new Object JavaDoc [] { source });
54     }
55 }
56
Popular Tags