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>
40 #include <cppuhelper/queryinterface.hxx>
41 #include <comphelper/sequence.hxx>
43 #include "pq_tools.hxx"
44 #include "pq_xbase.hxx"
46 using osl::MutexGuard
;
48 using com::sun::star::uno::Any
;
49 using com::sun::star::uno::Sequence
;
50 using com::sun::star::uno::Reference
;
51 using com::sun::star::uno::RuntimeException
;
53 using com::sun::star::beans::Property
;
54 using com::sun::star::beans::XPropertySetInfo
;
55 using com::sun::star::beans::XPropertySet
;
57 namespace pq_sdbc_driver
60 ReflectionBase::ReflectionBase(
61 const OUString
&implName
,
62 const css::uno::Sequence
< OUString
> &supportedServices
,
63 const ::rtl::Reference
< comphelper::RefCountedMutex
>& refMutex
,
64 const css::uno::Reference
< css::sdbc::XConnection
> &conn
,
65 ConnectionSettings
*pSettings
,
66 cppu::IPropertyArrayHelper
& props
/* must survive this object !*/ )
67 : ReflectionBase_BASE( refMutex
->GetMutex() ),
68 OPropertySetHelper( ReflectionBase_BASE::rBHelper
),
69 m_implName( implName
),
70 m_supportedServices( supportedServices
),
73 m_pSettings( pSettings
),
75 m_values( props
.getProperties().getLength() )
78 cppu::IPropertyArrayHelper
& ReflectionBase::getInfoHelper()
83 sal_Bool
ReflectionBase::convertFastPropertyValue(
84 css::uno::Any
& rConvertedValue
,
85 css::uno::Any
& rOldValue
,
87 const css::uno::Any
& rValue
)
90 rOldValue
= m_values
[nHandle
];
91 rConvertedValue
= rValue
; // TODO !!! implement correct conversion !
92 m_values
[nHandle
] = rValue
;
96 void ReflectionBase::setPropertyValue_NoBroadcast_public(
97 const OUString
& name
, const css::uno::Any
& value
)
99 sal_Int32 nHandle
= m_propsDesc
.getHandleByName( name
);
102 throw css::uno::RuntimeException(
103 "Unknown property '" + name
+ "' in " + m_implName
,
106 setFastPropertyValue_NoBroadcast( nHandle
, value
);
109 void ReflectionBase::setFastPropertyValue_NoBroadcast(
111 const css::uno::Any
& rValue
)
115 // printf( "setting value (handle %d):%s\n" ,
116 // nHandle, OUStringToOString(s, RTL_TEXTENCODING_ASCII_US).getStr() );
117 m_values
[nHandle
] = rValue
;
120 void ReflectionBase::getFastPropertyValue(
121 css::uno::Any
& rValue
,
122 sal_Int32 nHandle
) const
124 rValue
= m_values
[nHandle
];
127 // printf( "getting value (handle %d):%s\n" ,
128 // nHandle, OUStringToOString(s, RTL_TEXTENCODING_ASCII_US).getStr() );
132 Reference
< css::beans::XPropertySetInfo
> ReflectionBase::getPropertySetInfo()
134 return OPropertySetHelper::createPropertySetInfo( m_propsDesc
);
137 OUString
ReflectionBase::getImplementationName()
142 sal_Bool
ReflectionBase::supportsService(const OUString
& ServiceName
)
144 return cppu::supportsService(this, ServiceName
);
147 Sequence
< OUString
> ReflectionBase::getSupportedServiceNames()
149 return m_supportedServices
;
153 Sequence
< css::uno::Type
> ReflectionBase::getTypes()
155 osl::MutexGuard
guard( m_xMutex
->GetMutex() );
156 static Sequence
< css::uno::Type
> collection(
157 ::comphelper::concatSequences(
158 ::cppu::OPropertySetHelper::getTypes(),
159 ReflectionBase_BASE::getTypes() ) );
164 css::uno::Any
ReflectionBase::queryInterface(
165 const css::uno::Type
& reqType
)
167 Any ret
= ReflectionBase_BASE::queryInterface( reqType
);
168 return ret
.hasValue() ? ret
: OPropertySetHelper::queryInterface( reqType
);
172 Sequence
< sal_Int8
> ReflectionBase::getImplementationId()
174 return css::uno::Sequence
<sal_Int8
>();
177 void ReflectionBase::copyValuesFrom( const Reference
< XPropertySet
> & set
)
179 Reference
< XPropertySetInfo
> info
= set
->getPropertySetInfo();
182 Reference
< XPropertySetInfo
> myPropInfo
= getPropertySetInfo();
184 Sequence
< Property
> props
= info
->getProperties();
185 for( int i
= 0 ; i
< props
.getLength() ; i
++ )
187 if( myPropInfo
->hasPropertyByName( props
[i
].Name
) )
188 setPropertyValue_NoBroadcast_public(
189 props
[i
].Name
, set
->getPropertyValue( props
[i
].Name
) );
194 OUString
ReflectionBase::getName( )
196 Statics
& st
= getStatics();
197 if( getInfoHelper().hasPropertyByName( st
.SCHEMA_NAME
) )
198 return concatQualified(
199 extractStringProperty( this, getStatics().SCHEMA_NAME
),
200 extractStringProperty( this, getStatics().NAME
) );
202 return extractStringProperty( this, getStatics().NAME
);
206 void ReflectionBase::setName( const OUString
& /* aName */ )
208 throw RuntimeException(
209 "pq_sdbc::ReflectionBase::setName not implemented",
211 //setPropertyValue( getStatics().NAME , makeAny( aName ) );
217 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */