1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: configexcept.cxx,v $
10 * $Revision: 1.7.10.3 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_configmgr.hxx"
34 #include "configexcept.hxx"
35 #include <osl/diagnose.h>
39 namespace configuration
41 //-----------------------------------------------------------------------------
43 //---------------------------------------------------------------------
44 Exception::Exception(char const* sAsciiMessage
)
45 : m_sAsciiMessage(sAsciiMessage
)
48 //---------------------------------------------------------------------
49 Exception::Exception(rtl::OString
const& sAsciiMessage
)
50 : m_sAsciiMessage(sAsciiMessage
)
53 //---------------------------------------------------------------------
55 rtl::OUString
Exception::message() const
58 return rtl::OStringToOUString( m_sAsciiMessage
, RTL_TEXTENCODING_ASCII_US
);
60 //---------------------------------------------------------------------
61 char const* Exception::what() const
63 return m_sAsciiMessage
.getLength() ? m_sAsciiMessage
.getStr() : "FAILURE in CONFIGURATION: No description available";
65 //---------------------------------------------------------------------
67 static const char c_sInvalidNamePre
[] = "CONFIGURATION: Invalid path or name: ";
68 static const char c_sInvalidName
[] = "CONFIGURATION: <Invalid path or name>";
69 //-----------------------------------------------------------------------------
71 //---------------------------------------------------------------------
73 InvalidName::InvalidName(rtl::OUString
const& sName
, char const* sAsciiDescription
)
74 : Exception( rtl::OString(RTL_CONSTASCII_STRINGPARAM(c_sInvalidName
)) += sAsciiDescription
)
75 , m_sName( sName
.concat(rtl::OUString::createFromAscii(sAsciiDescription
)) )
78 //---------------------------------------------------------------------
80 rtl::OUString
InvalidName::message() const
82 return rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(c_sInvalidNamePre
)).concat( m_sName
);
84 //-----------------------------------------------------------------------------
86 static const char c_sViolation
[] = "CONFIGURATION: Update Violates Constraint: ";
87 //---------------------------------------------------------------------
89 ConstraintViolation::ConstraintViolation(char const* sConstraint
)
90 : Exception( rtl::OString(RTL_CONSTASCII_STRINGPARAM(c_sViolation
)) += sConstraint
)
94 //-----------------------------------------------------------------------------
96 static const char c_sTypeMismatch
[] = "CONFIGURATION: Data Types do not match: ";
97 //---------------------------------------------------------------------
98 rtl::OUString
TypeMismatch::describe(rtl::OUString
const& sFoundType
, rtl::OUString
const& sExpectedType
)
100 rtl::OUString sRet
= rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Found Type: '"));
102 if (sExpectedType
.getLength() != 0)
104 sRet
+= rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("' - Expected Type: '"));
105 sRet
+= sExpectedType
;
106 sRet
+= rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("'"));
110 sRet
+= rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("' is not valid in this context"));
114 //---------------------------------------------------------------------
116 //---------------------------------------------------------------------
118 TypeMismatch::TypeMismatch(rtl::OUString
const& sType1
, rtl::OUString
const& sType2
)
119 : Exception( rtl::OString(RTL_CONSTASCII_STRINGPARAM(c_sTypeMismatch
)) )
120 , m_sTypes( describe(sType1
,sType2
) )
123 //---------------------------------------------------------------------
124 TypeMismatch::TypeMismatch(rtl::OUString
const& sType1
, rtl::OUString
const& sType2
, char const* sAsciiDescription
)
125 : Exception( rtl::OString(RTL_CONSTASCII_STRINGPARAM(c_sTypeMismatch
)) += sAsciiDescription
)
126 , m_sTypes( describe(sType1
,sType2
).concat(rtl::OUString::createFromAscii(sAsciiDescription
)) )
129 //---------------------------------------------------------------------
131 rtl::OUString
TypeMismatch::message() const
133 return rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(c_sTypeMismatch
)).concat( m_sTypes
);
135 //-----------------------------------------------------------------------------
140 //-----------------------------------------------------------------------------
141 ExceptionMapper::ExceptionMapper(configuration::Exception
& e
)
144 , m_sMessage(e
.message())
147 //---------------------------------------------------------------------
149 ExceptionMapper::~ExceptionMapper()
152 //---------------------------------------------------------------------
154 void ExceptionMapper::setContext(uno::XInterface
* pContext
)
156 m_xContext
= pContext
;
158 //---------------------------------------------------------------------
160 rtl::OUString
ExceptionMapper::message() const
162 return rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("FAILURE in CONFIGMGR: ")).concat( m_sMessage
);
164 //---------------------------------------------------------------------
166 uno::Reference
<uno::XInterface
> ExceptionMapper::context() const
170 //---------------------------------------------------------------------
172 void ExceptionMapper::illegalArgument(sal_Int16 nArgument
) throw(lang::IllegalArgumentException
)
174 throw lang::IllegalArgumentException(message(),context(),nArgument
);
176 //---------------------------------------------------------------------
178 void ExceptionMapper::unhandled() throw(uno::RuntimeException
)
180 throw uno::RuntimeException(message(),context());
182 //-----------------------------------------------------------------------------