KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > openharmonise > dav > server > utils > ExceptionTransformer


1 /*
2  * The contents of this file are subject to the
3  * Mozilla Public License Version 1.1 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at http://www.mozilla.org/MPL/
6  *
7  * Software distributed under the License is distributed on an "AS IS"
8  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied.
9  * See the License for the specific language governing rights and
10  * limitations under the License.
11  *
12  * The Initial Developer of the Original Code is Simulacra Media Ltd.
13  * Portions created by Simulacra Media Ltd are Copyright (C) Simulacra Media Ltd, 2004.
14  *
15  * All Rights Reserved.
16  *
17  * Contributor(s):
18  */

19
20 package org.openharmonise.dav.server.utils;
21
22 import java.net.MalformedURLException JavaDoc;
23
24 import org.openharmonise.dav.server.apm.APMException;
25 import org.openharmonise.rm.*;
26 import org.openharmonise.rm.config.ConfigException;
27 import org.openharmonise.rm.metadata.InvalidProfileException;
28 import org.openharmonise.rm.resources.*;
29
30 import com.ibm.webdav.*;
31
32 /**
33  * Utility class which provides a method that can transform a general
34  * <code>Exception</code> and returns a <code>WebDAVException</code>
35  *
36  * @author Michael Bell
37  * @version $Revision: 1.1 $
38  *
39  */

40 public class ExceptionTransformer {
41
42     /**
43      *
44      */

45     private ExceptionTransformer() {
46         super();
47     }
48     
49     /**
50      * Returns a <code>WebDAVException</code> appropriate to the given
51      * <code>Exception</code>
52      *
53      * @param e
54      * @return
55      */

56     static public WebDAVException transform(Exception JavaDoc e) {
57         WebDAVException transform = null;
58         
59         if (e instanceof MalformedURLException JavaDoc) {
60             transform = new WebDAVException(
61                 WebDAVStatus.SC_BAD_REQUEST,
62                 e.getLocalizedMessage());
63         } else if (e instanceof PopulateException) {
64             transform = new WebDAVException(
65                     WebDAVStatus.SC_INTERNAL_SERVER_ERROR,
66                     e.getLocalizedMessage());
67         } else if (e instanceof InvalidNameException) {
68             transform = new WebDAVException(
69                     WebDAVStatus.SC_FORBIDDEN,
70                     e.getLocalizedMessage());
71         } else if (e instanceof DataAccessException) {
72             transform = new WebDAVException(
73                     WebDAVStatus.SC_INTERNAL_SERVER_ERROR,
74                     e.getLocalizedMessage());
75         } else if (e instanceof InvalidProfileException) {
76             transform = new WebDAVException(
77                     WebDAVStatus.SC_FORBIDDEN,
78                     e.getLocalizedMessage());
79         } else if (e instanceof InvalidChildException) {
80             transform = new WebDAVException(
81                     WebDAVStatus.SC_FORBIDDEN,
82                     e.getLocalizedMessage());
83         } else if (e instanceof ConfigException) {
84             transform = new WebDAVException(
85                     WebDAVStatus.SC_INTERNAL_SERVER_ERROR,
86                     e.getLocalizedMessage());
87         } else if (e instanceof NameResolverException) {
88             transform = new WebDAVException(
89                     WebDAVStatus.SC_INTERNAL_SERVER_ERROR,
90                     e.getLocalizedMessage());
91         } else if (e instanceof ClassNotFoundException JavaDoc) {
92             transform = new WebDAVException(
93                     WebDAVStatus.SC_INTERNAL_SERVER_ERROR,
94                     e.getLocalizedMessage());
95         } else if (e instanceof InstantiationException JavaDoc) {
96             transform = new WebDAVException(
97                     WebDAVStatus.SC_INTERNAL_SERVER_ERROR,
98                     e.getLocalizedMessage());
99         } else if (e instanceof IllegalAccessException JavaDoc) {
100             transform = new WebDAVException(
101                     WebDAVStatus.SC_INTERNAL_SERVER_ERROR,
102                     e.getLocalizedMessage());
103         } else if (e instanceof APMException) {
104             transform = new WebDAVException(
105                     WebDAVStatus.SC_INTERNAL_SERVER_ERROR,
106                     e.getLocalizedMessage());
107         } else if((e instanceof WebDAVException) == false) {
108             transform = new WebDAVException(
109                     WebDAVStatus.SC_INTERNAL_SERVER_ERROR,
110                     e.getLocalizedMessage());
111         }
112         
113         
114         return transform;
115     }
116
117 }
118
Popular Tags