Package org.jostraca.process

Source Code of org.jostraca.process.TemplateHandlerSupport

/*
* Name:    TemplateHandlerSupport
* Authors: Richard Rodger
*
* Copyright (c) 2004 Richard Rodger
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published
* by the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
*/


// package
package org.jostraca.process;


// import
import org.jostraca.Template;
import org.jostraca.util.UserMessageHandler;
import org.jostraca.util.CommandLineUserMessageHandler;

import org.jostraca.util.Internal;

import java.util.List;
import java.util.ArrayList;
import java.util.Iterator;


/** Support classe for template handler implementations.
*/
public abstract class TemplateHandlerSupport implements TemplateHandler {   


  // create a cmd line user msg handler by default
  protected UserMessageHandler iUserMessageHandler = new CommandLineUserMessageHandler();


  public TemplateHandlerSupport() {
    // do nothing
  }


  public void setUserMessageHandler( UserMessageHandler pUserMessageHandler ) {
    iUserMessageHandler = (UserMessageHandler) Internal.null_arg( pUserMessageHandler );
  }


  public void process( Template pTemplate ) {
    Template tm = (Template) Internal.null_arg( pTemplate );
    processImpl( tm );
  }

  public void complete( List pTemplateList ) {
    List tmlist = (List) Internal.null_arg( pTemplateList );

    ArrayList validtmlist = new ArrayList();
    for( Iterator tmT = tmlist.iterator(); tmT.hasNext(); ) {
      Object tmo = tmT.next();

      if( null != tmo && tmo instanceof Template ) {
        validtmlist.add( tmo );
      }
      else {
        throw ProcessException.CODE_not_tm_complete( "object", String.valueOf(tmo) );
      }
    }

    completeImpl( validtmlist );
  }


  public String toString() {
    return super.toString();
  }

  protected abstract void processImpl( Template pTemplate );
  protected abstract void completeImpl( List pTemplateList );

}




TOP

Related Classes of org.jostraca.process.TemplateHandlerSupport

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.