1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_framework.hxx"
26 #include <classes/actiontriggercontainer.hxx>
27 #include <cppuhelper/typeprovider.hxx>
28 
29 #include <classes/actiontriggerpropertyset.hxx>
30 #include <classes/actiontriggerseparatorpropertyset.hxx>
31 
32 using namespace cppu;
33 using namespace com::sun::star::uno;
34 using namespace com::sun::star::lang;
35 using namespace com::sun::star::container;
36 
37 namespace framework
38 {
39 
ActionTriggerContainer(const Reference<XMultiServiceFactory> & rServiceManager)40 ActionTriggerContainer::ActionTriggerContainer( const Reference< XMultiServiceFactory >& rServiceManager ) :
41 	PropertySetContainer( rServiceManager )
42 {
43 }
44 
45 
~ActionTriggerContainer()46 ActionTriggerContainer::~ActionTriggerContainer()
47 {
48 }
49 
50 // XInterface
queryInterface(const Type & aType)51 Any SAL_CALL ActionTriggerContainer::queryInterface( const Type& aType )
52 throw ( RuntimeException )
53 {
54 	Any a = ::cppu::queryInterface(
55 				aType ,
56 				SAL_STATIC_CAST( XMultiServiceFactory*, this ),
57 				SAL_STATIC_CAST( XServiceInfo* ,  this ),
58 				SAL_STATIC_CAST( XTypeProvider* ,  this ));
59 
60 	if( a.hasValue() )
61 	{
62 		return a;
63 	}
64 
65 	return PropertySetContainer::queryInterface( aType );
66 }
67 
acquire()68 void ActionTriggerContainer::acquire() throw()
69 {
70 	PropertySetContainer::acquire();
71 }
72 
release()73 void ActionTriggerContainer::release() throw()
74 {
75 	PropertySetContainer::release();
76 }
77 
78 
79 // XMultiServiceFactory
createInstance(const::rtl::OUString & aServiceSpecifier)80 Reference< XInterface > SAL_CALL ActionTriggerContainer::createInstance( const ::rtl::OUString& aServiceSpecifier )
81 throw ( ::com::sun::star::uno::Exception, RuntimeException)
82 {
83 	if ( aServiceSpecifier.equalsAscii( SERVICENAME_ACTIONTRIGGER ))
84 		return (OWeakObject *)( new ActionTriggerPropertySet( m_xServiceManager ));
85 	else if ( aServiceSpecifier.equalsAscii( SERVICENAME_ACTIONTRIGGERCONTAINER ))
86 		return (OWeakObject *)( new ActionTriggerContainer( m_xServiceManager ));
87 	else if ( aServiceSpecifier.equalsAscii( SERVICENAME_ACTIONTRIGGERSEPARATOR ))
88 		return (OWeakObject *)( new ActionTriggerSeparatorPropertySet( m_xServiceManager ));
89 	else
90 		throw com::sun::star::uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Unknown service specifier!" )), (OWeakObject *)this );
91 }
92 
93 
createInstanceWithArguments(const::rtl::OUString & ServiceSpecifier,const Sequence<Any> &)94 Reference< XInterface > SAL_CALL ActionTriggerContainer::createInstanceWithArguments( const ::rtl::OUString& ServiceSpecifier, const Sequence< Any >& /*Arguments*/ )
95 throw ( Exception, RuntimeException)
96 {
97 	return createInstance( ServiceSpecifier );
98 }
99 
100 
getAvailableServiceNames()101 Sequence< ::rtl::OUString > SAL_CALL ActionTriggerContainer::getAvailableServiceNames()
102 throw ( RuntimeException )
103 {
104 	Sequence< ::rtl::OUString > aSeq( 3 );
105 
106 	aSeq[0] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( SERVICENAME_ACTIONTRIGGER ));
107 	aSeq[1] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( SERVICENAME_ACTIONTRIGGERCONTAINER ));
108 	aSeq[2] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( SERVICENAME_ACTIONTRIGGERSEPARATOR ));
109 
110 	return aSeq;
111 }
112 
113 // XServiceInfo
getImplementationName()114 ::rtl::OUString SAL_CALL ActionTriggerContainer::getImplementationName()
115 throw ( RuntimeException )
116 {
117 	return ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( IMPLEMENTATIONNAME_ACTIONTRIGGERCONTAINER ));
118 }
119 
supportsService(const::rtl::OUString & ServiceName)120 sal_Bool SAL_CALL ActionTriggerContainer::supportsService( const ::rtl::OUString& ServiceName )
121 throw ( RuntimeException )
122 {
123 	if ( ServiceName.equalsAscii( SERVICENAME_ACTIONTRIGGERCONTAINER ))
124 		return sal_True;
125 
126 	return sal_False;
127 }
128 
getSupportedServiceNames()129 Sequence< ::rtl::OUString > SAL_CALL ActionTriggerContainer::getSupportedServiceNames()
130 throw ( RuntimeException )
131 {
132     Sequence< ::rtl::OUString > seqServiceNames( 1 );
133 
134 	seqServiceNames[0] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( SERVICENAME_ACTIONTRIGGERCONTAINER ));
135 	return seqServiceNames;
136 }
137 
138 // XTypeProvider
getTypes()139 Sequence< Type > SAL_CALL ActionTriggerContainer::getTypes() throw ( RuntimeException )
140 {
141 	// Optimize this method !
142 	// We initialize a static variable only one time. And we don't must use a mutex at every call!
143 	// For the first call; pTypeCollection is NULL - for the second call pTypeCollection is different from NULL!
144 	static ::cppu::OTypeCollection* pTypeCollection = NULL ;
145 
146 	if ( pTypeCollection == NULL )
147 	{
148 		// Ready for multithreading; get global mutex for first call of this method only! see before
149 		osl::MutexGuard aGuard( osl::Mutex::getGlobalMutex() ) ;
150 
151 		// Control these pointer again ... it can be, that another instance will be faster then these!
152 		if ( pTypeCollection == NULL )
153 		{
154 			// Create a static typecollection ...
155 			static ::cppu::OTypeCollection aTypeCollection(
156 						::getCppuType(( const Reference< XMultiServiceFactory	>*)NULL ) ,
157 						::getCppuType(( const Reference< XIndexContainer		>*)NULL ) ,
158 						::getCppuType(( const Reference< XServiceInfo			>*)NULL ) ,
159 						::getCppuType(( const Reference< XTypeProvider			>*)NULL ) ) ;
160 
161 			// ... and set his address to static pointer!
162 			pTypeCollection = &aTypeCollection ;
163 		}
164 	}
165 
166 	return pTypeCollection->getTypes() ;
167 }
168 
getImplementationId()169 Sequence< sal_Int8 > SAL_CALL ActionTriggerContainer::getImplementationId() throw ( RuntimeException )
170 {
171 	// Create one Id for all instances of this class.
172 	// Use ethernet address to do this! (sal_True)
173 
174 	// Optimize this method
175 	// We initialize a static variable only one time. And we don't must use a mutex at every call!
176 	// For the first call; pID is NULL - for the second call pID is different from NULL!
177 	static ::cppu::OImplementationId* pID = NULL ;
178 
179 	if ( pID == NULL )
180 	{
181 		// Ready for multithreading; get global mutex for first call of this method only! see before
182 		osl::MutexGuard aGuard( osl::Mutex::getGlobalMutex() ) ;
183 
184 		// Control these pointer again ... it can be, that another instance will be faster then these!
185 		if ( pID == NULL )
186 		{
187 			// Create a new static ID ...
188 			static ::cppu::OImplementationId aID( sal_False ) ;
189 			// ... and set his address to static pointer!
190 			pID = &aID ;
191 		}
192 	}
193 
194 	return pID->getImplementationId() ;
195 }
196 
197 }
198 
199