xref: /AOO41X/main/framework/source/fwe/classes/actiontriggercontainer.cxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
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.
14  *
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).
20  *
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.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_framework.hxx"
30 #include <classes/actiontriggercontainer.hxx>
31 #include <cppuhelper/typeprovider.hxx>
32 
33 #include <classes/actiontriggerpropertyset.hxx>
34 #include <classes/actiontriggerseparatorpropertyset.hxx>
35 
36 using namespace cppu;
37 using namespace com::sun::star::uno;
38 using namespace com::sun::star::lang;
39 using namespace com::sun::star::container;
40 
41 namespace framework
42 {
43 
44 ActionTriggerContainer::ActionTriggerContainer( const Reference< XMultiServiceFactory >& rServiceManager ) :
45 	PropertySetContainer( rServiceManager )
46 {
47 }
48 
49 
50 ActionTriggerContainer::~ActionTriggerContainer()
51 {
52 }
53 
54 // XInterface
55 Any SAL_CALL ActionTriggerContainer::queryInterface( const Type& aType )
56 throw ( RuntimeException )
57 {
58 	Any a = ::cppu::queryInterface(
59 				aType ,
60 				SAL_STATIC_CAST( XMultiServiceFactory*, this ),
61 				SAL_STATIC_CAST( XServiceInfo* ,  this ));
62 
63 	if( a.hasValue() )
64 	{
65 		return a;
66 	}
67 
68 	return PropertySetContainer::queryInterface( aType );
69 }
70 
71 void ActionTriggerContainer::acquire() throw()
72 {
73 	PropertySetContainer::acquire();
74 }
75 
76 void ActionTriggerContainer::release() throw()
77 {
78 	PropertySetContainer::release();
79 }
80 
81 
82 // XMultiServiceFactory
83 Reference< XInterface > SAL_CALL ActionTriggerContainer::createInstance( const ::rtl::OUString& aServiceSpecifier )
84 throw ( ::com::sun::star::uno::Exception, RuntimeException)
85 {
86 	if ( aServiceSpecifier.equalsAscii( SERVICENAME_ACTIONTRIGGER ))
87 		return (OWeakObject *)( new ActionTriggerPropertySet( m_xServiceManager ));
88 	else if ( aServiceSpecifier.equalsAscii( SERVICENAME_ACTIONTRIGGERCONTAINER ))
89 		return (OWeakObject *)( new ActionTriggerContainer( m_xServiceManager ));
90 	else if ( aServiceSpecifier.equalsAscii( SERVICENAME_ACTIONTRIGGERSEPARATOR ))
91 		return (OWeakObject *)( new ActionTriggerSeparatorPropertySet( m_xServiceManager ));
92 	else
93 		throw com::sun::star::uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Unknown service specifier!" )), (OWeakObject *)this );
94 }
95 
96 
97 Reference< XInterface > SAL_CALL ActionTriggerContainer::createInstanceWithArguments( const ::rtl::OUString& ServiceSpecifier, const Sequence< Any >& /*Arguments*/ )
98 throw ( Exception, RuntimeException)
99 {
100 	return createInstance( ServiceSpecifier );
101 }
102 
103 
104 Sequence< ::rtl::OUString > SAL_CALL ActionTriggerContainer::getAvailableServiceNames()
105 throw ( RuntimeException )
106 {
107 	Sequence< ::rtl::OUString > aSeq( 3 );
108 
109 	aSeq[0] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( SERVICENAME_ACTIONTRIGGER ));
110 	aSeq[1] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( SERVICENAME_ACTIONTRIGGERCONTAINER ));
111 	aSeq[2] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( SERVICENAME_ACTIONTRIGGERSEPARATOR ));
112 
113 	return aSeq;
114 }
115 
116 // XServiceInfo
117 ::rtl::OUString SAL_CALL ActionTriggerContainer::getImplementationName()
118 throw ( RuntimeException )
119 {
120 	return ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( IMPLEMENTATIONNAME_ACTIONTRIGGERCONTAINER ));
121 }
122 
123 sal_Bool SAL_CALL ActionTriggerContainer::supportsService( const ::rtl::OUString& ServiceName )
124 throw ( RuntimeException )
125 {
126 	if ( ServiceName.equalsAscii( SERVICENAME_ACTIONTRIGGERCONTAINER ))
127 		return sal_True;
128 
129 	return sal_False;
130 }
131 
132 Sequence< ::rtl::OUString > SAL_CALL ActionTriggerContainer::getSupportedServiceNames()
133 throw ( RuntimeException )
134 {
135     Sequence< ::rtl::OUString > seqServiceNames( 1 );
136 
137 	seqServiceNames[0] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( SERVICENAME_ACTIONTRIGGERCONTAINER ));
138 	return seqServiceNames;
139 }
140 
141 // XTypeProvider
142 Sequence< Type > SAL_CALL ActionTriggerContainer::getTypes() throw ( RuntimeException )
143 {
144 	// Optimize this method !
145 	// We initialize a static variable only one time. And we don't must use a mutex at every call!
146 	// For the first call; pTypeCollection is NULL - for the second call pTypeCollection is different from NULL!
147 	static ::cppu::OTypeCollection* pTypeCollection = NULL ;
148 
149 	if ( pTypeCollection == NULL )
150 	{
151 		// Ready for multithreading; get global mutex for first call of this method only! see before
152 		osl::MutexGuard aGuard( osl::Mutex::getGlobalMutex() ) ;
153 
154 		// Control these pointer again ... it can be, that another instance will be faster then these!
155 		if ( pTypeCollection == NULL )
156 		{
157 			// Create a static typecollection ...
158 			static ::cppu::OTypeCollection aTypeCollection(
159 						::getCppuType(( const Reference< XMultiServiceFactory	>*)NULL ) ,
160 						::getCppuType(( const Reference< XIndexContainer		>*)NULL ) ,
161 						::getCppuType(( const Reference< XIndexAccess			>*)NULL ) ,
162 						::getCppuType(( const Reference< XIndexReplace			>*)NULL ) ,
163 						::getCppuType(( const Reference< XServiceInfo			>*)NULL ) ,
164 						::getCppuType(( const Reference< XTypeProvider			>*)NULL ) ) ;
165 
166 			// ... and set his address to static pointer!
167 			pTypeCollection = &aTypeCollection ;
168 		}
169 	}
170 
171 	return pTypeCollection->getTypes() ;
172 }
173 
174 Sequence< sal_Int8 > SAL_CALL ActionTriggerContainer::getImplementationId() throw ( RuntimeException )
175 {
176 	// Create one Id for all instances of this class.
177 	// Use ethernet address to do this! (sal_True)
178 
179 	// Optimize this method
180 	// We initialize a static variable only one time. And we don't must use a mutex at every call!
181 	// For the first call; pID is NULL - for the second call pID is different from NULL!
182 	static ::cppu::OImplementationId* pID = NULL ;
183 
184 	if ( pID == NULL )
185 	{
186 		// Ready for multithreading; get global mutex for first call of this method only! see before
187 		osl::MutexGuard aGuard( osl::Mutex::getGlobalMutex() ) ;
188 
189 		// Control these pointer again ... it can be, that another instance will be faster then these!
190 		if ( pID == NULL )
191 		{
192 			// Create a new static ID ...
193 			static ::cppu::OImplementationId aID( sal_False ) ;
194 			// ... and set his address to static pointer!
195 			pID = &aID ;
196 		}
197 	}
198 
199 	return pID->getImplementationId() ;
200 }
201 
202 }
203 
204