*/
package jalview.ext.paradise;
-import jalview.util.JSONUtils;
-import jalview.util.MessageManager;
-import jalview.ws.HttpClientUtils;
-
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import org.json.simple.parser.ContentHandler;
import org.json.simple.parser.ParseException;
+import jalview.util.JSONUtils;
+import jalview.util.MessageManager;
+import jalview.ws.HttpClientUtils;
+
/**
* simple methods for calling the various paradise RNA tools
*
}
- /**
- * @param respons
- * @return
- * @throws Exception
- */
public static Iterator<Reader> processJsonResponseFor(Reader respons)
throws Exception
{
- // BH 2019 never called?
+ org.json.simple.parser.JSONParser jp = new org.json.simple.parser.JSONParser();
try
{
- @SuppressWarnings("unchecked")
- final Iterator<Object> rvals = ((List<Object>) JSONUtils.parse(respons)).iterator();
- return new Iterator<>()
- {
- @Override
- public boolean hasNext()
- {
- return rvals.hasNext();
- }
-
- @SuppressWarnings("unchecked")
- @Override
- public Reader next()
- {
- 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 = "";
- }
- 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
- protected void finalize() throws Throwable
- {
- while (rvals.hasNext())
- {
- rvals.next();
- }
- super.finalize();
- }
- };
+ final RvalsIterator rvals = new RvalsIterator(respons);
+ return rvals;
} catch (Exception foo)
{
throw new Exception(MessageManager.getString(
"exception.couldnt_parse_responde_from_annotated3d_server"),
foo);
}
+
}
public static Iterator<Reader> getRNAMLForPDBId(String pdbid)
}
}
+
+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();
+ }
+ }
+}