http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/ab15d45b/juneau-core-rdf/src/main/java/org/apache/juneau/jena/RdfCommonContext.java ---------------------------------------------------------------------- diff --git a/juneau-core-rdf/src/main/java/org/apache/juneau/jena/RdfCommonContext.java b/juneau-core-rdf/src/main/java/org/apache/juneau/jena/RdfCommonContext.java deleted file mode 100644 index ae65e23..0000000 --- a/juneau-core-rdf/src/main/java/org/apache/juneau/jena/RdfCommonContext.java +++ /dev/null @@ -1,646 +0,0 @@ -// *************************************************************************************************************************** -// * 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.juneau.jena; - -import java.util.*; - -import org.apache.juneau.jena.annotation.*; -import org.apache.juneau.utils.*; -import org.apache.juneau.xml.*; -import org.apache.juneau.xml.annotation.*; - -/** - * Configurable properties common to both the {@link RdfSerializer} and {@link RdfParser} classes. - */ -public interface RdfCommonContext { - - /** - * Maps RDF writer names to property prefixes that apply to them. - */ - final static Map<String,String> LANG_PROP_MAP = new AMap<String,String>() - .append("RDF/XML","rdfXml.") - .append("RDF/XML-ABBREV","rdfXml.") - .append("N3","n3.") - .append("N3-PP","n3.") - .append("N3-PLAIN","n3.") - .append("N3-TRIPLES","n3.") - .append("TURTLE","n3.") - .append("N-TRIPLE","ntriple."); - - /** - * <b>Configuration property:</b> RDF language. - * - * <ul> - * <li><b>Name:</b> <js>"Rdf.language"</js> - * <li><b>Data type:</b> <code>String</code> - * <li><b>Default:</b> <js>"RDF/XML-ABBREV"</js> - * </ul> - * - * <p> - * Can be any of the following: - * <ul class='spaced-list'> - * <li> - * <js>"RDF/XML"</js> - * <li> - * <js>"RDF/XML-ABBREV"</js> - * <li> - * <js>"N-TRIPLE"</js> - * <li> - * <js>"N3"</js> - General name for the N3 writer. - * Will make a decision on exactly which writer to use (pretty writer, plain writer or simple writer) when - * created. - * Default is the pretty writer but can be overridden with system property - * <code>com.hp.hpl.jena.n3.N3JenaWriter.writer</code>. - * <li> - * <js>"N3-PP"</js> - Name of the N3 pretty writer. - * The pretty writer uses a frame-like layout, with prefixing, clustering like properties and embedding - * one-referenced bNodes. - * <li> - * <js>"N3-PLAIN"</js> - Name of the N3 plain writer. - * The plain writer writes records by subject. - * <li> - * <js>"N3-TRIPLES"</js> - Name of the N3 triples writer. - * This writer writes one line per statement, like N-Triples, but does N3-style prefixing. - * <li> - * <js>"TURTLE"</js> - Turtle writer. - * http://www.dajobe.org/2004/01/turtle/ - * </ul> - */ - public static final String RDF_language = "Rdf.language"; - - /** - * <b>Configuration property:</b> XML namespace for Juneau properties. - * - * <ul> - * <li><b>Name:</b> <js>"Rdf.juneauNs"</js> - * <li><b>Data type:</b> {@link Namespace} - * <li><b>Default:</b> <code>{j:<js>'http://www.apache.org/juneau/'</js>}</code> - * </ul> - */ - public static final String RDF_juneauNs = "Rdf.juneauNs"; - - /** - * <b>Configuration property:</b> Default XML namespace for bean properties. - * - * <ul> - * <li><b>Name:</b> <js>"Rdf.juneauBpNs"</js> - * <li><b>Data type:</b> {@link Namespace} - * <li><b>Default:</b> <code>{j:<js>'http://www.apache.org/juneaubp/'</js>}</code> - * </ul> - */ - public static final String RDF_juneauBpNs = "Rdf.juneauBpNs"; - - /** - * <b>Configuration property:</b> Reuse XML namespaces when RDF namespaces not specified. - * - * <ul> - * <li><b>Name:</b> <js>"Rdf.useXmlNamespaces"</js> - * <li><b>Data type:</b> <code>Boolean</code> - * <li><b>Default:</b> <jk>true</jk> - * </ul> - * - * <p> - * When specified, namespaces defined using {@link XmlNs} and {@link Xml} will be inherited by the RDF serializers. - * Otherwise, namespaces will be defined using {@link RdfNs} and {@link Rdf}. - */ - public static final String RDF_useXmlNamespaces = "Rdf.useXmlNamespaces"; - - /** - * <b>Configuration property:</b> RDF/XML property: <code>iri_rules</code>. - * - * <ul> - * <li><b>Name:</b> <js>"Rdf.jena.rdfXml.iri-rules"</js> - * <li><b>Data type:</b> <code>String</code> - * <li><b>Default:</b> <js>"lax"</js> - * </ul> - * - * <p> - * Set the engine for checking and resolving. - * - * <p> - * Possible values: - * <ul class='spaced-list'> - * <li> - * <js>"lax"</js> - The rules for RDF URI references only, which does permit spaces although the use of spaces - * is not good practice. - * <li> - * <js>"strict"</js> - Sets the IRI engine with rules for valid IRIs, XLink and RDF; it does not permit spaces - * in IRIs. - * <li> - * <js>"iri"</js> - Sets the IRI engine to IRI - * (<a class="doclink" href="http://www.ietf.org/rfc/rfc3986.txt">RFC 3986</a>, - * <a class="doclink" href="http://www.ietf.org/rfc/rfc3987.txt">RFC 3987</a>). - * </ul> - */ - public static final String RDF_arp_iriRules = "Rdf.jena.rdfXml.iri-rules"; - - /** - * <b>Configuration property:</b> RDF/XML ARP property: <code>error-mode</code>. - * - * <ul> - * <li><b>Name:</b> <js>"Rdf.jena.rdfXml.error-mode"</js> - * <li><b>Data type:</b> <code>String</code> - * <li><b>Default:</b> <js>"lax"</js> - * </ul> - * - * <p> - * This allows a coarse-grained approach to control of error handling. - * - * <p> - * Possible values: - * <ul> - * <li><js>"default"</js> - * <li><js>"lax"</js> - * <li><js>"strict"</js> - * <li><js>"strict-ignore"</js> - * <li><js>"strict-warning"</js> - * <li><js>"strict-error"</js> - * <li><js>"strict-fatal"</js> - * </ul> - * - * <p> - * See also: - * <ul class='spaced-list'> - * <li> - * <a class="doclink" href="http://jena.sourceforge.net/javadoc/com/hp/hpl/jena/rdf/arp/ARPOptions.html#setDefaultErrorMode()">ARPOptions.setDefaultErrorMode()</a> - * <li> - * <a class="doclink" href="http://jena.sourceforge.net/javadoc/com/hp/hpl/jena/rdf/arp/ARPOptions.html#setLaxErrorMode()">ARPOptions.setLaxErrorMode()</a> - * <li> - * <a class="doclink" href="http://jena.sourceforge.net/javadoc/com/hp/hpl/jena/rdf/arp/ARPOptions.html#setStrictErrorMode()">ARPOptions.setStrictErrorMode()</a> - * <li> - * <a class="doclink" href="http://jena.sourceforge.net/javadoc/com/hp/hpl/jena/rdf/arp/ARPOptions.html#setStrictErrorMode(int)">ARPOptions.setStrictErrorMode(int)</a> - * </ul> - */ - public static final String RDF_arp_errorMode = "Rdf.jena.rdfXml.error-mode"; - - /** - * <b>Configuration property:</b> RDF/XML ARP property: <code>embedding</code>. - * - * <ul> - * <li><b>Name:</b> <js>"Rdf.jena.rdfXml.embedding"</js> - * <li><b>Data type:</b> <code>Boolean</code> - * <li><b>Default:</b> <jk>false</jk> - * </ul> - * - * <p> - * Sets ARP to look for RDF embedded within an enclosing XML document. - * - * <p> - * See also: - * <ul class='spaced-list'> - * <li> - * <a class="doclink" href="http://jena.sourceforge.net/javadoc/com/hp/hpl/jena/rdf/arp/ARPOptions.html#setEmbedding(boolean)">ARPOptions.setEmbedding(boolean)</a> - * </ul> - */ - public static final String RDF_arp_embedding = "Rdf.jena.rdfXml.embedding"; - - /** - * <b>Configuration property:</b> RDF/XML ARP property: <code>ERR_xxx</code>. - * - * <ul> - * <li><b>Name:</b> <js>"Rdf.jena.rdfXml.ERR_"</js> - * <li><b>Data type:</b> <code>String</code> - * </ul> - * - * <p> - * Provides fine-grained control over detected error conditions. - * - * <p> - * Possible values: - * <ul> - * <li><js>"EM_IGNORE"</js> - * <li><js>"EM_WARNING"</js> - * <li><js>"EM_ERROR"</js> - * <li><js>"EM_FATAL"</js> - * </ul> - * - * <p> - * See also: - * <ul class='spaced-list'> - * <li> - * <a class="doclink" href="http://jena.sourceforge.net/javadoc/com/hp/hpl/jena/rdf/arp/ARPErrorNumbers.html">ARPErrorNumbers</a> - * <li> - * <a class="doclink" href="http://jena.sourceforge.net/javadoc/com/hp/hpl/jena/rdf/arp/ARPOptions.html#setErrorMode(int,%20int)">ARPOptions.setErrorMode(int, int)</a> - * </ul> - */ - public static final String RDF_arp_err_ = "Rdf.jena.rdfXml.ERR_"; - - /** - * <b>Configuration property:</b> RDF/XML ARP property: <code>WARN_xxx</code>. - * - * <ul> - * <li><b>Name:</b> <js>"Rdf.jena.rdfXml.WARN_"</js> - * <li><b>Data type:</b> <code>String</code> - * </ul> - * - * <p> - * See {@link #RDF_arp_err_} for details. - */ - public static final String RDF_arp_warn_ = "Rdf.jena.rdfXml.WARN_"; - - /** - * RDF/XML ARP property: <code>IGN_xxx</code>. - * - * <ul> - * <li><b>Name:</b> <js>"Rdf.jena.rdfXml.IGN_"</js> - * <li><b>Data type:</b> <code>String</code> - * </ul> - * - * <p> - * See {@link #RDF_arp_err_} for details. - */ - public static final String RDF_arp_ign_ = "Rdf.jena.rdfXml.IGN_"; - - /** - * <b>Configuration property:</b> RDF/XML property: <code>xmlbase</code>. - * - * <ul> - * <li><b>Name:</b> <js>"Rdf.jena.rdfXml.xmlbase"</js> - * <li><b>Data type:</b> <code>String</code> - * <li><b>Default:</b> <jk>null</jk> - * </ul> - * - * <p> - * The value to be included for an <xa>xml:base</xa> attribute on the root element in the file. - */ - public static final String RDF_rdfxml_xmlBase = "Rdf.jena.rdfXml.xmlbase"; - - /** - * <b>Configuration property:</b> RDF/XML property: <code>longId</code>. - * - * <ul> - * <li><b>Name:</b> <js>"Rdf.jena.rdfXml.longId"</js> - * <li><b>Data type:</b> <code>Boolean</code> - * <li><b>Default:</b> <jk>false</jk> - * </ul> - * - * <p> - * Whether to use long ID's for anon resources. - * Short ID's are easier to read, but can run out of memory on very large models. - */ - public static final String RDF_rdfxml_longId = "Rdf.jena.rdfXml.longId"; - - /** - * <b>Configuration property:</b> RDF/XML property: <code>allowBadURIs</code>. - * - * <ul> - * <li><b>Name:</b> <js>"Rdf.jena.rdfXml.allowBadURIs"</js> - * <li><b>Data type:</b> <code>Boolean</code> - * <li><b>Default:</b> <jk>false</jk> - * </ul> - * - * <p> - * URIs in the graph are, by default, checked prior to serialization. - */ - public static final String RDF_rdfxml_allowBadUris = "Rdf.jena.rdfXml.allowBadURIs"; - - /** - * <b>Configuration property:</b> RDF/XML property: <code>relativeURIs</code>. - * - * <ul> - * <li><b>Name:</b> <js>"Rdf.jena.rdfXml.relativeURIs"</js> - * <li><b>Data type:</b> <code>String</code> - * <li><b>Default:</b> <js>"same-document, absolute, relative, parent"</js> - * </ul> - * - * <p> - * What sort of relative URIs should be used. - * - * <p> - * A comma separate list of options: - * <ul class='spaced-list'> - * <li> - * <js>"same-document"</js> - Same-document references (e.g. <js>""</js> or <js>"#foo"</js>) - * <li> - * <js>"network"</js> - Network paths (e.g. <js>"//example.org/foo"</js> omitting the URI scheme) - * <li> - * <js>"absolute"</js> - Absolute paths (e.g. <js>"/foo"</js> omitting the scheme and authority) - * <li> - * <js>"relative"</js> - Relative path not beginning in <js>"../"</js> - * <li> - * <js>"parent"</js> - Relative path beginning in <js>"../"</js> - * <li> - * <js>"grandparent"</js> - Relative path beginning in <js>"../../"</js> - * </ul> - * - * <p> - * The default value is <js>"same-document, absolute, relative, parent"</js>. - * To switch off relative URIs use the value <js>""</js>. - * Relative URIs of any of these types are output where possible if and only if the option has been specified. - */ - public static final String RDF_rdfxml_relativeUris = "Rdf.jena.rdfXml.relativeURIs"; - - /** - * <b>Configuration property:</b> RDF/XML property: <code>showXmlDeclaration</code>. - * - * <ul> - * <li><b>Name:</b> <js>"Rdf.jena.rdfXml.showXmlDeclaration"</js> - * <li><b>Data type:</b> <code>String</code> - * <li><b>Default:</b> <js>"default"</js> - * </ul> - * - * <p> - * Possible values: - * <ul class='spaced-list'> - * <li> - * <js>"true"</js> - Add XML Declaration to the output. - * <li> - * <js>"false"</js> - Don't add XML Declaration to the output. - * <li> - * <js>"default"</js> - Only add an XML Declaration when asked to write to an <code>OutputStreamWriter</code> - * that uses some encoding other than <code>UTF-8</code> or <code>UTF-16</code>. - * In this case the encoding is shown in the XML declaration. - * </ul> - */ - public static final String RDF_rdfxml_showXmlDeclaration = "Rdf.jena.rdfXml.showXmlDeclaration"; - - /** - * <b>Configuration property:</b> RDF/XML property: <code>showDoctypeDeclaration</code>. - * - * <ul> - * <li><b>Name:</b> <js>"Rdf.jena.rdfXml.showDoctypeDeclaration"</js> - * <li><b>Data type:</b> <code>Boolean</code> - * <li><b>Default:</b> <jk>true</jk> - * </ul> - * - * <p> - * If true, an XML doctype declaration is included in the output. - * This declaration includes a <code>!ENTITY</code> declaration for each prefix mapping in the model, and any - * attribute value that starts with the URI of that mapping is written as starting with the corresponding entity - * invocation. - */ - public static final String RDF_rdfxml_showDoctypeDeclaration = "Rdf.jena.rdfXml.showDoctypeDeclaration"; - - /** - * <b>Configuration property:</b> RDF/XML property: <code>tab</code>. - * - * <ul> - * <li><b>Name:</b> <js>"Rdf.jena.rdfXml.tab"</js> - * <li><b>Data type:</b> <code>Integer</code> - * <li><b>Default:</b> <code>2</code> - * </ul> - * - * <p> - * The number of spaces with which to indent XML child elements. - */ - public static final String RDF_rdfxml_tab = "Rdf.jena.rdfXml.tab"; - - /** - * <b>Configuration property:</b> RDF/XML property: <code>attributeQuoteChar</code>. - * - * <ul> - * <li><b>Name:</b> <js>"Rdf.jena.rdfXml.attributeQuoteChar"</js> - * <li><b>Data type:</b> <code>Character</code> - * <li><b>Default:</b> <js>'"'</js> - * </ul> - * - * <p> - * The XML attribute quote character. - */ - public static final String RDF_rdfxml_attributeQuoteChar = "Rdf.jena.rdfXml.attributeQuoteChar"; - - /** - * <b>Configuration property:</b> RDF/XML property: <code>blockRules</code>. - * - * <ul> - * <li><b>Name:</b> <js>"Rdf.jena.rdfXml.blockRules"</js> - * <li><b>Data type:</b> <code>String</code> - * <li><b>Default:</b> <js>""</js> - * </ul> - * - * <p> - * A list of <code>Resource</code> or a <code>String</code> being a comma separated list of fragment IDs from - * <a class="doclink" href="http://www.w3.org/TR/rdf-syntax-grammar">RDF Syntax Grammar</a> indicating grammar - * rules that will not be used. - */ - public static final String RDF_rdfxml_blockRules = "Rdf.jena.rdfXml.blockRules"; - - /** - * <b>Configuration property:</b> N3/Turtle property: <code>minGap</code>. - * - * <ul> - * <li><b>Name:</b> <js>"Rdf.jena.n3.minGap"</js> - * <li><b>Data type:</b> <code>Integer</code> - * <li><b>Default:</b> <code>1</code> - * </ul> - * - * <p> - * Minimum gap between items on a line. - */ - public static final String RDF_n3_minGap = "Rdf.jena.n3.minGap"; - - /** - * <b>Configuration property:</b> N3/Turtle property: <code>objectLists</code>. - * - * <ul> - * <li><b>Name:</b> <js>"Rdf.jena.n3.objectLists"</js> - * <li><b>Data type:</b> <code>Boolean</code> - * <li><b>Default:</b> <jk>true</jk> - * </ul> - * - * <p> - * Print object lists as comma separated lists. - */ - public static final String RDF_n3_objectLists = "Rdf.jena.n3.objectLists"; - - /** - * <b>Configuration property:</b> N3/Turtle property: <code>subjectColumn</code>. - * - * <ul> - * <li><b>Name:</b> <js>"Rdf.jena.n3.subjectColumn"</js> - * <li><b>Data type:</b> <code>Integer</code> - * <li><b>Default:</b> indentProperty - * </ul> - * - * <p> - * If the subject is shorter than this value, the first property may go on the same line. - */ - public static final String RDF_n3_subjectColumn = "Rdf.jena.n3.subjectColumn"; - - /** - * <b>Configuration property:</b> N3/Turtle property: <code>propertyColumn</code>. - * - * <ul> - * <li><b>Name:</b> <js>"Rdf.jena.n3.propertyColumn"</js> - * <li><b>Data type:</b> <code>Integer</code> - * <li><b>Default:</b> <code>8</code> - * </ul> - * - * <p> - * Width of the property column. - */ - public static final String RDF_n3_propertyColumn = "Rdf.jena.n3.propertyColumn"; - - /** - * <b>Configuration property:</b> N3/Turtle property: <code>indentProperty</code>. - * - * <ul> - * <li><b>Name:</b> <js>"Rdf.jena.n3.indentProperty"</js> - * <li><b>Data type:</b> <code>Integer</code> - * <li><b>Default:</b> <code>6</code> - * </ul> - * - * <p> - * Width to indent properties. - */ - public static final String RDF_n3_indentProperty = "Rdf.jena.n3.indentProperty"; - - /** - * <b>Configuration property:</b> N3/Turtle property: <code>widePropertyLen</code>. - * - * <ul> - * <li><b>Name:</b> <js>"Rdf.jena.n3.widePropertyLen"</js> - * <li><b>Data type:</b> <code>Integer</code> - * <li><b>Default:</b> <code>20</code> - * </ul> - * - * <p> - * Width of the property column. - * Must be longer than <code>propertyColumn</code>. - */ - public static final String RDF_n3_widePropertyLen = "Rdf.jena.n3.widePropertyLen"; - - /** - * <b>Configuration property:</b> N3/Turtle property: <code>abbrevBaseURI</code>. - * - * <ul> - * <li><b>Name:</b> <js>"Rdf.jena.n3.abbrevBaseURI"</js> - * <li><b>Data type:</b> <code>Boolean</code> - * <li><b>Default:</b> <jk>true</jk> - * </ul> - * - * <p> - * Control whether to use abbreviations <code><></code> or <code><#></code>. - */ - public static final String RDF_n3_abbrevBaseUri = "Rdf.jena.n3.abbrevBaseURI"; - - /** - * <b>Configuration property:</b> N3/Turtle property: <code>usePropertySymbols</code>. - * - * <ul> - * <li><b>Name:</b> <js>"Rdf.jena.n3.usePropertySymbols"</js> - * <li><b>Data type:</b> <code>Boolean</code> - * <li><b>Default:</b> <jk>true</jk> - * </ul> - * - * <p> - * Control whether to use <code>a</code>, <code>=</code> and <code>=></code> in output - */ - public static final String RDF_n3_usePropertySymbols = "Rdf.jena.n3.usePropertySymbols"; - - /** - * <b>Configuration property:</b> N3/Turtle property: <code>useTripleQuotedStrings</code>. - * - * <ul> - * <li><b>Name:</b> <js>"Rdf.jena.n3.useTripleQuotedStrings"</js> - * <li><b>Data type:</b> <code>Boolean</code> - * <li><b>Default:</b> <jk>true</jk> - * </ul> - * - * <p> - * Allow the use of <code>"""</code> to delimit long strings. - */ - public static final String RDF_n3_useTripleQuotedStrings = "Rdf.jena.n3.useTripleQuotedStrings"; - - /** - * <b>Configuration property:</b> N3/Turtle property: <code>useDoubles</code>. - * - * <ul> - * <li><b>Name:</b> <js>"Rdf.jena.n3.useDoubles"</js> - * <li><b>Data type:</b> <code>Boolean</code> - * <li><b>Default:</b> <jk>true</jk> - * </ul> - * - * <p> - * Allow the use doubles as <code>123.456</code>. - */ - public static final String RDF_n3_useDoubles = "Rdf.jena.n3.useDoubles"; - - /** - * <b>Configuration property:</b> RDF format for representing collections and arrays. - * - * <ul> - * <li><b>Name:</b> <js>"Rdf.collectionFormat"</js> - * <li><b>Data type:</b> <code>String</code> - * <li><b>Default:</b> <js>"DEFAULT"</js> - * </ul> - * - * <p> - * Possible values: - * <ul class='spaced-list'> - * <li> - * <js>"DEFAULT"</js> - Default format. The default is an RDF Sequence container. - * <li> - * <js>"SEQ"</js> - RDF Sequence container. - * <li> - * <js>"BAG"</js> - RDF Bag container. - * <li> - * <js>"LIST"</js> - RDF List container. - * <li> - * <js>"MULTI_VALUED"</js> - Multi-valued properties. - * </ul> - * - * <h5 class='section'>Notes:</h5> - * <ul> - * <li>If you use <js>"BAG"</js> or <js>"MULTI_VALUED"</js>, the order of the elements in the collection will get - * lost. - * </ul> - */ - public static final String RDF_collectionFormat = "Rdf.collectionFormat"; - - /** - * <b>Configuration property:</b> Collections should be serialized and parsed as loose collections. - * - * <ul> - * <li><b>Name:</b> <js>"Rdf.looseCollections"</js> - * <li><b>Data type:</b> <code>Boolean</code> - * <li><b>Default:</b> <jk>false</jk> - * </ul> - * - * <p> - * When specified, collections of resources are handled as loose collections of resources in RDF instead of - * resources that are children of an RDF collection (e.g. Sequence, Bag). - * - * <p> - * Note that this setting is specialized for RDF syntax, and is incompatible with the concept of - * losslessly representing POJO models, since the tree structure of these POJO models are lost - * when serialized as loose collections. - * - * <p> - * This setting is typically only useful if the beans being parsed into do not have a bean property - * annotated with {@link Rdf#beanUri @Rdf(beanUri=true)}. - * - * <h5 class='section'>Example:</h5> - * <p class='bcode'> - * WriterSerializer s = <jk>new</jk> RdfSerializerBuilder().xmlabbrev().looseCollections(<jk>true</jk>).build(); - * ReaderParser p = <jk>new</jk> RdfParserBuilder().xml().looseCollections(<jk>true</jk>).build(); - * - * List<MyBean> l = createListOfMyBeans(); - * - * <jc>// Serialize to RDF/XML as loose resources</jc> - * String rdfXml = s.serialize(l); - * - * <jc>// Parse back into a Java collection</jc> - * l = p.parse(rdfXml, LinkedList.<jk>class</jk>, MyBean.<jk>class</jk>); - * - * MyBean[] b = createArrayOfMyBeans(); - * - * <jc>// Serialize to RDF/XML as loose resources</jc> - * String rdfXml = s.serialize(b); - * - * <jc>// Parse back into a bean array</jc> - * b = p.parse(rdfXml, MyBean[].<jk>class</jk>); - * </p> - */ - public static final String RDF_looseCollections = "Rdf.looseCollections"; -}
http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/ab15d45b/juneau-core-rdf/src/main/java/org/apache/juneau/jena/RdfParser.java ---------------------------------------------------------------------- diff --git a/juneau-core-rdf/src/main/java/org/apache/juneau/jena/RdfParser.java b/juneau-core-rdf/src/main/java/org/apache/juneau/jena/RdfParser.java deleted file mode 100644 index a94c123..0000000 --- a/juneau-core-rdf/src/main/java/org/apache/juneau/jena/RdfParser.java +++ /dev/null @@ -1,137 +0,0 @@ -// *************************************************************************************************************************** -// * 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.juneau.jena; - -import static org.apache.juneau.jena.Constants.*; -import static org.apache.juneau.jena.RdfCommonContext.*; - -import org.apache.juneau.*; -import org.apache.juneau.parser.*; - -/** - * Parses RDF into POJOs. - * - * <h5 class='section'>Configurable properties:</h5> - * - * Refer to <a class="doclink" href="package-summary.html#ParserConfigurableProperties">Configurable Properties</a> - * for the entire list of configurable properties. - * - * <h6 class='topic'>Behavior-specific subclasses</h6> - * - * The following direct subclasses are provided for language-specific parsers: - * <ul class='spaced-list'> - * <li> - * {@link RdfParser.Xml} - RDF/XML and RDF/XML-ABBREV. - * <li> - * {@link RdfParser.NTriple} - N-TRIPLE. - * <li> - * {@link RdfParser.Turtle} - TURTLE. - * <li> - * {@link RdfParser.N3} - N3. - * </ul> - * - * <h5 class='section'>Additional information:</h5> - * - * See <a class="doclink" href="package-summary.html#TOC">RDF Overview</a> for an overview of RDF support in Juneau. - */ -public class RdfParser extends ReaderParser { - - /** Default XML parser, all default settings.*/ - public static final RdfParser DEFAULT_XML = new Xml(PropertyStore.create()); - - /** Default Turtle parser, all default settings.*/ - public static final RdfParser DEFAULT_TURTLE = new Turtle(PropertyStore.create()); - - /** Default N-Triple parser, all default settings.*/ - public static final RdfParser DEFAULT_NTRIPLE = new NTriple(PropertyStore.create()); - - /** Default N3 parser, all default settings.*/ - public static final RdfParser DEFAULT_N3 = new N3(PropertyStore.create()); - - - /** Consumes RDF/XML input */ - public static class Xml extends RdfParser { - - /** - * Constructor. - * - * @param propertyStore The property store containing all the settings for this object. - */ - public Xml(PropertyStore propertyStore) { - super(propertyStore.copy().append(RDF_language, LANG_RDF_XML), "text/xml+rdf"); - } - } - - /** Consumes N-Triple input */ - public static class NTriple extends RdfParser { - - /** - * Constructor. - * - * @param propertyStore The property store containing all the settings for this object. - */ - public NTriple(PropertyStore propertyStore) { - super(propertyStore.copy().append(RDF_language, LANG_NTRIPLE), "text/n-triple"); - } - } - - /** Consumes Turtle input */ - public static class Turtle extends RdfParser { - - /** - * Constructor. - * - * @param propertyStore The property store containing all the settings for this object. - */ - public Turtle(PropertyStore propertyStore) { - super(propertyStore.copy().append(RDF_language, LANG_TURTLE), "text/turtle"); - } - } - - /** Consumes N3 input */ - public static class N3 extends RdfParser { - - /** - * Constructor. - * - * @param propertyStore The property store containing all the settings for this object. - */ - public N3(PropertyStore propertyStore) { - super(propertyStore.copy().append(RDF_language, LANG_N3), "text/n3"); - } - } - - - private final RdfParserContext ctx; - - /** - * Constructor. - * - * @param propertyStore The property store containing all the settings for this object. - * @param consumes The list of media types that this parser consumes (e.g. <js>"application/json"</js>). - */ - public RdfParser(PropertyStore propertyStore, String...consumes) { - super(propertyStore, consumes); - this.ctx = createContext(RdfParserContext.class); - } - - @Override /* CoreObject */ - public RdfParserBuilder builder() { - return new RdfParserBuilder(propertyStore); - } - - @Override /* Parser */ - public ReaderParserSession createSession(ParserSessionArgs args) { - return new RdfParserSession(ctx, args); - } -} http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/ab15d45b/juneau-core-rdf/src/main/java/org/apache/juneau/jena/RdfParserBuilder.java ---------------------------------------------------------------------- diff --git a/juneau-core-rdf/src/main/java/org/apache/juneau/jena/RdfParserBuilder.java b/juneau-core-rdf/src/main/java/org/apache/juneau/jena/RdfParserBuilder.java deleted file mode 100644 index 095d45a..0000000 --- a/juneau-core-rdf/src/main/java/org/apache/juneau/jena/RdfParserBuilder.java +++ /dev/null @@ -1,765 +0,0 @@ -// *************************************************************************************************************************** -// * 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.juneau.jena; - -import static org.apache.juneau.jena.RdfCommonContext.*; -import static org.apache.juneau.jena.RdfParserContext.*; - -import java.util.*; - -import org.apache.juneau.*; -import org.apache.juneau.http.*; -import org.apache.juneau.jena.annotation.*; -import org.apache.juneau.parser.*; -import org.apache.juneau.xml.*; -import org.apache.juneau.xml.annotation.*; - -/** - * Builder class for building instances of RDF parsers. - */ -public class RdfParserBuilder extends ParserBuilder { - - /** - * Constructor, default settings. - */ - public RdfParserBuilder() { - super(); - } - - /** - * Constructor. - * - * @param propertyStore The initial configuration settings for this builder. - */ - public RdfParserBuilder(PropertyStore propertyStore) { - super(propertyStore); - } - - @Override /* CoreObjectBuilder */ - public RdfParser build() { - return new RdfParser(propertyStore, "text/xml+rdf"); - } - - - //-------------------------------------------------------------------------------- - // Properties - //-------------------------------------------------------------------------------- - - /** - * <b>Configuration property:</b> Trim whitespace from text elements. - * - * <ul> - * <li><b>Name:</b> <js>"RdfParser.trimWhitespace"</js> - * <li><b>Data type:</b> <code>Boolean</code> - * <li><b>Default:</b> <jk>false</jk> - * <li><b>Session-overridable:</b> <jk>true</jk> - * </ul> - * - * <p> - * If <jk>true</jk>, whitespace in text elements will be automatically trimmed. - * - * <h5 class='section'>Notes:</h5> - * <ul> - * <li>This is equivalent to calling <code>property(<jsf>RDF_trimWhitespace</jsf>, value)</code>. - * </ul> - * - * @param value The new value for this property. - * @return This object (for method chaining). - * @see RdfParserContext#RDF_trimWhitespace - */ - public RdfParserBuilder trimWhitespace(boolean value) { - return property(RDF_trimWhitespace, value); - } - - /** - * <b>Configuration property:</b> RDF language. - * - * <ul> - * <li><b>Name:</b> <js>"Rdf.language"</js> - * <li><b>Data type:</b> <code>String</code> - * <li><b>Default:</b> <js>"RDF/XML-ABBREV"</js> - * </ul> - * - * <p> - * Can be any of the following: - * <ul class='spaced-list'> - * <li> - * <js>"RDF/XML"</js> - * <li> - * <js>"RDF/XML-ABBREV"</js> - * <li> - * <js>"N-TRIPLE"</js> - * <li> - * <js>"N3"</js> - General name for the N3 writer. - * Will make a decision on exactly which writer to use (pretty writer, plain writer or simple writer) when - * created. - * Default is the pretty writer but can be overridden with system property - * <code>com.hp.hpl.jena.n3.N3JenaWriter.writer</code>. - * <li> - * <js>"N3-PP"</js> - Name of the N3 pretty writer. - * The pretty writer uses a frame-like layout, with prefixing, clustering like properties and embedding - * one-referenced bNodes. - * <li> - * <js>"N3-PLAIN"</js> - Name of the N3 plain writer. - * The plain writer writes records by subject. - * <li> - * <js>"N3-TRIPLES"</js> - Name of the N3 triples writer. - * This writer writes one line per statement, like N-Triples, but does N3-style prefixing. - * <li> - * <js>"TURTLE"</js> - Turtle writer. - * http://www.dajobe.org/2004/01/turtle/ - * </ul> - * - * <h5 class='section'>Notes:</h5> - * <ul> - * <li>This is equivalent to calling <code>property(<jsf>RDF_language</jsf>, value)</code>. - * </ul> - * - * @param value The new value for this property. - * @return This object (for method chaining). - * @see RdfParserContext#RDF_language - */ - public RdfParserBuilder language(String value) { - return property(RDF_language, value); - } - - /** - * Shortcut for calling <code>language(<jsf>LANG_RDF_XML</jsf>)</code> - * - * @return This object (for method chaining). - */ - public RdfParserBuilder xml() { - return language(Constants.LANG_RDF_XML); - } - - /** - * Shortcut for calling <code>language(<jsf>LANG_RDF_XML_ABBREV</jsf>)</code> - * - * @return This object (for method chaining). - */ - public RdfParserBuilder xmlabbrev() { - return language(Constants.LANG_RDF_XML_ABBREV); - } - - /** - * Shortcut for calling <code>language(<jsf>LANG_NTRIPLE</jsf>)</code> - * - * @return This object (for method chaining). - */ - public RdfParserBuilder ntriple() { - return language(Constants.LANG_NTRIPLE); - } - - /** - * Shortcut for calling <code>language(<jsf>LANG_N3</jsf>)</code> - * - * @return This object (for method chaining). - */ - public RdfParserBuilder n3() { - return language(Constants.LANG_N3); - } - - /** - * Shortcut for calling <code>language(<jsf>LANG_TURTLE</jsf>)</code> - * - * @return This object (for method chaining). - */ - public RdfParserBuilder turtle() { - return language(Constants.LANG_TURTLE); - } - - /** - * <b>Configuration property:</b> XML namespace for Juneau properties. - * - * <ul> - * <li><b>Name:</b> <js>"Rdf.juneauNs"</js> - * <li><b>Data type:</b> {@link Namespace} - * <li><b>Default:</b> <code>{j:<js>'http://www.apache.org/juneau/'</js>}</code> - * </ul> - * - * <h5 class='section'>Notes:</h5> - * <ul> - * <li>This is equivalent to calling <code>property(<jsf>RDF_juneauNs</jsf>, value)</code>. - * </ul> - * - * @param value The new value for this property. - * @return This object (for method chaining). - * @see RdfParserContext#RDF_juneauNs - */ - public RdfParserBuilder juneauNs(Namespace value) { - return property(RDF_juneauNs, value); - } - - /** - * <b>Configuration property:</b> Default XML namespace for bean properties. - * - * <ul> - * <li><b>Name:</b> <js>"Rdf.juneauBpNs"</js> - * <li><b>Data type:</b> {@link Namespace} - * <li><b>Default:</b> <code>{j:<js>'http://www.apache.org/juneaubp/'</js>}</code> - * </ul> - * - * <h5 class='section'>Notes:</h5> - * <ul> - * <li>This is equivalent to calling <code>property(<jsf>RDF_juneauBpNs</jsf>, value)</code>. - * </ul> - * - * @param value The new value for this property. - * @return This object (for method chaining). - * @see RdfParserContext#RDF_juneauBpNs - */ - public RdfParserBuilder juneauBpNs(Namespace value) { - return property(RDF_juneauBpNs, value); - } - - /** - * <b>Configuration property:</b> Reuse XML namespaces when RDF namespaces not specified. - * - * <ul> - * <li><b>Name:</b> <js>"Rdf.useXmlNamespaces"</js> - * <li><b>Data type:</b> <code>Boolean</code> - * <li><b>Default:</b> <jk>true</jk> - * </ul> - * - * <p> - * When specified, namespaces defined using {@link XmlNs} and {@link Xml} will be inherited by the RDF parsers. - * Otherwise, namespaces will be defined using {@link RdfNs} and {@link Rdf}. - * - * <h5 class='section'>Notes:</h5> - * <ul> - * <li>This is equivalent to calling <code>property(<jsf>RDF_useXmlNamespaces</jsf>, value)</code>. - * </ul> - * - * @param value The new value for this property. - * @return This object (for method chaining). - * @see RdfParserContext#RDF_useXmlNamespaces - */ - public RdfParserBuilder useXmlNamespaces(boolean value) { - return property(RDF_useXmlNamespaces, value); - } - - /** - * <b>Configuration property:</b> RDF format for representing collections and arrays. - * - * <ul> - * <li><b>Name:</b> <js>"Rdf.collectionFormat"</js> - * <li><b>Data type:</b> <code>RdfCollectionFormat</code> - * <li><b>Default:</b> <js>"DEFAULT"</js> - * </ul> - * - * <p> - * Possible values: - * <ul class='spaced-list'> - * <li> - * <js>"DEFAULT"</js> - Default format. The default is an RDF Sequence container. - * <li> - * <js>"SEQ"</js> - RDF Sequence container. - * <li> - * <js>"BAG"</js> - RDF Bag container. - * <li> - * <js>"LIST"</js> - RDF List container. - * <li> - * <js>"MULTI_VALUED"</js> - Multi-valued properties. - * </ul> - * - * <h5 class='section'>Notes:</h5> - * <ul> - * <li>If you use <js>"BAG"</js> or <js>"MULTI_VALUED"</js>, the order of the elements in the collection will get - * lost. - * </ul> - * - * <h5 class='section'>Notes:</h5> - * <ul> - * <li>This is equivalent to calling <code>property(<jsf>RDF_collectionFormat</jsf>, value)</code>. - * <li>This introduces a slight performance penalty. - * </ul> - * - * @param value The new value for this property. - * @return This object (for method chaining). - * @see RdfCommonContext#RDF_collectionFormat - */ - public RdfParserBuilder collectionFormat(RdfCollectionFormat value) { - return property(RDF_collectionFormat, value); - } - - /** - * <b>Configuration property:</b> Collections should be serialized and parsed as loose collections. - * - * <ul> - * <li><b>Name:</b> <js>"Rdf.looseCollections"</js> - * <li><b>Data type:</b> <code>Boolean</code> - * <li><b>Default:</b> <jk>false</jk> - * </ul> - * - * <p> - * When specified, collections of resources are handled as loose collections of resources in RDF instead of - * resources that are children of an RDF collection (e.g. Sequence, Bag). - * - * <p> - * Note that this setting is specialized for RDF syntax, and is incompatible with the concept of - * losslessly representing POJO models, since the tree structure of these POJO models are lost - * when serialized as loose collections. - * - * <p> - * This setting is typically only useful if the beans being parsed into do not have a bean property - * annotated with {@link Rdf#beanUri @Rdf(beanUri=true)}. - * - * <h5 class='section'>Example:</h5> - * <p class='bcode'> - * WriterSerializer s = <jk>new</jk> RdfSerializerBuilder().xmlabbrev().looseCollections(<jk>true</jk>).build(); - * ReaderParser p = <jk>new</jk> RdfParserBuilder().xml().looseCollections(<jk>true</jk>).build(); - * - * List<MyBean> l = createListOfMyBeans(); - * - * <jc>// Serialize to RDF/XML as loose resources</jc> - * String rdfXml = s.serialize(l); - * - * <jc>// Parse back into a Java collection</jc> - * l = p.parse(rdfXml, LinkedList.<jk>class</jk>, MyBean.<jk>class</jk>); - * - * MyBean[] b = createArrayOfMyBeans(); - * - * <jc>// Serialize to RDF/XML as loose resources</jc> - * String rdfXml = s.serialize(b); - * - * <jc>// Parse back into a bean array</jc> - * b = p.parse(rdfXml, MyBean[].<jk>class</jk>); - * </p> - * - * <h5 class='section'>Notes:</h5> - * <ul> - * <li>This is equivalent to calling <code>property(<jsf>RDF_looseCollections</jsf>, value)</code>. - * </ul> - * - * @param value The new value for this property. - * @return This object (for method chaining). - * @see RdfCommonContext#RDF_looseCollections - */ - public RdfParserBuilder looseCollections(boolean value) { - return property(RDF_looseCollections, value); - } - - @Override /* ParserBuilder */ - public RdfParserBuilder trimStrings(boolean value) { - super.trimStrings(value); - return this; - } - - @Override /* ParserBuilder */ - public RdfParserBuilder strict(boolean value) { - super.strict(value); - return this; - } - - @Override /* ParserBuilder */ - public RdfParserBuilder strict() { - super.strict(); - return this; - } - - @Override /* ParserBuilder */ - public RdfParserBuilder inputStreamCharset(String value) { - super.inputStreamCharset(value); - return this; - } - - @Override /* ParserBuilder */ - public RdfParserBuilder fileCharset(String value) { - super.fileCharset(value); - return this; - } - - @Override /* ParserBuilder */ - public RdfParserBuilder listener(Class<? extends ParserListener> value) { - super.listener(value); - return this; - } - - @Override /* CoreObjectBuilder */ - public RdfParserBuilder beansRequireDefaultConstructor(boolean value) { - super.beansRequireDefaultConstructor(value); - return this; - } - - @Override /* CoreObjectBuilder */ - public RdfParserBuilder beansRequireSerializable(boolean value) { - super.beansRequireSerializable(value); - return this; - } - - @Override /* CoreObjectBuilder */ - public RdfParserBuilder beansRequireSettersForGetters(boolean value) { - super.beansRequireSettersForGetters(value); - return this; - } - - @Override /* CoreObjectBuilder */ - public RdfParserBuilder beansRequireSomeProperties(boolean value) { - super.beansRequireSomeProperties(value); - return this; - } - - @Override /* CoreObjectBuilder */ - public RdfParserBuilder beanMapPutReturnsOldValue(boolean value) { - super.beanMapPutReturnsOldValue(value); - return this; - } - - @Override /* CoreObjectBuilder */ - public RdfParserBuilder beanConstructorVisibility(Visibility value) { - super.beanConstructorVisibility(value); - return this; - } - - @Override /* CoreObjectBuilder */ - public RdfParserBuilder beanClassVisibility(Visibility value) { - super.beanClassVisibility(value); - return this; - } - - @Override /* CoreObjectBuilder */ - public RdfParserBuilder beanFieldVisibility(Visibility value) { - super.beanFieldVisibility(value); - return this; - } - - @Override /* CoreObjectBuilder */ - public RdfParserBuilder methodVisibility(Visibility value) { - super.methodVisibility(value); - return this; - } - - @Override /* CoreObjectBuilder */ - public RdfParserBuilder useJavaBeanIntrospector(boolean value) { - super.useJavaBeanIntrospector(value); - return this; - } - - @Override /* CoreObjectBuilder */ - public RdfParserBuilder useInterfaceProxies(boolean value) { - super.useInterfaceProxies(value); - return this; - } - - @Override /* CoreObjectBuilder */ - public RdfParserBuilder ignoreUnknownBeanProperties(boolean value) { - super.ignoreUnknownBeanProperties(value); - return this; - } - - @Override /* CoreObjectBuilder */ - public RdfParserBuilder ignoreUnknownNullBeanProperties(boolean value) { - super.ignoreUnknownNullBeanProperties(value); - return this; - } - - @Override /* CoreObjectBuilder */ - public RdfParserBuilder ignorePropertiesWithoutSetters(boolean value) { - super.ignorePropertiesWithoutSetters(value); - return this; - } - - @Override /* CoreObjectBuilder */ - public RdfParserBuilder ignoreInvocationExceptionsOnGetters(boolean value) { - super.ignoreInvocationExceptionsOnGetters(value); - return this; - } - - @Override /* CoreObjectBuilder */ - public RdfParserBuilder ignoreInvocationExceptionsOnSetters(boolean value) { - super.ignoreInvocationExceptionsOnSetters(value); - return this; - } - - @Override /* CoreObjectBuilder */ - public RdfParserBuilder sortProperties(boolean value) { - super.sortProperties(value); - return this; - } - - @Override /* CoreObjectBuilder */ - public RdfParserBuilder notBeanPackages(String...values) { - super.notBeanPackages(values); - return this; - } - - @Override /* CoreObjectBuilder */ - public RdfParserBuilder notBeanPackages(Collection<String> values) { - super.notBeanPackages(values); - return this; - } - - @Override /* CoreObjectBuilder */ - public RdfParserBuilder setNotBeanPackages(String...values) { - super.setNotBeanPackages(values); - return this; - } - - @Override /* CoreObjectBuilder */ - public RdfParserBuilder setNotBeanPackages(Collection<String> values) { - super.setNotBeanPackages(values); - return this; - } - - @Override /* CoreObjectBuilder */ - public RdfParserBuilder removeNotBeanPackages(String...values) { - super.removeNotBeanPackages(values); - return this; - } - - @Override /* CoreObjectBuilder */ - public RdfParserBuilder removeNotBeanPackages(Collection<String> values) { - super.removeNotBeanPackages(values); - return this; - } - - @Override /* CoreObjectBuilder */ - public RdfParserBuilder notBeanClasses(Class<?>...values) { - super.notBeanClasses(values); - return this; - } - - @Override /* CoreObjectBuilder */ - public RdfParserBuilder notBeanClasses(Collection<Class<?>> values) { - super.notBeanClasses(values); - return this; - } - - @Override /* CoreObjectBuilder */ - public RdfParserBuilder setNotBeanClasses(Class<?>...values) { - super.setNotBeanClasses(values); - return this; - } - - @Override /* CoreObjectBuilder */ - public RdfParserBuilder setNotBeanClasses(Collection<Class<?>> values) { - super.setNotBeanClasses(values); - return this; - } - - @Override /* CoreObjectBuilder */ - public RdfParserBuilder removeNotBeanClasses(Class<?>...values) { - super.removeNotBeanClasses(values); - return this; - } - - @Override /* CoreObjectBuilder */ - public RdfParserBuilder removeNotBeanClasses(Collection<Class<?>> values) { - super.removeNotBeanClasses(values); - return this; - } - - @Override /* CoreObjectBuilder */ - public RdfParserBuilder beanFilters(Class<?>...values) { - super.beanFilters(values); - return this; - } - - @Override /* CoreObjectBuilder */ - public RdfParserBuilder beanFilters(Collection<Class<?>> values) { - super.beanFilters(values); - return this; - } - - @Override /* CoreObjectBuilder */ - public RdfParserBuilder setBeanFilters(Class<?>...values) { - super.setBeanFilters(values); - return this; - } - - @Override /* CoreObjectBuilder */ - public RdfParserBuilder setBeanFilters(Collection<Class<?>> values) { - super.setBeanFilters(values); - return this; - } - - @Override /* CoreObjectBuilder */ - public RdfParserBuilder removeBeanFilters(Class<?>...values) { - super.removeBeanFilters(values); - return this; - } - - @Override /* CoreObjectBuilder */ - public RdfParserBuilder removeBeanFilters(Collection<Class<?>> values) { - super.removeBeanFilters(values); - return this; - } - - @Override /* CoreObjectBuilder */ - public RdfParserBuilder pojoSwaps(Class<?>...values) { - super.pojoSwaps(values); - return this; - } - - @Override /* CoreObjectBuilder */ - public RdfParserBuilder pojoSwaps(Collection<Class<?>> values) { - super.pojoSwaps(values); - return this; - } - - @Override /* CoreObjectBuilder */ - public RdfParserBuilder setPojoSwaps(Class<?>...values) { - super.setPojoSwaps(values); - return this; - } - - @Override /* CoreObjectBuilder */ - public RdfParserBuilder setPojoSwaps(Collection<Class<?>> values) { - super.setPojoSwaps(values); - return this; - } - - @Override /* CoreObjectBuilder */ - public RdfParserBuilder removePojoSwaps(Class<?>...values) { - super.removePojoSwaps(values); - return this; - } - - @Override /* CoreObjectBuilder */ - public RdfParserBuilder removePojoSwaps(Collection<Class<?>> values) { - super.removePojoSwaps(values); - return this; - } - - @Override /* CoreObjectBuilder */ - public RdfParserBuilder implClasses(Map<Class<?>,Class<?>> values) { - super.implClasses(values); - return this; - } - - @Override /* CoreObjectBuilder */ - public <T> RdfParserBuilder implClass(Class<T> interfaceClass, Class<? extends T> implClass) { - super.implClass(interfaceClass, implClass); - return this; - } - - @Override /* CoreObjectBuilder */ - public RdfParserBuilder beanDictionary(Class<?>...values) { - super.beanDictionary(values); - return this; - } - - @Override /* CoreObjectBuilder */ - public RdfParserBuilder beanDictionary(Collection<Class<?>> values) { - super.beanDictionary(values); - return this; - } - - @Override /* CoreObjectBuilder */ - public RdfParserBuilder setBeanDictionary(Class<?>...values) { - super.setBeanDictionary(values); - return this; - } - - @Override /* CoreObjectBuilder */ - public RdfParserBuilder setBeanDictionary(Collection<Class<?>> values) { - super.setBeanDictionary(values); - return this; - } - - @Override /* CoreObjectBuilder */ - public RdfParserBuilder removeFromBeanDictionary(Class<?>...values) { - super.removeFromBeanDictionary(values); - return this; - } - - @Override /* CoreObjectBuilder */ - public RdfParserBuilder removeFromBeanDictionary(Collection<Class<?>> values) { - super.removeFromBeanDictionary(values); - return this; - } - - @Override /* CoreObjectBuilder */ - public RdfParserBuilder beanTypePropertyName(String value) { - super.beanTypePropertyName(value); - return this; - } - - @Override /* CoreObjectBuilder */ - public RdfParserBuilder defaultParser(Class<?> value) { - super.defaultParser(value); - return this; - } - - @Override /* CoreObjectBuilder */ - public RdfParserBuilder locale(Locale value) { - super.locale(value); - return this; - } - - @Override /* CoreObjectBuilder */ - public RdfParserBuilder timeZone(TimeZone value) { - super.timeZone(value); - return this; - } - - @Override /* CoreObjectBuilder */ - public RdfParserBuilder mediaType(MediaType value) { - super.mediaType(value); - return this; - } - - @Override /* CoreObjectBuilder */ - public RdfParserBuilder debug() { - super.debug(); - return this; - } - - @Override /* CoreObjectBuilder */ - public RdfParserBuilder property(String name, Object value) { - super.property(name, value); - return this; - } - - @Override /* CoreObjectBuilder */ - public RdfParserBuilder properties(Map<String,Object> properties) { - super.properties(properties); - return this; - } - - @Override /* CoreObjectBuilder */ - public RdfParserBuilder addToProperty(String name, Object value) { - super.addToProperty(name, value); - return this; - } - - @Override /* CoreObjectBuilder */ - public RdfParserBuilder putToProperty(String name, Object key, Object value) { - super.putToProperty(name, key, value); - return this; - } - - @Override /* CoreObjectBuilder */ - public RdfParserBuilder putToProperty(String name, Object value) { - super.putToProperty(name, value); - return this; - } - - @Override /* CoreObjectBuilder */ - public RdfParserBuilder removeFromProperty(String name, Object value) { - super.removeFromProperty(name, value); - return this; - } - - @Override /* CoreObjectBuilder */ - public RdfParserBuilder classLoader(ClassLoader classLoader) { - super.classLoader(classLoader); - return this; - } - - @Override /* CoreObjectBuilder */ - public RdfParserBuilder apply(PropertyStore copyFrom) { - super.apply(copyFrom); - return this; - } -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/ab15d45b/juneau-core-rdf/src/main/java/org/apache/juneau/jena/RdfParserContext.java ---------------------------------------------------------------------- diff --git a/juneau-core-rdf/src/main/java/org/apache/juneau/jena/RdfParserContext.java b/juneau-core-rdf/src/main/java/org/apache/juneau/jena/RdfParserContext.java deleted file mode 100644 index 42833c4..0000000 --- a/juneau-core-rdf/src/main/java/org/apache/juneau/jena/RdfParserContext.java +++ /dev/null @@ -1,104 +0,0 @@ -// *************************************************************************************************************************** -// * 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.juneau.jena; - -import java.util.*; - -import org.apache.juneau.*; -import org.apache.juneau.parser.*; -import org.apache.juneau.xml.*; - -/** - * Configurable properties on the {@link RdfParser} class. - * - * <p> - * Context properties are set by calling {@link PropertyStore#setProperty(String, Object)} on the property store - * passed into the constructor. - * - * <p> - * See {@link PropertyStore} for more information about context properties. - * - * <h6 class='topic' id='ConfigProperties'>Configurable properties inherited by the RDF parsers</h6> - * <ul class='doctree'> - * <li class='jc'> - * <a class="doclink" href="../BeanContext.html#ConfigProperties">BeanContext</a> - * - Properties associated with handling beans on serializers and parsers. - * <ul> - * <li class='jc'> - * <a class="doclink" href="../parser/ParserContext.html#ConfigProperties">ParserContext</a> - * - Configurable properties common to all parsers. - * <ul> - * <li class='jic'> - * <a class="doclink" href="RdfCommonContext.html#ConfigProperties">RdfCommonContext</a> - * - Configurable properties common to the RDF serializers and parsers. - * </ul> - * </li> - * </ul> - * </li> - * </ul> - */ -public final class RdfParserContext extends ParserContext implements RdfCommonContext { - - /** - * <b>Configuration property:</b> Trim whitespace from text elements. - * - * <ul> - * <li><b>Name:</b> <js>"RdfParser.trimWhitespace"</js> - * <li><b>Data type:</b> <code>Boolean</code> - * <li><b>Default:</b> <jk>false</jk> - * <li><b>Session-overridable:</b> <jk>true</jk> - * </ul> - * - * <p> - * If <jk>true</jk>, whitespace in text elements will be automatically trimmed. - */ - public static final String RDF_trimWhitespace = "RdfParser.trimWhitespace"; - - final boolean trimWhitespace, looseCollections; - final String rdfLanguage; - final Namespace juneauNs, juneauBpNs; - final RdfCollectionFormat collectionFormat; - final Map<String,Object> jenaSettings = new HashMap<String,Object>(); - - /** - * Constructor. - * - * <p> - * Typically only called from {@link PropertyStore#getContext(Class)}. - * - * @param ps The property store that created this context. - */ - public RdfParserContext(PropertyStore ps) { - super(ps); - trimWhitespace = ps.getProperty(RDF_trimWhitespace, boolean.class, false); - looseCollections = ps.getProperty(RDF_looseCollections, boolean.class, false); - rdfLanguage = ps.getProperty(RDF_language, String.class, "RDF/XML-ABBREV"); - juneauNs = ps.getProperty(RDF_juneauNs, Namespace.class, new Namespace("j", "http://www.apache.org/juneau/")); - juneauBpNs = ps.getProperty(RDF_juneauBpNs, Namespace.class, new Namespace("j", "http://www.apache.org/juneaubp/")); - collectionFormat = ps.getProperty(RDF_collectionFormat, RdfCollectionFormat.class, RdfCollectionFormat.DEFAULT); - } - - @Override /* Context */ - public ObjectMap asMap() { - return super.asMap() - .append("RdfParserContext", new ObjectMap() - .append("trimWhitespace", trimWhitespace) - .append("looseCollections", looseCollections) - .append("rdfLanguage", rdfLanguage) - .append("juneauNs", juneauNs) - .append("juneauBpNs", juneauBpNs) - .append("collectionFormat", collectionFormat) - ); - } -} - http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/ab15d45b/juneau-core-rdf/src/main/java/org/apache/juneau/jena/RdfParserSession.java ---------------------------------------------------------------------- diff --git a/juneau-core-rdf/src/main/java/org/apache/juneau/jena/RdfParserSession.java b/juneau-core-rdf/src/main/java/org/apache/juneau/jena/RdfParserSession.java deleted file mode 100644 index 267d06f..0000000 --- a/juneau-core-rdf/src/main/java/org/apache/juneau/jena/RdfParserSession.java +++ /dev/null @@ -1,434 +0,0 @@ -// *************************************************************************************************************************** -// * 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.juneau.jena; - -import static org.apache.juneau.internal.StringUtils.*; -import static org.apache.juneau.jena.Constants.*; -import static org.apache.juneau.jena.RdfCommonContext.*; - -import java.util.*; - -import org.apache.juneau.*; -import org.apache.juneau.parser.*; -import org.apache.juneau.transform.*; -import org.apache.juneau.xml.*; - -import com.hp.hpl.jena.rdf.model.*; -import com.hp.hpl.jena.util.iterator.*; - -/** - * Session object that lives for the duration of a single use of {@link RdfParser}. - * - * <p> - * This class is NOT thread safe. - * It is typically discarded after one-time use although it can be reused against multiple inputs. - */ -@SuppressWarnings({"unchecked", "rawtypes"}) -public class RdfParserSession extends ReaderParserSession { - - private final String rdfLanguage; - private final Namespace juneauNs, juneauBpNs; - private final Property pRoot, pValue, pType, pRdfType; - private final Model model; - private final boolean trimWhitespace, looseCollections; - private final RDFReader rdfReader; - private final Set<Resource> urisVisited = new HashSet<Resource>(); - private final RdfCollectionFormat collectionFormat; - - /** - * Create a new session using properties specified in the context. - * - * @param ctx - * The context creating this session object. - * The context contains all the configuration settings for this object. - * @param args - * Runtime session arguments. - */ - protected RdfParserSession(RdfParserContext ctx, ParserSessionArgs args) { - super(ctx, args); - ObjectMap jenaSettings = new ObjectMap(); - jenaSettings.putAll(ctx.jenaSettings); - ObjectMap p = getProperties(); - if (p.isEmpty()) { - this.rdfLanguage = ctx.rdfLanguage; - this.juneauNs = ctx.juneauNs; - this.juneauBpNs = ctx.juneauBpNs; - this.trimWhitespace = ctx.trimWhitespace; - this.collectionFormat = ctx.collectionFormat; - this.looseCollections = ctx.looseCollections; - } else { - this.rdfLanguage = p.getString(RDF_language, ctx.rdfLanguage); - this.juneauNs = (p.containsKey(RDF_juneauNs) ? NamespaceFactory.parseNamespace(p.get(RDF_juneauNs)) : ctx.juneauNs); - this.juneauBpNs = (p.containsKey(RDF_juneauBpNs) ? NamespaceFactory.parseNamespace(p.get(RDF_juneauBpNs)) : ctx.juneauBpNs); - this.trimWhitespace = p.getBoolean(RdfParserContext.RDF_trimWhitespace, ctx.trimWhitespace); - this.collectionFormat = RdfCollectionFormat.valueOf(p.getString(RDF_collectionFormat, "DEFAULT")); - this.looseCollections = p.getBoolean(RDF_looseCollections, ctx.looseCollections); - } - this.model = ModelFactory.createDefaultModel(); - addModelPrefix(juneauNs); - addModelPrefix(juneauBpNs); - this.pRoot = model.createProperty(juneauNs.getUri(), RDF_juneauNs_ROOT); - this.pValue = model.createProperty(juneauNs.getUri(), RDF_juneauNs_VALUE); - this.pType = model.createProperty(juneauBpNs.getUri(), RDF_juneauNs_TYPE); - this.pRdfType = model.createProperty("http://www.w3.org/1999/02/22-rdf-syntax-ns#type"); - rdfReader = model.getReader(rdfLanguage); - - // Note: NTripleReader throws an exception if you try to set any properties on it. - if (! rdfLanguage.equals(LANG_NTRIPLE)) { - for (Map.Entry<String,Object> e : jenaSettings.entrySet()) - rdfReader.setProperty(e.getKey(), e.getValue()); - } - } - - @Override /* ReaderParserSession */ - protected <T> T doParse(ParserPipe pipe, ClassMeta<T> type) throws Exception { - - RDFReader r = rdfReader; - r.read(model, pipe.getBufferedReader(), null); - - List<Resource> roots = getRoots(model); - - // Special case where we're parsing a loose collection of resources. - if (looseCollections && type.isCollectionOrArray()) { - Collection c = null; - if (type.isArray() || type.isArgs()) - c = new ArrayList(); - else - c = ( - type.canCreateNewInstance(getOuter()) - ? (Collection<?>)type.newInstance(getOuter()) - : new ObjectList(this) - ); - - int argIndex = 0; - for (Resource resource : roots) - c.add(parseAnything(type.isArgs() ? type.getArg(argIndex++) : type.getElementType(), resource, - getOuter(), null)); - - if (type.isArray() || type.isArgs()) - return (T)toArray(type, c); - return (T)c; - } - - if (roots.isEmpty()) - return null; - if (roots.size() > 1) - throw new ParseException(loc(), "Too many root nodes found in model: {0}", roots.size()); - Resource resource = roots.get(0); - - return parseAnything(type, resource, getOuter(), null); - } - - private final void addModelPrefix(Namespace ns) { - model.setNsPrefix(ns.getName(), ns.getUri()); - } - - /* - * Decodes the specified string. - * If {@link RdfParserContext#RDF_trimWhitespace} is <jk>true</jk>, the resulting string is trimmed before decoding. - * If {@link #isTrimStrings()} is <jk>true</jk>, the resulting string is trimmed after decoding. - */ - private String decodeString(Object o) { - if (o == null) - return null; - String s = o.toString(); - if (s.isEmpty()) - return s; - if (trimWhitespace) - s = s.trim(); - s = XmlUtils.decode(s, null); - if (isTrimStrings()) - s = s.trim(); - return s; - } - - /* - * Finds the roots in the model using either the "root" property to identify it, - * or by resorting to scanning the model for all nodes with no incoming predicates. - */ - private List<Resource> getRoots(Model m) { - List<Resource> l = new LinkedList<Resource>(); - - // First try to find the root using the "http://www.apache.org/juneau/root" property. - Property root = m.createProperty(juneauNs.getUri(), RDF_juneauNs_ROOT); - for (ResIterator i = m.listResourcesWithProperty(root); i.hasNext();) - l.add(i.next()); - - if (! l.isEmpty()) - return l; - - // Otherwise, we need to find all resources that aren't objects. - // We want to explicitly ignore statements where the subject - // and object are the same node. - Set<RDFNode> objects = new HashSet<RDFNode>(); - for (StmtIterator i = m.listStatements(); i.hasNext();) { - Statement st = i.next(); - RDFNode subject = st.getSubject(); - RDFNode object = st.getObject(); - if (object.isResource() && ! object.equals(subject)) - objects.add(object); - } - for (ResIterator i = m.listSubjects(); i.hasNext();) { - Resource r = i.next(); - if (! objects.contains(r)) - l.add(r); - } - return l; - } - - private <T> BeanMap<T> parseIntoBeanMap(Resource r2, BeanMap<T> m) throws Exception { - BeanMeta<T> bm = m.getMeta(); - RdfBeanMeta rbm = bm.getExtendedMeta(RdfBeanMeta.class); - if (rbm.hasBeanUri() && r2.getURI() != null) - rbm.getBeanUriProperty().set(m, null, r2.getURI()); - for (StmtIterator i = r2.listProperties(); i.hasNext();) { - Statement st = i.next(); - Property p = st.getPredicate(); - String key = decodeString(p.getLocalName()); - BeanPropertyMeta pMeta = m.getPropertyMeta(key); - setCurrentProperty(pMeta); - if (pMeta != null) { - RDFNode o = st.getObject(); - ClassMeta<?> cm = pMeta.getClassMeta(); - if (cm.isCollectionOrArray() && isMultiValuedCollections(pMeta)) { - ClassMeta<?> et = cm.getElementType(); - Object value = parseAnything(et, o, m.getBean(false), pMeta); - setName(et, value, key); - pMeta.add(m, key, value); - } else { - Object value = parseAnything(cm, o, m.getBean(false), pMeta); - setName(cm, value, key); - pMeta.set(m, key, value); - } - } else if (! (p.equals(pRoot) || p.equals(pType))) { - onUnknownProperty(null, key, m, -1, -1); - } - setCurrentProperty(null); - } - return m; - } - - private boolean isMultiValuedCollections(BeanPropertyMeta pMeta) { - if (pMeta != null && pMeta.getExtendedMeta(RdfBeanPropertyMeta.class).getCollectionFormat() != RdfCollectionFormat.DEFAULT) - return pMeta.getExtendedMeta(RdfBeanPropertyMeta.class).getCollectionFormat() == RdfCollectionFormat.MULTI_VALUED; - return collectionFormat == RdfCollectionFormat.MULTI_VALUED; - } - - private <T> T parseAnything(ClassMeta<T> eType, RDFNode n, Object outer, BeanPropertyMeta pMeta) throws Exception { - - if (eType == null) - eType = (ClassMeta<T>)object(); - PojoSwap<T,Object> transform = (PojoSwap<T,Object>)eType.getPojoSwap(); - ClassMeta<?> sType = eType.getSerializedClassMeta(); - setCurrentClass(sType); - - if (! sType.canCreateNewInstance(outer)) { - if (n.isResource()) { - Statement st = n.asResource().getProperty(pType); - if (st != null) { - String c = st.getLiteral().getString(); - ClassMeta tcm = getClassMeta(c, pMeta, eType); - if (tcm != null) - sType = eType = tcm; - } - } - } - - Object o = null; - if (n.isResource() && n.asResource().getURI() != null && n.asResource().getURI().equals(RDF_NIL)) { - // Do nothing. Leave o == null. - } else if (sType.isObject()) { - if (n.isLiteral()) { - o = n.asLiteral().getValue(); - if (o instanceof String) { - o = decodeString(o); - } - } - else if (n.isResource()) { - Resource r = n.asResource(); - if (! urisVisited.add(r)) - o = r.getURI(); - else if (r.getProperty(pValue) != null) { - o = parseAnything(object(), n.asResource().getProperty(pValue).getObject(), outer, null); - } else if (isSeq(r)) { - o = new ObjectList(this); - parseIntoCollection(r.as(Seq.class), (Collection)o, sType, pMeta); - } else if (isBag(r)) { - o = new ObjectList(this); - parseIntoCollection(r.as(Bag.class), (Collection)o, sType, pMeta); - } else if (r.canAs(RDFList.class)) { - o = new ObjectList(this); - parseIntoCollection(r.as(RDFList.class), (Collection)o, sType, pMeta); - } else { - // If it has a URI and no child properties, we interpret this as an - // external resource, and convert it to just a URL. - String uri = r.getURI(); - if (uri != null && ! r.listProperties().hasNext()) { - o = r.getURI(); - } else { - ObjectMap m2 = new ObjectMap(this); - parseIntoMap(r, m2, null, null, pMeta); - o = cast(m2, pMeta, eType); - } - } - } else { - throw new ParseException(loc(), "Unrecognized node type ''{0}'' for object", n); - } - } else if (sType.isBoolean()) { - o = convertToType(getValue(n, outer), boolean.class); - } else if (sType.isCharSequence()) { - o = decodeString(getValue(n, outer)); - } else if (sType.isChar()) { - o = decodeString(getValue(n, outer)).charAt(0); - } else if (sType.isNumber()) { - o = parseNumber(getValue(n, outer).toString(), (Class<? extends Number>)sType.getInnerClass()); - } else if (sType.isMap()) { - Resource r = n.asResource(); - if (! urisVisited.add(r)) - return null; - Map m = (sType.canCreateNewInstance(outer) ? (Map)sType.newInstance(outer) : new ObjectMap(this)); - o = parseIntoMap(r, m, eType.getKeyType(), eType.getValueType(), pMeta); - } else if (sType.isCollectionOrArray() || sType.isArgs()) { - if (sType.isArray() || sType.isArgs()) - o = new ArrayList(); - else - o = (sType.canCreateNewInstance(outer) ? (Collection<?>)sType.newInstance(outer) : new ObjectList(this)); - Resource r = n.asResource(); - if (! urisVisited.add(r)) - return null; - if (isSeq(r)) { - parseIntoCollection(r.as(Seq.class), (Collection)o, sType, pMeta); - } else if (isBag(r)) { - parseIntoCollection(r.as(Bag.class), (Collection)o, sType, pMeta); - } else if (r.canAs(RDFList.class)) { - parseIntoCollection(r.as(RDFList.class), (Collection)o, sType, pMeta); - } else { - throw new ParseException("Unrecognized node type ''{0}'' for collection", n); - } - if (sType.isArray() || sType.isArgs()) - o = toArray(sType, (Collection)o); - } else if (sType.canCreateNewBean(outer)) { - Resource r = n.asResource(); - if (! urisVisited.add(r)) - return null; - BeanMap<?> bm = newBeanMap(outer, sType.getInnerClass()); - o = parseIntoBeanMap(r, bm).getBean(); - } else if (sType.isUri() && n.isResource()) { - o = sType.newInstanceFromString(outer, decodeString(n.asResource().getURI())); - } else if (sType.canCreateNewInstanceFromString(outer)) { - o = sType.newInstanceFromString(outer, decodeString(getValue(n, outer))); - } else if (sType.canCreateNewInstanceFromNumber(outer)) { - o = sType.newInstanceFromNumber(this, outer, parseNumber(getValue(n, outer).toString(), sType.getNewInstanceFromNumberClass())); - } else if (n.isResource()) { - Resource r = n.asResource(); - Map m = new ObjectMap(this); - parseIntoMap(r, m, sType.getKeyType(), sType.getValueType(), pMeta); - if (m.containsKey(getBeanTypePropertyName(eType))) - o = cast((ObjectMap)m, pMeta, eType); - else - throw new ParseException(loc(), "Class ''{0}'' could not be instantiated. Reason: ''{1}''", sType.getInnerClass().getName(), sType.getNotABeanReason()); - } else { - throw new ParseException("Class ''{0}'' could not be instantiated. Reason: ''{1}''", sType.getInnerClass().getName(), sType.getNotABeanReason()); - } - - if (transform != null && o != null) - o = transform.unswap(this, o, eType); - - if (outer != null) - setParent(eType, o, outer); - - return (T)o; - } - - private ObjectMap loc() { - return getLastLocation(); - } - - private boolean isSeq(RDFNode n) { - if (n.isResource()) { - Statement st = n.asResource().getProperty(pRdfType); - if (st != null) - return RDF_SEQ.equals(st.getResource().getURI()); - } - return false; - } - - private boolean isBag(RDFNode n) { - if (n.isResource()) { - Statement st = n.asResource().getProperty(pRdfType); - if (st != null) - return RDF_BAG.equals(st.getResource().getURI()); - } - return false; - } - - private Object getValue(RDFNode n, Object outer) throws Exception { - if (n.isLiteral()) - return n.asLiteral().getValue(); - if (n.isResource()) { - Statement st = n.asResource().getProperty(pValue); - if (st != null) { - n = st.getObject(); - if (n.isLiteral()) - return n.asLiteral().getValue(); - return parseAnything(object(), st.getObject(), outer, null); - } - } - throw new ParseException(loc(), "Unknown value type for node ''{0}''", n); - } - - private <K,V> Map<K,V> parseIntoMap(Resource r, Map<K,V> m, ClassMeta<K> keyType, - ClassMeta<V> valueType, BeanPropertyMeta pMeta) throws Exception { - // Add URI as "uri" to generic maps. - if (r.getURI() != null) { - K uri = convertAttrToType(m, "uri", keyType); - V value = convertAttrToType(m, r.getURI(), valueType); - m.put(uri, value); - } - for (StmtIterator i = r.listProperties(); i.hasNext();) { - Statement st = i.next(); - Property p = st.getPredicate(); - String key = p.getLocalName(); - if (! (key.equals("root") && p.getURI().equals(juneauNs.getUri()))) { - key = decodeString(key); - RDFNode o = st.getObject(); - K key2 = convertAttrToType(m, key, keyType); - V value = parseAnything(valueType, o, m, pMeta); - setName(valueType, value, key); - m.put(key2, value); - } - - } - return m; - } - - private <E> Collection<E> parseIntoCollection(Container c, Collection<E> l, - ClassMeta<?> type, BeanPropertyMeta pMeta) throws Exception { - int argIndex = 0; - for (NodeIterator ni = c.iterator(); ni.hasNext();) { - E e = (E)parseAnything(type.isArgs() ? type.getArg(argIndex++) : type.getElementType(), ni.next(), l, pMeta); - l.add(e); - } - return l; - } - - private <E> Collection<E> parseIntoCollection(RDFList list, Collection<E> l, - ClassMeta<?> type, BeanPropertyMeta pMeta) throws Exception { - int argIndex = 0; - for (ExtendedIterator<RDFNode> ni = list.iterator(); ni.hasNext();) { - E e = (E)parseAnything(type.isArgs() ? type.getArg(argIndex++) : type.getElementType(), ni.next(), l, pMeta); - l.add(e); - } - return l; - } -} http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/ab15d45b/juneau-core-rdf/src/main/java/org/apache/juneau/jena/RdfSerializer.java ---------------------------------------------------------------------- diff --git a/juneau-core-rdf/src/main/java/org/apache/juneau/jena/RdfSerializer.java b/juneau-core-rdf/src/main/java/org/apache/juneau/jena/RdfSerializer.java deleted file mode 100644 index b574186..0000000 --- a/juneau-core-rdf/src/main/java/org/apache/juneau/jena/RdfSerializer.java +++ /dev/null @@ -1,165 +0,0 @@ -// *************************************************************************************************************************** -// * 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.juneau.jena; - -import static org.apache.juneau.jena.Constants.*; -import static org.apache.juneau.jena.RdfCommonContext.*; - -import org.apache.juneau.*; -import org.apache.juneau.serializer.*; - -/** - * Serializes POJOs to RDF. - * - * <h5 class='section'>Configurable properties:</h5> - * - * Refer to <a class="doclink" href="package-summary.html#SerializerConfigurableProperties">Configurable Properties</a> - * for the entire list of configurable properties. - * - * <h6 class='topic'>Behavior-specific subclasses</h6> - * - * The following direct subclasses are provided for language-specific serializers: - * <ul> - * <li>{@link RdfSerializer.Xml} - RDF/XML. - * <li>{@link RdfSerializer.XmlAbbrev} - RDF/XML-ABBREV. - * <li>{@link RdfSerializer.NTriple} - N-TRIPLE. - * <li>{@link RdfSerializer.Turtle} - TURTLE. - * <li>{@link RdfSerializer.N3} - N3. - * </ul> - * - * <h5 class='section'>Additional information:</h5> - * - * See <a class="doclink" href="package-summary.html#TOC">RDF Overview</a> for an overview of RDF support in Juneau. - */ -public class RdfSerializer extends WriterSerializer { - - /** Default RDF/XML serializer, all default settings.*/ - public static final RdfSerializer DEFAULT_XML = new Xml(PropertyStore.create()); - - /** Default Abbreviated RDF/XML serializer, all default settings.*/ - public static final RdfSerializer DEFAULT_XMLABBREV = new XmlAbbrev(PropertyStore.create()); - - /** Default Turtle serializer, all default settings.*/ - public static final RdfSerializer DEFAULT_TURTLE = new Turtle(PropertyStore.create()); - - /** Default N-Triple serializer, all default settings.*/ - public static final RdfSerializer DEFAULT_NTRIPLE = new NTriple(PropertyStore.create()); - - /** Default N3 serializer, all default settings.*/ - public static final RdfSerializer DEFAULT_N3 = new N3(PropertyStore.create()); - - - /** Produces RDF/XML output */ - public static class Xml extends RdfSerializer { - - /** - * Constructor. - * - * @param propertyStore The property store containing all the settings for this object. - */ - public Xml(PropertyStore propertyStore) { - super(propertyStore.copy().append(RDF_language, LANG_RDF_XML), "text/xml+rdf"); - } - } - - /** Produces Abbreviated RDF/XML output */ - public static class XmlAbbrev extends RdfSerializer { - - /** - * Constructor. - * - * @param propertyStore The property store containing all the settings for this object. - */ - public XmlAbbrev(PropertyStore propertyStore) { - super(propertyStore.copy().append(RDF_language, LANG_RDF_XML_ABBREV), "text/xml+rdf", "text/xml+rdf+abbrev"); - } - } - - /** Produces N-Triple output */ - public static class NTriple extends RdfSerializer { - - /** - * Constructor. - * - * @param propertyStore The property store containing all the settings for this object. - */ - public NTriple(PropertyStore propertyStore) { - super(propertyStore.copy().append(RDF_language, LANG_NTRIPLE), "text/n-triple"); - } - } - - /** Produces Turtle output */ - public static class Turtle extends RdfSerializer { - - /** - * Constructor. - * - * @param propertyStore The property store containing all the settings for this object. - */ - public Turtle(PropertyStore propertyStore) { - super(propertyStore.copy().append(RDF_language, LANG_TURTLE), "text/turtle"); - } - } - - /** Produces N3 output */ - public static class N3 extends RdfSerializer { - - /** - * Constructor. - * - * @param propertyStore The property store containing all the settings for this object. - */ - public N3(PropertyStore propertyStore) { - super(propertyStore.copy().append(RDF_language, LANG_N3), "text/n3"); - } - } - - - private final RdfSerializerContext ctx; - - /** - * Constructor. - * - * @param propertyStore - * The property store containing all the settings for this object. - * @param produces - * The media type that this serializer produces. - * @param accept - * The accept media types that the serializer can handle. - * <p> - * Can contain meta-characters per the <code>media-type</code> specification of - * <a class="doclink" href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.1">RFC2616/14.1</a> - * <p> - * If empty, then assumes the only media type supported is <code>produces</code>. - * <p> - * For example, if this serializer produces <js>"application/json"</js> but should handle media types of - * <js>"application/json"</js> and <js>"text/json"</js>, then the arguments should be: - * <br><code><jk>super</jk>(propertyStore, <js>"application/json"</js>, <js>"application/json"</js>, <js>"text/json"</js>);</code> - * <br>...or... - * <br><code><jk>super</jk>(propertyStore, <js>"application/json"</js>, <js>"*​/json"</js>);</code> - */ - public RdfSerializer(PropertyStore propertyStore, String produces, String...accept) { - super(propertyStore, produces, accept); - this.ctx = createContext(RdfSerializerContext.class); - } - - @Override /* CoreObject */ - public RdfSerializerBuilder builder() { - return new RdfSerializerBuilder(propertyStore); - } - - @Override /* Serializer */ - public WriterSerializerSession createSession(SerializerSessionArgs args) { - return new RdfSerializerSession(ctx, args); - } -}
