1 package org.exoplatform.services.xml.querying.impl.xtas; 2 3 import java.io.ByteArrayInputStream ; 4 import org.exoplatform.services.xml.querying.InvalidStatementException; 5 import org.exoplatform.services.xml.querying.UniFormTransformationException; 6 7 22 23 public class SimpleStatement extends BaseStatement { 24 25 28 public SimpleStatement(String type, String match, UniFormTree newValue, String source, String destination) throws InvalidStatementException 29 { 31 32 try { 33 34 if( newValue == null ) { 35 newValue = new UniFormTreeFragment(); 36 ((UniFormTreeFragment)newValue).init( new ByteArrayInputStream ("".getBytes()) ); 37 } 38 39 } catch (Exception e) { 40 throw new InvalidStatementException("Create SimpleStatement: could not create UniFormTree! Reason: "+e); 41 } 42 43 this.sourceId = source; 44 this.destinationId = destination; 45 46 addInstruction( type, match, newValue ); 47 48 } 49 50 51 public SimpleStatement(String type, String match, String value, String source, String destination) throws InvalidStatementException, UniFormTransformationException 52 { 53 UniFormTreeFragment newValue = new UniFormTreeFragment (); 54 if (value != null) 55 newValue.init( new ByteArrayInputStream (value.getBytes()) ); 56 else 57 newValue.init( new ByteArrayInputStream ("".getBytes()) ); 58 59 this.sourceId = source; 60 this.destinationId = destination; 61 62 addInstruction( type, match, newValue ); 64 65 } 66 67 68 public SimpleStatement(String queryType, String match, String value) throws InvalidStatementException, UniFormTransformationException 69 { 70 this(queryType, match, value, null, null); 71 } 72 73 74 public SimpleStatement(String queryType, String match) throws InvalidStatementException, UniFormTransformationException 75 { 76 this(queryType, match, (String )null, null, null); 77 } 78 79 80 public SimpleStatement() throws InvalidStatementException 81 { 82 this(QueryType.SELECT, "/", (UniFormTreeFragment)null, null, null); 83 } 84 85 public static SimpleStatement select(String match, String source) throws InvalidStatementException 86 { 87 return select(match, source, null); 88 } 89 90 public static SimpleStatement select(String match) throws InvalidStatementException 91 { 92 return select(match, null, null); 93 } 94 95 public static SimpleStatement select(String match, String source, String destination) throws InvalidStatementException 96 { 97 if( match == null || match.length() == 0 ) 98 match = "/"; 99 return new SimpleStatement( QueryType.SELECT, match, (UniFormTreeFragment)null, source, destination); 100 } 101 102 public static SimpleStatement create(String name, String initXml) throws InvalidStatementException, UniFormTransformationException 103 { 104 return new SimpleStatement( QueryType.CREATE, name, initXml, null, name); 105 } 106 107 public static SimpleStatement create(String name, UniFormTree initXml) throws InvalidStatementException, UniFormTransformationException 108 { 109 return new SimpleStatement( QueryType.CREATE, name, initXml, null, name); 110 } 111 112 public static SimpleStatement drop(String name) throws InvalidStatementException 113 { 114 return new SimpleStatement( QueryType.DROP, name, (UniFormTreeFragment)null, null, name); 115 } 116 117 public static SimpleStatement append(String match, String destination, UniFormTree value) throws InvalidStatementException 118 { 119 return new SimpleStatement( QueryType.APPEND, match, value, destination, destination); 120 } 121 122 public static SimpleStatement append(String match, String destination, String value) throws InvalidStatementException, UniFormTransformationException 123 { 124 return new SimpleStatement( QueryType.APPEND, match, value, destination, destination); 125 } 126 127 public static SimpleStatement update(String match, String destination, UniFormTree value) throws InvalidStatementException 128 { 129 return new SimpleStatement( QueryType.UPDATE, match, value, destination, destination); 130 } 131 132 public static SimpleStatement update(String match, String destination, String value) throws InvalidStatementException, UniFormTransformationException 133 { 134 return new SimpleStatement( QueryType.UPDATE, match, value, destination, destination); 135 } 136 137 public static SimpleStatement delete(String match, String destination) throws InvalidStatementException 138 { 139 return new SimpleStatement( QueryType.DELETE, match, (UniFormTreeFragment)null, destination, destination); 140 } 141 142 } 143 | Popular Tags |