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.cp.*;
019
020/**
021 * Interface used to convert HTTP headers, query parameters, form-data parameters, and URI path variables to POJOs
022 *
023 * <p>
024 * The following default implementations are provided:
025 * <ul class='doctree'>
026 *    <li class='jc'>{@link org.apache.juneau.oapi.OpenApiParser} - Parts encoded in based on OpenAPI schema.
027 *    <li class='jc'>{@link org.apache.juneau.uon.UonParser} - Parts encoded in UON notation.
028 *    <li class='jc'>{@link org.apache.juneau.httppart.SimplePartParser} - Parts encoded in plain text.
029 * </ul>
030 *
031 * <p>
032 * Implementations must include either a public no-args constructor.
033 *
034 * <h5 class='section'>See Also:</h5><ul>
035 *    <li class='link'><a class="doclink" href="../../../../index.html#jm.HttpPartSerializersParsers">HTTP Part Serializers and Parsers</a>
036 * </ul>
037 */
038public interface HttpPartParser {
039
040   //-----------------------------------------------------------------------------------------------------------------
041   // Static
042   //-----------------------------------------------------------------------------------------------------------------
043
044   /**
045    * Represent "no" part parser.
046    *
047    * <p>
048    * Used to represent the absence of a part parser in annotations.
049    */
050   public static interface Void extends HttpPartParser {}
051
052   /**
053    * Instantiates a creator for a part parser.
054    * @return A new creator.
055    */
056   public static Creator creator() {
057      return new Creator();
058   }
059
060   //-----------------------------------------------------------------------------------------------------------------
061   // Creator
062   //-----------------------------------------------------------------------------------------------------------------
063
064   /**
065    * A creator for a part parser.
066    */
067   public static class Creator extends ContextBeanCreator<HttpPartParser> {
068      Creator() {
069         super(HttpPartParser.class);
070      }
071
072      Creator(Creator creator) {
073         super(creator);
074      }
075
076      @Override
077      public Creator impl(Object value) {
078         super.impl(value);
079         return this;
080      }
081
082      @Override
083      public Creator type(Class<? extends HttpPartParser> value) {
084         super.type(value);
085         return this;
086      }
087
088      @Override
089      public Creator copy() {
090         return new Creator(this);
091      }
092
093      /**
094       * Associates an existing bean context builder with this part parser.
095       *
096       * @param value The value for this setting.
097       * @return This object.
098       */
099      public Creator beanContext(BeanContext.Builder value) {
100         builder(BeanContextable.Builder.class).ifPresent(x -> x.beanContext(value));
101         return this;
102      }
103   }
104
105   //-----------------------------------------------------------------------------------------------------------------
106   // Instance
107   //-----------------------------------------------------------------------------------------------------------------
108
109   /**
110    * Creates a new parser session.
111    *
112    * @return A new parser session.
113    */
114   public HttpPartParserSession getPartSession();
115
116   /**
117    * Returns metadata about the specified class.
118    *
119    * @param <T> The class type.
120    * @param c The class type.
121    * @return Metadata about the specified class.
122    */
123   public <T> ClassMeta<T> getClassMeta(Class<T> c);
124
125   /**
126    * Returns metadata about the specified class.
127    *
128    * @param <T> The class type.
129    * @param t The class type.
130    * @param args The class type args.
131    * @return Metadata about the specified class.
132    */
133   public <T> ClassMeta<T> getClassMeta(Type t, Type...args);
134}