KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > exoplatform > services > xml > querying > impl > xtas > SimpleStatement


1 package org.exoplatform.services.xml.querying.impl.xtas;
2
3 import java.io.ByteArrayInputStream JavaDoc;
4 import org.exoplatform.services.xml.querying.InvalidStatementException;
5 import org.exoplatform.services.xml.querying.UniFormTransformationException;
6
7 /**
8  * XTAS query statement
9  * with only one instruction inside
10  *
11  * The queryStatement is the data for the XTAS-Query
12  * queryType - see <code>QueryType</code>
13  * match (XPath) expression - *match* attribute in XSLT's xsl:template element
14  * (XSLT uses the expression language defined by XPath)
15  * - or Path|URI for query at resource (create,drop)
16  * value for update - convertable to Result Tree Fragment (in XSLT terms)
17  * source - resource id for the XTAS source
18  * destination - resource id for the XTAS destination
19  *
20  * @version $Id: SimpleStatement.java 566 2005-01-25 12:50:49Z kravchuk $
21  */

22
23 public class SimpleStatement extends BaseStatement {
24
25     /**
26      * Builds query statement from scratch
27      * */

28     public SimpleStatement(String JavaDoc type, String JavaDoc match, UniFormTree newValue, String JavaDoc source, String JavaDoc destination) throws InvalidStatementException
29     // ParserConfigurationException, SAXException, IOException, TransformerException,
30
{
31
32         try {
33
34            if( newValue == null ) {
35               newValue = new UniFormTreeFragment();
36               ((UniFormTreeFragment)newValue).init( new ByteArrayInputStream JavaDoc("".getBytes()) );
37            }
38
39         } catch (Exception JavaDoc 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     /** Builds query statement from scratch */
51     public SimpleStatement(String JavaDoc type, String JavaDoc match, String JavaDoc value, String JavaDoc source, String JavaDoc destination) throws InvalidStatementException, UniFormTransformationException
52     {
53         UniFormTreeFragment newValue = new UniFormTreeFragment ();
54         if (value != null)
55             newValue.init( new ByteArrayInputStream JavaDoc(value.getBytes()) );
56         else
57             newValue.init( new ByteArrayInputStream JavaDoc("".getBytes()) );
58
59         this.sourceId = source;
60         this.destinationId = destination;
61
62 // addInstruction( Instruction.create (type, match, newValue) );
63
addInstruction( type, match, newValue );
64
65     }
66
67     /** Builds *update* - like (with updating value) query statement */
68     public SimpleStatement(String JavaDoc queryType, String JavaDoc match, String JavaDoc value) throws InvalidStatementException, UniFormTransformationException
69     {
70          this(queryType, match, value, null, null);
71     }
72
73     /** Builds *select* - like query statement */
74     public SimpleStatement(String JavaDoc queryType, String JavaDoc match) throws InvalidStatementException, UniFormTransformationException
75     {
76         this(queryType, match, (String JavaDoc)null, null, null);
77     }
78
79     /** Constructs 'select' - query with '/' xpath */
80     public SimpleStatement() throws InvalidStatementException
81     {
82         this(QueryType.SELECT, "/", (UniFormTreeFragment)null, null, null);
83     }
84
85     public static SimpleStatement select(String JavaDoc match, String JavaDoc source) throws InvalidStatementException
86     {
87         return select(match, source, null);
88     }
89
90     public static SimpleStatement select(String JavaDoc match) throws InvalidStatementException
91     {
92         return select(match, null, null);
93     }
94
95     public static SimpleStatement select(String JavaDoc match, String JavaDoc source, String JavaDoc 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 JavaDoc name, String JavaDoc initXml) throws InvalidStatementException, UniFormTransformationException
103     {
104         return new SimpleStatement( QueryType.CREATE, name, initXml, null, name);
105     }
106
107     public static SimpleStatement create(String JavaDoc 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 JavaDoc name) throws InvalidStatementException
113     {
114         return new SimpleStatement( QueryType.DROP, name, (UniFormTreeFragment)null, null, name);
115     }
116
117     public static SimpleStatement append(String JavaDoc match, String JavaDoc destination, UniFormTree value) throws InvalidStatementException
118     {
119         return new SimpleStatement( QueryType.APPEND, match, value, destination, destination);
120     }
121
122     public static SimpleStatement append(String JavaDoc match, String JavaDoc destination, String JavaDoc value) throws InvalidStatementException, UniFormTransformationException
123     {
124         return new SimpleStatement( QueryType.APPEND, match, value, destination, destination);
125     }
126
127     public static SimpleStatement update(String JavaDoc match, String JavaDoc destination, UniFormTree value) throws InvalidStatementException
128     {
129         return new SimpleStatement( QueryType.UPDATE, match, value, destination, destination);
130     }
131
132     public static SimpleStatement update(String JavaDoc match, String JavaDoc destination, String JavaDoc value) throws InvalidStatementException, UniFormTransformationException
133     {
134         return new SimpleStatement( QueryType.UPDATE, match, value, destination, destination);
135     }
136
137     public static SimpleStatement delete(String JavaDoc match, String JavaDoc destination) throws InvalidStatementException
138     {
139         return new SimpleStatement( QueryType.DELETE, match, (UniFormTreeFragment)null, destination, destination);
140     }
141
142 }
143
Popular Tags