![JAR search and dependency download from the Maven repository](/logo.png)
net.anwiba.spatial.geo.json.v01_0.GeoJsonObject Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of anwiba-spatial-data-geo-json Show documentation
Show all versions of anwiba-spatial-data-geo-json Show documentation
anwiba spatial geojson io project
//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 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.ensure.Conditions;
import net.anwiba.commons.ensure.Ensure;
import net.anwiba.commons.reflection.OptionalReflectionMethodInvoker;
import net.anwiba.commons.reflection.ReflectionConstructorInvoker;
import net.anwiba.commons.reflection.ReflectionFieldSetter;
import net.anwiba.commons.reflection.ReflectionMethodInvoker;
import net.anwiba.commons.utilities.string.StringUtilities;
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) {
Ensure.ensureThatArgument(name, Conditions.notNull());
_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 (StringUtilities.isNullOrTrimmedEmpty(type)) {
return new GeoJsonObject();
}
Class extends GeoJsonObject> 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 _validateBean(GeoJsonObject bean) {
try {
Class clazz = bean.getClass();
ReflectionMethodInvoker> methodInvoker = new ReflectionMethodInvoker>(clazz, "get");
Map unkownMembers = methodInvoker.invoke(bean);
ReflectionFieldSetter setterInvoker = new ReflectionFieldSetter(bean);
if (unkownMembers == null) {
return bean;
}
for (java.lang.String member: unkownMembers.keySet()) {
try {
Object value = unkownMembers.get(member);
if (value == null) {
continue;
}
if (clazz.getDeclaredField(member) == null) {
continue;
}
setterInvoker.invoke(member, value);
} catch (NoSuchFieldException exception) {
throw new RuntimeException(exception);
} catch (SecurityException exception) {
throw new RuntimeException(exception);
}
}
return bean;
} catch (InvocationTargetException exception) {
throw new RuntimeException(exception);
}
}
private static GeoJsonObject _createBean(Class extends GeoJsonObject> clazz) {
try {
ReflectionConstructorInvoker invoker = new ReflectionConstructorInvoker(clazz);
return invoker.invoke();
} catch (InvocationTargetException exception) {
throw new RuntimeException(exception);
}
}
private static synchronized Class extends GeoJsonObject> _createClass(java.lang.String type) {
if (_classes.containsKey(type)) {
return ((Class extends GeoJsonObject> ) _classes.get(type));
}
try {
java.lang.String packageName = GeoJsonObject.class.getPackage().getName();
java.lang.String typeName = StringUtilities.setFirstTrimedCharacterToUpperCase(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 extends GeoJsonObject> ) clazz);
} catch (ClassNotFoundException exception) {
_classes.put(type, null);
return null;
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy