1 package org.exoplatform.services.xml.querying.impl.xtas; 2 import org.exoplatform.services.xml.querying.InvalidSourceException; 3 import org.exoplatform.services.xml.querying.InvalidStatementException; 4 import org.exoplatform.services.xml.querying.QueryRunTimeException; 5 6 10 public class XMLInstruction extends Instruction { 11 12 private static QueryProcessor processor = QueryProcessorFactory.getInstance().getProcessor(); 13 Command command; 14 15 18 public XMLInstruction(Instruction instr) 19 { 20 super(instr); 21 } 22 23 public XMLInstruction(String type, String match, UniFormTree newValue) throws InvalidStatementException 24 { 25 super(type, match, newValue); 26 } 27 28 public String getAsString() 29 { 30 31 String matchStr = ""; 32 if( match != null ) 33 matchStr = " xpath=\"" + match + "\""; 34 35 return "<" + type + matchStr + ">" + 36 newValue.getAsString() + 37 "</" + type + ">"; 38 } 39 40 44 public void compile() throws InvalidStatementException 45 { 46 this.command = compiler.compile( getAsString() ); 47 processor.init(command); 48 } 51 52 55 public String getCommandAsString() 56 { 57 return command.toString(); 58 } 59 60 64 public UniFormTree execute(UniFormTree input) throws InvalidSourceException, QueryRunTimeException 65 { 66 if( input == null ) 67 throw new InvalidSourceException("Query execution Error: XTAS Source Can Not be NULL !"); 68 if( command == null ) 69 throw new QueryRunTimeException("Query execution Error: Command has not be created, call compile() first!"); 70 71 return processor.process( command, input ); 72 } 73 74 public void setContext(Object resourceContext) 75 {} 76 77 } 78 | Popular Tags |