Split out fluent interfaces

under org.apache.commons.rdf.api.io


Project: http://git-wip-us.apache.org/repos/asf/commons-rdf/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-rdf/commit/a11db68d
Tree: http://git-wip-us.apache.org/repos/asf/commons-rdf/tree/a11db68d
Diff: http://git-wip-us.apache.org/repos/asf/commons-rdf/diff/a11db68d

Branch: refs/heads/fluent-parser
Commit: a11db68d6cb78be783cef91163bc1e952834350f
Parents: 84a644d
Author: Stian Soiland-Reyes <st...@apache.org>
Authored: Fri Feb 24 11:31:04 2017 +0000
Committer: Stian Soiland-Reyes <st...@apache.org>
Committed: Wed Feb 14 18:58:54 2018 +0000

----------------------------------------------------------------------
 .../org/apache/commons/rdf/api/io/Async.java    |  28 ++
 .../commons/rdf/api/io/NeedSourceBased.java     |  27 ++
 .../commons/rdf/api/io/NeedSourceOrBase.java    |  23 ++
 .../apache/commons/rdf/api/io/NeedTarget.java   |  23 ++
 .../commons/rdf/api/io/NeedTargetOrRDF.java     |  23 ++
 .../org/apache/commons/rdf/api/io/Option.java   |  25 ++
 .../commons/rdf/api/io/OptionalTarget.java      |  23 ++
 .../org/apache/commons/rdf/api/io/Parsed.java   |  26 ++
 .../commons/rdf/api/io/ParserFactory.java       |  25 ++
 .../apache/commons/rdf/api/io/ParserSource.java |  33 ++
 .../apache/commons/rdf/api/io/ParserTarget.java |  32 ++
 .../org/apache/commons/rdf/api/io/Sync.java     |  29 ++
 .../apache/commons/rdf/api/io/_Buildable.java   |  47 +++
 .../rdf/api/io/_NeedIdentifiedSource.java       |  34 ++
 .../apache/commons/rdf/api/io/_NeedTarget.java  |  29 ++
 .../commons/rdf/api/io/_NeedTargetOrRDF.java    |  21 ++
 .../commons/rdf/api/io/_OptionalBase.java       |  26 ++
 .../apache/commons/rdf/api/io/_OptionalRDF.java |  25 ++
 .../apache/commons/rdf/api/io/package-info.java |  21 ++
 .../commons/rdf/experimental/ParserFactory.java | 143 --------
 .../test/resources/example-rdf/example.jsonld   |  32 +-
 .../rdf4j/experimental/RDF4JParserFactory.java  | 212 +++++++++++
 .../rdf/rdf4j/experimental/RDF4JParserTest.java |  75 ++++
 .../rdf/simple/experimental/DatasetTarget.java  |  25 --
 .../rdf/simple/experimental/GraphTarget.java    |  29 --
 .../rdf/simple/experimental/IRISource.java      |  20 -
 .../experimental/ImplicitDatasetTarget.java     |  37 --
 .../simple/experimental/InputStreamSource.java  |  20 -
 .../rdf/simple/experimental/ParsedImpl.java     |  34 --
 .../rdf/simple/experimental/ParserBuilder.java  | 150 --------
 .../simple/experimental/ParserFactoryImpl.java  |  44 ---
 .../experimental/ParserImplementation.java      |  14 -
 .../rdf/simple/experimental/PathSource.java     |  20 -
 .../commons/rdf/simple/experimental/State.java  | 356 ------------------
 .../commons/rdf/simple/io/DatasetTarget.java    |  25 ++
 .../commons/rdf/simple/io/GraphTarget.java      |  27 ++
 .../apache/commons/rdf/simple/io/IRISource.java |  53 +++
 .../rdf/simple/io/ImplicitDatasetTarget.java    |  35 ++
 .../rdf/simple/io/InputStreamSource.java        |  32 ++
 .../apache/commons/rdf/simple/io/ParseJob.java  | 364 +++++++++++++++++++
 .../commons/rdf/simple/io/ParsedImpl.java       |  34 ++
 .../commons/rdf/simple/io/ParserBuilder.java    | 159 ++++++++
 .../rdf/simple/io/ParserFactoryImpl.java        |  52 +++
 .../rdf/simple/io/ParserImplementation.java     |  14 +
 .../commons/rdf/simple/io/PathSource.java       |  46 +++
 .../commons/rdf/simple/io/package-info.java     |  21 ++
 .../simple/experimental/ParserFactoryTest.java  |  24 --
 .../rdf/simple/io/ParserFactoryTest.java        |  30 ++
 48 files changed, 1717 insertions(+), 930 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-rdf/blob/a11db68d/api/src/main/java/org/apache/commons/rdf/api/io/Async.java
----------------------------------------------------------------------
diff --git a/api/src/main/java/org/apache/commons/rdf/api/io/Async.java 
b/api/src/main/java/org/apache/commons/rdf/api/io/Async.java
new file mode 100644
index 0000000..2c99a0b
--- /dev/null
+++ b/api/src/main/java/org/apache/commons/rdf/api/io/Async.java
@@ -0,0 +1,28 @@
+/**
+ * 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.api.io;
+
+import java.util.concurrent.Future;
+
+public interface Async<T, S> extends _Buildable {
+    Async<T, S> build();
+    
+    <V> Async<T, S> option(Option<V> option, V value);
+
+    Future<Parsed<T, S>> parseAsync();
+}

http://git-wip-us.apache.org/repos/asf/commons-rdf/blob/a11db68d/api/src/main/java/org/apache/commons/rdf/api/io/NeedSourceBased.java
----------------------------------------------------------------------
diff --git 
a/api/src/main/java/org/apache/commons/rdf/api/io/NeedSourceBased.java 
b/api/src/main/java/org/apache/commons/rdf/api/io/NeedSourceBased.java
new file mode 100644
index 0000000..d390529
--- /dev/null
+++ b/api/src/main/java/org/apache/commons/rdf/api/io/NeedSourceBased.java
@@ -0,0 +1,27 @@
+/**
+ * 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.api.io;
+
+import java.io.InputStream;
+
+public interface NeedSourceBased<T> extends _NeedIdentifiedSource<T>, 
_Buildable {
+    NeedSourceBased<T> build();
+    <V> NeedSourceBased<T> option(Option<V> option, V value);
+
+    Sync<T, InputStream> source(InputStream is);
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/commons-rdf/blob/a11db68d/api/src/main/java/org/apache/commons/rdf/api/io/NeedSourceOrBase.java
----------------------------------------------------------------------
diff --git 
a/api/src/main/java/org/apache/commons/rdf/api/io/NeedSourceOrBase.java 
b/api/src/main/java/org/apache/commons/rdf/api/io/NeedSourceOrBase.java
new file mode 100644
index 0000000..4211137
--- /dev/null
+++ b/api/src/main/java/org/apache/commons/rdf/api/io/NeedSourceOrBase.java
@@ -0,0 +1,23 @@
+/**
+ * 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.api.io;
+
+public interface NeedSourceOrBase<T> extends _OptionalBase<T>, 
_NeedIdentifiedSource<T>, _Buildable {
+    NeedSourceOrBase<T> build();
+    <V> NeedSourceOrBase<T> option(Option<V> option, V value);
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/commons-rdf/blob/a11db68d/api/src/main/java/org/apache/commons/rdf/api/io/NeedTarget.java
----------------------------------------------------------------------
diff --git a/api/src/main/java/org/apache/commons/rdf/api/io/NeedTarget.java 
b/api/src/main/java/org/apache/commons/rdf/api/io/NeedTarget.java
new file mode 100644
index 0000000..4816382
--- /dev/null
+++ b/api/src/main/java/org/apache/commons/rdf/api/io/NeedTarget.java
@@ -0,0 +1,23 @@
+/**
+ * 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.api.io;
+
+interface NeedTarget extends _NeedTarget,_Buildable {
+    NeedTarget build();
+    <V> NeedTarget option(Option<V> option, V value);
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/commons-rdf/blob/a11db68d/api/src/main/java/org/apache/commons/rdf/api/io/NeedTargetOrRDF.java
----------------------------------------------------------------------
diff --git 
a/api/src/main/java/org/apache/commons/rdf/api/io/NeedTargetOrRDF.java 
b/api/src/main/java/org/apache/commons/rdf/api/io/NeedTargetOrRDF.java
new file mode 100644
index 0000000..1ed3b0a
--- /dev/null
+++ b/api/src/main/java/org/apache/commons/rdf/api/io/NeedTargetOrRDF.java
@@ -0,0 +1,23 @@
+/**
+ * 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.api.io;
+
+public interface NeedTargetOrRDF extends _NeedTargetOrRDF,_Buildable {
+    NeedTargetOrRDF build();
+    <V> NeedTargetOrRDF option(Option<V> option, V value);
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/commons-rdf/blob/a11db68d/api/src/main/java/org/apache/commons/rdf/api/io/Option.java
----------------------------------------------------------------------
diff --git a/api/src/main/java/org/apache/commons/rdf/api/io/Option.java 
b/api/src/main/java/org/apache/commons/rdf/api/io/Option.java
new file mode 100644
index 0000000..7cf5c86
--- /dev/null
+++ b/api/src/main/java/org/apache/commons/rdf/api/io/Option.java
@@ -0,0 +1,25 @@
+/**
+ * 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.api.io;
+
+public interface Option<V> {
+
+    public interface RequiredOption<V> extends Option<V> {
+
+    }
+}

http://git-wip-us.apache.org/repos/asf/commons-rdf/blob/a11db68d/api/src/main/java/org/apache/commons/rdf/api/io/OptionalTarget.java
----------------------------------------------------------------------
diff --git 
a/api/src/main/java/org/apache/commons/rdf/api/io/OptionalTarget.java 
b/api/src/main/java/org/apache/commons/rdf/api/io/OptionalTarget.java
new file mode 100644
index 0000000..f9bf651
--- /dev/null
+++ b/api/src/main/java/org/apache/commons/rdf/api/io/OptionalTarget.java
@@ -0,0 +1,23 @@
+/**
+ * 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.api.io;
+
+public interface OptionalTarget<T> extends _NeedTarget, 
NeedSourceOrBase<T>,_Buildable {
+    OptionalTarget<T> build();
+    <V> OptionalTarget<T> option(Option<V> option, V value);
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/commons-rdf/blob/a11db68d/api/src/main/java/org/apache/commons/rdf/api/io/Parsed.java
----------------------------------------------------------------------
diff --git a/api/src/main/java/org/apache/commons/rdf/api/io/Parsed.java 
b/api/src/main/java/org/apache/commons/rdf/api/io/Parsed.java
new file mode 100644
index 0000000..753eda1
--- /dev/null
+++ b/api/src/main/java/org/apache/commons/rdf/api/io/Parsed.java
@@ -0,0 +1,26 @@
+/**
+ * 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.api.io;
+
+public interface Parsed<T, S> {
+    long count();
+
+    ParserSource<S> source();
+
+    ParserTarget<T> target();
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/commons-rdf/blob/a11db68d/api/src/main/java/org/apache/commons/rdf/api/io/ParserFactory.java
----------------------------------------------------------------------
diff --git a/api/src/main/java/org/apache/commons/rdf/api/io/ParserFactory.java 
b/api/src/main/java/org/apache/commons/rdf/api/io/ParserFactory.java
new file mode 100644
index 0000000..6026b00
--- /dev/null
+++ b/api/src/main/java/org/apache/commons/rdf/api/io/ParserFactory.java
@@ -0,0 +1,25 @@
+/**
+ * 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.api.io;
+
+import org.apache.commons.rdf.api.RDFSyntax;
+
+public interface ParserFactory extends _NeedTargetOrRDF {
+
+    NeedTargetOrRDF syntax(RDFSyntax syntax);
+}

http://git-wip-us.apache.org/repos/asf/commons-rdf/blob/a11db68d/api/src/main/java/org/apache/commons/rdf/api/io/ParserSource.java
----------------------------------------------------------------------
diff --git a/api/src/main/java/org/apache/commons/rdf/api/io/ParserSource.java 
b/api/src/main/java/org/apache/commons/rdf/api/io/ParserSource.java
new file mode 100644
index 0000000..7aa5dee
--- /dev/null
+++ b/api/src/main/java/org/apache/commons/rdf/api/io/ParserSource.java
@@ -0,0 +1,33 @@
+/**
+ * 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.api.io;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Optional;
+
+import org.apache.commons.rdf.api.IRI;
+
+/**
+ *
+ */
+public interface ParserSource<S> {
+    S source();   
+    InputStream inputStream() throws IOException;
+    Optional<IRI> iri();
+}

http://git-wip-us.apache.org/repos/asf/commons-rdf/blob/a11db68d/api/src/main/java/org/apache/commons/rdf/api/io/ParserTarget.java
----------------------------------------------------------------------
diff --git a/api/src/main/java/org/apache/commons/rdf/api/io/ParserTarget.java 
b/api/src/main/java/org/apache/commons/rdf/api/io/ParserTarget.java
new file mode 100644
index 0000000..a2ef4aa
--- /dev/null
+++ b/api/src/main/java/org/apache/commons/rdf/api/io/ParserTarget.java
@@ -0,0 +1,32 @@
+/**
+ * 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.api.io;
+
+import java.util.function.Consumer;
+
+import org.apache.commons.rdf.api.Quad;
+
+/**
+ *
+ */
+@FunctionalInterface
+public interface ParserTarget<T> extends Consumer<Quad> {
+    default T target() {
+        return null;// unknown
+    }
+}

http://git-wip-us.apache.org/repos/asf/commons-rdf/blob/a11db68d/api/src/main/java/org/apache/commons/rdf/api/io/Sync.java
----------------------------------------------------------------------
diff --git a/api/src/main/java/org/apache/commons/rdf/api/io/Sync.java 
b/api/src/main/java/org/apache/commons/rdf/api/io/Sync.java
new file mode 100644
index 0000000..7d8add7
--- /dev/null
+++ b/api/src/main/java/org/apache/commons/rdf/api/io/Sync.java
@@ -0,0 +1,29 @@
+/**
+ * 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.api.io;
+
+import java.util.concurrent.ExecutorService;
+
+public interface Sync<T, S> extends _Buildable{
+    Sync<T ,S> build();
+    <V> Sync<T, S> option(Option<V> option, V value);
+
+    Async<T, S> async();
+    Async<T, S> async(ExecutorService executor);
+    Parsed<T, S> parse();
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/commons-rdf/blob/a11db68d/api/src/main/java/org/apache/commons/rdf/api/io/_Buildable.java
----------------------------------------------------------------------
diff --git a/api/src/main/java/org/apache/commons/rdf/api/io/_Buildable.java 
b/api/src/main/java/org/apache/commons/rdf/api/io/_Buildable.java
new file mode 100644
index 0000000..23c4561
--- /dev/null
+++ b/api/src/main/java/org/apache/commons/rdf/api/io/_Buildable.java
@@ -0,0 +1,47 @@
+/**
+ * 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.api.io;
+
+import org.apache.commons.rdf.api.io.Option.RequiredOption;
+
+interface _Buildable {
+    /**
+     * Return an immutable builder at the current state. The returned builder
+     * can be re-used multiple times in a thread-safe way.
+     * 
+     * @return
+     */
+    _Buildable build();
+    
+    /**
+     * Return a builder with the given option set.
+     * <p>
+     * Note that implementations of {@link ParserFactory} may support different
+     * vendor-specific {@link Option} types, and are free to ignore the set
+     * option (unless it is a {@link RequiredOption}).
+     * <p>
+     * It is undefined if setting multiple values for the same (equal) option
+     * are accumulative or overriding.
+     * 
+     * @param option
+     * @param value
+     * @return
+     */
+    <V> _Buildable option(Option<V> option, V value);
+
+}

http://git-wip-us.apache.org/repos/asf/commons-rdf/blob/a11db68d/api/src/main/java/org/apache/commons/rdf/api/io/_NeedIdentifiedSource.java
----------------------------------------------------------------------
diff --git 
a/api/src/main/java/org/apache/commons/rdf/api/io/_NeedIdentifiedSource.java 
b/api/src/main/java/org/apache/commons/rdf/api/io/_NeedIdentifiedSource.java
new file mode 100644
index 0000000..bc4a55c
--- /dev/null
+++ b/api/src/main/java/org/apache/commons/rdf/api/io/_NeedIdentifiedSource.java
@@ -0,0 +1,34 @@
+/**
+ * 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.api.io;
+
+import java.nio.file.Path;
+
+import javax.xml.transform.Source;
+
+import org.apache.commons.rdf.api.IRI;
+
+interface _NeedIdentifiedSource<T> {
+    Sync<T, IRI> source(IRI iri);
+
+    Sync<T, Path> source(Path path);
+
+    <S> Sync<T, S> source(ParserSource<S> source);
+
+    Sync<T, IRI> source(String iri);
+}

http://git-wip-us.apache.org/repos/asf/commons-rdf/blob/a11db68d/api/src/main/java/org/apache/commons/rdf/api/io/_NeedTarget.java
----------------------------------------------------------------------
diff --git a/api/src/main/java/org/apache/commons/rdf/api/io/_NeedTarget.java 
b/api/src/main/java/org/apache/commons/rdf/api/io/_NeedTarget.java
new file mode 100644
index 0000000..a8385dc
--- /dev/null
+++ b/api/src/main/java/org/apache/commons/rdf/api/io/_NeedTarget.java
@@ -0,0 +1,29 @@
+/**
+ * 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.api.io;
+
+import org.apache.commons.rdf.api.Dataset;
+import org.apache.commons.rdf.api.Graph;
+
+interface _NeedTarget {
+    NeedSourceOrBase<Dataset> target(Dataset dataset);
+
+    NeedSourceOrBase<Graph> target(Graph graph);
+
+    <T> NeedSourceOrBase<T> target(ParserTarget<T> target);
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/commons-rdf/blob/a11db68d/api/src/main/java/org/apache/commons/rdf/api/io/_NeedTargetOrRDF.java
----------------------------------------------------------------------
diff --git 
a/api/src/main/java/org/apache/commons/rdf/api/io/_NeedTargetOrRDF.java 
b/api/src/main/java/org/apache/commons/rdf/api/io/_NeedTargetOrRDF.java
new file mode 100644
index 0000000..daf34fe
--- /dev/null
+++ b/api/src/main/java/org/apache/commons/rdf/api/io/_NeedTargetOrRDF.java
@@ -0,0 +1,21 @@
+/**
+ * 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.api.io;
+
+interface _NeedTargetOrRDF extends _NeedTarget, _OptionalRDF {
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/commons-rdf/blob/a11db68d/api/src/main/java/org/apache/commons/rdf/api/io/_OptionalBase.java
----------------------------------------------------------------------
diff --git a/api/src/main/java/org/apache/commons/rdf/api/io/_OptionalBase.java 
b/api/src/main/java/org/apache/commons/rdf/api/io/_OptionalBase.java
new file mode 100644
index 0000000..f9a4e2d
--- /dev/null
+++ b/api/src/main/java/org/apache/commons/rdf/api/io/_OptionalBase.java
@@ -0,0 +1,26 @@
+/**
+ * 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.api.io;
+
+import org.apache.commons.rdf.api.IRI;
+
+interface _OptionalBase<T> {
+    NeedSourceBased<T> base(IRI iri);
+
+    NeedSourceBased<T> base(String iri);
+}

http://git-wip-us.apache.org/repos/asf/commons-rdf/blob/a11db68d/api/src/main/java/org/apache/commons/rdf/api/io/_OptionalRDF.java
----------------------------------------------------------------------
diff --git a/api/src/main/java/org/apache/commons/rdf/api/io/_OptionalRDF.java 
b/api/src/main/java/org/apache/commons/rdf/api/io/_OptionalRDF.java
new file mode 100644
index 0000000..b593e2b
--- /dev/null
+++ b/api/src/main/java/org/apache/commons/rdf/api/io/_OptionalRDF.java
@@ -0,0 +1,25 @@
+/**
+ * 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.api.io;
+
+import org.apache.commons.rdf.api.Dataset;
+import org.apache.commons.rdf.api.RDF;
+
+interface _OptionalRDF {
+    OptionalTarget<Dataset> rdf(RDF rdf);
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/commons-rdf/blob/a11db68d/api/src/main/java/org/apache/commons/rdf/api/io/package-info.java
----------------------------------------------------------------------
diff --git a/api/src/main/java/org/apache/commons/rdf/api/io/package-info.java 
b/api/src/main/java/org/apache/commons/rdf/api/io/package-info.java
new file mode 100644
index 0000000..e80574b
--- /dev/null
+++ b/api/src/main/java/org/apache/commons/rdf/api/io/package-info.java
@@ -0,0 +1,21 @@
+/*
+ * 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.api.io;
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/commons-rdf/blob/a11db68d/api/src/main/java/org/apache/commons/rdf/experimental/ParserFactory.java
----------------------------------------------------------------------
diff --git 
a/api/src/main/java/org/apache/commons/rdf/experimental/ParserFactory.java 
b/api/src/main/java/org/apache/commons/rdf/experimental/ParserFactory.java
deleted file mode 100644
index 2b4fcf3..0000000
--- a/api/src/main/java/org/apache/commons/rdf/experimental/ParserFactory.java
+++ /dev/null
@@ -1,143 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed  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
- *  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,
- * OUT 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.experimental;
-
-import java.io.InputStream;
-import java.nio.file.Path;
-import java.util.concurrent.ExecutorService;
-import java.util.concurrent.Future;
-import java.util.function.Consumer;
-
-import org.apache.commons.rdf.api.Dataset;
-import org.apache.commons.rdf.api.Graph;
-import org.apache.commons.rdf.api.IRI;
-import org.apache.commons.rdf.api.Quad;
-import org.apache.commons.rdf.api.RDF;
-import org.apache.commons.rdf.api.RDFSyntax;
-import org.apache.commons.rdf.experimental.ParserFactory.NeedSourceBased;
-import org.apache.commons.rdf.experimental.ParserFactory.NeedSourceOrBase;
-import org.apache.commons.rdf.experimental.ParserFactory.OptionalTarget;
-import org.apache.commons.rdf.experimental.ParserFactory.Sync;
-import org.apache.commons.rdf.experimental.ParserFactory.Source;
-import org.apache.commons.rdf.experimental.ParserFactory.Target;
-
-public interface ParserFactory extends _NeedTargetOrRDF {
-    
-    interface Async<T, S> {
-        <V> Async<T, S> option(Option<V> option, V value);
-
-        Future<Parsed<T, S>> parseAsync();
-    }
-
-    interface NeedSourceBased<T> extends _NeedIdentifiedSource<T> {
-        <V> NeedSourceBased<T> option(Option<V> option, V value);
-
-        Sync<T, InputStream> source(InputStream is);
-    }
-
-    interface NeedSourceOrBase<T> extends _OptionalBase<T>, 
_NeedIdentifiedSource<T> {
-        <V> NeedSourceOrBase<T> option(Option<V> option, V value);
-    }
-
-    interface NeedSourceOrBaseOrSyntax<T> extends _OptionalBase<T>, 
_NeedIdentifiedSource<T> {
-        <V> NeedSourceOrBaseOrSyntax<T> option(Option<V> option, V value);
-
-        NeedSourceOrBase<T> syntax(RDFSyntax syntax);
-    }
-
-    interface NeedTarget extends _NeedTarget {
-        <V> NeedTarget option(Option<V> option, V value);
-    }
-
-    interface NeedTargetOrRDF extends _NeedTargetOrRDF {
-        <V> NeedTargetOrRDF option(Option<V> option, V value);
-    }
-
-    interface NeedTargetOrRDFOrSyntax extends _NeedTargetOrRDF {
-        <V> NeedTargetOrRDFOrSyntax option(Option<V> option, V value);
-    }
-
-    interface Option<V> {
-    }
-
-    interface OptionalTarget<T> extends _NeedTarget, NeedSourceOrBase<T> {
-        <V> OptionalTarget<T> option(Option<V> option, V value);
-    }
-
-    interface Parsed<T, S> {
-        long count();
-
-        Source<S> source();
-
-        Target<T> target();
-    }
-
-    interface Sync<T, S> {
-        Async<T, S> async();
-
-        Async<T, S> async(ExecutorService executor);
-
-        <V> Sync<T, S> option(Option<V> option, V value);
-
-        Parsed<T, S> parse();
-    }
-
-    interface Source<T> {
-        T source();
-    }
-
-    @FunctionalInterface
-    interface Target<T> extends Consumer<Quad> {
-        default T target() {
-            return null; // unknown
-        }
-    }
-
-    NeedTargetOrRDF syntax(RDFSyntax syntax);
-}
-
-interface _NeedIdentifiedSource<T> {
-    Sync<T, IRI> source(IRI iri);
-
-    Sync<T, Path> source(Path path);
-
-    <S> Sync<T, S> source(Source<S> source);
-
-    Sync<T, IRI> source(String iri);
-}
-
-interface _NeedTarget {
-    NeedSourceOrBase<Dataset> target(Dataset dataset);
-
-    NeedSourceOrBase<Graph> target(Graph graph);
-
-    <T> NeedSourceOrBase<T> target(Target<T> target);
-}
-
-interface _NeedTargetOrRDF extends _NeedTarget, _OptionalRDF {
-}
-
-interface _OptionalBase<T> {
-    NeedSourceBased<T> base(IRI iri);
-
-    NeedSourceBased<T> base(String iri);
-}
-
-interface _OptionalRDF {
-    OptionalTarget rdf(RDF rdf);
-}

http://git-wip-us.apache.org/repos/asf/commons-rdf/blob/a11db68d/commons-rdf-api/src/test/resources/example-rdf/example.jsonld
----------------------------------------------------------------------
diff --git a/commons-rdf-api/src/test/resources/example-rdf/example.jsonld 
b/commons-rdf-api/src/test/resources/example-rdf/example.jsonld
index d6fb670..179d8fa 100644
--- a/commons-rdf-api/src/test/resources/example-rdf/example.jsonld
+++ b/commons-rdf-api/src/test/resources/example-rdf/example.jsonld
@@ -1,25 +1,29 @@
 {
-  "@graph" : [ {
-    "@id" : "_:b0",
+ "@context" : {
+  "name": "http://schema.org/name";,
+  "rights": "http://purl.org/dc/terms/rights";,
+  "license" : {
+    "@id" : "http://purl.org/dc/terms/license";,
+    "@type" : "@id"
+  }
+ },
+ "@graph" : [ 
+  {
+    "@id" : "",
+    "name": "JSON-LD example",
     "license" : "http://www.apache.org/licenses/LICENSE-2.0";,
     "rights" : {
       "@language" : "en",
       "@value" : "Licensed to the Apache Software Foundation (ASF) under one\n 
or more contributor license agreements. See the NOTICE file\n distributed with 
this work for additional information\n regarding copyright ownership. The ASF 
licenses this file\n to you under the Apache License, Version 2.0 (the\n 
\"License\"); you may not use this file except in compliance\n with the 
License.  You may obtain a copy of the License at\n \n 
http://www.apache.org/licenses/LICENSE-2.0\n \n Unless required by applicable 
law or agreed to in writing, software\n distributed under the License is 
distributed on an \"AS IS\" BASIS,\n WITHOUT WARRANTIES OR CONDITIONS OF ANY 
KIND, either express or implied.\n See the License for the specific language 
governing permissions and\n limitations under the License.\n"
     }
   }, {
-    "@graph" : [ {
+    "@id" : "_:b0",
+    "name": "Same BNode",
+    "@graph" : [{
       "@id" : "_:b0",
+      "name": "Graph with different license",
       "license" : "http://example.com/LICENSE";
-    } ],
-    "@id" : "http://example.com";
-  } ],
-  "@context" : {
-    "rights" : {
-      "@id" : "http://purl.org/dc/terms/rights";
-    },
-    "license" : {
-      "@id" : "http://purl.org/dc/terms/license";,
-      "@type" : "@id"
-    }
+    }]
   }
+ ]
 }

http://git-wip-us.apache.org/repos/asf/commons-rdf/blob/a11db68d/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/experimental/RDF4JParserFactory.java
----------------------------------------------------------------------
diff --git 
a/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/experimental/RDF4JParserFactory.java
 
b/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/experimental/RDF4JParserFactory.java
new file mode 100644
index 0000000..c11efe7
--- /dev/null
+++ 
b/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/experimental/RDF4JParserFactory.java
@@ -0,0 +1,212 @@
+package org.apache.commons.rdf.rdf4j.experimental;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.util.Map;
+import java.util.Optional;
+import java.util.concurrent.atomic.AtomicLong;
+import java.util.function.Consumer;
+import java.util.stream.Stream;
+
+import org.apache.commons.rdf.api.IRI;
+import org.apache.commons.rdf.api.Quad;
+import org.apache.commons.rdf.api.RDF;
+import org.apache.commons.rdf.api.RDFSyntax;
+import org.apache.commons.rdf.rdf4j.RDF4J;
+import org.apache.commons.rdf.rdf4j.RDF4JBlankNodeOrIRI;
+import org.apache.commons.rdf.rdf4j.RDF4JDataset;
+import org.apache.commons.rdf.rdf4j.RDF4JGraph;
+import org.apache.commons.rdf.simple.experimental.IRISource;
+import org.apache.commons.rdf.simple.experimental.ParserBuilder;
+import org.apache.commons.rdf.simple.experimental.ParserFactoryImpl;
+import org.apache.commons.rdf.simple.experimental.ParserImplementation;
+import org.apache.commons.rdf.simple.experimental.PathSource;
+import org.eclipse.rdf4j.model.Model;
+import org.eclipse.rdf4j.model.Resource;
+import org.eclipse.rdf4j.model.Statement;
+import org.eclipse.rdf4j.repository.util.RDFInserter;
+import org.eclipse.rdf4j.repository.util.RDFLoader;
+import org.eclipse.rdf4j.rio.ParserConfig;
+import org.eclipse.rdf4j.rio.RDFFormat;
+import org.eclipse.rdf4j.rio.RDFHandler;
+import org.eclipse.rdf4j.rio.RDFHandlerException;
+import org.eclipse.rdf4j.rio.RDFParseException;
+import org.eclipse.rdf4j.rio.Rio;
+import org.eclipse.rdf4j.rio.helpers.AbstractRDFHandler;
+import org.eclipse.rdf4j.rio.helpers.RDFHandlerBase;
+import org.eclipse.rdf4j.rio.helpers.RDFHandlerWrapper;
+
+public class RDF4JParserFactory extends ParserFactoryImpl {
+
+    public RDF4JParserFactory() {
+        super(new RDF4JParserImpl());
+    }
+    
+    private static RDFHandler makeRDFHandler(
+            @SuppressWarnings("rawtypes") Target target, 
+            RDF rdf) {
+        Object t = target.target();
+        if (t instanceof RDF4JDataset) {
+            // One of us, we can add them as Statements directly
+            final RDF4JDataset dataset = (RDF4JDataset) t;
+            if (dataset.asRepository().isPresent()) {
+                return new 
RDFInserter(dataset.asRepository().get().getConnection());
+            }
+            if (dataset.asModel().isPresent()) {
+                final Model model = dataset.asModel().get();
+                return new AddToModel(model);
+            }
+            // Not backed by Repository or Model?
+            // Third-party RDF4JDataset subclass, so we'll fall through to the
+            // Dataset handling
+        }
+        if (t instanceof RDF4JGraph) {
+            final RDF4JGraph graph = (RDF4JGraph) t;
+
+            if (graph.asRepository().isPresent()) {
+                final RDFInserter inserter = new 
RDFInserter(graph.asRepository().get().getConnection());
+                if (!graph.getContextMask().isEmpty()) {
+                    final Stream<RDF4JBlankNodeOrIRI> b = 
graph.getContextMask().stream();
+                    final Stream<Resource> c = 
b.map(RDF4JBlankNodeOrIRI::asValue);
+                    final Resource[] contexts = c.toArray(Resource[]::new);
+                    inserter.enforceContext(contexts);
+                }
+                return inserter;
+            }
+            if (graph.asModel().isPresent() && 
graph.getContextMask().isEmpty()) {
+                // the model accepts any quad
+                final Model model = graph.asModel().get();
+                return new AddToModel(model);
+            }
+        }
+        // Fall thorough: let target consume our converted quads.
+        return new AddToQuadConsumer(target, rdf);
+    }
+
+    private static final class RDF4JParserImpl implements ParserImplementation 
{
+        @Override
+        @SuppressWarnings("rawtypes") 
+        public long parse(Source source, Optional<RDFSyntax> rdfSyntax, 
+               Target target, Optional<RDF> rdf, Map<Option, Object> map) {
+            final CountingHandler rdfHandler = new 
CountingHandler(makeRDFHandler(target, rdf));
+            RDF4J rdf4j;
+            if (rdf.isPresent() && rdf.get() instanceof RDF4J) { 
+                rdf4j = (RDF4J) rdf.get();
+            } else { 
+                rdf4j = new RDF4J();
+            }            
+            // TODO: Support setting ParserConfig as Option?
+            ParserConfig parserConfig = new ParserConfig();
+            final RDFLoader loader = new RDFLoader(parserConfig, 
rdf4j.getValueFactory());
+            
+            
+            IRI baseIri = (IRI) 
map.getOrDefault(ParserBuilder.BaseOption.BASE, source.iri());
+            String base; // handle null
+            
+            if (source instanceof PathSource) {
+                Path p = ((PathSource)source).source();
+                
+                // rdfSyntax might not be present, or might not match RDF4J's 
known mime types
+                Optional<RDFFormat> formatByMimeType = 
rdfSyntax.flatMap(Rio::getParserFormatForMIMEType);
+                
+                // but RDF4J  can also try to guess it by the file name        
        
+                final Optional<RDFFormat> formatByFilename = 
p.map(Path::getFileName).map(Path::toString)
+                        .flatMap(Rio::getParserFormatForFileName);
+                // TODO: for the excited.. what about the extension after 
following
+                // symlinks? 
+                
+                final RDFFormat format = 
formatByMimeType.orElse(formatByFilename.orElse(null));
+                
+                try (InputStream in = Files.newInputStream(p)) { 
+                    loader.load(in, base.getIRIString(), format, rdfHandler);
+                }
+                return rdfHandler.count();
+                
+            }
+            if (source instanceof IRISource) { 
+                // TODO: Do we support other iri()'s?
+                IRI i = source.iri();
+                
+                return rdfHandler.count()
+            } else {
+                // Fallback to parsing InputStream
+                InputStream in = source.inputStream();
+                // MUST have base and format
+                IRI base = (IRI) 
map.getOrDefault(ParserBuilder.BaseOption.BASE, source.iri());
+                RDFFormat format = 
Rio.getParserFormatForMIMEType(rdfSyntax.mediaType()).get();
+                try {
+                    loader.load(in, base.getIRIString(), format, rdfHandler);
+                } catch (RDFParseException | RDFHandlerException | IOException 
e) {
+                    throw new RuntimeException("Can't parse", e);
+                }
+                        
+                return rdfHandler.count();
+            }
+        }
+    }
+
+    public static class CountingHandler extends RDFHandlerWrapper implements 
RDFHandler {
+        private final AtomicLong counter = new AtomicLong();
+        public CountingHandler(RDFHandler makeRDFHandler) {
+            super(makeRDFHandler);
+        }
+        @Override
+        public void handleStatement(Statement st) throws RDFHandlerException {
+            super.handleStatement(st);
+            counter.incrementAndGet();
+        }
+        public long count() {
+            return counter.get();
+        }        
+    }
+    
+    private static final class AddToQuadConsumer extends AbstractRDFHandler {
+        private final Consumer<Quad> quadTarget;
+        private final RDF4J rdf4j;
+
+        private AddToQuadConsumer(final Consumer<Quad> quadTarget, final RDF 
rdf) {
+            this.quadTarget = quadTarget;
+            if (rdf instanceof RDF4J) { 
+                this.rdf4j = (RDF4J) rdf;
+            } else { 
+                this.rdf4j = new RDF4J();
+            }
+        }
+
+        @Override
+        public void handleStatement(final org.eclipse.rdf4j.model.Statement st)
+                throws org.eclipse.rdf4j.rio.RDFHandlerException {
+            quadTarget.accept(rdf4j.asQuad(st));
+            // Performance note:
+            // Graph/Quad.add should pick up again our
+            // RDF4JGraphLike.asStatement()
+            // and avoid double conversion.
+            // Additionally the RDF4JQuad and RDF4JTriple implementations
+            // are lazily converting subj/obj/pred/graph.s
+        }
+    }
+
+    private static final class AddToModel extends AbstractRDFHandler {
+        private final Model model;
+
+        public AddToModel(final Model model) {
+            this.model = model;
+        }
+
+        @Override
+        public void handleStatement(final org.eclipse.rdf4j.model.Statement st)
+                throws org.eclipse.rdf4j.rio.RDFHandlerException {
+            model.add(st);
+        }
+
+        @Override
+        public void handleNamespace(final String prefix, final String uri) 
throws RDFHandlerException {
+            model.setNamespace(prefix, uri);
+        }
+    }
+
+    
+}

http://git-wip-us.apache.org/repos/asf/commons-rdf/blob/a11db68d/rdf4j/src/test/java/org/apache/commons/rdf/rdf4j/experimental/RDF4JParserTest.java
----------------------------------------------------------------------
diff --git 
a/rdf4j/src/test/java/org/apache/commons/rdf/rdf4j/experimental/RDF4JParserTest.java
 
b/rdf4j/src/test/java/org/apache/commons/rdf/rdf4j/experimental/RDF4JParserTest.java
new file mode 100644
index 0000000..4a0200f
--- /dev/null
+++ 
b/rdf4j/src/test/java/org/apache/commons/rdf/rdf4j/experimental/RDF4JParserTest.java
@@ -0,0 +1,75 @@
+/**
+ * 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.rdf4j.experimental;
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+import java.util.Optional;
+import java.util.stream.Stream;
+
+import org.apache.commons.rdf.api.BlankNode;
+import org.apache.commons.rdf.api.BlankNodeOrIRI;
+import org.apache.commons.rdf.api.Dataset;
+import org.apache.commons.rdf.api.IRI;
+import org.apache.commons.rdf.api.Quad;
+import org.apache.commons.rdf.api.RDFSyntax;
+import org.apache.commons.rdf.api.RDFTerm;
+import org.apache.commons.rdf.rdf4j.RDF4J;
+import org.junit.Test;
+
+public class RDF4JParserTest {
+    RDF4J rdf = new RDF4J();
+
+    @Test
+    public void parseJsonLd() throws Exception {
+        IRI base = rdf.createIRI("http://example.com/ex.jsonld";);
+        IRI name = rdf.createIRI("http://schema.org/name";);
+        IRI license = rdf.createIRI("http://purl.org/dc/terms/license";);
+        IRI rights = rdf.createIRI("http://purl.org/dc/terms/rights";);
+        IRI apacheLicense = 
rdf.createIRI("http://www.apache.org/licenses/LICENSE-2.0";);
+        IRI exampleLicense = rdf.createIRI("http://example.com/LICENSE";);
+
+        Dataset ds = new 
RDF4JParserFactory().syntax(RDFSyntax.JSONLD).rdf(rdf).base(base)
+                
.source(getClass().getResourceAsStream("/example-rdf/example.jsonld")).parse().target().target();
+
+        // default graph
+        try (Stream<? extends Quad> s = ds.stream()) {
+            s.forEach(System.out::println);
+        }
+        System.out.println();
+        assertTrue(ds.getGraph().contains(base, name, 
rdf.createLiteral("JSON-LD example")));
+        assertTrue(ds.getGraph().contains(base, rights, null));
+        assertTrue(ds.getGraph().contains(base, license, apacheLicense));
+        // no leak from named graph
+        assertFalse(ds.getGraph().contains(base, license, exampleLicense));
+
+        // Let's find the bnode in the default graph
+        BlankNodeOrIRI bnode = firstSubject(ds, name, rdf.createLiteral("Same 
BNode"));
+        assertTrue(bnode instanceof BlankNode);
+        // the bnode should be the same inside the graph with the same bnode
+        assertTrue(ds.contains(Optional.of(bnode), bnode, name, 
rdf.createLiteral("Graph with different license")));
+    }
+
+    private BlankNodeOrIRI firstSubject(Dataset ds, IRI pred, RDFTerm obj) {
+        try (Stream<? extends Quad> s = ds.stream(Optional.empty(), null, 
pred, obj)) {
+            return s.findAny().get().getSubject();
+        }
+
+    }
+}

http://git-wip-us.apache.org/repos/asf/commons-rdf/blob/a11db68d/simple/src/main/java/org/apache/commons/rdf/simple/experimental/DatasetTarget.java
----------------------------------------------------------------------
diff --git 
a/simple/src/main/java/org/apache/commons/rdf/simple/experimental/DatasetTarget.java
 
b/simple/src/main/java/org/apache/commons/rdf/simple/experimental/DatasetTarget.java
deleted file mode 100644
index 714e188..0000000
--- 
a/simple/src/main/java/org/apache/commons/rdf/simple/experimental/DatasetTarget.java
+++ /dev/null
@@ -1,25 +0,0 @@
-package org.apache.commons.rdf.simple.experimental;
-
-import org.apache.commons.rdf.api.Dataset;
-import org.apache.commons.rdf.api.Quad;
-import org.apache.commons.rdf.experimental.ParserFactory.Target;
-
-public class DatasetTarget implements Target<Dataset> {
-
-    private final Dataset dataset;
-
-    public DatasetTarget(Dataset dataset) {
-        this.dataset = dataset;
-    }
-    
-    @Override
-    public void accept(Quad q) {
-        dataset.add(q);
-    }
-    
-    @Override
-    public Dataset target() {
-        return dataset;
-    }
-
-}

http://git-wip-us.apache.org/repos/asf/commons-rdf/blob/a11db68d/simple/src/main/java/org/apache/commons/rdf/simple/experimental/GraphTarget.java
----------------------------------------------------------------------
diff --git 
a/simple/src/main/java/org/apache/commons/rdf/simple/experimental/GraphTarget.java
 
b/simple/src/main/java/org/apache/commons/rdf/simple/experimental/GraphTarget.java
deleted file mode 100644
index 6270048..0000000
--- 
a/simple/src/main/java/org/apache/commons/rdf/simple/experimental/GraphTarget.java
+++ /dev/null
@@ -1,29 +0,0 @@
-package org.apache.commons.rdf.simple.experimental;
-
-import java.util.function.Consumer;
-
-import org.apache.commons.rdf.api.Graph;
-import org.apache.commons.rdf.api.Quad;
-import org.apache.commons.rdf.experimental.ParserFactory.Target;
-
-public class GraphTarget implements Target<Graph> {
-
-    private Graph graph;
-
-    public GraphTarget(Graph graph) {
-        this.graph = graph;
-    }
-
-    @Override
-    public void accept(Quad q) {
-        if (! q.getGraphName().isPresent()) {
-            graph.add(q.asTriple());
-        }
-    }
-    
-    @Override
-    public Graph target() {
-        return graph;
-    }
-
-}

http://git-wip-us.apache.org/repos/asf/commons-rdf/blob/a11db68d/simple/src/main/java/org/apache/commons/rdf/simple/experimental/IRISource.java
----------------------------------------------------------------------
diff --git 
a/simple/src/main/java/org/apache/commons/rdf/simple/experimental/IRISource.java
 
b/simple/src/main/java/org/apache/commons/rdf/simple/experimental/IRISource.java
deleted file mode 100644
index 8324929..0000000
--- 
a/simple/src/main/java/org/apache/commons/rdf/simple/experimental/IRISource.java
+++ /dev/null
@@ -1,20 +0,0 @@
-package org.apache.commons.rdf.simple.experimental;
-
-import org.apache.commons.rdf.api.IRI;
-import org.apache.commons.rdf.experimental.ParserFactory.Source;
-
-public final class IRISource implements Source<IRI> {
-
-    private final IRI source;
-
-    public IRISource(IRI iri) {
-        this.source = iri;
-    }
-
-    @Override
-    public IRI source() {
-        return source;
-    }
-
-
-}

http://git-wip-us.apache.org/repos/asf/commons-rdf/blob/a11db68d/simple/src/main/java/org/apache/commons/rdf/simple/experimental/ImplicitDatasetTarget.java
----------------------------------------------------------------------
diff --git 
a/simple/src/main/java/org/apache/commons/rdf/simple/experimental/ImplicitDatasetTarget.java
 
b/simple/src/main/java/org/apache/commons/rdf/simple/experimental/ImplicitDatasetTarget.java
deleted file mode 100644
index 0b0de2d..0000000
--- 
a/simple/src/main/java/org/apache/commons/rdf/simple/experimental/ImplicitDatasetTarget.java
+++ /dev/null
@@ -1,37 +0,0 @@
-package org.apache.commons.rdf.simple.experimental;
-
-import java.util.function.Consumer;
-
-import org.apache.commons.rdf.api.Dataset;
-import org.apache.commons.rdf.api.Quad;
-import org.apache.commons.rdf.api.RDF;
-import org.apache.commons.rdf.experimental.ParserFactory.Target;
-
-public class ImplicitDatasetTarget implements Target<Dataset> {
-
-    private final RDF rdf;
-    
-    private Dataset target;
-
-    public ImplicitDatasetTarget(RDF rdf) {
-        this.rdf = rdf;
-    }
-    
-    @Override
-    public Dataset target() {
-        if (target == null) {
-            synchronized (this) {
-                // Make sure we only make it once
-                if (target == null) {
-                    target = rdf.createDataset();
-                }
-            }
-        }
-        return target;
-    }
-
-    @Override
-    public void accept(Quad t) {
-        target().add(t);        
-    }
-}

http://git-wip-us.apache.org/repos/asf/commons-rdf/blob/a11db68d/simple/src/main/java/org/apache/commons/rdf/simple/experimental/InputStreamSource.java
----------------------------------------------------------------------
diff --git 
a/simple/src/main/java/org/apache/commons/rdf/simple/experimental/InputStreamSource.java
 
b/simple/src/main/java/org/apache/commons/rdf/simple/experimental/InputStreamSource.java
deleted file mode 100644
index f68ac78..0000000
--- 
a/simple/src/main/java/org/apache/commons/rdf/simple/experimental/InputStreamSource.java
+++ /dev/null
@@ -1,20 +0,0 @@
-package org.apache.commons.rdf.simple.experimental;
-
-import java.io.InputStream;
-
-import org.apache.commons.rdf.experimental.ParserFactory.Source;
-
-public class InputStreamSource implements Source<InputStream> {
-
-    private final InputStream source;
-
-    public InputStreamSource(InputStream source) {
-        this.source = source;
-    }
-
-    @Override
-    public InputStream source() {
-        return source;
-    }
-    
-}

http://git-wip-us.apache.org/repos/asf/commons-rdf/blob/a11db68d/simple/src/main/java/org/apache/commons/rdf/simple/experimental/ParsedImpl.java
----------------------------------------------------------------------
diff --git 
a/simple/src/main/java/org/apache/commons/rdf/simple/experimental/ParsedImpl.java
 
b/simple/src/main/java/org/apache/commons/rdf/simple/experimental/ParsedImpl.java
deleted file mode 100644
index afbac1f..0000000
--- 
a/simple/src/main/java/org/apache/commons/rdf/simple/experimental/ParsedImpl.java
+++ /dev/null
@@ -1,34 +0,0 @@
-package org.apache.commons.rdf.simple.experimental;
-
-import org.apache.commons.rdf.experimental.ParserFactory.Parsed;
-import org.apache.commons.rdf.experimental.ParserFactory.Source;
-import org.apache.commons.rdf.experimental.ParserFactory.Target;
-
-public class ParsedImpl<T,S> implements Parsed<T, S> {
-
-    private final Source<S> source;
-    private final Target<T> target;
-    private final long count;
-
-    public ParsedImpl(Source<S> source, Target<T> target, final long count) {
-        this.source = source;
-        this.target = target;
-        this.count = count;
-    }
-
-    @Override
-    public long count() {
-        return count;
-    }
-    
-    @Override
-    public Source<S> source() {
-        return source;
-    }
-
-    @Override
-    public Target<T> target() {
-        return target;
-    }
-
-}

http://git-wip-us.apache.org/repos/asf/commons-rdf/blob/a11db68d/simple/src/main/java/org/apache/commons/rdf/simple/experimental/ParserBuilder.java
----------------------------------------------------------------------
diff --git 
a/simple/src/main/java/org/apache/commons/rdf/simple/experimental/ParserBuilder.java
 
b/simple/src/main/java/org/apache/commons/rdf/simple/experimental/ParserBuilder.java
deleted file mode 100644
index 6842c54..0000000
--- 
a/simple/src/main/java/org/apache/commons/rdf/simple/experimental/ParserBuilder.java
+++ /dev/null
@@ -1,150 +0,0 @@
-package org.apache.commons.rdf.simple.experimental;
-
-import java.io.InputStream;
-import java.nio.file.Path;
-import java.util.Map;
-import java.util.concurrent.ExecutorService;
-import java.util.concurrent.ForkJoinPool;
-import java.util.concurrent.Future;
-import java.util.function.Consumer;
-
-import org.apache.commons.rdf.api.Dataset;
-import org.apache.commons.rdf.api.Graph;
-import org.apache.commons.rdf.api.IRI;
-import org.apache.commons.rdf.api.Quad;
-import org.apache.commons.rdf.api.RDF;
-import org.apache.commons.rdf.api.RDFSyntax;
-import org.apache.commons.rdf.experimental.ParserFactory.*;
-
-@SuppressWarnings({ "rawtypes", "unchecked" })
-public final class ParserBuilder implements NeedTargetOrRDF, NeedSourceBased, 
Sync, NeedSourceOrBase, OptionalTarget,
-        NeedSourceOrBaseOrSyntax, Async {
-
-    public static enum AsyncOption implements Option<ExecutorService> {
-        EXECUTOR_SERVICE
-    }
-
-    public static enum BaseOption implements Option<IRI> {
-        BASE        
-    }
-    
-    private final State state;
-
-    public ParserBuilder() {
-        this.state = new DefaultState();
-    }
-
-    public ParserBuilder(ParserImplementation impl) {
-        this.state = new WithImplementation(impl);
-    }
-
-    public ParserBuilder(State state) {
-        this.state = state;
-    }
-
-    @Override
-    public Async async() {
-        return async(ForkJoinPool.commonPool());
-    }
-
-    @Override
-    public Async async(ExecutorService executor) {
-        return newState(state.withOption(AsyncOption.EXECUTOR_SERVICE, 
executor));
-    }
-
-    @Override
-    public NeedSourceBased<Dataset> base(IRI iri) {
-        return newState(implicitTarget().withOption(BaseOption.BASE, iri));
-    }
-
-    @Override
-    public NeedSourceBased<Dataset> base(String iri) {
-        return base(state.rdf().createIRI(iri));
-    }
-
-    public ParserBuilder build() {
-        return newState(state.freeze());
-    }
-
-    @Override
-    public ParserBuilder option(Option o, Object v) {
-        return newState(state.withOption(o, v));
-    }
-
-    @Override
-    public Parsed parse() {
-        ParserImplementation impl = state.impl();
-        long count = impl.parse(state.source(), state.syntax(), 
state.target(), state.rdf(), state.optionsAsMap());
-        return new ParsedImpl<>(state.source(), state.target(), count);
-    }
-
-    @Override
-    public Future parseAsync() {
-        Map<Option, Object> options = state.optionsAsMap();
-        ExecutorService executor = (ExecutorService) 
options.getOrDefault(AsyncOption.EXECUTOR_SERVICE,
-                ForkJoinPool.commonPool());
-        return executor.submit(this::parse);
-    }
-
-    @Override
-    public OptionalTarget rdf(RDF rdf) {
-        return newState(state.withRDF(rdf));
-    }
-
-    @Override
-    public Sync source(InputStream is) {
-        return source(new InputStreamSource(is));
-    }
-
-    @Override
-    public Sync source(IRI iri) {
-        return source(new IRISource(iri));
-    }
-
-    @Override
-    public Sync source(Path path) {
-        return source(new PathSource(path));
-    }
-
-    @Override
-    public Sync source(Source source) {
-        return newState(implicitTarget().withSource(source));
-    }
-
-    @Override
-    public Sync source(String iri) {
-        return source(state.rdf().createIRI(iri));
-    }
-
-    public NeedSourceOrBase syntax(RDFSyntax syntax) {
-        return newState(state.withSyntax(syntax));
-    }
-
-    @Override
-    public NeedSourceOrBase<Dataset> target(Dataset dataset) {
-        return target(new DatasetTarget(dataset));
-    }
-
-    @Override
-    public NeedSourceOrBase<Graph> target(Graph graph) {
-        return target(new GraphTarget(graph));
-    }
-
-    @Override
-    public NeedSourceOrBase target(Target target) {
-        return newState(state.withTarget(target));
-    }
-
-    private State implicitTarget() {
-        return state.withTarget(new ImplicitDatasetTarget(state.rdf()));
-    }
-
-    private ParserBuilder newState(State newState) {
-        if (this.state == newState) {
-            // probably a MutableState
-            return this;
-        }
-        return new ParserBuilder(newState);
-    }
-
-}

http://git-wip-us.apache.org/repos/asf/commons-rdf/blob/a11db68d/simple/src/main/java/org/apache/commons/rdf/simple/experimental/ParserFactoryImpl.java
----------------------------------------------------------------------
diff --git 
a/simple/src/main/java/org/apache/commons/rdf/simple/experimental/ParserFactoryImpl.java
 
b/simple/src/main/java/org/apache/commons/rdf/simple/experimental/ParserFactoryImpl.java
deleted file mode 100644
index 70b7237..0000000
--- 
a/simple/src/main/java/org/apache/commons/rdf/simple/experimental/ParserFactoryImpl.java
+++ /dev/null
@@ -1,44 +0,0 @@
-package org.apache.commons.rdf.simple.experimental;
-
-import org.apache.commons.rdf.api.Dataset;
-import org.apache.commons.rdf.api.Graph;
-import org.apache.commons.rdf.api.RDF;
-import org.apache.commons.rdf.api.RDFSyntax;
-import org.apache.commons.rdf.experimental.ParserFactory;
-
-public class ParserFactoryImpl implements ParserFactory {
-
-    private State state;
-
-    public ParserFactoryImpl(ParserImplementation impl) {
-        this.state = new WithImplementation(impl);
-    }
-    
-    @Override
-    public NeedSourceOrBase<Graph> target(Graph graph) {
-        return target(new GraphTarget(graph));
-    }
-
-    @Override
-    public NeedSourceOrBase<Dataset> target(Dataset dataset) {
-        return target(new DatasetTarget(dataset));
-    }
-
-    @SuppressWarnings("unchecked")
-    @Override
-    public <T> NeedSourceOrBase<T> target(Target<T> target) {
-        return new ParserBuilder(state.withTarget(target));
-    }
-
-    @SuppressWarnings("unchecked")
-    @Override
-    public OptionalTarget<Dataset> rdf(RDF rdf) {
-        return new ParserBuilder(state.withRDF(rdf));
-    }
-
-    @Override
-    public NeedTargetOrRDF syntax(RDFSyntax syntax) {
-        return new ParserBuilder(state.withSyntax(syntax));
-    }
-
-}

http://git-wip-us.apache.org/repos/asf/commons-rdf/blob/a11db68d/simple/src/main/java/org/apache/commons/rdf/simple/experimental/ParserImplementation.java
----------------------------------------------------------------------
diff --git 
a/simple/src/main/java/org/apache/commons/rdf/simple/experimental/ParserImplementation.java
 
b/simple/src/main/java/org/apache/commons/rdf/simple/experimental/ParserImplementation.java
deleted file mode 100644
index 4284429..0000000
--- 
a/simple/src/main/java/org/apache/commons/rdf/simple/experimental/ParserImplementation.java
+++ /dev/null
@@ -1,14 +0,0 @@
-package org.apache.commons.rdf.simple.experimental;
-
-import java.util.Map;
-
-import org.apache.commons.rdf.api.RDF;
-import org.apache.commons.rdf.api.RDFSyntax;
-import org.apache.commons.rdf.experimental.ParserFactory.Option;
-import org.apache.commons.rdf.experimental.ParserFactory.Source;
-import org.apache.commons.rdf.experimental.ParserFactory.Target;
-
-public interface ParserImplementation {
-    @SuppressWarnings("rawtypes")
-    public long parse(Source source, RDFSyntax rdfSyntax, Target target, RDF 
rdf, Map<Option, Object> map);
-}

http://git-wip-us.apache.org/repos/asf/commons-rdf/blob/a11db68d/simple/src/main/java/org/apache/commons/rdf/simple/experimental/PathSource.java
----------------------------------------------------------------------
diff --git 
a/simple/src/main/java/org/apache/commons/rdf/simple/experimental/PathSource.java
 
b/simple/src/main/java/org/apache/commons/rdf/simple/experimental/PathSource.java
deleted file mode 100644
index 0341f47..0000000
--- 
a/simple/src/main/java/org/apache/commons/rdf/simple/experimental/PathSource.java
+++ /dev/null
@@ -1,20 +0,0 @@
-package org.apache.commons.rdf.simple.experimental;
-
-import java.nio.file.Path;
-
-import org.apache.commons.rdf.experimental.ParserFactory.Source;
-
-public class PathSource implements Source<Path> {
-    private final Path source;
-
-    public PathSource(Path source) {
-        this.source = source;
-    }
-    
-    @Override
-    public Path source() {
-        return source;
-    }
-
-
-}

http://git-wip-us.apache.org/repos/asf/commons-rdf/blob/a11db68d/simple/src/main/java/org/apache/commons/rdf/simple/experimental/State.java
----------------------------------------------------------------------
diff --git 
a/simple/src/main/java/org/apache/commons/rdf/simple/experimental/State.java 
b/simple/src/main/java/org/apache/commons/rdf/simple/experimental/State.java
deleted file mode 100644
index f94f827..0000000
--- a/simple/src/main/java/org/apache/commons/rdf/simple/experimental/State.java
+++ /dev/null
@@ -1,356 +0,0 @@
-package org.apache.commons.rdf.simple.experimental;
-
-import java.util.AbstractMap.SimpleImmutableEntry;
-import java.util.Collections;
-import java.util.LinkedHashMap;
-import java.util.Map;
-import java.util.Map.Entry;
-import java.util.Objects;
-import java.util.stream.Collectors;
-import java.util.stream.Stream;
-
-import org.apache.commons.rdf.api.RDF;
-import org.apache.commons.rdf.api.RDFSyntax;
-import org.apache.commons.rdf.experimental.ParserFactory.Option;
-import org.apache.commons.rdf.experimental.ParserFactory.Source;
-import org.apache.commons.rdf.experimental.ParserFactory.Target;
-import org.apache.commons.rdf.simple.SimpleRDF;
-
-@SuppressWarnings("rawtypes")
-interface State {
-    ParserImplementation impl();
-    RDF rdf();
-    Source source();
-    Target target();
-    RDFSyntax syntax();
-    Stream<Map.Entry<Option, Object>> options();
-    Map<Option, Object> optionsAsMap();
-    State withRDF(RDF rdf);
-    State withSource(Source p);
-    State withTarget(Target g);
-    State withSyntax(RDFSyntax s);
-    <O> State withOption(Option<O> o, O v);
-    State withImplementation(ParserImplementation impl);
-    State freeze();
-}
-
-@SuppressWarnings("rawtypes")
-final class MutableState implements State, Cloneable {
-    private ParserImplementation impl;
-    private RDF rdf = new SimpleRDF();
-    private Source source;
-    private Target target;
-    private RDFSyntax syntax;
-    private Map<Option, Object> options = new LinkedHashMap<>();
-
-    @Override
-    public ParserImplementation impl() {
-        return Objects.requireNonNull(impl);
-    }
-    public State freeze() {
-        // options will be cloned inside constructor
-        return new FrozenState(impl, source, syntax, target, rdf, options);
-    }
-    @Override
-    public RDF rdf() {
-        return Objects.requireNonNull(rdf);
-    }
-    @Override
-    public Source source() {
-        return Objects.requireNonNull(source);
-    }
-    @Override
-    public Target target() {
-        return Objects.requireNonNull(target);
-    }
-    @Override
-    public RDFSyntax syntax() {
-        return Objects.requireNonNull(syntax);
-    }
-    @Override
-    public Stream<Entry<Option, Object>> options() {
-        return options.entrySet().stream();
-    }
-    @Override
-    public Map<Option, Object> optionsAsMap() {
-        return Collections.unmodifiableMap(options);
-    }
-    @Override
-    public State withRDF(RDF rdf) {
-        this.rdf = rdf;
-        return this;
-    }
-    @Override
-    public State withSource(Source s) {
-        this.source = s;
-        return this;
-    }
-    @Override
-    public State withTarget(Target t) {
-        this.target = t;
-        return this;
-    }
-    @Override
-    public State withSyntax(RDFSyntax s) {
-        this.syntax = s;
-        return this;
-    }
-    @Override
-    public <O> State withOption(Option<O> o, O v) {
-        options.put(o, v);
-        return this;
-    }
-    @Override
-    public State withImplementation(ParserImplementation impl) {
-        this.impl = impl;
-        return this;
-    }
-}
-
-
-@SuppressWarnings("rawtypes")
-abstract class ImmutableState implements State {
-    @Override
-    public State withSource(Source src) {
-        return new WithSource(src, this);
-    }
-    @Override
-    public State withSyntax(RDFSyntax s) {
-        return new WithSyntax(s, this);
-    }
-    @Override
-    public State withTarget(Target t) {
-        return new WithTarget(t, this);
-    }
-    public State withRDF(RDF rdf) {
-        return new WithRDF(rdf, this);
-    };
-    public <O> State withOption(Option<O> o, O v) {
-        return new WithOption(o, v, this);
-    };
-    @Override
-    public State withImplementation(ParserImplementation impl) {
-        return new WithImplementation(impl, this);
-    }
-    @Override
-    public State freeze() {
-        return this;
-    }
-}
-
-@SuppressWarnings("rawtypes")
-final class DefaultState extends ImmutableState {
-    @Override
-    public Source source() {
-        throw new IllegalStateException("Source not set");
-    }
-    @Override
-    public Target target() {
-        throw new IllegalStateException("Target not set");
-    }
-    @Override
-    public RDFSyntax syntax() {
-        throw new IllegalStateException("Syntax not set");
-    }
-    @Override
-    public RDF rdf() {
-        return new SimpleRDF(); // fresh every time?
-    }
-    @Override
-    public Stream<Entry<Option, Object>> options() {
-        return Stream.empty();
-    }
-    @Override
-    public Map<Option, Object> optionsAsMap() {
-        return Collections.emptyMap();
-    }
-    @Override
-    public ParserImplementation impl() {
-        throw new IllegalStateException("Implementation not set");
-    }
-}
-
-@SuppressWarnings("rawtypes")
-final class FrozenState extends ImmutableState implements State {
-    private final ParserImplementation impl;
-    private final Source source;
-    private final RDFSyntax syntax;
-    private final Target target;
-    private final RDF rdf;
-    private final Map<Option, Object> options;
-
-    public FrozenState(ParserImplementation impl, Source source, RDFSyntax 
syntax, Target target, RDF rdf,
-            Map<Option, Object> options) {
-        this.impl = impl;
-        this.source = source;
-        this.syntax = syntax;
-        this.target = target;
-        this.rdf = rdf;
-        // shallow copy of options
-        this.options = Collections.unmodifiableMap(new 
LinkedHashMap<>(options));
-    }
-    @Override
-    public ParserImplementation impl() {
-        return impl;
-    }
-    @Override
-    public RDF rdf() {
-        return rdf;
-    }
-    @Override
-    public Source source() {
-        return source;
-    }
-    @Override
-    public Target target() {
-        return target;
-    }
-    @Override
-    public RDFSyntax syntax() {
-        return syntax;
-    }
-    @Override
-    public Stream<Entry<Option, Object>> options() {
-        return options.entrySet().stream();
-    }
-    @Override
-    public Map<Option, Object> optionsAsMap() {
-        return options;
-    }
-}
-
-@SuppressWarnings("rawtypes")
-abstract class Inherited extends ImmutableState {
-    private final ImmutableState parent;
-    public Inherited() {
-        this(new DefaultState());
-    }
-    public Inherited(ImmutableState state) {
-        parent = state;
-    }
-    @Override
-    public Source source() {
-        return parent.source();
-    }
-    @Override
-    public Target target() {
-        return parent.target();
-    }
-    @Override
-    public RDFSyntax syntax() {
-        return parent.syntax();
-    }
-    @Override
-    public RDF rdf() {
-        return parent.rdf();
-    }
-    @Override
-    public Stream<Entry<Option, Object>> options() {
-        return parent.options();
-    }
-    @Override
-    public Map<Option, Object> optionsAsMap() {
-        return parent.optionsAsMap();
-    }
-    @Override
-    public ParserImplementation impl() {
-        return parent.impl();
-    }
-}
-
-@SuppressWarnings("rawtypes")
-final class WithSource extends Inherited {
-    private final Source source;
-
-    public WithSource(final Source src) {
-        this.source = src;
-    }
-    public WithSource(final Source src, final ImmutableState state) {
-        super(state);
-        this.source = src;
-    }
-    @Override
-    public Source source() {
-        return source;
-    }
-}
-
-@SuppressWarnings("rawtypes")
-final class WithTarget extends Inherited {
-    private final Target target;
-
-    public WithTarget(final Target t) {
-        this.target = t;
-    }
-    public WithTarget(final Target t, final ImmutableState state) {
-        super(state);
-        this.target = t;
-    }
-    @Override
-    public Target target() {
-        return target;
-    }
-}
-
-final class WithSyntax extends Inherited {
-    private final RDFSyntax syntax;
-    public WithSyntax(final RDFSyntax s) {
-        syntax = s;
-    }
-    public WithSyntax(final RDFSyntax s, final ImmutableState state) {
-        super(state);
-        syntax = s;
-    }
-    @Override
-    public RDFSyntax syntax() {
-        return syntax;
-    }
-}
-
-final class WithRDF extends Inherited {
-    private final RDF rdf;
-    public WithRDF(final RDF r) {
-        rdf = r;
-    }
-    public WithRDF(final RDF r, final ImmutableState state) {
-        super(state);
-        rdf = r;
-    }
-    @Override
-    public RDF rdf() {
-        return rdf;
-    }
-}
-
-@SuppressWarnings({ "rawtypes", "unchecked" })
-final class WithOption extends Inherited {
-    private Option<? extends Object> option;
-    private Object value;
-    public <O> WithOption(Option<O> o, O v, ImmutableState immutableState) {
-        this.option = o;
-        this.value = v;
-    }
-    @Override
-    public Stream<Entry<Option, Object>> options() {
-        return Stream.concat(super.options(), Stream.of(new 
SimpleImmutableEntry(option, value)));
-    }
-    @Override
-    public Map<Option, Object> optionsAsMap() {
-        return options().collect(Collectors.toMap(Entry::getKey, 
Entry::getValue));
-    }
-}
-
-final class WithImplementation extends Inherited {
-    private final ParserImplementation impl;
-    public WithImplementation(ParserImplementation impl) {
-        this.impl = impl;
-    }
-    public WithImplementation(ParserImplementation impl, ImmutableState 
parent) {
-        super(parent);
-        this.impl = impl;
-    }
-    @Override
-    public ParserImplementation impl() {
-        return impl;
-    }
-}

http://git-wip-us.apache.org/repos/asf/commons-rdf/blob/a11db68d/simple/src/main/java/org/apache/commons/rdf/simple/io/DatasetTarget.java
----------------------------------------------------------------------
diff --git 
a/simple/src/main/java/org/apache/commons/rdf/simple/io/DatasetTarget.java 
b/simple/src/main/java/org/apache/commons/rdf/simple/io/DatasetTarget.java
new file mode 100644
index 0000000..e8535d7
--- /dev/null
+++ b/simple/src/main/java/org/apache/commons/rdf/simple/io/DatasetTarget.java
@@ -0,0 +1,25 @@
+package org.apache.commons.rdf.simple.io;
+
+import org.apache.commons.rdf.api.Dataset;
+import org.apache.commons.rdf.api.Quad;
+import org.apache.commons.rdf.api.io.ParserTarget;
+
+public class DatasetTarget implements ParserTarget<Dataset> {
+
+    private final Dataset dataset;
+
+    public DatasetTarget(Dataset dataset) {
+        this.dataset = dataset;
+    }
+    
+    @Override
+    public void accept(Quad q) {
+        dataset.add(q);
+    }
+    
+    @Override
+    public Dataset target() {
+        return dataset;
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/commons-rdf/blob/a11db68d/simple/src/main/java/org/apache/commons/rdf/simple/io/GraphTarget.java
----------------------------------------------------------------------
diff --git 
a/simple/src/main/java/org/apache/commons/rdf/simple/io/GraphTarget.java 
b/simple/src/main/java/org/apache/commons/rdf/simple/io/GraphTarget.java
new file mode 100644
index 0000000..458c169
--- /dev/null
+++ b/simple/src/main/java/org/apache/commons/rdf/simple/io/GraphTarget.java
@@ -0,0 +1,27 @@
+package org.apache.commons.rdf.simple.io;
+
+import org.apache.commons.rdf.api.Graph;
+import org.apache.commons.rdf.api.Quad;
+import org.apache.commons.rdf.api.io.ParserTarget;
+
+public class GraphTarget implements ParserTarget<Graph> {
+
+    private Graph graph;
+
+    public GraphTarget(Graph graph) {
+        this.graph = graph;
+    }
+
+    @Override
+    public void accept(Quad q) {
+        if (! q.getGraphName().isPresent()) {
+            graph.add(q.asTriple());
+        }
+    }
+    
+    @Override
+    public Graph target() {
+        return graph;
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/commons-rdf/blob/a11db68d/simple/src/main/java/org/apache/commons/rdf/simple/io/IRISource.java
----------------------------------------------------------------------
diff --git 
a/simple/src/main/java/org/apache/commons/rdf/simple/io/IRISource.java 
b/simple/src/main/java/org/apache/commons/rdf/simple/io/IRISource.java
new file mode 100644
index 0000000..9b251b0
--- /dev/null
+++ b/simple/src/main/java/org/apache/commons/rdf/simple/io/IRISource.java
@@ -0,0 +1,53 @@
+package org.apache.commons.rdf.simple.io;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.Optional;
+
+import org.apache.commons.rdf.api.IRI;
+import org.apache.commons.rdf.api.io.ParserSource;
+
+public final class IRISource implements ParserSource<IRI> {
+
+    private final IRI source;
+
+    public IRISource(IRI iri) {
+        this.source = iri;
+    }
+
+    @Override
+    public IRI source() {
+        return source;
+    }
+
+    /**
+     * NOTE: This does not follow HTTP redirects or perform content negotiation
+     * and should not generally be used.
+     */
+    @Override
+    public InputStream inputStream() {
+        // NOTE: This does not follow HTTP redirects, content negotiation,
+        try {
+            return asURL().openStream();
+        } catch (IOException ex) {
+            throw new UnsupportedOperationException("Unable to connect to " + 
source.getIRIString(), ex);
+        }
+    }
+
+    private URL asURL() throws MalformedURLException {
+        return new URL(source.getIRIString());
+    }
+
+    /**
+     * NOTE: This does not follow HTTP redirects, content negotiation, or
+     * respect the Content-Location, and so should NOT be used as a base URL
+     * when parsing.
+     */
+    @Override
+    public Optional<IRI> iri() {
+        return Optional.of(source);
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/commons-rdf/blob/a11db68d/simple/src/main/java/org/apache/commons/rdf/simple/io/ImplicitDatasetTarget.java
----------------------------------------------------------------------
diff --git 
a/simple/src/main/java/org/apache/commons/rdf/simple/io/ImplicitDatasetTarget.java
 
b/simple/src/main/java/org/apache/commons/rdf/simple/io/ImplicitDatasetTarget.java
new file mode 100644
index 0000000..00be95e
--- /dev/null
+++ 
b/simple/src/main/java/org/apache/commons/rdf/simple/io/ImplicitDatasetTarget.java
@@ -0,0 +1,35 @@
+package org.apache.commons.rdf.simple.io;
+
+import org.apache.commons.rdf.api.Dataset;
+import org.apache.commons.rdf.api.Quad;
+import org.apache.commons.rdf.api.RDF;
+import org.apache.commons.rdf.api.io.ParserTarget;
+
+public class ImplicitDatasetTarget implements ParserTarget<Dataset> {
+
+    private final RDF rdf;
+    
+    private Dataset target;
+
+    public ImplicitDatasetTarget(RDF rdf) {
+        this.rdf = rdf;
+    }
+    
+    @Override
+    public Dataset target() {
+        if (target == null) {
+            synchronized (this) {
+                // Make sure we only make it once
+                if (target == null) {
+                    target = rdf.createDataset();
+                }
+            }
+        }
+        return target;
+    }
+
+    @Override
+    public void accept(Quad t) {
+        target().add(t);        
+    }
+}

http://git-wip-us.apache.org/repos/asf/commons-rdf/blob/a11db68d/simple/src/main/java/org/apache/commons/rdf/simple/io/InputStreamSource.java
----------------------------------------------------------------------
diff --git 
a/simple/src/main/java/org/apache/commons/rdf/simple/io/InputStreamSource.java 
b/simple/src/main/java/org/apache/commons/rdf/simple/io/InputStreamSource.java
new file mode 100644
index 0000000..2682176
--- /dev/null
+++ 
b/simple/src/main/java/org/apache/commons/rdf/simple/io/InputStreamSource.java
@@ -0,0 +1,32 @@
+package org.apache.commons.rdf.simple.io;
+
+import java.io.InputStream;
+import java.util.Optional;
+
+import org.apache.commons.rdf.api.IRI;
+import org.apache.commons.rdf.api.io.ParserSource;
+
+public class InputStreamSource implements ParserSource<InputStream> {
+
+    private final InputStream source;
+
+    public InputStreamSource(InputStream source) {
+        this.source = source;
+    }
+
+    @Override
+    public InputStream source() {
+        return source;
+    }
+    
+    @Override
+    public InputStream inputStream() {
+        return source;
+    }
+    
+    @Override
+    public Optional<IRI> iri() {
+        // Unknown base
+        return Optional.empty();
+    }
+}

Reply via email to