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_stoc.hxx" 30 31 #include "base.hxx" 32 33 namespace stoc_corefl 34 { 35 36 //================================================================================================== 37 class IdlEnumFieldImpl 38 : public IdlMemberImpl 39 , public XIdlField 40 , public XIdlField2 41 { 42 sal_Int32 _nValue; 43 44 public: 45 IdlEnumFieldImpl( IdlReflectionServiceImpl * pReflection, const OUString & rName, 46 typelib_TypeDescription * pTypeDescr, sal_Int32 nValue ) 47 : IdlMemberImpl( pReflection, rName, pTypeDescr, pTypeDescr ) 48 , _nValue( nValue ) 49 {} 50 virtual ~IdlEnumFieldImpl(); 51 52 // XInterface 53 virtual Any SAL_CALL queryInterface( const Type & rType ) throw(::com::sun::star::uno::RuntimeException); 54 virtual void SAL_CALL acquire() throw(); 55 virtual void SAL_CALL release() throw(); 56 57 // XTypeProvider 58 virtual Sequence< Type > SAL_CALL getTypes() throw (::com::sun::star::uno::RuntimeException); 59 virtual Sequence< sal_Int8 > SAL_CALL getImplementationId() throw (::com::sun::star::uno::RuntimeException); 60 61 // XIdlMember 62 virtual Reference< XIdlClass > SAL_CALL getDeclaringClass() throw(::com::sun::star::uno::RuntimeException); 63 virtual OUString SAL_CALL getName() throw(::com::sun::star::uno::RuntimeException); 64 // XIdlField 65 virtual Reference< XIdlClass > SAL_CALL getType() throw(::com::sun::star::uno::RuntimeException); 66 virtual FieldAccessMode SAL_CALL getAccessMode() throw(::com::sun::star::uno::RuntimeException); 67 virtual Any SAL_CALL get( const Any & rObj ) throw(::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException); 68 virtual void SAL_CALL set( const Any & rObj, const Any & rValue ) throw(::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::lang::IllegalAccessException, ::com::sun::star::uno::RuntimeException); 69 // XIdlField2: getType, getAccessMode and get are equal to XIdlField 70 virtual void SAL_CALL set( Any & rObj, const Any & rValue ) throw(::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::lang::IllegalAccessException, ::com::sun::star::uno::RuntimeException); 71 }; 72 //__________________________________________________________________________________________________ 73 IdlEnumFieldImpl::~IdlEnumFieldImpl() 74 { 75 } 76 77 // XInterface 78 //__________________________________________________________________________________________________ 79 Any IdlEnumFieldImpl::queryInterface( const Type & rType ) 80 throw(::com::sun::star::uno::RuntimeException) 81 { 82 Any aRet( ::cppu::queryInterface( rType, 83 static_cast< XIdlField * >( this ), 84 static_cast< XIdlField2 * >( this ) ) ); 85 return (aRet.hasValue() ? aRet : IdlMemberImpl::queryInterface( rType )); 86 } 87 //__________________________________________________________________________________________________ 88 void IdlEnumFieldImpl::acquire() throw() 89 { 90 IdlMemberImpl::acquire(); 91 } 92 //__________________________________________________________________________________________________ 93 void IdlEnumFieldImpl::release() throw() 94 { 95 IdlMemberImpl::release(); 96 } 97 98 // XTypeProvider 99 //__________________________________________________________________________________________________ 100 Sequence< Type > IdlEnumFieldImpl::getTypes() 101 throw (::com::sun::star::uno::RuntimeException) 102 { 103 static OTypeCollection * s_pTypes = 0; 104 if (! s_pTypes) 105 { 106 MutexGuard aGuard( getMutexAccess() ); 107 if (! s_pTypes) 108 { 109 static OTypeCollection s_aTypes( 110 ::getCppuType( (const Reference< XIdlField2 > *)0 ), 111 ::getCppuType( (const Reference< XIdlField > *)0 ), 112 IdlMemberImpl::getTypes() ); 113 s_pTypes = &s_aTypes; 114 } 115 } 116 return s_pTypes->getTypes(); 117 } 118 //__________________________________________________________________________________________________ 119 Sequence< sal_Int8 > IdlEnumFieldImpl::getImplementationId() 120 throw (::com::sun::star::uno::RuntimeException) 121 { 122 static OImplementationId * s_pId = 0; 123 if (! s_pId) 124 { 125 MutexGuard aGuard( getMutexAccess() ); 126 if (! s_pId) 127 { 128 static OImplementationId s_aId; 129 s_pId = &s_aId; 130 } 131 } 132 return s_pId->getImplementationId(); 133 } 134 135 // XIdlMember 136 //__________________________________________________________________________________________________ 137 Reference< XIdlClass > IdlEnumFieldImpl::getDeclaringClass() 138 throw(::com::sun::star::uno::RuntimeException) 139 { 140 return IdlMemberImpl::getDeclaringClass(); 141 } 142 //__________________________________________________________________________________________________ 143 OUString IdlEnumFieldImpl::getName() 144 throw(::com::sun::star::uno::RuntimeException) 145 { 146 return IdlMemberImpl::getName(); 147 } 148 149 // XIdlField 150 //__________________________________________________________________________________________________ 151 Reference< XIdlClass > IdlEnumFieldImpl::getType() 152 throw(::com::sun::star::uno::RuntimeException) 153 { 154 return getDeclaringClass(); 155 } 156 //__________________________________________________________________________________________________ 157 FieldAccessMode IdlEnumFieldImpl::getAccessMode() 158 throw(::com::sun::star::uno::RuntimeException) 159 { 160 return FieldAccessMode_READONLY; 161 } 162 //__________________________________________________________________________________________________ 163 Any IdlEnumFieldImpl::get( const Any & ) 164 throw(::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException) 165 { 166 return Any( &_nValue, getTypeDescr() ); 167 } 168 //__________________________________________________________________________________________________ 169 void IdlEnumFieldImpl::set( const Any &, const Any & ) 170 throw(::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::lang::IllegalAccessException, ::com::sun::star::uno::RuntimeException) 171 { 172 throw IllegalAccessException( 173 OUString( RTL_CONSTASCII_USTRINGPARAM("enum field is constant!") ), 174 (XWeak *)(OWeakObject *)this ); 175 } 176 //__________________________________________________________________________________________________ 177 void IdlEnumFieldImpl::set( Any &, const Any & ) 178 throw(::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::lang::IllegalAccessException, ::com::sun::star::uno::RuntimeException) 179 { 180 throw IllegalAccessException( 181 OUString( RTL_CONSTASCII_USTRINGPARAM("enum field is constant!") ), 182 (XWeak *)(OWeakObject *)this ); 183 } 184 185 //################################################################################################## 186 //################################################################################################## 187 //################################################################################################## 188 189 190 //__________________________________________________________________________________________________ 191 EnumIdlClassImpl::~EnumIdlClassImpl() 192 { 193 delete _pFields; 194 } 195 196 // IdlClassImpl modifications 197 //__________________________________________________________________________________________________ 198 Reference< XIdlField > EnumIdlClassImpl::getField( const OUString & rName ) 199 throw(::com::sun::star::uno::RuntimeException) 200 { 201 if (! _pFields) 202 getFields(); // init members 203 204 const OUString2Field::const_iterator iFind( _aName2Field.find( rName ) ); 205 if (iFind != _aName2Field.end()) 206 return (*iFind).second; 207 else 208 return Reference< XIdlField >(); 209 } 210 //__________________________________________________________________________________________________ 211 Sequence< Reference< XIdlField > > EnumIdlClassImpl::getFields() 212 throw(::com::sun::star::uno::RuntimeException) 213 { 214 if (! _pFields) 215 { 216 MutexGuard aGuard( getMutexAccess() ); 217 if (! _pFields) 218 { 219 sal_Int32 nFields = getTypeDescr()->nEnumValues; 220 Sequence< Reference< XIdlField > > * pFields = 221 new Sequence< Reference< XIdlField > >( nFields ); 222 Reference< XIdlField > * pSeq = pFields->getArray(); 223 224 while (nFields--) 225 { 226 OUString aName( getTypeDescr()->ppEnumNames[nFields] ); 227 _aName2Field[aName] = pSeq[nFields] = new IdlEnumFieldImpl( 228 getReflection(), aName, IdlClassImpl::getTypeDescr(), getTypeDescr()->pEnumValues[nFields] ); 229 } 230 231 _pFields = pFields; 232 } 233 } 234 return *_pFields; 235 } 236 //__________________________________________________________________________________________________ 237 void EnumIdlClassImpl::createObject( Any & rObj ) 238 throw(::com::sun::star::uno::RuntimeException) 239 { 240 sal_Int32 eVal = 241 ((typelib_EnumTypeDescription *)IdlClassImpl::getTypeDescr())->nDefaultEnumValue; 242 rObj.setValue( &eVal, IdlClassImpl::getTypeDescr() ); 243 } 244 245 } 246 247 248