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
10*647a425cSAndrew Rist  *
11*647a425cSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*647a425cSAndrew Rist  *
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.
19*647a425cSAndrew Rist  *
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 "tdmgr_common.hxx"
28cdf0e10cSrcweir #include "rtl/ustrbuf.hxx"
29cdf0e10cSrcweir #include "typelib/typedescription.h"
30cdf0e10cSrcweir #include "com/sun/star/beans/PropertyAttribute.hpp"
31cdf0e10cSrcweir #include "com/sun/star/reflection/XConstantsTypeDescription.hpp"
32cdf0e10cSrcweir #include "com/sun/star/reflection/XIndirectTypeDescription.hpp"
33cdf0e10cSrcweir #include "com/sun/star/reflection/XEnumTypeDescription.hpp"
34cdf0e10cSrcweir #include "com/sun/star/reflection/XStructTypeDescription.hpp"
35cdf0e10cSrcweir #include "com/sun/star/reflection/XInterfaceTypeDescription2.hpp"
36cdf0e10cSrcweir #include "com/sun/star/reflection/XInterfaceMethodTypeDescription.hpp"
37cdf0e10cSrcweir #include "com/sun/star/reflection/XInterfaceAttributeTypeDescription2.hpp"
38cdf0e10cSrcweir #include "com/sun/star/reflection/XServiceTypeDescription2.hpp"
39cdf0e10cSrcweir #include "com/sun/star/reflection/XSingletonTypeDescription2.hpp"
40cdf0e10cSrcweir 
41cdf0e10cSrcweir 
42cdf0e10cSrcweir using ::rtl::OUString;
43cdf0e10cSrcweir using ::rtl::OUStringBuffer;
44cdf0e10cSrcweir using namespace ::com::sun::star;
45cdf0e10cSrcweir using namespace ::com::sun::star::uno;
46cdf0e10cSrcweir using namespace ::stoc_tdmgr;
47cdf0e10cSrcweir 
48cdf0e10cSrcweir namespace {
49cdf0e10cSrcweir 
getTypeClassName(TypeClass tc)50cdf0e10cSrcweir OUString getTypeClassName( TypeClass tc )
51cdf0e10cSrcweir {
52cdf0e10cSrcweir     typelib_EnumTypeDescription * typeDescr = 0;
53cdf0e10cSrcweir     OUString name = OUSTR("com.sun.star.uno.TypeClass");
54cdf0e10cSrcweir     typelib_typedescription_getByName(
55cdf0e10cSrcweir         reinterpret_cast<typelib_TypeDescription **>(&typeDescr), name.pData );
56cdf0e10cSrcweir     OSL_ASSERT( typeDescr != 0 );
57cdf0e10cSrcweir     if (typeDescr == 0)
58cdf0e10cSrcweir         return OUSTR("Cannot get type description of ") + name;
59cdf0e10cSrcweir     typelib_typedescription_complete(
60cdf0e10cSrcweir         reinterpret_cast<typelib_TypeDescription **>(&typeDescr) );
61cdf0e10cSrcweir 
62cdf0e10cSrcweir     sal_Int32 const * pValues = typeDescr->pEnumValues;
63cdf0e10cSrcweir     sal_Int32 nPos = typeDescr->nEnumValues;
64cdf0e10cSrcweir     while (nPos--)
65cdf0e10cSrcweir     {
66cdf0e10cSrcweir         if (pValues[ nPos ] == (sal_Int32) tc)
67cdf0e10cSrcweir             break;
68cdf0e10cSrcweir     }
69cdf0e10cSrcweir     if (nPos >= 0)
70cdf0e10cSrcweir         name = typeDescr->ppEnumNames[ nPos ];
71cdf0e10cSrcweir     else
72cdf0e10cSrcweir         name = OUSTR("unknown TypeClass value: ") +
73cdf0e10cSrcweir             OUString::valueOf( (sal_Int32) tc );
74cdf0e10cSrcweir 
75cdf0e10cSrcweir     typelib_typedescription_release(
76cdf0e10cSrcweir         reinterpret_cast<typelib_TypeDescription *>(typeDescr) );
77cdf0e10cSrcweir     return name;
78cdf0e10cSrcweir }
79cdf0e10cSrcweir 
getPropertyFlagsAsString(sal_Int16 attributes)80cdf0e10cSrcweir OUString getPropertyFlagsAsString( sal_Int16 attributes )
81cdf0e10cSrcweir {
82cdf0e10cSrcweir     OUStringBuffer buf;
83cdf0e10cSrcweir     if ((attributes & beans::PropertyAttribute::MAYBEVOID) != 0)
84cdf0e10cSrcweir         buf.appendAscii( RTL_CONSTASCII_STRINGPARAM("MAYBEVOID, ") );
85cdf0e10cSrcweir     if ((attributes & beans::PropertyAttribute::BOUND) != 0)
86cdf0e10cSrcweir         buf.appendAscii( RTL_CONSTASCII_STRINGPARAM("BOUND, ") );
87cdf0e10cSrcweir     if ((attributes & beans::PropertyAttribute::CONSTRAINED) != 0)
88cdf0e10cSrcweir         buf.appendAscii( RTL_CONSTASCII_STRINGPARAM("CONSTRAINED, ") );
89cdf0e10cSrcweir     if ((attributes & beans::PropertyAttribute::TRANSIENT) != 0)
90cdf0e10cSrcweir         buf.appendAscii( RTL_CONSTASCII_STRINGPARAM("TRANSIENT, ") );
91cdf0e10cSrcweir     if ((attributes & beans::PropertyAttribute::READONLY) != 0)
92cdf0e10cSrcweir         buf.appendAscii( RTL_CONSTASCII_STRINGPARAM("READONLY, ") );
93cdf0e10cSrcweir     if ((attributes & beans::PropertyAttribute::MAYBEAMBIGUOUS) != 0)
94cdf0e10cSrcweir         buf.appendAscii( RTL_CONSTASCII_STRINGPARAM("MAYBEAMBIGUOUS, ") );
95cdf0e10cSrcweir     if ((attributes & beans::PropertyAttribute::MAYBEDEFAULT) != 0)
96cdf0e10cSrcweir         buf.appendAscii( RTL_CONSTASCII_STRINGPARAM("MAYBEDEFAULT, ") );
97cdf0e10cSrcweir     if ((attributes & beans::PropertyAttribute::REMOVEABLE) != 0)
98cdf0e10cSrcweir         buf.appendAscii( RTL_CONSTASCII_STRINGPARAM("REMOVEABLE, ") );
99cdf0e10cSrcweir     if ((attributes & beans::PropertyAttribute::OPTIONAL) != 0)
100cdf0e10cSrcweir         buf.appendAscii( RTL_CONSTASCII_STRINGPARAM("OPTIONAL") );
101cdf0e10cSrcweir     else if (buf.getLength() > 0)
102cdf0e10cSrcweir         buf.setLength( buf.getLength() - 2 ); // truncate ", "
103cdf0e10cSrcweir     return buf.makeStringAndClear();
104cdf0e10cSrcweir }
105cdf0e10cSrcweir 
typeError(OUString const & msg,OUString const & context)106cdf0e10cSrcweir void typeError( OUString const & msg, OUString const & context )
107cdf0e10cSrcweir {
108cdf0e10cSrcweir     OUStringBuffer buf;
109cdf0e10cSrcweir     if (context.getLength() > 0) {
110cdf0e10cSrcweir         buf.append( static_cast<sal_Unicode>('[') );
111cdf0e10cSrcweir         buf.append( context );
112cdf0e10cSrcweir         buf.appendAscii( RTL_CONSTASCII_STRINGPARAM("] ") );
113cdf0e10cSrcweir     }
114cdf0e10cSrcweir     buf.append( msg );
115cdf0e10cSrcweir     throw IncompatibleTypeException( buf.makeStringAndClear() );
116cdf0e10cSrcweir }
117cdf0e10cSrcweir 
118cdf0e10cSrcweir template<typename T>
checkSeq(Sequence<Reference<T>> const & newTypes,Sequence<Reference<T>> const & existingTypes,OUString const & context,bool optionalMode=false)119cdf0e10cSrcweir void checkSeq( Sequence< Reference<T> > const & newTypes,
120cdf0e10cSrcweir             Sequence< Reference<T> > const & existingTypes,
121cdf0e10cSrcweir             OUString const & context,
122cdf0e10cSrcweir             bool optionalMode = false )
123cdf0e10cSrcweir {
124cdf0e10cSrcweir     sal_Int32 len = newTypes.getLength();
125cdf0e10cSrcweir     if (len != existingTypes.getLength())
126cdf0e10cSrcweir     {
127cdf0e10cSrcweir         if (!optionalMode || len < newTypes.getLength())
128cdf0e10cSrcweir             typeError( OUSTR("Different number of types!"), context );
129cdf0e10cSrcweir         len = existingTypes.getLength();
130cdf0e10cSrcweir     }
131cdf0e10cSrcweir 
132cdf0e10cSrcweir     Reference<T> const * pNewTypes = newTypes.getConstArray();
133cdf0e10cSrcweir     Reference<T> const * pExistingTypes = existingTypes.getConstArray();
134cdf0e10cSrcweir     for ( sal_Int32 pos = 0; pos < len; ++pos )
135cdf0e10cSrcweir     {
136cdf0e10cSrcweir         OUStringBuffer buf;
137cdf0e10cSrcweir         buf.append( context );
138cdf0e10cSrcweir         buf.appendAscii( RTL_CONSTASCII_STRINGPARAM(", position ") );
139cdf0e10cSrcweir         buf.append( pos );
140cdf0e10cSrcweir         check( pNewTypes[pos].get(), pExistingTypes[pos].get(),
141cdf0e10cSrcweir                buf.makeStringAndClear() );
142cdf0e10cSrcweir     }
143cdf0e10cSrcweir }
144cdf0e10cSrcweir 
checkEnum(Reference<reflection::XEnumTypeDescription> const & xNewTD,Reference<reflection::XEnumTypeDescription> const & xExistingTD)145cdf0e10cSrcweir void checkEnum(
146cdf0e10cSrcweir     Reference<reflection::XEnumTypeDescription> const & xNewTD,
147cdf0e10cSrcweir     Reference<reflection::XEnumTypeDescription> const & xExistingTD )
148cdf0e10cSrcweir {
149cdf0e10cSrcweir     if (xNewTD->getEnumNames() != xExistingTD->getEnumNames())
150cdf0e10cSrcweir         typeError( OUSTR("ENUM names don't match!"), xNewTD->getName() );
151cdf0e10cSrcweir     if (xNewTD->getEnumValues() != xExistingTD->getEnumValues())
152cdf0e10cSrcweir         typeError( OUSTR("ENUM values don't match!"), xNewTD->getName() );
153cdf0e10cSrcweir }
154cdf0e10cSrcweir 
checkStruct(Reference<reflection::XCompoundTypeDescription> const & xNewTD,Reference<reflection::XCompoundTypeDescription> const & xExistingTD)155cdf0e10cSrcweir void checkStruct(
156cdf0e10cSrcweir     Reference<reflection::XCompoundTypeDescription> const & xNewTD,
157cdf0e10cSrcweir     Reference<reflection::XCompoundTypeDescription> const & xExistingTD )
158cdf0e10cSrcweir {
159cdf0e10cSrcweir     check( xNewTD->getBaseType(), xExistingTD->getBaseType(),
160cdf0e10cSrcweir            xNewTD->getName() + OUSTR(", base type") );
161cdf0e10cSrcweir     checkSeq( xNewTD->getMemberTypes(), xExistingTD->getMemberTypes(),
162cdf0e10cSrcweir               xNewTD->getName() + OUSTR(", member types") );
163cdf0e10cSrcweir 
164cdf0e10cSrcweir     if (xNewTD->getMemberNames() != xExistingTD->getMemberNames())
165cdf0e10cSrcweir         typeError( OUSTR("Different member names!"), xNewTD->getName() );
166cdf0e10cSrcweir 
167cdf0e10cSrcweir     if (xNewTD->getTypeClass() == TypeClass_STRUCT)
168cdf0e10cSrcweir     {
169cdf0e10cSrcweir         Reference<reflection::XStructTypeDescription> xNewStructTD(
170cdf0e10cSrcweir             xNewTD, UNO_QUERY );
171cdf0e10cSrcweir         Reference<reflection::XStructTypeDescription> xExistingStructTD(
172cdf0e10cSrcweir             xExistingTD, UNO_QUERY );
173cdf0e10cSrcweir         if (xNewStructTD.is() && xExistingStructTD.is())
174cdf0e10cSrcweir         {
175cdf0e10cSrcweir             if (xNewStructTD->getTypeParameters() !=
176cdf0e10cSrcweir                 xExistingStructTD->getTypeParameters())
177cdf0e10cSrcweir                 typeError( OUSTR("Different type parameters of instantiated "
178cdf0e10cSrcweir                                  "polymorphic STRUCT!"), xNewTD->getName() );
179cdf0e10cSrcweir             checkSeq( xNewStructTD->getTypeArguments(),
180cdf0e10cSrcweir                       xExistingStructTD->getTypeArguments(),
181cdf0e10cSrcweir                       xNewTD->getName() + OUSTR(", argument types") );
182cdf0e10cSrcweir         }
183cdf0e10cSrcweir         else if (xNewStructTD.is() || xExistingStructTD.is())
184cdf0e10cSrcweir             typeError( OUSTR("Mixing polymorphic STRUCT types "
185cdf0e10cSrcweir                              "with non-polymorphic!"), xNewTD->getName() );
186cdf0e10cSrcweir     }
187cdf0e10cSrcweir }
188cdf0e10cSrcweir 
checkInterface(Reference<reflection::XInterfaceTypeDescription2> const & xNewTD,Reference<reflection::XInterfaceTypeDescription2> const & xExistingTD)189cdf0e10cSrcweir void checkInterface(
190cdf0e10cSrcweir     Reference<reflection::XInterfaceTypeDescription2> const & xNewTD,
191cdf0e10cSrcweir     Reference<reflection::XInterfaceTypeDescription2> const & xExistingTD )
192cdf0e10cSrcweir {
193cdf0e10cSrcweir     checkSeq( xNewTD->getBaseTypes(), xExistingTD->getBaseTypes(),
194cdf0e10cSrcweir               xNewTD->getName() + OUSTR(", base types") );
195cdf0e10cSrcweir     checkSeq(xNewTD->getOptionalBaseTypes(),xExistingTD->getOptionalBaseTypes(),
196cdf0e10cSrcweir              xNewTD->getName() + OUSTR(", optional base types") );
197cdf0e10cSrcweir     checkSeq( xNewTD->getMembers(), xExistingTD->getMembers(),
198cdf0e10cSrcweir               xNewTD->getName() + OUSTR(", members") );
199cdf0e10cSrcweir }
200cdf0e10cSrcweir 
checkRestParam(Reference<reflection::XParameter> const & xNewParam,Reference<reflection::XParameter> const & xExistingParam,OUString const & context)201cdf0e10cSrcweir void checkRestParam( Reference<reflection::XParameter> const & xNewParam,
202cdf0e10cSrcweir                      Reference<reflection::XParameter> const & xExistingParam,
203cdf0e10cSrcweir                      OUString const & context )
204cdf0e10cSrcweir {
205cdf0e10cSrcweir     if (xNewParam->isRestParameter() != xExistingParam->isRestParameter())
206cdf0e10cSrcweir         typeError( OUSTR("Different ... parameters specified!"), context );
207cdf0e10cSrcweir }
208cdf0e10cSrcweir 
checkRestParam(Reference<reflection::XMethodParameter> const &,Reference<reflection::XMethodParameter> const &,OUString const &)209cdf0e10cSrcweir void checkRestParam( Reference<reflection::XMethodParameter> const &,
210cdf0e10cSrcweir                      Reference<reflection::XMethodParameter> const &,
211cdf0e10cSrcweir                      OUString const & )
212cdf0e10cSrcweir {
213cdf0e10cSrcweir }
214cdf0e10cSrcweir 
215cdf0e10cSrcweir template<typename T>
checkParameters(Sequence<Reference<T>> const & newParams,Sequence<Reference<T>> const & existingParams,OUString const & context_)216cdf0e10cSrcweir void checkParameters( Sequence< Reference<T> > const & newParams,
217cdf0e10cSrcweir                       Sequence< Reference<T> > const & existingParams,
218cdf0e10cSrcweir                       OUString const & context_ )
219cdf0e10cSrcweir {
220cdf0e10cSrcweir     sal_Int32 len = newParams.getLength();
221cdf0e10cSrcweir     if (len != existingParams.getLength())
222cdf0e10cSrcweir         typeError( OUSTR("Different number of parameters!"), context_ );
223cdf0e10cSrcweir 	Reference<T> const * pNewParams = newParams.getConstArray();
224cdf0e10cSrcweir 	Reference<T> const * pExistingParams = existingParams.getConstArray();
225cdf0e10cSrcweir     for ( sal_Int32 pos = 0; pos < len; ++pos )
226cdf0e10cSrcweir     {
227cdf0e10cSrcweir         Reference<T> const & xNewParam = pNewParams[pos];
228cdf0e10cSrcweir         Reference<T> const & xExistingParam = pExistingParams[pos];
229cdf0e10cSrcweir 
230cdf0e10cSrcweir         OUStringBuffer buf;
231cdf0e10cSrcweir         buf.append( context_ );
232cdf0e10cSrcweir         buf.appendAscii( RTL_CONSTASCII_STRINGPARAM(", parameter ") );
233cdf0e10cSrcweir         buf.append( pos );
234cdf0e10cSrcweir         OSL_ASSERT( pos == xNewParam->getPosition() &&
235cdf0e10cSrcweir                     pos == xExistingParam->getPosition() );
236cdf0e10cSrcweir         OUString context( buf.makeStringAndClear() );
237cdf0e10cSrcweir 
238cdf0e10cSrcweir         if (xNewParam->getName() != xExistingParam->getName())
239cdf0e10cSrcweir         {
240cdf0e10cSrcweir             buf.appendAscii( RTL_CONSTASCII_STRINGPARAM("Name differs: ") );
241cdf0e10cSrcweir             buf.append( xNewParam->getName() );
242cdf0e10cSrcweir             buf.appendAscii( RTL_CONSTASCII_STRINGPARAM(", ") );
243cdf0e10cSrcweir             buf.append( xExistingParam->getName() );
244cdf0e10cSrcweir             typeError( buf.makeStringAndClear(), context );
245cdf0e10cSrcweir         }
246cdf0e10cSrcweir         check( xNewParam->getType(), xExistingParam->getType(), context );
247cdf0e10cSrcweir 
248cdf0e10cSrcweir         if (xNewParam->isIn() != xExistingParam->isIn())
249cdf0e10cSrcweir             typeError( OUSTR("IN attribute differs!"), context );
250cdf0e10cSrcweir         if (xNewParam->isOut() != xExistingParam->isOut())
251cdf0e10cSrcweir             typeError( OUSTR("OUT attribute differs!"), context );
252cdf0e10cSrcweir         checkRestParam( xNewParam, xExistingParam, context );
253cdf0e10cSrcweir     }
254cdf0e10cSrcweir }
255cdf0e10cSrcweir 
checkMethod(Reference<reflection::XInterfaceMethodTypeDescription> const & xNewTD,Reference<reflection::XInterfaceMethodTypeDescription> const & xExistingTD)256cdf0e10cSrcweir static void checkMethod(
257cdf0e10cSrcweir     Reference<reflection::XInterfaceMethodTypeDescription> const & xNewTD,
258cdf0e10cSrcweir     Reference<reflection::XInterfaceMethodTypeDescription> const & xExistingTD )
259cdf0e10cSrcweir {
260cdf0e10cSrcweir 	check( xNewTD->getReturnType(), xExistingTD->getReturnType(),
261cdf0e10cSrcweir            xNewTD->getName() );
262cdf0e10cSrcweir 
263cdf0e10cSrcweir 	if (xNewTD->isOneway() != xExistingTD->isOneway())
264cdf0e10cSrcweir         typeError( OUSTR("Methods have differing OneWay attribute!"),
265cdf0e10cSrcweir                    xNewTD->getName() );
266cdf0e10cSrcweir 
267cdf0e10cSrcweir     checkParameters( xNewTD->getParameters(), xExistingTD->getParameters(),
268cdf0e10cSrcweir                      xNewTD->getName() );
269cdf0e10cSrcweir 
270cdf0e10cSrcweir     checkSeq( xNewTD->getExceptions(), xExistingTD->getExceptions(),
271cdf0e10cSrcweir               xNewTD->getName() + OUSTR(", declared exceptions") );
272cdf0e10cSrcweir }
273cdf0e10cSrcweir 
checkAttribute(Reference<reflection::XInterfaceAttributeTypeDescription2> const & xNewTD,Reference<reflection::XInterfaceAttributeTypeDescription2> const & xExistingTD)274cdf0e10cSrcweir void checkAttribute(
275cdf0e10cSrcweir     Reference<reflection::XInterfaceAttributeTypeDescription2> const & xNewTD,
276cdf0e10cSrcweir     Reference<reflection::XInterfaceAttributeTypeDescription2>
277cdf0e10cSrcweir     const & xExistingTD )
278cdf0e10cSrcweir {
279cdf0e10cSrcweir 	if (xNewTD->isReadOnly() != xExistingTD->isReadOnly())
280cdf0e10cSrcweir         typeError( OUSTR("ReadOnly attribute differs!"), xNewTD->getName() );
281cdf0e10cSrcweir 
282cdf0e10cSrcweir     check( xNewTD->getType(), xExistingTD->getType(),
283cdf0e10cSrcweir            xNewTD->getName() + OUSTR(", attribute type") );
284cdf0e10cSrcweir 
285cdf0e10cSrcweir     if (xNewTD->isBound() != xExistingTD->isBound())
286cdf0e10cSrcweir         typeError( OUSTR("Bound attribute differs!"), xNewTD->getName() );
287cdf0e10cSrcweir 
288cdf0e10cSrcweir     checkSeq( xNewTD->getGetExceptions(), xExistingTD->getGetExceptions(),
289cdf0e10cSrcweir               xNewTD->getName() + OUSTR(", getter exceptions") );
290cdf0e10cSrcweir     checkSeq( xNewTD->getSetExceptions(), xExistingTD->getSetExceptions(),
291cdf0e10cSrcweir               xNewTD->getName() + OUSTR(", setter exceptions") );
292cdf0e10cSrcweir }
293cdf0e10cSrcweir 
checkProperty(Reference<reflection::XPropertyTypeDescription> const & xNewTD,Reference<reflection::XPropertyTypeDescription> const & xExistingTD)294cdf0e10cSrcweir void checkProperty(
295cdf0e10cSrcweir     Reference<reflection::XPropertyTypeDescription> const & xNewTD,
296cdf0e10cSrcweir     Reference<reflection::XPropertyTypeDescription> const & xExistingTD )
297cdf0e10cSrcweir {
298cdf0e10cSrcweir     if (xNewTD->getPropertyFlags() != xExistingTD->getPropertyFlags())
299cdf0e10cSrcweir     {
300cdf0e10cSrcweir         OUStringBuffer buf;
301cdf0e10cSrcweir         buf.appendAscii( RTL_CONSTASCII_STRINGPARAM(
302cdf0e10cSrcweir                              "Different set of property flags: { ") );
303cdf0e10cSrcweir         buf.append( getPropertyFlagsAsString(
304cdf0e10cSrcweir                         xNewTD->getPropertyFlags() ) );
305cdf0e10cSrcweir         buf.appendAscii( RTL_CONSTASCII_STRINGPARAM(" } (new), { ") );
306cdf0e10cSrcweir         buf.append( getPropertyFlagsAsString(
307cdf0e10cSrcweir                         xExistingTD->getPropertyFlags() ) );
308cdf0e10cSrcweir         buf.appendAscii( RTL_CONSTASCII_STRINGPARAM(" } (existing)!") );
309cdf0e10cSrcweir         typeError( buf.makeStringAndClear(), xNewTD->getName() );
310cdf0e10cSrcweir     }
311cdf0e10cSrcweir 
312cdf0e10cSrcweir     check( xNewTD->getPropertyTypeDescription(),
313cdf0e10cSrcweir            xExistingTD->getPropertyTypeDescription(),
314cdf0e10cSrcweir            xNewTD->getName() );
315cdf0e10cSrcweir }
316cdf0e10cSrcweir 
checkSingleton(Reference<reflection::XSingletonTypeDescription2> const & xNewTD,Reference<reflection::XSingletonTypeDescription2> const & xExistingTD)317cdf0e10cSrcweir void checkSingleton(
318cdf0e10cSrcweir     Reference<reflection::XSingletonTypeDescription2> const & xNewTD,
319cdf0e10cSrcweir     Reference<reflection::XSingletonTypeDescription2> const & xExistingTD )
320cdf0e10cSrcweir {
321cdf0e10cSrcweir     sal_Bool ifaceBased = xNewTD->isInterfaceBased();
322cdf0e10cSrcweir     if (ifaceBased != xExistingTD->isInterfaceBased())
323cdf0e10cSrcweir         typeError(
324cdf0e10cSrcweir             OUSTR("Mixing interface and NON-interface based singletons!"),
325cdf0e10cSrcweir             xNewTD->getName() );
326cdf0e10cSrcweir     if (ifaceBased)
327cdf0e10cSrcweir         check( xNewTD->getInterface(), xExistingTD->getInterface(),
328cdf0e10cSrcweir                xNewTD->getName() );
329cdf0e10cSrcweir     else
330cdf0e10cSrcweir         check( xNewTD->getService().get(), xExistingTD->getService().get(),
331cdf0e10cSrcweir                xNewTD->getName() );
332cdf0e10cSrcweir }
333cdf0e10cSrcweir 
checkService(Reference<reflection::XServiceTypeDescription2> const & xNewTD,Reference<reflection::XServiceTypeDescription2> const & xExistingTD)334cdf0e10cSrcweir void checkService(
335cdf0e10cSrcweir     Reference<reflection::XServiceTypeDescription2> const & xNewTD,
336cdf0e10cSrcweir     Reference<reflection::XServiceTypeDescription2> const & xExistingTD )
337cdf0e10cSrcweir {
338cdf0e10cSrcweir     sal_Bool singleIfaceBased = xNewTD->isSingleInterfaceBased();
339cdf0e10cSrcweir     if (singleIfaceBased != xExistingTD->isSingleInterfaceBased())
340cdf0e10cSrcweir         typeError( OUSTR("Mixing interface and NON-interface based services!"),
341cdf0e10cSrcweir                    xNewTD->getName() );
342cdf0e10cSrcweir     if (singleIfaceBased)
343cdf0e10cSrcweir     {
344cdf0e10cSrcweir         check( xNewTD->getInterface(), xExistingTD->getInterface(),
345cdf0e10cSrcweir                xNewTD->getName() );
346cdf0e10cSrcweir         Sequence< Reference<reflection::XServiceConstructorDescription> >
347cdf0e10cSrcweir             newCtors( xNewTD->getConstructors() );
348cdf0e10cSrcweir         Sequence< Reference<reflection::XServiceConstructorDescription> >
349cdf0e10cSrcweir             existingCtors( xExistingTD->getConstructors() );
350cdf0e10cSrcweir         sal_Int32 len = newCtors.getLength();
351cdf0e10cSrcweir         if (len != existingCtors.getLength())
352cdf0e10cSrcweir             typeError( OUSTR("Different number of service constructors!"),
353cdf0e10cSrcweir                        xNewTD->getName() );
354cdf0e10cSrcweir         Reference<reflection::XServiceConstructorDescription> const *
355cdf0e10cSrcweir             pNewCtors = newCtors.getConstArray();
356cdf0e10cSrcweir         Reference<reflection::XServiceConstructorDescription> const *
357cdf0e10cSrcweir             pExistingCtors = existingCtors.getConstArray();
358cdf0e10cSrcweir         for ( sal_Int32 pos = 0; pos < len; ++pos )
359cdf0e10cSrcweir         {
360cdf0e10cSrcweir             Reference<reflection::XServiceConstructorDescription> const &
361cdf0e10cSrcweir                 xNewCtor = pNewCtors[pos];
362cdf0e10cSrcweir             Reference<reflection::XServiceConstructorDescription> const &
363cdf0e10cSrcweir                 xExistingCtor = pExistingCtors[pos];
364cdf0e10cSrcweir 
365cdf0e10cSrcweir             if (xNewCtor->getName() != xExistingCtor->getName())
366cdf0e10cSrcweir             {
367cdf0e10cSrcweir                 OUStringBuffer buf;
368cdf0e10cSrcweir                 buf.appendAscii( RTL_CONSTASCII_STRINGPARAM(
369cdf0e10cSrcweir                                      "Different constructor names: ") );
370cdf0e10cSrcweir                 buf.append( xNewCtor->getName() );
371cdf0e10cSrcweir                 buf.appendAscii( RTL_CONSTASCII_STRINGPARAM(" (new), ") );
372cdf0e10cSrcweir                 buf.append( xExistingCtor->getName() );
373cdf0e10cSrcweir                 buf.appendAscii( RTL_CONSTASCII_STRINGPARAM(" (existing)!") );
374cdf0e10cSrcweir                 typeError( buf.makeStringAndClear(), xNewTD->getName() );
375cdf0e10cSrcweir             }
376cdf0e10cSrcweir 
377cdf0e10cSrcweir             OUStringBuffer buf;
378cdf0e10cSrcweir             buf.append( xNewTD->getName() );
379cdf0e10cSrcweir             buf.appendAscii( RTL_CONSTASCII_STRINGPARAM(", constructor ") );
380cdf0e10cSrcweir             buf.append( xNewCtor->getName() );
381cdf0e10cSrcweir             OUString context( buf.makeStringAndClear() );
382cdf0e10cSrcweir             checkParameters( xNewCtor->getParameters(),
383cdf0e10cSrcweir                              xExistingCtor->getParameters(),
384cdf0e10cSrcweir                              context );
385cdf0e10cSrcweir             checkSeq( xNewCtor->getExceptions(), xExistingCtor->getExceptions(),
386cdf0e10cSrcweir                       context + OUSTR(", exceptions") );
387cdf0e10cSrcweir         }
388cdf0e10cSrcweir     }
389cdf0e10cSrcweir     else // old-style service descriptions:
390cdf0e10cSrcweir     {
391cdf0e10cSrcweir         checkSeq( xNewTD->getMandatoryServices(),
392cdf0e10cSrcweir                   xExistingTD->getMandatoryServices(),
393cdf0e10cSrcweir                   xNewTD->getName() + OUSTR(", mandatory services") );
394cdf0e10cSrcweir         checkSeq( xNewTD->getOptionalServices(),
395cdf0e10cSrcweir                   xExistingTD->getOptionalServices(),
396cdf0e10cSrcweir                   xNewTD->getName() + OUSTR(", optional services"),
397cdf0e10cSrcweir                   true /* optionalMode */ );
398cdf0e10cSrcweir         checkSeq( xNewTD->getMandatoryInterfaces(),
399cdf0e10cSrcweir                   xExistingTD->getMandatoryInterfaces(),
400cdf0e10cSrcweir                   xNewTD->getName() + OUSTR(", mandatory interfaces") );
401cdf0e10cSrcweir         checkSeq( xNewTD->getOptionalInterfaces(),
402cdf0e10cSrcweir                   xExistingTD->getOptionalInterfaces(),
403cdf0e10cSrcweir                   xNewTD->getName() + OUSTR(", optional interfaces"),
404cdf0e10cSrcweir                   true /* optionalMode */ );
405cdf0e10cSrcweir 
406cdf0e10cSrcweir         Sequence< Reference<reflection::XPropertyTypeDescription> >
407cdf0e10cSrcweir             newProperties( xNewTD->getProperties() );
408cdf0e10cSrcweir         Sequence< Reference<reflection::XPropertyTypeDescription> >
409cdf0e10cSrcweir             existingProperties( xExistingTD->getProperties() );
410cdf0e10cSrcweir         checkSeq( newProperties, existingProperties,
411cdf0e10cSrcweir                   xNewTD->getName() + OUSTR(", properties"),
412cdf0e10cSrcweir                   true /* optionalMode */ );
413cdf0e10cSrcweir         if (newProperties.getLength() > existingProperties.getLength())
414cdf0e10cSrcweir         {
415cdf0e10cSrcweir             // check whether all added properties are OPTIONAL:
416cdf0e10cSrcweir             Reference<reflection::XPropertyTypeDescription> const *
417cdf0e10cSrcweir                 pNewProperties = newProperties.getConstArray();
418cdf0e10cSrcweir             for ( sal_Int32 pos = existingProperties.getLength() + 1;
419cdf0e10cSrcweir                   pos < newProperties.getLength(); ++pos )
420cdf0e10cSrcweir             {
421cdf0e10cSrcweir                 if ((pNewProperties[pos]->getPropertyFlags() &
422cdf0e10cSrcweir                      beans::PropertyAttribute::OPTIONAL) == 0)
423cdf0e10cSrcweir                     typeError( OUSTR("New property is not OPTIONAL!"),
424cdf0e10cSrcweir                                pNewProperties[pos]->getName() );
425cdf0e10cSrcweir             }
426cdf0e10cSrcweir         }
427cdf0e10cSrcweir     }
428cdf0e10cSrcweir }
429cdf0e10cSrcweir 
430cdf0e10cSrcweir }
431cdf0e10cSrcweir 
432cdf0e10cSrcweir namespace stoc_tdmgr {
433cdf0e10cSrcweir 
check(Reference<reflection::XTypeDescription> const & xNewTD,Reference<reflection::XTypeDescription> const & xExistingTD,OUString const & context)434cdf0e10cSrcweir void check( Reference<reflection::XTypeDescription> const & xNewTD,
435cdf0e10cSrcweir             Reference<reflection::XTypeDescription> const & xExistingTD,
436cdf0e10cSrcweir             OUString const & context )
437cdf0e10cSrcweir {
438cdf0e10cSrcweir     if (xNewTD == xExistingTD)
439cdf0e10cSrcweir         return;
440cdf0e10cSrcweir     if (xNewTD->getName() != xExistingTD->getName())
441cdf0e10cSrcweir     {
442cdf0e10cSrcweir         OUStringBuffer buf;
443cdf0e10cSrcweir         buf.appendAscii( RTL_CONSTASCII_STRINGPARAM("Different type names: ") );
444cdf0e10cSrcweir         buf.append( xNewTD->getName() );
445cdf0e10cSrcweir         buf.appendAscii( RTL_CONSTASCII_STRINGPARAM(" (new), ") );
446cdf0e10cSrcweir         buf.append( xExistingTD->getName() );
447cdf0e10cSrcweir         buf.appendAscii( RTL_CONSTASCII_STRINGPARAM(" (existing)!") );
448cdf0e10cSrcweir         typeError( buf.makeStringAndClear(), context );
449cdf0e10cSrcweir     }
450cdf0e10cSrcweir 
451cdf0e10cSrcweir     TypeClass tc = xNewTD->getTypeClass();
452cdf0e10cSrcweir     if (tc != xExistingTD->getTypeClass())
453cdf0e10cSrcweir     {
454cdf0e10cSrcweir         OUStringBuffer buf;
455cdf0e10cSrcweir         buf.append( xNewTD->getName() );
456cdf0e10cSrcweir         buf.appendAscii( RTL_CONSTASCII_STRINGPARAM(
457cdf0e10cSrcweir                              " has different type classes: ") );
458cdf0e10cSrcweir         buf.append( getTypeClassName( tc ) );
459cdf0e10cSrcweir         buf.appendAscii( RTL_CONSTASCII_STRINGPARAM(" (new), ") );
460cdf0e10cSrcweir         buf.append( getTypeClassName( xExistingTD->getTypeClass() ) );
461cdf0e10cSrcweir         buf.appendAscii( RTL_CONSTASCII_STRINGPARAM(" (existing)!") );
462cdf0e10cSrcweir         typeError( buf.makeStringAndClear(), context );
463cdf0e10cSrcweir     }
464cdf0e10cSrcweir 
465cdf0e10cSrcweir     switch (tc)
466cdf0e10cSrcweir     {
467cdf0e10cSrcweir     case TypeClass_ENUM:
468cdf0e10cSrcweir         checkEnum( Reference<reflection::XEnumTypeDescription>(
469cdf0e10cSrcweir                        xNewTD, UNO_QUERY_THROW ),
470cdf0e10cSrcweir                    Reference<reflection::XEnumTypeDescription>(
471cdf0e10cSrcweir                        xExistingTD, UNO_QUERY_THROW ) );
472cdf0e10cSrcweir         break;
473cdf0e10cSrcweir 
474cdf0e10cSrcweir     case TypeClass_TYPEDEF:
475cdf0e10cSrcweir     case TypeClass_SEQUENCE:
476cdf0e10cSrcweir         check( Reference<reflection::XIndirectTypeDescription>(
477cdf0e10cSrcweir                    xNewTD, UNO_QUERY_THROW )->getReferencedType(),
478cdf0e10cSrcweir                Reference<reflection::XIndirectTypeDescription>(
479cdf0e10cSrcweir                    xExistingTD, UNO_QUERY_THROW )->getReferencedType() );
480cdf0e10cSrcweir         break;
481cdf0e10cSrcweir 
482cdf0e10cSrcweir     case TypeClass_STRUCT:
483cdf0e10cSrcweir     case TypeClass_EXCEPTION:
484cdf0e10cSrcweir         checkStruct( Reference<reflection::XCompoundTypeDescription>(
485cdf0e10cSrcweir                          xNewTD, UNO_QUERY_THROW ),
486cdf0e10cSrcweir                      Reference<reflection::XCompoundTypeDescription>(
487cdf0e10cSrcweir                          xExistingTD, UNO_QUERY_THROW ) );
488cdf0e10cSrcweir         break;
489cdf0e10cSrcweir 
490cdf0e10cSrcweir     case TypeClass_INTERFACE:
491cdf0e10cSrcweir         checkInterface( Reference<reflection::XInterfaceTypeDescription2>(
492cdf0e10cSrcweir                             xNewTD, UNO_QUERY_THROW ),
493cdf0e10cSrcweir                         Reference<reflection::XInterfaceTypeDescription2>(
494cdf0e10cSrcweir                             xExistingTD, UNO_QUERY_THROW ) );
495cdf0e10cSrcweir         break;
496cdf0e10cSrcweir 
497cdf0e10cSrcweir     case TypeClass_SERVICE:
498cdf0e10cSrcweir         checkService( Reference<reflection::XServiceTypeDescription2>(
499cdf0e10cSrcweir                           xNewTD, UNO_QUERY_THROW ),
500cdf0e10cSrcweir                       Reference<reflection::XServiceTypeDescription2>(
501cdf0e10cSrcweir                           xExistingTD, UNO_QUERY_THROW ) );
502cdf0e10cSrcweir         break;
503cdf0e10cSrcweir 
504cdf0e10cSrcweir     case TypeClass_INTERFACE_METHOD:
505cdf0e10cSrcweir         checkMethod( Reference<reflection::XInterfaceMethodTypeDescription>(
506cdf0e10cSrcweir                          xNewTD, UNO_QUERY_THROW ),
507cdf0e10cSrcweir                      Reference<reflection::XInterfaceMethodTypeDescription>(
508cdf0e10cSrcweir                          xExistingTD, UNO_QUERY_THROW ) );
509cdf0e10cSrcweir         break;
510cdf0e10cSrcweir     case TypeClass_INTERFACE_ATTRIBUTE:
511cdf0e10cSrcweir         checkAttribute(
512cdf0e10cSrcweir             Reference<reflection::XInterfaceAttributeTypeDescription2>(
513cdf0e10cSrcweir                 xNewTD, UNO_QUERY_THROW ),
514cdf0e10cSrcweir             Reference<reflection::XInterfaceAttributeTypeDescription2>(
515cdf0e10cSrcweir                 xExistingTD, UNO_QUERY_THROW ) );
516cdf0e10cSrcweir         break;
517cdf0e10cSrcweir 
518cdf0e10cSrcweir     case TypeClass_PROPERTY:
519cdf0e10cSrcweir         checkProperty( Reference<reflection::XPropertyTypeDescription>(
520cdf0e10cSrcweir                            xNewTD, UNO_QUERY_THROW ),
521cdf0e10cSrcweir                        Reference<reflection::XPropertyTypeDescription>(
522cdf0e10cSrcweir                            xExistingTD, UNO_QUERY_THROW ) );
523cdf0e10cSrcweir         break;
524cdf0e10cSrcweir 
525cdf0e10cSrcweir     case TypeClass_CONSTANT:
526cdf0e10cSrcweir         if (Reference<reflection::XConstantTypeDescription>(
527cdf0e10cSrcweir                 xNewTD, UNO_QUERY_THROW )->getConstantValue() !=
528cdf0e10cSrcweir             Reference<reflection::XConstantTypeDescription>(
529cdf0e10cSrcweir                 xExistingTD, UNO_QUERY_THROW )->getConstantValue())
530cdf0e10cSrcweir             typeError( OUSTR("Different constant value!"), xNewTD->getName() );
531cdf0e10cSrcweir         break;
532cdf0e10cSrcweir     case TypeClass_CONSTANTS:
533cdf0e10cSrcweir         checkSeq( Reference<reflection::XConstantsTypeDescription>(
534cdf0e10cSrcweir                       xNewTD, UNO_QUERY_THROW )->getConstants(),
535cdf0e10cSrcweir                   Reference<reflection::XConstantsTypeDescription>(
536cdf0e10cSrcweir                       xExistingTD, UNO_QUERY_THROW )->getConstants(),
537cdf0e10cSrcweir                   xNewTD->getName() );
538cdf0e10cSrcweir         break;
539cdf0e10cSrcweir 
540cdf0e10cSrcweir     case TypeClass_SINGLETON:
541cdf0e10cSrcweir         checkSingleton( Reference<reflection::XSingletonTypeDescription2>(
542cdf0e10cSrcweir                             xNewTD, UNO_QUERY_THROW ),
543cdf0e10cSrcweir                         Reference<reflection::XSingletonTypeDescription2>(
544cdf0e10cSrcweir                             xExistingTD, UNO_QUERY_THROW ) );
545cdf0e10cSrcweir         break;
546cdf0e10cSrcweir 
547cdf0e10cSrcweir     default:
548cdf0e10cSrcweir         break;
549cdf0e10cSrcweir     }
550cdf0e10cSrcweir }
551cdf0e10cSrcweir 
552cdf0e10cSrcweir }
553