org.formaria.data.pojo
Class PojoDataSource

java.lang.Object
  extended by org.formaria.data.DataSource
      extended by org.formaria.data.pojo.PojoDataSource
Direct Known Subclasses:
PersistentPojoDataSource

public class PojoDataSource
extends DataSource

A data source for working with POJOs. When the application is loaded the datasources are instantiated and in the case of a PojoDataSource the PojoRoot instance specified by the root element is instantiated and configured. The configuration project involves traversing the class hierarchy and setting up PojoModel nodes or proxies for each class in the pojo hierarchy. The configuration can specify naming overrides if the names established by reflection are not suitable

Copyright (c) Formaria Ltd., 2008
License: see license.txt


Field Summary
protected  java.util.Hashtable adapters
           
protected  java.util.Hashtable overrides
           
protected  PojoContext pojoContext
           
protected  DataModel pojoRootModel
           
 
Fields inherited from class org.formaria.data.DataSource
currentProject
 
Constructor Summary
PojoDataSource(Project project)
          Creates a new instance of PojoDataSource
 
Method Summary
protected  PojoAdapter createAdapter(java.lang.Class pojoClass)
          Creates and returns a new instance of PojoAdapter
protected  PojoModel createPojoModel(DataModel parent, java.lang.Object pojo)
          Creates and returns a new instance of PojoModel
protected  PojoModel createPojoModel(DataModel parent, java.lang.String subPath)
          Creates and returns a new instance of PojoModel
protected  PojoAdapter createProxyAdapter(java.lang.reflect.Proxy proxy)
          Creates and returns a new instance of PojoAdapter
protected  void customizeProperty(PojoAdapter adapter, XmlElement propertyElement)
           
 PojoAdapter getAdapter(java.lang.Object pojo)
           
protected  XmlElement getOverrideXml(PojoAdapter adapter)
          Gets the xml element describing overrides of the class being adapted by the specified adapter.
 PojoContext getPojoContext()
          Returns the pojo context object
protected  PojoContext instantiatePojoContext(java.lang.String className, java.lang.ClassLoader classLoader)
          Creates and returns new PojoContext object
 void loadTable(XmlElement source, DataModel model)
          Recursively load the model data
protected  void overrideAdapter(PojoAdapter adapter)
          Override the adapter specification loaded via reflection and add the customization specified by the configuration
 
Methods inherited from class org.formaria.data.DataSource
outputModel, outputModel, outputModel, read, read, readDataSource, setUseValueAsId, write, write
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

pojoContext

protected PojoContext pojoContext

pojoRootModel

protected DataModel pojoRootModel

overrides

protected java.util.Hashtable overrides

adapters

protected java.util.Hashtable adapters
Constructor Detail

PojoDataSource

public PojoDataSource(Project project)
Creates a new instance of PojoDataSource

Parameters:
project - the owner project
Method Detail

getPojoContext

public PojoContext getPojoContext()
Returns the pojo context object

Returns:
pojo context

instantiatePojoContext

protected PojoContext instantiatePojoContext(java.lang.String className,
                                             java.lang.ClassLoader classLoader)
                                      throws java.lang.Exception
Creates and returns new PojoContext object

Parameters:
className - the name of the class whose instance should be returned
classLoader - class loader object to load the specified class definition
Returns:
PojoContext object
Throws:
java.lang.Exception

loadTable

public void loadTable(XmlElement source,
                      DataModel model)
Recursively load the model data

Overrides:
loadTable in class DataSource
Parameters:
source - the source element
model - the model for the source element

getAdapter

public PojoAdapter getAdapter(java.lang.Object pojo)

createAdapter

protected PojoAdapter createAdapter(java.lang.Class pojoClass)
Creates and returns a new instance of PojoAdapter

Parameters:
pojoClass - pojoClass class to be adapted by the returned adapter
Returns:
PojoAdapter object

createProxyAdapter

protected PojoAdapter createProxyAdapter(java.lang.reflect.Proxy proxy)
Creates and returns a new instance of PojoAdapter

Parameters:
pojoClass - pojoClass class to be adapted by the returned adapter
Returns:
PojoAdapter object

createPojoModel

protected PojoModel createPojoModel(DataModel parent,
                                    java.lang.String subPath)
Creates and returns a new instance of PojoModel

Parameters:
parent - the parent model of the node which is to be created
subpath - String consisting of pojo properties, which must be in the format: propertyName(arguments...)[idx]
Returns:
PojoModel object

createPojoModel

protected PojoModel createPojoModel(DataModel parent,
                                    java.lang.Object pojo)
Creates and returns a new instance of PojoModel

Parameters:
parent - the parent model node
Returns:
PojoModel object

getOverrideXml

protected XmlElement getOverrideXml(PojoAdapter adapter)
Gets the xml element describing overrides of the class being adapted by the specified adapter.

Parameters:
adapter - the adapter object
Returns:
XmlElement object describing the overrides.

overrideAdapter

protected void overrideAdapter(PojoAdapter adapter)
Override the adapter specification loaded via reflection and add the customization specified by the configuration

Parameters:
adapter - the adapter being customized

customizeProperty

protected void customizeProperty(PojoAdapter adapter,
                                 XmlElement propertyElement)