Return-Path: X-Original-To: apmail-commons-dev-archive@www.apache.org Delivered-To: apmail-commons-dev-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 9BF731776E for ; Tue, 17 Feb 2015 06:04:05 +0000 (UTC) Received: (qmail 58264 invoked by uid 500); 17 Feb 2015 06:04:05 -0000 Delivered-To: apmail-commons-dev-archive@commons.apache.org Received: (qmail 58136 invoked by uid 500); 17 Feb 2015 06:04:05 -0000 Mailing-List: contact dev-help@commons.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: "Commons Developers List" Delivered-To: mailing list dev@commons.apache.org Received: (qmail 58125 invoked by uid 99); 17 Feb 2015 06:04:05 -0000 Received: from mail-relay.apache.org (HELO mail-relay.apache.org) (140.211.11.15) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 17 Feb 2015 06:04:05 +0000 Received: from mail-wi0-f181.google.com (mail-wi0-f181.google.com [209.85.212.181]) by mail-relay.apache.org (ASF Mail Server at mail-relay.apache.org) with ESMTPSA id 045DC1A025E for ; Tue, 17 Feb 2015 06:04:03 +0000 (UTC) Received: by mail-wi0-f181.google.com with SMTP id r20so30617203wiv.2 for ; Mon, 16 Feb 2015 22:04:02 -0800 (PST) MIME-Version: 1.0 X-Received: by 10.194.83.98 with SMTP id p2mr56875909wjy.125.1424153042743; Mon, 16 Feb 2015 22:04:02 -0800 (PST) Received: by 10.194.25.231 with HTTP; Mon, 16 Feb 2015 22:04:02 -0800 (PST) In-Reply-To: References: <20150215184117.51B15AC006D@hades.apache.org> Date: Tue, 17 Feb 2015 07:04:02 +0100 Message-ID: Subject: Re: svn commit: r1659973 [1/3] - in /commons/sandbox/rdf/trunk: ./ api/src/main/java/org/apache/commons/rdf/ impl.sparql/ impl.sparql/src/ impl.sparql/src/main/ impl.sparql/src/main/java/ impl.sparql/src/main/java/org/ impl.sparql/src/main/java/org/apache/... From: Benedikt Ritter To: Commons Developers List Content-Type: multipart/alternative; boundary=047d7bdc87a237f8c0050f4278af --047d7bdc87a237f8c0050f4278af Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable 2015-02-17 0:13 GMT+01:00 Peter Ansell : > Hi Bernard, > > The Commons RDF project is not planning on including any non-trivial > implementations, to avoid bias towards any of the participating > platforms. Stian has written a trivial implementation and submitted it > to GitHub to provide a reference for our test harness, but it is never > planned to be used by anyone for non-trivial purposes. > > Reto is moving this code here unilaterally from Clerezza at this point > based on the ability of any Apache committer to send code into Apache > Commons. > > The code that will be sent to the incubator is still planned to be the > code that is in the GitHub repository at the time the incubator > request goes through. > This is still in the sandbox so I'm not too crazy about it. But creating a separate code base in the commons-rdf git repository doesn't sound like a good idea given the fact that github Commons RDF will eventually move to Apache Commons after incubation. What should haben with the code that is in the repository by that time? Reto, can you comment please? Regards, Benedikt > > Cheers, > > Peter > > On 16 February 2015 at 18:34, Benedikt Ritter wrote: > > Hello Reto, > > > > how does this relate to github Commons RDF? Is this part of the code ba= se > > proposed for incubation? > > > > Regards, > > Benedikt > > > > 2015-02-15 19:41 GMT+01:00 : > > > >> Author: reto > >> Date: Sun Feb 15 18:41:15 2015 > >> New Revision: 1659973 > >> > >> URL: http://svn.apache.org/r1659973 > >> Log: > >> Started SPARQL Backed Implementation > >> > >> Added: > >> commons/sandbox/rdf/trunk/alerts.txt > >> commons/sandbox/rdf/trunk/impl.sparql/ (with props) > >> commons/sandbox/rdf/trunk/impl.sparql/pom.xml > >> commons/sandbox/rdf/trunk/impl.sparql/src/ > >> commons/sandbox/rdf/trunk/impl.sparql/src/main/ > >> commons/sandbox/rdf/trunk/impl.sparql/src/main/java/ > >> commons/sandbox/rdf/trunk/impl.sparql/src/main/java/org/ > >> commons/sandbox/rdf/trunk/impl.sparql/src/main/java/org/apache/ > >> > commons/sandbox/rdf/trunk/impl.sparql/src/main/java/org/apache/commons/ > >> > >> > commons/sandbox/rdf/trunk/impl.sparql/src/main/java/org/apache/commons/rd= f/ > >> > >> > commons/sandbox/rdf/trunk/impl.sparql/src/main/java/org/apache/commons/rd= f/impl/ > >> > >> > commons/sandbox/rdf/trunk/impl.sparql/src/main/java/org/apache/commons/rd= f/impl/sparql/ > >> > >> > commons/sandbox/rdf/trunk/impl.sparql/src/main/java/org/apache/commons/rd= f/impl/sparql/SparqlClient.java > >> > >> > commons/sandbox/rdf/trunk/impl.sparql/src/main/java/org/apache/commons/rd= f/impl/sparql/SparqlGraph.java > >> commons/sandbox/rdf/trunk/impl.sparql/src/main/resources/ > >> commons/sandbox/rdf/trunk/impl.sparql/src/test/ > >> commons/sandbox/rdf/trunk/impl.sparql/src/test/java/ > >> commons/sandbox/rdf/trunk/impl.sparql/src/test/java/org/ > >> commons/sandbox/rdf/trunk/impl.sparql/src/test/java/org/apache/ > >> > commons/sandbox/rdf/trunk/impl.sparql/src/test/java/org/apache/commons/ > >> > >> > commons/sandbox/rdf/trunk/impl.sparql/src/test/java/org/apache/commons/rd= f/ > >> > >> > commons/sandbox/rdf/trunk/impl.sparql/src/test/java/org/apache/commons/rd= f/impl/ > >> > >> > commons/sandbox/rdf/trunk/impl.sparql/src/test/java/org/apache/commons/rd= f/impl/sparql/ > >> > >> > commons/sandbox/rdf/trunk/impl.sparql/src/test/java/org/apache/commons/rd= f/impl/sparql/SparqlGraphTest.java > >> commons/sandbox/rdf/trunk/impl.sparql/src/test/resources/ > >> commons/sandbox/rdf/trunk/impl.sparql/src/test/resources/org/ > >> commons/sandbox/rdf/trunk/impl.sparql/src/test/resources/org/apach= e/ > >> > >> > commons/sandbox/rdf/trunk/impl.sparql/src/test/resources/org/apache/commo= ns/ > >> > >> > commons/sandbox/rdf/trunk/impl.sparql/src/test/resources/org/apache/commo= ns/rdf/ > >> > >> > commons/sandbox/rdf/trunk/impl.sparql/src/test/resources/org/apache/commo= ns/rdf/impl/ > >> > >> > commons/sandbox/rdf/trunk/impl.sparql/src/test/resources/org/apache/commo= ns/rdf/impl/sparql/ > >> > >> > commons/sandbox/rdf/trunk/impl.sparql/src/test/resources/org/apache/commo= ns/rdf/impl/sparql/grounded.ttl > >> commons/sandbox/rdf/trunk/impl.utils/ (with props) > >> commons/sandbox/rdf/trunk/impl.utils/pom.xml > >> - copied, changed from r1651181, commons/sandbox/rdf/trunk/pom.x= ml > >> commons/sandbox/rdf/trunk/impl.utils/src/ > >> commons/sandbox/rdf/trunk/impl.utils/src/main/ > >> commons/sandbox/rdf/trunk/impl.utils/src/main/java/ > >> commons/sandbox/rdf/trunk/impl.utils/src/main/java/org/ > >> commons/sandbox/rdf/trunk/impl.utils/src/main/java/org/apache/ > >> > commons/sandbox/rdf/trunk/impl.utils/src/main/java/org/apache/commons/ > >> > >> > commons/sandbox/rdf/trunk/impl.utils/src/main/java/org/apache/commons/rdf= / > >> > >> > commons/sandbox/rdf/trunk/impl.utils/src/main/java/org/apache/commons/rdf= /impl/ > >> > >> > commons/sandbox/rdf/trunk/impl.utils/src/main/java/org/apache/commons/rdf= /impl/utils/ > >> > >> > commons/sandbox/rdf/trunk/impl.utils/src/main/java/org/apache/commons/rdf= /impl/utils/AbstractGraph.java > >> > >> > commons/sandbox/rdf/trunk/impl.utils/src/main/java/org/apache/commons/rdf= /impl/utils/AbstractImmutableGraph.java > >> > >> > commons/sandbox/rdf/trunk/impl.utils/src/main/java/org/apache/commons/rdf= /impl/utils/AbstractLiteral.java > >> > >> > commons/sandbox/rdf/trunk/impl.utils/src/main/java/org/apache/commons/rdf= /impl/utils/DelayedNotificator.java > >> > >> > commons/sandbox/rdf/trunk/impl.utils/src/main/java/org/apache/commons/rdf= /impl/utils/LockingIterator.java > >> > >> > commons/sandbox/rdf/trunk/impl.utils/src/main/java/org/apache/commons/rdf= /impl/utils/PlainLiteralImpl.java > >> > >> > commons/sandbox/rdf/trunk/impl.utils/src/main/java/org/apache/commons/rdf= /impl/utils/TripleImpl.java > >> > >> > commons/sandbox/rdf/trunk/impl.utils/src/main/java/org/apache/commons/rdf= /impl/utils/TypedLiteralImpl.java > >> > >> > commons/sandbox/rdf/trunk/impl.utils/src/main/java/org/apache/commons/rdf= /impl/utils/WatchableGraphWrapper.java > >> > >> > commons/sandbox/rdf/trunk/impl.utils/src/main/java/org/apache/commons/rdf= /impl/utils/debug/ > >> > >> > commons/sandbox/rdf/trunk/impl.utils/src/main/java/org/apache/commons/rdf= /impl/utils/debug/ReadLockDebug.java > >> > >> > commons/sandbox/rdf/trunk/impl.utils/src/main/java/org/apache/commons/rdf= /impl/utils/debug/ReentrantReadWriteLockTracker.java > >> > >> > commons/sandbox/rdf/trunk/impl.utils/src/main/java/org/apache/commons/rdf= /impl/utils/debug/WriteLockDebug.java > >> > >> > commons/sandbox/rdf/trunk/impl.utils/src/main/java/org/apache/commons/rdf= /impl/utils/graphmatching/ > >> > >> > commons/sandbox/rdf/trunk/impl.utils/src/main/java/org/apache/commons/rdf= /impl/utils/graphmatching/GraphMatcher.java > >> > >> > commons/sandbox/rdf/trunk/impl.utils/src/main/java/org/apache/commons/rdf= /impl/utils/graphmatching/GraphNotIsomorphicException.java > >> > >> > commons/sandbox/rdf/trunk/impl.utils/src/main/java/org/apache/commons/rdf= /impl/utils/graphmatching/GroupMappingIterator.java > >> > >> > commons/sandbox/rdf/trunk/impl.utils/src/main/java/org/apache/commons/rdf= /impl/utils/graphmatching/HashMatching.java > >> > >> > commons/sandbox/rdf/trunk/impl.utils/src/main/java/org/apache/commons/rdf= /impl/utils/graphmatching/MappingIterator.java > >> > >> > commons/sandbox/rdf/trunk/impl.utils/src/main/java/org/apache/commons/rdf= /impl/utils/graphmatching/PermutationIterator.java > >> > >> > commons/sandbox/rdf/trunk/impl.utils/src/main/java/org/apache/commons/rdf= /impl/utils/graphmatching/Utils.java > >> > >> > commons/sandbox/rdf/trunk/impl.utils/src/main/java/org/apache/commons/rdf= /impl/utils/graphmatching/collections/ > >> > >> > commons/sandbox/rdf/trunk/impl.utils/src/main/java/org/apache/commons/rdf= /impl/utils/graphmatching/collections/IntHashMap.java > >> > >> > commons/sandbox/rdf/trunk/impl.utils/src/main/java/org/apache/commons/rdf= /impl/utils/graphmatching/collections/IntHashSet.java > >> > >> > commons/sandbox/rdf/trunk/impl.utils/src/main/java/org/apache/commons/rdf= /impl/utils/graphmatching/collections/IntIterator.java > >> > >> > commons/sandbox/rdf/trunk/impl.utils/src/main/java/org/apache/commons/rdf= /impl/utils/graphmatching/collections/IntSet.java > >> > >> > commons/sandbox/rdf/trunk/impl.utils/src/main/java/org/apache/commons/rdf= /impl/utils/package-info.java > >> - copied, changed from r1651181, > >> > commons/sandbox/rdf/trunk/src/main/java/org/apache/commons/rdf/package-in= fo.java > >> > >> > commons/sandbox/rdf/trunk/impl.utils/src/main/java/org/apache/commons/rdf= /impl/utils/simple/ > >> > >> > commons/sandbox/rdf/trunk/impl.utils/src/main/java/org/apache/commons/rdf= /impl/utils/simple/SimpleGraph.java > >> > >> > commons/sandbox/rdf/trunk/impl.utils/src/main/java/org/apache/commons/rdf= /impl/utils/simple/SimpleImmutableGraph.java > >> > >> > commons/sandbox/rdf/trunk/impl.utils/src/main/java/org/apache/commons/rdf= /impl/utils/simple/SimpleMGraph.java > >> commons/sandbox/rdf/trunk/impl.utils/src/main/resources/ > >> commons/sandbox/rdf/trunk/impl.utils/src/test/ > >> commons/sandbox/rdf/trunk/impl.utils/src/test/java/ > >> commons/sandbox/rdf/trunk/impl.utils/src/test/java/org/ > >> commons/sandbox/rdf/trunk/impl.utils/src/test/java/org/apache/ > >> > commons/sandbox/rdf/trunk/impl.utils/src/test/java/org/apache/commons/ > >> > >> > commons/sandbox/rdf/trunk/impl.utils/src/test/java/org/apache/commons/rdf= / > >> > >> > commons/sandbox/rdf/trunk/impl.utils/src/test/java/org/apache/commons/rdf= /impl/ > >> > >> > commons/sandbox/rdf/trunk/impl.utils/src/test/java/org/apache/commons/rdf= /impl/utils/ > >> > >> > commons/sandbox/rdf/trunk/impl.utils/src/test/java/org/apache/commons/rdf= /impl/utils/simple/ > >> > >> > commons/sandbox/rdf/trunk/impl.utils/src/test/java/org/apache/commons/rdf= /impl/utils/simple/PlainLiteralImplTest.java > >> > >> > commons/sandbox/rdf/trunk/impl.utils/src/test/java/org/apache/commons/rdf= /impl/utils/simple/SimpleGraphTest.java > >> > >> > commons/sandbox/rdf/trunk/impl.utils/src/test/java/org/apache/commons/rdf= /impl/utils/simple/TripleImplTest.java > >> > >> > commons/sandbox/rdf/trunk/impl.utils/src/test/java/org/apache/commons/rdf= /impl/utils/simple/TypedLiteralImplTest.java > >> commons/sandbox/rdf/trunk/report.xml > >> Modified: > >> > >> > commons/sandbox/rdf/trunk/api/src/main/java/org/apache/commons/rdf/Litera= l.java > >> commons/sandbox/rdf/trunk/pom.xml > >> > >> Added: commons/sandbox/rdf/trunk/alerts.txt > >> URL: > >> > http://svn.apache.org/viewvc/commons/sandbox/rdf/trunk/alerts.txt?rev=3D1= 659973&view=3Dauto > >> > >> > =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D > >> (empty) > >> > >> Modified: > >> > commons/sandbox/rdf/trunk/api/src/main/java/org/apache/commons/rdf/Litera= l.java > >> URL: > >> > http://svn.apache.org/viewvc/commons/sandbox/rdf/trunk/api/src/main/java/= org/apache/commons/rdf/Literal.java?rev=3D1659973&r1=3D1659972&r2=3D1659973= &view=3Ddiff > >> > >> > =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D > >> --- > >> > commons/sandbox/rdf/trunk/api/src/main/java/org/apache/commons/rdf/Litera= l.java > >> (original) > >> +++ > >> > commons/sandbox/rdf/trunk/api/src/main/java/org/apache/commons/rdf/Litera= l.java > >> Sun Feb 15 18:41:15 2015 > >> @@ -84,7 +84,8 @@ public interface Literal extends RdfTerm > >> > >> /** > >> * Returns the hash code of the lexical form plus the hash code o= f > the > >> - * language, plush the hash code of the datatype > >> + * datatype plus if the literal has a language the hash code of t= he > >> + * language. > >> * > >> * @return hash code > >> */ > >> > >> Propchange: commons/sandbox/rdf/trunk/impl.sparql/ > >> > >> > -------------------------------------------------------------------------= ----- > >> --- svn:ignore (added) > >> +++ svn:ignore Sun Feb 15 18:41:15 2015 > >> @@ -0,0 +1 @@ > >> +target > >> > >> Added: commons/sandbox/rdf/trunk/impl.sparql/pom.xml > >> URL: > >> > http://svn.apache.org/viewvc/commons/sandbox/rdf/trunk/impl.sparql/pom.xm= l?rev=3D1659973&view=3Dauto > >> > >> > =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D > >> --- commons/sandbox/rdf/trunk/impl.sparql/pom.xml (added) > >> +++ commons/sandbox/rdf/trunk/impl.sparql/pom.xml Sun Feb 15 18:41:15 > 2015 > >> @@ -0,0 +1,52 @@ > >> + > >> + >> http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation=3D" > >> http://maven.apache.org/POM/4.0.0 > >> http://maven.apache.org/xsd/maven-4.0.0.xsd"> > >> + > >> + org.apache.commons > >> + commons-parent > >> + 37 > >> + > >> + > >> + 4.0.0 > >> + commons-rdf > >> + commons-rdf-impl-sparql > >> + 1.0.0-SNAPSHOT > >> + jar > >> + Apache Commons RDF SPARQL backed implementation. > >> + An implementation of the rdf commons API backed by a > >> sparql > >> + endpoint. STATUS: Incomplete, currecnt code only supports > reading > >> + graphs and does not yet support BlankNodes. > >> + > >> + > UTF-8 > >> + 1.7 > >> + 1.7 > >> + > >> + > >> + > >> + org.apache.httpcomponents > >> + httpclient > >> + 4.4 > >> + > >> + > >> + commons-rdf > >> + commons-rdf-api > >> + 0.1-SNAPSHOT > >> + > >> + > >> + commons-rdf > >> + commons-rdf-impl-utils > >> + 0.1-SNAPSHOT > >> + > >> + > >> + junit > >> + junit > >> + 4.12 > >> + test > >> + > >> + > >> + org.apache.jena > >> + jena-fuseki > >> + 1.1.1 > >> + test > >> + > >> + > >> + > >> \ No newline at end of file > >> > >> Added: > >> > commons/sandbox/rdf/trunk/impl.sparql/src/main/java/org/apache/commons/rd= f/impl/sparql/SparqlClient.java > >> URL: > >> > http://svn.apache.org/viewvc/commons/sandbox/rdf/trunk/impl.sparql/src/ma= in/java/org/apache/commons/rdf/impl/sparql/SparqlClient.java?rev=3D1659973&= view=3Dauto > >> > >> > =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D > >> --- > >> > commons/sandbox/rdf/trunk/impl.sparql/src/main/java/org/apache/commons/rd= f/impl/sparql/SparqlClient.java > >> (added) > >> +++ > >> > commons/sandbox/rdf/trunk/impl.sparql/src/main/java/org/apache/commons/rd= f/impl/sparql/SparqlClient.java > >> Sun Feb 15 18:41:15 2015 > >> @@ -0,0 +1,220 @@ > >> +/* > >> + * To change this license header, choose License Headers in Project > >> Properties. > >> + * To change this template file, choose Tools | Templates > >> + * and open the template in the editor. > >> + */ > >> +package org.apache.commons.rdf.impl.sparql; > >> + > >> +import java.io.IOException; > >> +import java.io.InputStream; > >> +import java.io.UnsupportedEncodingException; > >> +import java.util.ArrayList; > >> +import java.util.Enumeration; > >> +import java.util.HashMap; > >> +import java.util.Hashtable; > >> +import java.util.List; > >> +import java.util.Map; > >> +import java.util.logging.Level; > >> +import java.util.logging.Logger; > >> +import org.apache.http.HttpEntity; > >> +import org.apache.http.NameValuePair; > >> +import org.apache.http.client.entity.UrlEncodedFormEntity; > >> +import org.apache.http.client.methods.CloseableHttpResponse; > >> +import org.apache.http.client.methods.HttpPost; > >> +import org.apache.http.impl.client.CloseableHttpClient; > >> +import org.apache.http.impl.client.HttpClients; > >> +import org.apache.http.message.BasicNameValuePair; > >> +import org.apache.http.util.EntityUtils; > >> +import javax.xml.parsers.*; > >> +import org.apache.commons.rdf.BlankNode; > >> +import org.apache.commons.rdf.BlankNodeOrIri; > >> +import org.apache.commons.rdf.Iri; > >> +import org.apache.commons.rdf.Language; > >> +import org.apache.commons.rdf.Literal; > >> +import org.apache.commons.rdf.RdfTerm; > >> +import org.apache.commons.rdf.Triple; > >> +import org.apache.commons.rdf.impl.utils.AbstractLiteral; > >> +import org.xml.sax.*; > >> +import org.xml.sax.helpers.*; > >> + > >> +/** > >> + * > >> + * @author developer > >> + */ > >> +public class SparqlClient { > >> + > >> + final String endpoint; > >> + > >> + public SparqlClient(final String endpoint) { > >> + this.endpoint =3D endpoint; > >> + } > >> + > >> + List> queryResultSet(final String query) > throws > >> IOException { > >> + CloseableHttpClient httpclient =3D HttpClients.createDefault(= ); > >> + HttpPost httpPost =3D new HttpPost(endpoint); > >> + List nvps =3D new ArrayList(); > >> + nvps.add(new BasicNameValuePair("query", query)); > >> + httpPost.setEntity(new UrlEncodedFormEntity(nvps)); > >> + CloseableHttpResponse response2 =3D httpclient.execute(httpPo= st); > >> + > >> + try { > >> + HttpEntity entity2 =3D response2.getEntity(); > >> + InputStream in =3D entity2.getContent(); > >> + SAXParserFactory spf =3D SAXParserFactory.newInstance(); > >> + spf.setNamespaceAware(true); > >> + SAXParser saxParser =3D spf.newSAXParser(); > >> + XMLReader xmlReader =3D saxParser.getXMLReader(); > >> + final SparqlsResultsHandler sparqlsResultsHandler =3D new > >> SparqlsResultsHandler(); > >> + xmlReader.setContentHandler(sparqlsResultsHandler); > >> + xmlReader.parse(new InputSource(in)); > >> + /* > >> + for (int ch =3D in.read(); ch !=3D -1; ch =3D in.read())= { > >> + System.out.print((char)ch); > >> + } > >> + */ > >> + // do something useful with the response body > >> + // and ensure it is fully consumed > >> + EntityUtils.consume(entity2); > >> + return sparqlsResultsHandler.getResults(); > >> + } catch (ParserConfigurationException ex) { > >> + throw new RuntimeException(ex); > >> + } catch (SAXException ex) { > >> + throw new RuntimeException(ex); > >> + } finally { > >> + response2.close(); > >> + } > >> + > >> + } > >> + > >> + final public static class SparqlsResultsHandler extends > >> DefaultHandler { > >> + > >> + private String currentBindingName; > >> + private Map currentResult =3D null; > >> + private final List> results =3D new > >> ArrayList<>(); > >> + private boolean readingValue; > >> + private String value; > >> + private Map bNodeMap =3D new HashMap<>(); > >> + private static final Iri XSD_STRING =3D new Iri(" > >> http://www.w3.org/2001/XMLSchema#string"); > >> + > >> + private RdfTerm getBNode(String value) { > >> + if (!bNodeMap.containsKey(value)) { > >> + bNodeMap.put(value, new BlankNode()); > >> + } > >> + return bNodeMap.get(value); > >> + } > >> + > >> + private List> getResults() { > >> + return results; > >> + } > >> + > >> + enum BindingType { > >> + > >> + uri, bnode, literal; > >> + } > >> + > >> + @Override > >> + public void startDocument() throws SAXException { > >> + > >> + } > >> + > >> + @Override > >> + public void startElement(String namespaceURI, > >> + String localName, > >> + String qName, > >> + Attributes atts) > >> + throws SAXException { > >> + if ("http://www.w3.org/2005/sparql-results# > ".equals(namespaceURI)) > >> { > >> + if ("result".equals(localName)) { > >> + if (currentResult !=3D null) { > >> + throw new SAXException("unexpected tag > "); > >> + } > >> + currentResult =3D new HashMap<>(); > >> + } else if ("binding".equals(localName)) { > >> + if (currentResult =3D=3D null) { > >> + throw new SAXException("unexpected tag > >> "); > >> + } > >> + currentBindingName =3D atts.getValue("name"); > >> + } else if ("uri".equals(localName) || > >> "bnode".equals(localName) || "literal".equals(localName)) { > >> + if (readingValue) { > >> + throw new SAXException("unexpected tag <" + > >> localName + ">"); > >> + } > >> + readingValue =3D true; > >> + } > >> + } > >> + > >> + //System.out.println(namespaceURI); > >> + //System.out.println(qName); > >> + } > >> + > >> + @Override > >> + public void characters(char[] chars, int start, int length) > >> throws SAXException { > >> + if (readingValue) { > >> + value =3D new String(chars, start, length); > >> + //System.err.println(value + start + ", " + length); > >> + } > >> + } > >> + > >> + @Override > >> + public void endElement(String namespaceURI, > >> + String localName, > >> + String qName) > >> + throws SAXException { > >> + if ("http://www.w3.org/2005/sparql-results# > ".equals(namespaceURI)) > >> { > >> + if ("result".equals(localName)) { > >> + results.add(currentResult); > >> + currentResult =3D null; > >> + } else if ("binding".equals(localName)) { > >> + if (currentBindingName =3D=3D null) { > >> + throw new SAXException("unexpected tag > >> "); > >> + } > >> + currentBindingName =3D null; > >> + } else { > >> + try { > >> + BindingType b =3D BindingType.valueOf(localNa= me); > >> + RdfTerm rdfTerm =3D null; > >> + switch (b) { > >> + case uri: > >> + rdfTerm =3D new Iri(value); > >> + break; > >> + case bnode: > >> + rdfTerm =3D getBNode(value); > >> + break; > >> + case literal: > >> + final String lf =3D value; > >> + rdfTerm =3D new AbstractLiteral() { > >> + > >> + @Override > >> + public String getLexicalForm() { > >> + return lf; > >> + } > >> + > >> + @Override > >> + public Iri getDataType() { > >> + //TODO implement > >> + return XSD_STRING; > >> + } > >> + > >> + @Override > >> + public Language getLanguage() { > >> + //TODO impl > >> + return null; > >> + } > >> + }; > >> + break; > >> + } > >> + currentResult.put(currentBindingName, rdfTerm= ); > >> + readingValue =3D false; > >> + } catch (IllegalArgumentException e) { > >> + //not uri|bnode|literal > >> + } > >> + } > >> + } > >> + } > >> + > >> + public void endDocument() throws SAXException { > >> + //System.out.println("results: " + results.size()); > >> + } > >> + > >> + } > >> + > >> +} > >> > >> Added: > >> > commons/sandbox/rdf/trunk/impl.sparql/src/main/java/org/apache/commons/rd= f/impl/sparql/SparqlGraph.java > >> URL: > >> > http://svn.apache.org/viewvc/commons/sandbox/rdf/trunk/impl.sparql/src/ma= in/java/org/apache/commons/rdf/impl/sparql/SparqlGraph.java?rev=3D1659973&v= iew=3Dauto > >> > >> > =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D > >> --- > >> > commons/sandbox/rdf/trunk/impl.sparql/src/main/java/org/apache/commons/rd= f/impl/sparql/SparqlGraph.java > >> (added) > >> +++ > >> > commons/sandbox/rdf/trunk/impl.sparql/src/main/java/org/apache/commons/rd= f/impl/sparql/SparqlGraph.java > >> Sun Feb 15 18:41:15 2015 > >> @@ -0,0 +1,121 @@ > >> +/* > >> + * To change this license header, choose License Headers in Project > >> Properties. > >> + * To change this template file, choose Tools | Templates > >> + * and open the template in the editor. > >> + */ > >> +package org.apache.commons.rdf.impl.sparql; > >> + > >> +import java.io.IOException; > >> +import java.util.Iterator; > >> +import java.util.List; > >> +import java.util.Map; > >> +import org.apache.commons.rdf.BlankNode; > >> +import org.apache.commons.rdf.BlankNodeOrIri; > >> +import org.apache.commons.rdf.Iri; > >> +import org.apache.commons.rdf.Literal; > >> +import org.apache.commons.rdf.RdfTerm; > >> +import org.apache.commons.rdf.Triple; > >> +import org.apache.commons.rdf.impl.utils.AbstractGraph; > >> +import org.apache.commons.rdf.impl.utils.TripleImpl; > >> + > >> +/** > >> + * > >> + * @author reto > >> + */ > >> +public class SparqlGraph extends AbstractGraph { > >> + > >> + final SparqlClient sparqlClient; > >> + > >> + /** Constructs a Graph representing the default graph at the > specified > >> + * endpoint > >> + */ > >> + public SparqlGraph(final String endpoint) { > >> + sparqlClient =3D new SparqlClient(endpoint); > >> + } > >> + > >> + @Override > >> + protected Iterator performFilter(final BlankNodeOrIri > subject, > >> + final Iri predicate, final RdfTerm object) { > >> + try { > >> + final StringBuilder queryBuilder =3D new StringBuilder(); > >> + queryBuilder.append("SELECT * WHERE { "); > >> + if (subject =3D=3D null) { > >> + queryBuilder.append("?s"); > >> + } else { > >> + queryBuilder.append(asSparqlTerm(subject)); > >> + } > >> + queryBuilder.append(' '); > >> + if (predicate =3D=3D null) { > >> + queryBuilder.append("?p"); > >> + } else { > >> + queryBuilder.append(asSparqlTerm(predicate)); > >> + } > >> + queryBuilder.append(' '); > >> + if (object =3D=3D null) { > >> + queryBuilder.append("?o"); > >> + } else { > >> + queryBuilder.append(asSparqlTerm(object)); > >> + } > >> + queryBuilder.append(" }"); > >> + List> sparqlResults =3D > >> sparqlClient.queryResultSet(queryBuilder.toString()); > >> + final Iterator> resultsIterator =3D > >> sparqlResults.iterator(); > >> + return new Iterator() { > >> + > >> + @Override > >> + public boolean hasNext() { > >> + return resultsIterator.hasNext(); > >> + } > >> + > >> + @Override > >> + public Triple next() { > >> + Map result =3D > resultsIterator.next(); > >> + return new TripleImpl(subject !=3D null ? subject= : > >> (BlankNodeOrIri)result.get("s"), > >> + predicate !=3D null ? predicate : > >> (Iri)result.get("p"), > >> + object !=3D null ? object : result.get("o= ")); > >> + } > >> + }; > >> + } catch (IOException ex) { > >> + throw new RuntimeException(ex); > >> + } > >> + } > >> + > >> + @Override > >> + protected int performSize() { > >> + try { > >> + return sparqlClient.queryResultSet("SELECT * WHERE { ?s ?= p > >> ?o}").size(); > >> + } catch (IOException ex) { > >> + throw new RuntimeException(ex); > >> + } > >> + } > >> + > >> + private String asSparqlTerm(Iri iri) { > >> + return "<"+iri.getUnicodeString()+">"; > >> + } > >> + > >> + private String asSparqlTerm(Literal literal) { > >> + //TODO langauge and datatype > >> + return "\""+literal.getLexicalForm()+"\""; > >> + } > >> + > >> + private String asSparqlTerm(BlankNode bnode) { > >> + //this requires adding additional clauses to the graph patter= n > >> + throw new UnsupportedOperationException("Not supported yet.")= ; > >> + } > >> + > >> + private String asSparqlTerm(BlankNodeOrIri term) { > >> + if (term instanceof Iri) { > >> + return asSparqlTerm((Iri)term); > >> + } else { > >> + return asSparqlTerm((BlankNode)term); > >> + } > >> + } > >> + > >> + private String asSparqlTerm(RdfTerm term) { > >> + if (term instanceof BlankNodeOrIri) { > >> + return asSparqlTerm((BlankNodeOrIri)term); > >> + } else { > >> + return asSparqlTerm((Literal)term); > >> + } > >> + } > >> + > >> +} > >> > >> Added: > >> > commons/sandbox/rdf/trunk/impl.sparql/src/test/java/org/apache/commons/rd= f/impl/sparql/SparqlGraphTest.java > >> URL: > >> > http://svn.apache.org/viewvc/commons/sandbox/rdf/trunk/impl.sparql/src/te= st/java/org/apache/commons/rdf/impl/sparql/SparqlGraphTest.java?rev=3D16599= 73&view=3Dauto > >> > >> > =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D > >> --- > >> > commons/sandbox/rdf/trunk/impl.sparql/src/test/java/org/apache/commons/rd= f/impl/sparql/SparqlGraphTest.java > >> (added) > >> +++ > >> > commons/sandbox/rdf/trunk/impl.sparql/src/test/java/org/apache/commons/rd= f/impl/sparql/SparqlGraphTest.java > >> Sun Feb 15 18:41:15 2015 > >> @@ -0,0 +1,106 @@ > >> +/* > >> + * To change this license header, choose License Headers in Project > >> Properties. > >> + * To change this template file, choose Tools | Templates > >> + * and open the template in the editor. > >> + */ > >> +package org.apache.commons.rdf.impl.sparql; > >> + > >> +import com.hp.hpl.jena.query.DatasetAccessor; > >> +import com.hp.hpl.jena.query.DatasetAccessorFactory; > >> +import java.io.File; > >> +import java.io.IOException; > >> +import java.net.ServerSocket; > >> +import org.apache.jena.fuseki.EmbeddedFusekiServer; > >> +import com.hp.hpl.jena.rdf.model.Model; > >> +import com.hp.hpl.jena.rdf.model.ModelFactory; > >> +import java.io.InputStream; > >> +import java.util.HashSet; > >> +import java.util.Iterator; > >> +import java.util.Set; > >> +import org.apache.commons.rdf.Graph; > >> +import org.apache.commons.rdf.Iri; > >> +import org.apache.commons.rdf.Literal; > >> +import org.apache.commons.rdf.RdfTerm; > >> +import org.apache.commons.rdf.Triple; > >> +import org.apache.commons.rdf.impl.utils.PlainLiteralImpl; > >> +import org.junit.AfterClass; > >> +import org.junit.Assert; > >> +import org.junit.BeforeClass; > >> +import org.junit.Test; > >> + > >> +/** > >> + * > >> + * @author reto > >> + */ > >> +public class SparqlGraphTest { > >> + > >> + final static int serverPort =3D findFreePort(); > >> + static EmbeddedFusekiServer server; > >> + > >> + @BeforeClass > >> + public static void prepare() throws IOException { > >> + final String serviceURI =3D "http://localhost:" + serverPort = + > >> "/ds/data"; > >> + final DatasetAccessorFactory factory =3D new > >> DatasetAccessorFactory(); > >> + final DatasetAccessor accessor =3D > factory.createHTTP(serviceURI); > >> + final InputStream in =3D > >> SparqlGraphTest.class.getResourceAsStream("grounded.ttl"); > >> + final Model m =3D ModelFactory.createDefaultModel(); > >> + String base =3D "http://example.org/"; > >> + m.read(in, base, "TURTLE"); > >> + > >> + final File dataSet =3D File.createTempFile("dataset", "fuseki= "); > >> + dataSet.delete(); > >> + server =3D EmbeddedFusekiServer.memTDB(serverPort, > >> "/ds");//dataSet.getAbsolutePath()); > >> + server.start(); > >> + System.out.println("Started fuseki on port " + serverPort); > >> + accessor.putModel(m); > >> + } > >> + > >> + @AfterClass > >> + public static void cleanup() { > >> + server.stop(); > >> + } > >> + > >> + @Test > >> + public void graphSize() { > >> + final Graph graph =3D new SparqlGraph("http://localhost:" + > >> serverPort + "/ds/query"); > >> + Assert.assertEquals("Graph not of the exepected size", 8, > >> graph.size()); > >> + } > >> + > >> + @Test > >> + public void filter1() { > >> + final Graph graph =3D new SparqlGraph("http://localhost:" + > >> serverPort + "/ds/query"); > >> + final Iri spiderman =3D new Iri("http://example.org/#spiderma= n > "); > >> + final Iri greenGoblin =3D new Iri(" > http://example.org/#green-goblin > >> "); > >> + final Iri enemyOf =3D new Iri(" > >> http://www.perceive.net/schemas/relationship/enemyOf"); > >> + final Iri foafName =3D new Iri("http://xmlns.com/foaf/0.1/nam= e > "); > >> + { > >> + final Iterator iter =3D graph.filter(spiderman, n= ull, > >> greenGoblin); > >> + Assert.assertTrue(iter.hasNext()); > >> + Assert.assertEquals(enemyOf, iter.next().getPredicate()); > >> + Assert.assertFalse(iter.hasNext()); > >> + } > >> + { > >> + final Iterator iter =3D graph.filter(spiderman, > >> foafName, null); > >> + Set names =3D new HashSet<>(); > >> + for (int i =3D 0; i < 2; i++) { > >> + Assert.assertTrue(iter.hasNext()); > >> + RdfTerm name =3D iter.next().getObject(); > >> + Assert.assertTrue(name instanceof Literal); > >> + names.add((Literal)name); > >> + } > >> + Assert.assertFalse(iter.hasNext()); > >> + Assert.assertTrue(names.contains(new > >> PlainLiteralImpl("Spiderman"))); > >> + } > >> + } > >> + > >> + public static int findFreePort() { > >> + int port =3D 0; > >> + try (ServerSocket server =3D new ServerSocket(0);) { > >> + port =3D server.getLocalPort(); > >> + } catch (Exception e) { > >> + throw new RuntimeException("unable to find a free port"); > >> + } > >> + return port; > >> + } > >> + > >> +} > >> > >> Added: > >> > commons/sandbox/rdf/trunk/impl.sparql/src/test/resources/org/apache/commo= ns/rdf/impl/sparql/grounded.ttl > >> URL: > >> > http://svn.apache.org/viewvc/commons/sandbox/rdf/trunk/impl.sparql/src/te= st/resources/org/apache/commons/rdf/impl/sparql/grounded.ttl?rev=3D1659973&= view=3Dauto > >> > >> > =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D > >> --- > >> > commons/sandbox/rdf/trunk/impl.sparql/src/test/resources/org/apache/commo= ns/rdf/impl/sparql/grounded.ttl > >> (added) > >> +++ > >> > commons/sandbox/rdf/trunk/impl.sparql/src/test/resources/org/apache/commo= ns/rdf/impl/sparql/grounded.ttl > >> Sun Feb 15 18:41:15 2015 > >> @@ -0,0 +1,16 @@ > >> +@base . > >> +@prefix rdf: . > >> +@prefix rdfs: . > >> +@prefix foaf: . > >> +@prefix rel: . > >> + > >> +<#green-goblin> > >> + rel:enemyOf <#spiderman> ; > >> + a foaf:Person ; # in the context of the Marvel universe > >> + foaf:name "Green Goblin" ; > >> + foaf:age 128 . > >> + > >> +<#spiderman> > >> + rel:enemyOf <#green-goblin> ; > >> + a foaf:Person ; > >> + foaf:name "Spiderman", "=C3=90=C2=A7=C3=90=C2=B5=C3=90=C2=BB=C3= =90=C2=BE=C3=90=C2=B2=C3=90=C2=B5=C3=90=C2=BA-=C3=90=C2=BF=C3=90=C2=B0=C3= =91=C6=92=C3=90=C2=BA"@ru . > >> \ No newline at end of file > >> > >> Propchange: commons/sandbox/rdf/trunk/impl.utils/ > >> > >> > -------------------------------------------------------------------------= ----- > >> --- svn:ignore (added) > >> +++ svn:ignore Sun Feb 15 18:41:15 2015 > >> @@ -0,0 +1 @@ > >> +target > >> > >> Copied: commons/sandbox/rdf/trunk/impl.utils/pom.xml (from r1651181, > >> commons/sandbox/rdf/trunk/pom.xml) > >> URL: > >> > http://svn.apache.org/viewvc/commons/sandbox/rdf/trunk/impl.utils/pom.xml= ?p2=3Dcommons/sandbox/rdf/trunk/impl.utils/pom.xml&p1=3Dcommons/sandbox/rdf= /trunk/pom.xml&r1=3D1651181&r2=3D1659973&rev=3D1659973&view=3Ddiff > >> > >> > =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D > >> --- commons/sandbox/rdf/trunk/pom.xml (original) > >> +++ commons/sandbox/rdf/trunk/impl.utils/pom.xml Sun Feb 15 18:41:15 > 2015 > >> @@ -22,13 +22,14 @@ > >> > >> org.apache.commons > >> commons-parent > >> - 35 > >> + 37 > >> + > >> > >> 4.0.0 > >> commons-rdf > >> - commons-rdf > >> + commons-rdf-impl-utils > >> 0.1-SNAPSHOT > >> - Apache Commons RDF > >> + Apache Commons RDF Implementation Utils > >> > >> Apache Commons RDF provides an API modelling the RDF data mod= el > >> as defined by > >> http://www.w3.org/TR/rdf11-concepts/ > >> @@ -50,11 +51,22 @@ > >> > >> > >> > >> + commons-rdf > >> + commons-rdf-api > >> + 0.1-SNAPSHOT > >> + > >> + > >> junit > >> junit > >> 4.12 > >> test > >> > >> + > >> + org.slf4j > >> + slf4j-api > >> + 1.7.7 > >> + jar > >> + > >> > >> > >> > >> > >> Added: > >> > commons/sandbox/rdf/trunk/impl.utils/src/main/java/org/apache/commons/rdf= /impl/utils/AbstractGraph.java > >> URL: > >> > http://svn.apache.org/viewvc/commons/sandbox/rdf/trunk/impl.utils/src/mai= n/java/org/apache/commons/rdf/impl/utils/AbstractGraph.java?rev=3D1659973&v= iew=3Dauto > >> > >> > =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D > >> --- > >> > commons/sandbox/rdf/trunk/impl.utils/src/main/java/org/apache/commons/rdf= /impl/utils/AbstractGraph.java > >> (added) > >> +++ > >> > commons/sandbox/rdf/trunk/impl.utils/src/main/java/org/apache/commons/rdf= /impl/utils/AbstractGraph.java > >> Sun Feb 15 18:41:15 2015 > >> @@ -0,0 +1,316 @@ > >> +/* > >> + * Licensed to the Apache Software Foundation (ASF) under one > >> + * or more contributor license agreements. See the NOTICE file > >> + * distributed with this work for additional information > >> + * regarding copyright ownership. The ASF licenses this file > >> + * to you under the Apache License, Version 2.0 (the > >> + * "License"); you may not use this file except in compliance > >> + * with the License. You may obtain a copy of the License at > >> + * > >> + * http://www.apache.org/licenses/LICENSE-2.0 > >> + * > >> + * Unless required by applicable law or agreed to in writing, > >> + * software distributed under the License is distributed on an > >> + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY > >> + * KIND, either express or implied. See the License for the > >> + * specific language governing permissions and limitations > >> + * under the License. > >> + */ > >> +package org.apache.commons.rdf.impl.utils; > >> + > >> +import java.lang.ref.WeakReference; > >> +import java.util.AbstractCollection; > >> +import java.util.Collection; > >> +import java.util.Collections; > >> +import java.util.HashSet; > >> +import java.util.Iterator; > >> + > >> +import java.util.Set; > >> +import java.util.concurrent.locks.Lock; > >> +import java.util.concurrent.locks.ReadWriteLock; > >> +import java.util.concurrent.locks.ReentrantReadWriteLock; > >> +import org.apache.commons.rdf.BlankNodeOrIri; > >> +import org.apache.commons.rdf.RdfTerm; > >> +import org.apache.commons.rdf.Triple; > >> +import org.apache.commons.rdf.Graph; > >> +import org.apache.commons.rdf.ImmutableGraph; > >> +import org.apache.commons.rdf.Iri; > >> +import org.apache.commons.rdf.WatchableGraph; > >> +import org.apache.commons.rdf.event.AddEvent; > >> +import org.apache.commons.rdf.event.FilterTriple; > >> +import org.apache.commons.rdf.event.GraphEvent; > >> +import org.apache.commons.rdf.event.GraphListener; > >> +import org.apache.commons.rdf.event.RemoveEvent; > >> +import > >> org.apache.commons.rdf.impl.utils.debug.ReentrantReadWriteLockTracker; > >> +import org.apache.commons.rdf.impl.utils.simple.SimpleImmutableGraph; > >> + > >> +/** > >> + * An abstract implementation of Graph implementing > >> + * iterator and contains calling > >> filter. > >> + * > >> + * @author reto > >> + */ > >> +public abstract class AbstractGraph extends AbstractCollection > >> + implements Graph { > >> + > >> + > >> + private static final String DEBUG_MODE =3D "rdfLocksDebugging"; > >> + private final ReadWriteLock lock; > >> + > >> + private final Lock readLock; > >> + private final Lock writeLock; > >> + > >> + /** > >> + * Constructs a LocalbleMGraph for an Graph. > >> + * > >> + * @param providedMGraph a non-lockable graph > >> + */ > >> + public AbstractGraph() { > >> + { > >> + String debugMode =3D System.getProperty(DEBUG_MODE); > >> + if (debugMode !=3D null && > >> debugMode.toLowerCase().equals("true")) { > >> + lock =3D new ReentrantReadWriteLockTracker(); > >> + } else { > >> + lock =3D new ReentrantReadWriteLock(); > >> + } > >> + } > >> + readLock =3D lock.readLock(); > >> + writeLock =3D lock.writeLock(); > >> + } > >> + > >> + public AbstractGraph(final ReadWriteLock lock) { > >> + this.lock =3D lock; > >> + readLock =3D lock.readLock(); > >> + writeLock =3D lock.writeLock(); > >> + } > >> + > >> + @Override > >> + public ReadWriteLock getLock() { > >> + return lock; > >> + } > >> + > >> + @Override > >> + public ImmutableGraph getImmutableGraph() { > >> + readLock.lock(); > >> + try { > >> + return performGetImmutableGraph(); > >> + } finally { > >> + readLock.unlock(); > >> + } > >> + } > >> + > >> + public ImmutableGraph performGetImmutableGraph() { > >> + return new SimpleImmutableGraph(this); > >> + } > >> + > >> + @Override > >> + public Iterator filter(BlankNodeOrIri subject, Iri > predicate, > >> RdfTerm object) { > >> + readLock.lock(); > >> + try { > >> + return new LockingIterator(performFilter(subject, > predicate, > >> object), lock); > >> + } finally { > >> + readLock.unlock(); > >> + } > >> + } > >> + > >> + @Override > >> + public int size() { > >> + readLock.lock(); > >> + try { > >> + return performSize(); > >> + } finally { > >> + readLock.unlock(); > >> + } > >> + } > >> + > >> + @Override > >> + public boolean isEmpty() { > >> + readLock.lock(); > >> + try { > >> + return performIsEmpty(); > >> + } finally { > >> + readLock.unlock(); > >> + } > >> + } > >> + > >> + @Override > >> + @SuppressWarnings("element-type-mismatch") > >> + public boolean contains(Object o) { > >> + readLock.lock(); > >> + try { > >> + return performContains(o); > >> + } finally { > >> + readLock.unlock(); > >> + } > >> + } > >> + > >> + @Override > >> + public Iterator iterator() { > >> + readLock.lock(); > >> + try { > >> + return new LockingIterator(performIterator(), lock); > >> + } finally { > >> + readLock.unlock(); > >> + } > >> + } > >> + > >> + @Override > >> + public Object[] toArray() { > >> + readLock.lock(); > >> + try { > >> + return performToArray(); > >> + } finally { > >> + readLock.unlock(); > >> + } > >> + } > >> + > >> + @Override > >> + public T[] toArray(T[] a) { > >> + readLock.lock(); > >> + try { > >> + return performToArray(a); > >> + } finally { > >> + readLock.unlock(); > >> + } > >> + } > >> + > >> + @Override > >> + public boolean containsAll(Collection c) { > >> + readLock.lock(); > >> + try { > >> + return performContainsAll(c); > >> + } finally { > >> + readLock.unlock(); > >> + } > >> + } > >> + > >> + @Override > >> + public boolean add(Triple e) { > >> + writeLock.lock(); > >> + try { > >> + return performAdd(e); > >> + } finally { > >> + writeLock.unlock(); > >> + } > >> + } > >> + > >> + @Override > >> + public boolean remove(Object o) { > >> + writeLock.lock(); > >> + try { > >> + return performRemove(o); > >> + } finally { > >> + writeLock.unlock(); > >> + } > >> + } > >> + > >> + @Override > >> + public boolean addAll(Collection c) { > >> + writeLock.lock(); > >> + try { > >> + return performAddAll(c); > >> + } finally { > >> + writeLock.unlock(); > >> + } > >> + } > >> + > >> + @Override > >> + public boolean removeAll(Collection c) { > >> + writeLock.lock(); > >> + try { > >> + return performRemoveAll(c); > >> + } finally { > >> + writeLock.unlock(); > >> + } > >> + } > >> + > >> + @Override > >> + public boolean retainAll(Collection c) { > >> + writeLock.lock(); > >> + try { > >> + return performRetainAll(c); > >> + } finally { > >> + writeLock.unlock(); > >> + } > >> + } > >> + > >> + @Override > >> + public void clear() { > >> + writeLock.lock(); > >> + try { > >> + performClear(); > >> + } finally { > >> + writeLock.unlock(); > >> + } > >> + } > >> + > >> + > >> + @Override > >> + public boolean equals(Object obj) { > >> + /*if (obj =3D=3D null) { > >> + return false; > >> + } > >> + if (obj =3D=3D this) { > >> + return true; > >> + } > >> + if (obj.getClass() !=3D getClass()) { > >> + return false; > >> + }*/ > >> + return this =3D=3D obj; > >> + } > >> + > >> + > >> + protected abstract Iterator performFilter(BlankNodeOrIri > >> subject, Iri predicate, RdfTerm object); > >> + > >> + protected abstract int performSize(); > >> + > >> + protected boolean performIsEmpty() { > >> + return super.isEmpty(); > >> + } > >> + > >> + protected Object[] performToArray() { > >> + return super.toArray(); > >> + } > >> + > >> + protected boolean performRemove(Object o) { > >> + return super.remove(o); > >> + } > >> + > >> + protected boolean performAddAll(Collection c) { > >> + return super.addAll(c); > >> + } > >> + > >> + protected boolean performRemoveAll(Collection c) { > >> + return super.removeAll(c); > >> + } > >> + > >> + protected boolean performRetainAll(Collection c) { > >> + return super.retainAll(c); > >> + } > >> + > >> + protected void performClear() { > >> + super.clear(); > >> + } > >> + > >> + protected boolean performContains(Object o) { > >> + return super.contains(o); > >> + } > >> + > >> + protected Iterator performIterator() { > >> + return performFilter(null, null, null); > >> + } > >> + > >> + protected boolean performContainsAll(Collection c) { > >> + return super.containsAll(c); > >> + } > >> + > >> + protected T[] performToArray(T[] a) { > >> + return super.toArray(a); > >> + } > >> + > >> + protected boolean performAdd(Triple e) { > >> + return super.add(e); > >> + } > >> + > >> + > >> +} > >> > >> Added: > >> > commons/sandbox/rdf/trunk/impl.utils/src/main/java/org/apache/commons/rdf= /impl/utils/AbstractImmutableGraph.java > >> URL: > >> > http://svn.apache.org/viewvc/commons/sandbox/rdf/trunk/impl.utils/src/mai= n/java/org/apache/commons/rdf/impl/utils/AbstractImmutableGraph.java?rev=3D= 1659973&view=3Dauto > >> > >> > =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D > >> --- > >> > commons/sandbox/rdf/trunk/impl.utils/src/main/java/org/apache/commons/rdf= /impl/utils/AbstractImmutableGraph.java > >> (added) > >> +++ > >> > commons/sandbox/rdf/trunk/impl.utils/src/main/java/org/apache/commons/rdf= /impl/utils/AbstractImmutableGraph.java > >> Sun Feb 15 18:41:15 2015 > >> @@ -0,0 +1,112 @@ > >> +/* > >> + * Licensed to the Apache Software Foundation (ASF) under one > >> + * or more contributor license agreements. See the NOTICE file > >> + * distributed with this work for additional information > >> + * regarding copyright ownership. The ASF licenses this file > >> + * to you under the Apache License, Version 2.0 (the > >> + * "License"); you may not use this file except in compliance > >> + * with the License. You may obtain a copy of the License at > >> + * > >> + * http://www.apache.org/licenses/LICENSE-2.0 > >> + * > >> + * Unless required by applicable law or agreed to in writing, > >> + * software distributed under the License is distributed on an > >> + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY > >> + * KIND, either express or implied. See the License for the > >> + * specific language governing permissions and limitations > >> + * under the License. > >> + */ > >> +package org.apache.commons.rdf.impl.utils; > >> + > >> +import java.util.Collection; > >> +import java.util.Iterator; > >> + > >> +import org.apache.commons.rdf.BlankNode; > >> +import org.apache.commons.rdf.ImmutableGraph; > >> +import org.apache.commons.rdf.RdfTerm; > >> +import org.apache.commons.rdf.Triple; > >> +import org.apache.commons.rdf.impl.utils.graphmatching.GraphMatcher; > >> + > >> +/** > >> + * AbstractGraph is an abstract implementation of > >> ImmutableGraph > >> + * implementing the equals and the hashCode > >> methods. > >> + * > >> + * @author reto > >> + * > >> + */ > >> +public abstract class AbstractImmutableGraph extends AbstractGraph > >> + implements ImmutableGraph { > >> + > >> + public final synchronized int hashCode() { > >> + int result =3D 0; > >> + for (Iterator iter =3D iterator(); iter.hasNext();) { > >> + result +=3D getBlankNodeBlindHash(iter.next()); > >> + } > >> + return result; > >> + } > >> + > >> + /** > >> + * @param triple > >> + * @return hash without BNode hashes > >> + */ > >> + private int getBlankNodeBlindHash(Triple triple) { > >> + int hash =3D triple.getPredicate().hashCode(); > >> + RdfTerm subject =3D triple.getSubject(); > >> + > >> + if (!(subject instanceof BlankNode)) { > >> + hash ^=3D subject.hashCode() >> 1; > >> + } > >> + RdfTerm object =3D triple.getObject(); > >> + if (!(object instanceof BlankNode)) { > >> + hash ^=3D object.hashCode() << 1; > >> + } > >> + > >> + return hash; > >> + } > >> + > >> + @Override > >> + public boolean add(Triple e) { > >> + throw new UnsupportedOperationException("Graphs are not > mutable, > >> use Graph"); > >> + > >> + } > >> + > >> + @Override > >> + public boolean addAll(Collection c) { > >> + throw new UnsupportedOperationException("Graphs are not > mutable, > >> use Graph"); > >> + } > >> + > >> + @Override > >> + public boolean remove(Object o) { > >> + throw new UnsupportedOperationException("Graphs are not > mutable, > >> use Graph"); > >> + } > >> + > >> + @Override > >> + public boolean removeAll(Collection c) { > >> + throw new UnsupportedOperationException("Graphs are not > mutable, > >> use Graph"); > >> + } > >> + > >> + @Override > >> + public void clear() { > >> + throw new UnsupportedOperationException("Graphs are not > mutable, > >> use Graph"); > >> + } > >> + > >> + > >> + @Override > >> + public ImmutableGraph getImmutableGraph() { > >> + return this; > >> + } > >> + > >> + @Override > >> + public boolean equals(Object obj) { > >> + if (this =3D=3D obj) { > >> + return true; > >> + } > >> + if (!(obj instanceof ImmutableGraph)) { > >> + return false; > >> + } > >> + if (hashCode() !=3D obj.hashCode()) { > >> + return false; > >> + } > >> + return GraphMatcher.getValidMapping(this, (ImmutableGraph) ob= j) > >> !=3D null; > >> + } > >> +} > >> > >> Added: > >> > commons/sandbox/rdf/trunk/impl.utils/src/main/java/org/apache/commons/rdf= /impl/utils/AbstractLiteral.java > >> URL: > >> > http://svn.apache.org/viewvc/commons/sandbox/rdf/trunk/impl.utils/src/mai= n/java/org/apache/commons/rdf/impl/utils/AbstractLiteral.java?rev=3D1659973= &view=3Dauto > >> > >> > =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D > >> --- > >> > commons/sandbox/rdf/trunk/impl.utils/src/main/java/org/apache/commons/rdf= /impl/utils/AbstractLiteral.java > >> (added) > >> +++ > >> > commons/sandbox/rdf/trunk/impl.utils/src/main/java/org/apache/commons/rdf= /impl/utils/AbstractLiteral.java > >> Sun Feb 15 18:41:15 2015 > >> @@ -0,0 +1,61 @@ > >> +/* > >> + * Copyright 2015 The Apache Software Foundation. > >> + * > >> + * Licensed under the Apache License, Version 2.0 (the "License"); > >> + * you may not use this file except in compliance with the License. > >> + * You may obtain a copy of the License at > >> + * > >> + * http://www.apache.org/licenses/LICENSE-2.0 > >> + * > >> + * Unless required by applicable law or agreed to in writing, softwar= e > >> + * distributed under the License is distributed on an "AS IS" BASIS, > >> + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or > >> implied. > >> + * See the License for the specific language governing permissions an= d > >> + * limitations under the License. > >> + */ > >> +package org.apache.commons.rdf.impl.utils; > >> + > >> +import org.apache.commons.rdf.Literal; > >> + > >> +/** > >> + * > >> + * @author developer > >> + */ > >> +public abstract class AbstractLiteral implements Literal { > >> + > >> + @Override > >> + public int hashCode() { > >> + int result =3D 0; > >> + if (getLanguage() !=3D null) { > >> + result =3D getLanguage().hashCode(); > >> + } > >> + result +=3D getLexicalForm().hashCode(); > >> + result +=3D getDataType().hashCode(); > >> + return result; > >> + } > >> + > >> + @Override > >> + public boolean equals(Object obj) { > >> + if (this =3D=3D obj) { > >> + return true; > >> + } > >> + if (obj instanceof Literal) { > >> + Literal other =3D (Literal) obj; > >> + > >> + if (getLanguage() =3D=3D null) { > >> + if (other.getLanguage() !=3D null) { > >> + return false; > >> + } > >> + } else { > >> + if (!getLanguage().equals(other.getLanguage())) { > >> + return false; > >> + } > >> + } > >> + boolean res =3D getDataType().equals(other.getDataType())= && > >> getLexicalForm().equals(other.getLexicalForm()); > >> + return res; > >> + } else { > >> + return false; > >> + } > >> + } > >> + > >> +} > >> > >> Added: > >> > commons/sandbox/rdf/trunk/impl.utils/src/main/java/org/apache/commons/rdf= /impl/utils/DelayedNotificator.java > >> URL: > >> > http://svn.apache.org/viewvc/commons/sandbox/rdf/trunk/impl.utils/src/mai= n/java/org/apache/commons/rdf/impl/utils/DelayedNotificator.java?rev=3D1659= 973&view=3Dauto > >> > >> > =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D > >> --- > >> > commons/sandbox/rdf/trunk/impl.utils/src/main/java/org/apache/commons/rdf= /impl/utils/DelayedNotificator.java > >> (added) > >> +++ > >> > commons/sandbox/rdf/trunk/impl.utils/src/main/java/org/apache/commons/rdf= /impl/utils/DelayedNotificator.java > >> Sun Feb 15 18:41:15 2015 > >> @@ -0,0 +1,112 @@ > >> +/* > >> + * Licensed to the Apache Software Foundation (ASF) under one > >> + * or more contributor license agreements. See the NOTICE file > >> + * distributed with this work for additional information > >> + * regarding copyright ownership. The ASF licenses this file > >> + * to you under the Apache License, Version 2.0 (the > >> + * "License"); you may not use this file except in compliance > >> + * with the License. You may obtain a copy of the License at > >> + * > >> + * http://www.apache.org/licenses/LICENSE-2.0 > >> + * > >> + * Unless required by applicable law or agreed to in writing, > >> + * software distributed under the License is distributed on an > >> + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY > >> + * KIND, either express or implied. See the License for the > >> + * specific language governing permissions and limitations > >> + * under the License. > >> + */ > >> +package org.apache.commons.rdf.impl.utils; > >> + > >> +import java.lang.ref.WeakReference; > >> +import java.util.*; > >> + > >> +import org.apache.commons.rdf.event.GraphEvent; > >> +import org.apache.commons.rdf.event.GraphListener; > >> +import org.slf4j.Logger; > >> +import org.slf4j.LoggerFactory; > >> + > >> +/** > >> + * > >> + * @author reto > >> + */ > >> +class DelayedNotificator { > >> + > >> + private static final Logger log =3D > >> LoggerFactory.getLogger(DelayedNotificator.class); > >> + private static Timer timer =3D new Timer("Event delivery > timer",true); > >> + > >> + static class ListenerHolder { > >> + > >> + long delay; > >> + List events =3D null; > >> + WeakReference listenerRef; > >> + > >> + public ListenerHolder(GraphListener listener, long delay) { > >> + this.listenerRef =3D new > WeakReference(listener); > >> + this.delay =3D delay; > >> + } > >> + > >> + private void registerEvent(GraphEvent event) { > >> + synchronized (this) { > >> + if (events =3D=3D null) { > >> + events =3D new ArrayList(); > >> + events.add(event); > >> + timer.schedule(new TimerTask() { > >> + > >> + @Override > >> + public void run() { > >> + List eventsLocal; > >> + synchronized (ListenerHolder.this) { > >> + eventsLocal =3D events; > >> + events =3D null; > >> + } > >> + GraphListener listener =3D listenerRef.ge= t(); > >> + if (listener =3D=3D null) { > >> + log.debug("Ignoring garbage collected > >> listener"); > >> + } else { > >> + try { > >> + listener.graphChanged(eventsLocal= ); > >> + } catch (Exception e) { > >> + log.warn("Exception delivering > >> ImmutableGraph event", e); > >> + } > >> + } > >> + } > >> + }, delay); > >> + } else { > >> + events.add(event); > >> + } > >> + } > >> + } > >> + } > >> + > >> + private final Map map =3D > >> Collections.synchronizedMap( > >> + new WeakHashMap()); > >> + > >> + void addDelayedListener(GraphListener listener, long delay) { > >> + map.put(listener, new ListenerHolder(listener, delay)); > >> + } > >> + > >> + /** > >> + * removes a Listener, this doesn't prevent the listenerRef from > >> receiving > >> + * events alreay scheduled. > >> + * > >> + * @param listenerRef > >> + */ > >> + void removeDelayedListener(GraphListener listener) { > >> + map.remove(listener); > >> + } > >> + > >> + /** > >> + * if the listenerRef has not been registered as delayed > listenerRef > >> te events is > >> + * forwarded synchroneously > >> + * @param event > >> + */ > >> + void sendEventToListener(GraphListener listener, GraphEvent event= ) > { > >> + ListenerHolder holder =3D map.get(listener); > >> + if (holder =3D=3D null) { > >> + listener.graphChanged(Collections.singletonList(event)); > >> + } else { > >> + holder.registerEvent(event); > >> + } > >> + } > >> +} > >> > >> Added: > >> > commons/sandbox/rdf/trunk/impl.utils/src/main/java/org/apache/commons/rdf= /impl/utils/LockingIterator.java > >> URL: > >> > http://svn.apache.org/viewvc/commons/sandbox/rdf/trunk/impl.utils/src/mai= n/java/org/apache/commons/rdf/impl/utils/LockingIterator.java?rev=3D1659973= &view=3Dauto > >> > >> > =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D > >> --- > >> > commons/sandbox/rdf/trunk/impl.utils/src/main/java/org/apache/commons/rdf= /impl/utils/LockingIterator.java > >> (added) > >> +++ > >> > commons/sandbox/rdf/trunk/impl.utils/src/main/java/org/apache/commons/rdf= /impl/utils/LockingIterator.java > >> Sun Feb 15 18:41:15 2015 > >> @@ -0,0 +1,73 @@ > >> +/* > >> + * Licensed to the Apache Software Foundation (ASF) under one > >> + * or more contributor license agreements. See the NOTICE file > >> + * distributed with this work for additional information > >> + * regarding copyright ownership. The ASF licenses this file > >> + * to you under the Apache License, Version 2.0 (the > >> + * "License"); you may not use this file except in compliance > >> + * with the License. You may obtain a copy of the License at > >> + * > >> + * http://www.apache.org/licenses/LICENSE-2.0 > >> + * > >> + * Unless required by applicable law or agreed to in writing, > >> + * software distributed under the License is distributed on an > >> + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY > >> + * KIND, either express or implied. See the License for the > >> + * specific language governing permissions and limitations > >> + * under the License. > >> + */ > >> +package org.apache.commons.rdf.impl.utils; > >> + > >> +import java.util.Iterator; > >> +import java.util.concurrent.locks.Lock; > >> +import java.util.concurrent.locks.ReadWriteLock; > >> +import org.apache.commons.rdf.Triple; > >> + > >> +/** > >> + * Wrapps an iterator reading entering a read-lock on every > >> invocation > >> + * of hasNext and next > >> + * @author reto > >> + */ > >> +class LockingIterator implements Iterator { > >> + > >> + private Iterator base; > >> + private Lock readLock; > >> + private Lock writeLock; > >> + > >> + public LockingIterator(Iterator iterator, ReadWriteLock > lock) > >> { > >> + base =3D iterator; > >> + readLock =3D lock.readLock(); > >> + writeLock =3D lock.writeLock(); > >> + } > >> + > >> + @Override > >> + public boolean hasNext() { > >> + readLock.lock(); > >> + try { > >> + return base.hasNext(); > >> + } finally { > >> + readLock.unlock(); > >> + } > >> + } > >> + > >> + @Override > >> + public Triple next() { > >> + readLock.lock(); > >> + try { > >> + return base.next(); > >> + } finally { > >> + readLock.unlock(); > >> + } > >> + } > >> + > >> + @Override > >> + public void remove() { > >> + writeLock.lock(); > >> + try { > >> + base.remove(); > >> + } finally { > >> + writeLock.unlock(); > >> + } > >> + } > >> + > >> +} > >> > >> Added: > >> > commons/sandbox/rdf/trunk/impl.utils/src/main/java/org/apache/commons/rdf= /impl/utils/PlainLiteralImpl.java > >> URL: > >> > http://svn.apache.org/viewvc/commons/sandbox/rdf/trunk/impl.utils/src/mai= n/java/org/apache/commons/rdf/impl/utils/PlainLiteralImpl.java?rev=3D165997= 3&view=3Dauto > >> > >> > =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D > >> --- > >> > commons/sandbox/rdf/trunk/impl.utils/src/main/java/org/apache/commons/rdf= /impl/utils/PlainLiteralImpl.java > >> (added) > >> +++ > >> > commons/sandbox/rdf/trunk/impl.utils/src/main/java/org/apache/commons/rdf= /impl/utils/PlainLiteralImpl.java > >> Sun Feb 15 18:41:15 2015 > >> @@ -0,0 +1,104 @@ > >> +/* > >> + * Licensed to the Apache Software Foundation (ASF) under one > >> + * or more contributor license agreements. See the NOTICE file > >> + * distributed with this work for additional information > >> + * regarding copyright ownership. The ASF licenses this file > >> + * to you under the Apache License, Version 2.0 (the > >> + * "License"); you may not use this file except in compliance > >> + * with the License. You may obtain a copy of the License at > >> + * > >> + * http://www.apache.org/licenses/LICENSE-2.0 > >> + * > >> + * Unless required by applicable law or agreed to in writing, > >> + * software distributed under the License is distributed on an > >> + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY > >> + * KIND, either express or implied. See the License for the > >> + * specific language governing permissions and limitations > >> + * under the License. > >> + */ > >> +package org.apache.commons.rdf.impl.utils; > >> + > >> +import java.io.Serializable; > >> +import org.apache.commons.rdf.Iri; > >> + > >> +import org.apache.commons.rdf.Language; > >> +import org.apache.commons.rdf.Literal; > >> + > >> +/** > >> + * > >> + * @author reto > >> + */ > >> +public class PlainLiteralImpl implements Literal, Serializable { > >> + > >> + private String lexicalForm; > >> + private Language language =3D null; > >> + > >> + public PlainLiteralImpl(String value) { > >> + if (value =3D=3D null) { > >> + throw new IllegalArgumentException("The literal string > cannot > >> be null"); > >> + } > >> + this.lexicalForm =3D value; > >> + } > >> + > >> + public PlainLiteralImpl(String value, Language language) { > >> + if (value =3D=3D null) { > >> + throw new IllegalArgumentException("The literal string > cannot > >> be null"); > >> + } > >> + this.lexicalForm =3D value; > >> + this.language =3D language; > >> + } > >> + > >> + @Override > >> + public String getLexicalForm() { > >> + return lexicalForm; > >> + } > >> + > >> + @Override > >> + public boolean equals(Object otherObj) { > >> + if (!(otherObj instanceof Literal)) { > >> + return false; > >> + } > >> + Literal other =3D (Literal) otherObj; > >> + if (!lexicalForm.equals(other.getLexicalForm())) { > >> + return false; > >> + } > >> + if (language !=3D null) { > >> + return language.equals(other.getLanguage()); > >> + } > >> + if (other.getLanguage() !=3D null) { > >> + return false; > >> + } > >> + return true; > >> + } > >> + > >> + @Override > >> + public int hashCode() { > >> + int hash =3D lexicalForm.hashCode() + XSD_STRING_HASH; > >> + if (language !=3D null) { > >> + hash +=3D language.hashCode(); > >> + } > >> + return hash; > >> + } > >> + > >> + @Override > >> + public Language getLanguage() { > >> + return language; > >> + } > >> + > >> + @Override > >> + public String toString() { > >> + StringBuffer result =3D new StringBuffer(); > >> + result.append('\"').append(lexicalForm).append('\"'); > >> + if (language !=3D null) { > >> + result.append("@").append(language.toString()); > >> + } > >> + return result.toString(); > >> + } > >> + > >> + @Override > >> + public Iri getDataType() { > >> + return XSD_STRING; > >> + } > >> + private static final Iri XSD_STRING =3D new Iri(" > >> http://www.w3.org/2001/XMLSchema#string"); > >> + private static final int XSD_STRING_HASH =3D XSD_STRING.hashCode(= ); > >> +} > >> > >> Added: > >> > commons/sandbox/rdf/trunk/impl.utils/src/main/java/org/apache/commons/rdf= /impl/utils/TripleImpl.java > >> URL: > >> > http://svn.apache.org/viewvc/commons/sandbox/rdf/trunk/impl.utils/src/mai= n/java/org/apache/commons/rdf/impl/utils/TripleImpl.java?rev=3D1659973&view= =3Dauto > >> > >> > =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D > >> --- > >> > commons/sandbox/rdf/trunk/impl.utils/src/main/java/org/apache/commons/rdf= /impl/utils/TripleImpl.java > >> (added) > >> +++ > >> > commons/sandbox/rdf/trunk/impl.utils/src/main/java/org/apache/commons/rdf= /impl/utils/TripleImpl.java > >> Sun Feb 15 18:41:15 2015 > >> @@ -0,0 +1,100 @@ > >> +/* > >> + * Licensed to the Apache Software Foundation (ASF) under one > >> + * or more contributor license agreements. See the NOTICE file > >> + * distributed with this work for additional information > >> + * regarding copyright ownership. The ASF licenses this file > >> + * to you under the Apache License, Version 2.0 (the > >> + * "License"); you may not use this file except in compliance > >> + * with the License. You may obtain a copy of the License at > >> + * > >> + * http://www.apache.org/licenses/LICENSE-2.0 > >> + * > >> + * Unless required by applicable law or agreed to in writing, > >> + * software distributed under the License is distributed on an > >> + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY > >> + * KIND, either express or implied. See the License for the > >> + * specific language governing permissions and limitations > >> + * under the License. > >> + */ > >> +package org.apache.commons.rdf.impl.utils; > >> + > >> +import org.apache.commons.rdf.BlankNodeOrIri; > >> +import org.apache.commons.rdf.RdfTerm; > >> +import org.apache.commons.rdf.Triple; > >> +import org.apache.commons.rdf.Iri; > >> + > >> +/** > >> + * > >> + * @author reto > >> + */ > >> +public class TripleImpl implements Triple { > >> + > >> + private final BlankNodeOrIri subject; > >> + private final Iri predicate; > >> + private final RdfTerm object; > >> + > >> + /** > >> + * Creates a new TripleImpl. > >> + * > >> + * @param subject the subject. > >> + * @param predicate the predicate. > >> + * @param object the object. > >> + * @throws IllegalArgumentException if an attribute is > >> null. > >> + */ > >> + public TripleImpl(BlankNodeOrIri subject, Iri predicate, RdfTerm > >> object) { > >> + if (subject =3D=3D null) { > >> + throw new IllegalArgumentException("Invalid subject: > null"); > >> + } else if (predicate =3D=3D null) { > >> + throw new IllegalArgumentException("Invalid predicate: > null"); > >> + } else if (object =3D=3D null) { > >> + throw new IllegalArgumentException("Invalid object: null"= ); > >> + } > >> + this.subject =3D subject; > >> + this.predicate =3D predicate; > >> + this.object =3D object; > >> + } > >> + > >> + @Override > >> + public boolean equals(Object obj) { > >> + if (obj =3D=3D null) { > >> + return false; > >> + } > >> + if (!(obj instanceof Triple)) { > >> + return false; > >> + } > >> + final Triple other =3D (Triple) obj; > >> + if (!this.subject.equals(other.getSubject())) { > >> + return false; > >> + } > >> + if (!this.predicate.equals(other.getPredicate())) { > >> + return false; > >> + } > >> + if (!this.object.equals(other.getObject())) { > >> + return false; > >> + } > >> + return true; > >> + } > >> + > >> + @Override > >> + public int hashCode() { > >> + return (subject.hashCode() >> 1) ^ predicate.hashCode() ^ > >> (object.hashCode() << 1); > >> + } > >> + > >> + @Override > >> + public BlankNodeOrIri getSubject() { > >> + return subject; > >> + } > >> + > >> + public Iri getPredicate() { > >> + return predicate; > >> + } > >> + > >> + public RdfTerm getObject() { > >> + return object; > >> + } > >> + > >> + @Override > >> + public String toString() { > >> + return subject + " " + predicate + " " + object + "."; > >> + } > >> +} > >> > >> Added: > >> > commons/sandbox/rdf/trunk/impl.utils/src/main/java/org/apache/commons/rdf= /impl/utils/TypedLiteralImpl.java > >> URL: > >> > http://svn.apache.org/viewvc/commons/sandbox/rdf/trunk/impl.utils/src/mai= n/java/org/apache/commons/rdf/impl/utils/TypedLiteralImpl.java?rev=3D165997= 3&view=3Dauto > >> > >> > =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D > >> --- > >> > commons/sandbox/rdf/trunk/impl.utils/src/main/java/org/apache/commons/rdf= /impl/utils/TypedLiteralImpl.java > >> (added) > >> +++ > >> > commons/sandbox/rdf/trunk/impl.utils/src/main/java/org/apache/commons/rdf= /impl/utils/TypedLiteralImpl.java > >> Sun Feb 15 18:41:15 2015 > >> @@ -0,0 +1,80 @@ > >> +/* > >> + * Licensed to the Apache Software Foundation (ASF) under one > >> + * or more contributor license agreements. See the NOTICE file > >> + * distributed with this work for additional information > >> + * regarding copyright ownership. The ASF licenses this file > >> + * to you under the Apache License, Version 2.0 (the > >> + * "License"); you may not use this file except in compliance > >> + * with the License. You may obtain a copy of the License at > >> + * > >> + * http://www.apache.org/licenses/LICENSE-2.0 > >> + * > >> + * Unless required by applicable law or agreed to in writing, > >> + * software distributed under the License is distributed on an > >> + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY > >> + * KIND, either express or implied. See the License for the > >> + * specific language governing permissions and limitations > >> + * under the License. > >> + */ > >> +package org.apache.commons.rdf.impl.utils; > >> + > >> +import java.io.Serializable; > >> + > >> +import org.apache.commons.rdf.Iri; > >> +import org.apache.commons.rdf.Language; > >> +import org.apache.commons.rdf.Literal; > >> + > >> +/** > >> + * > >> + * @author reto > >> + */ > >> +public class TypedLiteralImpl extends AbstractLiteral implements > >> Serializable { > >> + private String lexicalForm; > >> + private Iri dataType; > >> + private int hashCode; > >> + > >> + /** > >> + * @param lexicalForm > >> + * @param dataType > >> + */ > >> + public TypedLiteralImpl(String lexicalForm, Iri dataType) { > >> + this.lexicalForm =3D lexicalForm; > >> + this.dataType =3D dataType; > >> + this.hashCode =3D lexicalForm.hashCode()+dataType.hashCode(); > >> + } > >> + > >> + public Iri getDataType() { > >> + return dataType; > >> + } > >> + > >> + /* (non-Javadoc) > >> + * @see org.apache.clerezza.rdf.core.LiteralNode#getLexicalForm() > >> + */ > >> + @Override > >> + public String getLexicalForm() { > >> + return lexicalForm; > >> + } > >> + > >> + @Override > >> + public int hashCode() { > >> + return hashCode; > >> + } > >> + > >> + > >> + @Override > >> + public String toString() { > >> + StringBuffer result =3D new StringBuffer(); > >> + result.append('\"'); > >> + result.append(getLexicalForm()); > >> + result.append('\"'); > >> + result.append("^^"); > >> + result.append(getDataType()); > >> + return result.toString(); > >> + } > >> + > >> + @Override > >> + public Language getLanguage() { > >> + return null; > >> + } > >> + > >> +} > >> > >> Added: > >> > commons/sandbox/rdf/trunk/impl.utils/src/main/java/org/apache/commons/rdf= /impl/utils/WatchableGraphWrapper.java > >> URL: > >> > http://svn.apache.org/viewvc/commons/sandbox/rdf/trunk/impl.utils/src/mai= n/java/org/apache/commons/rdf/impl/utils/WatchableGraphWrapper.java?rev=3D1= 659973&view=3Dauto > >> > >> > =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D > >> --- > >> > commons/sandbox/rdf/trunk/impl.utils/src/main/java/org/apache/commons/rdf= /impl/utils/WatchableGraphWrapper.java > >> (added) > >> +++ > >> > commons/sandbox/rdf/trunk/impl.utils/src/main/java/org/apache/commons/rdf= /impl/utils/WatchableGraphWrapper.java > >> Sun Feb 15 18:41:15 2015 > >> @@ -0,0 +1,289 @@ > >> +/* > >> + * Copyright 2015 The Apache Software Foundation. > >> + * > >> + * Licensed under the Apache License, Version 2.0 (the "License"); > >> + * you may not use this file except in compliance with the License. > >> + * You may obtain a copy of the License at > >> + * > >> + * http://www.apache.org/licenses/LICENSE-2.0 > >> + * > >> + * Unless required by applicable law or agreed to in writing, softwar= e > >> + * distributed under the License is distributed on an "AS IS" BASIS, > >> + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or > >> implied. > >> + * See the License for the specific language governing permissions an= d > >> + * limitations under the License. > >> + */ > >> +package org.apache.commons.rdf.impl.utils; > >> + > >> +import java.lang.ref.WeakReference; > >> +import java.util.Collection; > >> +import java.util.Collections; > >> +import java.util.HashSet; > >> +import java.util.Iterator; > >> +import java.util.Set; > >> +import java.util.concurrent.locks.ReadWriteLock; > >> +import org.apache.commons.rdf.BlankNodeOrIri; > >> +import org.apache.commons.rdf.Graph; > >> +import org.apache.commons.rdf.ImmutableGraph; > >> +import org.apache.commons.rdf.Iri; > >> +import org.apache.commons.rdf.RdfTerm; > >> +import org.apache.commons.rdf.Triple; > >> +import org.apache.commons.rdf.WatchableGraph; > >> +import org.apache.commons.rdf.event.AddEvent; > >> +import org.apache.commons.rdf.event.FilterTriple; > >> +import org.apache.commons.rdf.event.GraphEvent; > >> +import org.apache.commons.rdf.event.GraphListener; > >> +import org.apache.commons.rdf.event.RemoveEvent; > >> + > >> +/** > >> + * > >> + * @author developer > >> + */ > >> +public class WatchableGraphWrapper implements WatchableGraph { > >> + > >> + final Graph wrapped; > >> + > >> + public WatchableGraphWrapper(Graph wrapped) { > >> + this.wrapped =3D wrapped; > >> + } > >> + > >> + > >> + //all listeners > >> + private final Set listenerConfigs =3D > >> Collections.synchronizedSet( > >> + new HashSet()); > >> + private DelayedNotificator delayedNotificator =3D new > >> DelayedNotificator(); > >> + > >> + @Override > >> + public Iterator iterator() { > >> + return filter(null, null, null); > >> + } > >> + > >> + @Override > >> + public boolean contains(Object o) { > >> + if (!(o instanceof Triple)) { > >> + return false; > >> + } > >> + Triple t =3D (Triple) o; > >> + return filter(t.getSubject(), t.getPredicate(), > >> t.getObject()).hasNext(); > >> + } > >> + > >> + @Override > >> + public Iterator filter(BlankNodeOrIri subject, Iri > predicate, > >> + RdfTerm object) { > >> + final Iterator baseIter =3D wrapped.filter(subject, > >> predicate, object); > >> + return new Iterator() { > >> + > >> + Triple currentTriple =3D null; > >> + > >> + @Override > >> + public boolean hasNext() { > >> + return baseIter.hasNext(); > >> + } > >> + > >> + @Override > >> + public Triple next() { > >> + currentTriple =3D baseIter.next(); > >> + return currentTriple; > >> + } > >> + > >> + @Override > >> + public void remove() { > >> + baseIter.remove(); > >> + dispatchEvent(new > RemoveEvent(WatchableGraphWrapper.this, > >> currentTriple)); > >> + } > >> + }; > >> + } > >> + > >> + @Override > >> + public boolean add(Triple triple) { > >> + boolean success =3D performAdd(triple); > >> + if (success) { > >> + dispatchEvent(new AddEvent(this, triple)); > >> + } > >> + return success; > >> + } > >> + > >> + /** > >> + * A subclass of AbstractGraph should override > >> + * this method instead of add for Graph event suppor= t > to > >> be > >> + * added. > >> + * > >> + * @param e The triple to be added to the triple collection > >> + * @return > >> + */ > >> + protected boolean performAdd(Triple e) { > >> + return wrapped.add(e); > >> + } > >> + > >> + @Override > >> + public boolean remove(Object o) { > >> + Triple triple =3D (Triple) o; > >> + boolean success =3D performRemove(triple); > >> + if (success) { > >> + dispatchEvent(new RemoveEvent(this, triple)); > >> + } > >> + return success; > >> + } > >> + > >> + @Override > >> + public boolean removeAll(Collection c) { > >> + boolean modified =3D false; > >> + for (Iterator it =3D c.iterator(); > it.hasNext();) > >> { > >> + Object object =3D it.next(); > >> + if (remove(object)) { > >> + modified =3D true; > >> + } > >> + } > >> + return modified; > >> + } > >> + > >> + /** > >> + * A subclass of AbstractGraph should override > >> + * this method instead of remove for ImmutableGraph > >> event support to be > >> + * added. > >> + * > >> + * @param o The triple to be removed from the triple collection > >> + * @return > >> + */ > >> + protected boolean performRemove(Triple triple) { > >> + Iterator e =3D filter(null, null, null); > >> + while (e.hasNext()) { > >> + if (triple.equals(e.next())) { > >> + e.remove(); > >> + return true; > >> + } > >> + } > >> + return false; > >> + } > >> + > >> + /** > >> + * Dispatches a GraphEvent to all registered listene= rs > >> for which > >> + * the specified Triple matches the > >> FilterTriples > >> + * of the listeners. > >> + * > >> + * @param triple The Triple that was modified > >> + * @param type The type of modification > >> + */ > >> + protected void dispatchEvent(GraphEvent event) { > >> + synchronized(listenerConfigs) { > >> + Iterator iter =3D > >> listenerConfigs.iterator(); > >> + while (iter.hasNext()) { > >> + ListenerConfiguration config =3D iter.next(); > >> + GraphListener registeredListener =3D > config.getListener(); > >> + if (registeredListener =3D=3D null) { > >> + iter.remove(); > >> + continue; > >> + } > >> + if (config.getFilter().match(event.getTriple())) { > >> + > >> delayedNotificator.sendEventToListener(registeredListener, event); > >> + } > >> + } > >> + } > >> + } > >> + > >> + @Override > >> + public void addGraphListener(GraphListener listener, FilterTriple > >> filter) { > >> + addGraphListener(listener, filter, 0); > >> + } > >> + > >> + @Override > >> + public void addGraphListener(GraphListener listener, FilterTriple > >> filter, > >> + long delay) { > >> + listenerConfigs.add(new ListenerConfiguration(listener, > filter)); > >> + if (delay > 0) { > >> + delayedNotificator.addDelayedListener(listener, delay); > >> + } > >> + } > >> + > >> + @Override > >> + public void removeGraphListener(GraphListener listener) { > >> + synchronized(listenerConfigs) { > >> + Iterator iter =3D > >> listenerConfigs.iterator(); > >> + while (iter.hasNext()) { > >> + ListenerConfiguration listenerConfig =3D iter.next(); > >> + GraphListener registeredListener =3D > >> listenerConfig.getListener(); > >> + if ((registeredListener =3D=3D null) || > >> (registeredListener.equals(listener))) { > >> + iter.remove(); > >> + } > >> + } > >> + } > >> + delayedNotificator.removeDelayedListener(listener); > >> + } > >> + > >> + @Override > >> + public ImmutableGraph getImmutableGraph() { > >> + throw new UnsupportedOperationException("Not supported yet.")= ; > >> //To change body of generated methods, choose Tools | Templates. > >> + } > >> + > >> + @Override > >> + public ReadWriteLock getLock() { > >> + return wrapped.getLock(); > >> + } > >> + > >> + @Override > >> + public int size() { > >> + return wrapped.size(); > >> + } > >> + > >> + @Override > >> + public boolean isEmpty() { > >> + return wrapped.isEmpty(); > >> + } > >> + > >> + @Override > >> + public Object[] toArray() { > >> + return wrapped.toArray(); > >> + } > >> + > >> + @Override > >> + public T[] toArray(T[] a) { > >> + return wrapped.toArray(a); > >> + } > >> + > >> + @Override > >> + public boolean containsAll(Collection c) { > >> + return wrapped.containsAll(c); > >> + } > >> + > >> + @Override > >> + public boolean addAll(Collection c) { > >> + return wrapped.addAll(c); > >> + } > >> + > >> + @Override > >> + public boolean retainAll(Collection c) { > >> + return wrapped.retainAll(c); > >> + } > >> + > >> + @Override > >> + public void clear() { > >> + wrapped.clear(); > >> + } > >> + > >> + private static class ListenerConfiguration { > >> + > >> + private WeakReference listenerRef; > >> + private FilterTriple filter; > >> + > >> + private ListenerConfiguration(GraphListener listener, > >> FilterTriple filter) { > >> + this.listenerRef =3D new > WeakReference(listener); > >> + this.filter =3D filter; > >> + } > >> + > >> + /** > >> + * @return the listener > >> + */ > >> + GraphListener getListener() { > >> + GraphListener listener =3D listenerRef.get(); > >> + return listener; > >> + } > >> + > >> + /** > >> + * @return the filter > >> + */ > >> + FilterTriple getFilter() { > >> + return filter; > >> + } > >> + } > >> + > >> +} > >> > >> Added: > >> > commons/sandbox/rdf/trunk/impl.utils/src/main/java/org/apache/commons/rdf= /impl/utils/debug/ReadLockDebug.java > >> URL: > >> > http://svn.apache.org/viewvc/commons/sandbox/rdf/trunk/impl.utils/src/mai= n/java/org/apache/commons/rdf/impl/utils/debug/ReadLockDebug.java?rev=3D165= 9973&view=3Dauto > >> > >> > =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D > >> --- > >> > commons/sandbox/rdf/trunk/impl.utils/src/main/java/org/apache/commons/rdf= /impl/utils/debug/ReadLockDebug.java > >> (added) > >> +++ > >> > commons/sandbox/rdf/trunk/impl.utils/src/main/java/org/apache/commons/rdf= /impl/utils/debug/ReadLockDebug.java > >> Sun Feb 15 18:41:15 2015 > >> @@ -0,0 +1,85 @@ > >> +/* > >> + * Licensed to the Apache Software Foundation (ASF) under one > >> + * or more contributor license agreements. See the NOTICE file > >> + * distributed with this work for additional information > >> + * regarding copyright ownership. The ASF licenses this file > >> + * to you under the Apache License, Version 2.0 (the > >> + * "License"); you may not use this file except in compliance > >> + * with the License. You may obtain a copy of the License at > >> + * > >> + * http://www.apache.org/licenses/LICENSE-2.0 > >> + * > >> + * Unless required by applicable law or agreed to in writing, > >> + * software distributed under the License is distributed on an > >> + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY > >> + * KIND, either express or implied. See the License for the > >> + * specific language governing permissions and limitations > >> + * under the License. > >> + */ > >> + > >> +package org.apache.commons.rdf.impl.utils.debug; > >> + > >> +import java.util.concurrent.TimeUnit; > >> +import java.util.concurrent.locks.Condition; > >> +import java.util.concurrent.locks.ReentrantReadWriteLock.ReadLock; > >> + > >> +/** > >> + * > >> + * @author mir > >> + */ > >> +public class ReadLockDebug extends ReadLock { > >> + > >> + ReentrantReadWriteLockTracker lock; > >> + StackTraceElement[] stackTrace; > >> + > >> + ReadLock readLock; > >> + public ReadLockDebug(ReentrantReadWriteLockTracker lock) { > >> + super(lock); > >> + this.lock =3D lock; > >> + this.readLock =3D lock.realReadLock(); > >> + } > >> + > >> + @Override > >> + public void lock() { > >> + readLock.lock(); > >> + lock.addLockedReadLock(this); > >> + stackTrace =3D Thread.currentThread().getStackTrace(); > >> + } > >> + > >> + @Override > >> + public void lockInterruptibly() throws InterruptedException { > >> + readLock.lockInterruptibly(); > >> + } > >> + > >> + @Override > >> + public Condition newCondition() { > >> + return readLock.newCondition(); > >> + } > >> + > >> + @Override > >> + public String toString() { > >> + return readLock.toString(); > >> + } > >> + > >> + @Override > >> + public boolean tryLock() { > >> + return readLock.tryLock(); > >> + } > >> + > >> + @Override > >> + public boolean tryLock(long timeout, TimeUnit unit) throws > >> InterruptedException { > >> + return readLock.tryLock(timeout, unit); > >> + } > >> + > >> + @Override > >> + public void unlock() { > >> + readLock.unlock(); > >> + lock.removeReadLock(this); > >> + stackTrace =3D null; > >> + } > >> + > >> + public StackTraceElement[] getStackTrace() { > >> + return stackTrace; > >> + } > >> + > >> +} > >> > >> Added: > >> > commons/sandbox/rdf/trunk/impl.utils/src/main/java/org/apache/commons/rdf= /impl/utils/debug/ReentrantReadWriteLockTracker.java > >> URL: > >> > http://svn.apache.org/viewvc/commons/sandbox/rdf/trunk/impl.utils/src/mai= n/java/org/apache/commons/rdf/impl/utils/debug/ReentrantReadWriteLockTracke= r.java?rev=3D1659973&view=3Dauto > >> > >> > =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D > >> --- > >> > commons/sandbox/rdf/trunk/impl.utils/src/main/java/org/apache/commons/rdf= /impl/utils/debug/ReentrantReadWriteLockTracker.java > >> (added) > >> +++ > >> > commons/sandbox/rdf/trunk/impl.utils/src/main/java/org/apache/commons/rdf= /impl/utils/debug/ReentrantReadWriteLockTracker.java > >> Sun Feb 15 18:41:15 2015 > >> @@ -0,0 +1,133 @@ > >> +/* > >> + * Licensed to the Apache Software Foundation (ASF) under one > >> + * or more contributor license agreements. See the NOTICE file > >> + * distributed with this work for additional information > >> + * regarding copyright ownership. The ASF licenses this file > >> + * to you under the Apache License, Version 2.0 (the > >> + * "License"); you may not use this file except in compliance > >> + * with the License. You may obtain a copy of the License at > >> + * > >> + * http://www.apache.org/licenses/LICENSE-2.0 > >> + * > >> + * Unless required by applicable law or agreed to in writing, > >> + * software distributed under the License is distributed on an > >> + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY > >> + * KIND, either express or implied. See the License for the > >> + * specific language governing permissions and limitations > >> + * under the License. > >> + */ > >> +package org.apache.commons.rdf.impl.utils.debug; > >> + > >> +import java.util.Collection; > >> +import java.util.Collections; > >> +import java.util.HashSet; > >> +import java.util.Set; > >> +import java.util.concurrent.locks.Condition; > >> +import java.util.concurrent.locks.ReentrantReadWriteLock; > >> + > >> +/** > >> + * > >> + * @author mir > >> + */ > >> +public class ReentrantReadWriteLockTracker extends > ReentrantReadWriteLock > >> { > >> + > >> + > >> + private Set lockedReadLocks =3D > >> Collections.synchronizedSet(new HashSet()); > >> + private final WriteLockDebug writeLock =3D new WriteLockDebug(thi= s); > >> + @Override > >> + protected Thread getOwner() { > >> + return super.getOwner(); > >> + } > >> + > >> + @Override > >> + protected Collection getQueuedReaderThreads() { > >> + return super.getQueuedReaderThreads(); > >> + } > >> + > >> + @Override > >> + protected Collection getQueuedThreads() { > >> + return super.getQueuedThreads(); > >> + } > >> + > >> + @Override > >> + protected Collection getQueuedWriterThreads() { > >> + return super.getQueuedWriterThreads(); > >> + } > >> + > >> + @Override > >> + public int getReadHoldCount() { > >> + return super.getReadHoldCount(); > >> + } > >> + > >> + @Override > >> + public int getReadLockCount() { > >> + return super.getReadLockCount(); > >> + } > >> + > >> + @Override > >> + public int getWaitQueueLength(Condition condition) { > >> + return super.getWaitQueueLength(condition); > >> + } > >> + > >> + @Override > >> + protected Collection getWaitingThreads(Condition > condition) { > >> + return super.getWaitingThreads(condition); > >> + } > >> + > >> + @Override > >> + public int getWriteHoldCount() { > >> + return super.getWriteHoldCount(); > >> + } > >> + > >> + @Override > >> + public boolean hasWaiters(Condition condition) { > >> + return super.hasWaiters(condition); > >> + } > >> + > >> + @Override > >> + public boolean isWriteLocked() { > >> + return super.isWriteLocked(); > >> + } > >> + > >> + @Override > >> + public boolean isWriteLockedByCurrentThread() { > >> + return super.isWriteLockedByCurrentThread(); > >> + } > >> + > >> + @Override > >> + public ReadLock readLock() { > >> + return new ReadLockDebug(this); > >> + } > >> + > >> + ReadLock realReadLock() { > >> + return super.readLock(); > >> + } > >> + > >> + WriteLock realWriteLock() { > >> + return super.writeLock(); > >> + } > >> + > >> + @Override > >> + public String toString() { > >> + return super.toString(); > >> + } > >> + > >> + @Override > >> + public WriteLockDebug writeLock() { > >> + return writeLock; > >> + } > >> + > >> + void addLockedReadLock(ReadLockDebug lock) { > >> + lockedReadLocks.add(lock); > >> + } > >> + > >> + void removeReadLock(ReadLockDebug lock) { > >> + lockedReadLocks.remove(lock); > >> + } > >> + > >> + public Set getLockedReadLocks() { > >> + return lockedReadLocks; > >> + } > >> + > >> + > >> +} > >> > >> Added: > >> > commons/sandbox/rdf/trunk/impl.utils/src/main/java/org/apache/commons/rdf= /impl/utils/debug/WriteLockDebug.java > >> URL: > >> > http://svn.apache.org/viewvc/commons/sandbox/rdf/trunk/impl.utils/src/mai= n/java/org/apache/commons/rdf/impl/utils/debug/WriteLockDebug.java?rev=3D16= 59973&view=3Dauto > >> > >> > =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D > >> --- > >> > commons/sandbox/rdf/trunk/impl.utils/src/main/java/org/apache/commons/rdf= /impl/utils/debug/WriteLockDebug.java > >> (added) > >> +++ > >> > commons/sandbox/rdf/trunk/impl.utils/src/main/java/org/apache/commons/rdf= /impl/utils/debug/WriteLockDebug.java > >> Sun Feb 15 18:41:15 2015 > >> @@ -0,0 +1,89 @@ > >> +/* > >> + * Licensed to the Apache Software Foundation (ASF) under one > >> + * or more contributor license agreements. See the NOTICE file > >> + * distributed with this work for additional information > >> + * regarding copyright ownership. The ASF licenses this file > >> + * to you under the Apache License, Version 2.0 (the > >> + * "License"); you may not use this file except in compliance > >> + * with the License. You may obtain a copy of the License at > >> + * > >> + * http://www.apache.org/licenses/LICENSE-2.0 > >> + * > >> + * Unless required by applicable law or agreed to in writing, > >> + * software distributed under the License is distributed on an > >> + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY > >> + * KIND, either express or implied. See the License for the > >> + * specific language governing permissions and limitations > >> + * under the License. > >> + */ > >> + > >> +package org.apache.commons.rdf.impl.utils.debug; > >> + > >> +import java.util.concurrent.TimeUnit; > >> +import java.util.concurrent.locks.Condition; > >> +import java.util.concurrent.locks.ReentrantReadWriteLock.WriteLock; > >> + > >> +/** > >> + * > >> + * @author mir > >> + */ > >> +public class WriteLockDebug extends WriteLock { > >> + > >> + private ReentrantReadWriteLockTracker lock; > >> + private WriteLock writeLock; > >> + private StackTraceElement[] stackTrace; > >> + > >> + public WriteLockDebug(ReentrantReadWriteLockTracker lock) { > >> + super(lock); > >> + this.lock =3D lock; > >> + this.writeLock =3D lock.realWriteLock(); > >> + } > >> + > >> + @Override > >> + public int getHoldCount() { > >> + return writeLock.getHoldCount(); > >> + } > >> + > >> + @Override > >> + public boolean isHeldByCurrentThread() { > >> + return writeLock.isHeldByCurrentThread(); > >> + } > >> + > >> + @Override > >> + public void lock() { > >> + writeLock.lock(); > >> + stackTrace =3D Thread.currentThread().getStackTrace(); > >> + } > >> + > >> + @Override > >> + public void lockInterruptibly() throws InterruptedException { > >> + writeLock.lockInterruptibly(); > >> + } > >> + > >> + @Override > >> + public Condition newCondition() { > >> + return writeLock.newCondition(); > >> + } > >> + > >> + @Override > >> + public boolean tryLock() { > >> + return writeLock.tryLock(); > >> + } > >> + > >> + @Override > >> + public boolean tryLock(long timeout, TimeUnit unit) throws > >> InterruptedException { > >> + return writeLock.tryLock(timeout, unit); > >> + } > >> + > >> + @Override > >> + public void unlock() { > >> + writeLock.unlock(); > >> + stackTrace =3D null; > >> + } > >> + > >> + public StackTraceElement[] getStackTrace() { > >> + return stackTrace; > >> + } > >> + > >> + > >> +} > >> > >> > >> > > > > > > -- > > http://people.apache.org/~britter/ > > http://www.systemoutprintln.de/ > > http://twitter.com/BenediktRitter > > http://github.com/britter > > --------------------------------------------------------------------- > To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org > For additional commands, e-mail: dev-help@commons.apache.org > > --=20 http://people.apache.org/~britter/ http://www.systemoutprintln.de/ http://twitter.com/BenediktRitter http://github.com/britter --047d7bdc87a237f8c0050f4278af--