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.msgpack;
014
015import org.apache.juneau.*;
016import org.apache.juneau.parser.*;
017
018/**
019 * Parses a MessagePack stream into a POJO model.
020 * 
021 * <h5 class='topic'>Media types</h5>
022 * 
023 * Handles <code>Content-Type</code> types:  <code><b>octal/msgpack</b></code>
024 */
025public class MsgPackParser extends InputStreamParser {
026
027   //-------------------------------------------------------------------------------------------------------------------
028   // Predefined instances
029   //-------------------------------------------------------------------------------------------------------------------
030
031   /** Default parser, all default settings.*/
032   public static final MsgPackParser DEFAULT = new MsgPackParser(PropertyStore.DEFAULT);
033
034
035   //-------------------------------------------------------------------------------------------------------------------
036   // Instance
037   //-------------------------------------------------------------------------------------------------------------------
038
039   /**
040    * Constructor.
041    * 
042    * @param ps The property store containing all the settings for this object.
043    */
044   public MsgPackParser(PropertyStore ps) {
045      super(ps, "octal/msgpack");
046   }
047
048   @Override /* Context */
049   public MsgPackParserBuilder builder() {
050      return new MsgPackParserBuilder(getPropertyStore());
051   }
052
053   /**
054    * Instantiates a new clean-slate {@link MsgPackParserBuilder} object.
055    * 
056    * <p>
057    * This is equivalent to simply calling <code><jk>new</jk> MsgPackParserBuilder()</code>.
058    * 
059    * <p>
060    * Note that this method creates a builder initialized to all default settings, whereas {@link #builder()} copies 
061    * the settings of the object called on.
062    * 
063    * @return A new {@link MsgPackParserBuilder} object.
064    */
065   public static MsgPackParserBuilder create() {
066      return new MsgPackParserBuilder();
067   }
068
069   @Override /* Parser */
070   public MsgPackParserSession createSession(ParserSessionArgs args) {
071      return new MsgPackParserSession(this, args);
072   }
073
074   @Override /* Context */
075   public ObjectMap asMap() {
076      return super.asMap()
077         .append("MsgPackParser", new ObjectMap());
078   }
079}