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;
014
015import static org.apache.juneau.BeanContext.*;
016
017import java.util.*;
018
019import org.apache.juneau.http.*;
020import org.apache.juneau.httppart.*;
021
022/**
023 * Runtime arguments common to all bean, serializer, and parser sessions.
024 */
025public class BeanSessionArgs extends SessionArgs {
026
027   /**
028    * Default empty session arguments.
029    */
030   public static final BeanSessionArgs DEFAULT = new BeanSessionArgs();
031
032   HttpPartSchema schema;
033
034   /**
035    * Constructor
036    */
037   public BeanSessionArgs() {}
038
039   /**
040    * Static creator method.
041    *
042    * @return A new {@link BeanSessionArgs} object.
043    */
044   public static BeanSessionArgs create() {
045      return new BeanSessionArgs();
046   }
047
048   //-----------------------------------------------------------------------------------------------------------------
049   // Properties.
050   //-----------------------------------------------------------------------------------------------------------------
051
052   /**
053    * Debug mode.
054    *
055    * <p>
056    * Enables the following additional information during parsing:
057    * <ul>
058    *    <li> When bean setters throws exceptions, the exception includes the object stack information in order to determine how that method was invoked.
059    * </ul>
060    *
061    * <p>
062    * If not specified, defaults to {@link BeanContext#BEAN_debug}.
063    *
064    * @param value
065    *    The new value for this property.
066    *    <br>Can be <jk>null</jk>.
067    * @return This object (for method chaining).
068    */
069   public BeanSessionArgs debug(Boolean value) {
070      property(BEAN_debug, value);
071      return this;
072   }
073
074   /**
075    * The session locale.
076    *
077    * <p>
078    * Specifies the default locale for serializer and parser sessions.
079    *
080    * <p>
081    * If not specified, defaults to {@link BeanContext#BEAN_locale}.
082    *
083    * @param value
084    *    The new value for this property.
085    *    <br>If <jk>null</jk>, then the locale defined on the context is used.
086    * @return This object (for method chaining).
087    */
088   public BeanSessionArgs locale(Locale value) {
089      property(BEAN_locale, value);
090      return this;
091   }
092
093   /**
094    * The session media type.
095    *
096    * <p>
097    * Specifies the default media type value for serializer and parser sessions.
098    *
099    * <p>
100    * If not specified, defaults to {@link BeanContext#BEAN_mediaType}.
101    *
102    * @param value
103    *    The new value for this property.
104    *    <br>Can be <jk>null</jk>.
105    * @return This object (for method chaining).
106    */
107   public BeanSessionArgs mediaType(MediaType value) {
108      property(BEAN_mediaType, value);
109      return this;
110   }
111
112   /**
113    * HTTP-part schema.
114    *
115    * <p>
116    * Used for schema-based serializers and parsers to define additional formatting.
117    *
118    * @param value
119    *    The new value for this property.
120    *    <br>Can be <jk>null</jk>.
121    * @return This object (for method chaining).
122    */
123   public BeanSessionArgs schema(HttpPartSchema value) {
124      this.schema = value;
125      return this;
126   }
127
128   /**
129    * The session timezone.
130    *
131    * <p>
132    * Specifies the default timezone for serializer and parser sessions.
133    *
134    * <p>
135    * If not specified, defaults to {@link BeanContext#BEAN_timeZone}.
136    *
137    * @param value
138    *    The new value for this property.
139    *    <br>Can be <jk>null</jk>.
140    * @return This object (for method chaining).
141    */
142   public BeanSessionArgs timeZone(TimeZone value) {
143      property(BEAN_timeZone, value);
144      return this;
145   }
146
147   @Override /* SessionArgs */
148   public BeanSessionArgs properties(ObjectMap value) {
149      super.properties(value);
150      return this;
151   }
152
153   @Override /* SessionArgs */
154   public BeanSessionArgs property(String key, Object value) {
155      super.property(key, value);
156      return this;
157   }
158
159   @Override /* SessionArgs */
160   public ObjectMap toMap() {
161      return super.toMap()
162         .append("BeanSessionArgs", new DefaultFilteringObjectMap()
163            .append("schema", schema)
164         );
165   }
166}