001 package railo.transformer.bytecode.statement.tag; 002 003 import railo.runtime.exp.TemplateException; 004 import railo.transformer.bytecode.BytecodeContext; 005 import railo.transformer.bytecode.BytecodeException; 006 import railo.transformer.bytecode.Position; 007 import railo.transformer.bytecode.Statement; 008 import railo.transformer.bytecode.statement.FlowControlFinal; 009 import railo.transformer.bytecode.visitor.ParseBodyVisitor; 010 011 public final class TagOutput extends TagGroup { 012 013 public static final int TYPE_QUERY = 0; 014 public static final int TYPE_GROUP = 1; 015 public static final int TYPE_INNER_GROUP = 2; 016 public static final int TYPE_INNER_QUERY = 3; 017 public static final int TYPE_NORMAL= 4; 018 019 020 private int type; 021 022 023 public TagOutput(Position start,Position end) { 024 super(start,end); 025 } 026 027 028 public static TagOutput getParentTagOutputQuery(Statement stat) throws BytecodeException { 029 Statement parent=stat.getParent(); 030 if(parent==null) throw new BytecodeException("there is no parent output with query",null); 031 else if(parent instanceof TagOutput) { 032 if(((TagOutput)parent).hasQuery()) 033 return ((TagOutput)parent); 034 } 035 return getParentTagOutputQuery(parent); 036 } 037 038 public void setType(int type) { 039 this.type=type; 040 } 041 042 043 /** 044 * 045 * @see railo.transformer.bytecode.statement.tag.TagBase#_writeOut(org.objectweb.asm.commons.GeneratorAdapter) 046 */ 047 public void _writeOut(BytecodeContext bc) throws BytecodeException { 048 boolean old; 049 switch(type) { 050 case TYPE_GROUP: 051 old = bc.changeDoSubFunctions(false); 052 TagGroupUtil.writeOutTypeGroup(this,bc); 053 bc.changeDoSubFunctions(old); 054 break; 055 case TYPE_INNER_GROUP: 056 old = bc.changeDoSubFunctions(false); 057 TagGroupUtil.writeOutTypeInnerGroup(this,bc); 058 bc.changeDoSubFunctions(old); 059 break; 060 case TYPE_INNER_QUERY: 061 old = bc.changeDoSubFunctions(false); 062 TagGroupUtil.writeOutTypeInnerQuery(this,bc); 063 bc.changeDoSubFunctions(old); 064 break; 065 case TYPE_NORMAL: 066 writeOutTypeNormal(bc); 067 break; 068 case TYPE_QUERY: 069 old = bc.changeDoSubFunctions(false); 070 TagGroupUtil.writeOutTypeQuery(this,bc); 071 bc.changeDoSubFunctions(old); 072 break; 073 074 default: 075 throw new BytecodeException("invalid type",getStart()); 076 } 077 } 078 079 080 081 082 083 084 085 086 087 /** 088 * write out normal query 089 * @param adapter 090 * @throws TemplateException 091 */ 092 private void writeOutTypeNormal(BytecodeContext bc) throws BytecodeException { 093 ParseBodyVisitor pbv=new ParseBodyVisitor(); 094 pbv.visitBegin(bc); 095 getBody().writeOut(bc); 096 pbv.visitEnd(bc); 097 } 098 099 100 @Override 101 public short getType() { 102 return TAG_OUTPUT; 103 } 104 105 106 @Override 107 public FlowControlFinal getFlowControlFinal() { 108 return null; 109 } 110 111 }