1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
11 * OpenOffice.org is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License version 3
13 * only, as published by the Free Software Foundation.
15 * OpenOffice.org is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License version 3 for more details
19 * (a copy is included in the LICENSE file that accompanied this code).
21 * You should have received a copy of the GNU Lesser General Public License
22 * version 3 along with OpenOffice.org. If not, see
23 * <http://www.openoffice.org/license.html>
24 * for a copy of the LGPLv3 License.
26 ************************************************************************/
27 #ifndef _APPHELPER_SERVICEMACROS_HXX
28 #define _APPHELPER_SERVICEMACROS_HXX
31 to use these macros the supported services and the implementation name needs to be static
32 especially you need to implement (declaration is contained in macro already):
34 static com::sun::star::uno::Sequence< rtl::OUString >
35 Class::getSupportedServiceNames_Static();
38 //=========================================================================
42 //=========================================================================
46 #define APPHELPER_XSERVICEINFO_DECL() \
47 virtual ::rtl::OUString SAL_CALL \
48 getImplementationName() \
49 throw( ::com::sun::star::uno::RuntimeException ); \
50 virtual sal_Bool SAL_CALL \
51 supportsService( const ::rtl::OUString& ServiceName ) \
52 throw( ::com::sun::star::uno::RuntimeException ); \
53 virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL \
54 getSupportedServiceNames() \
55 throw( ::com::sun::star::uno::RuntimeException ); \
57 static ::rtl::OUString getImplementationName_Static(); \
58 static ::com::sun::star::uno::Sequence< ::rtl::OUString > \
59 getSupportedServiceNames_Static();
61 //=========================================================================
65 //=========================================================================
67 #define APPHELPER_XSERVICEINFO_IMPL( Class, ImplName ) \
68 ::rtl::OUString SAL_CALL Class::getImplementationName() \
69 throw( ::com::sun::star::uno::RuntimeException ) \
71 return getImplementationName_Static(); \
74 ::rtl::OUString Class::getImplementationName_Static() \
80 Class::supportsService( const ::rtl::OUString& ServiceName ) \
81 throw( ::com::sun::star::uno::RuntimeException ) \
83 ::com::sun::star::uno::Sequence< ::rtl::OUString > aSNL = \
84 getSupportedServiceNames(); \
85 const ::rtl::OUString* pArray = aSNL.getArray(); \
86 for( sal_Int32 i = 0; i < aSNL.getLength(); i++ ) \
88 if( pArray[ i ] == ServiceName ) \
95 ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL \
96 Class::getSupportedServiceNames() \
97 throw( ::com::sun::star::uno::RuntimeException ) \
99 return getSupportedServiceNames_Static(); \
102 //=========================================================================
104 // Service factory helper decl+impl
106 //to use this macro you need to provide a constructor:
107 //class( Reference< XComponentContext > const & xContext )
108 //and implement OWeakObject
109 //=========================================================================
111 #define APPHELPER_SERVICE_FACTORY_HELPER(Class) \
112 static ::com::sun::star::uno::Reference< \
113 ::com::sun::star::uno::XInterface > SAL_CALL \
114 create( ::com::sun::star::uno::Reference< \
115 ::com::sun::star::uno::XComponentContext > const & xContext) \
116 throw(::com::sun::star::uno::Exception) \
118 return (::cppu::OWeakObject *)new Class( xContext ); \
121 /** This macro contains the default implementation for getImplementationId().
122 Note, that you have to include the header necessary for rtl_createUuid.
123 Insert the following into your file:
126 #include <rtl/uuid.h>
129 @param Class the Class-Name for which getImplementationId() should be
132 #define APPHELPER_GETIMPLEMENTATIONID_IMPL(Class) \
133 ::com::sun::star::uno::Sequence< sal_Int8 > SAL_CALL Class::getImplementationId() \
134 throw (::com::sun::star::uno::RuntimeException) \
136 static ::com::sun::star::uno::Sequence< sal_Int8 > aId; \
137 if( aId.getLength() == 0 ) \
140 rtl_createUuid( (sal_uInt8 *)aId.getArray(), 0, sal_True ); \
145 }//end namespace apphelper