1 /*************************************************************************
3 * $RCSfile: pq_xbase.cxx,v $
7 * last change: $Author: jbu $ $Date: 2004/06/10 15:26:59 $
9 * The Contents of this file are made available subject to the terms of
10 * either of the following licenses
12 * - GNU Lesser General Public License Version 2.1
13 * - Sun Industry Standards Source License Version 1.1
15 * Sun Microsystems Inc., October, 2000
17 * GNU Lesser General Public License Version 2.1
18 * =============================================
19 * Copyright 2000 by Sun Microsystems, Inc.
20 * 901 San Antonio Road, Palo Alto, CA 94303, USA
22 * This library is free software; you can redistribute it and/or
23 * modify it under the terms of the GNU Lesser General Public
24 * License version 2.1, as published by the Free Software Foundation.
26 * This library is distributed in the hope that it will be useful,
27 * but WITHOUT ANY WARRANTY; without even the implied warranty of
28 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
29 * Lesser General Public License for more details.
31 * You should have received a copy of the GNU Lesser General Public
32 * License along with this library; if not, write to the Free Software
33 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
37 * Sun Industry Standards Source License Version 1.1
38 * =================================================
39 * The contents of this file are subject to the Sun Industry Standards
40 * Source License Version 1.1 (the "License"); You may not use this file
41 * except in compliance with the License. You may obtain a copy of the
42 * License at http://www.openoffice.org/license.html.
44 * Software provided under this License is provided on an "AS IS" basis,
45 * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
46 * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
47 * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
48 * See the License for the specific provisions governing your rights and
49 * obligations concerning the Software.
51 * The Initial Developer of the Original Code is: Joerg Budischewski
53 * Copyright: 2000 by Sun Microsystems, Inc.
55 * All Rights Reserved.
57 * Contributor(s): Joerg Budischewski
60 ************************************************************************/
62 #include <rtl/ustrbuf.hxx>
63 #include <cppuhelper/typeprovider.hxx>
65 #include "pq_tools.hxx"
66 #include "pq_xbase.hxx"
68 using osl::MutexGuard
;
70 using com::sun::star::uno::Any
;
71 using com::sun::star::uno::Sequence
;
72 using com::sun::star::uno::Reference
;
73 using com::sun::star::uno::RuntimeException
;
75 using com::sun::star::beans::Property
;
76 using com::sun::star::beans::XPropertySetInfo
;
77 using com::sun::star::beans::XMultiPropertySet
;
78 using com::sun::star::beans::XFastPropertySet
;
79 using com::sun::star::beans::XPropertySet
;
81 namespace pq_sdbc_driver
84 ReflectionBase::ReflectionBase(
85 const ::rtl::OUString
&implName
,
86 const ::com::sun::star::uno::Sequence
< rtl::OUString
> &supportedServices
,
87 const ::rtl::Reference
< RefCountedMutex
> refMutex
,
88 const ::com::sun::star::uno::Reference
< com::sun::star::sdbc::XConnection
> &conn
,
89 ConnectionSettings
*pSettings
,
90 cppu::IPropertyArrayHelper
& props
/* must survive this object !*/ )
91 : OComponentHelper( refMutex
->mutex
),
92 OPropertySetHelper( OComponentHelper::rBHelper
),
93 m_implName( implName
),
94 m_supportedServices( supportedServices
),
95 m_refMutex( refMutex
),
97 m_pSettings( pSettings
),
99 m_values( props
.getProperties().getLength() )
102 cppu::IPropertyArrayHelper
& ReflectionBase::getInfoHelper()
107 sal_Bool
ReflectionBase::convertFastPropertyValue(
108 ::com::sun::star::uno::Any
& rConvertedValue
,
109 ::com::sun::star::uno::Any
& rOldValue
,
111 const ::com::sun::star::uno::Any
& rValue
)
112 throw (::com::sun::star::lang::IllegalArgumentException
)
115 rOldValue
= m_values
[nHandle
];
116 rConvertedValue
= rValue
; // TODO !!! implement correct conversion !
117 m_values
[nHandle
] = rValue
;
121 void ReflectionBase::setPropertyValue_NoBroadcast_public(
122 const rtl::OUString
& name
, const com::sun::star::uno::Any
& value
)
124 sal_Int32 nHandle
= m_propsDesc
.getHandleByName( name
);
127 rtl::OUStringBuffer
buf(128);
128 buf
.appendAscii( "Unkown property '" );
130 buf
.appendAscii( "' in " );
131 buf
.append( m_implName
);
132 throw com::sun::star::uno::RuntimeException( buf
.makeStringAndClear() , *this );
134 setFastPropertyValue_NoBroadcast( nHandle
, value
);
137 void ReflectionBase::setFastPropertyValue_NoBroadcast(
139 const ::com::sun::star::uno::Any
& rValue
)
140 throw (::com::sun::star::uno::Exception
)
144 // printf( "setting value (handle %d):%s\n" ,
145 // nHandle, rtl::OUStringToOString(s, RTL_TEXTENCODING_ASCII_US).getStr() );
146 m_values
[nHandle
] = rValue
;
149 void ReflectionBase::getFastPropertyValue(
150 ::com::sun::star::uno::Any
& rValue
,
151 sal_Int32 nHandle
) const
153 rValue
= m_values
[nHandle
];
156 // printf( "getting value (handle %d):%s\n" ,
157 // nHandle, rtl::OUStringToOString(s, RTL_TEXTENCODING_ASCII_US).getStr() );
161 Reference
< ::com::sun::star::beans::XPropertySetInfo
> ReflectionBase::getPropertySetInfo()
162 throw(com::sun::star::uno::RuntimeException
)
164 return OPropertySetHelper::createPropertySetInfo( m_propsDesc
);
167 rtl::OUString
ReflectionBase::getImplementationName()
168 throw(::com::sun::star::uno::RuntimeException
)
173 sal_Bool
ReflectionBase::supportsService(const rtl::OUString
& ServiceName
)
174 throw(::com::sun::star::uno::RuntimeException
)
176 for( int i
= 0 ; i
< m_supportedServices
.getLength() ; i
++ )
177 if( m_supportedServices
[i
] == ServiceName
)
182 Sequence
< rtl::OUString
> ReflectionBase::getSupportedServiceNames(void)
183 throw(::com::sun::star::uno::RuntimeException
)
185 return m_supportedServices
;
189 Sequence
< com::sun::star::uno::Type
> ReflectionBase::getTypes()
190 throw( com::sun::star::uno::RuntimeException
)
192 osl::MutexGuard
guard( m_refMutex
->mutex
);
193 static cppu::OTypeCollection
collection(
194 getCppuType( (Reference
< XPropertySet
>*) 0 ),
195 getCppuType( (Reference
< XFastPropertySet
> *) 0 ),
196 getCppuType( (Reference
< XMultiPropertySet
> *) 0 ),
197 getCppuType( (Reference
< com::sun::star::lang::XServiceInfo
> *) 0 ),
198 getCppuType( (Reference
< com::sun::star::sdbcx::XDataDescriptorFactory
> *) 0 ),
199 getCppuType( (Reference
< com::sun::star::container::XNamed
> *) 0 ),
200 OComponentHelper::getTypes());
201 return collection
.getTypes();
205 com::sun::star::uno::Any
ReflectionBase::queryInterface(
206 const com::sun::star::uno::Type
& reqType
)
207 throw (com::sun::star::uno::RuntimeException
)
210 ret
= OComponentHelper::queryInterface( reqType
);
211 if( ! ret
.hasValue() )
212 ret
= ::cppu::queryInterface(
214 static_cast< com::sun::star::beans::XPropertySet
* > ( this ),
215 static_cast< com::sun::star::beans::XMultiPropertySet
* > ( this ),
216 static_cast< com::sun::star::lang::XServiceInfo
* > ( this ),
217 static_cast< com::sun::star::beans::XFastPropertySet
* > ( this ) ,
218 static_cast< com::sun::star::sdbcx::XDataDescriptorFactory
* > ( this ),
219 static_cast< com::sun::star::container::XNamed
* > ( this ) );
224 Sequence
< sal_Int8
> ReflectionBase::getImplementationId() throw( RuntimeException
)
226 static cppu::OImplementationId
*pId
;
229 MutexGuard
guard( osl::Mutex::getGlobalMutex() );
232 static cppu::OImplementationId
id(sal_False
);
236 return pId
->getImplementationId();
239 void ReflectionBase::copyValuesFrom( const Reference
< XPropertySet
> & set
)
241 Reference
< XPropertySetInfo
> info
= set
->getPropertySetInfo();
244 Reference
< XPropertySetInfo
> myPropInfo
= getPropertySetInfo();
246 Sequence
< Property
> props
= info
->getProperties();
247 for( int i
= 0 ; i
< props
.getLength() ; i
++ )
249 if( myPropInfo
->hasPropertyByName( props
[i
].Name
) )
250 setPropertyValue_NoBroadcast_public(
251 props
[i
].Name
, set
->getPropertyValue( props
[i
].Name
) );
256 ::rtl::OUString
ReflectionBase::getName( ) throw (::com::sun::star::uno::RuntimeException
)
258 Statics
& st
= getStatics();
259 if( getInfoHelper().hasPropertyByName( st
.SCHEMA_NAME
) )
260 return concatQualified(
261 extractStringProperty( this, getStatics().SCHEMA_NAME
),
262 extractStringProperty( this, getStatics().NAME
) );
264 return extractStringProperty( this, getStatics().NAME
);
268 void ReflectionBase::setName( const ::rtl::OUString
& aName
)
269 throw (::com::sun::star::uno::RuntimeException
)
271 throw RuntimeException(
273 RTL_CONSTASCII_USTRINGPARAM( "pq_sdbc::ReflectionBase::setName not implemented" ) ),
275 //setPropertyValue( getStatics().NAME , makeAny( aName ) );