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