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;
}
}
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;
}
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;
}
}
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());
}
}
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;
}
}
Aggregations