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 * Version: MPL 1.1 / GPLv3+ / LGPLv2.1+
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/
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
43 * Major Contributor(s):
44 * [ Copyright (C) 2011 Lionel Elie Mamane <lionel@mamane.lu> ]
46 * All Rights Reserved.
48 * For minor contributions see the git repository.
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.
56 ************************************************************************/
58 #include <rtl/ustrbuf.hxx>
59 #include <cppuhelper/typeprovider.hxx>
61 #include "pq_tools.hxx"
62 #include "pq_xbase.hxx"
64 using osl::MutexGuard
;
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
;
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
;
77 namespace pq_sdbc_driver
80 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 : OComponentHelper( refMutex
->mutex
),
88 OPropertySetHelper( OComponentHelper::rBHelper
),
89 m_implName( implName
),
90 m_supportedServices( supportedServices
),
91 m_refMutex( refMutex
),
93 m_pSettings( pSettings
),
95 m_values( props
.getProperties().getLength() )
98 cppu::IPropertyArrayHelper
& ReflectionBase::getInfoHelper()
103 sal_Bool
ReflectionBase::convertFastPropertyValue(
104 ::com::sun::star::uno::Any
& rConvertedValue
,
105 ::com::sun::star::uno::Any
& rOldValue
,
107 const ::com::sun::star::uno::Any
& rValue
)
108 throw (::com::sun::star::lang::IllegalArgumentException
)
111 rOldValue
= m_values
[nHandle
];
112 rConvertedValue
= rValue
; // TODO !!! implement correct conversion !
113 m_values
[nHandle
] = rValue
;
117 void ReflectionBase::setPropertyValue_NoBroadcast_public(
118 const rtl::OUString
& name
, const com::sun::star::uno::Any
& value
)
120 sal_Int32 nHandle
= m_propsDesc
.getHandleByName( name
);
123 rtl::OUStringBuffer
buf(128);
124 buf
.appendAscii( "Unkown property '" );
126 buf
.appendAscii( "' in " );
127 buf
.append( m_implName
);
128 throw com::sun::star::uno::RuntimeException( buf
.makeStringAndClear() , *this );
130 setFastPropertyValue_NoBroadcast( nHandle
, value
);
133 void ReflectionBase::setFastPropertyValue_NoBroadcast(
135 const ::com::sun::star::uno::Any
& rValue
)
136 throw (::com::sun::star::uno::Exception
)
140 // printf( "setting value (handle %d):%s\n" ,
141 // nHandle, rtl::OUStringToOString(s, RTL_TEXTENCODING_ASCII_US).getStr() );
142 m_values
[nHandle
] = rValue
;
145 void ReflectionBase::getFastPropertyValue(
146 ::com::sun::star::uno::Any
& rValue
,
147 sal_Int32 nHandle
) const
149 rValue
= m_values
[nHandle
];
152 // printf( "getting value (handle %d):%s\n" ,
153 // nHandle, rtl::OUStringToOString(s, RTL_TEXTENCODING_ASCII_US).getStr() );
157 Reference
< ::com::sun::star::beans::XPropertySetInfo
> ReflectionBase::getPropertySetInfo()
158 throw(com::sun::star::uno::RuntimeException
)
160 return OPropertySetHelper::createPropertySetInfo( m_propsDesc
);
163 rtl::OUString
ReflectionBase::getImplementationName()
164 throw(::com::sun::star::uno::RuntimeException
)
169 sal_Bool
ReflectionBase::supportsService(const rtl::OUString
& ServiceName
)
170 throw(::com::sun::star::uno::RuntimeException
)
172 for( int i
= 0 ; i
< m_supportedServices
.getLength() ; i
++ )
173 if( m_supportedServices
[i
] == ServiceName
)
178 Sequence
< rtl::OUString
> ReflectionBase::getSupportedServiceNames(void)
179 throw(::com::sun::star::uno::RuntimeException
)
181 return m_supportedServices
;
185 Sequence
< com::sun::star::uno::Type
> ReflectionBase::getTypes()
186 throw( com::sun::star::uno::RuntimeException
)
188 osl::MutexGuard
guard( m_refMutex
->mutex
);
189 static cppu::OTypeCollection
collection(
190 getCppuType( (Reference
< XPropertySet
>*) 0 ),
191 getCppuType( (Reference
< XFastPropertySet
> *) 0 ),
192 getCppuType( (Reference
< XMultiPropertySet
> *) 0 ),
193 getCppuType( (Reference
< com::sun::star::lang::XServiceInfo
> *) 0 ),
194 getCppuType( (Reference
< com::sun::star::sdbcx::XDataDescriptorFactory
> *) 0 ),
195 getCppuType( (Reference
< com::sun::star::container::XNamed
> *) 0 ),
196 OComponentHelper::getTypes());
197 return collection
.getTypes();
201 com::sun::star::uno::Any
ReflectionBase::queryInterface(
202 const com::sun::star::uno::Type
& reqType
)
203 throw (com::sun::star::uno::RuntimeException
)
206 ret
= OComponentHelper::queryInterface( reqType
);
207 if( ! ret
.hasValue() )
208 ret
= ::cppu::queryInterface(
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 static_cast< com::sun::star::container::XNamed
* > ( this ) );
220 Sequence
< sal_Int8
> ReflectionBase::getImplementationId() throw( RuntimeException
)
222 static cppu::OImplementationId
*pId
;
225 MutexGuard
guard( osl::Mutex::getGlobalMutex() );
228 static cppu::OImplementationId
id(sal_False
);
232 return pId
->getImplementationId();
235 void ReflectionBase::copyValuesFrom( const Reference
< XPropertySet
> & set
)
237 Reference
< XPropertySetInfo
> info
= set
->getPropertySetInfo();
240 Reference
< XPropertySetInfo
> myPropInfo
= getPropertySetInfo();
242 Sequence
< Property
> props
= info
->getProperties();
243 for( int i
= 0 ; i
< props
.getLength() ; i
++ )
245 if( myPropInfo
->hasPropertyByName( props
[i
].Name
) )
246 setPropertyValue_NoBroadcast_public(
247 props
[i
].Name
, set
->getPropertyValue( props
[i
].Name
) );
252 ::rtl::OUString
ReflectionBase::getName( ) throw (::com::sun::star::uno::RuntimeException
)
254 Statics
& st
= getStatics();
255 if( getInfoHelper().hasPropertyByName( st
.SCHEMA_NAME
) )
256 return concatQualified(
257 extractStringProperty( this, getStatics().SCHEMA_NAME
),
258 extractStringProperty( this, getStatics().NAME
) );
260 return extractStringProperty( this, getStatics().NAME
);
264 void ReflectionBase::setName( const ::rtl::OUString
& /* aName */ )
265 throw (::com::sun::star::uno::RuntimeException
)
267 throw RuntimeException(
269 RTL_CONSTASCII_USTRINGPARAM( "pq_sdbc::ReflectionBase::setName not implemented" ) ),
271 //setPropertyValue( getStatics().NAME , makeAny( aName ) );