DataEntryService.java :  » XML-UI » xui32 » com » xoetrope » service » data » Java Open Source

Java Open Source » XML UI » xui32 
xui32 » com » xoetrope » service » data » DataEntryService.java
package com.xoetrope.service.data;

import java.io.StringReader;
import net.xoetrope.optional.data.XOptionalDataSource;
import net.xoetrope.optional.service.ServiceContext;
import net.xoetrope.optional.service.ServiceProxy;
import net.xoetrope.optional.service.ServiceProxyArgs;
import net.xoetrope.optional.service.ServiceProxyException;
import net.xoetrope.optional.service.XRouteManager;
import net.xoetrope.xml.XmlElement;
import net.xoetrope.xml.XmlSource;
import net.xoetrope.xui.XProject;
import net.xoetrope.xui.XProjectManager;
import net.xoetrope.xui.data.XBaseModel;

/**
 * The basic ServiceProxy class which needs to be subclassed in order to carry out 
 * transactional operations on a database connection. This class expects an
 * XModel to be passed in the pass param specified by the ARG_NAME_MODELPARAM
 * parameter. This class then loads the model into a temporary XModel and calls
 * the processQueries function which should be overloaded in the derived class.
 *
 * <p> Copyright (c) Xoetrope Ltd., 2001-2006, This software is licensed under
 * the GNU Public License (GPL), please see license.txt for more details. If
 * you make commercial use of this software you must purchase a commercial
 * license from Xoetrope.</p>
 * <p> $Revision: 1.6 $</p>
 */
public class DataEntryService extends ServiceProxy 
{  
  /**
   * The name of the parameter which stores the model data.
   */
  public static final String ARG_NAME_MODELPARAM = "dataentry:modelparam";
  
  /**
   * The XModel object created from the passed XML
   */
  protected XBaseModel dataModel;

  protected XProject currentProject = XProjectManager.getCurrentProject();

  /**
   * Call this proxy with the specified arguments
   * @return the result of the call 
   * @param context The ServiceContext contain pass and return parameters
   * @param method the name of the service being called
   * @throws net.xoetrope.optional.service.ServiceProxyException Throw an exception if there is a problem with the call
   */
  public Object call( String method, ServiceContext context ) throws ServiceProxyException
  {
    if ( side == XRouteManager.SERVER_SIDE ) {
      loadModel( context );
      processQueries( method, context );
    }
    return callNextProxy( method, context, null );
  }
  
  /**
   * Needs to be overloaded by the subclass so that queries can be batched in transactions
   * @param method The name of the service being called
   * @param context The ServiceContext object
   */
  protected void processQueries( String method, ServiceContext context )
  {    
  }
  
  /**
   * Retrieve the model XML and load it into the dataModel variable
   * @param context The ServiceContext instance
   */
  protected void loadModel( ServiceContext context )
  {
    ServiceProxyArgs args = context.getArgs();
    String modelParamName = ( String ) args.getPassParam( ARG_NAME_MODELPARAM );
    String modelData = ( String ) args.getPassParam( modelParamName );
    dataModel = new XBaseModel();
    
    StringReader sr = new StringReader( modelData );
    XmlElement ele = XmlSource.read( sr );

    if ( ele != null ) {
      XOptionalDataSource ds = new XOptionalDataSource( currentProject );
      ds.loadTable( ele, dataModel );
    }
  }      
}
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.