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.csv; 014 015import java.io.IOException; 016import java.lang.reflect.*; 017import java.nio.charset.*; 018import java.util.*; 019import java.util.function.*; 020 021import org.apache.juneau.*; 022import org.apache.juneau.httppart.*; 023import org.apache.juneau.internal.*; 024import org.apache.juneau.parser.*; 025 026/** 027 * Session object that lives for the duration of a single use of {@link CsvParser}. 028 * 029 * <h5 class='section'>Notes:</h5><ul> 030 * <li class='warn'>This class is not thread safe and is typically discarded after one use. 031 * </ul> 032 * 033 * <h5 class='section'>See Also:</h5><ul> 034 035 * </ul> 036 */ 037public final class CsvParserSession extends ReaderParserSession { 038 039 //------------------------------------------------------------------------------------------------------------------- 040 // Static 041 //------------------------------------------------------------------------------------------------------------------- 042 043 /** 044 * Creates a new builder for this object. 045 * 046 * @param ctx The context creating this session. 047 * @return A new builder. 048 */ 049 public static Builder create(CsvParser ctx) { 050 return new Builder(ctx); 051 } 052 053 //------------------------------------------------------------------------------------------------------------------- 054 // Builder 055 //------------------------------------------------------------------------------------------------------------------- 056 057 /** 058 * Builder class. 059 */ 060 @FluentSetters 061 public static class Builder extends ReaderParserSession.Builder { 062 063 CsvParser ctx; 064 065 /** 066 * Constructor 067 * 068 * @param ctx The context creating this session. 069 */ 070 protected Builder(CsvParser ctx) { 071 super(ctx); 072 this.ctx = ctx; 073 } 074 075 @Override 076 public CsvParserSession build() { 077 return new CsvParserSession(this); 078 } 079 080 // <FluentSetters> 081 082 @Override /* GENERATED - org.apache.juneau.ContextSession.Builder */ 083 public <T> Builder apply(Class<T> type, Consumer<T> apply) { 084 super.apply(type, apply); 085 return this; 086 } 087 088 @Override /* GENERATED - org.apache.juneau.ContextSession.Builder */ 089 public Builder debug(Boolean value) { 090 super.debug(value); 091 return this; 092 } 093 094 @Override /* GENERATED - org.apache.juneau.ContextSession.Builder */ 095 public Builder properties(Map<String,Object> value) { 096 super.properties(value); 097 return this; 098 } 099 100 @Override /* GENERATED - org.apache.juneau.ContextSession.Builder */ 101 public Builder property(String key, Object value) { 102 super.property(key, value); 103 return this; 104 } 105 106 @Override /* GENERATED - org.apache.juneau.ContextSession.Builder */ 107 public Builder unmodifiable() { 108 super.unmodifiable(); 109 return this; 110 } 111 112 @Override /* GENERATED - org.apache.juneau.BeanSession.Builder */ 113 public Builder locale(Locale value) { 114 super.locale(value); 115 return this; 116 } 117 118 @Override /* GENERATED - org.apache.juneau.BeanSession.Builder */ 119 public Builder localeDefault(Locale value) { 120 super.localeDefault(value); 121 return this; 122 } 123 124 @Override /* GENERATED - org.apache.juneau.BeanSession.Builder */ 125 public Builder mediaType(MediaType value) { 126 super.mediaType(value); 127 return this; 128 } 129 130 @Override /* GENERATED - org.apache.juneau.BeanSession.Builder */ 131 public Builder mediaTypeDefault(MediaType value) { 132 super.mediaTypeDefault(value); 133 return this; 134 } 135 136 @Override /* GENERATED - org.apache.juneau.BeanSession.Builder */ 137 public Builder timeZone(TimeZone value) { 138 super.timeZone(value); 139 return this; 140 } 141 142 @Override /* GENERATED - org.apache.juneau.BeanSession.Builder */ 143 public Builder timeZoneDefault(TimeZone value) { 144 super.timeZoneDefault(value); 145 return this; 146 } 147 148 @Override /* GENERATED - org.apache.juneau.parser.ParserSession.Builder */ 149 public Builder javaMethod(Method value) { 150 super.javaMethod(value); 151 return this; 152 } 153 154 @Override /* GENERATED - org.apache.juneau.parser.ParserSession.Builder */ 155 public Builder outer(Object value) { 156 super.outer(value); 157 return this; 158 } 159 160 @Override /* GENERATED - org.apache.juneau.parser.ParserSession.Builder */ 161 public Builder schema(HttpPartSchema value) { 162 super.schema(value); 163 return this; 164 } 165 166 @Override /* GENERATED - org.apache.juneau.parser.ParserSession.Builder */ 167 public Builder schemaDefault(HttpPartSchema value) { 168 super.schemaDefault(value); 169 return this; 170 } 171 172 @Override /* GENERATED - org.apache.juneau.parser.ReaderParserSession.Builder */ 173 public Builder fileCharset(Charset value) { 174 super.fileCharset(value); 175 return this; 176 } 177 178 @Override /* GENERATED - org.apache.juneau.parser.ReaderParserSession.Builder */ 179 public Builder streamCharset(Charset value) { 180 super.streamCharset(value); 181 return this; 182 } 183 184 // </FluentSetters> 185 } 186 187 //------------------------------------------------------------------------------------------------------------------- 188 // Instance 189 //------------------------------------------------------------------------------------------------------------------- 190 191 /** 192 * Constructor. 193 * 194 * @param builder The builder for this object. 195 */ 196 protected CsvParserSession(Builder builder) { 197 super(builder); 198 } 199 200 @Override /* ParserSession */ 201 protected <T> T doParse(ParserPipe pipe, ClassMeta<T> type) throws IOException, ParseException { 202 try (ParserReader r = pipe.getParserReader()) { 203 if (r == null) 204 return null; 205 return parseAnything(type, r, getOuter(), null); 206 } 207 } 208 209 private <T> T parseAnything(ClassMeta<T> eType, ParserReader r, Object outer, BeanPropertyMeta pMeta) throws ParseException { 210 throw new ParseException("Not implemented."); 211 } 212}