+
+class RvalsIterator implements Iterator, AutoCloseable
+{
+ private Iterator<Object> rvals;
+
+ @SuppressWarnings("unchecked")
+ protected RvalsIterator(Reader respons) throws IOException, ParseException
+ {
+ /*
+ * as in 2.11.1 (pre-JalviewJS)
+ */
+ // final JSONArray responses = (JSONArray) jp.parse(respons);
+ // this.rvals = responses.iterator();
+
+ /*
+ * as in JalviewJS (with comment that this code is never called)
+ */
+ this.rvals = ((List<Object>) JSONUtils.parse(respons)).iterator();
+ }
+
+ @Override
+ public boolean hasNext()
+ {
+ return rvals.hasNext();
+ }
+
+ @Override
+ public Reader next()
+ {
+ // JSONObject val = (JSONObject) rvals.next(); // 2.11.1
+ @SuppressWarnings("unchecked")
+ Map<String, Object> val = (Map<String, Object>) rvals.next();
+
+ Object sval = null;
+ try
+ {
+ sval = val.get("2D");
+ } catch (Exception x)
+ {
+ x.printStackTrace();
+ }
+
+ if (sval == null)
+ {
+ System.err.println(
+ "DEVELOPER WARNING: Annotate3d didn't return a '2D' tag in its response. Consider checking output of server. Response was :"
+ + val.toString());
+
+ sval = "";
+ }
+ // 2.11.1:
+ // return new StringReader(
+ // (sval instanceof JSONObject) ? ((JSONObject) sval).toString()
+ // : sval.toString());
+ return new StringReader(sval.toString());
+
+ }
+
+ @Override
+ public void remove()
+ {
+ throw new Error(
+ MessageManager.getString("error.not_implemented_remove"));
+
+ }
+
+ @Override
+ protected Object clone() throws CloneNotSupportedException
+ {
+ throw new CloneNotSupportedException(
+ MessageManager.getString("error.not_implemented_clone"));
+ }
+
+ @Override
+ public boolean equals(Object obj)
+ {
+ return super.equals(obj);
+ }
+
+ @Override
+ public void close()
+ {
+ while (rvals.hasNext())
+ {
+ rvals.next();
+ }
+ }
+}