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-Quads into POJOs. 021 * 022 * <p> 023 * Accepts RDF in N-Quads format (quads with optional graph component) and converts it to Java beans, 024 * maps, 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-Quads string into a bean.</jc> 029 * String <jv>nQuads</jv> = ...; <jc>// N-Quads content</jc> 030 * Person <jv>person</jv> = NQuadsParser.<jsf>DEFAULT</jsf>.read(<jv>nQuads</jv>, Person.<jk>class</jk>); 031 * </p> 032 * <p class='bjava'> 033 * <jc>// Or use the NQuads marshaller for convenience.</jc> 034 * Person <jv>person</jv> = NQuads.<jsm>to</jsm>(<jv>nQuads</jv>, Person.<jk>class</jk>); 035 * </p> 036 * <p class='bjava'> 037 * <jc>// Custom parser with swaps.</jc> 038 * NQuadsParser <jv>p</jv> = NQuadsParser.create().swaps(DateSwap.<jk>class</jk>).build(); 039 * MyBean <jv>bean</jv> = <jv>p</jv>.read(<jv>nQuads</jv>, MyBean.<jk>class</jk>); 040 * </p> 041 * 042 * <h5 class='figure'>Example input (bean with name/age):</h5> 043 * <p class='bcode'> 044 * <...> <.../name> "Alice" <...> . 045 * <...> <.../age> "30"^^<http://www.w3.org/2001/XMLSchema#int> <...> . 046 * </p> 047 * 048 * <h5 class='figure'>Complex (nested address + array):</h5> 049 * <p class='bcode'> 050 * <...> <.../name> "Alice" <graph> . 051 * <...> <.../address> <.../address> <graph> . 052 * <.../address> <.../street> "123 Main St" <graph> . 053 * <.../address> <.../city> "Boston" <graph> . 054 * <.../address> <.../state> "MA" <graph> . 055 * </p> 056 * 057 * <h5 class='section'>Notes:</h5><ul> 058 * <li class='note'>This class is thread safe and reusable. 059 * </ul> 060 * 061 * <h5 class='section'>See Also:</h5><ul> 062 * <li class='link'>{doc jmr.RdfDetails} 063 * </ul> 064 */ 065@SuppressWarnings({ 066 "java:S110" // Deep inheritance inherent to the RDF parser hierarchy. 067}) 068public class NQuadsParser extends RdfParser { 069 070 /** Default N-Quads parser, all default settings.*/ 071 public static final NQuadsParser DEFAULT = new NQuadsParser(create()); 072 073 /** 074 * Creates a new builder for this object. 075 * 076 * @return A new builder. 077 */ 078 @SuppressWarnings({ 079 "java:S1452", // Builder<?> wildcard return intentional; callers chain via fluent API without needing the concrete type 080 "java:S9149" // Public Juneau DSL factory; hiding parent create() is intentional. 081 }) 082 public static RdfParser.Builder<?> create() { 083 return RdfParser.create().nQuads(); 084 } 085 086 /** 087 * Constructor. 088 * 089 * @param builder The builder for this object. 090 * <br>Cannot be <jk>null</jk>. 091 */ 092 public NQuadsParser(RdfParser.Builder<?> builder) { 093 super(builder.nQuads().consumes("application/n-quads")); 094 } 095}