LCOV - code coverage report
Current view: top level - dbaccess/source/core/inc - definitioncontainer.hxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 15 19 78.9 %
Date: 2015-06-13 12:38:46 Functions: 12 15 80.0 %
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             : #ifndef INCLUDED_DBACCESS_SOURCE_CORE_INC_DEFINITIONCONTAINER_HXX
      21             : #define INCLUDED_DBACCESS_SOURCE_CORE_INC_DEFINITIONCONTAINER_HXX
      22             : 
      23             : #include <sal/config.h>
      24             : 
      25             : #include <map>
      26             : #include <vector>
      27             : 
      28             : #include <cppuhelper/interfacecontainer.hxx>
      29             : #include <cppuhelper/implbase7.hxx>
      30             : #include <osl/mutex.hxx>
      31             : #include <com/sun/star/container/XChild.hpp>
      32             : #include <com/sun/star/container/XNameContainer.hpp>
      33             : #include <com/sun/star/container/XContainer.hpp>
      34             : #include <com/sun/star/container/XEnumerationAccess.hpp>
      35             : #include <com/sun/star/container/XIndexAccess.hpp>
      36             : #include <com/sun/star/lang/XServiceInfo.hpp>
      37             : #include <com/sun/star/lang/DisposedException.hpp>
      38             : #include <com/sun/star/beans/XPropertyChangeListener.hpp>
      39             : #include <com/sun/star/beans/XVetoableChangeListener.hpp>
      40             : #include <com/sun/star/container/XContainerApproveBroadcaster.hpp>
      41             : #include "ContentHelper.hxx"
      42             : #include "containerapprove.hxx"
      43             : #include <comphelper/uno3.hxx>
      44             : #include <rtl/ref.hxx>
      45             : #include "apitools.hxx"
      46             : 
      47             : namespace dbaccess
      48             : {
      49             : 
      50        1400 : class ODefinitionContainer_Impl : public OContentHelper_Impl
      51             : {
      52             : public:
      53             :     typedef ::std::map< OUString, TContentPtr >  NamedDefinitions;
      54             :     typedef NamedDefinitions::iterator                  iterator;
      55             :     typedef NamedDefinitions::const_iterator            const_iterator;
      56             : 
      57             : private:
      58             :     NamedDefinitions    m_aDefinitions;
      59             : 
      60             : public:
      61           0 :     inline size_t size() const { return m_aDefinitions.size(); }
      62             : 
      63         841 :     inline const_iterator begin() const   { return m_aDefinitions.begin(); }
      64        1170 :     inline const_iterator end() const     { return m_aDefinitions.end(); }
      65             : 
      66         216 :     inline const_iterator find( const OUString& _rName ) const { return m_aDefinitions.find( _rName ); }
      67             :            const_iterator find( TContentPtr _pDefinition ) const;
      68             : 
      69           0 :     inline void erase( const OUString& _rName ) { m_aDefinitions.erase( _rName ); }
      70             :     void erase( TContentPtr _pDefinition );
      71             : 
      72          75 :     inline void insert( const OUString& _rName, TContentPtr _pDefinition )
      73             :     {
      74          75 :         m_aDefinitions.insert( NamedDefinitions::value_type( _rName, _pDefinition ) );
      75          75 :     }
      76             : 
      77             : private:
      78             :     iterator find( TContentPtr _pDefinition );
      79             :         // (for the moment, this is private. Make it public if needed. If really needed.)
      80             : };
      81             : 
      82             : // ODefinitionContainer -  base class of collections of database definition
      83             : //                         documents
      84             : typedef ::cppu::ImplHelper7 <   ::com::sun::star::container::XIndexAccess
      85             :                             ,   ::com::sun::star::container::XNameContainer
      86             :                             ,   ::com::sun::star::container::XEnumerationAccess
      87             :                             ,   ::com::sun::star::container::XContainer
      88             :                             ,   ::com::sun::star::container::XContainerApproveBroadcaster
      89             :                             ,   ::com::sun::star::beans::XPropertyChangeListener
      90             :                             ,   ::com::sun::star::beans::XVetoableChangeListener
      91             :                             >   ODefinitionContainer_Base;
      92             : 
      93             : class ODefinitionContainer
      94             :             :public OContentHelper
      95             :             ,public ODefinitionContainer_Base
      96             : {
      97             : protected:
      98             :     typedef std::map< OUString, ::com::sun::star::uno::WeakReference< ::com::sun::star::ucb::XContent > > Documents;
      99             :     typedef std::vector<Documents::iterator> DocumentsIndexAccess;
     100             : 
     101             :     enum ContainerOperation
     102             :     {
     103             :         E_REPLACED,
     104             :         E_REMOVED,
     105             :         E_INSERTED
     106             :     };
     107             : 
     108             :     enum ListenerType
     109             :     {
     110             :         ApproveListeners,
     111             :         ContainerListemers
     112             :     };
     113             : 
     114             : private:
     115             :     PContainerApprove   m_pElementApproval;
     116             : 
     117             : protected:
     118             :     // we can't just hold a vector of XContentRefs, as after initialization they're all empty
     119             :     // cause we load them only on access
     120             :     DocumentsIndexAccess    m_aDocuments;               // for a efficient index access
     121             :     Documents               m_aDocumentMap;             // for a efficient name access
     122             : 
     123             :     ::cppu::OInterfaceContainerHelper
     124             :                             m_aApproveListeners;
     125             :     ::cppu::OInterfaceContainerHelper
     126             :                             m_aContainerListeners;
     127             : 
     128             :     bool                m_bInPropertyChange;
     129             :     bool                    m_bCheckSlash;
     130             : 
     131             : protected:
     132             :     /** Additionally to our own approvals which new elements must pass, derived classes
     133             :         can specifiy an additional approval instance here.
     134             : 
     135             :         Every time a new element is inserted into the container (or an element is replaced
     136             :         with a new one), this new element must pass our own internal approval, plus the approval
     137             :         given here.
     138             :     */
     139         243 :     void                setElementApproval( PContainerApprove _pElementApproval ) { m_pElementApproval = _pElementApproval; }
     140          25 :     PContainerApprove   getElementApproval() const { return m_pElementApproval; }
     141             : 
     142             : protected:
     143             :     virtual ~ODefinitionContainer();
     144             : 
     145          74 :     inline const ODefinitionContainer_Impl& getDefinitions() const
     146             :     {
     147          74 :         return dynamic_cast< const ODefinitionContainer_Impl& >( *m_pImpl.get() );
     148             :     }
     149             : 
     150        1008 :     inline       ODefinitionContainer_Impl&  getDefinitions()
     151             :     {
     152        1008 :         return dynamic_cast<       ODefinitionContainer_Impl& >( *m_pImpl.get() );
     153             :     }
     154             : public:
     155             :     /** constructs the container.
     156             :     */
     157             :     ODefinitionContainer(
     158             :           const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >& _xORB
     159             :         , const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >&  _xParentContainer
     160             :         , const TContentPtr& _pImpl
     161             :         , bool _bCheckSlash = true
     162             :         );
     163             : 
     164             : // ::com::sun::star::uno::XInterface
     165             :     DECLARE_XINTERFACE( )
     166             : 
     167             :     virtual css::uno::Sequence<css::uno::Type> SAL_CALL getTypes()
     168             :         throw (css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     169             :     virtual css::uno::Sequence<sal_Int8> SAL_CALL getImplementationId()
     170             :         throw (css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     171             : 
     172             : // ::com::sun::star::lang::XServiceInfo
     173             :     virtual OUString SAL_CALL getImplementationName(  ) throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     174             :     virtual ::com::sun::star::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames(  ) throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     175             : 
     176             : // ::com::sun::star::container::XElementAccess
     177             :     virtual ::com::sun::star::uno::Type SAL_CALL getElementType(  ) throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     178             :     virtual sal_Bool SAL_CALL hasElements(  ) throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     179             : 
     180             : // ::com::sun::star::container::XEnumerationAccess
     181             :     virtual ::com::sun::star::uno::Reference< ::com::sun::star::container::XEnumeration > SAL_CALL createEnumeration(  ) throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     182             : 
     183             : // ::com::sun::star::container::XIndexAccess
     184             :     virtual sal_Int32 SAL_CALL getCount(  ) throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     185             :     virtual ::com::sun::star::uno::Any SAL_CALL getByIndex( sal_Int32 _nIndex ) throw(::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     186             : 
     187             : // ::com::sun::star::container::XNameContainer
     188             :     virtual void SAL_CALL insertByName( const OUString& _rName, const ::com::sun::star::uno::Any& aElement ) throw(::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::container::ElementExistException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     189             :     virtual void SAL_CALL removeByName( const OUString& _rName ) throw(::com::sun::star::container::NoSuchElementException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     190             : 
     191             : // ::com::sun::star::container::XNameReplace
     192             :     virtual void SAL_CALL replaceByName( const OUString& _rName, const ::com::sun::star::uno::Any& aElement ) throw(::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::container::NoSuchElementException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     193             : 
     194             : // ::com::sun::star::container::XNameAccess
     195             :     virtual ::com::sun::star::uno::Any SAL_CALL getByName( const OUString& aName ) throw(::com::sun::star::container::NoSuchElementException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     196             :     virtual ::com::sun::star::uno::Sequence< OUString > SAL_CALL getElementNames(  ) throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     197             :     virtual sal_Bool SAL_CALL hasByName( const OUString& aName ) throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     198             : 
     199             : // ::com::sun::star::container::XContainer
     200             :     virtual void SAL_CALL addContainerListener( const ::com::sun::star::uno::Reference< ::com::sun::star::container::XContainerListener >& xListener ) throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     201             :     virtual void SAL_CALL removeContainerListener( const ::com::sun::star::uno::Reference< ::com::sun::star::container::XContainerListener >& xListener ) throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     202             : 
     203             :     // XContainerApproveBroadcaster
     204             :     virtual void SAL_CALL addContainerApproveListener( const ::com::sun::star::uno::Reference< ::com::sun::star::container::XContainerApproveListener >& Listener ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     205             :     virtual void SAL_CALL removeContainerApproveListener( const ::com::sun::star::uno::Reference< ::com::sun::star::container::XContainerApproveListener >& Listener ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     206             : 
     207             : // ::com::sun::star::lang::XEventListener
     208             :     virtual void SAL_CALL disposing( const ::com::sun::star::lang::EventObject& Source ) throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     209             : 
     210             :     // XPropertyChangeListener
     211             :     virtual void SAL_CALL propertyChange( const ::com::sun::star::beans::PropertyChangeEvent& evt ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     212             :     // XVetoableChangeListener
     213             :     virtual void SAL_CALL vetoableChange( const ::com::sun::star::beans::PropertyChangeEvent& aEvent ) throw (::com::sun::star::beans::PropertyVetoException, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     214             : 
     215             : protected:
     216             :     // helper
     217             :     virtual void SAL_CALL disposing() SAL_OVERRIDE;
     218             : 
     219             :     /** create a object from it's persistent data within the configuration. To be overwritten by derived classes.
     220             :         @param      _rName          the name the object has within the container
     221             :         @return                     the newly created object or an empty reference if something went wrong
     222             :     */
     223             :     virtual ::com::sun::star::uno::Reference< ::com::sun::star::ucb::XContent > createObject(
     224             :         const OUString& _rName) = 0;
     225             : 
     226             :     /** get the object specified by the given name. If desired, the object will be read if not already done so.<BR>
     227             :         @param      _rName              the object name
     228             :         @param      _bReadIfNecessary  if sal_True, the object will be created if necessary
     229             :         @return                         the property set interface of the object. Usually the return value is not NULL, but
     230             :                                         if so, then the object could not be read from the configuration
     231             :         @throws                         NoSuchElementException if there is no object with the given name.
     232             :         @see    createObject
     233             :     */
     234             :     ::com::sun::star::uno::Reference< ::com::sun::star::ucb::XContent >
     235             :                 implGetByName(const OUString& _rName, bool _bCreateIfNecessary) throw (::com::sun::star::container::NoSuchElementException);
     236             : 
     237             :     /** quickly checks if there already is an element with a given name. No access to the configuration occurs, i.e.
     238             :         if there is such an object which is not already loaded, it won't be loaded now.
     239             :         @param      _rName      the object name to check
     240             :         @return                 sal_True if there already exists such an object
     241             :     */
     242             :     virtual bool checkExistence(const OUString& _rName);
     243             : 
     244             :     /** append a new object to the container. No plausibility checks are done, e.g. if the object is non-NULL or
     245             :         if the name is already used by another object or anything like this. This method is for derived classes
     246             :         which may support different methods to create and/or append objects, and don't want to deal with the
     247             :         internal structures of this class.<BR>
     248             :         The old component will not be disposed, this is the callers responsibility, too.
     249             :         @param      _rName          the name of the new object
     250             :         @param      _rxNewObject    the new object (not surprising, is it ?)
     251             :         @see        createConfigKey
     252             :         @see        implReplace
     253             :         @see        implRemove
     254             :     */
     255             :     void    implAppend(
     256             :         const OUString& _rName,
     257             :         const ::com::sun::star::uno::Reference< ::com::sun::star::ucb::XContent >& _rxNewObject
     258             :         );
     259             : 
     260             :     /** remove all references to an object from the container. No plausibility checks are done, e.g. whether
     261             :         or not there exists an object with the given name. This is the responsibility of the caller.<BR>
     262             :         Additionally the node for the given object will be removed from the registry (including all sub nodes).<BR>
     263             :         The old component will not be disposed, this is the callers responsibility, too.
     264             :         @param          _rName      the objects name
     265             :         @see            implReplace
     266             :         @see            implAppend
     267             :     */
     268             :     void implRemove(const OUString& _rName);
     269             : 
     270             :     /** remove a object in the container. No plausibility checks are done, e.g. whether
     271             :         or not there exists an object with the given name or the object is non-NULL. This is the responsibility of the caller.<BR>
     272             :         Additionally all object-related information within the registry will be deleted. The new object config node,
     273             :         where the caller may want to store the new objects information, is returned.<BR>
     274             :         The old component will not be disposed, this is the callers responsibility, too.
     275             :         @param          _rName              the objects name
     276             :         @param          _rxNewObject        the new object
     277             :         @param          _rNewObjectNode     the configuration node where the new object may be stored
     278             :         @see            implAppend
     279             :         @see            implRemove
     280             :     */
     281             :     void implReplace(
     282             :         const OUString& _rName,
     283             :         const ::com::sun::star::uno::Reference< ::com::sun::star::ucb::XContent >& _rxNewObject
     284             :         );
     285             : 
     286             :     /** notifies our container/approve listeners
     287             :     */
     288             :     void notifyByName(
     289             :             ::osl::ResettableMutexGuard& _rGuard,
     290             :             const OUString& _rName,
     291             :             const ::com::sun::star::uno::Reference< ::com::sun::star::ucb::XContent >& _xNewElement,
     292             :             const ::com::sun::star::uno::Reference< ::com::sun::star::ucb::XContent >& xOldElement,
     293             :             ContainerOperation _eOperation,
     294             :             ListenerType _eType
     295             :         );
     296             : 
     297         910 :     inline SAL_CALL operator ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > () const
     298             :     {
     299         910 :         return const_cast< XContainer* >( static_cast< const XContainer* >( this ) );
     300             :     }
     301             : 
     302             : private:
     303             :     void    addObjectListener(const ::com::sun::star::uno::Reference< ::com::sun::star::ucb::XContent >& _xNewObject);
     304             :     void    removeObjectListener(const ::com::sun::star::uno::Reference< ::com::sun::star::ucb::XContent >& _xNewObject);
     305             : 
     306             :     /** approve that the object given may be inserted into the container.
     307             :         Should be overridden by derived classes,
     308             :         the default implementation just checks the object to be non-void.
     309             : 
     310             :         @throws IllegalArgumentException
     311             :             if the name or the object are invalid
     312             :         @throws ElementExistException
     313             :             if the object already exists in the container, or another object with the same name
     314             :             already exists
     315             :         @throws WrappedTargetException
     316             :             if another error occurs which prevents insertion of the object into the container
     317             :     */
     318             :     void approveNewObject(
     319             :             const OUString& _sName,
     320             :             const ::com::sun::star::uno::Reference< ::com::sun::star::ucb::XContent >& _rxObject
     321             :         ) const;
     322             : 
     323           0 :     inline bool impl_haveAnyListeners_nothrow() const
     324             :     {
     325           0 :         return ( m_aContainerListeners.getLength() > 0 ) || ( m_aApproveListeners.getLength() > 0 );
     326             :     }
     327             : };
     328             : 
     329             : }   // namespace dbaccess
     330             : 
     331             : #endif // INCLUDED_DBACCESS_SOURCE_CORE_INC_DEFINITIONCONTAINER_HXX
     332             : 
     333             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11