LCOV - code coverage report
Current view: top level - filter/source/config/cache - frameloaderfactory.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 27 47 57.4 %
Date: 2012-08-25 Functions: 9 9 100.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 23 124 18.5 %

           Branch data     Line data    Source code
       1                 :            : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2                 :            : /*************************************************************************
       3                 :            :  *
       4                 :            :  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       5                 :            :  *
       6                 :            :  * Copyright 2000, 2010 Oracle and/or its affiliates.
       7                 :            :  *
       8                 :            :  * OpenOffice.org - a multi-platform office productivity suite
       9                 :            :  *
      10                 :            :  * This file is part of OpenOffice.org.
      11                 :            :  *
      12                 :            :  * OpenOffice.org is free software: you can redistribute it and/or modify
      13                 :            :  * it under the terms of the GNU Lesser General Public License version 3
      14                 :            :  * only, as published by the Free Software Foundation.
      15                 :            :  *
      16                 :            :  * OpenOffice.org is distributed in the hope that it will be useful,
      17                 :            :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      18                 :            :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      19                 :            :  * GNU Lesser General Public License version 3 for more details
      20                 :            :  * (a copy is included in the LICENSE file that accompanied this code).
      21                 :            :  *
      22                 :            :  * You should have received a copy of the GNU Lesser General Public License
      23                 :            :  * version 3 along with OpenOffice.org.  If not, see
      24                 :            :  * <http://www.openoffice.org/license.html>
      25                 :            :  * for a copy of the LGPLv3 License.
      26                 :            :  *
      27                 :            :  ************************************************************************/
      28                 :            : 
      29                 :            : 
      30                 :            : #include "frameloaderfactory.hxx"
      31                 :            : #include "macros.hxx"
      32                 :            : #include "constant.hxx"
      33                 :            : #include "versions.hxx"
      34                 :            : 
      35                 :            : #include <com/sun/star/lang/XInitialization.hpp>
      36                 :            : #include <comphelper/enumhelper.hxx>
      37                 :            : 
      38                 :            : 
      39                 :            : namespace filter{
      40                 :            :     namespace config{
      41                 :            : 
      42                 :            : namespace css = ::com::sun::star;
      43                 :            : 
      44                 :            : 
      45                 :            : 
      46                 :            : 
      47                 :       2369 : FrameLoaderFactory::FrameLoaderFactory(const css::uno::Reference< css::lang::XMultiServiceFactory >& xSMGR)
      48                 :            : {
      49                 :            :     BaseContainer::init(xSMGR                                              ,
      50                 :            :                         FrameLoaderFactory::impl_getImplementationName()   ,
      51                 :            :                         FrameLoaderFactory::impl_getSupportedServiceNames(),
      52 [ +  - ][ +  - ]:       2369 :                         FilterCache::E_FRAMELOADER                         );
         [ +  - ][ +  - ]
      53                 :       2369 : }
      54                 :            : 
      55                 :            : 
      56                 :            : 
      57                 :       2369 : FrameLoaderFactory::~FrameLoaderFactory()
      58                 :            : {
      59         [ -  + ]:       4738 : }
      60                 :            : 
      61                 :            : 
      62                 :            : 
      63                 :       1753 : css::uno::Reference< css::uno::XInterface > SAL_CALL FrameLoaderFactory::createInstance(const ::rtl::OUString& sLoader)
      64                 :            :     throw(css::uno::Exception       ,
      65                 :            :           css::uno::RuntimeException)
      66                 :            : {
      67         [ +  - ]:       1753 :     return createInstanceWithArguments(sLoader, css::uno::Sequence< css::uno::Any >());
      68                 :            : }
      69                 :            : 
      70                 :            : 
      71                 :            : 
      72                 :       1753 : css::uno::Reference< css::uno::XInterface > SAL_CALL FrameLoaderFactory::createInstanceWithArguments(const ::rtl::OUString&                     sLoader  ,
      73                 :            :                                                                                                      const css::uno::Sequence< css::uno::Any >& lArguments)
      74                 :            :     throw(css::uno::Exception       ,
      75                 :            :           css::uno::RuntimeException)
      76                 :            : {
      77                 :            :     // SAFE ->
      78         [ +  - ]:       1753 :     ::osl::ResettableMutexGuard aLock(m_aLock);
      79                 :            : 
      80                 :       1753 :     ::rtl::OUString sRealLoader = sLoader;
      81                 :            : 
      82                 :            :     #ifdef _FILTER_CONFIG_MIGRATION_Q_
      83                 :            : 
      84                 :            :         /* -> TODO - HACK
      85                 :            :             check if the given loader name realy exist ...
      86                 :            :             Because our old implementation worked with an internal
      87                 :            :             type name instead of a loader name. For a small migration time
      88                 :            :             we must simulate this old feature :-( */
      89                 :            : 
      90 [ +  - ][ -  + ]:       1753 :         if (!m_rCache->hasItem(FilterCache::E_FRAMELOADER, sLoader) && m_rCache->hasItem(FilterCache::E_TYPE, sLoader))
         [ #  # ][ #  # ]
         [ #  # ][ -  + ]
                 [ +  - ]
      91                 :            :         {
      92                 :            :             _FILTER_CONFIG_LOG_("FrameLoaderFactory::createInstanceWithArguments() ... simulate old type search functionality!\n");
      93                 :            : 
      94         [ #  # ]:          0 :             css::uno::Sequence< ::rtl::OUString > lTypes(1);
      95         [ #  # ]:          0 :             lTypes[0] = sLoader;
      96                 :            : 
      97         [ #  # ]:          0 :             css::uno::Sequence< css::beans::NamedValue > lQuery(1);
      98         [ #  # ]:          0 :             lQuery[0].Name    = PROPNAME_TYPES;
      99 [ #  # ][ #  # ]:          0 :             lQuery[0].Value <<= lTypes;
     100                 :            : 
     101         [ #  # ]:          0 :             css::uno::Reference< css::container::XEnumeration > xSet = createSubSetEnumerationByProperties(lQuery);
     102 [ #  # ][ #  # ]:          0 :             while(xSet->hasMoreElements())
                 [ #  # ]
     103                 :            :             {
     104 [ #  # ][ #  # ]:          0 :                 ::comphelper::SequenceAsHashMap lLoaderProps(xSet->nextElement());
                 [ #  # ]
     105 [ #  # ][ #  # ]:          0 :                 if (!(lLoaderProps[PROPNAME_NAME] >>= sRealLoader))
     106                 :          0 :                     continue;
     107 [ #  # ][ #  # ]:          0 :             }
     108                 :            : 
     109                 :            :             // prevent outside code against NoSuchElementException!
     110                 :            :             // But dont implement such defensive strategy for our new create handling :-)
     111 [ #  # ][ #  # ]:          0 :             if (!m_rCache->hasItem(FilterCache::E_FRAMELOADER, sRealLoader))
                 [ #  # ]
     112 [ #  # ][ #  # ]:          0 :                 return css::uno::Reference< css::uno::XInterface>();
         [ #  # ][ #  # ]
                 [ #  # ]
     113                 :            :         }
     114                 :            : 
     115                 :            :         /* <- HACK */
     116                 :            : 
     117                 :            :     #endif // _FILTER_CONFIG_MIGRATION_Q_
     118                 :            : 
     119                 :            :     // search loader on cache
     120 [ +  - ][ +  - ]:       1753 :     CacheItem aLoader = m_rCache->getItem(m_eType, sRealLoader);
     121                 :            : 
     122                 :            :     // create service instance
     123 [ +  - ][ +  - ]:       1753 :     css::uno::Reference< css::uno::XInterface > xLoader = m_xSMGR->createInstance(sRealLoader);
     124                 :            : 
     125                 :            :     // initialize filter
     126         [ +  - ]:       1753 :     css::uno::Reference< css::lang::XInitialization > xInit(xLoader, css::uno::UNO_QUERY);
     127         [ -  + ]:       1753 :     if (xInit.is())
     128                 :            :     {
     129                 :            :         // format: lInitData[0] = seq<PropertyValue>, which contains all configuration properties of this loader
     130                 :            :         //         lInitData[1] = lArguments[0]
     131                 :            :         //         ...
     132                 :            :         //         lInitData[n] = lArguments[n-1]
     133         [ #  # ]:          0 :         css::uno::Sequence< css::beans::PropertyValue > lConfig;
     134         [ #  # ]:          0 :         aLoader >> lConfig;
     135                 :            : 
     136         [ #  # ]:          0 :         ::comphelper::SequenceAsVector< css::uno::Any > stlArguments(lArguments);
     137 [ #  # ][ #  # ]:          0 :         stlArguments.insert(stlArguments.begin(), css::uno::makeAny(lConfig));
     138                 :            : 
     139         [ #  # ]:          0 :         css::uno::Sequence< css::uno::Any > lInitData;
     140         [ #  # ]:          0 :         stlArguments >> lInitData;
     141                 :            : 
     142 [ #  # ][ #  # ]:          0 :         xInit->initialize(lInitData);
         [ #  # ][ #  # ]
     143                 :            :     }
     144                 :            : 
     145 [ +  - ][ +  - ]:       1753 :     return xLoader;
     146                 :            :     // <- SAFE
     147                 :            : }
     148                 :            : 
     149                 :            : 
     150                 :            : 
     151                 :          2 : css::uno::Sequence< ::rtl::OUString > SAL_CALL FrameLoaderFactory::getAvailableServiceNames()
     152                 :            :     throw(css::uno::RuntimeException)
     153                 :            : {
     154                 :            :     // must be the same list as ((XNameAccess*)this)->getElementNames() return!
     155                 :          2 :     return getElementNames();
     156                 :            : }
     157                 :            : 
     158                 :            : 
     159                 :            : 
     160                 :       2994 : ::rtl::OUString FrameLoaderFactory::impl_getImplementationName()
     161                 :            : {
     162                 :       2994 :     return ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.filter.config.FrameLoaderFactory" ));
     163                 :            : }
     164                 :            : 
     165                 :            : 
     166                 :            : 
     167                 :       2482 : css::uno::Sequence< ::rtl::OUString > FrameLoaderFactory::impl_getSupportedServiceNames()
     168                 :            : {
     169                 :       2482 :     css::uno::Sequence< ::rtl::OUString > lServiceNames(1);
     170 [ +  - ][ +  - ]:       2482 :     lServiceNames[0] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.frame.FrameLoaderFactory" ));
     171                 :       2482 :     return lServiceNames;
     172                 :            : }
     173                 :            : 
     174                 :            : 
     175                 :            : 
     176                 :       2369 : css::uno::Reference< css::uno::XInterface > SAL_CALL FrameLoaderFactory::impl_createInstance(const css::uno::Reference< css::lang::XMultiServiceFactory >& xSMGR)
     177                 :            : {
     178         [ +  - ]:       2369 :     FrameLoaderFactory* pNew = new FrameLoaderFactory(xSMGR);
     179         [ +  - ]:       2369 :     return css::uno::Reference< css::uno::XInterface >(static_cast< css::lang::XMultiServiceFactory* >(pNew), css::uno::UNO_QUERY);
     180                 :            : }
     181                 :            : 
     182                 :            :     } // namespace config
     183                 :            : } // namespace filter
     184                 :            : 
     185                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10