Writing Professional Components

From Apache OpenOffice Wiki
Revision as of 14:14, 3 August 2009 by SergeMoutou (Talk | contribs)

Jump to: navigation, search
Documentation caution.png This chapter is under construction for a while because I don't master all the topics evocated here at the moment. SergeMoutou 12:20, 3 August 2009 (UTC)

Writing components is not as easy as developping binary executable. When an exception occurs in your component a recovery process of your document begins. This process is too long to try some code and correct the errors. When designing a component, it would be a good idea to conceive it as a binary executable before to change it into a component. In this chapter we will discuss this idea and also the exceptions. But before starting we examine at first the inspection tools.

Java Inspector

I have already tackled Java Inspector in this document (see here). But in this section we will discuss how we can use Java Inspector in a component.

Creating the Header Files

Creating header files could be done with exporting the rdb with extension manager and then using cppumaker tool. Because the service name is "org.openoffice.InstanceInspector" put the created header files in "<OOo_SDK>/includes/org/openoffice/" folder. You can then use :

// C++
// Listing 1
// Java Inspector
#include <org/openoffice/XInstanceInspector.hpp>

in your component.

Creating the corresponding Service

This is done with :

// C++
// Listing 2
// If you want to use java Inspector
	m_xInspector = Reference< XInstanceInspector > (m_xMCF->createInstanceWithContext( 
			OUString( RTL_CONSTASCII_USTRINGPARAM( "org.openoffice.InstanceInspector" ) ),
			m_xContext),
			UNO_QUERY_THROW );

where you see a member data "m_xInspector" has to be added in your component class. The good place for this code is naturally in the constructor of your component class.

Calling the corresponding Interface

If you want to call and see the Java Inspector Dialog, you have to put a code as follows

// C++
// Listing 3
// Java Introspection
	any <<= somethingToInspect;
	m_xInspector->inspect(any,OUString::createFromAscii("Inspector"));        
	xParentNode->appendChild(xChildMutTreeNode);

where you have to adapt the "somethingToInspect".

My own Inspector

I have already presented in this document my own inspector but it wasn't a component. Then it was only valuable when writing binary executable, not component. In this section I will show how to transform it as a component. Because Java Inspector is more advanced my component is only interesting when using old and inefficient computers where Java runs slowly. But for me it represents the only experience with writing a great component.

Documentation caution.png The code presented here is not safe. You can see many "FIXME" in the code. At the moment the version is labelled 0.4

This component is composed with two separate class (at the moment)

The ReflectionHelper class

This class is composed with two source files. See the corresponding code.

The Component

See the corresponding code.

The OOoBasic code and result

Calling this component is done with the code as follows :

'Listing 6
REM  *****  BASIC  *****
 
Sub demonstrateSimpleComponent
    Dim oSimpleComponent
	oSimpleComponent = CreateUnoService( "foo.Counter" )
	oSimpleComponent.myInspect(oSimpleComponent)
End Sub

which yields :

Our Inspector dialog

General Remarks

Please read carefully the code and search the "FIXME" to see what the limitations are. If you never press the "invoke" button, all is OK. If you want to see what happens when invoking please read below.

Documentation caution.png The "Invoke" button is not safe. Because starting with a Tree selection, I have to parse this selection to retrieve the name of the method. The code provided only works when no argument are present in the method.

Template:Documentation/Note

Managing exceptions

Transforming a component

Personal tools