001: package com.xoetrope.data.pojo;
002:
003: import com.xoetrope.carousel.visualizer.TreeNodeCaption;
004: import java.lang.reflect.Method;
005: import net.xoetrope.xml.XmlElement;
006: import net.xoetrope.xui.XProject;
007: import net.xoetrope.xui.data.XModel;
008:
009: public class XPersistentPojoDataSourceEx extends XPojoDataSourceEx {
010:
011: /**
012: * Creates a new instance of XPersistentPojoDataSourceEx
013: * @param project the owner project
014: */
015: public XPersistentPojoDataSourceEx(XProject project) {
016: super (project);
017: }
018:
019: /**
020: * Adapts a POJO for use in the data visualiser.
021: * @param pojo the POJO to be adapted
022: * @param parentNode the parent model node
023: * @return model node wrapping the specified pojo
024: */
025: public XPojoModelVis adaptPojo(Object pojo, XModel parentNode) {
026: if (pojo == null)
027: return null;
028: // Do not adapt existing model nodes
029: if (pojo instanceof XPojoModelVis)
030: return (XPojoModelVis) pojo;
031: // Wrap the pojo instance.
032: XPojoModelVis model = new XPersistentPojoModelEx(parentNode,
033: pojo, this );
034: String value = getDispValue(pojo);
035: if (model != null)
036: ((TreeNodeCaption) model).setCaption(value + ": ");
037: return model;
038: }
039:
040: /**
041: * Adapts a POJO for use in the data visualiser
042: * @param method the method, the invocation of which returns the POJO
043: * to be adapted
044: * @param propertyName the property name of the parent node whose
045: * value is to be adapted
046: * @param parentNode the parent model node
047: * @return model node wrapping the specified pojo
048: */
049: public XPojoModelVis adaptPojo(Method gtr, Method str,
050: String propertyName, XModel parentNode) {
051: return (new XPersistentPojoModelEx(parentNode, gtr, str,
052: propertyName, this ));
053: }
054:
055: /**
056: * Adapts the specified POJO for use in the data visualizer.
057: * @param pojoClass the type of the POJO to be adapted
058: * @param propertyName the property name of the parent node whose
059: * value is to be adapted
060: * @param parentNode the parent model node
061: * @return model node wrapping the specified pojo
062: */
063: public XPojoModelVis adaptPojo(Class pojoClass,
064: String propertyName, XModel parentNode) {
065: return (new XPersistentPojoModelEx(parentNode, pojoClass,
066: propertyName, this ));
067: }
068:
069: /**
070: * Cutsomizes the specified adapter applying the changes from the propertyElement
071: * @param adapter the adapter to be customized
072: * @param propertyElement xml node describing customization
073: */
074: protected void customizeProperty(XPojoAdapterEx adapter,
075: XmlElement propertyElement) {
076: super .customizeProperty(adapter, propertyElement);
077: if ("property".equals(propertyElement.getName())) {
078:
079: String propertyName = propertyElement.getAttribute("id");
080: String getterSig = propertyElement.getAttribute("getter");
081: String txRequired = propertyElement.getAttribute("lazy");
082:
083: propertyName += XPojoAdapterEx.getSignature(getterSig);
084: if ("true".equals(txRequired))
085: ((XPersistentPojoAdapterEx) adapter)
086: .setTransaction(propertyName);
087: else if ("false".equals(txRequired))
088: ((XPersistentPojoAdapterEx) adapter)
089: .unsetTransaction(propertyName);
090: }
091: }
092:
093: /**
094: * Creates a new instance of XPersistentPojoAdapterEx
095: * @param pojoClass the class to be adapted
096: */
097: protected XPojoAdapterEx createAdapter(Class pojoClass) {
098: return (new XPersistentPojoAdapterEx(pojoClass, this));
099: }
100:
101: }
|