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
019import org.apache.juneau.commons.reflect.*;
020import org.apache.juneau.commons.svl.*;
021import org.apache.juneau.marshall.*;
022import org.apache.juneau.marshall.xml.*;
023
024/**
025 * Utility classes and methods for the {@link RdfConfig @RdfConfig} annotation.
026 *
027 * <h5 class='section'>See Also:</h5><ul>
028 *    <li class='link'>{doc jmr.RdfDetails}
029 * </ul>
030 */
031@SuppressWarnings({
032   "java:S1612", // Lambdas used instead of method references throughout; conditional checks before delegation prevent direct method ref conversion
033   "rawtypes" // Raw types required for reflective annotation application.
034})
035public class RdfConfigAnnotation {
036
037   private RdfConfigAnnotation() {}
038
039   /**
040    * Applies {@link RdfConfig} annotations to a {@link RdfParser.Builder}.
041    */
042   public static class ParserApply extends AnnotationApplier<RdfConfig,RdfParser.Builder> {
043
044      /**
045       * Constructor.
046       *
047       * @param vr The resolver for resolving values in annotations.
048       *    Must not be <jk>null</jk>.
049       */
050      public ParserApply(VarResolverSession vr) {
051         super(RdfConfig.class, RdfParser.Builder.class, vr);
052      }
053
054      @Override
055      public void apply(AnnotationInfo<RdfConfig> ai, RdfParser.Builder b) {
056         RdfConfig a = ai.inner();
057
058         string(a.language()).ifPresent(x -> b.language(x));
059         string(a.juneauNs()).map(Namespace::of).ifPresent(x -> b.juneauNs(x));
060         string(a.juneauBpNs()).map(Namespace::of).ifPresent(x -> b.juneauBpNs(x));
061         string(a.collectionFormat()).map(RdfCollectionFormat::valueOf).ifPresent(x -> b.collectionFormat(x));
062         bool(a.looseCollections()).ifPresent(x -> b.looseCollections(x));
063         bool(a.trimWhitespace()).ifPresent(x -> b.trimWhitespace(x));
064         string(a.rdfxml_iriRules()).ifPresent(x -> b.rdfxml_iriRules(x));
065         string(a.rdfxml_errorMode()).ifPresent(x -> b.rdfxml_errorMode(x));
066         bool(a.rdfxml_embedding()).ifPresent(x -> b.rdfxml_embedding(x));
067         string(a.rdfxml_xmlBase()).ifPresent(x -> b.rdfxml_xmlbase(x));
068         bool(a.rdfxml_longId()).ifPresent(x -> b.rdfxml_longId(x));
069         bool(a.rdfxml_allowBadUris()).ifPresent(x -> b.rdfxml_allowBadUris(x));
070         string(a.rdfxml_relativeUris()).ifPresent(x -> b.rdfxml_relativeUris(x));
071         string(a.rdfxml_showXmlDeclaration()).ifPresent(x -> b.rdfxml_showXmlDeclaration(x));
072         bool(a.rdfxml_disableShowDoctypeDeclaration()).ifPresent(x -> b.rdfxml_disableShowDoctypeDeclaration(x));
073         integer(a.rdfxml_tab(), "rdfxml_tab").ifPresent(x -> b.rdfxml_tab(x));
074         string(a.rdfxml_attributeQuoteChar()).map(x -> x.charAt(0)).ifPresent(x -> b.rdfxml_attributeQuoteChar(x));
075         string(a.rdfxml_blockRules()).ifPresent(x -> b.rdfxml_blockRules(x));
076         integer(a.n3_minGap(), "n3_minGap").ifPresent(x -> b.n3_minGap(x));
077         bool(a.n3_disableObjectLists()).ifPresent(x -> b.n3_disableObjectLists(x));
078         integer(a.n3_subjectColumn(), "n3_subjectColumn").ifPresent(x -> b.n3_subjectColumn(x));
079         integer(a.n3_propertyColumn(), "n3_propertyColumn").ifPresent(x -> b.n3_propertyColumn(x));
080         integer(a.n3_indentProperty(), "n3_indentProperty").ifPresent(x -> b.n3_indentProperty(x));
081         integer(a.n3_widePropertyLen(), "n3_widePropertyLen").ifPresent(x -> b.n3_widePropertyLen(x));
082         bool(a.n3_disableAbbrevBaseUri()).ifPresent(x -> b.n3_disableAbbrevBaseUri(x));
083         bool(a.n3_disableUsePropertySymbols()).ifPresent(x -> b.n3_disableUsePropertySymbols(x));
084         bool(a.n3_disableUseTripleQuotedStrings()).ifPresent(x -> b.n3_disableUseTripleQuotedStrings(x));
085         bool(a.n3_disableUseDoubles()).ifPresent(x -> b.n3_disableUseDoubles(x));
086      }
087   }
088
089   /**
090    * Applies {@link RdfConfig} annotations to a {@link RdfSerializer.Builder}.
091    */
092   public static class SerializerApply extends AnnotationApplier<RdfConfig,RdfSerializer.Builder> {
093
094      /**
095       * Constructor.
096       *
097       * @param vr The resolver for resolving values in annotations.
098       *    Must not be <jk>null</jk>.
099       */
100      public SerializerApply(VarResolverSession vr) {
101         super(RdfConfig.class, RdfSerializer.Builder.class, vr);
102      }
103
104      @Override
105      public void apply(AnnotationInfo<RdfConfig> ai, RdfSerializer.Builder b) {
106         RdfConfig a = ai.inner();
107
108         string(a.language()).ifPresent(x -> b.language(x));
109         string(a.juneauNs()).map(Namespace::of).ifPresent(x -> b.juneauNs(x));
110         string(a.juneauBpNs()).map(Namespace::of).ifPresent(x -> b.juneauBpNs(x));
111         bool(a.disableUseXmlNamespaces()).ifPresent(x -> b.disableUseXmlNamespaces(x));
112         string(a.collectionFormat()).map(RdfCollectionFormat::valueOf).ifPresent(x -> b.collectionFormat(x));
113         bool(a.looseCollections()).ifPresent(x -> b.looseCollections(x));
114         bool(a.addBeanTypes()).ifPresent(x -> b.addBeanTypesRdf(x));
115         bool(a.addLiteralTypes()).ifPresent(x -> b.addLiteralTypes(x));
116         bool(a.addRootProperty()).ifPresent(x -> b.addRootProperty(x));
117         bool(a.disableAutoDetectNamespaces()).ifPresent(x -> b.disableAutoDetectNamespaces(x));
118         strings(a.namespaces()).map(Namespace::createArray).ifPresent(x -> b.namespaces(x));
119         string(a.rdfxml_iriRules()).ifPresent(x -> b.rdfxml_iriRules(x));
120         string(a.rdfxml_errorMode()).ifPresent(x -> b.rdfxml_errorMode(x));
121         bool(a.rdfxml_embedding()).ifPresent(x -> b.rdfxml_embedding(x));
122         string(a.rdfxml_xmlBase()).ifPresent(x -> b.rdfxml_xmlbase(x));
123         bool(a.rdfxml_longId()).ifPresent(x -> b.rdfxml_longId(x));
124         bool(a.rdfxml_allowBadUris()).ifPresent(x -> b.rdfxml_allowBadUris(x));
125         string(a.rdfxml_relativeUris()).ifPresent(x -> b.rdfxml_relativeUris(x));
126         string(a.rdfxml_showXmlDeclaration()).ifPresent(x -> b.rdfxml_showXmlDeclaration(x));
127         bool(a.rdfxml_disableShowDoctypeDeclaration()).ifPresent(x -> b.rdfxml_disableShowDoctypeDeclaration(x));
128         integer(a.rdfxml_tab(), "rdfxml_tab").ifPresent(x -> b.rdfxml_tab(x));
129         string(a.rdfxml_attributeQuoteChar()).map(x -> x.charAt(0)).ifPresent(x -> b.rdfxml_attributeQuoteChar(x));
130         string(a.rdfxml_blockRules()).ifPresent(x -> b.rdfxml_blockRules(x));
131         integer(a.n3_minGap(), "n3_minGap").ifPresent(x -> b.n3_minGap(x));
132         bool(a.n3_disableObjectLists()).ifPresent(x -> b.n3_disableObjectLists(x));
133         integer(a.n3_subjectColumn(), "n3_subjectColumn").ifPresent(x -> b.n3_subjectColumn(x));
134         integer(a.n3_propertyColumn(), "n3_propertyColumn").ifPresent(x -> b.n3_propertyColumn(x));
135         integer(a.n3_indentProperty(), "n3_indentProperty").ifPresent(x -> b.n3_indentProperty(x));
136         integer(a.n3_widePropertyLen(), "n3_widePropertyLen").ifPresent(x -> b.n3_widePropertyLen(x));
137         bool(a.n3_disableAbbrevBaseUri()).ifPresent(x -> b.n3_disableAbbrevBaseUri(x));
138         bool(a.n3_disableUsePropertySymbols()).ifPresent(x -> b.n3_disableUsePropertySymbols(x));
139         bool(a.n3_disableUseTripleQuotedStrings()).ifPresent(x -> b.n3_disableUseTripleQuotedStrings(x));
140         bool(a.n3_disableUseDoubles()).ifPresent(x -> b.n3_disableUseDoubles(x));
141      }
142   }
143}