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 TriX (XML) into POJOs.
021 *
022 * <p>
023 * Accepts RDF in TriX XML format and converts it to Java beans, maps, collections, and primitive
024 * types. Date/time literals are parsed via ISO 8601.
025 *
026 * <h5 class='figure'>Examples:</h5>
027 * <p class='bjava'>
028 *    <jc>// Parse TriX XML string into a bean.</jc>
029 *    String <jv>triX</jv> = ...;  <jc>// TriX XML content</jc>
030 *    Person <jv>person</jv> = TriXParser.<jsf>DEFAULT</jsf>.read(<jv>triX</jv>, Person.<jk>class</jk>);
031 * </p>
032 * <p class='bjava'>
033 *    <jc>// Or use the TriX marshaller for convenience.</jc>
034 *    Person <jv>person</jv> = TriX.<jsm>to</jsm>(<jv>triX</jv>, Person.<jk>class</jk>);
035 * </p>
036 * <p class='bjava'>
037 *    <jc>// Custom parser with swaps.</jc>
038 *    TriXParser <jv>p</jv> = TriXParser.create().swaps(DateSwap.<jk>class</jk>).build();
039 *    MyBean <jv>bean</jv> = <jv>p</jv>.read(<jv>triX</jv>, MyBean.<jk>class</jk>);
040 * </p>
041 *
042 * <h5 class='figure'>Example input (bean with name/age):</h5>
043 * <p class='bxml'>
044 *    <xt>&lt;TriX&gt;</xt>
045 *       <xt>&lt;graph&gt;</xt>
046 *          <xt>&lt;triple&gt;</xt>...subject, predicate, object...
047 *       <xt>&lt;/graph&gt;</xt>
048 *    <xt>&lt;/TriX&gt;</xt>
049 * </p>
050 *
051 * <h5 class='figure'>Complex (nested address + array):</h5>
052 * <p class='bxml'>
053 *    <xt>&lt;TriX&gt;</xt>
054 *       <xt>&lt;graph&gt;</xt>
055 *          <xt>&lt;triple&gt;</xt>...person triples, address triples, tags...
056 *       <xt>&lt;/graph&gt;</xt>
057 *    <xt>&lt;/TriX&gt;</xt>
058 * </p>
059 *
060 * <h5 class='section'>Notes:</h5><ul>
061 *    <li class='note'>This class is thread safe and reusable.
062 * </ul>
063 *
064 * <h5 class='section'>See Also:</h5><ul>
065 *    <li class='link'>{doc jmr.RdfDetails}
066 * </ul>
067 */
068@SuppressWarnings({
069   "java:S110" // Deep inheritance inherent to the RDF parser hierarchy.
070})
071public class TriXParser extends RdfParser {
072
073   /** Default TriX parser, all default settings.*/
074   public static final TriXParser DEFAULT = new TriXParser(create());
075
076   /**
077    * Creates a new builder for this object.
078    *
079    * @return A new builder.
080    */
081   @SuppressWarnings({
082      "java:S1452", // Builder<?> wildcard return intentional; callers chain via fluent API without needing the concrete type
083      "java:S9149" // Public Juneau DSL factory; hiding parent create() is intentional.
084   })
085   public static RdfParser.Builder<?> create() {
086      return RdfParser.create().triX();
087   }
088
089   /**
090    * Constructor.
091    *
092    * @param builder The builder for this object.
093    *    <br>Cannot be <jk>null</jk>.
094    */
095   public TriXParser(RdfParser.Builder<?> builder) {
096      super(builder.triX().consumes("application/trix+xml"));
097   }
098}