dbXML API

org.dbxml.core.objects
Class Reflector

java.lang.Object
  |
  +--org.dbxml.core.objects.Reflector

public final class Reflector
extends java.lang.Object

Reflector is an Object reflection and method invocation utility for dbXML Reflectable implementations (XMLObjects).


Constructor Summary
Reflector()
           
Reflector(java.lang.Class c)
           
 
Method Summary
 void addMethod(java.lang.String name, java.lang.String[] params)
           
 void addMethod(java.lang.String name, java.lang.String[] params, java.lang.String[] defaults)
           
 void addMethod(java.lang.String name, java.lang.String[] params, java.lang.String[] defaults, java.lang.String[] errors)
          addMethod adds method meta data to the reflected Class definition.
 java.lang.String getParamDefault(java.lang.String method, java.lang.String param)
          getParamDefault returns the default value (String) for the specified parameter in the specified method.
 int getParamType(java.lang.String method, java.lang.String param)
          getParamType returns the parameter type for the specified parameter in the specified method.
 int getReturnType(java.lang.String method)
          getReturnType returns the return type for the specified method..
 java.lang.Object invoke(Reflectable obj, java.lang.String name, Args params)
          invoke invokes the named method against the specified Reflectable Object, passing to the method the set of specified parameters.
 java.lang.Object invoke(Reflectable obj, java.lang.String name, org.w3c.dom.Element element)
          invoke invokes the named method against the specified Reflectable Object, passing to the method the set of specified parameters.
 java.lang.Object invoke(Reflectable obj, java.lang.String name, java.lang.Object[] params)
          invoke invokes the named method against the specified Reflectable Object, passing to the method the set of specified parameters.
 java.lang.Object invoke(Reflectable obj, java.lang.String name, Variant[] args)
          invoke invokes the named method against the specified Reflectable Object, passing to the method the set of specified parameters.
 boolean isParamArray(java.lang.String method, java.lang.String param)
          isParamArray returns whether or not the parameter type for the specified parameter is an array type..
 java.lang.String[] listMethodParams(java.lang.String name)
          getMethodParams returns the names of the parameters that a method would require to be invoked.
 java.lang.String[] listMethods()
          getMethods returns the names of the publicly accessible methods for the reflected class.
 void reflect(java.lang.Class c)
          reflect performs an initial reflection against the Class that this Reflector will support.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Reflector

public Reflector()

Reflector

public Reflector(java.lang.Class c)
          throws XMLObjectException
Method Detail

reflect

public void reflect(java.lang.Class c)
             throws XMLObjectException
reflect performs an initial reflection against the Class that this Reflector will support. This method will not be capable of reflecting parameter names because the Java compiler throws them away. In order to create parameter name mappings, you must call addMethod.

addMethod

public void addMethod(java.lang.String name,
                      java.lang.String[] params,
                      java.lang.String[] defaults,
                      java.lang.String[] errors)
               throws XMLObjectException
addMethod adds method meta data to the reflected Class definition. The params that are passed in do not absolutely need to match the parameter names that are in the source code, but because they establish a contract between a set of named parameters and the parameter ordering for the method, it is your safest bet to match mapping parameters to source code parameters.
A method without parameter name mappings will not be accessible for invocation.
Parameters:
name - The method name
params - The parameter names
defaults - Default values for the parameters
errors - Errors values on conversion failure
Throws:
XMLObjectException - If a mapping error occurs

addMethod

public void addMethod(java.lang.String name,
                      java.lang.String[] params)
               throws XMLObjectException

addMethod

public void addMethod(java.lang.String name,
                      java.lang.String[] params,
                      java.lang.String[] defaults)
               throws XMLObjectException

listMethods

public java.lang.String[] listMethods()
getMethods returns the names of the publicly accessible methods for the reflected class.
Returns:
The method names

listMethodParams

public java.lang.String[] listMethodParams(java.lang.String name)
getMethodParams returns the names of the parameters that a method would require to be invoked. These names will be returned in the order by which they're specified upon invocation.
Parameters:
name - The method name
Returns:
The parameter names

getReturnType

public int getReturnType(java.lang.String method)
getReturnType returns the return type for the specified method..
Parameters:
method - The Method name
Returns:
The Result Class
See Also:
Types

getParamType

public int getParamType(java.lang.String method,
                        java.lang.String param)
getParamType returns the parameter type for the specified parameter in the specified method.
Parameters:
method - The Method name
param - The Parameter name
Returns:
The Parameter Class
See Also:
Types

getParamDefault

public java.lang.String getParamDefault(java.lang.String method,
                                        java.lang.String param)
getParamDefault returns the default value (String) for the specified parameter in the specified method.
Parameters:
method - The Method name
param - The Parameter name
Returns:
The default value

isParamArray

public boolean isParamArray(java.lang.String method,
                            java.lang.String param)
isParamArray returns whether or not the parameter type for the specified parameter is an array type..
Parameters:
method - The Method name
param - The Parameter name
Returns:
Whether or not the parameter is an array

invoke

public java.lang.Object invoke(Reflectable obj,
                               java.lang.String name,
                               java.lang.Object[] params)
                        throws XMLObjectException
invoke invokes the named method against the specified Reflectable Object, passing to the method the set of specified parameters.
Parameters:
obj - The target Reflectable
name - The method name
params - The parameter values
Returns:
The result of the method
Throws:
XMLObjectException - if an invocation error occurs

invoke

public java.lang.Object invoke(Reflectable obj,
                               java.lang.String name,
                               Variant[] args)
                        throws XMLObjectException
invoke invokes the named method against the specified Reflectable Object, passing to the method the set of specified parameters. This method will convert the String array in args to the appropriate Object types before invoking the method.
Parameters:
obj - The target Reflectable
name - The method name
args - The parameter values
Returns:
The result of the method
Throws:
XMLObjectException - if an invocation error occurs

invoke

public java.lang.Object invoke(Reflectable obj,
                               java.lang.String name,
                               Args params)
                        throws XMLObjectException
invoke invokes the named method against the specified Reflectable Object, passing to the method the set of specified parameters. This method will retrieve parameters by name from the Properties set, and convert them to a String array before invoking.
Parameters:
obj - The target Reflectable
name - The method name
params - The parameter values
Returns:
The result of the method
Throws:
XMLObjectException - if an invocation error occurs

invoke

public java.lang.Object invoke(Reflectable obj,
                               java.lang.String name,
                               org.w3c.dom.Element element)
                        throws XMLObjectException
invoke invokes the named method against the specified Reflectable Object, passing to the method the set of specified parameters. This method will retrieve parameters by name from the element's attribute set, and convert them to a String array before invoking.
Parameters:
obj - The target Reflectable
name - The method name
element - The Element to use for Attributes
Returns:
The result of the method
Throws:
XMLObjectException - if an invocation error occurs

dbXML API

Copyright (c) 1999-2001 The dbXML Group, All rights reserved