001/*
002 * Licensed to the Apache Software Foundation (ASF) under one or more
003 * contributor license agreements.  See the NOTICE file distributed with
004 * this work for additional information regarding copyright ownership.
005 * The ASF licenses this file to You under the Apache License, Version 2.0
006 * (the "License"); you may not use this file except in compliance with
007 * the License.  You may obtain a copy of the License at
008 *
009 *      http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017package org.apache.juneau.marshall.jena;
018
019/**
020 * Subclass of {@link RdfParser} for parsing N-Triples into POJOs.
021 *
022 * <p>
023 * Accepts RDF in W3C N-Triples format (one triple per line) and converts it to Java beans, maps,
024 * collections, and primitive types. Date/time literals are parsed via ISO 8601.
025 *
026 * <h5 class='figure'>Examples:</h5>
027 * <p class='bjava'>
028 *    <jc>// Parse N-Triples string into a bean.</jc>
029 *    String <jv>nTriples</jv> = ...;  <jc>// N-Triples content</jc>
030 *    Person <jv>person</jv> = NTripleParser.<jsf>DEFAULT</jsf>.read(<jv>nTriples</jv>, Person.<jk>class</jk>);
031 * </p>
032 * <p class='bjava'>
033 *    <jc>// Or use the NTriple marshaller for convenience.</jc>
034 *    Person <jv>person</jv> = NTriple.<jsf>DEFAULT</jsf>.read(<jv>nTriples</jv>, Person.<jk>class</jk>);
035 * </p>
036 * <p class='bjava'>
037 *    <jc>// Parse into a map.</jc>
038 *    Map&lt;String, String&gt; <jv>map</jv> = NTripleParser.<jsf>DEFAULT</jsf>.read(<jv>nTriples</jv>, Map.<jk>class</jk>, String.<jk>class</jk>, String.<jk>class</jk>);
039 * </p>
040 * <p class='bjava'>
041 *    <jc>// Custom parser with swaps.</jc>
042 *    NTripleParser <jv>p</jv> = NTripleParser.create().swaps(DateSwap.<jk>class</jk>).build();
043 *    MyBean <jv>bean</jv> = <jv>p</jv>.read(<jv>nTriples</jv>, MyBean.<jk>class</jk>);
044 * </p>
045 *
046 * <h5 class='figure'>Example input (bean with name/age):</h5>
047 * <p class='bcode'>
048 *    &lt;...&gt; &lt;.../name&gt; "Alice" .
049 *    &lt;...&gt; &lt;.../age&gt; "30"^^&lt;http://www.w3.org/2001/XMLSchema#int&gt; .
050 * </p>
051 *
052 * <h5 class='figure'>Complex (nested address + array):</h5>
053 * <p class='bcode'>
054 *    &lt;...&gt; &lt;.../name&gt; "Alice" .
055 *    &lt;...&gt; &lt;.../address&gt; &lt;.../address&gt; .
056 *    &lt;.../address&gt; &lt;.../street&gt; "123 Main St" .
057 *    &lt;.../address&gt; &lt;.../city&gt; "Boston" .
058 *    &lt;.../address&gt; &lt;.../state&gt; "MA" .
059 * </p>
060 *
061 * <h5 class='section'>Notes:</h5><ul>
062 *    <li class='note'>This class is thread safe and reusable.
063 * </ul>
064 *
065 * <h5 class='section'>See Also:</h5><ul>
066 *    <li class='link'>{doc jmr.RdfDetails}
067 * </ul>
068 */
069@SuppressWarnings({
070   "java:S110" // Deep inheritance inherent to the RDF parser hierarchy.
071})
072public class NTripleParser extends RdfParser {
073
074   /** Default N-Triple parser, all default settings.*/
075   public static final NTripleParser DEFAULT = new NTripleParser(create());
076
077   /**
078    * Creates a new builder for this object.
079    *
080    * @return A new builder.
081    */
082   @SuppressWarnings({
083      "java:S1452", // Builder<?> wildcard return intentional; callers chain via fluent API without needing the concrete type
084      "java:S9149" // Public Juneau DSL factory; hiding parent create() is intentional.
085   })
086   public static RdfParser.Builder<?> create() {
087      return RdfParser.create().ntriple();
088   }
089
090   /**
091    * Constructor.
092    *
093    * @param builder The builder for this object.
094    *    <br>Cannot be <jk>null</jk>.
095    */
096   public NTripleParser(RdfParser.Builder<?> builder) {
097      super(builder.ntriple().consumes("text/n-triple"));
098   }
099}