All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.landawn.abacus.parser.ParserFactory Maven / Gradle / Ivy

Go to download

A general programming library in Java/Android. It's easy to learn and simple to use with concise and powerful APIs.

There is a newer version: 2.1.12
Show newest version
/*
 * Copyright (C) 2015 HaiYang Li
 *
 * Licensed 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 com.landawn.abacus.parser;

/**
 * A factory for creating Parser objects.
 *
 * @author Haiyang Li
 * @since 0.8
 */
public final class ParserFactory {

    /** The Constant isXMLAvailable. */
    private static final boolean isXMLAvailable;

    /** The Constant isKryoAvailable. */
    private static final boolean isKryoAvailable;

    static {
        {
            Boolean isAvailable = false;

            try {
                new XMLParserImpl(XMLParserType.StAX);
                isAvailable = true;
            } catch (Throwable e) {
                // ignore;
            }

            isXMLAvailable = isAvailable;
        }

        {
            Boolean isAvailable = false;

            try {
                Class.forName("com.esotericsoftware.kryo.Kryo");
                ParserFactory.createKryoParser();
                isAvailable = true;
            } catch (Throwable e) {
                // ignore;
            }

            isKryoAvailable = isAvailable;
        }
    }

    private ParserFactory() {
        // singleton
    }

    /**
     * Checks if is XML available.
     *
     * @return true, if is XML available
     */
    public static boolean isXMLAvailable() {
        return isXMLAvailable;
    }

    /**
     * Checks if is kryo available.
     *
     * @return true, if is kryo available
     */
    public static boolean isKryoAvailable() {
        return isKryoAvailable;
    }

    /**
     * Creates a new Parser object.
     *
     * @return
     */
    public static KryoParser createKryoParser() {
        return new KryoParser();
    }

    /**
     * Creates a new Parser object.
     *
     * @return
     */
    public static JSONParser createJSONParser() {
        return new JSONParserImpl();
    }

    /**
     *
     * @param jsc
     * @param jdc
     * @return
     */
    public static JSONParser createJSONParser(final JSONSerializationConfig jsc, final JSONDeserializationConfig jdc) {
        return new JSONParserImpl(jsc, jdc);
    }

    /**
     * Creates a new Parser object.
     *
     * @return
     */
    public static XMLParser createXMLParser() {
        return new XMLParserImpl(XMLParserType.StAX);
    }

    /**
     * Creates a new Parser object.
     *
     * @return
     */
    public static XMLParser createXMLParser(final XMLSerializationConfig xsc, final XMLDeserializationConfig xdc) {
        return new XMLParserImpl(XMLParserType.StAX, xsc, xdc);
    }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy