LCOV - code coverage report
Current view: top level - dbaccess/source/core/dataaccess - ComponentDefinition.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 113 123 91.9 %
Date: 2015-06-13 12:38:46 Functions: 33 37 89.2 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : 
      20             : #include "ComponentDefinition.hxx"
      21             : #include "apitools.hxx"
      22             : #include "dbastrings.hrc"
      23             : #include "module_dba.hxx"
      24             : #include "services.hxx"
      25             : 
      26             : #include <boost/noncopyable.hpp>
      27             : #include <tools/debug.hxx>
      28             : #include <osl/diagnose.h>
      29             : #include <comphelper/sequence.hxx>
      30             : #include <com/sun/star/lang/DisposedException.hpp>
      31             : #include <com/sun/star/beans/PropertyAttribute.hpp>
      32             : #include <comphelper/property.hxx>
      33             : #include "definitioncolumn.hxx"
      34             : #include <cppuhelper/implbase1.hxx>
      35             : 
      36             : using namespace ::com::sun::star::uno;
      37             : using namespace ::com::sun::star::sdbc;
      38             : using namespace ::com::sun::star::lang;
      39             : 
      40             : using namespace ::com::sun::star::beans;
      41             : using namespace ::com::sun::star::container;
      42             : using namespace ::osl;
      43             : using namespace ::comphelper;
      44             : using namespace ::cppu;
      45             : 
      46          20 : extern "C" void SAL_CALL createRegistryInfo_OComponentDefinition()
      47             : {
      48          20 :     static ::dba::OAutoRegistration< ::dbaccess::OComponentDefinition > aAutoRegistration;
      49          20 : }
      50             : 
      51             : namespace dbaccess
      52             : {
      53             : 
      54             : /// helper class for column property change events which holds the OComponentDefinition weak
      55             : typedef ::cppu::WeakImplHelper1 < XPropertyChangeListener > TColumnPropertyListener_BASE;
      56             : class OColumnPropertyListener:
      57             :     public TColumnPropertyListener_BASE, private boost::noncopyable
      58             : {
      59             :     OComponentDefinition* m_pComponent;
      60             : protected:
      61         198 :     virtual ~OColumnPropertyListener(){}
      62             : public:
      63          99 :     OColumnPropertyListener(OComponentDefinition* _pComponent) : m_pComponent(_pComponent){}
      64             :     // XPropertyChangeListener
      65         286 :     virtual void SAL_CALL propertyChange( const PropertyChangeEvent& /*_rEvent*/ ) throw (RuntimeException, std::exception) SAL_OVERRIDE
      66             :     {
      67         286 :         if ( m_pComponent )
      68         286 :             m_pComponent->notifyDataSourceModified();
      69         286 :     }
      70             :     // XEventListener
      71         465 :     virtual void SAL_CALL disposing( const EventObject& /*_rSource*/ ) throw (RuntimeException, std::exception) SAL_OVERRIDE
      72             :     {
      73         465 :     }
      74          99 :     void clear() { m_pComponent = NULL; }
      75             : };
      76             : 
      77          70 : OComponentDefinition_Impl::OComponentDefinition_Impl()
      78             : {
      79          70 : }
      80             : 
      81         108 : OComponentDefinition_Impl::~OComponentDefinition_Impl()
      82             : {
      83         108 : }
      84             : 
      85             : // OComponentDefinition
      86             : 
      87             : 
      88          42 : void OComponentDefinition::initialize( const Sequence< Any >& aArguments ) throw(Exception, std::exception)
      89             : {
      90          42 :     OUString rName;
      91          42 :     if( (aArguments.getLength() == 1) && (aArguments[0] >>= rName) )
      92             :     {
      93          18 :         Sequence< Any > aNewArgs(1);
      94          36 :         PropertyValue aValue;
      95          18 :         aValue.Name = PROPERTY_NAME;
      96          18 :         aValue.Value <<= rName;
      97          18 :         aNewArgs[0] <<= aValue;
      98          36 :         OContentHelper::initialize(aNewArgs);
      99             :     }
     100             :     else
     101          24 :         OContentHelper::initialize(aArguments);
     102          42 : }
     103             : 
     104          99 : void OComponentDefinition::registerProperties()
     105             : {
     106          99 :     m_xColumnPropertyListener = new OColumnPropertyListener(this);
     107          99 :     OComponentDefinition_Impl& rDefinition( getDefinition() );
     108          99 :     ODataSettings::registerPropertiesFor( &rDefinition );
     109             : 
     110             :     registerProperty(PROPERTY_NAME, PROPERTY_ID_NAME, PropertyAttribute::BOUND | PropertyAttribute::READONLY|PropertyAttribute::CONSTRAINED,
     111          99 :                     &rDefinition.m_aProps.aTitle, cppu::UnoType<decltype(rDefinition.m_aProps.aTitle)>::get());
     112             : 
     113          99 :     if ( m_bTable )
     114             :     {
     115             :         registerProperty(PROPERTY_SCHEMANAME, PROPERTY_ID_SCHEMANAME, PropertyAttribute::BOUND,
     116          58 :                         &rDefinition.m_sSchemaName, cppu::UnoType<decltype(rDefinition.m_sSchemaName)>::get());
     117             : 
     118             :         registerProperty(PROPERTY_CATALOGNAME, PROPERTY_ID_CATALOGNAME, PropertyAttribute::BOUND,
     119          58 :                         &rDefinition.m_sCatalogName, cppu::UnoType<decltype(rDefinition.m_sCatalogName)>::get());
     120             :     }
     121          99 : }
     122             : 
     123          70 : OComponentDefinition::OComponentDefinition(const Reference< XComponentContext >& _xORB
     124             :                                            ,const Reference< XInterface >&  _xParentContainer
     125             :                                            ,const TContentPtr& _pImpl
     126             :                                            ,bool _bTable)
     127             :     :OContentHelper(_xORB,_xParentContainer,_pImpl)
     128          70 :     ,ODataSettings(OContentHelper::rBHelper,!_bTable)
     129         140 :     ,m_bTable(_bTable)
     130             : {
     131          70 :     registerProperties();
     132          70 : }
     133             : 
     134         157 : OComponentDefinition::~OComponentDefinition()
     135             : {
     136         157 : }
     137             : 
     138          29 : OComponentDefinition::OComponentDefinition( const Reference< XInterface >& _rxContainer
     139             :                                        ,const OUString& _rElementName
     140             :                                        ,const Reference< XComponentContext >& _xORB
     141             :                                        ,const TContentPtr& _pImpl
     142             :                                        ,bool _bTable)
     143             :     :OContentHelper(_xORB,_rxContainer,_pImpl)
     144          29 :     ,ODataSettings(OContentHelper::rBHelper,!_bTable)
     145          58 :     ,m_bTable(_bTable)
     146             : {
     147          29 :     registerProperties();
     148             : 
     149          29 :     m_pImpl->m_aProps.aTitle = _rElementName;
     150             :     OSL_ENSURE(!m_pImpl->m_aProps.aTitle.isEmpty(), "OComponentDefinition::OComponentDefinition : invalid name !");
     151          29 : }
     152             : 
     153           0 : css::uno::Sequence<sal_Int8> OComponentDefinition::getImplementationId()
     154             :     throw (css::uno::RuntimeException, std::exception)
     155             : {
     156           0 :     return css::uno::Sequence<sal_Int8>();
     157             : }
     158             : 
     159           0 : IMPLEMENT_GETTYPES3(OComponentDefinition,ODataSettings,OContentHelper,OComponentDefinition_BASE);
     160       30424 : IMPLEMENT_FORWARD_XINTERFACE3( OComponentDefinition,OContentHelper,ODataSettings,OComponentDefinition_BASE)
     161             : 
     162          21 : OUString OComponentDefinition::getImplementationName_static(  ) throw(RuntimeException)
     163             : {
     164          21 :     return OUString("com.sun.star.comp.dba.OComponentDefinition");
     165             : }
     166             : 
     167           1 : OUString SAL_CALL OComponentDefinition::getImplementationName(  ) throw(RuntimeException, std::exception)
     168             : {
     169           1 :     return getImplementationName_static();
     170             : }
     171             : 
     172          21 : Sequence< OUString > OComponentDefinition::getSupportedServiceNames_static(  ) throw(RuntimeException)
     173             : {
     174          21 :     Sequence< OUString > aServices(2);
     175          21 :     aServices[0] = "com.sun.star.sdb.TableDefinition";
     176          21 :     aServices[1] = "com.sun.star.ucb.Content";
     177             : 
     178          21 :     return aServices;
     179             : }
     180             : 
     181           1 : Sequence< OUString > SAL_CALL OComponentDefinition::getSupportedServiceNames(  ) throw(RuntimeException, std::exception)
     182             : {
     183           1 :     return getSupportedServiceNames_static();
     184             : }
     185             : 
     186          38 : Reference< XInterface > OComponentDefinition::Create( const Reference< XComponentContext >& _rxContext )
     187             : {
     188          38 :     return *(new OComponentDefinition( _rxContext, NULL, TContentPtr( new OComponentDefinition_Impl ) ) );
     189             : }
     190             : 
     191          99 : void SAL_CALL OComponentDefinition::disposing()
     192             : {
     193          99 :     OContentHelper::disposing();
     194          99 :     if ( m_pColumns.get() )
     195          53 :         m_pColumns->disposing();
     196          99 :     m_xColumnPropertyListener->clear();
     197          99 :     m_xColumnPropertyListener.clear();
     198          99 : }
     199             : 
     200        4153 : IPropertyArrayHelper& OComponentDefinition::getInfoHelper()
     201             : {
     202        4153 :     return *getArrayHelper();
     203             : }
     204             : 
     205          41 : IPropertyArrayHelper* OComponentDefinition::createArrayHelper( ) const
     206             : {
     207          41 :     Sequence< Property > aProps;
     208          41 :     describeProperties(aProps);
     209          41 :     return new OPropertyArrayHelper(aProps);
     210             : }
     211             : 
     212         311 : Reference< XPropertySetInfo > SAL_CALL OComponentDefinition::getPropertySetInfo(  ) throw(RuntimeException, std::exception)
     213             : {
     214         311 :     Reference<XPropertySetInfo> xInfo( createPropertySetInfo( getInfoHelper() ) );
     215         311 :     return xInfo;
     216             : }
     217             : 
     218           0 : OUString OComponentDefinition::determineContentType() const
     219             : {
     220             :     return m_bTable
     221             :         ?   OUString( "application/vnd.org.openoffice.DatabaseTable" )
     222           0 :         :   OUString( "application/vnd.org.openoffice.DatabaseCommandDefinition" );
     223             : }
     224             : 
     225          53 : Reference< XNameAccess> OComponentDefinition::getColumns() throw (RuntimeException, std::exception)
     226             : {
     227          53 :     ::osl::MutexGuard aGuard(m_aMutex);
     228          53 :     ::connectivity::checkDisposed(OContentHelper::rBHelper.bDisposed);
     229             : 
     230          53 :     if ( !m_pColumns.get() )
     231             :     {
     232          53 :         ::std::vector< OUString> aNames;
     233             : 
     234          53 :         const OComponentDefinition_Impl& rDefinition( getDefinition() );
     235          53 :         aNames.reserve( rDefinition.size() );
     236             : 
     237          53 :         OComponentDefinition_Impl::const_iterator aIter = rDefinition.begin();
     238          53 :         OComponentDefinition_Impl::const_iterator aEnd = rDefinition.end();
     239         266 :         for ( ; aIter != aEnd; ++aIter )
     240         213 :             aNames.push_back( aIter->first );
     241             : 
     242          53 :         m_pColumns.reset( new OColumns( *this, m_aMutex, true, aNames, this, NULL, true, false, false ) );
     243          53 :         m_pColumns->setParent( *this );
     244             :     }
     245          53 :     return m_pColumns.get();
     246             : }
     247             : 
     248         465 : OColumn* OComponentDefinition::createColumn(const OUString& _rName) const
     249             : {
     250         465 :     const OComponentDefinition_Impl& rDefinition( getDefinition() );
     251         465 :     OComponentDefinition_Impl::const_iterator aFind = rDefinition.find( _rName );
     252         465 :     if ( aFind != rDefinition.end() )
     253             :     {
     254         465 :         aFind->second->addPropertyChangeListener(OUString(),m_xColumnPropertyListener.get());
     255         465 :         return new OTableColumnWrapper( aFind->second, aFind->second, true );
     256             :     }
     257             :     OSL_FAIL( "OComponentDefinition::createColumn: is this a valid case?" );
     258             :         // This here is the last place creating a OTableColumn, and somehow /me thinks it is not needed ...
     259           0 :     return new OTableColumn( _rName );
     260             : }
     261             : 
     262         426 : Reference< XPropertySet > OComponentDefinition::createColumnDescriptor()
     263             : {
     264         426 :     return new OTableColumnDescriptor( true );
     265             : }
     266             : 
     267          47 : void OComponentDefinition::setFastPropertyValue_NoBroadcast(sal_Int32 nHandle,const Any& rValue) throw (Exception, std::exception)
     268             : {
     269          47 :     ODataSettings::setFastPropertyValue_NoBroadcast(nHandle,rValue);
     270          47 :     notifyDataSourceModified();
     271          47 : }
     272             : 
     273           0 : void OComponentDefinition::columnDropped(const OUString& _sName)
     274             : {
     275           0 :     getDefinition().erase( _sName );
     276           0 :     notifyDataSourceModified();
     277           0 : }
     278             : 
     279         213 : void OComponentDefinition::columnAppended( const Reference< XPropertySet >& _rxSourceDescriptor )
     280             : {
     281         213 :     OUString sName;
     282         213 :     _rxSourceDescriptor->getPropertyValue( PROPERTY_NAME ) >>= sName;
     283             : 
     284         426 :     Reference<XPropertySet> xColDesc = new OTableColumnDescriptor( true );
     285         213 :     ::comphelper::copyProperties( _rxSourceDescriptor, xColDesc );
     286         213 :     getDefinition().insert( sName, xColDesc );
     287             : 
     288             :     // formerly, here was a setParent at the xColDesc. The parent used was an adapter (ChildHelper_Impl)
     289             :     // which held another XChild weak, and forwarded all getParent requests to this other XChild.
     290             :     // m_pColumns was used for this. This was nonsense, since m_pColumns dies when our instance dies,
     291             :     // but xColDesc will live longer than this. So effectively, the setParent call was pretty useless.
     292             :     //
     293             :     // The intention for this parenting was that the column descriptor is able to find the data source,
     294             :     // by traveling up the parent hierarchy until there's an XDataSource. This didn't work (which
     295             :     // for instance causes #i65023#). We need another way to properly ensure this.
     296             : 
     297         426 :     notifyDataSourceModified();
     298         213 : }
     299             : 
     300             : }   // namespace dbaccess
     301             : 
     302             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11