com.rt.core.beans.Property Maven / Gradle / Ivy
package com.rt.core.beans;
import java.util.List;
import java.util.Map;
import com.json.JSONArray;
import com.rt.core.constant.RTConst;
import com.rt.core.util.RTUtil;
/**
* 属性bean
*
* @author msc
*/
public class Property extends TreeElement {
private static final long serialVersionUID = 1L;
protected static final String CODE = "code";
protected static final String ALIAS = "alias";
protected static final String TYPE = "type";
protected static final String STATE = "state";
protected static final String FORMAT = "format";
protected static final String PROPERTY = "property";
public Property() {
super();
}
public Property(Map map) {
super(map);
}
public Property(String string) throws Exception {
super(string);
}
@Override
public Property getChild(String id) {
return (Property) super.getChild(id);
}
/**
* 获得属性列表
*
* @return Map
*/
public Map getPropertys() {
return getJSONObject(PROPERTY, true);
}
/**
* 获得属性列表
*
* @return List
*/
public List getPropertysList() {
return new JSONArray(getPropertys().values());
}
/**
* 设置属性列表
*
* @param map map
*/
public void setPropertys(Map map) {
put(PROPERTY, map);
}
/**
* 是否有对应属性
*
* @param key key
* @return boolean
*/
public boolean hasProperty(String key) {
return getProperty(key) != null;
}
/**
* 获取Property(Property有多个属性或有子对象时使用)
*
* @param key key
* @return Property
*/
public Property getProperty(String key) {
if (key == null) {
return null;
}
return (Property) getPropertys().get(key);
}
/**
* 添加属性项目
*
* @param property 可附加属性Bean
*/
public void addProperty(Property property) {
if (property == null) {
return;
}
getPropertys().put(property.getId(), property);
}
/**
* 获取Property的值(Property没有子节点的情况下使用)
*
* @param id id
* @return String
*/
public String getPropertyValue(String id) {
if (id == null) {
return RTConst.EMPTY;
}
Property obj = getProperty(id);
if (obj == null) {
return RTConst.EMPTY;
}
return obj.getValueToString();
}
/**
* 获取指定Property的子Property
*
* @param id id
* @param contentId contentId
* @return Property
*/
public Property getPropertyContent(String id, String contentId) {
Property p = getProperty(id);
if (p == null) {
return null;
}
return p.getProperty(contentId);
}
/**
* 获取子节点
*
* @param id id
* @return List
*/
public List getPropertyContentList(String id) {
Map p = getPropertyContent(id);
if (p == null) {
return null;
}
return new JSONArray(p.values());
}
/**
* 获取Property所有子内容
*
* @param id id
* @return Map
*/
public Map getPropertyContent(String id) {
Property p = getProperty(id);
if (p == null) {
return null;
}
return p.getPropertys();
}
/**
* 获取指定Property内容Property中的值
*
* @param id id
* @param contentId contentId
* @return String
*/
public String getPropertyContentValue(String id, String contentId) {
Property p = getProperty(id);
if (p == null) {
return null;
}
return p.getPropertyValue(contentId);
}
/**
* id
*/
@Override
public String getId() {
return RTUtil.val(super.getId());
}
/**
* code
*
* @return the code
*/
public String getCode() {
return getString(CODE);
}
/**
* code
*
* @param code the code to set
*/
public void setCode(String code) {
put(CODE, code);
}
/**
* 别名
*
* @return the alias
*/
public String getAlias() {
return getString(ALIAS);
}
/**
* 别名
*
* @param alias the alias to set
*/
public void setAlias(String alias) {
put(ALIAS, alias);
}
/**
* 类型
*
* @return the type
*/
public String getType() {
return getString(TYPE);
}
/**
* 类型
*
* @param type the type to set
*/
public void setType(String type) {
put(TYPE, type);
}
/**
* 状态
*
* @return the state
*/
public String getState() {
return getString(STATE);
}
/**
* 状态
*
* @param state the state to set
*/
public void setState(String state) {
put(STATE, state);
}
/**
* 格式
*
* @return the format
*/
public String getFormat() {
return getString(FORMAT);
}
/**
* 格式
*
* @param format the format to set
*/
public void setFormat(String format) {
put(FORMAT, format);
}
/**
* 级别
*
* @return the level
*/
public long getLevel() {
return getlong("level");
}
/**
* 级别
*
* @param level the level to set
*/
public void setLevel(long level) {
put("level", level);
}
}