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

com.github.fge.jsonschema2pojo.DraftV3OnlySyntaxProcessor Maven / Gradle / Ivy

There is a newer version: 0.8.2
Show newest version
package com.github.fge.jsonschema2pojo;

import com.github.fge.jsonschema.SchemaVersion;
import com.github.fge.jsonschema.core.exceptions.ProcessingException;
import com.github.fge.jsonschema.core.keyword.syntax.SyntaxProcessor;
import com.github.fge.jsonschema.core.messages.JsonSchemaSyntaxMessageBundle;
import com.github.fge.jsonschema.core.processing.Processor;
import com.github.fge.jsonschema.core.processing.ProcessorMap;
import com.github.fge.jsonschema.core.ref.JsonRef;
import com.github.fge.jsonschema.core.report.ProcessingReport;
import com.github.fge.jsonschema.core.tree.SchemaTree;
import com.github.fge.jsonschema.core.util.ValueHolder;
import com.github.fge.jsonschema.library.DraftV3Library;
import com.github.fge.jsonschema.processors.syntax.SyntaxValidator;
import com.github.fge.msgsimple.bundle.MessageBundle;
import com.github.fge.msgsimple.load.MessageBundles;
import com.google.common.base.Function;

public final class DraftV3OnlySyntaxProcessor
    implements Processor, ValueHolder>
{
    private static final Function, JsonRef> FUNCTION
        = new Function, JsonRef>()
    {
        @Override
        public JsonRef apply(final ValueHolder input)
        {
            return input.getValue().getDollarSchema();
        }
    };

    private final Processor,  ValueHolder>
        processor;

    public DraftV3OnlySyntaxProcessor()
    {
        final MessageBundle bundle
            = MessageBundles.getBundle(JsonSchemaSyntaxMessageBundle.class);
        final SyntaxProcessor syntaxProcessor = new SyntaxProcessor(bundle,
            DraftV3Library.get().getSyntaxCheckers());

        final JsonRef draftv3
            = JsonRef.fromURI(SchemaVersion.DRAFTV3.getLocation());

        final ProcessorMap, ValueHolder>
            map
            = new ProcessorMap, ValueHolder>(FUNCTION)
                .addEntry(draftv3, syntaxProcessor)
                .addEntry(JsonRef.emptyRef(), syntaxProcessor)
                .setDefaultProcessor(UNSUPPORTED);

        processor = map.getProcessor();
    }

    @Override
    public ValueHolder process(final ProcessingReport report,
        final ValueHolder input)
        throws ProcessingException
    {
        return processor.process(report, input);
    }

    private static final Processor,
        ValueHolder> UNSUPPORTED
        = new Processor, ValueHolder>()
    {
        @Override
        public ValueHolder process(final ProcessingReport report,
            final ValueHolder input)
            throws ProcessingException
        {
            throw new UnsupportedVersionException();
        }
    };
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy