* = new Binding(); binding.setVariable("input", "world");
* gse.run("hello.groovy", binding); </code>
*/
- ClassLoader cl = (jalviewContext[0]!=null ? jalviewContext[0] : jalviewContext[1]).getClass().getClassLoader();
+ Class[] bspec;
+ Object[] binding;
+ int blen=((jalviewContext[0]==null) ? 0 : 1) + ((jalviewContext[1]==null) ? 0 : 1);
+ String cnames[] = new String[] { "Jalview", "currentAlFrame"};
+ bspec=new Class[blen*2];
+ binding=new Object[blen*2];
+ blen=0;
+ ClassLoader cl=null;
+ for (int jc=0;jc<jalviewContext.length;jc++)
+ {
+ if (jalviewContext[jc]!=null) {
+ if (cl==null)
+ {
+ cl = jalviewContext[jc].getClass().getClassLoader();
+ }
+ bspec[blen*2] = String.class;
+ bspec[blen*2+1] = Object.class;
+ binding[blen*2]=cnames[jc];
+ binding[blen*2+1]=jalviewContext[jc];
+ blen++;
+ }
+ }
Class gbindingc = cl.loadClass("groovy.lang.Binding");
Constructor gbcons = gbindingc.getConstructor(null);
Object gbinding = gbcons.newInstance(null);
+
java.lang.reflect.Method setvar = gbindingc.getMethod("setVariable",
- new Class[]
- { String.class, Object.class });
- setvar.invoke(gbinding, new Object[]
- { "Jalview", jalviewContext[0],"startupAlFrame",jalviewContext[1] });
+ bspec);
+
+ setvar.invoke(gbinding, binding);
Class gsec = cl.loadClass("groovy.util.GroovyScriptEngine");
Constructor gseccons = gsec.getConstructor(new Class[]
{ URL[].class }); // String[].class });