001 002package gudusoft.gsqlparser.pp.stmtformatter.builder; 003 004import gudusoft.gsqlparser.pp.para.GFmtOpt; 005import gudusoft.gsqlparser.pp.processor.ProcessorFactory; 006import gudusoft.gsqlparser.pp.stmtformatter.type.AbstractStmtFormatter; 007 008public class AbstractStmtFormatterBuilder<E extends AbstractStmtFormatter> 009{ 010 011 /** 012 * formatter option 013 */ 014 private GFmtOpt option; 015 016 public E build( ) 017 { 018 E formatter = this.newInstanceFormatter( ); 019 formatter.setSessionId( this.getOption( ).sessionId ); 020 this.initCommonProcessorsForFormatter( formatter ); 021 this.initSpecialProcessorForFormatter( formatter ); 022 return formatter; 023 } 024 025 /** 026 * initialize the common processors 027 * 028 * @param formatter 029 */ 030 protected void initCommonProcessorsForFormatter( E formatter ) 031 { 032 formatter.addExpressionProcessor( ProcessorFactory.createExpressionProcessor( getOption( ) ) ); 033 } 034 035 /** 036 * initialize the special processors 037 * 038 * @param formatter 039 */ 040 protected void initSpecialProcessorForFormatter( E formatter ) 041 { 042 043 } 044 045 /** 046 * create the formatter, subclass should override this template method to 047 * create a new instance 048 * 049 * @return 050 */ 051 protected E newInstanceFormatter( ) 052 { 053 return null; 054 } 055 056 public GFmtOpt getOption( ) 057 { 058 return option; 059 } 060 061 public void setOption( GFmtOpt option ) 062 { 063 this.option = option; 064 } 065 066}