Source code: org/apache/axis/encoding/ser/EnumDeserializer.java
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;
20 import java.beans.IntrospectionException;
21 import java.lang.reflect.Method;
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 fromStringMethod = null;
34
35 private static final Class[] STRING_CLASS = new Class[] { java.lang.String.class };
36
37 public EnumDeserializer(Class javaType, QName xmlType) {
38 super(javaType, xmlType);
39 }
40
41 public Object makeValue(String source) throws Exception
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 e) {
50 throw new IntrospectionException(e.toString());
51 }
52 }
53 return fromStringMethod.invoke(null,new Object [] { source });
54 }
55 }