Difference between revisions of "XIntrospection Interface"
SergeMoutou (talk | contribs)  | 
				SergeMoutou (talk | contribs)   | 
				||
| Line 45: | Line 45: | ||
The figure above explains how to get the methods information with returned type, name of method and parameters information. Please note that getParamMode is not provided by SDK but a my own code (inspired by Inspector Java code) We fist give this code :  | The figure above explains how to get the methods information with returned type, name of method and parameters information. Please note that getParamMode is not provided by SDK but a my own code (inspired by Inspector Java code) We fist give this code :  | ||
| − | + | <code>[cpp]  | |
| − | Listing 12 getParamMode function  | + | //Listing 12 getParamMode function  | 
// C++  | // C++  | ||
// Don't forget to add : #include <com/sun/star/reflection/ParamMode.hpp>  | // Don't forget to add : #include <com/sun/star/reflection/ParamMode.hpp>  | ||
| Line 59: | Line 59: | ||
   return toReturn;  |    return toReturn;  | ||
}  | }  | ||
| − | + | </code>  | |
Now the complete implementation is given : starting from Figure 1.7 it's easy to see we need two parameters, a XMultiServiceFactory and an Any :  | Now the complete implementation is given : starting from Figure 1.7 it's easy to see we need two parameters, a XMultiServiceFactory and an Any :  | ||
| − | + | <code>[cpp]  | |
| − | Listing 13 getMethods function  | + | //Listing 13 getMethods function  | 
//C++  | //C++  | ||
// translated in C++ from <OpenOffice1.1_SDK>/examples/java/Inspector  | // translated in C++ from <OpenOffice1.1_SDK>/examples/java/Inspector  | ||
| Line 107: | Line 107: | ||
	return OUStrs;  | 	return OUStrs;  | ||
}  | }  | ||
| + | </code>  | ||
| + | |||
== Obtaining all the interfaces ==  | == Obtaining all the interfaces ==  | ||
Revision as of 15:00, 26 May 2006
We prefer to use the Java Inspector method : inspect a real object. You can then find values of the properties for example. (<OpenOffice.org1.1_SDK>/examples/java/Inspector) Again we first give some of used interfaces.
// IDL
module com {  module sun {  module star {  module beans {
interface XIntrospection: com::sun::star::uno::XInterface
{ 
	com::sun::star::beans::XIntrospectionAccess inspect( [in] any aObject );
};
}; }; }; };
  
where we see we have to focus our attention to XIntrospectionAccess interface :
// IDL
module com {  module sun {  module star {  module beans {
interface XIntrospectionAccess: com::sun::star::uno::XInterface
{ 
	long getSuppliedMethodConcepts(); 
	long getSuppliedPropertyConcepts();
	com::sun::star::beans::Property getProperty( [in] string aName,
			 [in] long nPropertyConcepts ) 
			raises( com::sun::star::container::NoSuchElementException );
	boolean hasProperty( [in] string aName,
			 [in] long nPropertyConcepts ); 
	sequence<com::sun::star::beans::Property> getProperties(  
				[in] long nPropertyConcepts );
	com::sun::star::reflection::XIdlMethod getMethod( [in] string aName, 
			 [in] long nMethodConcepts )
			raises( com::sun::star::lang::NoSuchMethodException ); 
	boolean hasMethod( [in] string aName, 
			 [in] long nMethodConcepts );
	sequence<com::sun::star::reflection::XIdlMethod> getMethods(
			[in] long nMethodConcepts ); 
	sequence<type> getSupportedListeners(); 
	com::sun::star::uno::XInterface queryAdapter( [in] type aInterfaceType ) 
			raises( com::sun::star::beans::IllegalTypeException ); 
};
}; }; }; };
Please go on alone and have a look in the other involved IDL files.
Obtaining methods information
We present now how to construct the Reflection information with a schematic representation.
The figure above explains how to get the methods information with returned type, name of method and parameters information. Please note that getParamMode is not provided by SDK but a my own code (inspired by Inspector Java code) We fist give this code :
[cpp]
//Listing 12 getParamMode function
// C++
// Don't forget to add : #include <com/sun/star/reflection/ParamMode.hpp>
// Don't forget to add "com.sun.star.reflection.ParamMode \" in the makefile
OUString getParamMode(ParamMode paramMode) {
// comes from <OpenOffice1.1_SDK>/examples/java/Inspector
 OUString toReturn;
 toReturn = OUString::createFromAscii("");
 if (paramMode == ParamMode_IN) toReturn = OUString::createFromAscii("IN"); else
   if (paramMode == ParamMode_OUT) toReturn = OUString::createFromAscii("OUT"); else
     if (paramMode == ParamMode_INOUT) toReturn = OUString::createFromAscii("INOUT");
 return toReturn;
}
Now the complete implementation is given : starting from Figure 1.7 it's easy to see we need two parameters, a XMultiServiceFactory and an Any :
[cpp]
//Listing 13 getMethods function
//C++
// translated in C++ from <OpenOffice1.1_SDK>/examples/java/Inspector
// Don't forget to add : using namespace com::sun::star::beans;
// Don't forget to add : #include <com/sun/star/beans/XIntrospection.hpp>
// Don't forget to add "com.sun.star.beans.XIntrospection \" in the makefile
Sequence <OUString> getMethods(Any any,Reference< XMultiServiceFactory > rSVM)
	Reference< XIntrospection >xIntrospection = Reference< XIntrospection >
					( rSVM->createInstance(
                                OUString( RTL_CONSTASCII_USTRINGPARAM(
                                     "com.sun.star.beans.Introspection" ))), UNO_QUERY );
// ********* get all methods for the given object *********************
	Reference< XIntrospectionAccess > xIntrospec = xIntrospection->inspect(any);
// Don't forget to add : #include <com/sun/star/beans/MethodConcept.hpp>
// Don't forget to add "com.sun.star.beans.MethodConcept \" in the makefile
	Sequence< Reference < XIdlMethod > > mMethods = xIntrospec -> getMethods(MethodConcept::ALL);
	Sequence<OUString> OUStrs(mMethods.getLength());
	for (int i=0;i<mMethods.getLength();i++){
		OUString params;
		params=OUString::createFromAscii("(");
		Sequence< ParamInfo > ParamInfos = mMethods[i]->getParameterInfos();
		if (ParamInfos.getLength() > 0) {
			for (int j=0;j<ParamInfos.getLength();j++){
				Reference< XIdlClass > xIdlClass = ParamInfos[j].aType;
				if (j == 0)
				// first parameter has no leading comma
				params += OUString::createFromAscii("[") + getParamMode(ParamInfos[j].aMode)+
				OUString::createFromAscii("]") +
				xIdlClass->getName();
				else
				params += OUString::createFromAscii(",[") + getParamMode(ParamInfos[j].aMode)+
				OUString::createFromAscii("]")+
				xIdlClass->getName();
			}
		}
		params += OUString::createFromAscii(")");
		OUStrs[i]= mMethods[i]->getName()+params;
	}
	return OUStrs;
}
