* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
public InXML(JaxInfo jaxInfo) {
this.jaxInfo = jaxInfo;
}
-
+
public InXML(Class<?> cls, String ... rootNs) throws SecurityException, NoSuchFieldException, ClassNotFoundException, ParseException {
jaxInfo = JaxInfo.build(cls,rootNs);
}
// @Override
public Parsed<State> parse(Reader r, Parsed<State> parsed) throws ParseException {
State state = parsed.state;
-
+
// OK, before anything else, see if there is leftover processing, if so, do it!
if (state.unevaluated!=null) {
DerTag dt = state.unevaluated;
StringBuilder sb = parsed.sb, tempSB = new StringBuilder();
boolean go = true;
-
+
try {
while (go && (ch=r.read())>=0) {
c = (char)ch;
// don't add Whitespace to start of SB... saves removing later
if (sb.length()>0) {
sb.append(c);
- } else if (!Character.isWhitespace(c)) {
+ } else if (!Character.isWhitespace(c)) {
sb.append(c);
}
}
throw new ParseException(e);
}
}
-
+
public static final class DerTag {
public String name;
public boolean isEndTag;
public List<Prop> props;
private boolean isXmlInfo;
- //private String ns;
-
+ //private String ns;
+
public DerTag() {
name=null;
isEndTag = false;
props = null;
isXmlInfo = false;
}
-
+
public DerTag parse(Reader r, StringBuilder sb) throws ParseException {
int ch;
char c;
boolean inQuotes = false, escaped = false;
boolean go = true;
String tag = null;
-
+
try {
if ((ch = r.read())<0) throw new ParseException("Reader content ended before complete");
if (ch=='?') {
}
}
}
-
+
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append(isEndTag?"End":"Start");
return sb.toString();
}
}
-
+
private static class ArrayState {
public boolean firstObj = true;
public boolean didNext = false;
unevaluated = null;
attribs = null;;
}
-
+
public boolean hasAttributes() {
return attribs!=null && idx<attribs.size();
}
}
attribs.add(prop);
}
-
+
public Prop pop() {
Prop rv = null;
if (attribs!=null) {
return rv;
}
}
-
+
private static abstract class GreatExpectations {
protected JaxInfo ji;
protected GreatExpectations prev;
private Map<String,String> ns;
-
+
public GreatExpectations(State state, JaxInfo curr, GreatExpectations prev, DerTag derTag) throws ParseException {
this.prev = prev;
ns = null;
ji = getDerived(state, curr,derTag);
}
-
+
public abstract boolean eval(Parsed<State> parsed, DerTag derTag) throws ParseException;
// Recursively look back for any namespaces
private JaxInfo getDerived(State state, JaxInfo ji, DerTag derTag) throws ParseException {
if (derTag==null)return ji;
-
+
List<Prop> props = derTag.props;
-
+
Prop derived = null;
if (props!=null) {
// Load Namespaces (if any)
return derived==null?ji:ji.getDerived(derived.value);
}
}
-
+
private static class RootExpectations extends GreatExpectations {
-
+
public RootExpectations(State state, JaxInfo curr, GreatExpectations prev) throws ParseException {
super(state,curr,prev, null);
}
-
+
// @Override
public boolean eval(Parsed<State> parsed, DerTag derTag) throws ParseException {
if (derTag.isXmlInfo) {
} else {
//parsed.name = derTag.name;
parsed.event = START_OBJ;
- parsed.state.greatExp = new ObjectExpectations(parsed.state,ji, this, false, derTag);
+ parsed.state.greatExp = new ObjectExpectations(parsed.state,ji, this, false, derTag);
}
}
return false;
}
}
-
+
private static class ObjectExpectations extends GreatExpectations {
private boolean printName;
return false;
}
}
-
+
private static class LeafExpectations extends GreatExpectations {
public LeafExpectations(State state, JaxInfo curr, GreatExpectations prev) throws ParseException {
super(state, curr, prev, null);
throw new ParseException("Expected </" + ji.name + '>');
}
return false;
- }
+ }
}
private static class ArrayExpectations extends GreatExpectations {
if (derTag.isEndTag) {
throw new ParseException("Unexpected End Tag </" + derTag.name + '>');
} else {
- ArrayState ai = parsed.state.arrayInfo.peek();
+ ArrayState ai = parsed.state.arrayInfo.peek();
if (ai.firstObj || ai.didNext) {
ai.firstObj = false;
ai.didNext = false;
parsed.state.arrayInfo.pop();
}
return false;
- }
+ }
}
// @Override
public Parsed<State> newParsed() throws ParseException {
public TimeTaken start(Env env) {
return env.start("Rosetta XML In", Env.XML);
}
-
+
}