SourceForge.net Logo

Chapter 6. Getting started with a Reflective JMI client

Getting started with a Typed JMI client explained typed JMI interfaces. These interfaces are generated according to the JMI mapping specification. As you may have observed all these interfaces extend the interfaces from javax.jmi.reflect packages, namely RefObject, RefClass, RefPackage. etc. These reflective interfaces provide the same functionality as the generated typed interfaces, but in a reflective manner. Values can be get and set with the methods refGetValue(), refSetValue(), operations can be invoked with refInvoke(), etc.

This chapter explains how to write an openMDX client using the Reflective JMI accessors. The examples used throughout this chapter are based on the model that has been introduced in Figure 2-1.

Before you start, please make sure that you have generated the JMI accessors from the lab model beforehand. A description of the lab model and how to generate the associated JMI accessors can be found in Introduction to the lab model. Please make sure that you are also familiar with the JMI mapping which is discussed in the same chapter.

With the generic accessor, openMDX offers an alternate way of generic programming. In fact, the JMI implementation is a wrapper on top of the generic accessor as shown in JMI Mapping Overview. The main difference between JMI reflective and the generic accessor is, that JMI is typesafe whereas the generic accessor is not. The generic accessor does not have any model information. This may improve performance in some situations. The other difference is, that JMI reflective is specified by the JMI specification, whereas the interfaces of the generic accessor, namely Object_1_0 and ObjectFactory_1_0 are not.

As always at the end of this chapter you will have the opportunity to practice what you have learnt in a lab exercise.

How to retrieve a package?

This is done exactly the same way as it is done for a Typed JMI client. Please refer to the section How to retrieve a package?.