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 import org.exoplatform.services.xml.querying.UniFormTransformationException; 6 import org.exoplatform.services.xml.querying.impl.xtas.resource.Resource; 7 import org.exoplatform.services.xml.querying.impl.xtas.resource.ResourceResolver; 8 9 13 public class ResourceInstruction extends Instruction { 14 15 private Object context; 16 17 20 public ResourceInstruction(Instruction instr) 21 { 22 super(instr); 23 } 24 25 public ResourceInstruction(String type, String match, UniFormTree newValue) throws InvalidStatementException 26 { 27 super(type, match, newValue); 28 } 29 30 public String getAsString() 31 { 32 String matchStr = ""; 33 if( match != null ) 34 matchStr = " resource=\"" + match + "\""; 35 36 return "<" + type + matchStr + ">" + 37 newValue.getAsString() + 38 "</" + type + ">"; 39 } 40 41 45 public void compile() throws InvalidStatementException 46 { 47 return; 48 } 49 50 54 public UniFormTree execute(UniFormTree input) throws InvalidSourceException, QueryRunTimeException 55 { 56 57 58 try { 59 60 Resource res = ResourceResolver.getInstance().getResource( match ); 61 res.setContext( context ); 62 63 if ( type == QueryType.CREATE ) { 64 65 72 73 WellFormedUniFormTree initTree = UniFormConverter.toWellForm(newValue); 74 res.create( initTree ); 76 77 return newValue; 78 79 } 80 81 if ( type == QueryType.DROP ) { 82 res.drop(); 83 return null; 84 } 85 } catch (UniFormTransformationException e) { 86 87 throw new InvalidSourceException("Bad Resource Instruction (possible newValue is not well-formed) : " + e); 88 89 } catch (Exception e) { 90 91 throw new QueryRunTimeException("Query Run Time Exception: " + e); 92 } 93 94 return null; 95 96 } 97 98 public void setContext(Object resourceContext) 99 { 100 this.context = resourceContext; 101 } 102 103 } 104 | Popular Tags |