com.partnersoft.data
Class PathedIntrospector

java.lang.Object
  extended by com.partnersoft.data.PathedIntrospector

public class PathedIntrospector
extends java.lang.Object

A tool that simplifies the use of Java Introspection to get and put object properties and run methods.

This is a very useful tool, but embodies some complex abstract concepts, so was hard to name and a bit hard to explain. On the other hand, using it is pretty simple.

A common problem when building configuration-driven interfaces and reports is retrieving objects from within a complex Object graph using named paths. Straight Java or script code tends to be fragile when confronted with nulls anywhere along the path of retrieval. Also, datatype conversion is so common that it helps to build that in as well and reduce the amount of code required.

This was originally solved at Partner using the original 3.x Cog, but Cog has gone on to be more of a generic data structure and serialization framework and has drifted from this task.

PathedIntrospector is designed specifically to allow you to put and get properties and run methods using Path (or path Strings), while insulating the developer as much as possible from dealing with nulls and datatype conversion. This is a "fuzzy" approach, designed to be robust rather than correct. Properties that are missing will always return some kind of valid default value rather than breaking with a NullPointerException or similar error. The downside of this approach is that you lose both compiler-level and runtime checking and so it may not be obvious when something is misconfigured or broken.

Copyright 2009 Partner Software, Inc.

Version:
$Id$
Author:
Paul Reavis

Constructor Summary
PathedIntrospector(java.lang.Object root)
          Creates a new PathedIntrospector using the given root object.
 
Method Summary
 void copy(java.lang.String originalPropertyName, java.lang.String newPropertyName)
          Copies a property value to a new name.
 boolean getBoolean(java.lang.String propertyPath)
           
 double getDouble(java.lang.String propertyPath)
           
 float getFloat(java.lang.String propertyPath)
           
 int getInt(java.lang.String propertyPath)
           
 long getLong(java.lang.String propertyPath)
           
 java.lang.Object getObject(Path propertyPath)
           
 java.lang.Object getObject(java.lang.String propertyPath)
           
 java.lang.Object getRoot()
           
 java.lang.String getString(Path propertyPath)
           
 java.lang.String getString(java.lang.String... propertyPaths)
           
 java.lang.String getString(java.lang.String propertyPath)
           
 void move(java.lang.String originalPropertyName, java.lang.String newPropertyName)
          Changes the name of a property, "moving" its value.
 void putBoolean(java.lang.String propertyPath, boolean value)
           
 void putDouble(java.lang.String propertyPath, double newValue)
           
 void putFloat(java.lang.String propertyPath, float newValue)
           
 void putInt(java.lang.String propertyPath, int newValue)
           
 void putLong(java.lang.String propertyPath, long newValue)
           
 void putObject(Path propertyPath, java.lang.Object newValue)
           
 void putObject(java.lang.String propertyPath, java.lang.Object newValue)
           
 void putString(java.lang.String propertyPath, java.lang.String newValue)
           
 void remove(java.lang.String propertyName)
          Removes a property by putting its value to null.
 void setRoot(java.lang.Object newRoot)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PathedIntrospector

public PathedIntrospector(java.lang.Object root)
Creates a new PathedIntrospector using the given root object.

Method Detail

getObject

public java.lang.Object getObject(java.lang.String propertyPath)

getObject

public java.lang.Object getObject(Path propertyPath)

putObject

public void putObject(java.lang.String propertyPath,
                      java.lang.Object newValue)

putObject

public void putObject(Path propertyPath,
                      java.lang.Object newValue)

getInt

public int getInt(java.lang.String propertyPath)

putInt

public void putInt(java.lang.String propertyPath,
                   int newValue)

getLong

public long getLong(java.lang.String propertyPath)

putLong

public void putLong(java.lang.String propertyPath,
                    long newValue)

getFloat

public float getFloat(java.lang.String propertyPath)

putFloat

public void putFloat(java.lang.String propertyPath,
                     float newValue)

getDouble

public double getDouble(java.lang.String propertyPath)

putDouble

public void putDouble(java.lang.String propertyPath,
                      double newValue)

getString

public java.lang.String getString(java.lang.String propertyPath)

getString

public java.lang.String getString(java.lang.String... propertyPaths)

getString

public java.lang.String getString(Path propertyPath)

putString

public void putString(java.lang.String propertyPath,
                      java.lang.String newValue)

getBoolean

public boolean getBoolean(java.lang.String propertyPath)

putBoolean

public void putBoolean(java.lang.String propertyPath,
                       boolean value)

move

public void move(java.lang.String originalPropertyName,
                 java.lang.String newPropertyName)
Changes the name of a property, "moving" its value.


copy

public void copy(java.lang.String originalPropertyName,
                 java.lang.String newPropertyName)
Copies a property value to a new name.


remove

public void remove(java.lang.String propertyName)
Removes a property by putting its value to null.


getRoot

public java.lang.Object getRoot()

setRoot

public void setRoot(java.lang.Object newRoot)