1*647a425cSAndrew Rist /**************************************************************
2cdf0e10cSrcweir *
3*647a425cSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one
4*647a425cSAndrew Rist * or more contributor license agreements. See the NOTICE file
5*647a425cSAndrew Rist * distributed with this work for additional information
6*647a425cSAndrew Rist * regarding copyright ownership. The ASF licenses this file
7*647a425cSAndrew Rist * to you under the Apache License, Version 2.0 (the
8*647a425cSAndrew Rist * "License"); you may not use this file except in compliance
9*647a425cSAndrew Rist * with the License. You may obtain a copy of the License at
10cdf0e10cSrcweir *
11*647a425cSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir *
13*647a425cSAndrew Rist * Unless required by applicable law or agreed to in writing,
14*647a425cSAndrew Rist * software distributed under the License is distributed on an
15*647a425cSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*647a425cSAndrew Rist * KIND, either express or implied. See the License for the
17*647a425cSAndrew Rist * specific language governing permissions and limitations
18*647a425cSAndrew Rist * under the License.
19cdf0e10cSrcweir *
20*647a425cSAndrew Rist *************************************************************/
21*647a425cSAndrew Rist
22*647a425cSAndrew Rist
23cdf0e10cSrcweir
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_stoc.hxx"
26cdf0e10cSrcweir
27cdf0e10cSrcweir #include "base.hxx"
28cdf0e10cSrcweir
29cdf0e10cSrcweir namespace stoc_corefl
30cdf0e10cSrcweir {
31cdf0e10cSrcweir
32cdf0e10cSrcweir //==================================================================================================
33cdf0e10cSrcweir class IdlEnumFieldImpl
34cdf0e10cSrcweir : public IdlMemberImpl
35cdf0e10cSrcweir , public XIdlField
36cdf0e10cSrcweir , public XIdlField2
37cdf0e10cSrcweir {
38cdf0e10cSrcweir sal_Int32 _nValue;
39cdf0e10cSrcweir
40cdf0e10cSrcweir public:
IdlEnumFieldImpl(IdlReflectionServiceImpl * pReflection,const OUString & rName,typelib_TypeDescription * pTypeDescr,sal_Int32 nValue)41cdf0e10cSrcweir IdlEnumFieldImpl( IdlReflectionServiceImpl * pReflection, const OUString & rName,
42cdf0e10cSrcweir typelib_TypeDescription * pTypeDescr, sal_Int32 nValue )
43cdf0e10cSrcweir : IdlMemberImpl( pReflection, rName, pTypeDescr, pTypeDescr )
44cdf0e10cSrcweir , _nValue( nValue )
45cdf0e10cSrcweir {}
46cdf0e10cSrcweir virtual ~IdlEnumFieldImpl();
47cdf0e10cSrcweir
48cdf0e10cSrcweir // XInterface
49cdf0e10cSrcweir virtual Any SAL_CALL queryInterface( const Type & rType ) throw(::com::sun::star::uno::RuntimeException);
50cdf0e10cSrcweir virtual void SAL_CALL acquire() throw();
51cdf0e10cSrcweir virtual void SAL_CALL release() throw();
52cdf0e10cSrcweir
53cdf0e10cSrcweir // XTypeProvider
54cdf0e10cSrcweir virtual Sequence< Type > SAL_CALL getTypes() throw (::com::sun::star::uno::RuntimeException);
55cdf0e10cSrcweir virtual Sequence< sal_Int8 > SAL_CALL getImplementationId() throw (::com::sun::star::uno::RuntimeException);
56cdf0e10cSrcweir
57cdf0e10cSrcweir // XIdlMember
58cdf0e10cSrcweir virtual Reference< XIdlClass > SAL_CALL getDeclaringClass() throw(::com::sun::star::uno::RuntimeException);
59cdf0e10cSrcweir virtual OUString SAL_CALL getName() throw(::com::sun::star::uno::RuntimeException);
60cdf0e10cSrcweir // XIdlField
61cdf0e10cSrcweir virtual Reference< XIdlClass > SAL_CALL getType() throw(::com::sun::star::uno::RuntimeException);
62cdf0e10cSrcweir virtual FieldAccessMode SAL_CALL getAccessMode() throw(::com::sun::star::uno::RuntimeException);
63cdf0e10cSrcweir virtual Any SAL_CALL get( const Any & rObj ) throw(::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException);
64cdf0e10cSrcweir 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);
65cdf0e10cSrcweir // XIdlField2: getType, getAccessMode and get are equal to XIdlField
66cdf0e10cSrcweir 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);
67cdf0e10cSrcweir };
68cdf0e10cSrcweir //__________________________________________________________________________________________________
~IdlEnumFieldImpl()69cdf0e10cSrcweir IdlEnumFieldImpl::~IdlEnumFieldImpl()
70cdf0e10cSrcweir {
71cdf0e10cSrcweir }
72cdf0e10cSrcweir
73cdf0e10cSrcweir // XInterface
74cdf0e10cSrcweir //__________________________________________________________________________________________________
queryInterface(const Type & rType)75cdf0e10cSrcweir Any IdlEnumFieldImpl::queryInterface( const Type & rType )
76cdf0e10cSrcweir throw(::com::sun::star::uno::RuntimeException)
77cdf0e10cSrcweir {
78cdf0e10cSrcweir Any aRet( ::cppu::queryInterface( rType,
79cdf0e10cSrcweir static_cast< XIdlField * >( this ),
80cdf0e10cSrcweir static_cast< XIdlField2 * >( this ) ) );
81cdf0e10cSrcweir return (aRet.hasValue() ? aRet : IdlMemberImpl::queryInterface( rType ));
82cdf0e10cSrcweir }
83cdf0e10cSrcweir //__________________________________________________________________________________________________
acquire()84cdf0e10cSrcweir void IdlEnumFieldImpl::acquire() throw()
85cdf0e10cSrcweir {
86cdf0e10cSrcweir IdlMemberImpl::acquire();
87cdf0e10cSrcweir }
88cdf0e10cSrcweir //__________________________________________________________________________________________________
release()89cdf0e10cSrcweir void IdlEnumFieldImpl::release() throw()
90cdf0e10cSrcweir {
91cdf0e10cSrcweir IdlMemberImpl::release();
92cdf0e10cSrcweir }
93cdf0e10cSrcweir
94cdf0e10cSrcweir // XTypeProvider
95cdf0e10cSrcweir //__________________________________________________________________________________________________
getTypes()96cdf0e10cSrcweir Sequence< Type > IdlEnumFieldImpl::getTypes()
97cdf0e10cSrcweir throw (::com::sun::star::uno::RuntimeException)
98cdf0e10cSrcweir {
99cdf0e10cSrcweir static OTypeCollection * s_pTypes = 0;
100cdf0e10cSrcweir if (! s_pTypes)
101cdf0e10cSrcweir {
102cdf0e10cSrcweir MutexGuard aGuard( getMutexAccess() );
103cdf0e10cSrcweir if (! s_pTypes)
104cdf0e10cSrcweir {
105cdf0e10cSrcweir static OTypeCollection s_aTypes(
106cdf0e10cSrcweir ::getCppuType( (const Reference< XIdlField2 > *)0 ),
107cdf0e10cSrcweir ::getCppuType( (const Reference< XIdlField > *)0 ),
108cdf0e10cSrcweir IdlMemberImpl::getTypes() );
109cdf0e10cSrcweir s_pTypes = &s_aTypes;
110cdf0e10cSrcweir }
111cdf0e10cSrcweir }
112cdf0e10cSrcweir return s_pTypes->getTypes();
113cdf0e10cSrcweir }
114cdf0e10cSrcweir //__________________________________________________________________________________________________
getImplementationId()115cdf0e10cSrcweir Sequence< sal_Int8 > IdlEnumFieldImpl::getImplementationId()
116cdf0e10cSrcweir throw (::com::sun::star::uno::RuntimeException)
117cdf0e10cSrcweir {
118cdf0e10cSrcweir static OImplementationId * s_pId = 0;
119cdf0e10cSrcweir if (! s_pId)
120cdf0e10cSrcweir {
121cdf0e10cSrcweir MutexGuard aGuard( getMutexAccess() );
122cdf0e10cSrcweir if (! s_pId)
123cdf0e10cSrcweir {
124cdf0e10cSrcweir static OImplementationId s_aId;
125cdf0e10cSrcweir s_pId = &s_aId;
126cdf0e10cSrcweir }
127cdf0e10cSrcweir }
128cdf0e10cSrcweir return s_pId->getImplementationId();
129cdf0e10cSrcweir }
130cdf0e10cSrcweir
131cdf0e10cSrcweir // XIdlMember
132cdf0e10cSrcweir //__________________________________________________________________________________________________
getDeclaringClass()133cdf0e10cSrcweir Reference< XIdlClass > IdlEnumFieldImpl::getDeclaringClass()
134cdf0e10cSrcweir throw(::com::sun::star::uno::RuntimeException)
135cdf0e10cSrcweir {
136cdf0e10cSrcweir return IdlMemberImpl::getDeclaringClass();
137cdf0e10cSrcweir }
138cdf0e10cSrcweir //__________________________________________________________________________________________________
getName()139cdf0e10cSrcweir OUString IdlEnumFieldImpl::getName()
140cdf0e10cSrcweir throw(::com::sun::star::uno::RuntimeException)
141cdf0e10cSrcweir {
142cdf0e10cSrcweir return IdlMemberImpl::getName();
143cdf0e10cSrcweir }
144cdf0e10cSrcweir
145cdf0e10cSrcweir // XIdlField
146cdf0e10cSrcweir //__________________________________________________________________________________________________
getType()147cdf0e10cSrcweir Reference< XIdlClass > IdlEnumFieldImpl::getType()
148cdf0e10cSrcweir throw(::com::sun::star::uno::RuntimeException)
149cdf0e10cSrcweir {
150cdf0e10cSrcweir return getDeclaringClass();
151cdf0e10cSrcweir }
152cdf0e10cSrcweir //__________________________________________________________________________________________________
getAccessMode()153cdf0e10cSrcweir FieldAccessMode IdlEnumFieldImpl::getAccessMode()
154cdf0e10cSrcweir throw(::com::sun::star::uno::RuntimeException)
155cdf0e10cSrcweir {
156cdf0e10cSrcweir return FieldAccessMode_READONLY;
157cdf0e10cSrcweir }
158cdf0e10cSrcweir //__________________________________________________________________________________________________
get(const Any &)159cdf0e10cSrcweir Any IdlEnumFieldImpl::get( const Any & )
160cdf0e10cSrcweir throw(::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException)
161cdf0e10cSrcweir {
162cdf0e10cSrcweir return Any( &_nValue, getTypeDescr() );
163cdf0e10cSrcweir }
164cdf0e10cSrcweir //__________________________________________________________________________________________________
set(const Any &,const Any &)165cdf0e10cSrcweir void IdlEnumFieldImpl::set( const Any &, const Any & )
166cdf0e10cSrcweir throw(::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::lang::IllegalAccessException, ::com::sun::star::uno::RuntimeException)
167cdf0e10cSrcweir {
168cdf0e10cSrcweir throw IllegalAccessException(
169cdf0e10cSrcweir OUString( RTL_CONSTASCII_USTRINGPARAM("enum field is constant!") ),
170cdf0e10cSrcweir (XWeak *)(OWeakObject *)this );
171cdf0e10cSrcweir }
172cdf0e10cSrcweir //__________________________________________________________________________________________________
set(Any &,const Any &)173cdf0e10cSrcweir void IdlEnumFieldImpl::set( Any &, const Any & )
174cdf0e10cSrcweir throw(::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::lang::IllegalAccessException, ::com::sun::star::uno::RuntimeException)
175cdf0e10cSrcweir {
176cdf0e10cSrcweir throw IllegalAccessException(
177cdf0e10cSrcweir OUString( RTL_CONSTASCII_USTRINGPARAM("enum field is constant!") ),
178cdf0e10cSrcweir (XWeak *)(OWeakObject *)this );
179cdf0e10cSrcweir }
180cdf0e10cSrcweir
181cdf0e10cSrcweir //##################################################################################################
182cdf0e10cSrcweir //##################################################################################################
183cdf0e10cSrcweir //##################################################################################################
184cdf0e10cSrcweir
185cdf0e10cSrcweir
186cdf0e10cSrcweir //__________________________________________________________________________________________________
~EnumIdlClassImpl()187cdf0e10cSrcweir EnumIdlClassImpl::~EnumIdlClassImpl()
188cdf0e10cSrcweir {
189cdf0e10cSrcweir delete _pFields;
190cdf0e10cSrcweir }
191cdf0e10cSrcweir
192cdf0e10cSrcweir // IdlClassImpl modifications
193cdf0e10cSrcweir //__________________________________________________________________________________________________
getField(const OUString & rName)194cdf0e10cSrcweir Reference< XIdlField > EnumIdlClassImpl::getField( const OUString & rName )
195cdf0e10cSrcweir throw(::com::sun::star::uno::RuntimeException)
196cdf0e10cSrcweir {
197cdf0e10cSrcweir if (! _pFields)
198cdf0e10cSrcweir getFields(); // init members
199cdf0e10cSrcweir
200cdf0e10cSrcweir const OUString2Field::const_iterator iFind( _aName2Field.find( rName ) );
201cdf0e10cSrcweir if (iFind != _aName2Field.end())
202cdf0e10cSrcweir return (*iFind).second;
203cdf0e10cSrcweir else
204cdf0e10cSrcweir return Reference< XIdlField >();
205cdf0e10cSrcweir }
206cdf0e10cSrcweir //__________________________________________________________________________________________________
getFields()207cdf0e10cSrcweir Sequence< Reference< XIdlField > > EnumIdlClassImpl::getFields()
208cdf0e10cSrcweir throw(::com::sun::star::uno::RuntimeException)
209cdf0e10cSrcweir {
210cdf0e10cSrcweir if (! _pFields)
211cdf0e10cSrcweir {
212cdf0e10cSrcweir MutexGuard aGuard( getMutexAccess() );
213cdf0e10cSrcweir if (! _pFields)
214cdf0e10cSrcweir {
215cdf0e10cSrcweir sal_Int32 nFields = getTypeDescr()->nEnumValues;
216cdf0e10cSrcweir Sequence< Reference< XIdlField > > * pFields =
217cdf0e10cSrcweir new Sequence< Reference< XIdlField > >( nFields );
218cdf0e10cSrcweir Reference< XIdlField > * pSeq = pFields->getArray();
219cdf0e10cSrcweir
220cdf0e10cSrcweir while (nFields--)
221cdf0e10cSrcweir {
222cdf0e10cSrcweir OUString aName( getTypeDescr()->ppEnumNames[nFields] );
223cdf0e10cSrcweir _aName2Field[aName] = pSeq[nFields] = new IdlEnumFieldImpl(
224cdf0e10cSrcweir getReflection(), aName, IdlClassImpl::getTypeDescr(), getTypeDescr()->pEnumValues[nFields] );
225cdf0e10cSrcweir }
226cdf0e10cSrcweir
227cdf0e10cSrcweir _pFields = pFields;
228cdf0e10cSrcweir }
229cdf0e10cSrcweir }
230cdf0e10cSrcweir return *_pFields;
231cdf0e10cSrcweir }
232cdf0e10cSrcweir //__________________________________________________________________________________________________
createObject(Any & rObj)233cdf0e10cSrcweir void EnumIdlClassImpl::createObject( Any & rObj )
234cdf0e10cSrcweir throw(::com::sun::star::uno::RuntimeException)
235cdf0e10cSrcweir {
236cdf0e10cSrcweir sal_Int32 eVal =
237cdf0e10cSrcweir ((typelib_EnumTypeDescription *)IdlClassImpl::getTypeDescr())->nDefaultEnumValue;
238cdf0e10cSrcweir rObj.setValue( &eVal, IdlClassImpl::getTypeDescr() );
239cdf0e10cSrcweir }
240cdf0e10cSrcweir
241cdf0e10cSrcweir }
242cdf0e10cSrcweir
243cdf0e10cSrcweir
244