1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_dbaccess.hxx"
30 
31 #ifndef _DBAUI_SQLMESSAGE_HXX_
32 #include "sqlmessage.hxx"
33 #endif
34 #ifndef _DBAUI_UNOSQLMESSAGE_HXX_
35 #include "unosqlmessage.hxx"
36 #endif
37 #ifndef _DBU_REGHELPER_HXX_
38 #include "dbu_reghelper.hxx"
39 #endif
40 #ifndef DBACCESS_SHARED_DBUSTRINGS_HRC
41 #include "dbustrings.hrc"
42 #endif
43 #ifndef _CPPUHELPER_TYPEPROVIDER_HXX_
44 #include <cppuhelper/typeprovider.hxx>
45 #endif
46 #ifndef _DBHELPER_DBEXCEPTION_HXX_
47 #include <connectivity/dbexception.hxx>
48 #endif
49 
50 using namespace dbaui;
51 using namespace dbtools;
52 
53 using namespace ::com::sun::star::sdbc;
54 using namespace ::com::sun::star::sdb;
55 
56 extern "C" void SAL_CALL createRegistryInfo_OSQLMessageDialog()
57 {
58 	static OMultiInstanceAutoRegistration< OSQLMessageDialog > aAutoRegistration;
59 }
60 
61 //.........................................................................
62 namespace dbaui
63 {
64 //.........................................................................
65 
66 	using namespace ::com::sun::star::uno;
67 	using namespace ::com::sun::star::lang;
68 	using namespace ::com::sun::star::beans;
69 
70 //=========================================================================
71 //-------------------------------------------------------------------------
72 OSQLMessageDialog::OSQLMessageDialog(const Reference< XMultiServiceFactory >& _rxORB)
73 	:OSQLMessageDialogBase(_rxORB)
74 {
75 	registerMayBeVoidProperty(PROPERTY_SQLEXCEPTION, PROPERTY_ID_SQLEXCEPTION, PropertyAttribute::TRANSIENT | PropertyAttribute::MAYBEVOID,
76 		&m_aException, ::getCppuType(static_cast<SQLException*>(NULL)));
77     registerProperty( PROPERTY_HELP_URL, PROPERTY_ID_HELP_URL, PropertyAttribute::TRANSIENT,
78         &m_sHelpURL, ::getCppuType( &m_sHelpURL ) );
79 }
80 
81 //-------------------------------------------------------------------------
82 Sequence<sal_Int8> SAL_CALL OSQLMessageDialog::getImplementationId(  ) throw(RuntimeException)
83 {
84 	static ::cppu::OImplementationId aId;
85 	return aId.getImplementationId();
86 }
87 
88 //-------------------------------------------------------------------------
89 Reference< XInterface > SAL_CALL OSQLMessageDialog::Create(const Reference< XMultiServiceFactory >& _rxFactory)
90 {
91 	return *(new OSQLMessageDialog(_rxFactory));
92 }
93 
94 //-------------------------------------------------------------------------
95 ::rtl::OUString SAL_CALL OSQLMessageDialog::getImplementationName() throw(RuntimeException)
96 {
97 	return getImplementationName_Static();
98 }
99 
100 //-------------------------------------------------------------------------
101 ::rtl::OUString OSQLMessageDialog::getImplementationName_Static() throw(RuntimeException)
102 {
103 	return ::rtl::OUString::createFromAscii("org.openoffice.comp.dbu.OSQLMessageDialog");
104 }
105 
106 //-------------------------------------------------------------------------
107 ::comphelper::StringSequence SAL_CALL OSQLMessageDialog::getSupportedServiceNames() throw(RuntimeException)
108 {
109 	return getSupportedServiceNames_Static();
110 }
111 
112 //-------------------------------------------------------------------------
113 ::comphelper::StringSequence OSQLMessageDialog::getSupportedServiceNames_Static() throw(RuntimeException)
114 {
115 	::comphelper::StringSequence aSupported(1);
116 	aSupported.getArray()[0] = ::rtl::OUString::createFromAscii("com.sun.star.sdb.ErrorMessageDialog");
117 	return aSupported;
118 }
119 
120 //-------------------------------------------------------------------------
121 sal_Bool SAL_CALL OSQLMessageDialog::convertFastPropertyValue( Any& _rConvertedValue, Any& _rOldValue, sal_Int32 _nHandle, const Any& _rValue) throw(IllegalArgumentException)
122 {
123 	switch (_nHandle)
124 	{
125 		case PROPERTY_ID_SQLEXCEPTION:
126 		{
127 			SQLExceptionInfo aInfo(_rValue);
128 			if (!aInfo.isValid())
129 				throw IllegalArgumentException();
130 
131 			_rOldValue = m_aException;
132 			_rConvertedValue = aInfo.get();
133 
134 			return sal_True;
135 				// always assume "modified", don't bother with with comparing the two values
136 		}
137 		default:
138 			return OSQLMessageDialogBase::convertFastPropertyValue(_rConvertedValue, _rOldValue, _nHandle, _rValue);
139 	}
140 }
141 
142 //-------------------------------------------------------------------------
143 Reference<XPropertySetInfo>  SAL_CALL OSQLMessageDialog::getPropertySetInfo() throw(RuntimeException)
144 {
145 	Reference<XPropertySetInfo>  xInfo( createPropertySetInfo( getInfoHelper() ) );
146 	return xInfo;
147 }
148 
149 //-------------------------------------------------------------------------
150 ::cppu::IPropertyArrayHelper& OSQLMessageDialog::getInfoHelper()
151 {
152 	return *const_cast<OSQLMessageDialog*>(this)->getArrayHelper();
153 }
154 
155 //------------------------------------------------------------------------------
156 ::cppu::IPropertyArrayHelper* OSQLMessageDialog::createArrayHelper( ) const
157 {
158 	Sequence< Property > aProps;
159 	describeProperties(aProps);
160 	return new ::cppu::OPropertyArrayHelper(aProps);
161 }
162 
163 //------------------------------------------------------------------------------
164 Dialog*	OSQLMessageDialog::createDialog(Window* _pParent)
165 {
166 	if ( m_aException.hasValue() )
167         return new OSQLMessageBox( _pParent, SQLExceptionInfo( m_aException ), WB_OK | WB_DEF_OK, m_sHelpURL );
168 
169 	OSL_ENSURE(sal_False, "OSQLMessageDialog::createDialog : You should use the SQLException property to specify the error to display!");
170 	return new OSQLMessageBox(_pParent, SQLException());
171 }
172 
173 //.........................................................................
174 }	// namespace dbaui
175 //.........................................................................
176 
177