Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
// ***************************************************************************************************************************
// * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file *
// * distributed with this work for additional information regarding copyright ownership. The ASF licenses this file *
// * to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance *
// * with the License. You may obtain a copy of the License at *
// * *
// * http://www.apache.org/licenses/LICENSE-2.0 *
// * *
// * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an *
// * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the *
// * specific language governing permissions and limitations under the License. *
// ***************************************************************************************************************************
package org.apache.juneau.parser;
import static org.apache.juneau.internal.CollectionUtils.*;
import static org.apache.juneau.internal.ObjectUtils.*;
import static java.util.stream.Collectors.*;
import java.util.*;
import java.util.concurrent.*;
import java.util.function.*;
import java.util.stream.*;
import org.apache.juneau.*;
import org.apache.juneau.cp.*;
import org.apache.juneau.internal.*;
import org.apache.juneau.reflect.*;
/**
* Represents a group of {@link Parser Parsers} that can be looked up by media type.
*
*
Description
*
* Provides the following features:
*
*
* Finds parsers based on HTTP Content-Type header values.
*
* Sets common properties on all parsers in a single method call.
*
* Locks all parsers in a single method call.
*
* Clones existing groups and all parsers within the group in a single method call.
*
*
*
Match ordering
*
* Parsers are matched against Content-Type strings in the order they exist in this group.
*
*
* Adding new entries will cause the entries to be prepended to the group.
* This allows for previous parsers to be overridden through subsequent calls.
*
*
* For example, calling g.append(P1.class,P2.class).append(P3.class,P4.class)
* will result in the order P3, P4, P1, P2.
*
*
Example:
*
* // Construct a new parser group builder
* ParserSet parsers = ParserSet.create();
* .add(JsonParser.class, XmlParser.class); // Add some parsers to it
* .forEach(x -> x.swaps(CalendarSwap.IsoLocalDateTime.class))
* .forEach(x -> x.beansRequireSerializable())
* .build();
*
* // Find the appropriate parser by Content-Type
* ReaderParser parser = (ReaderParser)parsers.getParser("text/json");
*
* // Parse a bean from JSON
* String json = "{...}";
* AddressBook addressBook = parser.parse(json, AddressBook.class);
*
*/
public final class ParserSet {
//-----------------------------------------------------------------------------------------------------------------
// Static
//-----------------------------------------------------------------------------------------------------------------
/**
* An identifier that the previous entries in this group should be inherited.
*
* Used by {@link ParserSet.Builder#set(Class...)}
*/
@SuppressWarnings("javadoc")
public static abstract class Inherit extends Parser {
protected Inherit(Parser.Builder builder) {
super(builder);
}
}
/**
* An identifier that the previous entries in this group should not be inherited.
*
* Used by {@link ParserSet.Builder#add(Class...)}
*/
@SuppressWarnings("javadoc")
public static abstract class NoInherit extends Parser {
protected NoInherit(Parser.Builder builder) {
super(builder);
}
}
/**
* Static creator.
*
* @param beanStore The bean store to use for creating beans.
* @return A new builder for this object.
*/
public static Builder create(BeanStore beanStore) {
return new Builder(beanStore);
}
/**
* Static creator.
*
* @return A new builder for this object.
*/
public static Builder create() {
return new Builder(BeanStore.INSTANCE);
}
//-----------------------------------------------------------------------------------------------------------------
// Builder
//-----------------------------------------------------------------------------------------------------------------
/**
* Builder class.
*/
@FluentSetters
public static class Builder extends BeanBuilder {
List