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,
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 <rtl/ustrbuf.hxx>
38 #include <cppuhelper/supportsservice.hxx>
39 #include <cppuhelper/typeprovider.hxx>
41 #include "pq_tools.hxx"
42 #include "pq_xbase.hxx"
44 using osl::MutexGuard
;
46 using com::sun::star::uno::Any
;
47 using com::sun::star::uno::Sequence
;
48 using com::sun::star::uno::Reference
;
49 using com::sun::star::uno::RuntimeException
;
51 using com::sun::star::beans::Property
;
52 using com::sun::star::beans::XPropertySetInfo
;
53 using com::sun::star::beans::XMultiPropertySet
;
54 using com::sun::star::beans::XFastPropertySet
;
55 using com::sun::star::beans::XPropertySet
;
57 namespace pq_sdbc_driver
60 ReflectionBase::ReflectionBase(
61 const OUString
&implName
,
62 const ::com::sun::star::uno::Sequence
< OUString
> &supportedServices
,
63 const ::rtl::Reference
< RefCountedMutex
> refMutex
,
64 const ::com::sun::star::uno::Reference
< com::sun::star::sdbc::XConnection
> &conn
,
65 ConnectionSettings
*pSettings
,
66 cppu::IPropertyArrayHelper
& props
/* must survive this object !*/ )
67 : OComponentHelper( refMutex
->mutex
),
68 OPropertySetHelper( OComponentHelper::rBHelper
),
69 m_implName( implName
),
70 m_supportedServices( supportedServices
),
71 m_refMutex( refMutex
),
73 m_pSettings( pSettings
),
75 m_values( props
.getProperties().getLength() )
78 cppu::IPropertyArrayHelper
& ReflectionBase::getInfoHelper()
83 sal_Bool
ReflectionBase::convertFastPropertyValue(
84 ::com::sun::star::uno::Any
& rConvertedValue
,
85 ::com::sun::star::uno::Any
& rOldValue
,
87 const ::com::sun::star::uno::Any
& rValue
)
88 throw (::com::sun::star::lang::IllegalArgumentException
)
91 rOldValue
= m_values
[nHandle
];
92 rConvertedValue
= rValue
; // TODO !!! implement correct conversion !
93 m_values
[nHandle
] = rValue
;
97 void ReflectionBase::setPropertyValue_NoBroadcast_public(
98 const OUString
& name
, const com::sun::star::uno::Any
& value
)
100 sal_Int32 nHandle
= m_propsDesc
.getHandleByName( name
);
103 OUStringBuffer
buf(128);
104 buf
.appendAscii( "Unknown property '" );
106 buf
.appendAscii( "' in " );
107 buf
.append( m_implName
);
108 throw com::sun::star::uno::RuntimeException( buf
.makeStringAndClear() , *this );
110 setFastPropertyValue_NoBroadcast( nHandle
, value
);
113 void ReflectionBase::setFastPropertyValue_NoBroadcast(
115 const ::com::sun::star::uno::Any
& rValue
)
116 throw (::com::sun::star::uno::Exception
, std::exception
)
120 // printf( "setting value (handle %d):%s\n" ,
121 // nHandle, OUStringToOString(s, RTL_TEXTENCODING_ASCII_US).getStr() );
122 m_values
[nHandle
] = rValue
;
125 void ReflectionBase::getFastPropertyValue(
126 ::com::sun::star::uno::Any
& rValue
,
127 sal_Int32 nHandle
) const
129 rValue
= m_values
[nHandle
];
132 // printf( "getting value (handle %d):%s\n" ,
133 // nHandle, OUStringToOString(s, RTL_TEXTENCODING_ASCII_US).getStr() );
137 Reference
< ::com::sun::star::beans::XPropertySetInfo
> ReflectionBase::getPropertySetInfo()
138 throw(com::sun::star::uno::RuntimeException
, std::exception
)
140 return OPropertySetHelper::createPropertySetInfo( m_propsDesc
);
143 OUString
ReflectionBase::getImplementationName()
144 throw(::com::sun::star::uno::RuntimeException
, std::exception
)
149 sal_Bool
ReflectionBase::supportsService(const OUString
& ServiceName
)
150 throw(::com::sun::star::uno::RuntimeException
, std::exception
)
152 return cppu::supportsService(this, ServiceName
);
155 Sequence
< OUString
> ReflectionBase::getSupportedServiceNames(void)
156 throw(::com::sun::star::uno::RuntimeException
, std::exception
)
158 return m_supportedServices
;
162 Sequence
< com::sun::star::uno::Type
> ReflectionBase::getTypes()
163 throw( com::sun::star::uno::RuntimeException
, std::exception
)
165 osl::MutexGuard
guard( m_refMutex
->mutex
);
166 static cppu::OTypeCollection
collection(
167 getCppuType( (Reference
< XPropertySet
>*) 0 ),
168 getCppuType( (Reference
< XFastPropertySet
> *) 0 ),
169 getCppuType( (Reference
< XMultiPropertySet
> *) 0 ),
170 getCppuType( (Reference
< com::sun::star::lang::XServiceInfo
> *) 0 ),
171 getCppuType( (Reference
< com::sun::star::sdbcx::XDataDescriptorFactory
> *) 0 ),
172 getCppuType( (Reference
< com::sun::star::container::XNamed
> *) 0 ),
173 OComponentHelper::getTypes());
174 return collection
.getTypes();
178 com::sun::star::uno::Any
ReflectionBase::queryInterface(
179 const com::sun::star::uno::Type
& reqType
)
180 throw (com::sun::star::uno::RuntimeException
, std::exception
)
183 ret
= OComponentHelper::queryInterface( reqType
);
184 if( ! ret
.hasValue() )
185 ret
= ::cppu::queryInterface(
187 static_cast< com::sun::star::beans::XPropertySet
* > ( this ),
188 static_cast< com::sun::star::beans::XMultiPropertySet
* > ( this ),
189 static_cast< com::sun::star::lang::XServiceInfo
* > ( this ),
190 static_cast< com::sun::star::beans::XFastPropertySet
* > ( this ) ,
191 static_cast< com::sun::star::sdbcx::XDataDescriptorFactory
* > ( this ),
192 static_cast< com::sun::star::container::XNamed
* > ( this ) );
197 Sequence
< sal_Int8
> ReflectionBase::getImplementationId() throw( RuntimeException
, std::exception
)
199 return css::uno::Sequence
<sal_Int8
>();
202 void ReflectionBase::copyValuesFrom( const Reference
< XPropertySet
> & set
)
204 Reference
< XPropertySetInfo
> info
= set
->getPropertySetInfo();
207 Reference
< XPropertySetInfo
> myPropInfo
= getPropertySetInfo();
209 Sequence
< Property
> props
= info
->getProperties();
210 for( int i
= 0 ; i
< props
.getLength() ; i
++ )
212 if( myPropInfo
->hasPropertyByName( props
[i
].Name
) )
213 setPropertyValue_NoBroadcast_public(
214 props
[i
].Name
, set
->getPropertyValue( props
[i
].Name
) );
219 OUString
ReflectionBase::getName( ) throw (::com::sun::star::uno::RuntimeException
, std::exception
)
221 Statics
& st
= getStatics();
222 if( getInfoHelper().hasPropertyByName( st
.SCHEMA_NAME
) )
223 return concatQualified(
224 extractStringProperty( this, getStatics().SCHEMA_NAME
),
225 extractStringProperty( this, getStatics().NAME
) );
227 return extractStringProperty( this, getStatics().NAME
);
231 void ReflectionBase::setName( const OUString
& /* aName */ )
232 throw (::com::sun::star::uno::RuntimeException
, std::exception
)
234 throw RuntimeException(
235 OUString( "pq_sdbc::ReflectionBase::setName not implemented" ),
237 //setPropertyValue( getStatics().NAME , makeAny( aName ) );
243 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */