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.parser.annotation; 018 019import org.apache.juneau.*; 020import org.apache.juneau.parser.*; 021import org.apache.juneau.reflect.*; 022import org.apache.juneau.svl.*; 023 024/** 025 * Utility classes and methods for the {@link ParserConfig @ParserConfig} annotation. 026 * 027 * <h5 class='section'>See Also:</h5><ul> 028 * <li class='link'><a class="doclink" href="https://juneau.apache.org/docs/topics/SerializersAndParsers">Serializers and Parsers</a> 029 * </ul> 030 */ 031public class ParserConfigAnnotation { 032 033 /** 034 * Applies {@link ParserConfig} annotations to a {@link org.apache.juneau.parser.Parser.Builder}. 035 */ 036 public static class ParserApply extends AnnotationApplier<ParserConfig,Parser.Builder> { 037 038 /** 039 * Constructor. 040 * 041 * @param vr The resolver for resolving values in annotations. 042 */ 043 public ParserApply(VarResolverSession vr) { 044 super(ParserConfig.class, Parser.Builder.class, vr); 045 } 046 047 @Override 048 public void apply(AnnotationInfo<ParserConfig> ai, Parser.Builder b) { 049 ParserConfig a = ai.inner(); 050 051 bool(a.autoCloseStreams()).ifPresent(x -> b.autoCloseStreams(x)); 052 integer(a.debugOutputLines(), "debugOutputLines").ifPresent(x -> b.debugOutputLines(x)); 053 type(a.listener()).ifPresent(x -> b.listener(x)); 054 bool(a.strict()).ifPresent(x -> b.strict(x)); 055 bool(a.trimStrings()).ifPresent(x -> b.trimStrings(x)); 056 bool(a.unbuffered()).ifPresent(x -> b.unbuffered(x)); 057 } 058 } 059 060 /** 061 * Applies {@link ParserConfig} annotations to a {@link org.apache.juneau.parser.InputStreamParser.Builder}. 062 */ 063 public static class InputStreamParserApply extends AnnotationApplier<ParserConfig,InputStreamParser.Builder> { 064 065 /** 066 * Constructor. 067 * 068 * @param vr The resolver for resolving values in annotations. 069 */ 070 public InputStreamParserApply(VarResolverSession vr) { 071 super(ParserConfig.class, InputStreamParser.Builder.class, vr); 072 } 073 074 @Override 075 public void apply(AnnotationInfo<ParserConfig> ai, InputStreamParser.Builder b) { 076 ParserConfig a = ai.inner(); 077 078 string(a.binaryFormat()).map(BinaryFormat::valueOf).ifPresent(x -> b.binaryFormat(x)); 079 } 080 } 081 082 /** 083 * Applies {@link ParserConfig} annotations to a {@link org.apache.juneau.parser.ReaderParser.Builder}. 084 */ 085 public static class ReaderParserApply extends AnnotationApplier<ParserConfig,ReaderParser.Builder> { 086 087 /** 088 * Constructor. 089 * 090 * @param vr The resolver for resolving values in annotations. 091 */ 092 public ReaderParserApply(VarResolverSession vr) { 093 super(ParserConfig.class, ReaderParser.Builder.class, vr); 094 } 095 096 @Override 097 public void apply(AnnotationInfo<ParserConfig> ai, ReaderParser.Builder b) { 098 ParserConfig a = ai.inner(); 099 100 charset(a.fileCharset()).ifPresent(x -> b.fileCharset(x)); 101 charset(a.streamCharset()).ifPresent(x -> b.streamCharset(x)); 102 } 103 } 104}