com.cosylab.jcosyne.client
Class Introspective

java.lang.Object
  extended bycom.cosylab.jcosyne.client.Introspective

public class Introspective
extends java.lang.Object

A collection of static utility functions for turning objects into textual representation.

Author:
Gasper Tkacik (gasper.tkacik@cosylab.com)

Constructor Summary
Introspective()
           
 
Method Summary
static java.lang.String createReport(java.lang.Object value)
          Turns an object into a string.
static java.lang.String extractAttributeName(java.lang.String s)
          Given a string of the form "A@B" extract "B".
static java.lang.String[] extractSpec(java.lang.String s)
          Extract a list of names separated by "@" character in string s.
static java.lang.Object extractValue(java.lang.Object holder, java.lang.String[] spec)
          Given a Java object and a list of names, try to recursively extract the instance refered to by the names.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Introspective

public Introspective()
Method Detail

extractValue

public static java.lang.Object extractValue(java.lang.Object holder,
                                            java.lang.String[] spec)
Given a Java object and a list of names, try to recursively extract the instance refered to by the names. For instance, if structure A contains array of structures B and we want to access field C of B at location 5, then passing A as the holder and passing { "5", "C" } as the list of names, will extract the desired object. Currently works for arrays of whatever dimension and class fields.

Parameters:
holder - the object instance that contains the instance that we want to extract
spec - array of names, that are resolved one-by-one on the holder
Returns:
the object referred to by the names

createReport

public static java.lang.String createReport(java.lang.Object value)
Turns an object into a string. In case of simple types, this is just the default string representation. In case of 1D or 2D array, tabular text format is used. In case of structure-like classes all accessible fields are printed as (name, value) list.

Parameters:
value - object for which to create a report
Returns:
the stringized object

extractAttributeName

public static java.lang.String extractAttributeName(java.lang.String s)
Given a string of the form "A@B" extract "B".

Parameters:
s - the concatenated string
Returns:
part following the "@" character or s, if no such character is included

extractSpec

public static java.lang.String[] extractSpec(java.lang.String s)
Extract a list of names separated by "@" character in string s. This is useful because the user can extract elements from structures or arrays by hierarchically naming them and separating names with "@".

Parameters:
s - string to parse
Returns:
array of name components, that can be passed to extractValue()