in juneau-core/juneau-marshall/src/main/java/org/apache/juneau/uon/UonParserSession.java [631:746]
private <T> BeanMap<T> parseIntoBeanMap(UonReader r, BeanMap<T> m) throws IOException, ParseException, ExecutableException {
int c = r.readSkipWs();
if (c == -1 || c == AMP)
return null;
if (c == 'n')
return (BeanMap<T>)parseNull(r);
if (c != '(')
throw new ParseException(this, "Expected '(' at beginning of object.");
final int S1=1; // Looking for attrName start.
final int S2=2; // Found attrName end, looking for =.
final int S3=3; // Found =, looking for valStart.
final int S4=4; // Looking for , or }
boolean isInEscape = false;
int state = S1;
String currAttr = "";
mark();
try {
while (c != -1 && c != AMP) {
c = r.read();
if (! isInEscape) {
if (state == S1) {
if (c == ')' || c == -1 || c == AMP) {
return m;
}
if (Character.isWhitespace(c))
skipSpace(r);
else {
r.unread();
mark();
currAttr = parseAttrName(r, decoding);
if (currAttr == null) { // Value was '%00'
return null;
}
state = S2;
}
} else if (state == S2) {
if (c == EQ || c == '=')
state = S3;
else if (c == -1 || c == ',' || c == ')' || c == AMP) {
m.put(currAttr, null);
if (c == ')' || c == -1 || c == AMP) {
return m;
}
state = S1;
}
} else if (state == S3) {
if (c == -1 || c == ',' || c == ')' || c == AMP) {
if (! currAttr.equals(getBeanTypePropertyName(m.getClassMeta()))) {
BeanPropertyMeta pMeta = m.getPropertyMeta(currAttr);
if (pMeta == null) {
onUnknownProperty(currAttr, m, null);
unmark();
} else {
unmark();
Object value = convertToType("", pMeta.getClassMeta());
try {
pMeta.set(m, currAttr, value);
} catch (BeanRuntimeException e) {
onBeanSetterException(pMeta, e);
throw e;
}
}
}
if (c == -1 || c == ')' || c == AMP)
return m;
state = S1;
} else {
if (! currAttr.equals(getBeanTypePropertyName(m.getClassMeta()))) {
BeanPropertyMeta pMeta = m.getPropertyMeta(currAttr);
if (pMeta == null) {
onUnknownProperty(currAttr, m, parseAnything(object(), r.unread(), m.getBean(false), false, null));
unmark();
} else {
unmark();
setCurrentProperty(pMeta);
ClassMeta<?> cm = pMeta.getClassMeta();
Object value = parseAnything(cm, r.unread(), m.getBean(false), false, pMeta);
setName(cm, value, currAttr);
try {
pMeta.set(m, currAttr, value);
} catch (BeanRuntimeException e) {
onBeanSetterException(pMeta, e);
throw e;
}
setCurrentProperty(null);
}
}
state = S4;
}
} else if (state == S4) {
if (c == ',')
state = S1;
else if (c == ')' || c == -1 || c == AMP) {
return m;
}
}
}
isInEscape = isInEscape(c, r, isInEscape);
}
if (state == S1)
throw new ParseException(this, "Could not find attribute name on object.");
if (state == S2)
throw new ParseException(this, "Could not find '=' following attribute name on object.");
if (state == S3)
throw new ParseException(this, "Could not find value following '=' on object.");
if (state == S4)
throw new ParseException(this, "Could not find ')' marking end of object.");
} finally {
unmark();
}
return null; // Unreachable.
}