1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
29*cdf0e10cSrcweir #include "precompiled_svx.hxx"
30*cdf0e10cSrcweir #include <svx/dataaccessdescriptor.hxx>
31*cdf0e10cSrcweir #include <comphelper/stl_types.hxx>
32*cdf0e10cSrcweir #include <comphelper/propertysetinfo.hxx>
33*cdf0e10cSrcweir #include <comphelper/genericpropertyset.hxx>
34*cdf0e10cSrcweir #include <osl/diagnose.h>
35*cdf0e10cSrcweir #include <com/sun/star/sdbc/XConnection.hpp>
36*cdf0e10cSrcweir #include <com/sun/star/ucb/XContent.hpp>
37*cdf0e10cSrcweir #include <com/sun/star/beans/PropertyAttribute.hpp>
38*cdf0e10cSrcweir #include <tools/urlobj.hxx>
39*cdf0e10cSrcweir 
40*cdf0e10cSrcweir //........................................................................
41*cdf0e10cSrcweir namespace svx
42*cdf0e10cSrcweir {
43*cdf0e10cSrcweir //........................................................................
44*cdf0e10cSrcweir 
45*cdf0e10cSrcweir 	using namespace ::com::sun::star::uno;
46*cdf0e10cSrcweir 	using namespace ::com::sun::star::sdbc;
47*cdf0e10cSrcweir 	using namespace ::com::sun::star::beans;
48*cdf0e10cSrcweir 	using namespace ::com::sun::star::ucb;
49*cdf0e10cSrcweir 	using namespace ::comphelper;
50*cdf0e10cSrcweir 
51*cdf0e10cSrcweir #define CONST_CHAR( propname ) propname, sizeof(propname) - 1
52*cdf0e10cSrcweir 
53*cdf0e10cSrcweir #ifndef SVX_LIGHT
54*cdf0e10cSrcweir 	//====================================================================
55*cdf0e10cSrcweir 	//= ODADescriptorImpl
56*cdf0e10cSrcweir 	//====================================================================
57*cdf0e10cSrcweir 	class ODADescriptorImpl
58*cdf0e10cSrcweir 	{
59*cdf0e10cSrcweir 	protected:
60*cdf0e10cSrcweir 		sal_Bool					m_bSetOutOfDate			: 1;
61*cdf0e10cSrcweir 		sal_Bool					m_bSequenceOutOfDate	: 1;
62*cdf0e10cSrcweir 
63*cdf0e10cSrcweir 	public:
64*cdf0e10cSrcweir         typedef ::std::map< DataAccessDescriptorProperty, Any >     DescriptorValues;
65*cdf0e10cSrcweir 		DescriptorValues			m_aValues;
66*cdf0e10cSrcweir 		Sequence< PropertyValue >	m_aAsSequence;
67*cdf0e10cSrcweir 		Reference< XPropertySet >	m_xAsSet;
68*cdf0e10cSrcweir 
69*cdf0e10cSrcweir         typedef ::std::map< ::rtl::OUString, PropertyMapEntry* >    MapString2PropertyEntry;
70*cdf0e10cSrcweir 
71*cdf0e10cSrcweir 	public:
72*cdf0e10cSrcweir 		ODADescriptorImpl();
73*cdf0e10cSrcweir 		ODADescriptorImpl(const ODADescriptorImpl& _rSource);
74*cdf0e10cSrcweir 
75*cdf0e10cSrcweir 		void invalidateExternRepresentations();
76*cdf0e10cSrcweir 
77*cdf0e10cSrcweir 		void updateSequence();
78*cdf0e10cSrcweir 		void updateSet();
79*cdf0e10cSrcweir 
80*cdf0e10cSrcweir 		/** builds the descriptor from a property value sequence
81*cdf0e10cSrcweir 			@return <TRUE/>
82*cdf0e10cSrcweir 				if and only if the sequence contained valid properties only
83*cdf0e10cSrcweir 		*/
84*cdf0e10cSrcweir 		sal_Bool buildFrom( const Sequence< PropertyValue >& _rValues );
85*cdf0e10cSrcweir 
86*cdf0e10cSrcweir 		/** builds the descriptor from a property set
87*cdf0e10cSrcweir 			@return <TRUE/>
88*cdf0e10cSrcweir 				if and only if the set contained valid properties only
89*cdf0e10cSrcweir 		*/
90*cdf0e10cSrcweir 		sal_Bool buildFrom( const Reference< XPropertySet >& _rValues );
91*cdf0e10cSrcweir 
92*cdf0e10cSrcweir 	protected:
93*cdf0e10cSrcweir         static PropertyValue		            buildPropertyValue( const DescriptorValues::const_iterator& _rPos );
94*cdf0e10cSrcweir 		static const MapString2PropertyEntry&   getPropertyMap( );
95*cdf0e10cSrcweir         static PropertyMapEntry*                getPropertyMapEntry( const DescriptorValues::const_iterator& _rPos );
96*cdf0e10cSrcweir 	};
97*cdf0e10cSrcweir 
98*cdf0e10cSrcweir 	//--------------------------------------------------------------------
99*cdf0e10cSrcweir 	ODADescriptorImpl::ODADescriptorImpl()
100*cdf0e10cSrcweir 		:m_bSetOutOfDate(sal_True)
101*cdf0e10cSrcweir 		,m_bSequenceOutOfDate(sal_True)
102*cdf0e10cSrcweir 	{
103*cdf0e10cSrcweir 	}
104*cdf0e10cSrcweir 
105*cdf0e10cSrcweir 	//--------------------------------------------------------------------
106*cdf0e10cSrcweir 	ODADescriptorImpl::ODADescriptorImpl(const ODADescriptorImpl& _rSource)
107*cdf0e10cSrcweir         :m_bSetOutOfDate( _rSource.m_bSetOutOfDate )
108*cdf0e10cSrcweir         ,m_bSequenceOutOfDate( _rSource.m_bSequenceOutOfDate )
109*cdf0e10cSrcweir 		,m_aValues( _rSource.m_aValues )
110*cdf0e10cSrcweir 	{
111*cdf0e10cSrcweir 		if (!m_bSetOutOfDate)
112*cdf0e10cSrcweir 			m_xAsSet = _rSource.m_xAsSet;
113*cdf0e10cSrcweir 		if (!m_bSequenceOutOfDate)
114*cdf0e10cSrcweir 			m_aAsSequence = _rSource.m_aAsSequence;
115*cdf0e10cSrcweir 	}
116*cdf0e10cSrcweir 
117*cdf0e10cSrcweir 	//--------------------------------------------------------------------
118*cdf0e10cSrcweir 	sal_Bool ODADescriptorImpl::buildFrom( const Sequence< PropertyValue >& _rValues )
119*cdf0e10cSrcweir 	{
120*cdf0e10cSrcweir         const MapString2PropertyEntry& rProperties = getPropertyMap();
121*cdf0e10cSrcweir 
122*cdf0e10cSrcweir 		sal_Bool bValidPropsOnly = sal_True;
123*cdf0e10cSrcweir 
124*cdf0e10cSrcweir 		// loop through the sequence, and fill our m_aValues
125*cdf0e10cSrcweir 		const PropertyValue* pValues = _rValues.getConstArray();
126*cdf0e10cSrcweir 		const PropertyValue* pValuesEnd = pValues + _rValues.getLength();
127*cdf0e10cSrcweir 		for (;pValues != pValuesEnd; ++pValues)
128*cdf0e10cSrcweir 		{
129*cdf0e10cSrcweir             MapString2PropertyEntry::const_iterator aPropPos = rProperties.find( pValues->Name );
130*cdf0e10cSrcweir             if ( aPropPos != rProperties.end() )
131*cdf0e10cSrcweir 			{
132*cdf0e10cSrcweir 				DataAccessDescriptorProperty eProperty = (DataAccessDescriptorProperty)aPropPos->second->mnHandle;
133*cdf0e10cSrcweir 				m_aValues[eProperty] = pValues->Value;
134*cdf0e10cSrcweir 			}
135*cdf0e10cSrcweir 			else
136*cdf0e10cSrcweir 				// unknown property
137*cdf0e10cSrcweir 				bValidPropsOnly = sal_False;
138*cdf0e10cSrcweir 		}
139*cdf0e10cSrcweir 
140*cdf0e10cSrcweir 		if (bValidPropsOnly)
141*cdf0e10cSrcweir 		{
142*cdf0e10cSrcweir 			m_aAsSequence = _rValues;
143*cdf0e10cSrcweir 			m_bSequenceOutOfDate = sal_False;
144*cdf0e10cSrcweir 		}
145*cdf0e10cSrcweir 		else
146*cdf0e10cSrcweir 			m_bSequenceOutOfDate = sal_True;
147*cdf0e10cSrcweir 
148*cdf0e10cSrcweir 		return bValidPropsOnly;
149*cdf0e10cSrcweir 	}
150*cdf0e10cSrcweir 
151*cdf0e10cSrcweir 	//--------------------------------------------------------------------
152*cdf0e10cSrcweir 	sal_Bool ODADescriptorImpl::buildFrom( const Reference< XPropertySet >& _rxValues )
153*cdf0e10cSrcweir 	{
154*cdf0e10cSrcweir 		Reference< XPropertySetInfo > xPropInfo;
155*cdf0e10cSrcweir 		if (_rxValues.is())
156*cdf0e10cSrcweir 			xPropInfo = _rxValues->getPropertySetInfo();
157*cdf0e10cSrcweir 		if (!xPropInfo.is())
158*cdf0e10cSrcweir 		{
159*cdf0e10cSrcweir 			OSL_ENSURE(sal_False, "ODADescriptorImpl::buildFrom: invalid property set!");
160*cdf0e10cSrcweir 			return sal_False;
161*cdf0e10cSrcweir 		}
162*cdf0e10cSrcweir 
163*cdf0e10cSrcweir 		// build a PropertyValue sequence with the current values
164*cdf0e10cSrcweir 		Sequence< Property > aProperties = xPropInfo->getProperties();
165*cdf0e10cSrcweir 		const Property* pProperty = aProperties.getConstArray();
166*cdf0e10cSrcweir 		const Property* pPropertyEnd = pProperty + aProperties.getLength();
167*cdf0e10cSrcweir 
168*cdf0e10cSrcweir 		Sequence< PropertyValue > aValues(aProperties.getLength());
169*cdf0e10cSrcweir 		PropertyValue* pValues = aValues.getArray();
170*cdf0e10cSrcweir 
171*cdf0e10cSrcweir 		for (;pProperty != pPropertyEnd; ++pProperty, ++pValues)
172*cdf0e10cSrcweir 		{
173*cdf0e10cSrcweir 			pValues->Name = pProperty->Name;
174*cdf0e10cSrcweir 			pValues->Value = _rxValues->getPropertyValue(pProperty->Name);
175*cdf0e10cSrcweir 		}
176*cdf0e10cSrcweir 
177*cdf0e10cSrcweir 		sal_Bool bValidPropsOnly = buildFrom(aValues);
178*cdf0e10cSrcweir 		if (bValidPropsOnly)
179*cdf0e10cSrcweir 		{
180*cdf0e10cSrcweir 			m_xAsSet = _rxValues;
181*cdf0e10cSrcweir 			m_bSetOutOfDate = sal_False;
182*cdf0e10cSrcweir 		}
183*cdf0e10cSrcweir 		else
184*cdf0e10cSrcweir 			m_bSetOutOfDate = sal_True;
185*cdf0e10cSrcweir 
186*cdf0e10cSrcweir 		return bValidPropsOnly;
187*cdf0e10cSrcweir 	}
188*cdf0e10cSrcweir 
189*cdf0e10cSrcweir 	//--------------------------------------------------------------------
190*cdf0e10cSrcweir 	void ODADescriptorImpl::invalidateExternRepresentations()
191*cdf0e10cSrcweir 	{
192*cdf0e10cSrcweir 		m_bSetOutOfDate = sal_True;
193*cdf0e10cSrcweir 		m_bSequenceOutOfDate = sal_True;
194*cdf0e10cSrcweir 	}
195*cdf0e10cSrcweir 
196*cdf0e10cSrcweir 	//--------------------------------------------------------------------
197*cdf0e10cSrcweir 	const ODADescriptorImpl::MapString2PropertyEntry& ODADescriptorImpl::getPropertyMap( )
198*cdf0e10cSrcweir 	{
199*cdf0e10cSrcweir 		// the properties we know
200*cdf0e10cSrcweir         static MapString2PropertyEntry s_aProperties;
201*cdf0e10cSrcweir         if ( s_aProperties.empty() )
202*cdf0e10cSrcweir         {
203*cdf0e10cSrcweir 		    static PropertyMapEntry s_aDesriptorProperties[] =
204*cdf0e10cSrcweir 		    {
205*cdf0e10cSrcweir 			    { CONST_CHAR("ActiveConnection"),	daConnection,			&::getCppuType( static_cast< Reference< XConnection >* >(NULL) ),	PropertyAttribute::TRANSIENT, 0 },
206*cdf0e10cSrcweir 			    { CONST_CHAR("BookmarkSelection"),	daBookmarkSelection,	&::getBooleanCppuType( ),											PropertyAttribute::TRANSIENT, 0 },
207*cdf0e10cSrcweir 			    { CONST_CHAR("Column"),				daColumnObject,			&::getCppuType( static_cast< Reference< XPropertySet >* >(NULL) ),	PropertyAttribute::TRANSIENT, 0 },
208*cdf0e10cSrcweir 			    { CONST_CHAR("ColumnName"),			daColumnName,			&::getCppuType( static_cast< ::rtl::OUString* >(NULL) ),			PropertyAttribute::TRANSIENT, 0 },
209*cdf0e10cSrcweir 			    { CONST_CHAR("Command"),			daCommand,				&::getCppuType( static_cast< ::rtl::OUString* >(NULL) ),			PropertyAttribute::TRANSIENT, 0 },
210*cdf0e10cSrcweir 			    { CONST_CHAR("CommandType"),		daCommandType,			&::getCppuType( static_cast< sal_Int32* >(NULL) ),					PropertyAttribute::TRANSIENT, 0 },
211*cdf0e10cSrcweir 			    { CONST_CHAR("Component"),			daComponent,			&::getCppuType( static_cast< Reference< XContent >* >(NULL) ),		PropertyAttribute::TRANSIENT, 0 },
212*cdf0e10cSrcweir 			    { CONST_CHAR("ConnectionResource"),	daConnectionResource,	&::getCppuType( static_cast< ::rtl::OUString* >(NULL) ),			PropertyAttribute::TRANSIENT, 0 },
213*cdf0e10cSrcweir 			    { CONST_CHAR("Cursor"),				daCursor,				&::getCppuType( static_cast< Reference< XResultSet>* >(NULL) ),		PropertyAttribute::TRANSIENT, 0 },
214*cdf0e10cSrcweir 			    { CONST_CHAR("DataSourceName"),		daDataSource,			&::getCppuType( static_cast< ::rtl::OUString* >(NULL) ),			PropertyAttribute::TRANSIENT, 0 },
215*cdf0e10cSrcweir 			    { CONST_CHAR("DatabaseLocation"),	daDatabaseLocation,		&::getCppuType( static_cast< ::rtl::OUString* >(NULL) ),			PropertyAttribute::TRANSIENT, 0 },
216*cdf0e10cSrcweir 			    { CONST_CHAR("EscapeProcessing"),	daEscapeProcessing,		&::getBooleanCppuType( ),											PropertyAttribute::TRANSIENT, 0 },
217*cdf0e10cSrcweir 			    { CONST_CHAR("Filter"),				daFilter,				&::getCppuType( static_cast< ::rtl::OUString* >(NULL) ),			PropertyAttribute::TRANSIENT, 0 },
218*cdf0e10cSrcweir 			    { CONST_CHAR("Selection"),			daSelection,			&::getCppuType( static_cast< Sequence< Any >* >(NULL) ),			PropertyAttribute::TRANSIENT, 0 },
219*cdf0e10cSrcweir 			    { NULL, 0, 0, NULL, 0, 0 }
220*cdf0e10cSrcweir 		    };
221*cdf0e10cSrcweir 
222*cdf0e10cSrcweir             PropertyMapEntry* pEntry = s_aDesriptorProperties;
223*cdf0e10cSrcweir             while ( pEntry->mpName )
224*cdf0e10cSrcweir             {
225*cdf0e10cSrcweir                 s_aProperties[ ::rtl::OUString::createFromAscii( pEntry->mpName ) ] = pEntry;
226*cdf0e10cSrcweir                 ++pEntry;
227*cdf0e10cSrcweir             }
228*cdf0e10cSrcweir         }
229*cdf0e10cSrcweir 
230*cdf0e10cSrcweir 		return s_aProperties;
231*cdf0e10cSrcweir 	}
232*cdf0e10cSrcweir 
233*cdf0e10cSrcweir 	//--------------------------------------------------------------------
234*cdf0e10cSrcweir 	PropertyMapEntry* ODADescriptorImpl::getPropertyMapEntry( const DescriptorValues::const_iterator& _rPos )
235*cdf0e10cSrcweir 	{
236*cdf0e10cSrcweir         const MapString2PropertyEntry& rProperties = getPropertyMap();
237*cdf0e10cSrcweir 
238*cdf0e10cSrcweir 		sal_Int32 nNeededHandle = (sal_Int32)(_rPos->first);
239*cdf0e10cSrcweir 
240*cdf0e10cSrcweir         for ( MapString2PropertyEntry::const_iterator loop = rProperties.begin();
241*cdf0e10cSrcweir               loop != rProperties.end();
242*cdf0e10cSrcweir               ++loop
243*cdf0e10cSrcweir             )
244*cdf0e10cSrcweir         {
245*cdf0e10cSrcweir 			if ( nNeededHandle == loop->second->mnHandle )
246*cdf0e10cSrcweir 				return loop->second;
247*cdf0e10cSrcweir 		}
248*cdf0e10cSrcweir         throw RuntimeException();
249*cdf0e10cSrcweir 	}
250*cdf0e10cSrcweir 
251*cdf0e10cSrcweir 	//--------------------------------------------------------------------
252*cdf0e10cSrcweir 	PropertyValue ODADescriptorImpl::buildPropertyValue( const DescriptorValues::const_iterator& _rPos )
253*cdf0e10cSrcweir 	{
254*cdf0e10cSrcweir 		// the map entry
255*cdf0e10cSrcweir         PropertyMapEntry* pProperty = getPropertyMapEntry( _rPos );
256*cdf0e10cSrcweir 
257*cdf0e10cSrcweir 		// build the property value
258*cdf0e10cSrcweir 		PropertyValue aReturn;
259*cdf0e10cSrcweir         aReturn.Name	= ::rtl::OUString( pProperty->mpName, pProperty->mnNameLen, RTL_TEXTENCODING_ASCII_US );
260*cdf0e10cSrcweir 		aReturn.Handle	= pProperty->mnHandle;
261*cdf0e10cSrcweir 		aReturn.Value	= _rPos->second;
262*cdf0e10cSrcweir 		aReturn.State	= PropertyState_DIRECT_VALUE;
263*cdf0e10cSrcweir 
264*cdf0e10cSrcweir 		// outta here
265*cdf0e10cSrcweir 		return aReturn;
266*cdf0e10cSrcweir 	}
267*cdf0e10cSrcweir 
268*cdf0e10cSrcweir 	//--------------------------------------------------------------------
269*cdf0e10cSrcweir 	void ODADescriptorImpl::updateSequence()
270*cdf0e10cSrcweir 	{
271*cdf0e10cSrcweir 		if (!m_bSequenceOutOfDate)
272*cdf0e10cSrcweir 			return;
273*cdf0e10cSrcweir 
274*cdf0e10cSrcweir 		m_aAsSequence.realloc(m_aValues.size());
275*cdf0e10cSrcweir 		PropertyValue* pValue = m_aAsSequence.getArray();
276*cdf0e10cSrcweir 
277*cdf0e10cSrcweir 		// loop through all our values
278*cdf0e10cSrcweir 		for	(	DescriptorValues::const_iterator aLoop = m_aValues.begin();
279*cdf0e10cSrcweir 				aLoop != m_aValues.end();
280*cdf0e10cSrcweir 				++aLoop, ++pValue
281*cdf0e10cSrcweir 			)
282*cdf0e10cSrcweir 		{
283*cdf0e10cSrcweir 			*pValue = buildPropertyValue(aLoop);
284*cdf0e10cSrcweir 		}
285*cdf0e10cSrcweir 
286*cdf0e10cSrcweir 		// don't need to rebuild next time
287*cdf0e10cSrcweir 		m_bSequenceOutOfDate = sal_False;
288*cdf0e10cSrcweir 	}
289*cdf0e10cSrcweir 
290*cdf0e10cSrcweir 	//--------------------------------------------------------------------
291*cdf0e10cSrcweir 	void ODADescriptorImpl::updateSet()
292*cdf0e10cSrcweir 	{
293*cdf0e10cSrcweir 		if (!m_bSetOutOfDate)
294*cdf0e10cSrcweir 			return;
295*cdf0e10cSrcweir 
296*cdf0e10cSrcweir 		// will be the current values
297*cdf0e10cSrcweir 		Sequence< PropertyValue > aValuesToSet(m_aValues.size());
298*cdf0e10cSrcweir 		PropertyValue* pValuesToSet = aValuesToSet.getArray();
299*cdf0e10cSrcweir 
300*cdf0e10cSrcweir 		// build a new property set info
301*cdf0e10cSrcweir 		PropertySetInfo* pPropSetInfo = new PropertySetInfo;
302*cdf0e10cSrcweir 
303*cdf0e10cSrcweir 		// loop through all our values
304*cdf0e10cSrcweir 		for	(	DescriptorValues::const_iterator aLoop = m_aValues.begin();
305*cdf0e10cSrcweir 				aLoop != m_aValues.end();
306*cdf0e10cSrcweir 				++aLoop, ++pValuesToSet
307*cdf0e10cSrcweir 			)
308*cdf0e10cSrcweir 		{
309*cdf0e10cSrcweir 			PropertyMapEntry* pMapEntry = getPropertyMapEntry( aLoop );
310*cdf0e10cSrcweir 			pPropSetInfo->add( pMapEntry, 1 );
311*cdf0e10cSrcweir 
312*cdf0e10cSrcweir 			*pValuesToSet = buildPropertyValue(aLoop);
313*cdf0e10cSrcweir 		}
314*cdf0e10cSrcweir 
315*cdf0e10cSrcweir 		// create the generic set
316*cdf0e10cSrcweir 		m_xAsSet = GenericPropertySet_CreateInstance( pPropSetInfo );
317*cdf0e10cSrcweir 
318*cdf0e10cSrcweir 		// no we have the set, still need to set the current values
319*cdf0e10cSrcweir 		const PropertyValue* pSetValues = aValuesToSet.getConstArray();
320*cdf0e10cSrcweir 		const PropertyValue* pSetValuesEnd = pSetValues + aValuesToSet.getLength();
321*cdf0e10cSrcweir 		for	(; pSetValues != pSetValuesEnd; ++pSetValues)
322*cdf0e10cSrcweir 			m_xAsSet->setPropertyValue(pSetValues->Name, pSetValues->Value);
323*cdf0e10cSrcweir 
324*cdf0e10cSrcweir 		// don't need to rebuild next time
325*cdf0e10cSrcweir 		m_bSetOutOfDate = sal_True;
326*cdf0e10cSrcweir 	}
327*cdf0e10cSrcweir #endif
328*cdf0e10cSrcweir 
329*cdf0e10cSrcweir 	//====================================================================
330*cdf0e10cSrcweir 	//= ODataAccessDescriptor
331*cdf0e10cSrcweir 	//====================================================================
332*cdf0e10cSrcweir 	//--------------------------------------------------------------------
333*cdf0e10cSrcweir 	ODataAccessDescriptor::ODataAccessDescriptor()
334*cdf0e10cSrcweir #ifndef SVX_LIGHT
335*cdf0e10cSrcweir 		:m_pImpl(new ODADescriptorImpl)
336*cdf0e10cSrcweir #else
337*cdf0e10cSrcweir 		:m_pImpl(NULL)
338*cdf0e10cSrcweir #endif
339*cdf0e10cSrcweir 	{
340*cdf0e10cSrcweir 	}
341*cdf0e10cSrcweir 
342*cdf0e10cSrcweir 	//--------------------------------------------------------------------
343*cdf0e10cSrcweir 	ODataAccessDescriptor::ODataAccessDescriptor( const ODataAccessDescriptor& _rSource )
344*cdf0e10cSrcweir #ifndef SVX_LIGHT
345*cdf0e10cSrcweir 		:m_pImpl(new ODADescriptorImpl(*_rSource.m_pImpl))
346*cdf0e10cSrcweir #else
347*cdf0e10cSrcweir 		:m_pImpl(NULL)
348*cdf0e10cSrcweir #endif
349*cdf0e10cSrcweir 	{
350*cdf0e10cSrcweir 	}
351*cdf0e10cSrcweir 
352*cdf0e10cSrcweir 	//--------------------------------------------------------------------
353*cdf0e10cSrcweir 	const ODataAccessDescriptor& ODataAccessDescriptor::operator=(const ODataAccessDescriptor& _rSource)
354*cdf0e10cSrcweir 	{
355*cdf0e10cSrcweir #ifndef SVX_LIGHT
356*cdf0e10cSrcweir 		delete m_pImpl;
357*cdf0e10cSrcweir 		m_pImpl = new ODADescriptorImpl(*_rSource.m_pImpl);
358*cdf0e10cSrcweir #else
359*cdf0e10cSrcweir 		OSL_ENSURE(sal_False, "ODataAccessDescriptor::operator=: not available in the SVX_LIGHT version!");
360*cdf0e10cSrcweir #endif
361*cdf0e10cSrcweir 		return *this;
362*cdf0e10cSrcweir 	}
363*cdf0e10cSrcweir 
364*cdf0e10cSrcweir 	//--------------------------------------------------------------------
365*cdf0e10cSrcweir 	ODataAccessDescriptor::ODataAccessDescriptor( const Reference< XPropertySet >& _rValues )
366*cdf0e10cSrcweir #ifndef SVX_LIGHT
367*cdf0e10cSrcweir 		:m_pImpl(new ODADescriptorImpl)
368*cdf0e10cSrcweir #else
369*cdf0e10cSrcweir 		:m_pImpl(NULL)
370*cdf0e10cSrcweir #endif
371*cdf0e10cSrcweir 	{
372*cdf0e10cSrcweir #ifndef SVX_LIGHT
373*cdf0e10cSrcweir 		m_pImpl->buildFrom(_rValues);
374*cdf0e10cSrcweir #else
375*cdf0e10cSrcweir 		OSL_ENSURE(sal_False, "ODataAccessDescriptor::ODataAccessDescriptor: not available in the SVX_LIGHT version!");
376*cdf0e10cSrcweir #endif
377*cdf0e10cSrcweir 	}
378*cdf0e10cSrcweir 
379*cdf0e10cSrcweir 	//--------------------------------------------------------------------
380*cdf0e10cSrcweir 	ODataAccessDescriptor::ODataAccessDescriptor( const Any& _rValues )
381*cdf0e10cSrcweir #ifndef SVX_LIGHT
382*cdf0e10cSrcweir 		:m_pImpl(new ODADescriptorImpl)
383*cdf0e10cSrcweir #else
384*cdf0e10cSrcweir 		:m_pImpl(NULL)
385*cdf0e10cSrcweir #endif
386*cdf0e10cSrcweir 	{
387*cdf0e10cSrcweir #ifndef SVX_LIGHT
388*cdf0e10cSrcweir 		// check if we know the format in the Any
389*cdf0e10cSrcweir 		Sequence< PropertyValue > aValues;
390*cdf0e10cSrcweir 		Reference< XPropertySet > xValues;
391*cdf0e10cSrcweir 		if ( _rValues >>= aValues )
392*cdf0e10cSrcweir 			m_pImpl->buildFrom( aValues );
393*cdf0e10cSrcweir 		else if ( _rValues >>= xValues )
394*cdf0e10cSrcweir 			m_pImpl->buildFrom( xValues );
395*cdf0e10cSrcweir #else
396*cdf0e10cSrcweir 		OSL_ENSURE(sal_False, "ODataAccessDescriptor::ODataAccessDescriptor: not available in the SVX_LIGHT version!");
397*cdf0e10cSrcweir #endif
398*cdf0e10cSrcweir 	}
399*cdf0e10cSrcweir 
400*cdf0e10cSrcweir 	//--------------------------------------------------------------------
401*cdf0e10cSrcweir 	ODataAccessDescriptor::ODataAccessDescriptor( const Sequence< PropertyValue >& _rValues )
402*cdf0e10cSrcweir #ifndef SVX_LIGHT
403*cdf0e10cSrcweir 		:m_pImpl(new ODADescriptorImpl)
404*cdf0e10cSrcweir #else
405*cdf0e10cSrcweir 		:m_pImpl(NULL)
406*cdf0e10cSrcweir #endif
407*cdf0e10cSrcweir 	{
408*cdf0e10cSrcweir #ifndef SVX_LIGHT
409*cdf0e10cSrcweir 		m_pImpl->buildFrom(_rValues);
410*cdf0e10cSrcweir #else
411*cdf0e10cSrcweir 		OSL_ENSURE(sal_False, "ODataAccessDescriptor::ODataAccessDescriptor: not available in the SVX_LIGHT version!");
412*cdf0e10cSrcweir #endif
413*cdf0e10cSrcweir 	}
414*cdf0e10cSrcweir 
415*cdf0e10cSrcweir 	//--------------------------------------------------------------------
416*cdf0e10cSrcweir 	ODataAccessDescriptor::~ODataAccessDescriptor()
417*cdf0e10cSrcweir 	{
418*cdf0e10cSrcweir 		delete m_pImpl;
419*cdf0e10cSrcweir 	}
420*cdf0e10cSrcweir 
421*cdf0e10cSrcweir 	//--------------------------------------------------------------------
422*cdf0e10cSrcweir 	void ODataAccessDescriptor::clear()
423*cdf0e10cSrcweir 	{
424*cdf0e10cSrcweir #ifndef SVX_LIGHT
425*cdf0e10cSrcweir 		m_pImpl->m_aValues.clear();
426*cdf0e10cSrcweir #endif
427*cdf0e10cSrcweir 	}
428*cdf0e10cSrcweir 
429*cdf0e10cSrcweir 	//--------------------------------------------------------------------
430*cdf0e10cSrcweir 	void ODataAccessDescriptor::erase(DataAccessDescriptorProperty _eWhich)
431*cdf0e10cSrcweir 	{
432*cdf0e10cSrcweir #ifndef SVX_LIGHT
433*cdf0e10cSrcweir 		OSL_ENSURE(has(_eWhich), "ODataAccessDescriptor::erase: invalid call!");
434*cdf0e10cSrcweir 		if (has(_eWhich))
435*cdf0e10cSrcweir 			m_pImpl->m_aValues.erase(_eWhich);
436*cdf0e10cSrcweir #endif
437*cdf0e10cSrcweir 	}
438*cdf0e10cSrcweir 
439*cdf0e10cSrcweir 	//--------------------------------------------------------------------
440*cdf0e10cSrcweir 	sal_Bool ODataAccessDescriptor::has(DataAccessDescriptorProperty _eWhich) const
441*cdf0e10cSrcweir 	{
442*cdf0e10cSrcweir #ifndef SVX_LIGHT
443*cdf0e10cSrcweir 		return m_pImpl->m_aValues.find(_eWhich) != m_pImpl->m_aValues.end();
444*cdf0e10cSrcweir #else
445*cdf0e10cSrcweir 		return sal_False;
446*cdf0e10cSrcweir #endif
447*cdf0e10cSrcweir 	}
448*cdf0e10cSrcweir 
449*cdf0e10cSrcweir 	//--------------------------------------------------------------------
450*cdf0e10cSrcweir 	const Any& ODataAccessDescriptor::operator [] ( DataAccessDescriptorProperty _eWhich ) const
451*cdf0e10cSrcweir 	{
452*cdf0e10cSrcweir #ifndef SVX_LIGHT
453*cdf0e10cSrcweir 		if (!has(_eWhich))
454*cdf0e10cSrcweir 		{
455*cdf0e10cSrcweir 			OSL_ENSURE(sal_False, "ODataAccessDescriptor::operator[]: invalid acessor!");
456*cdf0e10cSrcweir 			static const Any aDummy;
457*cdf0e10cSrcweir 			return aDummy;
458*cdf0e10cSrcweir 		}
459*cdf0e10cSrcweir 
460*cdf0e10cSrcweir 		return m_pImpl->m_aValues[_eWhich];
461*cdf0e10cSrcweir #else
462*cdf0e10cSrcweir 		static const Any aDummy;
463*cdf0e10cSrcweir 		return aDummy;
464*cdf0e10cSrcweir #endif
465*cdf0e10cSrcweir 	}
466*cdf0e10cSrcweir 
467*cdf0e10cSrcweir 	//--------------------------------------------------------------------
468*cdf0e10cSrcweir 	Any& ODataAccessDescriptor::operator[] ( DataAccessDescriptorProperty _eWhich )
469*cdf0e10cSrcweir 	{
470*cdf0e10cSrcweir #ifndef SVX_LIGHT
471*cdf0e10cSrcweir 		m_pImpl->invalidateExternRepresentations();
472*cdf0e10cSrcweir 		return m_pImpl->m_aValues[_eWhich];
473*cdf0e10cSrcweir #else
474*cdf0e10cSrcweir 		static const Any aDummy;
475*cdf0e10cSrcweir 		return aDummy;
476*cdf0e10cSrcweir #endif
477*cdf0e10cSrcweir 	}
478*cdf0e10cSrcweir 
479*cdf0e10cSrcweir 	//--------------------------------------------------------------------
480*cdf0e10cSrcweir 	void ODataAccessDescriptor::initializeFrom(const Reference< XPropertySet >& _rxValues, sal_Bool _bClear)
481*cdf0e10cSrcweir 	{
482*cdf0e10cSrcweir #ifndef SVX_LIGHT
483*cdf0e10cSrcweir 		if (_bClear)
484*cdf0e10cSrcweir 			clear();
485*cdf0e10cSrcweir 		m_pImpl->buildFrom(_rxValues);
486*cdf0e10cSrcweir #endif
487*cdf0e10cSrcweir 	}
488*cdf0e10cSrcweir 
489*cdf0e10cSrcweir 	//--------------------------------------------------------------------
490*cdf0e10cSrcweir 	void ODataAccessDescriptor::initializeFrom(const Sequence< PropertyValue >& _rValues, sal_Bool _bClear)
491*cdf0e10cSrcweir 	{
492*cdf0e10cSrcweir #ifndef SVX_LIGHT
493*cdf0e10cSrcweir 		if (_bClear)
494*cdf0e10cSrcweir 			clear();
495*cdf0e10cSrcweir 		m_pImpl->buildFrom(_rValues);
496*cdf0e10cSrcweir #endif
497*cdf0e10cSrcweir 	}
498*cdf0e10cSrcweir 
499*cdf0e10cSrcweir 	//--------------------------------------------------------------------
500*cdf0e10cSrcweir 	Sequence< PropertyValue > ODataAccessDescriptor::createPropertyValueSequence()
501*cdf0e10cSrcweir 	{
502*cdf0e10cSrcweir #ifndef SVX_LIGHT
503*cdf0e10cSrcweir 		m_pImpl->updateSequence();
504*cdf0e10cSrcweir 		return m_pImpl->m_aAsSequence;
505*cdf0e10cSrcweir #else
506*cdf0e10cSrcweir 		return Sequence< PropertyValue >();
507*cdf0e10cSrcweir #endif
508*cdf0e10cSrcweir 	}
509*cdf0e10cSrcweir 	//--------------------------------------------------------------------
510*cdf0e10cSrcweir 	Sequence< Any > ODataAccessDescriptor::createAnySequence()
511*cdf0e10cSrcweir 	{
512*cdf0e10cSrcweir #ifndef SVX_LIGHT
513*cdf0e10cSrcweir 		m_pImpl->updateSequence();
514*cdf0e10cSrcweir 		Sequence< Any > aRet(m_pImpl->m_aAsSequence.getLength());
515*cdf0e10cSrcweir 		const PropertyValue* pBegin = m_pImpl->m_aAsSequence.getConstArray();
516*cdf0e10cSrcweir 		const PropertyValue* pEnd	  = pBegin + m_pImpl->m_aAsSequence.getLength();
517*cdf0e10cSrcweir 		for(sal_Int32 i=0;pBegin != pEnd;++pBegin,++i)
518*cdf0e10cSrcweir 			aRet[i] <<= *pBegin;
519*cdf0e10cSrcweir 		return aRet;
520*cdf0e10cSrcweir #else
521*cdf0e10cSrcweir 		return Sequence< createAnySequence >();
522*cdf0e10cSrcweir #endif
523*cdf0e10cSrcweir 	}
524*cdf0e10cSrcweir 
525*cdf0e10cSrcweir 	//--------------------------------------------------------------------
526*cdf0e10cSrcweir 	Reference< XPropertySet > ODataAccessDescriptor::createPropertySet()
527*cdf0e10cSrcweir 	{
528*cdf0e10cSrcweir #ifndef SVX_LIGHT
529*cdf0e10cSrcweir 		m_pImpl->updateSet();
530*cdf0e10cSrcweir 		return m_pImpl->m_xAsSet;
531*cdf0e10cSrcweir #else
532*cdf0e10cSrcweir 		return Reference< XPropertySet >();
533*cdf0e10cSrcweir #endif
534*cdf0e10cSrcweir 	}
535*cdf0e10cSrcweir 	//--------------------------------------------------------------------
536*cdf0e10cSrcweir 	::rtl::OUString ODataAccessDescriptor::getDataSource() const
537*cdf0e10cSrcweir 	{
538*cdf0e10cSrcweir #ifndef SVX_LIGHT
539*cdf0e10cSrcweir 		::rtl::OUString	sDataSourceName;
540*cdf0e10cSrcweir 		if ( has(daDataSource) )
541*cdf0e10cSrcweir 			(*this)[daDataSource] >>= sDataSourceName;
542*cdf0e10cSrcweir 		else if ( has(daDatabaseLocation) )
543*cdf0e10cSrcweir 			(*this)[daDatabaseLocation] >>= sDataSourceName;
544*cdf0e10cSrcweir 		return sDataSourceName;
545*cdf0e10cSrcweir #else
546*cdf0e10cSrcweir 		return ::rtl::OUString();
547*cdf0e10cSrcweir #endif
548*cdf0e10cSrcweir 	}
549*cdf0e10cSrcweir 	//--------------------------------------------------------------------
550*cdf0e10cSrcweir 	void ODataAccessDescriptor::setDataSource(const ::rtl::OUString& _sDataSourceNameOrLocation)
551*cdf0e10cSrcweir 	{
552*cdf0e10cSrcweir #ifndef SVX_LIGHT
553*cdf0e10cSrcweir 		if ( _sDataSourceNameOrLocation.getLength() )
554*cdf0e10cSrcweir 		{
555*cdf0e10cSrcweir 			INetURLObject aURL(_sDataSourceNameOrLocation);
556*cdf0e10cSrcweir 			(*this)[ (( aURL.GetProtocol() == INET_PROT_FILE ) ? daDatabaseLocation : daDataSource)] <<= _sDataSourceNameOrLocation;
557*cdf0e10cSrcweir 		}
558*cdf0e10cSrcweir 		else
559*cdf0e10cSrcweir 			(*this)[ daDataSource ] <<= ::rtl::OUString();
560*cdf0e10cSrcweir #endif
561*cdf0e10cSrcweir 	}
562*cdf0e10cSrcweir 
563*cdf0e10cSrcweir //........................................................................
564*cdf0e10cSrcweir }	// namespace svx
565*cdf0e10cSrcweir //........................................................................
566*cdf0e10cSrcweir 
567*cdf0e10cSrcweir 
568