001/* 002 * Copyright (c) 2006-2011 Nuxeo SA (http://nuxeo.com/) and others. 003 * 004 * All rights reserved. This program and the accompanying materials 005 * are made available under the terms of the Eclipse Public License v1.0 006 * which accompanies this distribution, and is available at 007 * http://www.eclipse.org/legal/epl-v10.html 008 * 009 * Contributors: 010 * bstefanescu 011 * 012 * $Id$ 013 */ 014 015package org.nuxeo.ecm.core.api; 016 017/** 018 * @author <a href="mailto:bs@nuxeo.com">Bogdan Stefanescu</a> 019 */ 020public class WrappedException extends Exception { 021 022 private static final long serialVersionUID = -8068323167952050687L; 023 024 // the class name of the original exception 025 private String className; 026 027 private WrappedException(String message, WrappedException cause) { 028 super(message, cause); 029 } 030 031 public String getClassName() { 032 return className; 033 } 034 035 public boolean sameAs(String className) { 036 return this.className == null ? className == null : this.className.equals(className); 037 } 038 039 /** 040 * No need to wrap Exception since RMI is not supported anymore 041 * 042 * @deprecated since 5.6 043 */ 044 @Deprecated 045 @SuppressWarnings({ "ThrowableInstanceNeverThrown" }) 046 public static WrappedException wrap(Throwable t) { 047 if (t == null) { 048 return null; 049 } 050 if (t instanceof WrappedException) { 051 return (WrappedException) t; 052 } 053 String exceptionClass = t.getClass().getName(); 054 String message = "Exception: " + exceptionClass + ". message: " + t.getMessage(); 055 WrappedException cause = wrap(t.getCause()); 056 WrappedException we = new WrappedException(message, cause); 057 we.className = exceptionClass; 058 we.setStackTrace(t.getStackTrace()); 059 return we; 060 } 061 062}