Search in sources :

Example 91 with MapEx

use of com.revolsys.collection.map.MapEx in project com.revolsys.open by revolsys.

the class MapObjectFactory method toObject.

@SuppressWarnings("unchecked")
static <V> V toObject(final Map<String, ? extends Object> map) {
    if (map == null) {
        return null;
    } else {
        // final long startTime = System.currentTimeMillis();
        final MapEx objectMap = new LinkedHashMapEx();
        for (final Entry<String, ? extends Object> entry : map.entrySet()) {
            final String key = entry.getKey();
            Object value = entry.getValue();
            value = objectToObject(value);
            objectMap.put(key, value);
        }
        final String typeClass = getTypeClass(objectMap);
        final V object;
        if (Property.hasValue(typeClass)) {
            final Constructor<V> configConstructor = JavaBeanUtil.getConstructor(typeClass, Map.class);
            if (configConstructor == null) {
                object = (V) JavaBeanUtil.createInstance(typeClass);
                ObjectWithProperties.setProperties(object, objectMap);
            } else {
                object = JavaBeanUtil.invokeConstructor(configConstructor, objectMap);
            }
        } else {
            final String type = getType(objectMap);
            final MapObjectFactory objectFactory = MapObjectFactoryRegistry.getFactory(type);
            if (objectFactory == null) {
                object = (V) objectMap;
            } else {
                object = (V) objectFactory.mapToObject(objectMap);
            }
        }
        // Dates.debugEllapsedTime(MapObjectFactory.class, map.toString(), startTime);
        return object;
    }
}
Also used : LinkedHashMapEx(com.revolsys.collection.map.LinkedHashMapEx) MapEx(com.revolsys.collection.map.MapEx) LinkedHashMapEx(com.revolsys.collection.map.LinkedHashMapEx)

Example 92 with MapEx

use of com.revolsys.collection.map.MapEx in project com.revolsys.open by revolsys.

the class AbstractConnection method getConfig.

@Override
public MapEx getConfig() {
    final MapEx config = new LinkedHashMapEx(this.config);
    config.putAll(getProperties());
    return config;
}
Also used : LinkedHashMapEx(com.revolsys.collection.map.LinkedHashMapEx) MapEx(com.revolsys.collection.map.MapEx) LinkedHashMapEx(com.revolsys.collection.map.LinkedHashMapEx)

Example 93 with MapEx

use of com.revolsys.collection.map.MapEx in project com.revolsys.open by revolsys.

the class FolderConnectionRegistry method loadConnection.

@Override
protected FolderConnection loadConnection(final Path connectionFile, final boolean importConnection) {
    try {
        final MapEx config = Json.toMap(connectionFile);
        final String name = getConnectionName(config, connectionFile, importConnection);
        final String fileName = (String) config.get("file");
        final Path file = Paths.getPath(fileName);
        final FolderConnection connection = new FolderConnection(this, name, file);
        if (!importConnection) {
            connection.setConnectionFile(connectionFile);
        }
        addConnection(connection);
        return connection;
    } catch (final Throwable e) {
        Logs.error(this, "Error creating folder connection from: " + connectionFile, e);
        return null;
    }
}
Also used : Path(java.nio.file.Path) MapEx(com.revolsys.collection.map.MapEx)

Example 94 with MapEx

use of com.revolsys.collection.map.MapEx in project com.revolsys.open by revolsys.

the class JsonParser method getMap.

public MapEx getMap() {
    if (getEvent() == EventType.startObject || hasNext() && next() == EventType.startObject) {
        EventType event = getEvent();
        final MapEx map = new LinkedHashMapEx();
        do {
            if (hasNext() && next() == EventType.string) {
                final String key = getStringIntern();
                if (hasNext()) {
                    if (next() == EventType.colon) {
                        if (hasNext()) {
                            final Object value = getValue();
                            if (value instanceof EventType) {
                                throw new IllegalStateException("Exepecting a value, not: " + key + "=" + value);
                            }
                            if (key != null) {
                                map.put(key, value);
                            }
                        }
                    }
                }
                event = next();
            } else {
                event = getEvent();
            }
        } while (event == EventType.comma);
        if (event != EventType.endObject) {
            throw new IllegalStateException("Exepecting end object, not:" + event);
        }
        return map;
    } else {
        throw new IllegalStateException("Exepecting end object, not:" + getEvent());
    }
}
Also used : LinkedHashMapEx(com.revolsys.collection.map.LinkedHashMapEx) MapEx(com.revolsys.collection.map.MapEx) LinkedHashMapEx(com.revolsys.collection.map.LinkedHashMapEx)

Example 95 with MapEx

use of com.revolsys.collection.map.MapEx in project com.revolsys.open by revolsys.

the class Json method toMap.

public static Map<String, String> toMap(final String string) {
    final MapEx map = toObjectMap(string);
    if (map.isEmpty()) {
        return new LinkedHashMap<>();
    } else {
        final Map<String, String> stringMap = new LinkedHashMap<>();
        for (final Entry<String, Object> entry : map.entrySet()) {
            final String key = entry.getKey();
            final Object value = entry.getValue();
            if (value == null) {
                stringMap.put(key, null);
            } else {
                stringMap.put(key, value.toString());
            }
        }
        return stringMap;
    }
}
Also used : MapEx(com.revolsys.collection.map.MapEx) LinkedHashMapEx(com.revolsys.collection.map.LinkedHashMapEx) LinkedHashMap(java.util.LinkedHashMap)

Aggregations

MapEx (com.revolsys.collection.map.MapEx)144 LinkedHashMapEx (com.revolsys.collection.map.LinkedHashMapEx)48 ArrayList (java.util.ArrayList)17 Resource (com.revolsys.spring.resource.Resource)9 GeometryFactory (com.revolsys.geometry.model.GeometryFactory)7 Map (java.util.Map)7 HashMap (java.util.HashMap)6 PathName (com.revolsys.io.PathName)5 UrlResource (com.revolsys.spring.resource.UrlResource)5 DataType (com.revolsys.datatype.DataType)4 FieldDefinition (com.revolsys.record.schema.FieldDefinition)4 PathResource (com.revolsys.spring.resource.PathResource)4 Color (java.awt.Color)4 LinkedHashMap (java.util.LinkedHashMap)4 List (java.util.List)4 TreeMap (java.util.TreeMap)4 NamedLinkedHashMapEx (com.revolsys.collection.map.NamedLinkedHashMapEx)3 Geometry (com.revolsys.geometry.model.Geometry)3 LineString (com.revolsys.geometry.model.LineString)3 Record (com.revolsys.record.Record)3