<commit_before>/*************************************************************************
 *
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 *
 * Copyright 2008 by Sun Microsystems, Inc.
 *
 * OpenOffice.org - a multi-platform office productivity suite
 *
 * $RCSfile: basecontainer.cxx,v $
 * $Revision: 1.10 $
 *
 * This file is part of OpenOffice.org.
 *
 * OpenOffice.org is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License version 3
 * only, as published by the Free Software Foundation.
 *
 * OpenOffice.org is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License version 3 for more details
 * (a copy is included in the LICENSE file that accompanied this code).
 *
 * You should have received a copy of the GNU Lesser General Public License
 * version 3 along with OpenOffice.org.  If not, see
 * <http://www.openoffice.org/license.html>
 * for a copy of the LGPLv3 License.
 *
 ************************************************************************/

// MARKER(update_precomp.py): autogen include statement, do not remove
#include "precompiled_filter.hxx"

#include "basecontainer.hxx"
#include "constant.hxx"

//_______________________________________________
// includes
#include <com/sun/star/lang/WrappedTargetRuntimeException.hpp>
#include <com/sun/star/uno/Type.h>
#include <comphelper/enumhelper.hxx>
#include <osl/diagnose.h>

//_______________________________________________
// namespace

#define LOAD_IMPLICIT

namespace css = ::com::sun::star;

namespace filter{
    namespace config{

//_______________________________________________
// definitions

::salhelper::SingletonRef< FilterCache >* BaseContainer::m_pPerformanceOptimizer = 0;

/*-----------------------------------------------
    03.03.2004 11:37
-----------------------------------------------*/
BaseContainer::BaseContainer()
    : BaseLock     (       )
    , m_rCache     (       )
    , m_pFlushCache(NULL   )
    , m_lListener  (m_aLock)
{
    m_rCache->load(FilterCache::E_CONTAINS_STANDARD);

    // GLOBAL SAFE (!) -> -----------------------
    // TODO use rtl pattern to create it realy threadsafe!
    ::osl::ResettableMutexGuard aGlobalLock(::osl::Mutex::getGlobalMutex());
    if (!m_pPerformanceOptimizer)
        m_pPerformanceOptimizer = new ::salhelper::SingletonRef< FilterCache >();
    aGlobalLock.clear();
    // <- GLOBAL SAFE (!) -----------------------
}

/*-----------------------------------------------
    02.07.2003 10:16
-----------------------------------------------*/
BaseContainer::~BaseContainer()
{
}

/*-----------------------------------------------
    03.07.2003 11:16
-----------------------------------------------*/
void BaseContainer::init(const css::uno::Reference< css::lang::XMultiServiceFactory >& xSMGR              ,
                         const ::rtl::OUString&                                        sImplementationName,
                         const css::uno::Sequence< ::rtl::OUString >&                  lServiceNames      ,
                               FilterCache::EItemType                                  eType              )
{
    // SAFE ->
    ::osl::ResettableMutexGuard aLock(m_aLock);

    m_sImplementationName = sImplementationName;
    m_lServiceNames       = lServiceNames      ;
    m_xSMGR               = xSMGR              ;
    m_eType               = eType              ;
    m_xRefreshBroadcaster = css::uno::Reference< css::util::XRefreshable >(
                                xSMGR->createInstance(SERVICE_FILTERCONFIGREFRESH),
                                css::uno::UNO_QUERY);
    // <- SAFE
}

/*-----------------------------------------------
    28.10.2003 09:04
-----------------------------------------------*/
void BaseContainer::impl_loadOnDemand()
{
#ifdef LOAD_IMPLICIT
    // SAFE ->
    ::osl::ResettableMutexGuard aLock(m_aLock);

    // A generic container needs all items of a set of our cache!
    // Of course it can block for a while, till the cache is realy filled.
    // Note: dont load all sets supported by the cache here!

    FilterCache::EFillState eRequiredState = FilterCache::E_CONTAINS_NOTHING;
    switch(m_eType)
    {
        case FilterCache::E_TYPE :
            eRequiredState = FilterCache::E_CONTAINS_TYPES;
            break;

        case FilterCache::E_FILTER :
            eRequiredState = FilterCache::E_CONTAINS_FILTERS;
            break;

        case FilterCache::E_DETECTSERVICE :
            eRequiredState = FilterCache::E_CONTAINS_DETECTSERVICES;
            break;

        case FilterCache::E_FRAMELOADER :
            eRequiredState = FilterCache::E_CONTAINS_FRAMELOADERS;
            break;

        case FilterCache::E_CONTENTHANDLER :
            eRequiredState = FilterCache::E_CONTAINS_CONTENTHANDLERS;
            break;
    }

    m_rCache->load(eRequiredState);
    // <- SAFE
#endif
}

/*-----------------------------------------------
    03.03.2004 12:18
-----------------------------------------------*/
void BaseContainer::impl_initFlushMode()
    throw (css::uno::RuntimeException)
{
    // SAFE ->
    ::osl::ResettableMutexGuard aLock(m_aLock);
    if (!m_pFlushCache)
        m_pFlushCache = m_rCache->clone();
    if (!m_pFlushCache)
        throw css::uno::RuntimeException(
                ::rtl::OUString::createFromAscii("Cant create write copy of internal used cache on demand."),
                dynamic_cast< css::container::XNameAccess* >(this));
    // <- SAFE
}

/*-----------------------------------------------
    03.03.2004 12:11
-----------------------------------------------*/
FilterCache* BaseContainer::impl_getWorkingCache() const
{
    // SAFE ->
    ::osl::ResettableMutexGuard aLock(m_aLock);
    if (m_pFlushCache)
        return m_pFlushCache;
    else
        return &(*m_rCache);
    // <- SAFE
}

//-----------------------------------------------
sal_Bool BaseContainer::impl_checkIfItemExist(const ::rtl::OUString& sItem)
{
    // SAFE ->
    ::osl::ResettableMutexGuard aLock(m_aLock);

    FilterCache* pCache = impl_getWorkingCache();
    if ( pCache->hasItem(m_eType, sItem) )
        return sal_True;

    impl_loadOnDemand();
    if ( pCache->hasItem(m_eType, sItem) )
        return sal_True;

    return sal_False;
}

/*-----------------------------------------------
    03.07.2003 11:12
-----------------------------------------------*/
::rtl::OUString SAL_CALL BaseContainer::getImplementationName()
    throw (css::uno::RuntimeException)
{
    // SAFE ->
    ::osl::ResettableMutexGuard aLock(m_aLock);
    return m_sImplementationName;
    // <- SAFE
}<commit_msg>INTEGRATION: CWS mba30patches01 (1.9.182); FILE MERGED 2008/04/23 10:57:26 mba 172.16.17.32: RESYNC: (1.9-1.10); FILE MERGED 2008/03/18 15:48:38 mba 172.16.58.3: #i86359#: remove unused code<commit_after>/*************************************************************************
 *
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 *
 * Copyright 2008 by Sun Microsystems, Inc.
 *
 * OpenOffice.org - a multi-platform office productivity suite
 *
 * $RCSfile: basecontainer.cxx,v $
 * $Revision: 1.11 $
 *
 * This file is part of OpenOffice.org.
 *
 * OpenOffice.org is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License version 3
 * only, as published by the Free Software Foundation.
 *
 * OpenOffice.org is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License version 3 for more details
 * (a copy is included in the LICENSE file that accompanied this code).
 *
 * You should have received a copy of the GNU Lesser General Public License
 * version 3 along with OpenOffice.org.  If not, see
 * <http://www.openoffice.org/license.html>
 * for a copy of the LGPLv3 License.
 *
 ************************************************************************/

// MARKER(update_precomp.py): autogen include statement, do not remove
#include "precompiled_filter.hxx"

#include "basecontainer.hxx"
#include "constant.hxx"

//_______________________________________________
// includes
#include <com/sun/star/lang/WrappedTargetRuntimeException.hpp>
#include <com/sun/star/uno/Type.h>
#include <comphelper/enumhelper.hxx>
#include <osl/diagnose.h>

//_______________________________________________
// namespace

#define LOAD_IMPLICIT

namespace css = ::com::sun::star;

namespace filter{
    namespace config{

//_______________________________________________
// definitions

::salhelper::SingletonRef< FilterCache >* BaseContainer::m_pPerformanceOptimizer = 0;

/*-----------------------------------------------
    03.03.2004 11:37
-----------------------------------------------*/
BaseContainer::BaseContainer()
    : BaseLock     (       )
    , m_rCache     (       )
    , m_pFlushCache(NULL   )
    , m_lListener  (m_aLock)
{
    m_rCache->load(FilterCache::E_CONTAINS_STANDARD);

    // GLOBAL SAFE (!) -> -----------------------
    // TODO use rtl pattern to create it realy threadsafe!
    ::osl::ResettableMutexGuard aGlobalLock(::osl::Mutex::getGlobalMutex());
    if (!m_pPerformanceOptimizer)
        m_pPerformanceOptimizer = new ::salhelper::SingletonRef< FilterCache >();
    aGlobalLock.clear();
    // <- GLOBAL SAFE (!) -----------------------
}

/*-----------------------------------------------
    02.07.2003 10:16
-----------------------------------------------*/
BaseContainer::~BaseContainer()
{
}

/*-----------------------------------------------
    03.07.2003 11:16
-----------------------------------------------*/
void BaseContainer::init(const css::uno::Reference< css::lang::XMultiServiceFactory >& xSMGR              ,
                         const ::rtl::OUString&                                        sImplementationName,
                         const css::uno::Sequence< ::rtl::OUString >&                  lServiceNames      ,
                               FilterCache::EItemType                                  eType              )
{
    // SAFE ->
    ::osl::ResettableMutexGuard aLock(m_aLock);

    m_sImplementationName = sImplementationName;
    m_lServiceNames       = lServiceNames      ;
    m_xSMGR               = xSMGR              ;
    m_eType               = eType              ;
    m_xRefreshBroadcaster = css::uno::Reference< css::util::XRefreshable >(
                                xSMGR->createInstance(SERVICE_FILTERCONFIGREFRESH),
                                css::uno::UNO_QUERY);
    // <- SAFE
}

/*-----------------------------------------------
    28.10.2003 09:04
-----------------------------------------------*/
void BaseContainer::impl_loadOnDemand()
{
#ifdef LOAD_IMPLICIT
    // SAFE ->
    ::osl::ResettableMutexGuard aLock(m_aLock);

    // A generic container needs all items of a set of our cache!
    // Of course it can block for a while, till the cache is realy filled.
    // Note: dont load all sets supported by the cache here!

    FilterCache::EFillState eRequiredState = FilterCache::E_CONTAINS_NOTHING;
    switch(m_eType)
    {
        case FilterCache::E_TYPE :
            eRequiredState = FilterCache::E_CONTAINS_TYPES;
            break;

        case FilterCache::E_FILTER :
            eRequiredState = FilterCache::E_CONTAINS_FILTERS;
            break;

        case FilterCache::E_DETECTSERVICE :
            eRequiredState = FilterCache::E_CONTAINS_DETECTSERVICES;
            break;

        case FilterCache::E_FRAMELOADER :
            eRequiredState = FilterCache::E_CONTAINS_FRAMELOADERS;
            break;

        case FilterCache::E_CONTENTHANDLER :
            eRequiredState = FilterCache::E_CONTAINS_CONTENTHANDLERS;
            break;
    }

    m_rCache->load(eRequiredState);
    // <- SAFE
#endif
}

/*-----------------------------------------------
    03.03.2004 12:18
-----------------------------------------------*/
void BaseContainer::impl_initFlushMode()
    throw (css::uno::RuntimeException)
{
    // SAFE ->
    ::osl::ResettableMutexGuard aLock(m_aLock);
    if (!m_pFlushCache)
        m_pFlushCache = m_rCache->clone();
    if (!m_pFlushCache)
        throw css::uno::RuntimeException(
                ::rtl::OUString::createFromAscii("Cant create write copy of internal used cache on demand."),
                dynamic_cast< css::container::XNameAccess* >(this));
    // <- SAFE
}

/*-----------------------------------------------
    03.03.2004 12:11
-----------------------------------------------*/
FilterCache* BaseContainer::impl_getWorkingCache() const
{
    // SAFE ->
    ::osl::ResettableMutexGuard aLock(m_aLock);
    if (m_pFlushCache)
        return m_pFlushCache;
    else
        return &(*m_rCache);
    // <- SAFE
}

/*-----------------------------------------------
    03.07.2003 11:12
-----------------------------------------------*/
::rtl::OUString SAL_CALL BaseContainer::getImplementationName()
    throw (css::uno::RuntimeException)
{
    // SAFE ->
    ::osl::ResettableMutexGuard aLock(m_aLock);
    return m_sImplementationName;
    // <- SAFE
}
{'fraction_non_alphanumeric': 0.22443628736234925, 'fraction_numerical': 0.019177466476889653, 'mean_word_length': 1.8908618449545258, 'pattern_counts': {'":': 0, '<': 37, '<?xml version=': 0, '>': 48, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 2, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3944337', 'n_tokens_mistral': 3845, 'n_tokens_neox': 3610, 'n_words': 818}