API CHANGE: Make TypeDescriptionManager/Provider more consistent
...by letting their getByHierarchicalName methods return information about UNO constants as X(Constant)TypeDescription values, just as for (alomst -- see the odd enum member case) all other entities. This will make future changes in this area easier. The only affected client I could find so far is the core reflection service, but there might be more that I overlooked. Change-Id: I6731f2914773d49e33eeaec6e256ff2e5409ad2d
This commit is contained in:
@@ -21,6 +21,7 @@
|
|||||||
#include <cppuhelper/implementationentry.hxx>
|
#include <cppuhelper/implementationentry.hxx>
|
||||||
|
|
||||||
#include <com/sun/star/lang/XComponent.hpp>
|
#include <com/sun/star/lang/XComponent.hpp>
|
||||||
|
#include <com/sun/star/reflection/XConstantTypeDescription.hpp>
|
||||||
#include <com/sun/star/reflection/XTypeDescription.hpp>
|
#include <com/sun/star/reflection/XTypeDescription.hpp>
|
||||||
#include "com/sun/star/uno/RuntimeException.hpp"
|
#include "com/sun/star/uno/RuntimeException.hpp"
|
||||||
|
|
||||||
@@ -283,35 +284,42 @@ Any IdlReflectionServiceImpl::getByHierarchicalName( const OUString & rName )
|
|||||||
Any aRet( _aElements.getValue( rName ) );
|
Any aRet( _aElements.getValue( rName ) );
|
||||||
if (! aRet.hasValue())
|
if (! aRet.hasValue())
|
||||||
{
|
{
|
||||||
// first look for constants exclusivly!
|
|
||||||
aRet = _xTDMgr->getByHierarchicalName( rName );
|
aRet = _xTDMgr->getByHierarchicalName( rName );
|
||||||
if (aRet.getValueTypeClass() == TypeClass_INTERFACE) // if no constant,
|
if (aRet.getValueTypeClass() == TypeClass_INTERFACE)
|
||||||
// i.e. XTypeDescription for a type
|
|
||||||
{
|
{
|
||||||
// type retrieved from tdmgr
|
// type retrieved from tdmgr
|
||||||
OSL_ASSERT( (*(Reference< XInterface > *)aRet.getValue())->queryInterface(
|
OSL_ASSERT( (*(Reference< XInterface > *)aRet.getValue())->queryInterface(
|
||||||
::getCppuType( (const Reference< XTypeDescription > *)0 ) ).hasValue() );
|
::getCppuType( (const Reference< XTypeDescription > *)0 ) ).hasValue() );
|
||||||
|
|
||||||
// if you are interested in a type then CALL forName()!!!
|
css::uno::Reference< css::reflection::XConstantTypeDescription >
|
||||||
// this way is NOT recommended for types, because this method looks for constants first
|
ctd;
|
||||||
|
if (aRet >>= ctd)
|
||||||
// if td manager found some type, it will be in the cache (hopefully.. we just got it)
|
|
||||||
// so the second retrieving via c typelib callback chain should succeed...
|
|
||||||
|
|
||||||
// try to get _type_ by name
|
|
||||||
typelib_TypeDescription * pTD = 0;
|
|
||||||
typelib_typedescription_getByName( &pTD, rName.pData );
|
|
||||||
|
|
||||||
aRet.clear(); // kick XTypeDescription interface
|
|
||||||
|
|
||||||
if (pTD)
|
|
||||||
{
|
{
|
||||||
Reference< XIdlClass > xIdlClass( constructClass( pTD ) );
|
aRet = ctd->getConstantValue();
|
||||||
aRet.setValue( &xIdlClass, ::getCppuType( (const Reference< XIdlClass > *)0 ) );
|
}
|
||||||
typelib_typedescription_release( pTD );
|
else
|
||||||
|
{
|
||||||
|
// if you are interested in a type then CALL forName()!!!
|
||||||
|
// this way is NOT recommended for types, because this method looks for constants first
|
||||||
|
|
||||||
|
// if td manager found some type, it will be in the cache (hopefully.. we just got it)
|
||||||
|
// so the second retrieving via c typelib callback chain should succeed...
|
||||||
|
|
||||||
|
// try to get _type_ by name
|
||||||
|
typelib_TypeDescription * pTD = 0;
|
||||||
|
typelib_typedescription_getByName( &pTD, rName.pData );
|
||||||
|
|
||||||
|
aRet.clear(); // kick XTypeDescription interface
|
||||||
|
|
||||||
|
if (pTD)
|
||||||
|
{
|
||||||
|
Reference< XIdlClass > xIdlClass( constructClass( pTD ) );
|
||||||
|
aRet.setValue( &xIdlClass, ::getCppuType( (const Reference< XIdlClass > *)0 ) );
|
||||||
|
typelib_typedescription_release( pTD );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// else is constant
|
// else is enum member(?)
|
||||||
|
|
||||||
// update
|
// update
|
||||||
if (aRet.hasValue())
|
if (aRet.hasValue())
|
||||||
|
@@ -365,9 +365,10 @@ Any ProviderImpl::getByHierarchicalNameImpl( const OUString & rName )
|
|||||||
aBytes.getConstArray(), aBytes.getLength(),
|
aBytes.getConstArray(), aBytes.getLength(),
|
||||||
false, TYPEREG_VERSION_1);
|
false, TYPEREG_VERSION_1);
|
||||||
|
|
||||||
if (aReader.getTypeClass() == RT_TYPE_MODULE ||
|
RTTypeClass tc = aReader.getTypeClass();
|
||||||
aReader.getTypeClass() == RT_TYPE_CONSTANTS ||
|
if (tc == RT_TYPE_MODULE ||
|
||||||
aReader.getTypeClass() == RT_TYPE_ENUM)
|
tc == RT_TYPE_CONSTANTS ||
|
||||||
|
tc == RT_TYPE_ENUM)
|
||||||
{
|
{
|
||||||
OUString aFieldName( aKey.copy( nIndex+1, aKey.getLength() - nIndex -1 ) );
|
OUString aFieldName( aKey.copy( nIndex+1, aKey.getLength() - nIndex -1 ) );
|
||||||
sal_Int16 nPos = aReader.getFieldCount();
|
sal_Int16 nPos = aReader.getFieldCount();
|
||||||
@@ -378,8 +379,18 @@ Any ProviderImpl::getByHierarchicalNameImpl( const OUString & rName )
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (nPos >= 0)
|
if (nPos >= 0)
|
||||||
|
{
|
||||||
aRet = getRTValue(
|
aRet = getRTValue(
|
||||||
aReader.getFieldValue(nPos));
|
aReader.getFieldValue(nPos));
|
||||||
|
if (tc != RT_TYPE_ENUM)
|
||||||
|
{
|
||||||
|
aRet = css::uno::makeAny<
|
||||||
|
css::uno::Reference<
|
||||||
|
css::reflection::XTypeDescription > >(
|
||||||
|
new ConstantTypeDescriptionImpl(
|
||||||
|
rName, aRet));
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -47,9 +47,18 @@ published service TypeDescriptionManager
|
|||||||
{
|
{
|
||||||
/** Interface to retrieve type descriptions.
|
/** Interface to retrieve type descriptions.
|
||||||
|
|
||||||
|
In addition to the semantics specified for the corresponding interface
|
||||||
|
of the <type>TypeDescriptionProvider</type> service (which changed
|
||||||
|
slightly for LibreOffice 4.1; see there), this interface allows to
|
||||||
|
retrieve the following entities:
|
||||||
<ul>
|
<ul>
|
||||||
<li>Names are given in dotted notation, for example
|
<li>The simple types are accessible via <code>"void"</code>,
|
||||||
<code>"com.sun.star.uno.XInterface"</code>.</li>
|
<code>"boolean"</code>, <code>"byte"</code>, <code>"short"</code>,
|
||||||
|
<code>"unsigned short"</code>, <code>"long"</code>, <code>"unsigned
|
||||||
|
long"</code>, <code>"hyper"</code>, <code>"unsigned hyper"</code>,
|
||||||
|
<code>"float"</code>, <code>"double"</code>, <code>"char"</code>,
|
||||||
|
<code>"string"</code>, <code>"type"</code>, and
|
||||||
|
<code>"any"</code>.</li>
|
||||||
|
|
||||||
<li>Sequence types are accessible via
|
<li>Sequence types are accessible via
|
||||||
<code>"[]<var>ComponentType</var>"</code></li>
|
<code>"[]<var>ComponentType</var>"</code></li>
|
||||||
@@ -63,9 +72,6 @@ published service TypeDescriptionManager
|
|||||||
<code>"<var>InterfaceType</var>::<var>Member</var>"</code>.</li>
|
<code>"<var>InterfaceType</var>::<var>Member</var>"</code>.</li>
|
||||||
</ul>
|
</ul>
|
||||||
|
|
||||||
<p>The returned values are of interface type
|
|
||||||
<type>XTypeDescription</type>.</p>
|
|
||||||
|
|
||||||
<p>Even though the name of this interface suggests that the used type
|
<p>Even though the name of this interface suggests that the used type
|
||||||
names are hierarchic, this need not be the case. (For example, consider
|
names are hierarchic, this need not be the case. (For example, consider
|
||||||
the names of instantiated polymorphic struct types, like
|
the names of instantiated polymorphic struct types, like
|
||||||
|
@@ -39,11 +39,16 @@ published service TypeDescriptionProvider
|
|||||||
/** Interface to retrieve type descriptions.
|
/** Interface to retrieve type descriptions.
|
||||||
|
|
||||||
<p>Names are given in dotted notation, for example
|
<p>Names are given in dotted notation, for example
|
||||||
<code>"com.sun.star.uno.XInterface"</code>. The returned values are of
|
<code>"com.sun.star.uno.XInterface"</code>.</p>
|
||||||
interface type <type>XTypeDescription</type>.</p>
|
|
||||||
|
|
||||||
<p>Even though the name of this interface suggests that the used type
|
</p>The returned values are generally non-null references of type
|
||||||
names are hierarchic, this need not be the case.</p>
|
<type>XTypeDescription</type>. However, before LibreOffice 4.1,
|
||||||
|
the value returned for a UNO constant was the value of the constant,
|
||||||
|
rather than a reference to an <type>XConstantTypeDescription</type>
|
||||||
|
object. (It also appears that some implementations return values for
|
||||||
|
individual UNO enum members, e.g.
|
||||||
|
<code>"com.sun.star.uno.TypeClass.VOID"</code>, though this is probably
|
||||||
|
best treated as an implementation obscurity.)</p>
|
||||||
*/
|
*/
|
||||||
interface com::sun::star::container::XHierarchicalNameAccess;
|
interface com::sun::star::container::XHierarchicalNameAccess;
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user