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 org.apache.juneau.parser.*; 016 017/** 018 * An implementation of {@link HttpPartParser} that takes in the strings and tries to convert them to POJOs using constructors and static create methods. 019 * 020 * <p> 021 * The class being created must be one of the following in order to convert it from a string: 022 * 023 * <ul> 024 * <li> 025 * An <jk>enum</jk>. 026 * <li> 027 * Have a public constructor with a single <c>String</c> parameter. 028 * <li> 029 * Have one of the following public static methods that takes in a single <c>String</c> parameter: 030 * <ul> 031 * <li><c>fromString</c> 032 * <li><c>fromValue</c> 033 * <li><c>valueOf</c> 034 * <li><c>parse</c> 035 * <li><c>parseString</c> 036 * <li><c>forName</c> 037 * <li><c>forString</c> 038 * </ul> 039 * </ul> 040 */ 041public class SimplePartParser extends BaseHttpPartParser { 042 043 //------------------------------------------------------------------------------------------------------------------- 044 // Predefined instances 045 //------------------------------------------------------------------------------------------------------------------- 046 047 /** Reusable instance of {@link SimplePartParser}, all default settings. */ 048 public static final SimplePartParser DEFAULT = new SimplePartParser(); 049 050 /** Reusable instance of {@link SimplePartParser}, all default settings. */ 051 public static final SimplePartParserSession DEFAULT_SESSION = DEFAULT.createPartSession(null); 052 053 054 //------------------------------------------------------------------------------------------------------------------- 055 // Instance 056 //------------------------------------------------------------------------------------------------------------------- 057 058 @Override 059 public SimplePartParserSession createPartSession(ParserSessionArgs args) { 060 return new SimplePartParserSession(); 061 } 062}