001package gudusoft.gsqlparser.stmt;
002
003import gudusoft.gsqlparser.*;
004import gudusoft.gsqlparser.nodes.TExpression;
005import gudusoft.gsqlparser.nodes.TStatementListSqlNode;
006import gudusoft.gsqlparser.nodes.TParseTreeVisitor;
007
008/**
009 * Represents ELSEIF ... THEN ... in if statement.
010 */
011
012public class TElsifStmt extends TCustomSqlStatement {
013    public TElsifStmt(){
014        this(EDbVendor.dbvoracle);
015    }
016     public TElsifStmt(EDbVendor dbvendor){
017        super(dbvendor);
018        sqlstatementtype = ESqlStatementType.sst_elsifstmt;
019        }
020
021    void buildsql() {
022    }
023
024    void clear() {
025    }
026
027    String getasprettytext() {
028        return "";
029    }
030
031    void iterate(TVisitorAbs pvisitor) {
032    }
033
034    private TExpression condition = null;
035
036    private TStatementList thenStatements = null;
037
038    /**
039     *
040     * @return the statements after the THEN keyword
041     */
042    public TStatementList getThenStatements() {
043        if (thenStatements == null){
044          thenStatements = new  TStatementList();
045        }
046        return thenStatements;
047    }
048    
049    /**
050     * 
051     * @return    If and only if the value of this expression is TRUE,
052     * the statements following THEN execute
053     */
054    public TExpression getCondition() {
055        return condition;
056    }
057
058    private TStatementListSqlNode thenStmts = null;
059
060    public void init(Object arg1)
061    {
062        condition = (TExpression)arg1;
063    }
064
065    public void init(Object arg1,Object arg2)
066    {
067        condition = (TExpression)arg1;
068        thenStmts = (TStatementListSqlNode)arg2;
069    }
070
071    public int doParseStatement(TCustomSqlStatement psql) {
072        super.doParseStatement(psql);
073        condition.doParse(this,ESqlClause.unknown);
074                if (thenStmts != null) {
075                        thenStmts.doParse(this,ESqlClause.unknown);
076                        for(int i=0;i<thenStmts.size();i++){
077                                this.getThenStatements().add(thenStmts.getStatementSqlNode(i).getStmt());
078                        }
079                }
080        return 0;
081    }
082
083    public void accept(TParseTreeVisitor v){
084        v.preVisit(this);
085        v.postVisit(this);
086    }
087
088    public void acceptChildren(TParseTreeVisitor v){
089        v.preVisit(this);
090        condition.acceptChildren(v);
091        thenStatements.acceptChildren(v);
092        v.postVisit(this);
093    }
094
095    public void setCondition(TExpression condition) {
096        this.condition = condition;
097    }
098
099    public void setThenStatements(TStatementList thenStatements) {
100        this.thenStatements = thenStatements;
101    }
102}