1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: stdidlclass.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_cppuhelper.hxx"
34 #include <osl/mutex.hxx>
36 #include <cppuhelper/weakref.hxx>
37 #include <cppuhelper/weak.hxx>
38 #include <cppuhelper/stdidlclass.hxx>
40 #include <com/sun/star/reflection/XIdlClassProvider.hpp>
41 #include <com/sun/star/reflection/XIdlReflection.hpp>
42 #include <com/sun/star/uno/XComponentContext.hpp>
43 #include <com/sun/star/uno/DeploymentException.hpp>
44 #include <com/sun/star/beans/XPropertySet.hpp>
46 using namespace com::sun::star
;
47 using namespace com::sun::star::uno
;
48 using namespace com::sun::star::lang
;
49 using namespace com::sun::star::reflection
;
54 /*---------------------------------------------------------
55 * This helper class implements XIdlClass. Is used by
57 *---------------------------------------------------------*/
61 public XIdlClassProvider
65 const Reference
< XMultiServiceFactory
> &rSMgr
,
66 const OUString
& sImplementationName
,
67 const Reference
< XIdlClass
> & rSuperClass
,
68 const Sequence
< OUString
> &seq
72 Any SAL_CALL
queryInterface( const ::com::sun::star::uno::Type
& rType
)
73 throw(::com::sun::star::uno::RuntimeException
);
75 void SAL_CALL
acquire() throw() { OWeakObject::acquire(); }
76 void SAL_CALL
release() throw() { OWeakObject::release(); }
79 Sequence
< Reference
< XIdlClass
> > SAL_CALL
getIdlClasses(void)
80 throw (RuntimeException
);
83 virtual Sequence
< Reference
< XIdlClass
> > SAL_CALL
getClasses( ) throw(RuntimeException
)
84 { return Sequence
< Reference
< XIdlClass
> > (); }
85 virtual Reference
< XIdlClass
> SAL_CALL
getClass( const ::rtl::OUString
& ) throw(RuntimeException
)
86 { return Reference
< XIdlClass
> (); }
87 virtual sal_Bool SAL_CALL
equals( const Reference
< XIdlClass
>& Type
) throw(RuntimeException
)
88 { return getName() == Type
->getName(); }
89 virtual sal_Bool SAL_CALL
isAssignableFrom( const Reference
< XIdlClass
>& xType
) throw(RuntimeException
)
90 { return equals( xType
); }
91 virtual TypeClass SAL_CALL
getTypeClass( ) throw(RuntimeException
)
92 { return TypeClass_UNKNOWN
; }
93 virtual OUString SAL_CALL
getName( ) throw(RuntimeException
)
94 { return m_sImplementationName
; }
95 virtual Uik SAL_CALL
getUik( ) throw(RuntimeException
)
97 virtual Sequence
< Reference
< XIdlClass
> > SAL_CALL
getSuperclasses( ) throw(RuntimeException
)
98 { return m_seqSuperClasses
; }
99 virtual Sequence
< Reference
< XIdlClass
> > SAL_CALL
getInterfaces( ) throw(RuntimeException
);
101 virtual Reference
< XIdlClass
> SAL_CALL
getComponentType( ) throw(RuntimeException
)
102 { return Reference
< XIdlClass
> (); }
103 virtual Reference
< XIdlField
> SAL_CALL
getField( const ::rtl::OUString
& ) throw(RuntimeException
)
104 { return Reference
< XIdlField
> (); }
105 virtual Sequence
< Reference
< XIdlField
> > SAL_CALL
getFields( ) throw(RuntimeException
)
106 { return Sequence
< Reference
< XIdlField
> > (); }
107 virtual Reference
< XIdlMethod
> SAL_CALL
getMethod( const ::rtl::OUString
& ) throw(RuntimeException
)
108 { return Reference
< XIdlMethod
> (); }
109 virtual Sequence
< Reference
< XIdlMethod
> > SAL_CALL
getMethods( ) throw(RuntimeException
)
110 { return Sequence
< Reference
< XIdlMethod
> > (); }
111 virtual Reference
< XIdlArray
> SAL_CALL
getArray( ) throw(RuntimeException
)
112 { return Reference
< XIdlArray
> (); }
113 virtual void SAL_CALL
createObject( Any
& ) throw(RuntimeException
) {}
116 OUString m_sImplementationName
;
117 Sequence
< OUString
> m_seqSupportedInterface
;
118 Sequence
< Reference
< XIdlClass
> > m_seqSuperClasses
;
119 Reference
< XMultiServiceFactory
> m_rSMgr
;
121 Reference
< XIdlReflection
> m_xCorefl
;
122 Reference
< XIdlReflection
> const & get_corefl() SAL_THROW( (RuntimeException
) );
125 Reference
< XIdlReflection
> const & OStdIdlClass::get_corefl()
126 SAL_THROW( (RuntimeException
) )
128 if (! m_xCorefl
.is())
132 Reference
< beans::XPropertySet
> xProps( m_rSMgr
, UNO_QUERY
);
133 OSL_ASSERT( xProps
.is() );
136 Reference
< XComponentContext
> xContext
;
137 xProps
->getPropertyValue(
138 OUString( RTL_CONSTASCII_USTRINGPARAM("DefaultContext") ) ) >>= xContext
;
139 OSL_ASSERT( xContext
.is() );
142 Reference
< XIdlReflection
> x
;
143 xContext
->getValueByName(
144 OUString( RTL_CONSTASCII_USTRINGPARAM("/singletons/com.sun.star.reflection.theCoreReflection") ) ) >>= x
;
145 OSL_ENSURE( x
.is(), "### CoreReflection singleton not accessible!?" );
149 ::osl::MutexGuard
guard( ::osl::Mutex::getGlobalMutex() );
150 if (! m_xCorefl
.is())
158 if (! m_xCorefl
.is())
160 throw DeploymentException(
161 OUString( RTL_CONSTASCII_USTRINGPARAM("/singletons/com.sun.star.reflection.theCoreReflection singleton not accessible") ),
162 Reference
< XInterface
>() );
168 OStdIdlClass::OStdIdlClass(
169 const Reference
< XMultiServiceFactory
> &rSMgr
,
170 const OUString
& sImplementationName
,
171 const Reference
< XIdlClass
> & rSuperClass
,
172 const Sequence
< OUString
> &seq
174 m_sImplementationName( sImplementationName
) ,
175 m_seqSupportedInterface( seq
),
178 if( rSuperClass
.is() )
179 m_seqSuperClasses
= Sequence
< Reference
< XIdlClass
> >( &rSuperClass
, 1 );
183 Any SAL_CALL
OStdIdlClass::queryInterface( const Type
& rType
)
184 throw(::com::sun::star::uno::RuntimeException
)
186 Any
aRet( ::cppu::queryInterface(
187 rType
, static_cast< XIdlClass
* >( this ), static_cast< XIdlClassProvider
* >( this ) ) );
189 return (aRet
.hasValue() ? aRet
: OWeakObject::queryInterface( rType
));
193 Sequence
< Reference
< XIdlClass
> > SAL_CALL
OStdIdlClass::getInterfaces( ) throw(RuntimeException
)
195 int nMax
= m_seqSupportedInterface
.getLength();
197 Reference
< XIdlReflection
> const & rCoreRefl
= get_corefl();
200 Sequence
< Reference
< XIdlClass
> > seqClasses( nMax
);
202 for( int n
= 0 ; n
< nMax
; n
++ )
204 seqClasses
.getArray()[n
] = rCoreRefl
->forName( m_seqSupportedInterface
.getArray()[n
] );
209 return Sequence
< Reference
< XIdlClass
> > () ;
214 Sequence
< Reference
< XIdlClass
> > SAL_CALL
OStdIdlClass::getIdlClasses(void)
215 throw (RuntimeException
)
217 // weak reference to cache the standard class
218 static WeakReference
< XIdlClass
> weakRef
;
220 // try to make weakref hard
221 Reference
< XIdlClass
> r
= weakRef
;
224 // xidlclass has not been initialized before or has been destroyed already.
225 r
= ::cppu::createStandardClass(
227 OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.comp.cppuhelper.OStdIdlClass") ) ,
228 Reference
< XIdlClass
> () ,
229 SAL_STATIC_CAST( XIdlClassProvider
* , this ) ,
230 SAL_STATIC_CAST( XIdlClass
* , this )
233 // store reference for later use
237 return Sequence
< Reference
< XIdlClass
> > ( &r
, 1 );
243 // external constructor
244 XIdlClass
* SAL_CALL
createStandardClassWithSequence(
245 const Reference
< XMultiServiceFactory
> &rSMgr
,
246 const OUString
& sImplementationName
,
247 const Reference
< XIdlClass
> & rSuperClass
,
248 const Sequence
< OUString
> &seqInterfaceNames
)
251 return SAL_STATIC_CAST(
262 } //end namespace cppu