Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * Effective License of whole file:
5 : : *
6 : : * This library is free software; you can redistribute it and/or
7 : : * modify it under the terms of the GNU Lesser General Public
8 : : * License version 2.1, as published by the Free Software Foundation.
9 : : *
10 : : * This library is distributed in the hope that it will be useful,
11 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 : : * Lesser General Public License for more details.
14 : : *
15 : : * You should have received a copy of the GNU Lesser General Public
16 : : * License along with this library; if not, write to the Free Software
17 : : * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
18 : : * MA 02111-1307 USA
19 : : *
20 : : * Parts "Copyright by Sun Microsystems, Inc" prior to August 2011:
21 : : *
22 : : * The Contents of this file are made available subject to the terms of
23 : : * the GNU Lesser General Public License Version 2.1
24 : : *
25 : : * Copyright: 2000 by Sun Microsystems, Inc.
26 : : *
27 : : * Contributor(s): Joerg Budischewski
28 : : *
29 : : * All parts contributed on or after August 2011:
30 : : *
31 : : * Version: MPL 1.1 / GPLv3+ / LGPLv2.1+
32 : : *
33 : : * The contents of this file are subject to the Mozilla Public License Version
34 : : * 1.1 (the "License"); you may not use this file except in compliance with
35 : : * the License or as specified alternatively below. You may obtain a copy of
36 : : * the License at http://www.mozilla.org/MPL/
37 : : *
38 : : * Software distributed under the License is distributed on an "AS IS" basis,
39 : : * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
40 : : * for the specific language governing rights and limitations under the
41 : : * License.
42 : : *
43 : : * Major Contributor(s):
44 : : * [ Copyright (C) 2011 Lionel Elie Mamane <lionel@mamane.lu> ]
45 : : *
46 : : * All Rights Reserved.
47 : : *
48 : : * For minor contributions see the git repository.
49 : : *
50 : : * Alternatively, the contents of this file may be used under the terms of
51 : : * either the GNU General Public License Version 3 or later (the "GPLv3+"), or
52 : : * the GNU Lesser General Public License Version 2.1 or later (the "LGPLv2.1+"),
53 : : * in which case the provisions of the GPLv3+ or the LGPLv2.1+ are applicable
54 : : * instead of those above.
55 : : *
56 : : ************************************************************************/
57 : :
58 : : #include <rtl/ustrbuf.hxx>
59 : : #include <cppuhelper/typeprovider.hxx>
60 : :
61 : : #include "pq_tools.hxx"
62 : : #include "pq_xbase.hxx"
63 : :
64 : : using osl::MutexGuard;
65 : :
66 : : using com::sun::star::uno::Any;
67 : : using com::sun::star::uno::Sequence;
68 : : using com::sun::star::uno::Reference;
69 : : using com::sun::star::uno::RuntimeException;
70 : :
71 : : using com::sun::star::beans::Property;
72 : : using com::sun::star::beans::XPropertySetInfo;
73 : : using com::sun::star::beans::XMultiPropertySet;
74 : : using com::sun::star::beans::XFastPropertySet;
75 : : using com::sun::star::beans::XPropertySet;
76 : :
77 : : namespace pq_sdbc_driver
78 : : {
79 : :
80 : 0 : ReflectionBase::ReflectionBase(
81 : : const ::rtl::OUString &implName,
82 : : const ::com::sun::star::uno::Sequence< rtl::OUString > &supportedServices,
83 : : const ::rtl::Reference< RefCountedMutex > refMutex,
84 : : const ::com::sun::star::uno::Reference< com::sun::star::sdbc::XConnection > &conn,
85 : : ConnectionSettings *pSettings,
86 : : cppu::IPropertyArrayHelper & props /* must survive this object !*/ )
87 : 0 : : OComponentHelper( refMutex->mutex ),
88 : : OPropertySetHelper( OComponentHelper::rBHelper ),
89 : : m_implName( implName ),
90 : : m_supportedServices( supportedServices ),
91 : : m_refMutex( refMutex ),
92 : : m_conn( conn ),
93 : : m_pSettings( pSettings ),
94 : : m_propsDesc( props ),
95 : 0 : m_values( props.getProperties().getLength() )
96 : 0 : {}
97 : :
98 : 0 : cppu::IPropertyArrayHelper & ReflectionBase::getInfoHelper()
99 : : {
100 : 0 : return m_propsDesc;
101 : : }
102 : :
103 : 0 : sal_Bool ReflectionBase::convertFastPropertyValue(
104 : : ::com::sun::star::uno::Any & rConvertedValue,
105 : : ::com::sun::star::uno::Any & rOldValue,
106 : : sal_Int32 nHandle,
107 : : const ::com::sun::star::uno::Any& rValue )
108 : : throw (::com::sun::star::lang::IllegalArgumentException)
109 : : {
110 : :
111 : 0 : rOldValue = m_values[nHandle];
112 : 0 : rConvertedValue = rValue; // TODO !!! implement correct conversion !
113 : 0 : m_values[nHandle] = rValue;
114 : 0 : return sal_True;
115 : : }
116 : :
117 : 0 : void ReflectionBase::setPropertyValue_NoBroadcast_public(
118 : : const rtl::OUString & name, const com::sun::star::uno::Any & value )
119 : : {
120 : 0 : sal_Int32 nHandle = m_propsDesc.getHandleByName( name );
121 : 0 : if( -1 == nHandle )
122 : : {
123 : 0 : rtl::OUStringBuffer buf(128);
124 : 0 : buf.appendAscii( "Unkown property '" );
125 : 0 : buf.append( name );
126 : 0 : buf.appendAscii( "' in " );
127 : 0 : buf.append( m_implName );
128 : 0 : throw com::sun::star::uno::RuntimeException( buf.makeStringAndClear() , *this );
129 : : }
130 : 0 : setFastPropertyValue_NoBroadcast( nHandle , value );
131 : 0 : }
132 : :
133 : 0 : void ReflectionBase::setFastPropertyValue_NoBroadcast(
134 : : sal_Int32 nHandle,
135 : : const ::com::sun::star::uno::Any& rValue )
136 : : throw (::com::sun::star::uno::Exception)
137 : : {
138 : : // rtl::OUString s;
139 : : // rValue >>= s;
140 : : // printf( "setting value (handle %d):%s\n" ,
141 : : // nHandle, rtl::OUStringToOString(s, RTL_TEXTENCODING_ASCII_US).getStr() );
142 : 0 : m_values[nHandle] = rValue;
143 : 0 : }
144 : :
145 : 0 : void ReflectionBase::getFastPropertyValue(
146 : : ::com::sun::star::uno::Any& rValue,
147 : : sal_Int32 nHandle ) const
148 : : {
149 : 0 : rValue = m_values[nHandle];
150 : : // rtl::OUString s;
151 : : // rValue >>= s;
152 : : // printf( "getting value (handle %d):%s\n" ,
153 : : // nHandle, rtl::OUStringToOString(s, RTL_TEXTENCODING_ASCII_US).getStr() );
154 : :
155 : 0 : }
156 : :
157 : 0 : Reference < ::com::sun::star::beans::XPropertySetInfo > ReflectionBase::getPropertySetInfo()
158 : : throw(com::sun::star::uno::RuntimeException)
159 : : {
160 : 0 : return OPropertySetHelper::createPropertySetInfo( m_propsDesc );
161 : : }
162 : :
163 : 0 : rtl::OUString ReflectionBase::getImplementationName()
164 : : throw(::com::sun::star::uno::RuntimeException)
165 : : {
166 : 0 : return m_implName;
167 : : }
168 : :
169 : 0 : sal_Bool ReflectionBase::supportsService(const rtl::OUString& ServiceName)
170 : : throw(::com::sun::star::uno::RuntimeException)
171 : : {
172 : 0 : for( int i = 0 ; i < m_supportedServices.getLength() ; i ++ )
173 : 0 : if( m_supportedServices[i] == ServiceName )
174 : 0 : return sal_True;
175 : 0 : return sal_False;
176 : : }
177 : :
178 : 0 : Sequence< rtl::OUString > ReflectionBase::getSupportedServiceNames(void)
179 : : throw(::com::sun::star::uno::RuntimeException)
180 : : {
181 : 0 : return m_supportedServices;
182 : : }
183 : :
184 : :
185 : 0 : Sequence< com::sun::star::uno::Type > ReflectionBase::getTypes()
186 : : throw( com::sun::star::uno::RuntimeException )
187 : : {
188 : 0 : osl::MutexGuard guard( m_refMutex->mutex );
189 : : static cppu::OTypeCollection collection(
190 : 0 : getCppuType( (Reference< XPropertySet >*) 0 ),
191 : 0 : getCppuType( (Reference< XFastPropertySet > *) 0 ),
192 : 0 : getCppuType( (Reference< XMultiPropertySet > *) 0 ),
193 : 0 : getCppuType( (Reference< com::sun::star::lang::XServiceInfo > *) 0 ),
194 : 0 : getCppuType( (Reference< com::sun::star::sdbcx::XDataDescriptorFactory > *) 0 ),
195 : 0 : getCppuType( (Reference< com::sun::star::container::XNamed > *) 0 ),
196 : 0 : OComponentHelper::getTypes());
197 : 0 : return collection.getTypes();
198 : : }
199 : :
200 : :
201 : 0 : com::sun::star::uno::Any ReflectionBase::queryInterface(
202 : : const com::sun::star::uno::Type & reqType )
203 : : throw (com::sun::star::uno::RuntimeException)
204 : : {
205 : 0 : Any ret;
206 : 0 : ret = OComponentHelper::queryInterface( reqType );
207 : 0 : if( ! ret.hasValue() )
208 : : ret = ::cppu::queryInterface(
209 : : reqType,
210 : : static_cast< com::sun::star::beans::XPropertySet * > ( this ),
211 : : static_cast< com::sun::star::beans::XMultiPropertySet * > ( this ),
212 : : static_cast< com::sun::star::lang::XServiceInfo * > ( this ),
213 : : static_cast< com::sun::star::beans::XFastPropertySet * > ( this ) ,
214 : : static_cast< com::sun::star::sdbcx::XDataDescriptorFactory * > ( this ),
215 : 0 : static_cast< com::sun::star::container::XNamed * > ( this ) );
216 : 0 : return ret;
217 : :
218 : : }
219 : :
220 : 0 : Sequence< sal_Int8> ReflectionBase::getImplementationId() throw( RuntimeException )
221 : : {
222 : : static cppu::OImplementationId *pId;
223 : 0 : if( ! pId )
224 : : {
225 : 0 : MutexGuard guard( osl::Mutex::getGlobalMutex() );
226 : 0 : if( ! pId )
227 : : {
228 : 0 : static cppu::OImplementationId id(sal_False);
229 : 0 : pId = &id;
230 : 0 : }
231 : : }
232 : 0 : return pId->getImplementationId();
233 : : }
234 : :
235 : 0 : void ReflectionBase::copyValuesFrom( const Reference< XPropertySet > & set )
236 : : {
237 : 0 : Reference< XPropertySetInfo > info = set->getPropertySetInfo();
238 : 0 : if( info.is () )
239 : : {
240 : 0 : Reference< XPropertySetInfo > myPropInfo = getPropertySetInfo();
241 : :
242 : 0 : Sequence< Property > props = info->getProperties();
243 : 0 : for( int i = 0 ; i < props.getLength() ; i ++ )
244 : : {
245 : 0 : if( myPropInfo->hasPropertyByName( props[i].Name ) )
246 : : setPropertyValue_NoBroadcast_public(
247 : 0 : props[i].Name, set->getPropertyValue( props[i].Name ) );
248 : 0 : }
249 : 0 : }
250 : 0 : }
251 : :
252 : 0 : ::rtl::OUString ReflectionBase::getName( ) throw (::com::sun::star::uno::RuntimeException)
253 : : {
254 : 0 : Statics & st = getStatics();
255 : 0 : if( getInfoHelper().hasPropertyByName( st.SCHEMA_NAME ) )
256 : : return concatQualified(
257 : 0 : extractStringProperty( this, getStatics().SCHEMA_NAME ),
258 : 0 : extractStringProperty( this, getStatics().NAME ) );
259 : : else
260 : 0 : return extractStringProperty( this, getStatics().NAME );
261 : : }
262 : :
263 : :
264 : 0 : void ReflectionBase::setName( const ::rtl::OUString& /* aName */ )
265 : : throw (::com::sun::star::uno::RuntimeException)
266 : : {
267 : : throw RuntimeException(
268 : : rtl::OUString(
269 : : RTL_CONSTASCII_USTRINGPARAM( "pq_sdbc::ReflectionBase::setName not implemented" ) ),
270 : 0 : *this );
271 : : //setPropertyValue( getStatics().NAME , makeAny( aName ) );
272 : : }
273 : :
274 : :
275 : : }
|