Difference between revisions of "Writing Professional Components"
SergeMoutou (Talk | contribs) m (→The OOoBasic Code and Result) |
SergeMoutou (Talk | contribs) m (→General Remarks) |
||
Line 78: | Line 78: | ||
==General Remarks== | ==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. | 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|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 | + | {{Documentation/Caution|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 parsing code provided only works when no argument is present in the method.}} |
{{Documentation/Note|The name of the service is "foo.Counter". It would be better to change it.}} | {{Documentation/Note|The name of the service is "foo.Counter". It would be better to change it.}} | ||
{{Documentation/Note|You cannot walk through the tree at the moment. The invoke button is only present for tests.}} | {{Documentation/Note|You cannot walk through the tree at the moment. The invoke button is only present for tests.}} |
Revision as of 17:14, 4 August 2009
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.
Contents
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 Inspector.uno.rdb with extension manager. This task was easy with old versions (I think before 3.0) because a tree was available in the extension manager. When done, use the 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 than my component it 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.
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. This class is under construction particularly the
// C++ // Listing void getTypeAndValue(Any toInspect);
method. Its code is running but this method has to be the main entry of the class. And it is also called every time you invoke (see below) and this is not a good thing because it is perturbing the member data of the class. In other word there is a problem of conception here !
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 :
When invoking the selected "getSupportedMethodNames()" you see the result in the text control : "LosingFocus" and "Invoke". That means invoke is partially working.
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.
Template:Documentation/Note Template:Documentation/Note
Managing exceptions
Transforming a component
When transforming a component in a binary executable, the first problem is the service manager. The component context allows you to retrieve a com.sun.star.lang.XMultiComponentFactory while a binary executable only works with com.sun.star.lang.XMultiServiceFactory. See The Component Helper and the Binary Executable Helper.