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.wsmo4rdf.impl;
19  
20  import org.openrdf.model.URI;
21  import org.openrdf.model.Value;
22  
23  import com.ontotext.ordi.exception.ORDIException;
24  import com.ontotext.ordi.tripleset.TConnection;
25  import com.ontotext.ordi.wsmo4rdf.WSMLTripleHandler;
26  
27  public class Handler2TConnectionImpl implements WSMLTripleHandler {
28  
29      protected final TConnection connection;
30      private int statementsProcessed;
31  
32      public Handler2TConnectionImpl(TConnection connection) {
33          if (connection == null) {
34              throw new IllegalArgumentException();
35          }
36          if (connection.isOpen() == false) {
37              throw new IllegalArgumentException("Connection is closed!");
38          }
39          this.connection = connection;
40      }
41  
42      public void handleTriple(URI subject, URI predicate, Value object,
43              URI namedGraph, URI... tripleSets) {
44          try {
45              connection.addStatement(subject, predicate, object, namedGraph,
46                      tripleSets);
47              statementsProcessed++;
48          } catch (ORDIException e) {
49              throw new RuntimeException(
50                      "Could not persist WSML triple to ORDI model!", e);
51          }
52      }
53  
54      public int getStatementsProcessed() {
55          return statementsProcessed;
56      }
57  
58  }