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.jso; 014 015import java.io.*; 016 017import org.apache.juneau.*; 018import org.apache.juneau.annotation.*; 019import org.apache.juneau.parser.*; 020 021/** 022 * Parses POJOs from HTTP responses as Java {@link ObjectInputStream ObjectInputStreams}. 023 * 024 * <h5 class='topic'>Media types</h5> 025 * 026 * Consumes <c>Content-Type</c> types: <bc>application/x-java-serialized-object</bc> 027 */ 028@ConfigurableContext 029public final class JsoParser extends InputStreamParser { 030 031 //------------------------------------------------------------------------------------------------------------------- 032 // Configurable properties 033 //------------------------------------------------------------------------------------------------------------------- 034 035 static final String PREFIX = "JsoParser"; 036 037 //------------------------------------------------------------------------------------------------------------------- 038 // Predefined instances 039 //------------------------------------------------------------------------------------------------------------------- 040 041 /** Default parser, all default settings.*/ 042 public static final JsoParser DEFAULT = new JsoParser(PropertyStore.DEFAULT); 043 044 //------------------------------------------------------------------------------------------------------------------- 045 // Instance 046 //------------------------------------------------------------------------------------------------------------------- 047 048 /** 049 * Constructor. 050 * 051 * @param ps The property store containing all the settings for this object. 052 */ 053 public JsoParser(PropertyStore ps) { 054 super(ps, "application/x-java-serialized-object"); 055 } 056 057 @Override /* Context */ 058 public JsoParserBuilder builder() { 059 return new JsoParserBuilder(getPropertyStore()); 060 } 061 062 /** 063 * Instantiates a new clean-slate {@link JsoParserBuilder} object. 064 * 065 * <p> 066 * This is equivalent to simply calling <code><jk>new</jk> JsoParserBuilder()</code>. 067 * 068 * <p> 069 * Note that this method creates a builder initialized to all default settings, whereas {@link #builder()} copies 070 * the settings of the object called on. 071 * 072 * @return A new {@link JsoParserBuilder} object. 073 */ 074 public static JsoParserBuilder create() { 075 return new JsoParserBuilder(); 076 } 077 078 @Override /* Parser */ 079 public JsoParserSession createSession() { 080 return createSession(createDefaultSessionArgs()); 081 } 082 083 @Override /* Parser */ 084 public JsoParserSession createSession(ParserSessionArgs args) { 085 return new JsoParserSession(args); 086 } 087 088 //----------------------------------------------------------------------------------------------------------------- 089 // Other methods 090 //----------------------------------------------------------------------------------------------------------------- 091 092 @Override /* Context */ 093 public ObjectMap toMap() { 094 return super.toMap() 095 .append("JsoParser", new DefaultFilteringObjectMap() 096 ); 097 } 098}