KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > hp > hpl > jena > rdf > arp > PullingTokenPipe


1 /*
2  * (c) Copyright 2004, 2005 Hewlett-Packard Development Company, LP
3  * [See end of file]
4  */

5
6 package com.hp.hpl.jena.rdf.arp;
7
8 import java.io.InterruptedIOException JavaDoc;
9 import java.util.*;
10
11 /**
12  * @author Jeremy J. Carroll
13  *
14  */

15 class PullingTokenPipe extends TokenPipe {
16
17     static PullingTokenPipe lastMade;
18     private int position = 0;
19     private boolean atEOF = false;
20     final XMLHandler arp;
21     final List pipe;
22
23     PullingTokenPipe(XMLHandler arp) {
24         this.arp = arp;
25         pipe = createPipe();
26         if (Token.COUNT)
27           lastMade = this;
28         else
29             lastMade = null;
30     }
31
32     void putNextToken(Token t) {
33    // System.err.print(t.toString()+", ");
34
pipe.add(t);
35     }
36
37     public Token getNextToken() {
38         while (true) {
39             if (getPosition() < pipe.size()) {
40                 int p = position++;
41                 Token rslt = (Token) pipe.get(p);
42                 pipe.set(p,null);
43                 setLast(rslt);
44                 return rslt;
45             }
46             if (atEOF)
47                 return new Token(RDFParserConstants.EOF, null);
48           if (Thread.interrupted())
49             throw new WrappedException(new InterruptedIOException JavaDoc("ARP interrupted"));
50             position=0;
51            // if ( pipe.size() > 0 )
52
// setLast((Token)pipe.get(pipe.size()-1));
53
pipe.clear();
54             while (pipe.size() == 0)
55                 if (!((SingleThreadedParser)arp).parseSome()) {
56                     atEOF = true;
57                     break;
58                 }
59         }
60     }
61     private List createPipe() {
62         return new ArrayList();
63     }
64     private int getPosition() {
65         return position;
66     }
67 }
68
69
70 /*
71  * (c) Copyright 2004, 2005 Hewlett-Packard Development Company, LP
72  * All rights reserved.
73  *
74  * Redistribution and use in source and binary forms, with or without
75  * modification, are permitted provided that the following conditions
76  * are met:
77  * 1. Redistributions of source code must retain the above copyright
78  * notice, this list of conditions and the following disclaimer.
79  * 2. Redistributions in binary form must reproduce the above copyright
80  * notice, this list of conditions and the following disclaimer in the
81  * documentation and/or other materials provided with the distribution.
82  * 3. The name of the author may not be used to endorse or promote products
83  * derived from this software without specific prior written permission.
84  *
85  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
86  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
87  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
88  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
89  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
90  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
91  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
92  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
93  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
94  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
95  */

96  
97
Popular Tags