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 java.util.Iterator;
21  
22  import org.openrdf.model.Resource;
23  import org.openrdf.model.URI;
24  import org.openrdf.model.Value;
25  
26  import com.ontotext.ordi.mapper.model.MapperDescriptor;
27  import com.ontotext.ordi.mapper.model.PredicatePattern;
28  import com.ontotext.ordi.mapper.model.RDFResultSet;
29  
30  public final class Processor {
31  
32      private MapperDescriptor descriptor;
33  
34      public Processor(MapperDescriptor descriptor) {
35          if (descriptor == null) {
36              throw new IllegalArgumentException();
37          }
38          this.descriptor = descriptor;
39      }
40  
41      public RDFResultSet evaluate(Resource subj, URI pred, Value value,
42              URI graphName) {
43          Iterator<PredicatePattern> iterator = descriptor.listPatterns()
44                  .iterator();
45          RDFResultManager resultManager = new RDFResultManager();
46          while (iterator.hasNext()) {
47              PredicatePattern pattern = iterator.next();
48              pattern.execute(subj, pred, value, graphName, resultManager);
49          }
50          return new AggregateRDFResultSet(resultManager);
51      }
52  }