xref: /AOO41X/main/stoc/source/corereflection/crenum.cxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
29*cdf0e10cSrcweir #include "precompiled_stoc.hxx"
30*cdf0e10cSrcweir 
31*cdf0e10cSrcweir #include "base.hxx"
32*cdf0e10cSrcweir 
33*cdf0e10cSrcweir namespace stoc_corefl
34*cdf0e10cSrcweir {
35*cdf0e10cSrcweir 
36*cdf0e10cSrcweir //==================================================================================================
37*cdf0e10cSrcweir class IdlEnumFieldImpl
38*cdf0e10cSrcweir 	: public IdlMemberImpl
39*cdf0e10cSrcweir 	, public XIdlField
40*cdf0e10cSrcweir 	, public XIdlField2
41*cdf0e10cSrcweir {
42*cdf0e10cSrcweir 	sal_Int32				_nValue;
43*cdf0e10cSrcweir 
44*cdf0e10cSrcweir public:
45*cdf0e10cSrcweir 	IdlEnumFieldImpl( IdlReflectionServiceImpl * pReflection, const OUString & rName,
46*cdf0e10cSrcweir 					  typelib_TypeDescription * pTypeDescr, sal_Int32 nValue )
47*cdf0e10cSrcweir 		: IdlMemberImpl( pReflection, rName, pTypeDescr, pTypeDescr )
48*cdf0e10cSrcweir 		, _nValue( nValue )
49*cdf0e10cSrcweir 		{}
50*cdf0e10cSrcweir 	virtual ~IdlEnumFieldImpl();
51*cdf0e10cSrcweir 
52*cdf0e10cSrcweir 	// XInterface
53*cdf0e10cSrcweir 	virtual Any SAL_CALL queryInterface( const Type & rType ) throw(::com::sun::star::uno::RuntimeException);
54*cdf0e10cSrcweir 	virtual void SAL_CALL acquire() throw();
55*cdf0e10cSrcweir 	virtual void SAL_CALL release() throw();
56*cdf0e10cSrcweir 
57*cdf0e10cSrcweir 	// XTypeProvider
58*cdf0e10cSrcweir 	virtual Sequence< Type > SAL_CALL getTypes() throw (::com::sun::star::uno::RuntimeException);
59*cdf0e10cSrcweir 	virtual Sequence< sal_Int8 > SAL_CALL getImplementationId() throw (::com::sun::star::uno::RuntimeException);
60*cdf0e10cSrcweir 
61*cdf0e10cSrcweir 	// XIdlMember
62*cdf0e10cSrcweir     virtual Reference< XIdlClass > SAL_CALL getDeclaringClass() throw(::com::sun::star::uno::RuntimeException);
63*cdf0e10cSrcweir     virtual OUString SAL_CALL getName() throw(::com::sun::star::uno::RuntimeException);
64*cdf0e10cSrcweir 	// XIdlField
65*cdf0e10cSrcweir     virtual Reference< XIdlClass > SAL_CALL getType() throw(::com::sun::star::uno::RuntimeException);
66*cdf0e10cSrcweir     virtual FieldAccessMode SAL_CALL getAccessMode() throw(::com::sun::star::uno::RuntimeException);
67*cdf0e10cSrcweir     virtual Any SAL_CALL get( const Any & rObj ) throw(::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException);
68*cdf0e10cSrcweir     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*cdf0e10cSrcweir 	// XIdlField2: getType, getAccessMode and get are equal to XIdlField
70*cdf0e10cSrcweir     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*cdf0e10cSrcweir };
72*cdf0e10cSrcweir //__________________________________________________________________________________________________
73*cdf0e10cSrcweir IdlEnumFieldImpl::~IdlEnumFieldImpl()
74*cdf0e10cSrcweir {
75*cdf0e10cSrcweir }
76*cdf0e10cSrcweir 
77*cdf0e10cSrcweir // XInterface
78*cdf0e10cSrcweir //__________________________________________________________________________________________________
79*cdf0e10cSrcweir Any IdlEnumFieldImpl::queryInterface( const Type & rType )
80*cdf0e10cSrcweir 	throw(::com::sun::star::uno::RuntimeException)
81*cdf0e10cSrcweir {
82*cdf0e10cSrcweir 	Any aRet( ::cppu::queryInterface( rType,
83*cdf0e10cSrcweir     								  static_cast< XIdlField * >( this ),
84*cdf0e10cSrcweir                                       static_cast< XIdlField2 * >( this ) ) );
85*cdf0e10cSrcweir 	return (aRet.hasValue() ? aRet : IdlMemberImpl::queryInterface( rType ));
86*cdf0e10cSrcweir }
87*cdf0e10cSrcweir //__________________________________________________________________________________________________
88*cdf0e10cSrcweir void IdlEnumFieldImpl::acquire() throw()
89*cdf0e10cSrcweir {
90*cdf0e10cSrcweir 	IdlMemberImpl::acquire();
91*cdf0e10cSrcweir }
92*cdf0e10cSrcweir //__________________________________________________________________________________________________
93*cdf0e10cSrcweir void IdlEnumFieldImpl::release() throw()
94*cdf0e10cSrcweir {
95*cdf0e10cSrcweir 	IdlMemberImpl::release();
96*cdf0e10cSrcweir }
97*cdf0e10cSrcweir 
98*cdf0e10cSrcweir // XTypeProvider
99*cdf0e10cSrcweir //__________________________________________________________________________________________________
100*cdf0e10cSrcweir Sequence< Type > IdlEnumFieldImpl::getTypes()
101*cdf0e10cSrcweir 	throw (::com::sun::star::uno::RuntimeException)
102*cdf0e10cSrcweir {
103*cdf0e10cSrcweir 	static OTypeCollection * s_pTypes = 0;
104*cdf0e10cSrcweir 	if (! s_pTypes)
105*cdf0e10cSrcweir 	{
106*cdf0e10cSrcweir 		MutexGuard aGuard( getMutexAccess() );
107*cdf0e10cSrcweir 		if (! s_pTypes)
108*cdf0e10cSrcweir 		{
109*cdf0e10cSrcweir 			static OTypeCollection s_aTypes(
110*cdf0e10cSrcweir 				::getCppuType( (const Reference< XIdlField2 > *)0 ),
111*cdf0e10cSrcweir 				::getCppuType( (const Reference< XIdlField > *)0 ),
112*cdf0e10cSrcweir 				IdlMemberImpl::getTypes() );
113*cdf0e10cSrcweir 			s_pTypes = &s_aTypes;
114*cdf0e10cSrcweir 		}
115*cdf0e10cSrcweir 	}
116*cdf0e10cSrcweir 	return s_pTypes->getTypes();
117*cdf0e10cSrcweir }
118*cdf0e10cSrcweir //__________________________________________________________________________________________________
119*cdf0e10cSrcweir Sequence< sal_Int8 > IdlEnumFieldImpl::getImplementationId()
120*cdf0e10cSrcweir 	throw (::com::sun::star::uno::RuntimeException)
121*cdf0e10cSrcweir {
122*cdf0e10cSrcweir 	static OImplementationId * s_pId = 0;
123*cdf0e10cSrcweir 	if (! s_pId)
124*cdf0e10cSrcweir 	{
125*cdf0e10cSrcweir 		MutexGuard aGuard( getMutexAccess() );
126*cdf0e10cSrcweir 		if (! s_pId)
127*cdf0e10cSrcweir 		{
128*cdf0e10cSrcweir 			static OImplementationId s_aId;
129*cdf0e10cSrcweir 			s_pId = &s_aId;
130*cdf0e10cSrcweir 		}
131*cdf0e10cSrcweir 	}
132*cdf0e10cSrcweir 	return s_pId->getImplementationId();
133*cdf0e10cSrcweir }
134*cdf0e10cSrcweir 
135*cdf0e10cSrcweir // XIdlMember
136*cdf0e10cSrcweir //__________________________________________________________________________________________________
137*cdf0e10cSrcweir Reference< XIdlClass > IdlEnumFieldImpl::getDeclaringClass()
138*cdf0e10cSrcweir 	throw(::com::sun::star::uno::RuntimeException)
139*cdf0e10cSrcweir {
140*cdf0e10cSrcweir 	return IdlMemberImpl::getDeclaringClass();
141*cdf0e10cSrcweir }
142*cdf0e10cSrcweir //__________________________________________________________________________________________________
143*cdf0e10cSrcweir OUString IdlEnumFieldImpl::getName()
144*cdf0e10cSrcweir 	throw(::com::sun::star::uno::RuntimeException)
145*cdf0e10cSrcweir {
146*cdf0e10cSrcweir 	return IdlMemberImpl::getName();
147*cdf0e10cSrcweir }
148*cdf0e10cSrcweir 
149*cdf0e10cSrcweir // XIdlField
150*cdf0e10cSrcweir //__________________________________________________________________________________________________
151*cdf0e10cSrcweir Reference< XIdlClass > IdlEnumFieldImpl::getType()
152*cdf0e10cSrcweir 	throw(::com::sun::star::uno::RuntimeException)
153*cdf0e10cSrcweir {
154*cdf0e10cSrcweir 	return getDeclaringClass();
155*cdf0e10cSrcweir }
156*cdf0e10cSrcweir //__________________________________________________________________________________________________
157*cdf0e10cSrcweir FieldAccessMode IdlEnumFieldImpl::getAccessMode()
158*cdf0e10cSrcweir 	throw(::com::sun::star::uno::RuntimeException)
159*cdf0e10cSrcweir {
160*cdf0e10cSrcweir     return FieldAccessMode_READONLY;
161*cdf0e10cSrcweir }
162*cdf0e10cSrcweir //__________________________________________________________________________________________________
163*cdf0e10cSrcweir Any IdlEnumFieldImpl::get( const Any & )
164*cdf0e10cSrcweir 	throw(::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException)
165*cdf0e10cSrcweir {
166*cdf0e10cSrcweir 	return Any( &_nValue, getTypeDescr() );
167*cdf0e10cSrcweir }
168*cdf0e10cSrcweir //__________________________________________________________________________________________________
169*cdf0e10cSrcweir void IdlEnumFieldImpl::set( const Any &, const Any & )
170*cdf0e10cSrcweir 	throw(::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::lang::IllegalAccessException, ::com::sun::star::uno::RuntimeException)
171*cdf0e10cSrcweir {
172*cdf0e10cSrcweir 	throw IllegalAccessException(
173*cdf0e10cSrcweir 		OUString( RTL_CONSTASCII_USTRINGPARAM("enum field is constant!") ),
174*cdf0e10cSrcweir 		(XWeak *)(OWeakObject *)this );
175*cdf0e10cSrcweir }
176*cdf0e10cSrcweir //__________________________________________________________________________________________________
177*cdf0e10cSrcweir void IdlEnumFieldImpl::set( Any &, const Any & )
178*cdf0e10cSrcweir 	throw(::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::lang::IllegalAccessException, ::com::sun::star::uno::RuntimeException)
179*cdf0e10cSrcweir {
180*cdf0e10cSrcweir 	throw IllegalAccessException(
181*cdf0e10cSrcweir 		OUString( RTL_CONSTASCII_USTRINGPARAM("enum field is constant!") ),
182*cdf0e10cSrcweir 		(XWeak *)(OWeakObject *)this );
183*cdf0e10cSrcweir }
184*cdf0e10cSrcweir 
185*cdf0e10cSrcweir //##################################################################################################
186*cdf0e10cSrcweir //##################################################################################################
187*cdf0e10cSrcweir //##################################################################################################
188*cdf0e10cSrcweir 
189*cdf0e10cSrcweir 
190*cdf0e10cSrcweir //__________________________________________________________________________________________________
191*cdf0e10cSrcweir EnumIdlClassImpl::~EnumIdlClassImpl()
192*cdf0e10cSrcweir {
193*cdf0e10cSrcweir 	delete _pFields;
194*cdf0e10cSrcweir }
195*cdf0e10cSrcweir 
196*cdf0e10cSrcweir // IdlClassImpl modifications
197*cdf0e10cSrcweir //__________________________________________________________________________________________________
198*cdf0e10cSrcweir Reference< XIdlField > EnumIdlClassImpl::getField( const OUString & rName )
199*cdf0e10cSrcweir 	throw(::com::sun::star::uno::RuntimeException)
200*cdf0e10cSrcweir {
201*cdf0e10cSrcweir 	if (! _pFields)
202*cdf0e10cSrcweir 		getFields(); // init members
203*cdf0e10cSrcweir 
204*cdf0e10cSrcweir 	const OUString2Field::const_iterator iFind( _aName2Field.find( rName ) );
205*cdf0e10cSrcweir 	if (iFind != _aName2Field.end())
206*cdf0e10cSrcweir 		return (*iFind).second;
207*cdf0e10cSrcweir 	else
208*cdf0e10cSrcweir 		return Reference< XIdlField >();
209*cdf0e10cSrcweir }
210*cdf0e10cSrcweir //__________________________________________________________________________________________________
211*cdf0e10cSrcweir Sequence< Reference< XIdlField > > EnumIdlClassImpl::getFields()
212*cdf0e10cSrcweir 	throw(::com::sun::star::uno::RuntimeException)
213*cdf0e10cSrcweir {
214*cdf0e10cSrcweir 	if (! _pFields)
215*cdf0e10cSrcweir 	{
216*cdf0e10cSrcweir 		MutexGuard aGuard( getMutexAccess() );
217*cdf0e10cSrcweir 		if (! _pFields)
218*cdf0e10cSrcweir 		{
219*cdf0e10cSrcweir 			sal_Int32 nFields = getTypeDescr()->nEnumValues;
220*cdf0e10cSrcweir 			Sequence< Reference< XIdlField > > * pFields =
221*cdf0e10cSrcweir 				new Sequence< Reference< XIdlField > >( nFields );
222*cdf0e10cSrcweir 			Reference< XIdlField > * pSeq = pFields->getArray();
223*cdf0e10cSrcweir 
224*cdf0e10cSrcweir 			while (nFields--)
225*cdf0e10cSrcweir 			{
226*cdf0e10cSrcweir 				OUString aName( getTypeDescr()->ppEnumNames[nFields] );
227*cdf0e10cSrcweir 				_aName2Field[aName] = pSeq[nFields] = new IdlEnumFieldImpl(
228*cdf0e10cSrcweir 					getReflection(), aName, IdlClassImpl::getTypeDescr(), getTypeDescr()->pEnumValues[nFields] );
229*cdf0e10cSrcweir 			}
230*cdf0e10cSrcweir 
231*cdf0e10cSrcweir 			_pFields = pFields;
232*cdf0e10cSrcweir 		}
233*cdf0e10cSrcweir 	}
234*cdf0e10cSrcweir 	return *_pFields;
235*cdf0e10cSrcweir }
236*cdf0e10cSrcweir //__________________________________________________________________________________________________
237*cdf0e10cSrcweir void EnumIdlClassImpl::createObject( Any & rObj )
238*cdf0e10cSrcweir 	throw(::com::sun::star::uno::RuntimeException)
239*cdf0e10cSrcweir {
240*cdf0e10cSrcweir 	sal_Int32 eVal =
241*cdf0e10cSrcweir         ((typelib_EnumTypeDescription *)IdlClassImpl::getTypeDescr())->nDefaultEnumValue;
242*cdf0e10cSrcweir 	rObj.setValue( &eVal, IdlClassImpl::getTypeDescr() );
243*cdf0e10cSrcweir }
244*cdf0e10cSrcweir 
245*cdf0e10cSrcweir }
246*cdf0e10cSrcweir 
247*cdf0e10cSrcweir 
248