Use correct object
[LibreOffice.git] / connectivity / source / drivers / postgresql / pq_xbase.cxx
blobdd9579fce0dabf7fba50251d11e854db514a568c
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * Effective License of whole file:
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.
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.
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
20 * Parts "Copyright by Sun Microsystems, Inc" prior to August 2011:
22 * The Contents of this file are made available subject to the terms of
23 * the GNU Lesser General Public License Version 2.1
25 * Copyright: 2000 by Sun Microsystems, Inc.
27 * Contributor(s): Joerg Budischewski
29 * All parts contributed on or after August 2011:
31 * This Source Code Form is subject to the terms of the Mozilla Public
32 * License, v. 2.0. If a copy of the MPL was not distributed with this
33 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
35 ************************************************************************/
37 #include <cppuhelper/supportsservice.hxx>
38 #include <comphelper/sequence.hxx>
39 #include <utility>
41 #include "pq_statics.hxx"
42 #include "pq_tools.hxx"
43 #include "pq_xbase.hxx"
45 using osl::MutexGuard;
47 using com::sun::star::uno::Any;
48 using com::sun::star::uno::Sequence;
49 using com::sun::star::uno::Reference;
50 using com::sun::star::uno::RuntimeException;
52 using com::sun::star::beans::Property;
53 using com::sun::star::beans::XPropertySetInfo;
54 using com::sun::star::beans::XPropertySet;
56 namespace pq_sdbc_driver
59 ReflectionBase::ReflectionBase(
60 OUString implName,
61 const css::uno::Sequence< OUString > &supportedServices,
62 const ::rtl::Reference< comphelper::RefCountedMutex >& refMutex,
63 css::uno::Reference< css::sdbc::XConnection > conn,
64 ConnectionSettings *pSettings,
65 cppu::IPropertyArrayHelper & props /* must survive this object !*/ )
66 : ReflectionBase_BASE( refMutex->GetMutex() ),
67 OPropertySetHelper( ReflectionBase_BASE::rBHelper ),
68 m_implName(std::move( implName )),
69 m_supportedServices( supportedServices ),
70 m_xMutex( refMutex ),
71 m_conn(std::move( conn )),
72 m_pSettings( pSettings ),
73 m_propsDesc( props ),
74 m_values( props.getProperties().getLength() )
77 cppu::IPropertyArrayHelper & ReflectionBase::getInfoHelper()
79 return m_propsDesc;
82 sal_Bool ReflectionBase::convertFastPropertyValue(
83 css::uno::Any & rConvertedValue,
84 css::uno::Any & rOldValue,
85 sal_Int32 nHandle,
86 const css::uno::Any& rValue )
89 rOldValue = m_values[nHandle];
90 rConvertedValue = rValue; // TODO !!! implement correct conversion !
91 m_values[nHandle] = rValue;
92 return true;
95 void ReflectionBase::setPropertyValue_NoBroadcast_public(
96 const OUString & name, const css::uno::Any & value )
98 sal_Int32 nHandle = m_propsDesc.getHandleByName( name );
99 if( -1 == nHandle )
101 throw css::uno::RuntimeException(
102 "Unknown property '" + name + "' in " + m_implName,
103 *this );
105 setFastPropertyValue_NoBroadcast( nHandle , value );
108 void ReflectionBase::setFastPropertyValue_NoBroadcast(
109 sal_Int32 nHandle,
110 const css::uno::Any& rValue )
112 // OUString s;
113 // rValue >>= s;
114 // printf( "setting value (handle %d):%s\n" ,
115 // nHandle, OUStringToOString(s, RTL_TEXTENCODING_ASCII_US).getStr() );
116 m_values[nHandle] = rValue;
119 void ReflectionBase::getFastPropertyValue(
120 css::uno::Any& rValue,
121 sal_Int32 nHandle ) const
123 rValue = m_values[nHandle];
124 // OUString s;
125 // rValue >>= s;
126 // printf( "getting value (handle %d):%s\n" ,
127 // nHandle, OUStringToOString(s, RTL_TEXTENCODING_ASCII_US).getStr() );
131 Reference < css::beans::XPropertySetInfo > ReflectionBase::getPropertySetInfo()
133 return OPropertySetHelper::createPropertySetInfo( m_propsDesc );
136 OUString ReflectionBase::getImplementationName()
138 return m_implName;
141 sal_Bool ReflectionBase::supportsService(const OUString& ServiceName)
143 return cppu::supportsService(this, ServiceName);
146 Sequence< OUString > ReflectionBase::getSupportedServiceNames()
148 return m_supportedServices;
152 Sequence< css::uno::Type > ReflectionBase::getTypes()
154 osl::MutexGuard guard( m_xMutex->GetMutex() );
155 static Sequence< css::uno::Type > collection(
156 ::comphelper::concatSequences(
157 ::cppu::OPropertySetHelper::getTypes(),
158 ReflectionBase_BASE::getTypes() ) );
159 return collection;
163 css::uno::Any ReflectionBase::queryInterface(
164 const css::uno::Type & reqType )
166 Any ret = ReflectionBase_BASE::queryInterface( reqType );
167 return ret.hasValue() ? ret : OPropertySetHelper::queryInterface( reqType );
171 Sequence< sal_Int8> ReflectionBase::getImplementationId()
173 return css::uno::Sequence<sal_Int8>();
176 void ReflectionBase::copyValuesFrom( const Reference< XPropertySet > & set )
178 Reference< XPropertySetInfo > info = set->getPropertySetInfo();
179 if( info.is () )
181 Reference< XPropertySetInfo > myPropInfo = getPropertySetInfo();
183 const Sequence< Property > props = info->getProperties();
184 for( Property const & prop : props )
186 if( myPropInfo->hasPropertyByName( prop.Name ) )
187 setPropertyValue_NoBroadcast_public(
188 prop.Name, set->getPropertyValue( prop.Name ) );
193 OUString ReflectionBase::getName( )
195 Statics & st = getStatics();
196 if( getInfoHelper().hasPropertyByName( st.SCHEMA_NAME ) )
197 return concatQualified(
198 extractStringProperty( this, getStatics().SCHEMA_NAME ),
199 extractStringProperty( this, getStatics().NAME ) );
200 else
201 return extractStringProperty( this, getStatics().NAME );
205 void ReflectionBase::setName( const OUString& /* aName */ )
207 throw RuntimeException(
208 u"pq_sdbc::ReflectionBase::setName not implemented"_ustr,
209 *this );
210 //setPropertyValue( getStatics().NAME , makeAny( aName ) );
216 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */