Package net.xoetrope.optional.data.pojo

Source Code of net.xoetrope.optional.data.pojo.XPersistentPojoDataSource

package net.xoetrope.optional.data.pojo;

import java.util.Enumeration;
import java.util.HashSet;
import java.util.Set;
import net.xoetrope.xml.XmlElement;
import net.xoetrope.xui.XProject;
import net.xoetrope.xui.data.XModel;

/**
* <p>A data source for working with Persistent POJOs. When the application is loaded the
* datasources are instantiated and in the case of a XPojoDataSource the
* XPojoRoot instance specified by the <code>root</code> element is
* instantiated and configured. The configuration project involves traversing
* the class hierarchy and setting up XPojoModel 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</p>
* <p>Copyright (c) Xoetrope Ltd., 2001-2007<br>
* License:      see license.txt
*/

public class XPersistentPojoDataSource extends XPojoDataSource
{     
  /**
   * Creates a new instance of XPersistentPojoDataSource
   * @param project the owner project
   */
  public XPersistentPojoDataSource( XProject project )
  {
    super( project );
  }

  /**
   * Creates and returns new XPersistenceController object
   * @param the name of the class, the instance of which should
   * be returned
   * @param classLoader ClassLoader object to load the specified
   * class defintion
   * @return XPersistentceController object
   */
  protected XPojoContext instantiatePojoContext( String className, ClassLoader classLoader )
  throws Exception
  {
    Object pojoContext = null;
    if ( classLoader != null )
      pojoContext = Class.forName( className, true, classLoader ).newInstance();
    else
      pojoContext = Class.forName( className ).newInstance();   
           
    return (XPersistenceController)pojoContext;
 
 
  /**
   * Creates and returns a new instance of XPersistentPojoAdapter
   * @param pojoClass the class to be adapted by the returned
   * adapter
   * @return XPersitentPojoAdapter object  
   */
  protected XPojoAdapter createAdapter( Class pojoClass )
  {
    return ( new XPersistentPojoAdapter( pojoClass, this ));
  }

  /**
   * Creates and returns a new instance of XPersitentPojoModel
   * @param parent the parent model of the model node
   * which is to be created
   * @param subpath String consisting of pojo properties,
   * must be in the format: propertyName(arguments...)[idx]
   * @return XPojoModel object
   */ 
  protected XPojoModel createPojoModel( XModel parent, String subPath )
  {
    return ( new XPersistentPojoModel( parent, subPath, this ));
  }
 
  /**
   * Creates and returns a new instance of XPojoModel
   * @param parent the parent model node
   * @pojo the underlying pojo
   * @return XPojoModel object
   */
  protected XPojoModel createPojoModel( XModel parent, Object pojo )
  {
    return ( new XPersistentPojoModel( parent, pojo, this ));   
 
 
  /**
   * Override the adapter specification loaded via reflection and add the
   * customization specified by the configuration
   * @param adapter the adapter being customized
   */
  protected void overrideAdapter( XPojoAdapter adapter )
  {
    XmlElement override = getOverrideXml( adapter );
    if ( override != null ) {
      boolean isDao = "true".equals( override.getAttribute( "dao" ));
      ((XPersistentPojoAdapter)adapter).setDao( isDao );
      super.overrideAdapter( adapter );
    }
  }
       
  /*
   * Customizes the given property, saves customization details in
   * the passed adapter object.
   * @param adapter adapter associated with type, the property of which
   * is being customized.
   * @param propertyElement xml element describing customization details.
   */
  protected void customizeProperty( XPojoAdapter adapter, XmlElement propertyElement )
  {
    super.customizeProperty( adapter, propertyElement );       
    if ( "property".equals( propertyElement.getName() )) {
     
      String txRequired = propertyElement.getAttribute( "lazy" );
      String propertyName = propertyElement.getAttribute( "id" );
      String getterSig = propertyElement.getAttribute( "getter" );
      String setterSig = propertyElement.getAttribute( "setter" );
     
      if ( "true".equals( txRequired )) {
        // save the getter info
        ((XPersistentPojoAdapter)adapter).setGetterTransaction( propertyName, getterSig );
        // save the setter info
        if ( setterSig != null )
          ((XPersistentPojoAdapter)adapter).setSetterTransaction( propertyName, setterSig );       
      }
      else if ( "false".equals( txRequired )) {
        // remove the getter info
        ((XPersistentPojoAdapter)adapter).unsetGetterTransaction( propertyName, getterSig );
        // remove the setter info
        if ( setterSig != null )
          ((XPersistentPojoAdapter)adapter).unsetSetterTransaction( propertyName, setterSig );
      }
    }
  }
   
}
TOP

Related Classes of net.xoetrope.optional.data.pojo.XPersistentPojoDataSource

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.