KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > directwebremoting > convert > ExceptionConverter


1 /*
2  * Copyright 2005 Joe Walker
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.directwebremoting.convert;
17
18 import java.beans.IntrospectionException JavaDoc;
19 import java.beans.PropertyDescriptor JavaDoc;
20 import java.util.Map JavaDoc;
21
22 import org.directwebremoting.extend.MarshallException;
23 import org.directwebremoting.impl.PropertyDescriptorProperty;
24
25 /**
26  * A special case of BeanConverter that doesn't convert StackTraces
27  * @author Joe Walker [joe at getahead dot ltd dot uk]
28  */

29 public class ExceptionConverter extends BeanConverter
30 {
31     /* (non-Javadoc)
32      * @see org.directwebremoting.convert.BasicBeanConverter#getPropertyDescriptors(java.lang.Class, boolean, boolean)
33      */

34     public Map JavaDoc getPropertyMapFromClass(Class JavaDoc type, boolean readRequired, boolean writeRequired) throws MarshallException
35     {
36         Map JavaDoc descriptors = super.getPropertyMapFromClass(type, readRequired, writeRequired);
37         descriptors.put("javaClassName", new PlainProperty("javaClassName", type.getName()));
38
39         // Make sure Throwable's standard properties are added
40
// (fix for Bean Introspector peculiarities)
41
try
42         {
43             fixMissingThrowableProperty(descriptors, "message", "getMessage");
44             fixMissingThrowableProperty(descriptors, "cause", "getCause");
45         }
46         catch (IntrospectionException JavaDoc ex)
47         {
48             throw new MarshallException(type, ex);
49         }
50
51         return descriptors;
52     }
53
54     /**
55      * Make sure Throwable's standard properties are added
56      * (fix for Bean Introspector peculiarities)
57      * @param descriptors The Map of the known descriptors
58      * @param name The name of the property to add
59      * @param readMethodName A method name to use when getting said property
60      * @throws IntrospectionException If we fail to build a PropertyDescriptor
61      */

62     protected void fixMissingThrowableProperty(Map JavaDoc descriptors, String JavaDoc name, String JavaDoc readMethodName) throws IntrospectionException JavaDoc
63     {
64         if (!descriptors.containsKey(name) && isAllowedByIncludeExcludeRules(name))
65         {
66             PropertyDescriptor JavaDoc descriptor = new PropertyDescriptor JavaDoc(name, Throwable JavaDoc.class, readMethodName, null);
67             descriptors.put(name, new PropertyDescriptorProperty(descriptor));
68         }
69     }
70 }
71
Popular Tags