001: /*
002: * File : $Source: /usr/local/cvs/opencms/src/org/opencms/main/CmsRuntimeException.java,v $
003: * Date : $Date: 2008-02-27 12:05:39 $
004: * Version: $Revision: 1.10 $
005: *
006: * This library is part of OpenCms -
007: * the Open Source Content Management System
008: *
009: * Copyright (c) 2002 - 2008 Alkacon Software GmbH (http://www.alkacon.com)
010: *
011: * This library is free software; you can redistribute it and/or
012: * modify it under the terms of the GNU Lesser General Public
013: * License as published by the Free Software Foundation; either
014: * version 2.1 of the License, or (at your option) any later version.
015: *
016: * This library is distributed in the hope that it will be useful,
017: * but WITHOUT ANY WARRANTY; without even the implied warranty of
018: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
019: * Lesser General Public License for more details.
020: *
021: * For further information about Alkacon Software GmbH, please see the
022: * company website: http://www.alkacon.com
023: *
024: * For further information about OpenCms, please see the
025: * project website: http://www.opencms.org
026: *
027: * You should have received a copy of the GNU Lesser General Public
028: * License along with this library; if not, write to the Free Software
029: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
030: */
031:
032: package org.opencms.main;
033:
034: import org.opencms.i18n.CmsMessageContainer;
035:
036: import java.util.Locale;
037:
038: /**
039: * A replacement for <code>{@link java.lang.RuntimeException}</code> to obtain fully
040: * localized exception messages for OpenCms.<p>
041: *
042: * @author Alexander Kandzior
043: *
044: * @version $Revision: 1.10 $
045: *
046: * @since 6.0.0
047: */
048: public class CmsRuntimeException extends RuntimeException implements
049: I_CmsThrowable {
050:
051: /** Serial version UID required for safe serialization. */
052: private static final long serialVersionUID = -7855345575622173787L;
053:
054: /** The container for the localized message. */
055: protected CmsMessageContainer m_message;
056:
057: /**
058: * Creates a new localized Exception.<p>
059: *
060: * @param message the localized message container to use
061: */
062: public CmsRuntimeException(CmsMessageContainer message) {
063:
064: super (message.getKey());
065: m_message = message;
066: }
067:
068: /**
069: * Creates a new localized Exception that also containes a root cause.<p>
070: *
071: * @param message the localized message container to use
072: * @param cause the Exception root cause
073: */
074: public CmsRuntimeException(CmsMessageContainer message,
075: Throwable cause) {
076:
077: super (message.getKey(), cause);
078: m_message = message;
079: }
080:
081: /**
082: * Creates a copied instance of this localized exception.<p>
083: *
084: * @param container the message container
085: * @param cause the root cause
086: *
087: * @return a copied instance of this localized exception
088: */
089: public CmsRuntimeException createException(
090: CmsMessageContainer container, Throwable cause) {
091:
092: return new CmsRuntimeException(container, cause);
093: }
094:
095: /**
096: * @see org.opencms.main.I_CmsThrowable#getLocalizedMessage()
097: */
098: public String getLocalizedMessage() {
099:
100: return m_message.key();
101: }
102:
103: /**
104: * @see org.opencms.main.I_CmsThrowable#getLocalizedMessage(Locale)
105: */
106: public String getLocalizedMessage(Locale locale) {
107:
108: return m_message.key(locale);
109: }
110:
111: /**
112: * @see java.lang.Throwable#getMessage()
113: */
114: public String getMessage() {
115:
116: return getLocalizedMessage();
117: }
118:
119: /**
120: * @see org.opencms.main.I_CmsThrowable#getMessageContainer()
121: */
122: public CmsMessageContainer getMessageContainer() {
123:
124: return m_message;
125: }
126: }
|