001: /*
002: * The contents of this file are subject to the
003: * Mozilla Public License Version 1.1 (the "License");
004: * you may not use this file except in compliance with the License.
005: * You may obtain a copy of the License at http://www.mozilla.org/MPL/
006: *
007: * Software distributed under the License is distributed on an "AS IS"
008: * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied.
009: * See the License for the specific language governing rights and
010: * limitations under the License.
011: *
012: * The Initial Developer of the Original Code is Simulacra Media Ltd.
013: * Portions created by Simulacra Media Ltd are Copyright (C) Simulacra Media Ltd, 2004.
014: *
015: * All Rights Reserved.
016: *
017: * Contributor(s):
018: */
019:
020: package org.openharmonise.dav.server.utils;
021:
022: import java.net.MalformedURLException;
023:
024: import org.openharmonise.dav.server.apm.APMException;
025: import org.openharmonise.rm.*;
026: import org.openharmonise.rm.config.ConfigException;
027: import org.openharmonise.rm.metadata.InvalidProfileException;
028: import org.openharmonise.rm.resources.*;
029:
030: import com.ibm.webdav.*;
031:
032: /**
033: * Utility class which provides a method that can transform a general
034: * <code>Exception</code> and returns a <code>WebDAVException</code>
035: *
036: * @author Michael Bell
037: * @version $Revision: 1.1 $
038: *
039: */
040: public class ExceptionTransformer {
041:
042: /**
043: *
044: */
045: private ExceptionTransformer() {
046: super ();
047: }
048:
049: /**
050: * Returns a <code>WebDAVException</code> appropriate to the given
051: * <code>Exception</code>
052: *
053: * @param e
054: * @return
055: */
056: static public WebDAVException transform(Exception e) {
057: WebDAVException transform = null;
058:
059: if (e instanceof MalformedURLException) {
060: transform = new WebDAVException(
061: WebDAVStatus.SC_BAD_REQUEST, e
062: .getLocalizedMessage());
063: } else if (e instanceof PopulateException) {
064: transform = new WebDAVException(
065: WebDAVStatus.SC_INTERNAL_SERVER_ERROR, e
066: .getLocalizedMessage());
067: } else if (e instanceof InvalidNameException) {
068: transform = new WebDAVException(WebDAVStatus.SC_FORBIDDEN,
069: e.getLocalizedMessage());
070: } else if (e instanceof DataAccessException) {
071: transform = new WebDAVException(
072: WebDAVStatus.SC_INTERNAL_SERVER_ERROR, e
073: .getLocalizedMessage());
074: } else if (e instanceof InvalidProfileException) {
075: transform = new WebDAVException(WebDAVStatus.SC_FORBIDDEN,
076: e.getLocalizedMessage());
077: } else if (e instanceof InvalidChildException) {
078: transform = new WebDAVException(WebDAVStatus.SC_FORBIDDEN,
079: e.getLocalizedMessage());
080: } else if (e instanceof ConfigException) {
081: transform = new WebDAVException(
082: WebDAVStatus.SC_INTERNAL_SERVER_ERROR, e
083: .getLocalizedMessage());
084: } else if (e instanceof NameResolverException) {
085: transform = new WebDAVException(
086: WebDAVStatus.SC_INTERNAL_SERVER_ERROR, e
087: .getLocalizedMessage());
088: } else if (e instanceof ClassNotFoundException) {
089: transform = new WebDAVException(
090: WebDAVStatus.SC_INTERNAL_SERVER_ERROR, e
091: .getLocalizedMessage());
092: } else if (e instanceof InstantiationException) {
093: transform = new WebDAVException(
094: WebDAVStatus.SC_INTERNAL_SERVER_ERROR, e
095: .getLocalizedMessage());
096: } else if (e instanceof IllegalAccessException) {
097: transform = new WebDAVException(
098: WebDAVStatus.SC_INTERNAL_SERVER_ERROR, e
099: .getLocalizedMessage());
100: } else if (e instanceof APMException) {
101: transform = new WebDAVException(
102: WebDAVStatus.SC_INTERNAL_SERVER_ERROR, e
103: .getLocalizedMessage());
104: } else if ((e instanceof WebDAVException) == false) {
105: transform = new WebDAVException(
106: WebDAVStatus.SC_INTERNAL_SERVER_ERROR, e
107: .getLocalizedMessage());
108: }
109:
110: return transform;
111: }
112:
113: }
|