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 RdfSerializer} for serializing POJOs to TriX (XML) format.
021 *
022 * <p>
023 * Produces RDF triples in TriX XML format. TriX represents RDF as XML elements, suitable for
024 * XML-based toolchains and transformations.
025 *
026 * <h5 class='figure'>Examples:</h5>
027 * <p class='bjava'>
028 *    <jc>// Serialize a bean to TriX XML string.</jc>
029 *    Person <jv>person</jv> = <jk>new</jk> Person(<js>"Alice"</js>, 30);
030 *    String <jv>triX</jv> = TriXSerializer.<jsf>DEFAULT</jsf>.write(<jv>person</jv>);
031 * </p>
032 * <p class='bjava'>
033 *    <jc>// Or use the TriX marshaller for convenience.</jc>
034 *    String <jv>triX</jv> = TriX.<jsm>of</jsm>(<jv>person</jv>);
035 * </p>
036 * <p class='bjava'>
037 *    <jc>// Custom serializer with swaps.</jc>
038 *    TriXSerializer <jv>s</jv> = TriXSerializer.create().swaps(DateSwap.<jk>class</jk>).build();
039 *    String <jv>triX</jv> = <jv>s</jv>.write(<jv>bean</jv>);
040 * </p>
041 *
042 * <h5 class='figure'>Example output (bean with name/age):</h5>
043 * <p class='bxml'>
044 *    <xt>&lt;TriX&gt;</xt>
045 *       <xt>&lt;graph&gt;</xt>
046 *          <xt>&lt;uri&gt;</xt>...<xt>&lt;/uri&gt;</xt>
047 *          <xt>&lt;triple&gt;</xt>
048 *             <xt>&lt;id&gt;</xt>...<xt>&lt;/id&gt;</xt>
049 *             <xt>&lt;name&gt;</xt>Alice<xt>&lt;/name&gt;</xt>
050 *             <xt>&lt;age&gt;</xt>30<xt>&lt;/age&gt;</xt>
051 *          <xt>&lt;/triple&gt;</xt>
052 *       <xt>&lt;/graph&gt;</xt>
053 *    <xt>&lt;/TriX&gt;</xt>
054 * </p>
055 *
056 * <h5 class='figure'>Complex (nested address + array):</h5>
057 * <p class='bxml'>
058 *    <xt>&lt;TriX&gt;</xt>
059 *       <xt>&lt;graph&gt;</xt>
060 *          <xt>&lt;triple&gt;</xt>...subject, predicate, object for name, age, address ref, tags...
061 *          <xt>&lt;triple&gt;</xt>...address subject, street, city, state...
062 *          <xt>&lt;triple&gt;</xt>...tags list members...
063 *       <xt>&lt;/graph&gt;</xt>
064 *    <xt>&lt;/TriX&gt;</xt>
065 * </p>
066 *
067 * <h5 class='section'>Notes:</h5><ul>
068 *    <li class='note'>This class is thread safe and reusable.
069 * </ul>
070 *
071 * <h5 class='section'>See Also:</h5><ul>
072 *    <li class='link'>{doc jmr.RdfDetails}
073 * </ul>
074 */
075@SuppressWarnings({
076   "java:S110" // Deep inheritance inherent to the RDF serializer hierarchy.
077})
078public class TriXSerializer extends RdfSerializer {
079
080   /** Default TriX serializer, all default settings.*/
081   public static final TriXSerializer DEFAULT = new TriXSerializer(create());
082
083   /**
084    * Creates a new builder for this object.
085    *
086    * @return A new builder.
087    */
088   @SuppressWarnings({
089      "java:S1452", // Builder<?> wildcard return intentional; callers chain via fluent API without needing the concrete type
090      "java:S9149" // Public Juneau DSL factory; hiding parent create() is intentional.
091   })
092   public static RdfSerializer.Builder<?> create() {
093      return RdfSerializer.create().triX();
094   }
095
096   /**
097    * Constructor.
098    *
099    * @param builder The builder for this object.
100    *    <br>Cannot be <jk>null</jk>.
101    */
102   public TriXSerializer(RdfSerializer.Builder<?> builder) {
103      super(builder.triX());
104   }
105}