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

net.anwiba.spatial.geo.json.v01_0.GeoJsonObject Maven / Gradle / Ivy

//Copyright (c) 2012 by Andreas W. Bartels ([email protected])
package net.anwiba.spatial.geo.json.v01_0;

import java.lang.reflect.InvocationTargetException;
import java.text.MessageFormat;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Objects;
import com.fasterxml.jackson.annotation.JsonAnyGetter;
import com.fasterxml.jackson.annotation.JsonAnySetter;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
import net.anwiba.commons.reflection.OptionalReflectionMethodInvoker;
import net.anwiba.commons.reflection.ReflectionConstructorInvoker;

public class GeoJsonObject {

    private final String type = "GeoJsonObject";
    private Crs crs = null;
    private double[] bbox = null;
    private final Map _unknownMembers = new LinkedHashMap();
    private final static HashMap _classes = new HashMap();

    @JsonProperty("type")
    public String getType() {
        return this.type;
    }

    @JsonProperty("crs")
    public void setCrs(final Crs crs) {
        this.crs = crs;
    }

    @JsonProperty("crs")
    public Crs getCrs() {
        return this.crs;
    }

    @JsonProperty("bbox")
    public void setBbox(final double[] bbox) {
        this.bbox = bbox;
    }

    @JsonProperty("bbox")
    public double[] getBbox() {
        return this.bbox;
    }

    private void _inject(java.lang.String name, Object value) {
        try {
            OptionalReflectionMethodInvoker setterInvoker = OptionalReflectionMethodInvoker.createSetter(this.getClass(), "JsonProperty", "value", name);
            setterInvoker.invoke(this, value);
        } catch (InvocationTargetException exception) {
            throw new RuntimeException(exception);
        }
    }

    @JsonAnySetter
    public void set(final java.lang.String name, final Object value) {
        Objects.requireNonNull(name);
        _inject(name, value);
        this._unknownMembers.put(name, value);
    }

    @JsonAnyGetter
    public Map get() {
        if (this._unknownMembers.isEmpty()) {
            return null;
        }
        return this._unknownMembers;
    }

    @JsonCreator
    public static GeoJsonObject create(
        @JsonProperty("type")
        java.lang.String type) {
        if (_isNullOrTrimmedEmpty(type)) {
            return new GeoJsonObject();
        }
        Class clazz = _createClass(type);
        if (clazz!= null) {
            return _createBean(clazz);
        }
        clazz = _createClass(type.toLowerCase());
        if (clazz!= null) {
            return _createBean(clazz);
        }
        java.lang.String className = MessageFormat.format("{0}{1}", type, "GeoJsonObject");
        clazz = _createClass(className);
        if (clazz!= null) {
            return _createBean(clazz);
        }
        className = MessageFormat.format("{0}{1}", type.toLowerCase(), "GeoJsonObject");
        clazz = _createClass(className);
        if (clazz!= null) {
            return _createBean(clazz);
        }
        return new GeoJsonObject();
    }

    private static GeoJsonObject _createBean(Class clazz) {
        try {
            ReflectionConstructorInvoker invoker = new ReflectionConstructorInvoker(clazz);
            return invoker.invoke();
        } catch (InvocationTargetException exception) {
            throw new RuntimeException(exception);
        }
    }

    private static synchronized Class _createClass(java.lang.String type) {
        if (_classes.containsKey(type)) {
            return ((Class ) _classes.get(type));
        }
        try {
            java.lang.String packageName = GeoJsonObject.class.getPackage().getName();
            java.lang.String typeName = _setFirstCharacterToUpperCase(type);
            java.lang.String className = MessageFormat.format("{0}.{1}", packageName, typeName);
            Class clazz = Class.forName(className);
            if (!GeoJsonObject.class.isAssignableFrom(clazz)) {
                _classes.put(type, null);
                return null;
            }
            _classes.put(type, clazz);
            return ((Class ) clazz);
        } catch (ClassNotFoundException exception) {
            _classes.put(type, null);
            return null;
        }
    }

    private static boolean _isNullOrTrimmedEmpty(java.lang.String value) {
        return ((value == null)||value.trim().isEmpty());
    }

    private static java.lang.String _setFirstCharacterToUpperCase(java.lang.String value) {
        if ((value == null)||value.trim().isEmpty()) {
            return null;
        }
        return (value.substring(0, 1).toUpperCase()+ value.substring(1, value.length()));
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy