001// *************************************************************************************************************************** 002// * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file * 003// * distributed with this work for additional information regarding copyright ownership. The ASF licenses this file * 004// * to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance * 005// * with the License. You may obtain a copy of the License at * 006// * * 007// * http://www.apache.org/licenses/LICENSE-2.0 * 008// * * 009// * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an * 010// * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the * 011// * specific language governing permissions and limitations under the License. * 012// *************************************************************************************************************************** 013package org.apache.juneau.parser; 014 015import java.lang.reflect.*; 016import java.nio.charset.*; 017import java.util.*; 018 019import org.apache.juneau.*; 020import org.apache.juneau.collections.*; 021import org.apache.juneau.http.*; 022import org.apache.juneau.httppart.*; 023import org.apache.juneau.internal.*; 024 025/** 026 * Runtime arguments common to all parser sessions. 027 */ 028public final class ParserSessionArgs extends BeanSessionArgs { 029 030 Method javaMethod; 031 Object outer; 032 033 /** 034 * Default parser session args. 035 */ 036 public static final ParserSessionArgs DEFAULT = new ParserSessionArgs(); 037 038 /** 039 * Creator. 040 * 041 * @return A new parser session arguments object. 042 */ 043 public static final ParserSessionArgs create() { 044 return new ParserSessionArgs(); 045 } 046 047 //----------------------------------------------------------------------------------------------------------------- 048 // Properties. 049 //----------------------------------------------------------------------------------------------------------------- 050 051 /** 052 * File charset. 053 * 054 * <p> 055 * The character set to use for reading Files from the file system. 056 * 057 * <p> 058 * Used when passing in files to {@link Parser#parse(Object, Class)}. 059 * 060 * <p> 061 * If not specified, defaults to the JVM system default charset. 062 * 063 * @param value 064 * The new property value. 065 * <br>Can be <jk>null</jk>. 066 * @return This object (for method chaining). 067 */ 068 @FluentSetter 069 public ParserSessionArgs fileCharset(Charset value) { 070 property(ReaderParser.RPARSER_fileCharset, value); 071 return this; 072 } 073 074 /** 075 * The java method that called this serializer, usually the method in a REST servlet. 076 * 077 * @param value 078 * The new property value. 079 * <br>Can be <jk>null</jk>. 080 * @return This object (for method chaining). 081 */ 082 @FluentSetter 083 public ParserSessionArgs javaMethod(Method value) { 084 this.javaMethod = value; 085 return this; 086 } 087 088 /** 089 * The outer object for instantiating top-level non-static inner classes. 090 * 091 * @param value 092 * The new property value. 093 * <br>Can be <jk>null</jk>. 094 * @return This object (for method chaining). 095 */ 096 @FluentSetter 097 public ParserSessionArgs outer(Object value) { 098 this.outer = value; 099 return this; 100 } 101 102 /** 103 * Input stream charset. 104 * 105 * <p> 106 * The character set to use for converting InputStreams and byte arrays to readers. 107 * 108 * <p> 109 * Used when passing in input streams and byte arrays to {@link Parser#parse(Object, Class)}. 110 * 111 * <p> 112 * If not specified, defaults to UTF-8. 113 * 114 * @param value 115 * The new property value. 116 * <br>Can be <jk>null</jk>. 117 * @return This object (for method chaining). 118 */ 119 @FluentSetter 120 public ParserSessionArgs streamCharset(Charset value) { 121 property(ReaderParser.RPARSER_streamCharset, value); 122 return this; 123 } 124 125 // <FluentSetters> 126 127 @Override /* GENERATED - SessionArgs */ 128 public ParserSessionArgs debug(Boolean value) { 129 super.debug(value); 130 return this; 131 } 132 133 @Override /* GENERATED - SessionArgs */ 134 public ParserSessionArgs locale(Locale value) { 135 super.locale(value); 136 return this; 137 } 138 139 @Override /* GENERATED - SessionArgs */ 140 public ParserSessionArgs mediaType(MediaType value) { 141 super.mediaType(value); 142 return this; 143 } 144 145 @Override /* GENERATED - SessionArgs */ 146 public ParserSessionArgs properties(OMap value) { 147 super.properties(value); 148 return this; 149 } 150 151 @Override /* GENERATED - SessionArgs */ 152 public ParserSessionArgs property(String key, Object value) { 153 super.property(key, value); 154 return this; 155 } 156 157 @Override /* GENERATED - SessionArgs */ 158 public ParserSessionArgs timeZone(TimeZone value) { 159 super.timeZone(value); 160 return this; 161 } 162 163 @Override /* GENERATED - BeanSessionArgs */ 164 public ParserSessionArgs schema(HttpPartSchema value) { 165 super.schema(value); 166 return this; 167 } 168 169 // </FluentSetters> 170 171 //----------------------------------------------------------------------------------------------------------------- 172 // Other methods 173 //----------------------------------------------------------------------------------------------------------------- 174 175 @Override /* SessionArgs */ 176 public OMap toMap() { 177 return super.toMap() 178 .a("ParserSessionArgs", new DefaultFilteringOMap() 179 .a("javaMethod", javaMethod) 180 .a("outer", outer) 181 ); 182 } 183}