You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 3 Next »

During the manipulation process, iPOJO gathers information about the manipulated classes. These metadata are stored inside the bundle manifest and are used to avoid reflection on the manipulated class. By using these metadata, your handler can check that the implementation class contains required fields, methods, interface ...

Contained information

Manipulation metadata contains:

  • Interfaces implemented by component type implementation
  • Fields of the component type implementation
  • Methods of the component type implementation

Field Metadata contains field name and type. Method Metadata contains method name, the sorted list of argument types and return type.

Building Manipulation Metadata

Manipulation can be obtained from the component metadata. Component Metadata are obtained in argument of the 'configure' method of your handler.

public void configure(InstanceManager im, Element metadata, Dictionary configuration)  {
    ...
    ManipulationMetadata manip = new ManipulationMetadata(metadata);
    ...
}

Getting Metadata

From the manipulation metadata, you can query manipulation information by using following methods:

  • MethodMetadata[] getMethods() : Get all methods

  • FieldMetadata[] getFields() : Get all fields

  • String[] getInterfaces() : Get all implemented interfaces

  • FieldMetadata getField(String name) : Look for the field with the given name. Returns null if not found.
  • FieldMetadata getField(String name, String type): Look for the field with the given name and type. Returns null if not found.
  • boolean isInterfaceImplemented(String itf) : Is the given interface name implemented by the manipulated class.
  • MethodMetadata getMethod(String name) :  Look for the method with the given name. Returns null if not found. Returns the first found if several method match.
  • MethodMetadata[] getMethods(String name) : Look for all methods with the given name. Returns an empty array if not found.

  • MethodMetadata getMethod(String name, String[] types) : : Look for the method with the given name and argument type list. Returns null if not found.

From a Field Metadata object, you can obtain the field name, type, and 'reflective' type. From a Method Metadata object, you can obtain the method name, the argument type array, and the returned type ('void' for void method).

Creating Callback from Manipulation Metadata

You often need to invoke method on the POJO objects. iPOJO provides an helper class, named Callback, allow you to manage this invocation easily. You can obtain a Callback object from the Method Metadata. By this way, you are sure that the method exists in the implementation. To create the callback, use the following code:

    ManipulationMetadata manip = new ManipulationMetadata(metadata);
    MethodMetadata method = manip.getMethod("your_method_name");
    Callback cb = new Callback(method, im);

Then you can directly invoke your method:

    ...
    Object[] args = ...;  // Build your argument array
    cb.call(args);
    ...

Types & Reflective Types

When querying field (or a method argument) type, the API will return following code identifier:

  • For primitive types : int, long, short, byte, char, double, float, boolean
  • For primitives type arrays : int[], long[], short[], byte[], char[], double[], float[], boolean[]

  • For object : qualified class name as java.lang.String
  • For object arrays : the qualified class name of the content type followed by [] as java.lang.String[]

Array types are different from Java internal/reflective array types. To get the internal/reflective array type for field type you can use the getReflectiveType method.

Error CSS Stylesheet macro - Import URL 'http://people.apache.org/~clement/ipojo/ipojo.css' is not on the allowlist. If you want to include this content, contact your Confluence administrator to request adding this URL to the Allowlist.

Overview
Getting Started
User Guide
Tools
Developer Guide
Misc & Contact
Experimentation

  • No labels