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

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

There is a newer version: 1.2.50
Show newest version
//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 Geometry
    extends GeoJsonObject
{

    private final String type = "Geometry";
    private final Map _unknownMembers = new LinkedHashMap();
    private final static HashMap _classes = new HashMap();

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

    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 Geometry create(
        @JsonProperty("type")
        java.lang.String type) {
        if (_isNullOrTrimmedEmpty(type)) {
            return new Geometry();
        }
        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, "Geometry");
        clazz = _createClass(className);
        if (clazz!= null) {
            return _createBean(clazz);
        }
        className = MessageFormat.format("{0}{1}", type.toLowerCase(), "Geometry");
        clazz = _createClass(className);
        if (clazz!= null) {
            return _createBean(clazz);
        }
        return new Geometry();
    }

    private static Geometry _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 = Geometry.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 (!Geometry.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