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