com.extjs.gxt.ui.client.data.BaseModelData Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of gxt Show documentation
Show all versions of gxt Show documentation
Rich Internet Application Framework for GWT
/*
* Sencha GXT 2.3.1 - Sencha for GWT
* Copyright(c) 2007-2013, Sencha, Inc.
* [email protected]
*
* http://www.sencha.com/products/gxt/license/
*/
package com.extjs.gxt.ui.client.data;
import java.io.Serializable;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.Set;
import com.extjs.gxt.ui.client.core.FastMap;
import com.extjs.gxt.ui.client.core.FastSet;
/**
* Default ModelData
implementation.
*/
public class BaseModelData implements ModelData, Serializable {
protected RpcMap map;
protected boolean allowNestedValues = true;
/**
* Creates a new model data instance.
*/
public BaseModelData() {
}
/**
* Creates a new model with the given properties.
*
* @param properties the initial properties
*/
public BaseModelData(Map properties) {
super();
setProperties(properties);
}
@SuppressWarnings({"unchecked", "rawtypes"})
public X get(String property) {
if (allowNestedValues && NestedModelUtil.isNestedProperty(property)) {
return (X) NestedModelUtil.getNestedValue(this, property);
}
if (map == null) {
return null;
}
int start = property.indexOf("[");
int end = property.indexOf("]");
X obj = null;
if (start > -1 && end > -1) {
Object o = map.get(property.substring(0, start));
String p = property.substring(start + 1, end);
if (o instanceof Object[]) {
obj = (X) ((Object[]) o)[Integer.valueOf(p)];
} else if (o instanceof List) {
obj = (X) ((List) o).get(Integer.valueOf(p));
} else if (o instanceof Map) {
obj = (X) ((Map) o).get(p);
}
} else {
obj = (X) map.get(property);
}
return obj;
}
/**
* Returns a property value.
*
* @param property the property name
* @param valueWhenNull
* @return the value
*/
@SuppressWarnings("unchecked")
public X get(String property, X valueWhenNull) {
X value = (X) get(property);
return (value == null) ? valueWhenNull : value;
}
public Map getProperties() {
Map newMap = new FastMap