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 40 ActionTriggerContainer::ActionTriggerContainer( const Reference< XMultiServiceFactory >& rServiceManager ) : 41 PropertySetContainer( rServiceManager ) 42 { 43 } 44 45 46 ActionTriggerContainer::~ActionTriggerContainer() 47 { 48 } 49 50 // XInterface 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 59 if( a.hasValue() ) 60 { 61 return a; 62 } 63 64 return PropertySetContainer::queryInterface( aType ); 65 } 66 67 void ActionTriggerContainer::acquire() throw() 68 { 69 PropertySetContainer::acquire(); 70 } 71 72 void ActionTriggerContainer::release() throw() 73 { 74 PropertySetContainer::release(); 75 } 76 77 78 // XMultiServiceFactory 79 Reference< XInterface > SAL_CALL ActionTriggerContainer::createInstance( const ::rtl::OUString& aServiceSpecifier ) 80 throw ( ::com::sun::star::uno::Exception, RuntimeException) 81 { 82 if ( aServiceSpecifier.equalsAscii( SERVICENAME_ACTIONTRIGGER )) 83 return (OWeakObject *)( new ActionTriggerPropertySet( m_xServiceManager )); 84 else if ( aServiceSpecifier.equalsAscii( SERVICENAME_ACTIONTRIGGERCONTAINER )) 85 return (OWeakObject *)( new ActionTriggerContainer( m_xServiceManager )); 86 else if ( aServiceSpecifier.equalsAscii( SERVICENAME_ACTIONTRIGGERSEPARATOR )) 87 return (OWeakObject *)( new ActionTriggerSeparatorPropertySet( m_xServiceManager )); 88 else 89 throw com::sun::star::uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Unknown service specifier!" )), (OWeakObject *)this ); 90 } 91 92 93 Reference< XInterface > SAL_CALL ActionTriggerContainer::createInstanceWithArguments( const ::rtl::OUString& ServiceSpecifier, const Sequence< Any >& /*Arguments*/ ) 94 throw ( Exception, RuntimeException) 95 { 96 return createInstance( ServiceSpecifier ); 97 } 98 99 100 Sequence< ::rtl::OUString > SAL_CALL ActionTriggerContainer::getAvailableServiceNames() 101 throw ( RuntimeException ) 102 { 103 Sequence< ::rtl::OUString > aSeq( 3 ); 104 105 aSeq[0] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( SERVICENAME_ACTIONTRIGGER )); 106 aSeq[1] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( SERVICENAME_ACTIONTRIGGERCONTAINER )); 107 aSeq[2] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( SERVICENAME_ACTIONTRIGGERSEPARATOR )); 108 109 return aSeq; 110 } 111 112 // XServiceInfo 113 ::rtl::OUString SAL_CALL ActionTriggerContainer::getImplementationName() 114 throw ( RuntimeException ) 115 { 116 return ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( IMPLEMENTATIONNAME_ACTIONTRIGGERCONTAINER )); 117 } 118 119 sal_Bool SAL_CALL ActionTriggerContainer::supportsService( const ::rtl::OUString& ServiceName ) 120 throw ( RuntimeException ) 121 { 122 if ( ServiceName.equalsAscii( SERVICENAME_ACTIONTRIGGERCONTAINER )) 123 return sal_True; 124 125 return sal_False; 126 } 127 128 Sequence< ::rtl::OUString > SAL_CALL ActionTriggerContainer::getSupportedServiceNames() 129 throw ( RuntimeException ) 130 { 131 Sequence< ::rtl::OUString > seqServiceNames( 1 ); 132 133 seqServiceNames[0] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( SERVICENAME_ACTIONTRIGGERCONTAINER )); 134 return seqServiceNames; 135 } 136 137 // XTypeProvider 138 Sequence< Type > SAL_CALL ActionTriggerContainer::getTypes() throw ( RuntimeException ) 139 { 140 // Optimize this method ! 141 // We initialize a static variable only one time. And we don't must use a mutex at every call! 142 // For the first call; pTypeCollection is NULL - for the second call pTypeCollection is different from NULL! 143 static ::cppu::OTypeCollection* pTypeCollection = NULL ; 144 145 if ( pTypeCollection == NULL ) 146 { 147 // Ready for multithreading; get global mutex for first call of this method only! see before 148 osl::MutexGuard aGuard( osl::Mutex::getGlobalMutex() ) ; 149 150 // Control these pointer again ... it can be, that another instance will be faster then these! 151 if ( pTypeCollection == NULL ) 152 { 153 // Create a static typecollection ... 154 static ::cppu::OTypeCollection aTypeCollection( 155 ::getCppuType(( const Reference< XMultiServiceFactory >*)NULL ) , 156 ::getCppuType(( const Reference< XIndexContainer >*)NULL ) , 157 ::getCppuType(( const Reference< XIndexAccess >*)NULL ) , 158 ::getCppuType(( const Reference< XIndexReplace >*)NULL ) , 159 ::getCppuType(( const Reference< XServiceInfo >*)NULL ) , 160 ::getCppuType(( const Reference< XTypeProvider >*)NULL ) ) ; 161 162 // ... and set his address to static pointer! 163 pTypeCollection = &aTypeCollection ; 164 } 165 } 166 167 return pTypeCollection->getTypes() ; 168 } 169 170 Sequence< sal_Int8 > SAL_CALL ActionTriggerContainer::getImplementationId() throw ( RuntimeException ) 171 { 172 // Create one Id for all instances of this class. 173 // Use ethernet address to do this! (sal_True) 174 175 // Optimize this method 176 // We initialize a static variable only one time. And we don't must use a mutex at every call! 177 // For the first call; pID is NULL - for the second call pID is different from NULL! 178 static ::cppu::OImplementationId* pID = NULL ; 179 180 if ( pID == NULL ) 181 { 182 // Ready for multithreading; get global mutex for first call of this method only! see before 183 osl::MutexGuard aGuard( osl::Mutex::getGlobalMutex() ) ; 184 185 // Control these pointer again ... it can be, that another instance will be faster then these! 186 if ( pID == NULL ) 187 { 188 // Create a new static ID ... 189 static ::cppu::OImplementationId aID( sal_False ) ; 190 // ... and set his address to static pointer! 191 pID = &aID ; 192 } 193 } 194 195 return pID->getImplementationId() ; 196 } 197 198 } 199 200