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