1 package org.exoplatform.services.xml.querying.impl.xtas; 2 3 import java.util.ArrayList ; 4 import org.exoplatform.services.xml.querying.InvalidStatementException; 5 import org.exoplatform.services.xml.querying.Statement; 6 7 15 abstract public class BaseStatement implements InstructionsSupport, Statement { 16 17 protected String destinationId; 18 19 protected String sourceId; 20 21 26 private ArrayList instructions = new ArrayList (); 27 28 30 31 32 public final String getSourceId() 33 { 34 return sourceId; 35 } 36 37 public final void setSourceId(String sourceId) 38 { 39 this.sourceId = sourceId; 40 } 41 42 public final String getDestinationId() 43 { 44 return destinationId; 45 } 46 47 public final void setDestinationId(String destinationId) 48 { 49 this.destinationId = destinationId; 50 } 51 52 public Instruction[] getInstructions( ) 53 { 54 Instruction[] ins = new Instruction[instructions.size()]; 55 for(int i=0; i<instructions.size(); i++) 56 ins[i] = (Instruction)instructions.get(i); 57 return ins; 58 } 60 61 public void addInstruction (String type, String match, UniFormTree newValue) throws InvalidStatementException 62 { 63 64 if( QueryType.isAtResource( type ) ) { 65 66 instructions.add( new ResourceInstruction( type, match, newValue ) ); 67 this.destinationId = match; 68 69 } else if( QueryType.isAtXml( type ) ) 70 instructions.add( new XMLInstruction( type, match, newValue ) ); 71 else 72 throw new InvalidStatementException("Add Instruction Error: Invalid instruction type '"+type+"'!"); 73 74 } 75 76 public Instruction pickNextInstruction() throws ForbiddenOperationException, InvalidStatementException 77 { 78 if( instructions.size() == 0 ) 79 throw new ForbiddenOperationException( "It is no more instructions!" ); 80 81 83 Instruction instr = (Instruction)instructions.get( 0 ); 84 85 87 instructions.remove(0); 88 return instr; 89 } 90 91 public String toString() 92 { 93 String srcStr = ""; 94 String destStr = ""; 95 96 if( sourceId != null ) 97 srcStr = " source=\"" + sourceId + "\""; 98 if( destinationId != null ) 99 destStr = " destination=\"" + destinationId + "\""; 100 101 String instrString = ""; 102 for(int i=0; i<instructions.size(); i++) 103 instrString += instructions.get(i); 104 105 return "<query" + srcStr + destStr + ">" + instrString + "</query>"; 106 } 107 108 109 } 110 | Popular Tags |