1 package org.exoplatform.services.xml.querying.impl.xtas; 2 3 import java.util.HashMap ; 4 import java.io.FileInputStream ; 5 import java.io.ByteArrayInputStream ; 6 import java.io.InputStream ; 7 import org.exoplatform.services.xml.querying.InvalidSourceException; 8 import org.exoplatform.services.xml.querying.InvalidStatementException; 9 import org.exoplatform.services.xml.querying.QueryRunTimeException; 10 import org.exoplatform.services.xml.querying.UniFormTransformationException; 11 12 17 abstract public class Instruction { 18 19 private final static String XTAS_XSL = "/xtas.xsl"; 20 21 protected static InstructionCompiler compiler; 22 23 protected String match; 24 protected UniFormTree newValue; 25 protected String type; 26 27 static { 28 29 try { 30 31 String xtasXsl = System.getProperty("xtas.xsl"); 32 InputStream is = null; 33 if( xtasXsl == null || xtasXsl.equals("") ) 34 is = Instruction.class.getResourceAsStream(XTAS_XSL); 35 else 36 is = new FileInputStream (xtasXsl); 37 38 compiler = new InstructionCompiler( is ); 39 40 } catch (Exception e) { 41 42 System.out.println("Instruction() create ERROR: " + e); 44 45 } 46 47 } 48 49 50 protected Instruction(String type, String match, UniFormTree newValue) throws InvalidStatementException 51 { 52 53 if( type == null || type.trim() == "") 54 throw new InvalidStatementException( "Query Type can not be NULL !" ); 55 56 this.type = type.toLowerCase(); 57 if( ! QueryType.exists(this.type) ) 58 throw new InvalidStatementException("Illegal query type '"+this.type+"' !"); 59 60 if( match == null || match.trim() == "") 61 throw new InvalidStatementException( "Match attribute is required for '"+type+"' statement"); 62 63 this.match = match; 64 65 try { 66 67 if (newValue == null) { 68 69 this.newValue = new UniFormTreeFragment (); 70 ((UniFormTreeFragment)this.newValue).init( new ByteArrayInputStream ( "".getBytes() ) ); 71 72 } else 73 this.newValue = newValue; 74 75 } catch (UniFormTransformationException e) { 76 77 System.out.println("Instruction() create error(UniFormTransformationException) : " + e); 79 80 } 81 82 } 83 84 87 protected Instruction(Instruction instr) 88 { 89 90 this.type = instr.type; 91 this.match = instr.match; 92 this.newValue = instr.newValue; 93 94 } 95 96 public UniFormTree getNewValue() 97 { 98 return newValue; 99 } 100 101 public String getMatch() 102 { 103 return match; 104 } 105 106 public String getType() 107 { 108 return type; 109 } 110 111 public boolean isAtResource() 112 { 113 return QueryType.isAtResource( type ); 114 } 115 116 public boolean isAtXml() 117 { 118 return QueryType.isAtXml( type ); 119 } 120 121 124 public String toString() 125 { 126 return getAsString(); 127 } 128 129 130 133 public abstract String getAsString(); 134 135 138 public abstract UniFormTree execute(UniFormTree input) throws InvalidSourceException, QueryRunTimeException; 139 140 144 public abstract void compile() throws InvalidStatementException; 145 146 147 151 public abstract void setContext(Object resourceContext); 152 153 } 154 | Popular Tags |