/*
* 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.format.FormatManager;
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 mUserMessageHandler = new CommandLineUserMessageHandler();
protected FormatManager mFormatManager;
public TemplateHandlerSupport() {
// do nothing
}
public void setUserMessageHandler( UserMessageHandler pUserMessageHandler ) {
mUserMessageHandler = (UserMessageHandler) Internal.null_arg( pUserMessageHandler );
}
public void setFormatManager( FormatManager pFormatManager ) {
mFormatManager = pFormatManager;
}
public void process( Template pTemplate ) throws Exception {
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 ) throws Exception;
protected abstract void completeImpl( List pTemplateList );
}