You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jena.apache.org by cl...@apache.org on 2014/06/07 09:50:08 UTC
svn commit: r1601074 - in /jena/Experimental/jena-commons: ./ src/ src/main/
src/main/java/ src/main/java/org/ src/main/java/org/apache/
src/main/java/org/apache/jena/ src/main/java/org/apache/jena/commons/
src/main/java/org/apache/jena/commons/configu...
Author: claude
Date: Sat Jun 7 07:50:07 2014
New Revision: 1601074
URL: http://svn.apache.org/r1601074
Log: (empty)
Added:
jena/Experimental/jena-commons/LICENSE
jena/Experimental/jena-commons/pom.xml (with props)
jena/Experimental/jena-commons/src/
jena/Experimental/jena-commons/src/main/
jena/Experimental/jena-commons/src/main/java/
jena/Experimental/jena-commons/src/main/java/org/
jena/Experimental/jena-commons/src/main/java/org/apache/
jena/Experimental/jena-commons/src/main/java/org/apache/jena/
jena/Experimental/jena-commons/src/main/java/org/apache/jena/commons/
jena/Experimental/jena-commons/src/main/java/org/apache/jena/commons/configuration/
jena/Experimental/jena-commons/src/main/java/org/apache/jena/commons/configuration/RDFConfig.java (with props)
jena/Experimental/jena-commons/src/main/java/org/apache/jena/commons/configuration/RDFFileConfiguration.java (with props)
jena/Experimental/jena-commons/src/test/
jena/Experimental/jena-commons/src/test/java/
jena/Experimental/jena-commons/src/test/java/org/
jena/Experimental/jena-commons/src/test/java/org/apache/
jena/Experimental/jena-commons/src/test/java/org/apache/jena/
jena/Experimental/jena-commons/src/test/java/org/apache/jena/commons/
jena/Experimental/jena-commons/src/test/java/org/apache/jena/commons/configuration/
jena/Experimental/jena-commons/src/test/java/org/apache/jena/commons/configuration/AssemblerRDFConfigTest.java (with props)
jena/Experimental/jena-commons/src/test/java/org/apache/jena/commons/configuration/RDFConfigTest.java (with props)
jena/Experimental/jena-commons/src/test/resources/
jena/Experimental/jena-commons/src/test/resources/org/
jena/Experimental/jena-commons/src/test/resources/org/apache/
jena/Experimental/jena-commons/src/test/resources/org/apache/jena/
jena/Experimental/jena-commons/src/test/resources/org/apache/jena/commons/
jena/Experimental/jena-commons/src/test/resources/org/apache/jena/commons/configuration/
jena/Experimental/jena-commons/src/test/resources/org/apache/jena/commons/configuration/assembler.ttl
Added: jena/Experimental/jena-commons/LICENSE
URL: http://svn.apache.org/viewvc/jena/Experimental/jena-commons/LICENSE?rev=1601074&view=auto
==============================================================================
--- jena/Experimental/jena-commons/LICENSE (added)
+++ jena/Experimental/jena-commons/LICENSE Sat Jun 7 07:50:07 2014
@@ -0,0 +1,222 @@
+
+ Apache License
+ Version 2.0, January 2004
+ http://www.apache.org/licenses/
+
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+ 1. Definitions.
+
+ "License" shall mean the terms and conditions for use, reproduction,
+ and distribution as defined by Sections 1 through 9 of this document.
+
+ "Licensor" shall mean the copyright owner or entity authorized by
+ the copyright owner that is granting the License.
+
+ "Legal Entity" shall mean the union of the acting entity and all
+ other entities that control, are controlled by, or are under common
+ control with that entity. For the purposes of this definition,
+ "control" means (i) the power, direct or indirect, to cause the
+ direction or management of such entity, whether by contract or
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
+ outstanding shares, or (iii) beneficial ownership of such entity.
+
+ "You" (or "Your") shall mean an individual or Legal Entity
+ exercising permissions granted by this License.
+
+ "Source" form shall mean the preferred form for making modifications,
+ including but not limited to software source code, documentation
+ source, and configuration files.
+
+ "Object" form shall mean any form resulting from mechanical
+ transformation or translation of a Source form, including but
+ not limited to compiled object code, generated documentation,
+ and conversions to other media types.
+
+ "Work" shall mean the work of authorship, whether in Source or
+ Object form, made available under the License, as indicated by a
+ copyright notice that is included in or attached to the work
+ (an example is provided in the Appendix below).
+
+ "Derivative Works" shall mean any work, whether in Source or Object
+ form, that is based on (or derived from) the Work and for which the
+ editorial revisions, annotations, elaborations, or other modifications
+ represent, as a whole, an original work of authorship. For the purposes
+ of this License, Derivative Works shall not include works that remain
+ separable from, or merely link (or bind by name) to the interfaces of,
+ the Work and Derivative Works thereof.
+
+ "Contribution" shall mean any work of authorship, including
+ the original version of the Work and any modifications or additions
+ to that Work or Derivative Works thereof, that is intentionally
+ submitted to Licensor for inclusion in the Work by the copyright owner
+ or by an individual or Legal Entity authorized to submit on behalf of
+ the copyright owner. For the purposes of this definition, "submitted"
+ means any form of electronic, verbal, or written communication sent
+ to the Licensor or its representatives, including but not limited to
+ communication on electronic mailing lists, source code control systems,
+ and issue tracking systems that are managed by, or on behalf of, the
+ Licensor for the purpose of discussing and improving the Work, but
+ excluding communication that is conspicuously marked or otherwise
+ designated in writing by the copyright owner as "Not a Contribution."
+
+ "Contributor" shall mean Licensor and any individual or Legal Entity
+ on behalf of whom a Contribution has been received by Licensor and
+ subsequently incorporated within the Work.
+
+ 2. Grant of Copyright License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ copyright license to reproduce, prepare Derivative Works of,
+ publicly display, publicly perform, sublicense, and distribute the
+ Work and such Derivative Works in Source or Object form.
+
+ 3. Grant of Patent License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ (except as stated in this section) patent license to make, have made,
+ use, offer to sell, sell, import, and otherwise transfer the Work,
+ where such license applies only to those patent claims licensable
+ by such Contributor that are necessarily infringed by their
+ Contribution(s) alone or by combination of their Contribution(s)
+ with the Work to which such Contribution(s) was submitted. If You
+ institute patent litigation against any entity (including a
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
+ or a Contribution incorporated within the Work constitutes direct
+ or contributory patent infringement, then any patent licenses
+ granted to You under this License for that Work shall terminate
+ as of the date such litigation is filed.
+
+ 4. Redistribution. You may reproduce and distribute copies of the
+ Work or Derivative Works thereof in any medium, with or without
+ modifications, and in Source or Object form, provided that You
+ meet the following conditions:
+
+ (a) You must give any other recipients of the Work or
+ Derivative Works a copy of this License; and
+
+ (b) You must cause any modified files to carry prominent notices
+ stating that You changed the files; and
+
+ (c) You must retain, in the Source form of any Derivative Works
+ that You distribute, all copyright, patent, trademark, and
+ attribution notices from the Source form of the Work,
+ excluding those notices that do not pertain to any part of
+ the Derivative Works; and
+
+ (d) If the Work includes a "NOTICE" text file as part of its
+ distribution, then any Derivative Works that You distribute must
+ include a readable copy of the attribution notices contained
+ within such NOTICE file, excluding those notices that do not
+ pertain to any part of the Derivative Works, in at least one
+ of the following places: within a NOTICE text file distributed
+ as part of the Derivative Works; within the Source form or
+ documentation, if provided along with the Derivative Works; or,
+ within a display generated by the Derivative Works, if and
+ wherever such third-party notices normally appear. The contents
+ of the NOTICE file are for informational purposes only and
+ do not modify the License. You may add Your own attribution
+ notices within Derivative Works that You distribute, alongside
+ or as an addendum to the NOTICE text from the Work, provided
+ that such additional attribution notices cannot be construed
+ as modifying the License.
+
+ You may add Your own copyright statement to Your modifications and
+ may provide additional or different license terms and conditions
+ for use, reproduction, or distribution of Your modifications, or
+ for any such Derivative Works as a whole, provided Your use,
+ reproduction, and distribution of the Work otherwise complies with
+ the conditions stated in this License.
+
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
+ any Contribution intentionally submitted for inclusion in the Work
+ by You to the Licensor shall be under the terms and conditions of
+ this License, without any additional terms or conditions.
+ Notwithstanding the above, nothing herein shall supersede or modify
+ the terms of any separate license agreement you may have executed
+ with Licensor regarding such Contributions.
+
+ 6. Trademarks. This License does not grant permission to use the trade
+ names, trademarks, service marks, or product names of the Licensor,
+ except as required for reasonable and customary use in describing the
+ origin of the Work and reproducing the content of the NOTICE file.
+
+ 7. Disclaimer of Warranty. Unless required by applicable law or
+ agreed to in writing, Licensor provides the Work (and each
+ Contributor provides its Contributions) on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ implied, including, without limitation, any warranties or conditions
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+ PARTICULAR PURPOSE. You are solely responsible for determining the
+ appropriateness of using or redistributing the Work and assume any
+ risks associated with Your exercise of permissions under this License.
+
+ 8. Limitation of Liability. In no event and under no legal theory,
+ whether in tort (including negligence), contract, or otherwise,
+ unless required by applicable law (such as deliberate and grossly
+ negligent acts) or agreed to in writing, shall any Contributor be
+ liable to You for damages, including any direct, indirect, special,
+ incidental, or consequential damages of any character arising as a
+ result of this License or out of the use or inability to use the
+ Work (including but not limited to damages for loss of goodwill,
+ work stoppage, computer failure or malfunction, or any and all
+ other commercial damages or losses), even if such Contributor
+ has been advised of the possibility of such damages.
+
+ 9. Accepting Warranty or Additional Liability. While redistributing
+ the Work or Derivative Works thereof, You may choose to offer,
+ and charge a fee for, acceptance of support, warranty, indemnity,
+ or other liability obligations and/or rights consistent with this
+ License. However, in accepting such obligations, You may act only
+ on Your own behalf and on Your sole responsibility, not on behalf
+ of any other Contributor, and only if You agree to indemnify,
+ defend, and hold each Contributor harmless for any liability
+ incurred by, or claims asserted against, such Contributor by reason
+ of your accepting any such warranty or additional liability.
+
+----------------------------------------------------------------------------------
+The following files contain code contributed by Plugged In Software:
+
+src/main/java/com/hp/hpl/jena/rdf/arp/ExtendedHandler.java
+src/main/java/com/hp/hpl/jena/rdf/arp/impl/XMLHandler.java
+src/main/java/com/hp/hpl/jena/rdf/arp/ARP.java
+
+ (c) Copyright 2003, Plugged In Software
+
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions
+ are met:
+ 1. Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+ 2. Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+ 3. The name of the author may not be used to endorse or promote products
+ derived from this software without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+----------------------------------------------------------------------------------
+
+- - - - - - - - - - - - - - - - - - - - - - -
+
+ Copyright (c) 2004-2009 Mort Bay Consulting Pty. Ltd.
+
+All rights reserved. This program and the accompanying materials
+are made available under the terms of the Eclipse Public License v1.0
+and Apache License v2.0 which accompanies this distribution.
+
+The Eclipse Public License is available at
+ http://www.eclipse.org/legal/epl-v10.html
+The Apache License v2.0 is available at
+ http://www.opensource.org/licenses/apache2.0.php
Added: jena/Experimental/jena-commons/pom.xml
URL: http://svn.apache.org/viewvc/jena/Experimental/jena-commons/pom.xml?rev=1601074&view=auto
==============================================================================
--- jena/Experimental/jena-commons/pom.xml (added)
+++ jena/Experimental/jena-commons/pom.xml Sat Jun 7 07:50:07 2014
@@ -0,0 +1,47 @@
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <artifactId>jena-commons</artifactId>
+ <version>0.0.1-SNAPSHOT</version>
+ <build>
+ <plugins>
+ <plugin>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <version>3.1</version>
+ <configuration>
+ <source/>
+ <target/>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.jena</groupId>
+ <artifactId>apache-jena-libs</artifactId>
+ <version>${jena-version}</version>
+ <type>pom</type>
+ </dependency>
+ <dependency>
+ <groupId>commons-configuration</groupId>
+ <artifactId>commons-configuration</artifactId>
+ <version>1.10</version>
+ </dependency>
+ </dependencies>
+ <name>Apache Jena - jena-commons</name>
+ <description>Implementations of common tools to use Jena in other projects. For example implementation of Apache Commons interfaces.</description>
+ <inceptionYear>2014</inceptionYear>
+ <organization>
+ <name>The Apache Software Foundation</name>
+ <url>http://www.apache.org/</url>
+ </organization>
+ <properties>
+ <jena-version>2.11.1</jena-version>
+ <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+ </properties>
+ <scm>
+ <url>https://svn.apache.org/repos/asf/jena/Experimental/jena-common/</url>
+ <connection>scm:svn:https://svn.apache.org/repos/asf/jena/Experimental/jena-common/</connection>
+ <developerConnection>scm:svn:https://svn.apache.org/repos/asf/jena/Experimental/jena-common/</developerConnection>
+ </scm>
+ <groupId>org.apache.jena</groupId>
+</project>
\ No newline at end of file
Propchange: jena/Experimental/jena-commons/pom.xml
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: jena/Experimental/jena-commons/src/main/java/org/apache/jena/commons/configuration/RDFConfig.java
URL: http://svn.apache.org/viewvc/jena/Experimental/jena-commons/src/main/java/org/apache/jena/commons/configuration/RDFConfig.java?rev=1601074&view=auto
==============================================================================
--- jena/Experimental/jena-commons/src/main/java/org/apache/jena/commons/configuration/RDFConfig.java (added)
+++ jena/Experimental/jena-commons/src/main/java/org/apache/jena/commons/configuration/RDFConfig.java Sat Jun 7 07:50:07 2014
@@ -0,0 +1,434 @@
+package org.apache.jena.commons.configuration;
+
+import java.util.Iterator;
+import java.util.Set;
+import java.util.Stack;
+import java.util.TreeSet;
+
+import org.apache.commons.configuration.AbstractConfiguration;
+import org.apache.commons.configuration.ConversionException;
+import org.apache.commons.lang.StringUtils;
+import org.apache.xerces.util.XMLChar;
+
+import com.hp.hpl.jena.rdf.model.Literal;
+import com.hp.hpl.jena.rdf.model.Model;
+import com.hp.hpl.jena.rdf.model.Property;
+import com.hp.hpl.jena.rdf.model.RDFNode;
+import com.hp.hpl.jena.rdf.model.Resource;
+import com.hp.hpl.jena.rdf.model.ResourceFactory;
+import com.hp.hpl.jena.rdf.model.Statement;
+import com.hp.hpl.jena.rdf.model.StmtIterator;
+import com.hp.hpl.jena.util.iterator.ExtendedIterator;
+import com.hp.hpl.jena.util.iterator.SingletonIterator;
+
+/**
+ * An implementation of Apache Commons Configuration that sets/reads data from
+ * an Apache Jena Model.
+ * <p>
+ * This implementation utilizes a model as the storage layer. It has the
+ * following properties:
+ * <ul>
+ * <li>Only the first instance of any key will be used, multi-valued keys are
+ * not yet supported.</li>
+ * <li>Keys may be qualified or unqualified strings.
+ * <ul>
+ * <li>Qualified strings contain a URI prefix defined in the model, a colon, and
+ * the local name (e.g. rdf:type)</li>
+ * <li>unqualified string contain only the local name. When unqualified names
+ * are used they are qualified by the following algorithm:
+ * <ol>
+ * <li>if the name is a valid XML name and has a colon the model.expandPrefix()
+ * is called and the result used to construct a Property.</li>
+ * <li>else if the name is a valid XML name and does not have a colon the
+ * effective namespace is calculated and prepended the the unqualified name to
+ * qualify it.</li>
+ * <li>else the unqualified string is assumed to be a URL and the
+ * model.createProperty() is called with it.</li>
+ * </ol>
+ * </li>
+ * </ul>
+ * </li>
+ * <li>Keys may be a series keys (path) separated by the slash "/" character.
+ * (e.g. foo:part1/bar:part2 or foo:part1/part2 ) The namespace of any
+ * unqualified key takes the namespace value of the preceding key.
+ * foo:part1/part2 resolves to foo:part1/foo:part2</li> If there is no
+ * expelicitly defined namespace (e.g. part1/part2) the effective namespace is
+ * used.</li>
+ * <li>The effective namespace is calculated as follows:
+ * <ol>
+ * <li>If the namespace has been defined it is used.</li>
+ * <li>else if the base has been set (Resource constructor, or subset() method)
+ * the namespace of the base is used.</li>
+ * <li>else if the model has a value set for the empty prefix ("") that is used</li>
+ * <li>else the prefix "#" is used</li>
+ * <ol></li>
+ * <li>Whenever a subset is created namespace is set to the namespace of the
+ * last key.</li>
+ * </ul>
+ * </p>
+ * <p>
+ * This class should work on any model, however the getKeys() methods produce a
+ * list of keys in memory and may exhaust memory on very large graphs.
+ * </p>
+ *
+ *
+ */
+public class RDFConfig extends AbstractConfiguration {
+ private final Model model;
+ private Resource base;
+ private String namespace;
+
+ /**
+ * Constructor to create RDFConfig on the a base node. The default namespace
+ * for unqualified properties will be the namepace of the node. The model
+ * will be the model from the base.
+ *
+ * @param base
+ * The resource on which to base the configuration.
+ * @throws IllegalArgumentException
+ * if the resource is not in a model.
+ */
+ public RDFConfig(Resource base) throws IllegalArgumentException {
+ this(base, base.getNameSpace());
+ }
+
+ /**
+ * Constructor to create RDFConfig on the a base node and a namespace.
+ *
+ * @param base
+ * The resource on which to base the configuration.
+ * @param namespace
+ * The default namespace for unqualified properties.
+ * @throws IllegalArgumentException
+ * if the resource is not in a model.
+ */
+ public RDFConfig(Resource base, String namespace) {
+ this.model = base.getModel();
+ if (this.model == null) {
+ throw new IllegalArgumentException(
+ "Base resource muse be in a model");
+ }
+ this.namespace = namespace;
+ this.base = base;
+ }
+
+ /**
+ * Constructor to create RDFConfig on the a model.
+ *
+ * There is no default namespace defined so all properties must be fully
+ * qualified with a prefix. (e.g. rdf:type)
+ *
+ * @param model
+ * The model on which to base the configuration.
+ * @param namespace
+ * The default namespace for unqualified properties.
+ */
+ public RDFConfig(Model model) {
+ this.model = model;
+ }
+
+ /**
+ * Constructor to create RDFConfig on the a model with the specified default
+ * base. This is equivalent to calling new RDFConfig(model).subset( base );
+ *
+ * Properties that are not fully qualified will be assumed to be in the
+ * default namespace. Namespace may be a fully qualified namespace or a
+ * prefix name defined in the model.
+ *
+ * @param model
+ * The model on which to base the configuration.
+ * @param namespace
+ * The default namespace for unqualified properties.
+ */
+ public RDFConfig(Model model, String namespace) {
+ this.model = model;
+ if (XMLChar.isValidName(namespace)) {
+ this.namespace = model.getNsPrefixURI(namespace);
+ if (StringUtils.isEmpty(this.namespace)) {
+ throw new IllegalArgumentException(String.format(
+ "Prefix %s did not map to a URI in the model.",
+ namespace));
+ }
+ } else {
+ this.namespace = namespace;
+ }
+ }
+
+ /**
+ * Get the property for a key. Key may be fuly qualified (e.g. rdf:type),
+ * simple, or a complete URL.
+ *
+ * @param key
+ * The key to create a property for.
+ * @return The property.
+ */
+ private Property getKeyProperty(String key) {
+ if (XMLChar.isValidName(key)) {
+ if (!XMLChar.isValidNCName(key)) // has colon
+ {
+ return model.createProperty(model.expandPrefix(key));
+ }
+ return model.createProperty(effectiveNamespace(), key);
+ } else {
+ return model.createProperty(key);
+ }
+ }
+
+ /**
+ * Returns true if the key is in the graph.
+ */
+ public boolean containsKey(String key) {
+ String[] keys = key.split("/");
+ RDFConfig subset = navigateToSubSet(keys);
+ return subset == null ? false : subset
+ .containsKeyDirect(keys[keys.length - 1]);
+ }
+
+ /**
+ * Checks for key presence in the current graph.
+ *
+ * @param key
+ * the key to check for
+ * @return true if present.
+ */
+ private boolean containsKeyDirect(String key) {
+ if (base != null) {
+ return base.hasProperty(getKeyProperty(key));
+ } else {
+ return model.listStatements(getKeyProperty(key), null,
+ (RDFNode) null).hasNext();
+ }
+
+ }
+
+ /**
+ * Get the keyspace for the key resolution.
+ *
+ * @return the keyspace string.
+ */
+ private String effectiveNamespace() {
+ if (namespace == null) {
+ if (base == null) {
+ String s = model.getNsPrefixURI("");
+ return s == null ? "#" : s;
+ }
+ return base.getNameSpace();
+ }
+ return namespace;
+ }
+
+ /**
+ * Get the key value for a resource.
+ *
+ * @param r
+ * @return The key.
+ */
+ private String getKeyValue(Resource r) {
+ if (effectiveNamespace().equals(r.getNameSpace())) {
+ return r.getLocalName();
+ }
+ String pfx = model.getNsURIPrefix(r.getNameSpace());
+ if (pfx == null) {
+ return r.getURI();
+ }
+ return String.format("%s:%s", pfx, r.getLocalName());
+ }
+
+ /**
+ * Get the keys from the table.
+ */
+ public Iterator<String> getKeys() {
+ ExtendedIterator<Resource> iter = (base == null) ? model.listSubjects()
+ : new SingletonIterator<Resource>(base);
+
+ Set<String> s = new TreeSet<String>();
+ Stack<Resource> stack = new Stack<Resource>();
+ while (iter.hasNext()) {
+ Resource r = iter.next();
+ addResourceKeys(stack, s, "", r);
+ }
+ return s.iterator();
+ }
+
+ @Override
+ public Iterator<String> getKeys(String prefix) {
+ return subset(prefix).getKeys();
+ }
+
+ private void addResourceKeys(Stack<Resource> stack, Set<String> s,
+ String pfx, Resource r) {
+ if (stack.contains(r)) {
+ return;
+ }
+ stack.push(r);
+ ExtendedIterator<Statement> stmtIter = r.listProperties();
+ while (stmtIter.hasNext()) {
+ Statement stmt = stmtIter.next();
+ String key = pfx + getKeyValue(stmt.getPredicate());
+ if (s.add(key) && stmt.getObject().isResource()) {
+ addResourceKeys(stack, s, key + "/", stmt.getObject()
+ .asResource());
+ }
+ }
+ stack.pop();
+ }
+
+ /**
+ * Go to the subset specified by the key path.
+ *
+ * @param keys
+ * the list of keys specifying a path/
+ * @return The subset configuration on the end node of the path.
+ */
+ private RDFConfig navigateToSubSet(String[] keys) {
+ if (keys.length == 1) {
+ return this;
+ }
+ // more than one key
+ RDFConfig subcfg = this;
+ for (int i = 0; i < keys.length - 1; i++) {
+ subcfg = subcfg.subset(keys[i]);
+ if (subcfg == null) {
+ return null;
+ }
+ }
+ return subcfg;
+ }
+
+ /**
+ * Get the property for a key.
+ */
+ public Object getProperty(String key) {
+ String[] keys = key.split("/");
+ if (keys.length > 1) {
+ RDFConfig subcfg = navigateToSubSet(keys);
+ return subcfg == null ? null : subcfg
+ .getProperty(keys[keys.length - 1]);
+ } else {
+ if (base == null) {
+ Property p = getKeyProperty(key);
+ // do not create the property just verify that it is here. Must
+ // return null if the
+ // property is not here.
+ StmtIterator iter = model.listStatements(p, null,
+ (RDFNode) null);
+ if (iter.hasNext()) {
+ return p;
+ }
+ return null;
+ } else {
+ Statement stmt = base.getProperty(getKeyProperty(key));
+ if (stmt == null) {
+ return null;
+ }
+ RDFNode r = stmt.getObject();
+ if (r.isLiteral()) {
+ return ((Literal) r).getValue();
+ }
+ return r;
+ }
+ }
+ }
+
+ @Override
+ public String getString(String key, String defaultValue) {
+ Object value = resolveContainerStore(key);
+ if (value instanceof Resource) {
+ return interpolate(getKeyValue((Resource) value));
+ }
+
+ if (value instanceof String) {
+ return interpolate((String) value);
+ } else if (value == null) {
+ return interpolate(defaultValue);
+ } else {
+ throw new ConversionException('\'' + key
+ + "' doesn't map to a String object");
+ }
+ }
+
+ public boolean isEmpty() {
+ return base == null ? model.isEmpty() : (!base.listProperties()
+ .hasNext());
+ }
+
+ @Override
+ protected void addPropertyDirect(String keyStr, Object valueObj) {
+ String[] keys = keyStr.split("/");
+ RDFConfig tmpCfg = null;
+ RDFConfig subCfg = this;
+ if (keys.length > 1) {
+ for (int i = 0; i < keys.length - 1; i++) {
+ tmpCfg = subCfg.subset(keys[i]);
+ if (tmpCfg == null) {
+ if (subCfg.base == null) {
+ // with 2 args we set value
+ if (i + 2 == keys.length) {
+ RDFNode value = valueObj instanceof RDFNode ? (RDFNode) valueObj
+ : ResourceFactory
+ .createTypedLiteral(valueObj);
+ model.add(getKeyProperty(keys[i]),
+ getKeyProperty(keys[i + 1]), value);
+ return;
+ } else {
+ model.add(getKeyProperty(keys[i]),
+ getKeyProperty(keys[i + 1]),
+ model.createResource());
+ }
+
+ } else {
+ // is at least i+1<keys.length
+ subCfg.base.addProperty(getKeyProperty(keys[i]),
+ model.createResource());
+ }
+ tmpCfg = subCfg.subset(keys[i]);
+ }
+ subCfg = tmpCfg;
+ }
+ subCfg.addPropertyDirect(keys[keys.length - 1], valueObj);
+ } else {
+
+ if (base == null) {
+ throw new IllegalArgumentException(
+ "Can not set single property when base has not been set");
+ }
+ RDFNode value = valueObj instanceof RDFNode ? (RDFNode) valueObj
+ : ResourceFactory.createTypedLiteral(valueObj);
+ Property key = getKeyProperty(keyStr);
+ Statement stmt = base.getProperty(key);
+ if (stmt == null) {
+ base.addProperty(key, value);
+ } else {
+ stmt.changeObject(value);
+ }
+ }
+ }
+
+ /**
+ * Creates a config that is based at the prefix node. The namespace is set
+ * to the namespace of the prefix node.
+ * <p>
+ * The prefix may be a series of keys separated by "/"
+ */
+ @Override
+ public RDFConfig subset(String prefix) {
+ Object o = getProperty(prefix);
+ if (o instanceof Resource) {
+ String[] parts = prefix.split("/");
+ Property p = getKeyProperty(parts[parts.length - 1]);
+ return new RDFConfig((Resource) o, p.getNameSpace());
+ }
+ return null;
+ }
+
+ /**
+ * Get the current base resource.
+ *
+ * Primarily used in testing.
+ *
+ * @return The base Resource
+ */
+ public Resource getBase() {
+ return base;
+ }
+}
Propchange: jena/Experimental/jena-commons/src/main/java/org/apache/jena/commons/configuration/RDFConfig.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: jena/Experimental/jena-commons/src/main/java/org/apache/jena/commons/configuration/RDFFileConfiguration.java
URL: http://svn.apache.org/viewvc/jena/Experimental/jena-commons/src/main/java/org/apache/jena/commons/configuration/RDFFileConfiguration.java?rev=1601074&view=auto
==============================================================================
--- jena/Experimental/jena-commons/src/main/java/org/apache/jena/commons/configuration/RDFFileConfiguration.java (added)
+++ jena/Experimental/jena-commons/src/main/java/org/apache/jena/commons/configuration/RDFFileConfiguration.java Sat Jun 7 07:50:07 2014
@@ -0,0 +1,183 @@
+package org.apache.jena.commons.configuration;
+
+import java.io.InputStream;
+import java.io.Reader;
+
+import com.hp.hpl.jena.rdf.model.Model;
+import com.hp.hpl.jena.rdf.model.ModelFactory;
+
+/**
+ * A wrapper around the Jena Model read() methodds to create Configurations
+ * from RDF files.
+ *
+ * These methods return Model based RDFConfigs.
+ *
+ * All arguments are equivalent to the Model.read() methods.
+ *
+ */
+public class RDFFileConfiguration extends RDFConfig {
+
+
+
+ /** Read the RDF statements from a document.
+ * Uses content negotiation to request appropriate mime types.
+ * If the content type is not found, it may guess from the URL.
+ * <p>See {@link Model} for a description of how to traverse a firewall.</p>
+ * <p>
+ * See <a href="http://jena.apache.org/documentation/io/index.html">"Reading and Writing RDF in Apache Jena"</a>
+ * for more information about determining the syntax.
+ * </p>
+ *
+ * @return this Configuration
+ * @param url of the document containing the RDF statements.
+ */
+ public RDFFileConfiguration(String url) {
+ super( ModelFactory.createDefaultModel().read(url) );
+ }
+
+ /** Read statements from a document.
+ * This method assumes the concrete syntax is RDF/XML.
+ * See {@link #read(InputStream, String, String)} for explicitly setting the language.
+ * <p>
+ * See <a href="http://jena.apache.org/documentation/io/index.html">"Reading and Writing RDF in Apache Jena"</a>
+ * for more information about concrete syntaxes.
+ * </p>
+ *
+ * @param in the input stream
+
+ @param base the base uri to be used when converting relative
+ URI's to absolute URI's. (Resolving relative URIs and fragment IDs is done
+ by prepending the base URI to the relative URI/fragment.) If there are no
+ relative URIs in the source, this argument may safely be <code>null</code>.
+ If the base is the empty string, then relative URIs <i>will be retained in
+ the model</i>. This is typically unwise and will usually generate errors
+ when writing the model back out.
+
+ * @return the current model
+ */
+ public RDFFileConfiguration(InputStream in, String base)
+ {
+ super(ModelFactory.createDefaultModel().read(in, base));
+ }
+
+ /** Read RDF statements represented in language <code>lang</code> to the model.
+ * <br />Predefined values for <code>lang</code> are "RDF/XML", "N-TRIPLE",
+ * "TURTLE" (or "TTL") and "N3".
+ * <code>null</code> represents the default language, "RDF/XML".
+ * "RDF/XML-ABBREV" is a synonym for "RDF/XML".
+ * <br />
+ *
+ * @return this model
+
+ @param base the base uri to be used when converting relative
+ URI's to absolute URI's. (Resolving relative URIs and fragment IDs is done
+ by prepending the base URI to the relative URI/fragment.) If there are no
+ relative URIs in the source, this argument may safely be <code>null</code>.
+ If the base is the empty string, then relative URIs <i>will be retained in
+ the model</i>. This is typically unwise and will usually generate errors
+ when writing the model back out.
+ * <p>
+ * See <a href="http://jena.apache.org/documentation/io/index.html">"Reading and Writing RDF in Apache Jena"</a>
+ * for more information about concrete syntaxes.
+ * </p>
+
+ * @param lang the langauge of the serialization <code>null</code>
+ * selects the default
+ * @param in the source of the input serialization
+ */
+ public RDFFileConfiguration(InputStream in, String base, String lang)
+ {
+ super(ModelFactory.createDefaultModel().read(in, base, lang));
+ }
+
+ /** Using this method is often a mistake.
+ * Read statements from an RDF/XML serialization.
+ * It is generally better to use an InputStream if possible,
+ * otherwise there is a danger of a
+ * mismatch between the character encoding of say the FileReader and the
+ * character encoding of the data in the file.
+ *
+ * It is better to explicitly set the serialization format.
+ * See {@link #read(InputStream, String, String)} for explicitily setting the serialization language.
+ *
+ * <p>
+ * See <a href="http://jena.apache.org/documentation/io/index.html">"Reading and Writing RDF in Apache Jena"</a>
+ * for more information about concrete syntaxes.
+ * </p>
+ * @param reader
+ * @param base the base uri to be used when converting relative URI's to absolute URI's and to guess the RDF serialization syntax.
+ * @return the current model
+ */
+ public RDFFileConfiguration(Reader reader, String base)
+ {
+ super(ModelFactory.createDefaultModel().read(reader, base));
+ }
+
+ /**
+ * Read statements from a serializion in language <code>lang</code> to the
+ * model.
+ * <br />Predefined values for <code>lang</code> are "RDF/XML", "N-TRIPLE",
+ * "TURTLE" (or "TTL") and "N3".
+ * <code>null</code> represents the default language, "RDF/XML".
+ * "RDF/XML-ABBREV" is a synonym for "RDF/XML".
+ * <br />
+ *
+ * <p>See {@link Model} for a description of how to traverse a firewall.</p>
+ * <p>
+ * See <a href="http://jena.apache.org/documentation/io/index.html">"Reading and Writing RDF in Apache Jena"</a>
+ * for more information about concrete syntaxes.
+ * </p>
+
+ * @param url a string representation of the url to read from
+ * @param lang the language of the serialization
+
+ * @return this model
+ */
+ public RDFFileConfiguration(String url, String lang)
+ {
+ super(ModelFactory.createDefaultModel().read(url, lang));
+ }
+
+
+ /** Using this method is often a mistake.
+ * Read RDF statements represented in language <code>lang</code> to the model.
+ * <br />Predefined values for <code>lang</code> are "RDF/XML", "N-TRIPLE",
+ * "TURTLE" (or "TTL") and "N3".
+ * <code>null</code> represents the default language, "RDF/XML".
+ *"RDF/XML-ABBREV" is a synonym for "RDF/XML".
+ * <br />
+ * It is generally better to use an InputStream if possible.
+ * {@link Model#read(InputStream,String)}, otherwise there is a danger of a
+ * mismatch between the character encoding of say the FileReader and the
+ * character encoding of the data in the file.
+ * @return this model
+
+ @param base the base uri to be used when converting relative
+ URI's to absolute URI's. (Resolving relative URIs and fragment IDs is done
+ by prepending the base URI to the relative URI/fragment.) If there are no
+ relative URIs in the source, this argument may safely be <code>null</code>.
+ If the base is the empty string, then relative URIs <i>will be retained in
+ the model</i>. This is typically unwise and will usually generate errors
+ when writing the model back out.
+
+ * @param lang the langauge of the serialization <code>null</code>
+ * selects the default
+ * @param reader the source of the input serialization
+ */
+ public RDFFileConfiguration(Reader reader, String base, String lang)
+ {
+ super(ModelFactory.createDefaultModel().read(reader, base, lang));
+ }
+
+ /**
+ Read the RDF at <code>url</code>, using
+ <code>baseURI</code> as the base URI if it is non-null. The RDF is assumed
+ to be RDF/XML unless <code>lang</code> is non-null, in which case it names
+ the language to be used. Answer this model.
+ */
+ public RDFFileConfiguration( String url, String base, String lang )
+ {
+ super(ModelFactory.createDefaultModel().read(url, base, lang));
+ }
+
+}
Propchange: jena/Experimental/jena-commons/src/main/java/org/apache/jena/commons/configuration/RDFFileConfiguration.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: jena/Experimental/jena-commons/src/test/java/org/apache/jena/commons/configuration/AssemblerRDFConfigTest.java
URL: http://svn.apache.org/viewvc/jena/Experimental/jena-commons/src/test/java/org/apache/jena/commons/configuration/AssemblerRDFConfigTest.java?rev=1601074&view=auto
==============================================================================
--- jena/Experimental/jena-commons/src/test/java/org/apache/jena/commons/configuration/AssemblerRDFConfigTest.java (added)
+++ jena/Experimental/jena-commons/src/test/java/org/apache/jena/commons/configuration/AssemblerRDFConfigTest.java Sat Jun 7 07:50:07 2014
@@ -0,0 +1,110 @@
+package org.apache.jena.commons.configuration;
+
+import static org.junit.Assert.*;
+
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.Set;
+
+import org.apache.commons.configuration.Configuration;
+import org.apache.jena.commons.configuration.RDFConfig;
+import org.junit.Before;
+import org.junit.Test;
+
+import com.hp.hpl.jena.rdf.model.ModelFactory;
+import com.hp.hpl.jena.rdf.model.Model;
+import com.hp.hpl.jena.rdf.model.Resource;
+import com.hp.hpl.jena.util.iterator.WrappedIterator;
+
+public class AssemblerRDFConfigTest {
+
+ protected Model model;
+ protected Resource base;
+ protected Configuration cfg;
+ protected URL url;
+
+ @Before
+ public void setup() {
+
+ model = ModelFactory.createDefaultModel();
+
+ url = AssemblerRDFConfigTest.class.getResource("assembler.ttl");
+ model.read(url.toString());
+ // use the model starting at data:graphNamed
+ cfg = new RDFConfig(model).subset( "data:graphNamed");
+ }
+
+ protected static String makeURI(String ns, String localName) {
+ return String.format("%s%s", ns, localName);
+ }
+
+ protected String makePfx(String ns, String localName) {
+ String s = model.getNsURIPrefix(ns);
+ if (s == null) {
+ return localName;
+ }
+ return String.format("%s:%s", s, localName);
+ }
+
+ @Test
+ public void testGetValue() throws MalformedURLException {
+ Resource r = ((RDFConfig) cfg).getBase();
+ assertNotNull(r);
+ assertEquals("http://example/test#graphNamed", r.getURI());
+
+ Object o = cfg.getProperty("rdf:type");
+ assertTrue(o instanceof Resource);
+ assertEquals("http://jena.hpl.hp.com/2007/sdb#Model",
+ ((Resource) o).getURI());
+
+ o = cfg.getProperty("sdb:namedGraph");
+ assertTrue(o instanceof Resource);
+ assertEquals("http://example/test#graph1", ((Resource) o).getURI());
+
+ o = cfg.getProperty("sdb:dataset");
+ assertTrue(o instanceof Resource);
+ URL u = new URL(((Resource) o).getURI());
+ assertEquals(url.toString() + "#dataset", u.toString());
+
+ }
+
+ @Test
+ public void testGetKeys() {
+ Resource r = ((RDFConfig) cfg).getBase();
+ assertNotNull(r);
+ assertEquals("http://example/test#graphNamed", r.getURI());
+
+ Set<String> keys = WrappedIterator.create(cfg.getKeys()).toSet();
+
+ assertTrue(keys.contains("rdf:type"));
+ assertTrue(keys.contains("sdb:namedGraph"));
+ assertTrue(keys.contains("sdb:dataset"));
+
+ }
+
+ @Test
+ public void testGetSubset() {
+ Resource r = ((RDFConfig) cfg).getBase();
+ assertNotNull(r);
+ assertEquals("http://example/test#graphNamed", r.getURI());
+
+ Configuration subset = cfg.subset("sdb:dataset");
+ assertNotNull(subset.getProperty("sdb:store"));
+
+ subset = subset.subset("sdb:store");
+
+ assertEquals("layout2", subset.getString("sdb:layout"));
+
+ subset = subset.subset("sdb:connection");
+
+ assertEquals("hsqldb", subset.getString("sdb:sdbType"));
+ assertEquals("mem", subset.getString("sdb:sdbHost"));
+ assertEquals("sa", subset.getString("sdb:sdbUser"));
+
+ assertEquals(
+ "hsqldb",
+ cfg.getString("sdb:dataset/sdb:store/sdb:connection/sdb:sdbType"));
+
+ }
+
+}
Propchange: jena/Experimental/jena-commons/src/test/java/org/apache/jena/commons/configuration/AssemblerRDFConfigTest.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: jena/Experimental/jena-commons/src/test/java/org/apache/jena/commons/configuration/RDFConfigTest.java
URL: http://svn.apache.org/viewvc/jena/Experimental/jena-commons/src/test/java/org/apache/jena/commons/configuration/RDFConfigTest.java?rev=1601074&view=auto
==============================================================================
--- jena/Experimental/jena-commons/src/test/java/org/apache/jena/commons/configuration/RDFConfigTest.java (added)
+++ jena/Experimental/jena-commons/src/test/java/org/apache/jena/commons/configuration/RDFConfigTest.java Sat Jun 7 07:50:07 2014
@@ -0,0 +1,425 @@
+package org.apache.jena.commons.configuration;
+
+import static org.junit.Assert.*;
+
+import java.util.List;
+
+import org.apache.commons.configuration.Configuration;
+import org.apache.jena.commons.configuration.RDFConfig;
+import org.junit.Before;
+import org.junit.Test;
+
+import com.hp.hpl.jena.rdf.model.ModelFactory;
+import com.hp.hpl.jena.rdf.model.Model;
+import com.hp.hpl.jena.rdf.model.Resource;
+import com.hp.hpl.jena.rdf.model.ResourceFactory;
+import com.hp.hpl.jena.util.iterator.WrappedIterator;
+
+public class RDFConfigTest {
+
+ protected String baseNS;
+ protected String propertyNS;
+ protected Model model;
+ protected Resource base;
+ protected Configuration cfg;
+
+ @Before
+ public void setup() {
+ baseNS = "http://example.com/";
+ propertyNS = "http://prop.example.com/";
+ model = ModelFactory.createDefaultModel();
+ base = model.createResource(makeURI(baseNS, "test"));
+ cfg = new RDFConfig(base);
+
+ }
+
+ protected static String makeURI(String ns, String localName) {
+ return String.format("%s%s", ns, localName);
+ }
+
+ protected String makePfx(String ns, String localName) {
+ String s = model.getNsURIPrefix(ns);
+ if (s == null) {
+ return localName;
+ }
+ return String.format("%s:%s", s, localName);
+ }
+
+ @Test
+ public void testSetValue() {
+
+ cfg.addProperty("text", "Text String");
+ cfg.addProperty("int", 1);
+ cfg.addProperty("double", 3.14);
+ cfg.addProperty("resource",
+ ResourceFactory.createResource(makeURI(baseNS, "test2")));
+
+ model.write(System.out, "TTL");
+
+ assertEquals("Text String", cfg.getString("text"));
+ assertEquals(Integer.valueOf(1), Integer.valueOf(cfg.getInt("int")));
+ assertEquals(Double.valueOf(3.14),
+ Double.valueOf(cfg.getDouble("double")));
+ model.getNsURIPrefix(baseNS);
+ assertEquals(makePfx(baseNS, "test2"), cfg.getString("resource"));
+ }
+
+ @Test
+ public void testGetResources() {
+ Resource r = model.createResource(makeURI(baseNS, "test2"));
+ r.addLiteral(ResourceFactory.createProperty(baseNS, "text"),
+ "Sub Test String");
+
+ cfg.addProperty("text", "Text String");
+ cfg.addProperty("text2/one", "Text String 1");
+ cfg.addProperty("text2/two", "Text String 2");
+ cfg.addProperty("int", 1);
+ cfg.addProperty("double", 3.14);
+ cfg.addProperty("resource", r);
+
+ model.write(System.out, "TTL");
+
+ assertEquals("Text String", cfg.getString("text"));
+ assertEquals(Integer.valueOf(1), Integer.valueOf(cfg.getInt("int")));
+ assertEquals(Double.valueOf(3.14),
+ Double.valueOf(cfg.getDouble("double")));
+ assertEquals(makePfx(baseNS, "test2"), cfg.getString("resource"));
+ Configuration subCfg = cfg.subset("resource");
+
+ assertNotNull(subCfg);
+ assertEquals("Sub Test String", subCfg.getString("text"));
+
+ subCfg = cfg.subset("text2");
+
+ assertNotNull(subCfg);
+ assertEquals("Text String 1", subCfg.getString("one"));
+ assertEquals("Text String 2", subCfg.getString("two"));
+ }
+
+ @Test
+ public void testGetResources_w_Model() {
+ Resource r = model.createResource(makeURI(baseNS, "test2"));
+ r.addLiteral(ResourceFactory.createProperty(propertyNS, "text"),
+ "Sub Test String");
+ cfg = new RDFConfig(model);
+ try {
+ cfg.addProperty("text", "Text String");
+ fail("Should have thrown IllegalArgumentException");
+ } catch (IllegalArgumentException expected) {
+ // do nothing
+ }
+ cfg.addProperty("pseudoBase/text", "Text String");
+ cfg.addProperty("pseudoBase/text2/one", "Text String 1");
+ cfg.addProperty("pseudoBase/text2/two", "Text String 2");
+ cfg.addProperty("pseudoBase/int", 1);
+ cfg.addProperty("pseudoBase/double", 3.14);
+ cfg.addProperty("pseudoBase/resource", r);
+
+ model.write(System.out, "TTL");
+
+ assertEquals("Text String", cfg.getString("pseudoBase/text"));
+ assertEquals(Integer.valueOf(1),
+ Integer.valueOf(cfg.getInt("pseudoBase/int")));
+ assertEquals(Double.valueOf(3.14),
+ Double.valueOf(cfg.getDouble("pseudoBase/double")));
+ assertEquals(makeURI(baseNS, "test2"),
+ cfg.getString("pseudoBase/resource"));
+ Configuration subCfg = cfg.subset("pseudoBase/resource");
+
+ assertNotNull(subCfg);
+ model.setNsPrefix("exp", propertyNS);
+ assertEquals("Sub Test String", subCfg.getString("exp:text"));
+
+ subCfg = cfg.subset("pseudoBase/text2");
+
+ assertNotNull(subCfg);
+ assertEquals("Text String 1", subCfg.getString("one"));
+ assertEquals("Text String 2", subCfg.getString("two"));
+ }
+
+ @Test
+ public void testGetResources_w_Pfx() {
+ setPrefixes();
+ Resource r = model.createResource(makeURI(baseNS, "test2"));
+ r.addLiteral(ResourceFactory.createProperty(propertyNS, "text"),
+ "Sub Test String");
+
+ cfg.addProperty("prop:text", "Text String");
+ cfg.addProperty("prop:text2/prop:one", "Text String 1");
+ cfg.addProperty("prop:text2/prop:two", "Text String 2");
+ cfg.addProperty("prop:int", 1);
+ cfg.addProperty("prop:double", 3.14);
+ cfg.addProperty("prop:resource", r);
+
+ model.write(System.out, "TTL");
+
+ assertEquals("Text String", cfg.getString("prop:text"));
+ assertEquals(Integer.valueOf(1),
+ Integer.valueOf(cfg.getInt("prop:int")));
+ assertEquals(Double.valueOf(3.14),
+ Double.valueOf(cfg.getDouble("prop:double")));
+ assertEquals("test2", cfg.getString("prop:resource"));
+ Configuration subCfg = cfg.subset("prop:resource");
+
+ assertNotNull(subCfg);
+ assertEquals("Sub Test String", subCfg.getString("prop:text"));
+
+ subCfg = cfg.subset("prop:text2");
+
+ assertNotNull(subCfg);
+ assertEquals("Text String 1", subCfg.getString("one"));
+ assertEquals("Text String 2", subCfg.getString("two"));
+
+ assertEquals("Text String 1", subCfg.getString("prop:one"));
+ assertEquals("Text String 2", subCfg.getString("prop:two"));
+
+ }
+
+ private void setPrefixes() {
+ model.setNsPrefix("prop", propertyNS);
+ model.setNsPrefix("base", baseNS);
+ model.setNsPrefix("foo", "http://foo.example.com/");
+ }
+
+ @Test
+ public void testGetResources_w_Model_w_pfx() {
+ setPrefixes();
+ Resource r = model.createResource(makeURI(baseNS, "test2"));
+ r.addLiteral(ResourceFactory.createProperty(propertyNS, "text"),
+ "Sub Test String");
+ cfg = new RDFConfig(model);
+ try {
+ cfg.addProperty("text", "Text String");
+ fail("Should have thrown IllegalArgumentException");
+ } catch (IllegalArgumentException expected) {
+ // do nothing
+ }
+ cfg.addProperty("prop:pseudoBase/prop:text", "Text String");
+ cfg.addProperty("prop:pseudoBase/prop:text2/prop:one", "Text String 1");
+ cfg.addProperty("prop:pseudoBase/prop:text2/prop:two", "Text String 2");
+ cfg.addProperty("prop:pseudoBase/prop:int", 1);
+ cfg.addProperty("prop:pseudoBase/prop:double", 3.14);
+ cfg.addProperty("prop:pseudoBase/prop:resource", r);
+
+ model.write(System.out, "TTL");
+
+ assertEquals("Text String", cfg.getString("prop:pseudoBase/prop:text"));
+ assertEquals(Integer.valueOf(1),
+ Integer.valueOf(cfg.getInt("prop:pseudoBase/prop:int")));
+ assertEquals(Double.valueOf(3.14),
+ Double.valueOf(cfg.getDouble("prop:pseudoBase/prop:double")));
+ assertEquals("base:test2",
+ cfg.getString("prop:pseudoBase/prop:resource"));
+ Configuration subCfg = cfg.subset("prop:pseudoBase/prop:resource");
+
+ assertNotNull(subCfg);
+ assertEquals("Sub Test String", subCfg.getString("prop:text"));
+
+ subCfg = cfg.subset("prop:pseudoBase/prop:text2");
+
+ assertNotNull(subCfg);
+ assertEquals("Text String 1", subCfg.getString("prop:one"));
+ assertEquals("Text String 2", subCfg.getString("prop:two"));
+ }
+
+ @Test
+ public void testSubsetBaseSetting_Base() {
+ setPrefixes();
+
+ cfg.addProperty("foo:text/foo:one", "Foo Foo String 1");
+ cfg.addProperty("foo:text/foo:two", "Foo Foo String 2");
+ cfg.addProperty("foo:text/prop:one", "Foo Prop String 1");
+ cfg.addProperty("foo:text/prop:two", "Foo Prop String 2");
+ cfg.addProperty("foo:text/base:one", "Foo Base String 1");
+ cfg.addProperty("foo:text/base:two", "Foo Base String 2");
+ cfg.addProperty("base:one", "Base Base String 1");
+ cfg.addProperty("base:two", "Base Base String 2");
+ cfg.addProperty("foo:one", "Base Foo String 1");
+ cfg.addProperty("foo:two", "Base Foo String 2");
+ cfg.addProperty("prop:one", "Base Prop String 1");
+ cfg.addProperty("prop:two", "Base Prop String 2");
+
+ model.write(System.out, "TTL");
+
+ assertEquals("Base Base String 1", cfg.getString("one"));
+ assertEquals("Base Foo String 1", cfg.getString("foo:one"));
+ assertEquals("Base Prop String 1", cfg.getString("prop:one"));
+ assertEquals("Base Base String 1", cfg.getString("base:one"));
+
+ Configuration subCfg = cfg.subset("foo:text");
+ assertEquals("Foo Foo String 1", subCfg.getString("one"));
+ assertEquals("Foo Foo String 1", subCfg.getString("foo:one"));
+ assertEquals("Foo Prop String 1", subCfg.getString("prop:one"));
+ assertEquals("Foo Base String 1", subCfg.getString("base:one"));
+
+ assertEquals("Foo Foo String 1", cfg.getString("foo:text/one"));
+ assertEquals("Foo Foo String 1", cfg.getString("foo:text/foo:one"));
+ assertEquals("Foo Prop String 1", cfg.getString("foo:text/prop:one"));
+ assertEquals("Foo Base String 1", cfg.getString("foo:text/base:one"));
+
+ }
+
+ @Test
+ public void testSubsetBaseSetting_Model() {
+ setPrefixes();
+ cfg = new RDFConfig(model);
+ cfg.addProperty("base:test/foo:text/foo:one", "Foo Foo String 1");
+ cfg.addProperty("base:test/foo:text/foo:two", "Foo Foo String 2");
+ cfg.addProperty("base:test/foo:text/prop:one", "Foo Prop String 1");
+ cfg.addProperty("base:test/foo:text/prop:two", "Foo Prop String 2");
+ cfg.addProperty("base:test/foo:text/base:one", "Foo Base String 1");
+ cfg.addProperty("base:test/foo:text/base:two", "Foo Base String 2");
+ cfg.addProperty("base:test/base:one", "Base Base String 1");
+ cfg.addProperty("base:test/base:two", "Base Base String 2");
+ cfg.addProperty("base:test/foo:one", "Base Foo String 1");
+ cfg.addProperty("base:test/foo:two", "Base Foo String 2");
+ cfg.addProperty("base:test/prop:one", "Base Prop String 1");
+ cfg.addProperty("base:test/prop:two", "Base Prop String 2");
+
+ model.write(System.out, "TTL");
+
+ assertEquals("Base Base String 1", cfg.getString("base:test/one"));
+ assertEquals("Base Foo String 1", cfg.getString("base:test/foo:one"));
+ assertEquals("Base Prop String 1", cfg.getString("base:test/prop:one"));
+ assertEquals("Base Base String 1", cfg.getString("base:test/base:one"));
+
+ Configuration subCfg = cfg.subset("base:test/foo:text");
+ assertEquals("Foo Foo String 1", subCfg.getString("one"));
+ assertEquals("Foo Foo String 1", subCfg.getString("foo:one"));
+ assertEquals("Foo Prop String 1", subCfg.getString("prop:one"));
+ assertEquals("Foo Base String 1", subCfg.getString("base:one"));
+
+ assertEquals("Foo Foo String 1",
+ cfg.getString("base:test/foo:text/one"));
+ assertEquals("Foo Foo String 1",
+ cfg.getString("base:test/foo:text/foo:one"));
+ assertEquals("Foo Prop String 1",
+ cfg.getString("base:test/foo:text/prop:one"));
+ assertEquals("Foo Base String 1",
+ cfg.getString("base:test/foo:text/base:one"));
+
+ }
+
+ @Test
+ public void testSubsetBaseSetting_Model_w_defaultNS() {
+ setPrefixes();
+ cfg = new RDFConfig(model, baseNS);
+ cfg.addProperty("base:test/foo:text/foo:one", "Foo Foo String 1");
+ cfg.addProperty("base:test/foo:text/foo:two", "Foo Foo String 2");
+ cfg.addProperty("base:test/foo:text/prop:one", "Foo Prop String 1");
+ cfg.addProperty("base:test/foo:text/prop:two", "Foo Prop String 2");
+ cfg.addProperty("base:test/foo:text/base:one", "Foo Base String 1");
+ cfg.addProperty("base:test/foo:text/base:two", "Foo Base String 2");
+ cfg.addProperty("base:test/base:one", "Base Base String 1");
+ cfg.addProperty("base:test/base:two", "Base Base String 2");
+ cfg.addProperty("base:test/foo:one", "Base Foo String 1");
+ cfg.addProperty("base:test/foo:two", "Base Foo String 2");
+ cfg.addProperty("base:test/prop:one", "Base Prop String 1");
+ cfg.addProperty("base:test/prop:two", "Base Prop String 2");
+
+ model.write(System.out, "TTL");
+
+ assertEquals("Base Base String 1", cfg.getString("base:test/one"));
+ assertEquals("Base Foo String 1", cfg.getString("base:test/foo:one"));
+ assertEquals("Base Prop String 1", cfg.getString("base:test/prop:one"));
+ assertEquals("Base Base String 1", cfg.getString("base:test/base:one"));
+
+ Configuration subCfg = cfg.subset("base:test/foo:text");
+ assertEquals("Foo Foo String 1", subCfg.getString("one"));
+ assertEquals("Foo Foo String 1", subCfg.getString("foo:one"));
+ assertEquals("Foo Prop String 1", subCfg.getString("prop:one"));
+ assertEquals("Foo Base String 1", subCfg.getString("base:one"));
+
+ assertEquals("Foo Foo String 1",
+ cfg.getString("base:test/foo:text/one"));
+ assertEquals("Foo Foo String 1",
+ cfg.getString("base:test/foo:text/foo:one"));
+ assertEquals("Foo Prop String 1",
+ cfg.getString("base:test/foo:text/prop:one"));
+ assertEquals("Foo Base String 1",
+ cfg.getString("base:test/foo:text/base:one"));
+
+ subCfg = cfg.subset("test/foo:text");
+ assertEquals("Foo Foo String 1", subCfg.getString("one"));
+ assertEquals("Foo Foo String 1", subCfg.getString("foo:one"));
+ assertEquals("Foo Prop String 1", subCfg.getString("prop:one"));
+ assertEquals("Foo Base String 1", subCfg.getString("base:one"));
+
+ assertEquals("Foo Foo String 1", cfg.getString("test/foo:text/one"));
+ assertEquals("Foo Foo String 1", cfg.getString("test/foo:text/foo:one"));
+ assertEquals("Foo Prop String 1",
+ cfg.getString("test/foo:text/prop:one"));
+ assertEquals("Foo Base String 1",
+ cfg.getString("test/foo:text/base:one"));
+
+ }
+
+ @Test
+ public void testGetKeys() {
+ setPrefixes();
+
+ cfg.addProperty("foo:text/foo:one", "Foo Foo String 1");
+ cfg.addProperty("foo:text/foo:two", "Foo Foo String 2");
+ cfg.addProperty("foo:text/prop:one", "Foo Prop String 1");
+ cfg.addProperty("foo:text/prop:two", "Foo Prop String 2");
+ cfg.addProperty("foo:text/base:one", "Foo Base String 1");
+ cfg.addProperty("foo:text/base:two", "Foo Base String 2");
+ cfg.addProperty("base:one", "Base Base String 1");
+ cfg.addProperty("base:two", "Base Base String 2");
+ cfg.addProperty("foo:one", "Base Foo String 1");
+ cfg.addProperty("foo:two", "Base Foo String 2");
+ cfg.addProperty("prop:one", "Base Prop String 1");
+ cfg.addProperty("prop:two", "Base Prop String 2");
+
+ model.write(System.out, "TTL");
+
+ List<String> keys = WrappedIterator.create(cfg.getKeys()).toList();
+ assertEquals(13, keys.size());
+ assertTrue(keys.toString(), keys.contains("foo:text"));
+ assertTrue(keys.toString(), keys.contains("foo:text/foo:one"));
+ assertTrue(keys.toString(), keys.contains("foo:text/foo:two"));
+ assertTrue(keys.toString(), keys.contains("foo:text/prop:one"));
+ assertTrue(keys.toString(), keys.contains("foo:text/prop:two"));
+ assertTrue(keys.toString(), keys.contains("foo:text/one"));
+ assertTrue(keys.toString(), keys.contains("foo:text/two"));
+ assertTrue(keys.toString(), keys.contains("one"));
+ assertTrue(keys.toString(), keys.contains("two"));
+ assertTrue(keys.toString(), keys.contains("foo:one"));
+ assertTrue(keys.toString(), keys.contains("foo:two"));
+ assertTrue(keys.toString(), keys.contains("prop:one"));
+ assertTrue(keys.toString(), keys.contains("prop:two"));
+
+ }
+
+ @Test
+ public void testGetKeys_subset() {
+ setPrefixes();
+
+ cfg.addProperty("foo:text/foo:one", "Foo Foo String 1");
+ cfg.addProperty("foo:text/foo:two", "Foo Foo String 2");
+ cfg.addProperty("foo:text/prop:one", "Foo Prop String 1");
+ cfg.addProperty("foo:text/prop:two", "Foo Prop String 2");
+ cfg.addProperty("foo:text/base:one", "Foo Base String 1");
+ cfg.addProperty("foo:text/base:two", "Foo Base String 2");
+ cfg.addProperty("base:one", "Base Base String 1");
+ cfg.addProperty("base:two", "Base Base String 2");
+ cfg.addProperty("foo:one", "Base Foo String 1");
+ cfg.addProperty("foo:two", "Base Foo String 2");
+ cfg.addProperty("prop:one", "Base Prop String 1");
+ cfg.addProperty("prop:two", "Base Prop String 2");
+
+ model.write(System.out, "TTL");
+
+ List<String> keys = WrappedIterator.create(cfg.getKeys("foo:text"))
+ .toList();
+ assertEquals(6, keys.size());
+ assertTrue(keys.contains("base:one"));
+ assertTrue(keys.contains("base:two"));
+ assertTrue(keys.contains("one"));
+ assertTrue(keys.contains("two"));
+ assertTrue(keys.contains("prop:one"));
+ assertTrue(keys.contains("prop:two"));
+
+ }
+
+}
Propchange: jena/Experimental/jena-commons/src/test/java/org/apache/jena/commons/configuration/RDFConfigTest.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: jena/Experimental/jena-commons/src/test/resources/org/apache/jena/commons/configuration/assembler.ttl
URL: http://svn.apache.org/viewvc/jena/Experimental/jena-commons/src/test/resources/org/apache/jena/commons/configuration/assembler.ttl?rev=1601074&view=auto
==============================================================================
--- jena/Experimental/jena-commons/src/test/resources/org/apache/jena/commons/configuration/assembler.ttl (added)
+++ jena/Experimental/jena-commons/src/test/resources/org/apache/jena/commons/configuration/assembler.ttl Sat Jun 7 07:50:07 2014
@@ -0,0 +1,48 @@
+@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
+@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
+@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
+
+@prefix ja: <http://jena.hpl.hp.com/2005/11/Assembler#> .
+@prefix sdb: <http://jena.hpl.hp.com/2007/sdb#> .
+@prefix data: <http://example/test#> .
+
+# Test assembler; An unformatted, in-memory HSQLDB store.
+
+[] ja:loadClass "com.hp.hpl.jena.sdb.SDB" .
+sdb:DatasetStore rdfs:subClassOf ja:RDFDataset .
+
+## Description: default graph of an SDB store.
+
+data:graphDft rdf:type sdb:Model ;
+ sdb:dataset <#dataset> .
+
+## Description: Named graph
+
+data:graphNamed rdf:type sdb:Model ;
+ sdb:namedGraph data:graph1 ;
+ sdb:dataset <#dataset> .
+
+## Assembler: Dataset
+
+<#dataset> rdf:type sdb:DatasetStore ;
+ sdb:store <#store> .
+
+## Assembler: store and connection
+
+<#store> rdf:type sdb:Store ;
+ sdb:layout "layout2" ;
+ sdb:connection
+ [ rdf:type sdb:SDBConnection ;
+ sdb:sdbType "hsqldb" ;
+ sdb:sdbHost "mem" ;
+ sdb:sdbUser "sa" ;
+ sdb:sdbPassword "" ;
+ sdb:sdbName "SDB2" ;
+ sdb:driver "org.hsqldb.jdbcDriver" ;
+ ]
+ .
+
+# Local Variables:
+# tab-width: 4
+# indent-tabs-mode: nil
+# End: