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.httppart; 014 015import java.lang.reflect.*; 016 017import org.apache.juneau.*; 018import org.apache.juneau.parser.*; 019 020/** 021 * An implementation of {@link HttpPartParser} that takes in the strings and tries to convert them to POJOs using constructors and static create methods. 022 * 023 * <p> 024 * The class being created must be one of the following in order to convert it from a string: 025 * 026 * <ul> 027 * <li> 028 * An <jk>enum</jk>. 029 * <li> 030 * Have a public constructor with a single <code>String</code> parameter. 031 * <li> 032 * Have one of the following public static methods that takes in a single <code>String</code> parameter: 033 * <ul> 034 * <li><code>fromString</code> 035 * <li><code>fromValue</code> 036 * <li><code>valueOf</code> 037 * <li><code>parse</code> 038 * <li><code>parseString</code> 039 * <li><code>forName</code> 040 * <li><code>forString</code> 041 * </ul> 042 * </ul> 043 */ 044public class SimplePartParser extends BaseHttpPartParser { 045 046 //------------------------------------------------------------------------------------------------------------------- 047 // Predefined instances 048 //------------------------------------------------------------------------------------------------------------------- 049 050 /** Reusable instance of {@link SimplePartParser}, all default settings. */ 051 public static final SimplePartParser DEFAULT = new SimplePartParser(); 052 053 //------------------------------------------------------------------------------------------------------------------- 054 // Instance 055 //------------------------------------------------------------------------------------------------------------------- 056 057 @Override 058 public SimplePartParserSession createPartSession(ParserSessionArgs args) { 059 return new SimplePartParserSession(); 060 } 061 062 @Override /* HttpPartParser */ 063 public <T> T parse(HttpPartType partType, HttpPartSchema schema, String in, Class<T> toType) throws ParseException, SchemaValidationException { 064 return createPartSession().parse(partType, schema, in, toType); 065 } 066 067 @Override /* HttpPartParser */ 068 public <T> T parse(HttpPartType partType, HttpPartSchema schema, String in, Type toType, Type...toTypeArgs) throws ParseException, SchemaValidationException { 069 return createPartSession().parse(partType, schema, in, toType, toTypeArgs); 070 } 071 072 /** 073 * @deprecated Unused. 074 */ 075 @Override 076 @Deprecated 077 public <T> T parse(HttpPartType partType, String in, ClassMeta<T> type) throws ParseException { 078 return null; 079 } 080}