KickJava   Java API By Example, From Geeks To Geeks.

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


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 /**
7  * Data processing based instruction
8  * @version $Id: XMLInstruction.java 566 2005-01-25 12:50:49Z kravchuk $
9  */

10 public class XMLInstruction extends Instruction {
11
12      private static QueryProcessor processor = QueryProcessorFactory.getInstance().getProcessor();
13      Command command;
14
15     /**
16      * Copy constructor
17      */

18     public XMLInstruction(Instruction instr)
19     {
20         super(instr);
21     }
22
23     public XMLInstruction(String JavaDoc type, String JavaDoc match, UniFormTree newValue) throws InvalidStatementException
24     {
25         super(type, match, newValue);
26     }
27
28     public String JavaDoc getAsString()
29     {
30
31         String JavaDoc matchStr = "";
32         if( match != null )
33             matchStr = " xpath=\"" + match + "\"";
34
35         return "<" + type + matchStr + ">" +
36                 newValue.getAsString() +
37                "</" + type + ">";
38     }
39
40     /**
41     * Compiles instruction
42     *
43     * */

44     public void compile() throws InvalidStatementException
45     {
46         this.command = compiler.compile( getAsString() );
47         processor.init(command);
48 // processor.setParameter("sourceId", sourceId);
49
// processor.setParameter("destinationId", destinationId);
50
}
51
52     /**
53     * Debug
54     * */

55     public String JavaDoc getCommandAsString()
56     {
57        return command.toString();
58     }
59
60     /**
61     * Executes instruction
62     * For Resource Instruction must return null.
63     * */

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 JavaDoc resourceContext)
75     {}
76
77 }
78
Popular Tags