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.*;
016import org.apache.juneau.serializer.*;
017
018/**
019 * Base class for implementations of {@link HttpPartSerializer}
020 *
021 * <h5 class='section'>Notes:</h5><ul>
022 *    <li class='note'>This class is thread safe and reusable.
023 * </ul>
024 *
025 * <h5 class='section'>See Also:</h5><ul>
026 *    <li class='link'><a class="doclink" href="../../../../index.html#jm.HttpPartSerializersParsers">HTTP Part Serializers and Parsers</a>
027 * </ul>
028 */
029public abstract class BaseHttpPartSerializer extends BeanContextable implements HttpPartSerializer {
030
031   //-------------------------------------------------------------------------------------------------------------------
032   // Builder
033   //-------------------------------------------------------------------------------------------------------------------
034
035   /**
036    * Builder class.
037    */
038   public abstract static class Builder extends BeanContextable.Builder {
039
040      /**
041       * Constructor.
042       */
043      protected Builder() {
044         super();
045      }
046
047      /**
048       * Copy constructor.
049       * @param builder The existing builder to copy.
050       */
051      protected Builder(Builder builder) {
052         super(builder);
053      }
054   }
055
056   //-------------------------------------------------------------------------------------------------------------------
057   // Instance
058   //-------------------------------------------------------------------------------------------------------------------
059
060   /**
061    * Constructor.
062    *
063    * @param builder The builder for this object.
064    */
065   protected BaseHttpPartSerializer(Builder builder) {
066      super(builder);
067   }
068
069   /**
070    * Converts the specified value to a string that can be used as an HTTP header value, query parameter value,
071    * form-data parameter, or URI path variable.
072    *
073    * <p>
074    * Returned values should NOT be URL-encoded.
075    *
076    * @param partType The category of value being serialized.
077    * @param schema
078    *    Schema information about the part.
079    *    <br>May be <jk>null</jk>.
080    *    <br>Not all part serializers use the schema information.
081    * @param value The value being serialized.
082    * @return The serialized value.
083    * @throws SerializeException If a problem occurred while trying to parse the input.
084    * @throws SchemaValidationException If the output fails schema validation.
085    */
086   public String serialize(HttpPartType partType, HttpPartSchema schema, Object value) throws SchemaValidationException, SerializeException {
087      return getPartSession().serialize(partType, schema, value);
088   }
089}