Update ooo320-m1
[ooovba.git] / configmgr / workben / logger / loggerdfn.cxx
blobae8931435bfaedd142427fde8cf2f9b1d0c1fe25
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: loggerdfn.cxx,v $
10 * $Revision: 1.5 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_configmgr.hxx"
34 #include "simplelogger.hxx"
35 #include <com/sun/star/registry/XRegistryKey.hpp>
36 #ifndef _CPPUHELPER_IMPLEMENTATIONENTRY_HXX_
37 #include <cppuhelper/implementationentry.hxx>
38 #endif
39 #include <rtl/ustrbuf.hxx>
41 namespace cssuno = com::sun::star::uno;
42 using rtl::OUString;
43 using rtl::OUStringBuffer;
45 //==============================================================================
47 static cssuno::Reference<cssuno::XInterface> SAL_CALL
48 createSimpleLogger( const cssuno::Reference<cssuno::XComponentContext>& aContext)
50 return * new logger::SimpleLogger(aContext,"configuration.log") ;
52 //==============================================================================
54 // adapted from the corresponding cppuhelper function
55 static sal_Bool component_writeInfoHelper_withSingleton(
56 void *pServiceManager, void *pRegistryKey ,
57 const cppu::ImplementationEntry entries[],
58 char const * const singletons[])
60 using namespace com::sun::star::registry;
61 using rtl::OUString;
63 sal_Bool bRet = sal_False;
64 try
66 if( pRegistryKey )
68 for( sal_Int32 i = 0; entries[i].create ; i ++ )
70 rtl::OUStringBuffer buf( 124 );
71 buf.appendAscii( RTL_CONSTASCII_STRINGPARAM("/") );
72 buf.append( entries[i].getImplementationName() );
73 buf.appendAscii(RTL_CONSTASCII_STRINGPARAM( "/UNO/SERVICES" ) );
74 cssuno::Reference< XRegistryKey > xNewKey(
75 static_cast< XRegistryKey * >( pRegistryKey )->createKey( buf.makeStringAndClear() ) );
77 cssuno::Sequence< OUString > const seq = entries[i].getSupportedServiceNames();
78 for ( sal_Int32 nPos = 0 ; nPos < seq.getLength(); nPos ++ )
79 xNewKey->createKey( seq[nPos] );
81 if (singletons[i])
83 rtl::OUStringBuffer buf( 124 );
84 buf.appendAscii( RTL_CONSTASCII_STRINGPARAM("/") );
85 buf.append( entries[i].getImplementationName() );
86 buf.appendAscii(RTL_CONSTASCII_STRINGPARAM( "/UNO/SINGLETONS/" ) );
87 buf.appendAscii(singletons[i]);
88 cssuno::Reference< XRegistryKey > xNewKey(
89 static_cast< XRegistryKey * >( pRegistryKey )->createKey( buf.makeStringAndClear() ) );
91 xNewKey->setStringValue(entries[i].getImplementationName());
94 bRet = sal_True;
97 catch ( InvalidRegistryException & )
99 OSL_ENSURE( sal_False, "### InvalidRegistryException!" );
101 catch ( cssuno::Exception & )
103 OSL_ENSURE( sal_False, "### Unexpected UNO Exception!" );
105 return bRet;
108 //------------------------------------------------------------------------------
110 static const cppu::ImplementationEntry kImplementations_entries[] =
113 createSimpleLogger,
114 logger::SimpleLogger::getImplementationName_static,
115 logger::SimpleLogger::getSupportedServiceNames_static,
116 cppu::createSingleComponentFactory,
117 NULL,
120 { NULL }
122 static const char * const kSingleton_names[] =
124 "com.sun.star.configuration.theLogger",
125 NULL
128 //------------------------------------------------------------------------------
130 extern "C" void SAL_CALL component_getImplementationEnvironment(
131 const sal_Char **aEnvTypeName,
132 uno_Environment **aEnvironment) {
133 *aEnvTypeName = CPPU_CURRENT_LANGUAGE_BINDING_NAME ;
135 //------------------------------------------------------------------------------
137 extern "C" sal_Bool SAL_CALL component_writeInfo(void *aServiceManager,
138 void *aRegistryKey) {
139 return component_writeInfoHelper_withSingleton( aServiceManager,
140 aRegistryKey,
141 kImplementations_entries,
142 kSingleton_names) ;
144 //------------------------------------------------------------------------------
146 extern "C" void *component_getFactory(const sal_Char *aImplementationName,
147 void *aServiceManager,
148 void *aRegistryKey) {
149 return cppu::component_getFactoryHelper(aImplementationName,
150 aServiceManager,
151 aRegistryKey,
152 kImplementations_entries) ;
154 //------------------------------------------------------------------------------