package foundation.json.tree;
|
|
import foundation.json.JType;
|
|
public class JBandItem {
|
|
private String fullName;
|
private String objectName;
|
private String propertyName;
|
private String[] segments;
|
private Object value;
|
|
|
public JBandItem(String fullName, Object value) {
|
this.fullName = fullName;
|
this.value = value;
|
|
parse(fullName);
|
}
|
|
private void parse(String fullName) {
|
//1. 默认深度不超过3的主从结构, org_account.shipment[0].code;
|
if (fullName == null) {
|
return;
|
}
|
|
//2. 根据.进行分割
|
fullName = fullName.trim();
|
segments = fullName.split("\\.");
|
|
propertyName = segments[segments.length - 1];
|
objectName = segments[segments.length - 2];
|
|
//3. Array检查
|
int max = segments.length;
|
for (int i = max - 2; i >= 0; i--) {
|
String segment = segments[i];
|
|
int begin = segment.lastIndexOf("[");
|
|
if (begin >= 0) {
|
int end = segment.indexOf("]", begin);
|
|
if (end >= 0) {
|
// String idx = segment.substring(begin + 1, end);
|
// arrayIndex = Integer.parseInt(idx);
|
// type = JType.Array;
|
}
|
}
|
}
|
}
|
|
public String getFullName() {
|
return fullName;
|
}
|
|
public String getObjectName() {
|
return objectName;
|
}
|
|
public String getPropertyName() {
|
return propertyName;
|
}
|
|
public Object getValue() {
|
return value;
|
}
|
|
public String[] getSegments() {
|
return segments;
|
}
|
|
public JType getType(int idx) {
|
int max = segments.length;
|
|
if (idx >= max) {
|
return JType.Unknown;
|
}
|
|
if (idx == (max - 1)) {
|
return null;//JType.Value;
|
}
|
|
String segment = segments[idx];
|
JType type = segment.endsWith("[]") ? JType.Array : JType.Object;
|
return type;
|
}
|
|
public String getName(int itemLevel) {
|
// TODO Auto-generated method stub
|
return null;
|
}
|
}
|