View Javadoc

1   /*
2    ORDI - Ontology Repository and Data Integration
3   
4    Copyright (c) 2004-2007, OntoText Lab. / SIRMA
5   
6    This library is free software; you can redistribute it and/or modify it under
7    the terms of the GNU Lesser General Public License as published by the Free
8    Software Foundation; either version 2.1 of the License, or (at your option)
9    any later version.
10   This library is distributed in the hope that it will be useful, but WITHOUT
11   ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12   FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
13   details.
14   You should have received a copy of the GNU Lesser General Public License along
15   with this library; if not, write to the Free Software Foundation, Inc.,
16   59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17   */
18  package com.ontotext.ordi.mapper.processor;
19  
20  import org.openrdf.model.Resource;
21  import org.openrdf.model.URI;
22  import org.openrdf.model.Value;
23  
24  import com.ontotext.ordi.mapper.model.RDFResultSet;
25  
26  public class AggregateRDFResultSet implements RDFResultSet {
27  
28      private RDFResultManager manager;
29      private RDFResultSet current;
30  
31      public AggregateRDFResultSet(RDFResultManager manager) {
32          if (manager == null) {
33              throw new IllegalArgumentException();
34          }
35          this.manager = manager;
36      }
37      
38      public void run() {
39      }
40  
41      public void close() {
42          do {
43              if (current != null) {
44                  current.close();
45              }
46              current = manager.getNextCompleted();
47          }  while (manager.getNextCompleted() != null);
48      }
49  
50      public URI getNamedGraph() {
51          if (current == null) {
52              throw new IllegalStateException(invalidState);
53          }
54          return current.getNamedGraph();
55      }
56  
57      public Value getObject() {
58          if (current == null) {
59              throw new IllegalStateException(invalidState);
60          }
61          return current.getObject();
62      }
63  
64      public URI getPredicate() {
65          if (current == null) {
66              throw new IllegalStateException(invalidState);
67          }
68          return current.getPredicate();
69      }
70  
71      public Resource getSubject() {
72          if (current == null) {
73              throw new IllegalStateException(invalidState);
74          }
75          return current.getSubject();
76      }
77  
78      public URI[] getTriplesets() {
79          if (current == null) {
80              throw new IllegalStateException(invalidState);
81          }
82          return current.getTriplesets();
83      }
84  
85      public boolean next() {
86          if (current == null) {
87              current = manager.getNextCompleted();
88          }
89          while (current != null) {
90              boolean hasNext = current.next();
91              if (hasNext) {
92                  return true;
93              }
94              current.close();
95              current = manager.getNextCompleted();
96              return next();
97          }
98          return false;
99      }
100     
101     private final String invalidState = "Invalid operation first call next() method!";
102 }