KickJava   Java API By Example, From Geeks To Geeks.

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


1 package org.exoplatform.services.xml.querying.impl.xtas;
2
3 import java.util.ArrayList JavaDoc;
4 import org.exoplatform.services.xml.querying.InvalidStatementException;
5 import org.exoplatform.services.xml.querying.Statement;
6
7 /**
8  * Abstract XTAS Statement
9  * Contains:
10  * destinationId - Path|URI - Must be NULL if empty !
11  * sourceId - Path|URI - Must be NULL if empty !
12  * and FIFO-array of instructions to execute
13  * @version $Id: BaseStatement.java 566 2005-01-25 12:50:49Z kravchuk $
14  */

15 abstract public class BaseStatement implements InstructionsSupport, Statement {
16
17     protected String JavaDoc destinationId;
18
19     protected String JavaDoc sourceId;
20
21     /**
22      * @clientCardinality 1
23      * @supplierCardinality 1..*
24      * @labelDirection forward
25      */

26     private ArrayList JavaDoc instructions = new ArrayList JavaDoc();
27
28     /** @link dependency
29      * @stereotype include*/

30     /*# Instruction lnkInstruction; */
31
32     public final String JavaDoc getSourceId()
33     {
34         return sourceId;
35     }
36
37     public final void setSourceId(String JavaDoc sourceId)
38     {
39         this.sourceId = sourceId;
40     }
41
42     public final String JavaDoc getDestinationId()
43     {
44         return destinationId;
45     }
46
47     public final void setDestinationId(String JavaDoc destinationId)
48     {
49         this.destinationId = destinationId;
50     }
51
52     public Instruction[] getInstructions( )
53     {
54         Instruction[] ins = new Instruction[instructions.size()];
55         for(int i=0; i<instructions.size(); i++)
56             ins[i] = (Instruction)instructions.get(i);
57         return ins;
58 // return (Instruction[])instructions.toArray();
59
}
60
61     public void addInstruction (String JavaDoc type, String JavaDoc match, UniFormTree newValue) throws InvalidStatementException
62     {
63
64         if( QueryType.isAtResource( type ) ) {
65
66             instructions.add( new ResourceInstruction( type, match, newValue ) );
67             this.destinationId = match;
68
69         } else if( QueryType.isAtXml( type ) )
70             instructions.add( new XMLInstruction( type, match, newValue ) );
71         else
72             throw new InvalidStatementException("Add Instruction Error: Invalid instruction type '"+type+"'!");
73
74     }
75
76     public Instruction pickNextInstruction() throws ForbiddenOperationException, InvalidStatementException
77     {
78         if( instructions.size() == 0 )
79               throw new ForbiddenOperationException( "It is no more instructions!" );
80
81 // Instruction instr = Instruction.create ( (Instruction)instructions.get( 0 ) );
82

83         Instruction instr = (Instruction)instructions.get( 0 );
84
85 // instr.compile(sourceId, destinationId);
86

87         instructions.remove(0);
88         return instr;
89     }
90
91     public String JavaDoc toString()
92     {
93         String JavaDoc srcStr = "";
94         String JavaDoc destStr = "";
95
96         if( sourceId != null )
97             srcStr = " source=\"" + sourceId + "\"";
98         if( destinationId != null )
99             destStr = " destination=\"" + destinationId + "\"";
100
101         String JavaDoc instrString = "";
102         for(int i=0; i<instructions.size(); i++)
103              instrString += instructions.get(i);
104
105         return "<query" + srcStr + destStr + ">" + instrString + "</query>";
106     }
107
108
109 }
110
Popular Tags