commonsrdf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From st...@apache.org
Subject [1/4] incubator-commonsrdf git commit: COMMONSRDF-20: Provide a mechanism for allowing the load of different RDF Term Factories
Date Fri, 08 May 2015 11:04:52 GMT
Repository: incubator-commonsrdf
Updated Branches:
  refs/heads/master 90b85287a -> d44aee6f7


COMMONSRDF-20: Provide a mechanism for allowing the load of different RDF Term Factories


Project: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/commit/8ba3b70c
Tree: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/tree/8ba3b70c
Diff: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/diff/8ba3b70c

Branch: refs/heads/master
Commit: 8ba3b70cb3166998872aec33131568ff011a1891
Parents: 7a0de10
Author: Benedikt Ritter <beneritter@gmail.com>
Authored: Fri May 1 23:31:53 2015 +0200
Committer: Benedikt Ritter <beneritter@gmail.com>
Committed: Fri May 1 23:31:53 2015 +0200

----------------------------------------------------------------------
 .../org.apache.commons.rdf.api.RDFTermFactory   |  1 +
 .../simple/SimpleRDFTermFactoryLookupTest.java  | 42 ++++++++++++++++++++
 src/site/markdown/userguide.md.vm               | 15 +++++++
 3 files changed, 58 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/8ba3b70c/simple/src/main/resources/META-INF/services/org.apache.commons.rdf.api.RDFTermFactory
----------------------------------------------------------------------
diff --git a/simple/src/main/resources/META-INF/services/org.apache.commons.rdf.api.RDFTermFactory
b/simple/src/main/resources/META-INF/services/org.apache.commons.rdf.api.RDFTermFactory
new file mode 100644
index 0000000..cc53468
--- /dev/null
+++ b/simple/src/main/resources/META-INF/services/org.apache.commons.rdf.api.RDFTermFactory
@@ -0,0 +1 @@
+org.apache.commons.rdf.simple.SimpleRDFTermFactory
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/8ba3b70c/simple/src/test/java/org/apache/commons/rdf/simple/SimpleRDFTermFactoryLookupTest.java
----------------------------------------------------------------------
diff --git a/simple/src/test/java/org/apache/commons/rdf/simple/SimpleRDFTermFactoryLookupTest.java
b/simple/src/test/java/org/apache/commons/rdf/simple/SimpleRDFTermFactoryLookupTest.java
new file mode 100644
index 0000000..2fdeba7
--- /dev/null
+++ b/simple/src/test/java/org/apache/commons/rdf/simple/SimpleRDFTermFactoryLookupTest.java
@@ -0,0 +1,42 @@
+/**
+ * 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.simple;
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+import java.util.Iterator;
+import java.util.ServiceLoader;
+
+import org.apache.commons.rdf.api.RDFTermFactory;
+import org.junit.Test;
+
+public class SimpleRDFTermFactoryLookupTest {
+
+    @Test
+    public void testServiceLoaderLookup() {
+        ServiceLoader<RDFTermFactory> loader = ServiceLoader.load(RDFTermFactory.class);
+
+        Iterator<RDFTermFactory> iterator = loader.iterator();
+        RDFTermFactory factory = iterator.next();
+
+        assertTrue(factory instanceof SimpleRDFTermFactory);
+        assertFalse(iterator.hasNext());
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/8ba3b70c/src/site/markdown/userguide.md.vm
----------------------------------------------------------------------
diff --git a/src/site/markdown/userguide.md.vm b/src/site/markdown/userguide.md.vm
index cca6998..fc63b6f 100644
--- a/src/site/markdown/userguide.md.vm
+++ b/src/site/markdown/userguide.md.vm
@@ -148,6 +148,21 @@ import org.apache.commons.rdf.simple.SimpleRDFTermFactory;
 RDFTermFactory factory = new SimpleRDFTermFactory();
 ```
 
+If you don't want to depend up the concret implementation you can use a
+[ServiceLoader](http://docs.oracle.com/javase/8/docs/api/java/util/ServiceLoader.html)
+to lookup instances:
+
+```java
+import java.util.Iterator;
+import java.util.ServiceLoader;
+
+import org.apache.commons.rdf.api.*;
+// ...
+ServiceLoader<RDFTermFactory> loader = ServiceLoader.load(RDFTermFactory.class);
+Iterator<RDFTermFactory> iterator = loader.iterator();
+RDFTermFactory factory = iterator.next();
+```
+
 Using the factory you can construct
 any [RDFTerm](apidocs/org/apache/commons/rdf/api/RDFTerm.html), e.g. to create a
 [BlankNode](apidocs/org/apache/commons/rdf/api/BlankNode.html),


Mime
View raw message