isac-java/src/java/isac/bridge/BridgeRMI.java
author Walther Neuper <wneuper@ist.tugraz.at>
Fri, 21 Aug 2015 14:40:41 +0200
changeset 4794 e52f27f14d39
parent 4793 9501a8761e06
child 4795 8598f3ba144a
permissions -rw-r--r--
PIDE-phase 2c CONTINUED: IsaToJava used in all simple cases
     1 /**
     2  * Created on Oct 13, 2003
     3  * @author Richard Gradischnegg RG
     4  */
     5 package isac.bridge;
     6 
     7 import isac.bridge.xml.DataTypes;
     8 import isac.bridge.xml.IntAssumptions;
     9 import isac.bridge.xml.IntCalcHead;
    10 import isac.bridge.xml.IntCChanged;
    11 import isac.bridge.xml.IntCEvent;
    12 import isac.bridge.xml.IntFormHead;
    13 import isac.bridge.xml.IntFormulas;
    14 import isac.bridge.xml.IntIntCompound;
    15 import isac.bridge.xml.IntMatchPbl;
    16 import isac.bridge.xml.IntPosition;
    17 import isac.bridge.xml.IntTactic;
    18 import isac.bridge.xml.IntTacticErrPats;
    19 import isac.bridge.xml.IntTactics;
    20 import isac.bridge.xml.IsaToJava;
    21 import isac.bridge.xml.JavaToIsa;
    22 import isac.interfaces.ICalcElement;
    23 import isac.interfaces.ICalcIterator;
    24 import isac.interfaces.IToCalc;
    25 import isac.util.Formalization;
    26 import isac.util.ResponseWrapper;
    27 import isac.util.formulae.Assumptions;
    28 import isac.util.formulae.CalcHead;
    29 import isac.util.formulae.Context;
    30 import isac.util.formulae.ContextMethod;
    31 import isac.util.formulae.ContextProblem;
    32 import isac.util.formulae.ContextTheory;
    33 import isac.util.formulae.HierarchyKey;
    34 import isac.util.formulae.CalcHeadSimpleID;
    35 import isac.util.formulae.CalcFormula;
    36 import isac.util.formulae.FormHeadsContainer;
    37 import isac.util.formulae.Match;
    38 import isac.util.formulae.MethodID;
    39 import isac.util.formulae.Position;
    40 import isac.util.formulae.ProblemID;
    41 import isac.util.parser.XMLParserDigest;
    42 import isac.util.tactics.SimpleTactic;
    43 import isac.util.tactics.Tactic;
    44 import isac.util.tactics.TacticsContainer;
    45 import isac.wsdialog.IContextProvider.ContextType;
    46 import edu.tum.cs.isabelle.japi.JSystem;
    47 import edu.tum.cs.isabelle.japi.Operations;
    48 import isabelle.XML;
    49 import isabelle.XML.Tree;
    50 
    51 import java.io.BufferedReader;
    52 import java.io.IOException;
    53 import java.io.InputStreamReader;
    54 import java.io.PrintWriter;
    55 import java.math.BigInteger;
    56 import java.net.MalformedURLException;
    57 import java.net.Socket;
    58 import java.net.UnknownHostException;
    59 import java.rmi.Naming;
    60 import java.rmi.RMISecurityManager;
    61 import java.rmi.RemoteException;
    62 import java.rmi.registry.LocateRegistry;
    63 import java.rmi.server.UnicastRemoteObject;
    64 import java.util.HashMap;
    65 import java.util.Iterator;
    66 import java.util.Map;
    67 import java.util.Set;
    68 import java.util.Vector;
    69 
    70 import scala.math.BigInt;
    71 
    72 import org.apache.log4j.Logger;
    73 
    74 /**
    75  * @author Richard Gradischnegg RG
    76  * 
    77  * WN0422 here seems to be the key for simplifying the whole bridge.* drawbacks
    78  * of the present implementation: # more complicated than necessary #
    79  * JUnitTestCases require BridgeMain running # BridgeLogger cannot be made
    80  * serializable, thus not accessible for writing by JUnitTestCases #
    81  */
    82 public class BridgeRMI extends UnicastRemoteObject implements IBridgeRMI {
    83 
    84     static final long serialVersionUID = -3047706038036289437L;
    85     private static final Logger logger = Logger.getLogger(BridgeRMI.class.getName());
    86 
    87 	private BridgeMain bridge_;
    88 
    89     private XMLParserDigest xml_parser_digest_;
    90 
    91     // Socket used to communicate with bridge
    92     private Socket socket_ = null;
    93 
    94     // Writer to write sml requests to the kernel
    95     private PrintWriter out_ = null;
    96 
    97     // Reader to read sml response from kernel
    98     private BufferedReader in_ = null;
    99 
   100     private String host_;
   101 
   102     private int rmiid_;
   103 
   104     /**
   105      * Maps the Java calc(Tree)rmiID to the sml calc(Tree)rmiID. A mapping is
   106      * nescessary because these ids are not (nescessary) the same: For example
   107      * when restoring the kernel, the calcTree rmiID can change because of
   108      * already finished CalcTrees no longer existing and their CalcId assigned
   109      * to another CalcTree. key: Integer (javaCalcID) value: Integer (smlCalcID)
   110      */
   111     private Map java_calcid_to_smlcalcid_;
   112 
   113     /**
   114      * This map stores user inputs which have already been answered by the
   115      * kernel and the response being sent back to the user. These inputs are
   116      * resent to the kernel in the case of a newstart of the kernel. key:
   117      * Integer (javaCalcID) value: Vector (containing input strings)
   118      */
   119     private Map inputs_;
   120 	private JSystem connection_to_kernel_;
   121 
   122     public BridgeRMI(BridgeMain bridge, String host, int port, String dtdPath)
   123             throws RemoteException {
   124         if (logger.isDebugEnabled())
   125             logger.debug("BridgeRMI obj.init: bridge=" + bridge + ", host=" + host
   126                 + ", port=" + port + ", dtdPath=" + dtdPath);
   127         this.host_ = host;
   128         this.bridge_ = bridge;
   129         this.connection_to_kernel_ = bridge.getConnectionToKernel();
   130         /*
   131          * out = bridge.getSmlWriter(); in = bridge.getSmlReader();
   132          */
   133         in_ = bridge.getSmlReader();
   134         try {
   135             socket_ = new Socket(host, port);
   136             out_ = new PrintWriter(socket_.getOutputStream(), true);
   137             in_ = new BufferedReader(new InputStreamReader(socket_
   138                     .getInputStream()));
   139         } catch (UnknownHostException e) {
   140             System.out.println("Unknown host: " + host + "\n");
   141         } catch (IOException e) {
   142             System.out.println("No I/O\n");
   143         }
   144         rmiBind();
   145         xml_parser_digest_ = new XMLParserDigest(dtdPath);
   146         //xml_parser_digest_.setValidating(true);
   147         //...all XML-data should be tested in
   148         //javatest.isac.util.parser.TestXMLParserDigest
   149         inputs_ = new HashMap();
   150         java_calcid_to_smlcalcid_ = new HashMap();
   151     }
   152 
   153     /**
   154      * Buffers input sent to the sml-Kernel (for later possible restart)
   155      * 
   156      * @param javaCalcID
   157      *            calcTree this input belongs to
   158      * @param input
   159      *            to be buffered
   160      */
   161     public void bufferInput(int javaCalcID, String input) {
   162         Vector v = (Vector) inputs_.get(new Integer(javaCalcID));
   163         if (v == null) {
   164             v = new Vector();
   165             inputs_.put(new Integer(javaCalcID), v);
   166         }
   167         v.add(input);
   168     }
   169 
   170     // '@calcid@' is a placeholder for the CalcID
   171     // this method replaces it with a real CalcID
   172     private String insertCalcID(int id, String s) {
   173         return s.replaceAll("@calcid@", String.valueOf(id));
   174     }
   175 
   176     // return smallest integer which is not yet
   177     // used as a (java)CalcID
   178     private int smallestFreeCalcID() {
   179         Set set = java_calcid_to_smlcalcid_.keySet();
   180         for (int i = 0; i < set.size(); i++) {
   181             if (!set.contains(new Integer(i))) {
   182                 return i;
   183             }
   184         }
   185         return set.size();
   186     }
   187 
   188     /*
   189      * Send a sml instruction to the kernel. restore == true, if the instruction
   190      * is resent after the kernel crashed
   191      */
   192     private ResponseWrapper sendToKernel(String smlInstr, boolean restore) {
   193         if (logger.isDebugEnabled())
   194             logger.debug("   BR->KN: sendToKernel(" + smlInstr + ")");
   195         ResponseWrapper wrapper = null;
   196         //bridge.log(1,"---sendToKernel |
   197         //bridge.isRestoring=="+bridge.isRestoring());
   198         //bridge.log(1,"---sendToKernel | restoring=="+restore);
   199         if (!bridge_.isRestoring() || restore) {
   200             String xmlString = "";
   201 
   202             out_.println(smlInstr);// send the sml Instruction to the sml Kernel
   203             try {
   204                 xmlString = in_.readLine();//read the response from the kernel
   205                 if (logger.isInfoEnabled())
   206                     logger.info("   BR<-KN: sendToKernel <- xml= " + xmlString);
   207             } catch (IOException e) {
   208                 bridge_.log(1, "BridgeRMI.interpretSKN: IOException");
   209                 e.printStackTrace();
   210             }
   211             //if (!(restore) && bridge.isRestoring()) {
   212             //	this.restoreExistingCalcTrees();
   213             //}
   214             
   215             bridge_.log( 1, xmlString );
   216             wrapper = xml_parser_digest_.parse(xmlString);
   217         }
   218         return wrapper;
   219     }
   220 
   221     /**
   222      * Send an instruction to the SML-Kernel and return the response
   223      * 
   224      * @param smlInstr
   225      *            Instruction
   226      * @return response from SML-Kernel
   227      */
   228     private synchronized ResponseWrapper interpretSML(int javaCalcID,
   229             String instr, boolean restore) {
   230         int smlCalcID;
   231         
   232         Integer smlCalcInteger = (Integer) java_calcid_to_smlcalcid_.get(new Integer(javaCalcID));
   233         if( smlCalcInteger == null ) {
   234         	bridge_.log(1, "smlCalcInteger is null for javaCalcID : " + javaCalcID );
   235         	return null;
   236         }
   237         
   238         smlCalcID = smlCalcInteger.intValue();
   239         String smlInstr = insertCalcID(smlCalcID, instr);
   240         bridge_.log(1, "JavaCalcID " + javaCalcID + " == SmlCalcID "
   241                 + smlCalcID);
   242         bridge_.log(1, "sent to bridge: " + smlInstr);
   243         ResponseWrapper wrapper = this.sendToKernel(smlInstr, restore); 
   244         if (!restore)
   245             bufferInput(javaCalcID, smlInstr);
   246         return wrapper;
   247     }
   248 
   249     private void rmiBind() {
   250         if (logger.isDebugEnabled())
   251             logger.debug("rmiBind");
   252         if (System.getSecurityManager() == null) {
   253             System.setSecurityManager(new RMISecurityManager());
   254         }
   255         
   256         String name = "//" + host_ + "/BridgeRMI";
   257         try {
   258             System.out.println("try to bind as " + name);
   259             Naming.rebind(name, this);
   260             System.out.println("Bridge RMI bound to " + name);
   261         } catch (java.rmi.ConnectException e) {
   262             System.err.println("failed to contact as " + name + " (creating RMI-Server on localhost: 1099)");
   263             try {
   264                 LocateRegistry.createRegistry(1099);
   265             } catch (java.rmi.RemoteException exc2) {
   266                 System.err.println("can not create registry: " + exc2.getMessage());
   267                 System.exit(1);
   268             }
   269             rmiBind();
   270         } catch (RemoteException e) {
   271         	System.err.println("RemoteException");
   272         	System.err.println(e.getMessage());
   273         	System.err.println(e.getCause().getMessage());
   274         	System.err.println(e.getCause().getClass());
   275         	e.printStackTrace();
   276         	System.exit(1);
   277 
   278         } catch (MalformedURLException e) {
   279         	System.err.println(e.getMessage());
   280         	e.printStackTrace();
   281         	System.exit(1);
   282 
   283         } catch (Exception e) {
   284         	System.err.println("----------- Exception");
   285         	System.err.println(e.getClass().getName());
   286         	System.err.println(e.getMessage());
   287         	e.printStackTrace();
   288         	System.exit(1);
   289         	
   290         }
   291     }
   292 
   293     /**
   294      * Restore a saved calcTree.
   295      * 
   296      * @param v
   297      *            Vector containing strings
   298      * @return Java CalcTreeID (not SML-ID)
   299      */
   300     public int loadCalcTree(Vector v) {
   301         this.bridge_.log(1, "----------------begin loading------------");
   302         int javaCalcID = smallestFreeCalcID();
   303         this.bridge_.log(1, "-----smallest free  = " + javaCalcID);
   304         restoreToSML(javaCalcID, v);
   305         this.bridge_.log(1, "----------------done loading-------------");
   306         return javaCalcID;
   307     }
   308 
   309     public int smlCalcIDtoJavaCalcID(int smlID) {
   310         Iterator it = java_calcid_to_smlcalcid_.keySet().iterator();
   311         while (it.hasNext()) {
   312             Object key = it.next();
   313             Integer value = (Integer) java_calcid_to_smlcalcid_.get(key);
   314             if (value.intValue() == smlID) {
   315                 return ((Integer) key).intValue();
   316             }
   317         }
   318         return -1;
   319     }
   320 
   321     public Map getInputs() {
   322         return inputs_;
   323     }
   324 
   325     public int getRmiID() {
   326         return rmiid_;
   327     }
   328 
   329     public void setRmiID(int i) {
   330         if (logger.isDebugEnabled())
   331             logger.debug("setRmiID: i=" + i);
   332         rmiid_ = i;
   333     }
   334 
   335     /**
   336      * causes a CalcChanged event for the first line on the Worksheet
   337      * 
   338      * @param id
   339      *            for the CalcTree (unused)
   340      * @return CalcChanged with Iterators pointing at the root of the CalcTree
   341      */
   342     public CChanged startCalculate(int id) {
   343         Position p = new Position();
   344         p.setKind("Pbl");// toSMLString --> ([],"Pbl")
   345         CChanged cc = new CChanged();
   346         cc.setLastUnchanged(p);
   347         cc.setLastDeleted(p);
   348         cc.setLastGenerated(p);
   349         return cc;
   350     }
   351 
   352     /**
   353      * Starts the specifying phase: fill the calcTree with the appropriate
   354      * information. Once the calc_head_ is fully specified, the user can begin
   355      * with the actual calculation.
   356      * 
   357      * @param f
   358      *            Formalization for this calculation (empty if user starts a
   359      *            complete new calculation)
   360      * @return javaCalcID
   361      */
   362     public int getCalcTree(Formalization formalization) {
   363     	int return_val;
   364     	int javaCalcID = smallestFreeCalcID();
   365     	this.bridge_.log(1, "-----smallest free javaCalcID = " + javaCalcID);
   366     	int smlCalcID = newCalculation(javaCalcID, 
   367     	  "CalcTree " + formalization.toSMLString() + ";", formalization, false);
   368     	return_val = javaCalcID;
   369         return return_val;
   370     }
   371 
   372     /***********************************************************************
   373      * Below are all the methods in structure Math_Engine : MATH_ENGINE
   374      * listed in the same order as in the signature.
   375      * The previous order still reflected original development;
   376      * method names reflect the original struggle at the 
   377      * interface Java <--> Isabelle/Isac: different names are made explicit.
   378      */
   379     
   380     /** MATH_ENGINE: val appendFormula : calcID -> cterm' -> XML.tree */
   381     public CEvent appendFormula(int id, CalcFormula f) {
   382     	CEvent return_val = null;
   383     	int sml_id = (Integer) java_calcid_to_smlcalcid_.get(new Integer(id));
   384     	/*PIDE*/bridge_.log(1, "-->ISA: " + "appendFormula " + sml_id + " \"" + f.toSMLString() + "\";");
   385 
   386     	/*PIDE*/XML.Tree TODO = JavaToIsa.append_form(new scala.math.BigInt(BigInteger.valueOf(sml_id)), f.getFormula());    	
   387     	/*PIDE*/bridge_.log(1, "-->ISA: " + TODO);    	
   388     	/*PIDE*/XML.Tree xml_out = connection_to_kernel_.invoke(Operations.APPEND_FORM, TODO);
   389 
   390     	/*PIDE*/IntCEvent java_out = null;
   391     	/*PIDE*/if (!IsaToJava.is_message(xml_out)) java_out = IsaToJava.append_form_out(xml_out);
   392     	/*PIDE*/// else: no message handling by DialogGuide
   393     	/*PIDE*/bridge_.log(1, "<--ISA: " + xml_out);
   394     	/*PIDE*/return_val = java_out.getCEvent();
   395         /*---------------------------------------------------------------------------*/
   396         /*---------------------------------------------------------------------------*/
   397     	/*TTY*/ResponseWrapper wrapper = null;
   398     	/*TTY*/wrapper = interpretSML(id, "appendFormula @calcid@ \"" + f.toSMLString() + "\";", false);
   399     	/*TTY*/if (wrapper == null) return null;
   400     	/*TTY*/return_val = (CEvent) wrapper.getResponse();
   401         return return_val;   
   402     }
   403 
   404     /** MATH_ENGINE: val autoCalculate : calcID -> auto -> XML.tree */
   405     public CEvent autoCalculate(int id, int scope, int steps) {
   406         if (logger.isDebugEnabled())
   407             logger.debug("BridgeRMI#autoCalculate: id=" + id + ", scope" + scope + ", steps" + steps);
   408         ResponseWrapper wrapper = null;
   409     	CEvent return_val = null;
   410     	int sml_id = (Integer) java_calcid_to_smlcalcid_.get(new Integer(id));
   411     	String log_str;
   412         //-----------------------------------------------------------------------------
   413     	/*PIDE*/String scope_str;
   414     	/*PIDE*/if ((scope == 3) && (steps == 0)) { //scope ==3 means IToCalc.SCOPE_CALCHEAD:
   415     	/*PIDE*/	scope_str = "CompleteCalcHead"; //FIXXXME.WN040624 steps == 0 hides mismatch in specifications
   416     	/*PIDE*/} else if ((scope == IToCalc.SCOPE_CALCULATION) && (steps == 0)) {
   417     	/*PIDE*/	scope_str = "CompleteCalc";
   418     	/*PIDE*/} else if ((scope == IToCalc.SCOPE_MODEL) && (steps == 0)) {
   419     	/*PIDE*/	scope_str = "CompleteModel";
   420     	/*PIDE*/} else if ((scope == IToCalc.SCOPE_SUBCALCULATION) && (steps == 0)) {
   421     	/*PIDE*/	scope_str = "CompleteToSubpbl";
   422     	/*PIDE*/} else if ((scope == IToCalc.SCOPE_SUBPROBLEM) && (steps == 0)) {
   423     	/*PIDE*/	scope_str = "CompleteSubpbl";
   424     	/*PIDE*/} else { //FIXXXME040624: steps do not regard the scope
   425     	/*PIDE*/	scope_str = "Step"; // steps > 0 according to impl.in "isabelle tty"
   426     	/*PIDE*/}
   427     	/*PIDE*/if (steps == 0) log_str = scope_str; else log_str = "(Step " + steps + ")";
   428     	/*PIDE*/bridge_.log(1, "-->ISA: " + "autoCalculate " + sml_id + " " + log_str + ";");
   429     	
   430     	/*PIDE*/XML.Tree TODO = JavaToIsa.auto_calculate(new scala.math.BigInt(BigInteger.valueOf(sml_id)), 
   431     	/*PIDE*/  scope_str, new scala.math.BigInt(BigInteger.valueOf(steps)));
   432     	/*PIDE*/bridge_.log(1, "-->ISA: " + TODO);
   433     	/*PIDE*/XML.Tree xml_out = connection_to_kernel_.invoke(Operations.AUTO_CALC, TODO);
   434 
   435     	/*PIDE*/IntCEvent java_out = null;
   436     	/*PIDE*/if (!IsaToJava.is_message(xml_out)) {
   437     	/*PIDE*/  java_out = IsaToJava.auto_calc_out(xml_out);
   438     	/*PIDE*/  return_val = java_out.getCEvent();
   439     	/*PIDE*/bridge_.log(1, "<--ISA: " + xml_out);    	
   440     	/*PIDE*/} else
   441         /*PIDE*/  bridge_.log(1, "<--ISA: IsaToJava.is_message: REVIEW!");    	
   442     	
   443     	//THIS RUN ON TestBridge: ----------------------------------------------------
   444     	//*PIDE*/XML.Tree AUTO_CALC_out = connection_to_kernel_.invoke(Operations.AUTO_CALC,
   445     	//*PIDE*/  JavaToIsa.auto_calculate(new scala.math.BigInt(BigInteger.valueOf(sml_id)), 
   446 	    //*PIDE*/	scope_str, new scala.math.BigInt(BigInteger.valueOf(steps))));
   447     	//*PIDE*/bridge_.log(1, "<--ISA: " + AUTO_CALC_out);
   448     	//*PIDE*/IntCChanged calcid_cc = IsaToJava.auto_calc_out(AUTO_CALC_out);
   449     	//*PIDE*/int calcid = calcid_cc.getCalcId();
   450     	//*PIDE*/return_val = (CEvent) calcid_cc.getCChanged();
   451         /*---------------------------------------------------------------------------*/
   452         /*---------------------------------------------------------------------------*/
   453     	/*TTY*/if ((scope == 3) && (steps == 0)) { //scope ==3 means IToCalc.SCOPE_CALCHEAD:
   454     	/*TTY*/    wrapper = interpretSML(id, "autoCalculate @calcid@ CompleteCalcHead;", false);
   455     	/*TTY*/} else if ((scope == IToCalc.SCOPE_CALCULATION) && (steps == 0)) {
   456     	/*TTY*/    wrapper = interpretSML(id, "autoCalculate @calcid@ CompleteCalc;", false);
   457         /*TTY*/} else if ((scope == IToCalc.SCOPE_MODEL) && (steps == 0)) {
   458         /*TTY*/    wrapper = interpretSML(id, "autoCalculate @calcid@ CompleteModel;", false);
   459         /*TTY*/} else if ((scope == IToCalc.SCOPE_SUBCALCULATION) && (steps == 0)) {
   460         /*TTY*/    wrapper = interpretSML(id, "autoCalculate @calcid@ CompleteToSubpbl;", false);
   461         /*TTY*/} else if ((scope == IToCalc.SCOPE_SUBPROBLEM) && (steps == 0)) {
   462         /*TTY*/    wrapper = interpretSML(id, "autoCalculate @calcid@ CompleteSubpbl;", false);
   463         /*TTY*/} else { //FIXXXME040624: steps do not regard the scope
   464         /*TTY*/    wrapper = interpretSML(id, "autoCalculate @calcid@ (Step " + steps + ");", false);
   465         /*TTY*/}
   466         /*TTY*/if (wrapper == null) return_val =  null;
   467         /*TTY*/return_val = (CEvent) wrapper.getResponse();
   468         /*\-------------------------------------------------------------------------/*/
   469         return return_val;
   470     }
   471 
   472     /** MATH_ENGINE: val applyTactic : calcID -> pos' -> tac -> XML.tree 
   473      * not implemented in Math_Engine.
   474      * compare setNextTactic. */
   475     
   476     /**
   477      * Starts a new calculation in the sml-Kernel: i.e. a new CalcTree with the
   478      * initial hot_spot_
   479      * 
   480      * @param instr
   481      *            "CalcTree" + Formalization in string Representation
   482      * @param fmz 
   483      * @return sml_calcid //WN150817 why return SML(?!) calcid to Java(?!)
   484      * 
   485      * MATH_ENGINE: val CalcTree : fmz list -> XML.tree
   486      */
   487     private synchronized int newCalculation(int javaCalcID, String instr,
   488             Formalization fmz, boolean restore) {
   489 
   490         if (logger.isDebugEnabled())
   491             logger.debug("newCalculation: javaCalcID=" + javaCalcID + ", instr" + instr + ", restore=" + restore);
   492         int sml_calcid;
   493         int return_val;
   494         //----- Mini_Test step 1, 2, 3 -----------------------------------------------\
   495         /*PIDE*/bridge_.log(1, "-->ISA: " + instr);
   496         /*PIDE*/XML.Tree CALC_TREE_out = connection_to_kernel_.invoke(Operations.CALC_TREE,
   497         /*PIDE*/  DataTypes.xml_of_Formalization(fmz));
   498         /*PIDE*/bridge_.log(1, "<--ISA: " + CALC_TREE_out);
   499         /*PIDE*/sml_calcid = (IsaToJava.calc_tree_out(CALC_TREE_out)).intValue();
   500         //----- Mini_Test step 2 WN150808 try to drop this step, see WN041209
   501         /*PIDE*/bridge_.log(1, "-->ISA: " + "Iterator " + sml_calcid + ";");
   502         /*PIDE*/XML.Tree ITERATOR_out = connection_to_kernel_.invoke(Operations.ITERATOR,
   503         /*PIDE*/  new scala.math.BigInt(BigInteger.valueOf(sml_calcid)));
   504         /*PIDE*/IntIntCompound int_int = IsaToJava.iterator_out(ITERATOR_out);
   505         /*PIDE*/sml_calcid = int_int.getCalcId().intValue();
   506         /*PIDE*/int userid = int_int.getUserId().intValue(); //WN150808 ununsed
   507         /*PIDE*/bridge_.log(1, "<--ISA: " + ITERATOR_out);
   508         //----- Mini_Test step 3
   509         /*PIDE*/bridge_.log(1, "-->ISA: " + "moveActiveRoot " + sml_calcid + ";");
   510         /*PIDE*/XML.Tree MOVE_ACTIVE_ROOT_out = connection_to_kernel_.invoke(Operations.MOVE_ACTIVE_ROOT,
   511         /*PIDE*/  new scala.math.BigInt(BigInteger.valueOf(sml_calcid)));
   512         /*PIDE*/IntPosition calcid_pos = IsaToJava.move_active_root_out(MOVE_ACTIVE_ROOT_out);
   513         /*PIDE*/return_val = calcid_pos.getCalcId();
   514         /*PIDE*/Position pos = calcid_pos.getPosition(); //WN150808 unused
   515         /*PIDE*/bridge_.log(1, "<--ISA: " + MOVE_ACTIVE_ROOT_out);
   516         /*---------------------------------------------------------------------------*/
   517         /*---------------------------------------------------------------------------*/
   518         /*TTY*/bridge_.log(1, "new calculation: " + instr);
   519         /*TTY*/ResponseWrapper wrapper = sendToKernel(instr, restore);
   520         /*TTY*/if (wrapper == null) return -1;
   521         /*TTY*/sml_calcid = wrapper.getCalcID();
   522         /*TTY*/sendToKernel("Iterator " + sml_calcid + ";", restore);//WN041209 no
   523         /*TTY*/sendToKernel("moveActiveRoot " + sml_calcid + ";", restore);//WN041209
   524         /*TTY*/if (!restore) bufferInput(javaCalcID, instr);
   525         /*\-------------------------------------------------------------------------/*/
   526         java_calcid_to_smlcalcid_.put(new Integer(javaCalcID), new Integer(sml_calcid));
   527         return_val = sml_calcid; //WN150808 SML_caldid --> JAVA frontend ?!?
   528         return return_val;
   529     }
   530 
   531     /** MATH_ENGINE: val checkContext : calcID -> pos' -> guh -> XML.tree */
   532     public Context checkContext(int javaCalcID, Context context, Position pos) throws RemoteException {
   533     	Context return_val = null;
   534     	/*PIDE*/int sml_id = (Integer) java_calcid_to_smlcalcid_.get(new Integer(javaCalcID));
   535     	/*PIDE*/bridge_.log(1, "-->ISA: " + "checkContext " + sml_id + " " + pos.toSMLString() + " \"" + context.getKEStoreKey().toString() + "\";");
   536 
   537     	/*PIDE*/XML.Tree TODO = JavaToIsa.check_ctxt(new scala.math.BigInt(BigInteger.valueOf(sml_id)), 
   538     	/*PIDE*/  pos, context.getKEStoreKey().toString() + "\"");
   539     	/*PIDE*/bridge_.log(1, "-->ISA: " + TODO);    	
   540     	/*PIDE*/XML.Tree xml_out = connection_to_kernel_.invoke(Operations.CHECK_CTXT, TODO);
   541 
   542     	/*PIDE*/ContextTheory java_out = null;
   543     	/*PIDE*/if (!IsaToJava.is_message(xml_out)) {
   544     	/*PIDE*/  java_out = IsaToJava.check_ctxt_out(xml_out);
   545     	/*PIDE*/  return_val = java_out;
   546     	/*PIDE*/bridge_.log(1, "<--ISA: " + xml_out);    	
   547     	/*PIDE*/} else
   548         /*PIDE*/  bridge_.log(1, "<--ISA: IsaToJava.is_message: REVIEW!");    	
   549     	/*TTY*/ResponseWrapper wrapper = interpretSML(javaCalcID,
   550     	/*TTY*/  "checkContext @calcid@ " + pos.toSMLString() + " \"" + context.getKEStoreKey().toString() + "\";", false);
   551     	/*TTY*/if(wrapper == null) return null;
   552     	/*TTY*/return_val = (Context) wrapper.getResponse();
   553         return return_val;
   554     }    
   555     
   556     /** MATH_ENGINE: val DEconstrCalcTree : calcID -> XML.tree */
   557     public boolean destruct(int javaCalcID) {
   558     	boolean return_val;
   559     	/*PIDE*/int sml_id = (Integer) java_calcid_to_smlcalcid_.get(new Integer(javaCalcID));
   560     	/*PIDE*/bridge_.log(1, "-->ISA: " + "DEconstrCalcTree " + sml_id);
   561     	/*PIDE*/XML.Tree xml_out = connection_to_kernel_.invoke(Operations.DEL_CALC,
   562     	/*PIDE*/  new scala.math.BigInt(BigInteger.valueOf(sml_id)));
   563 
   564     	/*PIDE*/Integer java_out = IsaToJava.del_calc_out(xml_out);
   565     	/*PIDE*/return_val = true;
   566     	/*PIDE*/bridge_.log(1, "<--ISA: " + xml_out);    	
   567     	/*---------------------------------------------------------------------------*/
   568     	/*---------------------------------------------------------------------------*/
   569     	/*TTY*/ResponseWrapper wrapper = interpretSML(javaCalcID,
   570     	/*TTY*/  "DEconstrCalcTree @calcid@;", false);
   571     	/*TTY*/if (wrapper == null) { return_val = false; }
   572     	/*TTY*/inputs_.remove(new Integer(javaCalcID));
   573     	/*TTY*/return_val = true;
   574     	/*\-------------------------------------------------------------------------/*/
   575     	java_calcid_to_smlcalcid_.remove(new Integer(javaCalcID));
   576     	return return_val;
   577     }
   578 
   579     /** MATH_ENGINE: val fetchApplicableTactics : calcID -> int -> pos' -> XML.tree */
   580     public Vector getAppliableTactics(int id, int scope, Position pos) {
   581     	Vector return_val = null;
   582     	/*PIDE*/int sml_id = (Integer) java_calcid_to_smlcalcid_.get(new Integer(id));
   583     	/*PIDE*/bridge_.log(1, "-->ISA: " + "fetchApplicableTactics " + sml_id + " " + scope + pos.toSMLString() + ";");
   584     	
   585     	/*PIDE*/XML.Tree TODO = JavaToIsa.fetch_applicable_tacs(new scala.math.BigInt(BigInteger.valueOf(sml_id)), 
   586     	/*PIDE*/  new scala.math.BigInt(BigInteger.valueOf(scope)), pos);    	
   587     	/*PIDE*/bridge_.log(1, "-->ISA: " + TODO);
   588     	/*PIDE*/XML.Tree xml_out = connection_to_kernel_.invoke(Operations.FETCH_APPL_TACS, TODO);
   589 
   590 //TODO IsaToJava.fetch_applicable_tacs_out   tested RED
   591 //    	System.out.println("xml_out = " + xml_out);
   592 //    	/*PIDE*/IntTactics java_out = null;
   593 //    	boolean xxx = IsaToJava.is_message(xml_out);
   594 //    	/*PIDE*/if (!IsaToJava.is_message(xml_out)) {
   595 //    	/*PIDE*/  java_out = IsaToJava.fetch_applicable_tacs_out(xml_out);
   596 //    	/*PIDE*/  return_val = java_out.getTactics();
   597 //    	/*PIDE*/bridge_.log(1, "<--ISA: " + xml_out);    	
   598 //    	/*PIDE*/} else
   599 //        /*PIDE*/  bridge_.log(1, "<--ISA: IsaToJava.is_message: REVIEW!");    	
   600     	/*TTY*/ResponseWrapper wrapper = interpretSML(id,
   601         /*TTY*/  "fetchApplicableTactics @calcid@ " + scope + pos.toSMLString() + ";", false);
   602         /*TTY*/if (wrapper == null) return null;
   603         /*TTY*/TacticsContainer tc = (TacticsContainer) wrapper.getResponse();
   604         /*TTY*/if( tc == null ) return null;
   605         /*TTY*/return_val = tc.getTactics();
   606         return return_val;
   607     }
   608 
   609     /** MATH_ENGINE: val fetchProposedTactic : calcID -> XML.tree */
   610     public Tactic fetchProposedTactic(int id) {
   611     	Tactic return_val = null;
   612     	/*PIDE*/int sml_id = (Integer) java_calcid_to_smlcalcid_.get(new Integer(id));
   613     	/*PIDE*/bridge_.log(1, "-->ISA: " + "fetchProposedTactic " + sml_id + ";");
   614     	
   615     	/*PIDE*/XML.Tree TODO = JavaToIsa.fetch_proposed_tac(new scala.math.BigInt(BigInteger.valueOf(sml_id)));    	
   616     	/*PIDE*/bridge_.log(1, "-->ISA: " + TODO);
   617     	/*PIDE*/XML.Tree xml_out = connection_to_kernel_.invoke(Operations.FETCH_PROP_TAC, TODO);
   618 
   619 //TODO IsaToJava.fetch_applicable_tacs_out  tested RED
   620 //    	/*PIDE*/IntTacticErrPats java_out = null;
   621 //    	/*PIDE*/if (!IsaToJava.is_message(xml_out)) {
   622 //    	/*PIDE*/  java_out = IsaToJava.fetch_proposed_tac_out(xml_out);
   623 //    	/*PIDE*/  return_val = java_out.getTactic();
   624 //    	/*PIDE*/bridge_.log(1, "<--ISA: " + xml_out);    	
   625 //    	/*PIDE*/} else
   626 //      /*PIDE*/  bridge_.log(1, "<--ISA: IsaToJava.is_message: REVIEW!");    	
   627     	/*TTY*/ResponseWrapper wrapper = interpretSML(id, "fetchProposedTactic @calcid@;", false);
   628         /*TTY*/if (wrapper == null) { return null; }
   629         /*TTY*/return_val = (Tactic) wrapper.getResponse();
   630         return return_val;
   631     }
   632 
   633     /** MATH_ENGINE: val findFillpatterns : calcID -> errpatID -> XML.tree 
   634      * only implemented in Math_Engine */
   635     
   636     /**
   637      * @see isac.bridge.IBridgeRMI#getAccumulatedAssumptions(int,
   638      *      isac.util.formulae.Position)
   639      *      
   640      * ** MATH_ENGINE: val getAccumulatedAsms : calcID -> pos' -> XML.tree
   641      */
   642     public Assumptions getAccumulatedAssumptions(int calcTreeID, Position pos) throws RemoteException {
   643     	Assumptions return_val = null;
   644     	/*PIDE*/int sml_id = (Integer) java_calcid_to_smlcalcid_.get(new Integer(calcTreeID));
   645     	/*PIDE*/bridge_.log(1, "-->ISA: " + "getAccumulatedAsms " + sml_id + " " + pos.toSMLString() + ";");
   646     	
   647     	/*PIDE*/XML.Tree TODO = JavaToIsa.get_accumulated_asms(new scala.math.BigInt(BigInteger.valueOf(sml_id)), pos);    	
   648     	/*PIDE*/bridge_.log(1, "-->ISA: " + TODO);
   649     	/*PIDE*/XML.Tree xml_out = connection_to_kernel_.invoke(Operations.GET_ACC_ASMS, TODO);
   650 
   651     	/*PIDE*/IntAssumptions java_out = null;
   652     	/*PIDE*/if (!IsaToJava.is_message(xml_out)) {
   653     	/*PIDE*/  java_out = IsaToJava.get_accumulated_asms_out(xml_out);
   654     	/*PIDE*/  return_val = java_out.getAssumptions();
   655     	/*PIDE*/bridge_.log(1, "<--ISA: " + xml_out);    	
   656     	/*PIDE*/} else
   657         /*PIDE*/  bridge_.log(1, "<--ISA: IsaToJava.is_message: REVIEW!");    	
   658     	/*TTY*/ResponseWrapper wrapper = interpretSML(calcTreeID,
   659         /*TTY*/  "getAccumulatedAsms @calcid@ " + pos.toSMLString() + ";", false);
   660         /*TTY*/return_val = (Assumptions) wrapper.getResponse();
   661         return return_val;
   662     }
   663     
   664     /** MATH_ENGINE: val getActiveFormula : calcID -> XML.tree */
   665     public Position getActiveFormula(int javaCalcID) {
   666     	Position return_val = null;
   667     	/*PIDE*/int sml_id = (Integer) java_calcid_to_smlcalcid_.get(new Integer(javaCalcID));
   668     	/*PIDE*/bridge_.log(1, "-->ISA: " + "getActiveFormula " + sml_id + " ;");
   669     	
   670     	/*PIDE*/XML.Tree TODO = JavaToIsa.get_active_form(new scala.math.BigInt(BigInteger.valueOf(sml_id)));
   671     	/*PIDE*/bridge_.log(1, "-->ISA: " + TODO);
   672     	/*PIDE*/XML.Tree xml_out = connection_to_kernel_.invoke(Operations.GET_ACTIVE_FORM, TODO);
   673 
   674     	/*PIDE*/IntPosition java_out = null;
   675     	/*PIDE*/if (!IsaToJava.is_message(xml_out)) {
   676     	/*PIDE*/  java_out = IsaToJava.get_active_form_out(xml_out);
   677     	/*PIDE*/  return_val = java_out.getPosition();
   678     	/*PIDE*/bridge_.log(1, "<--ISA: " + xml_out);    	
   679     	/*PIDE*/} else
   680         /*PIDE*/  bridge_.log(1, "<--ISA: IsaToJava.is_message: REVIEW!");    	
   681     	/*TTY*/ResponseWrapper wrapper = interpretSML(javaCalcID,
   682     	/*TTY*/  "getActiveFormula @calcid@ ;", false);
   683     	/*TTY*/return_val = moveSuccess(wrapper);
   684         return return_val;
   685     }
   686 
   687     /**
   688      * @see isac.bridge.IBridgeRMI#getAssumption(int, int)
   689      * 
   690      * MATH_ENGINE: val getAssumptions : calcID -> pos' -> XML.tree
   691      */
   692     public Assumptions getAssumptions(int calcTreeID, Position pos) throws RemoteException {
   693     	Assumptions return_val = null;
   694     	/*PIDE*/int sml_id = (Integer) java_calcid_to_smlcalcid_.get(new Integer(calcTreeID));
   695     	/*PIDE*/bridge_.log(1, "-->ISA: " + "getAssumptions " + sml_id + " " + pos.toSMLString() + ";");
   696     	
   697     	/*PIDE*/XML.Tree TODO = JavaToIsa.get_asms(new scala.math.BigInt(BigInteger.valueOf(sml_id)), pos);    	
   698     	/*PIDE*/bridge_.log(1, "-->ISA: " + TODO);
   699     	/*PIDE*/XML.Tree xml_out = connection_to_kernel_.invoke(Operations.GET_ASMS, TODO);
   700 
   701     	/*PIDE*/IntAssumptions java_out = null;
   702     	/*PIDE*/if (!IsaToJava.is_message(xml_out)) {
   703     	/*PIDE*/  java_out = IsaToJava.get_asms_out(xml_out);
   704     	/*PIDE*/  return_val = java_out.getAssumptions();
   705     	/*PIDE*/bridge_.log(1, "<--ISA: " + xml_out);    	
   706     	/*PIDE*/} else
   707         /*PIDE*/  bridge_.log(1, "<--ISA: IsaToJava.is_message: REVIEW!");    	
   708     	/*TTY*/ResponseWrapper wrapper = interpretSML(calcTreeID,
   709     	/*TTY*/  "getAssumptions @calcid@ " + pos.toSMLString() + ";", false);
   710     	/*TTY*/return_val = (Assumptions) wrapper.getResponse();
   711         return return_val;
   712     }
   713 
   714     /** MATH_ENGINE: val getFormulaeFromTo : calcID -> pos' -> pos' -> int -> bool -> XML.tree */
   715     public Vector getFormulaeFromTo(int id, ICalcIterator iterator_from,
   716             ICalcIterator iterator_to, Integer level, boolean result_includes_tactics) {
   717         XML.Tree TODO = null;
   718     	ResponseWrapper wrapper = null;
   719         Vector return_val = null;      
   720         //----- Mini_Test step 4 ------------------------------------------------------
   721         /*PIDE*/int sml_id = (Integer) java_calcid_to_smlcalcid_.get(new Integer(id));
   722         /*PIDE*/try {
   723         /*PIDE*/  bridge_.log(1, "-->ISA: " + "getFormulaeFromTo " + sml_id + " "
   724         /*PIDE*/    + iterator_from.toSMLString() + " " + iterator_to.toSMLString()
   725 		/*PIDE*/    + " " + level + " " + result_includes_tactics + ";");
   726 		/*PIDE*/} catch (RemoteException e2) { e2.printStackTrace(); }
   727         
   728         /*PIDE*/try {
   729         /*PIDE*/  TODO = JavaToIsa.get_formulae(new scala.math.BigInt(BigInteger.valueOf(sml_id)),
   730 		/*PIDE*/    iterator_from.getPosition(), iterator_to.getPosition(), 
   731 		/*PIDE*/    new scala.math.BigInt(BigInteger.valueOf(level)), result_includes_tactics);
   732         /*PIDE*/} catch (RemoteException e1) { e1.printStackTrace(); }
   733     	/*PIDE*/bridge_.log(1, "-->ISA: " + TODO);
   734     	/*PIDE*/XML.Tree xml_out = connection_to_kernel_.invoke(Operations.GET_FORMULAE, TODO);
   735 
   736 //TODO IsaToJava.get_formulae_out tested RED
   737 //    	/*PIDE*/IntFormulas java_out = null;
   738 //    	/*PIDE*/if (!IsaToJava.is_message(xml_out)) {
   739 //    	/*PIDE*/  java_out = IsaToJava.get_formulae_out(xml_out);
   740 //    	/*PIDE*/  return_val = java_out.getCalcFormulas();
   741 //    	/*PIDE*/bridge_.log(1, "<--ISA: " + xml_out);    	
   742 //    	/*PIDE*/} else
   743 //        /*PIDE*/  bridge_.log(1, "<--ISA: IsaToJava.is_message: REVIEW!");    	
   744 
   745     	//THIS RUN ON TestBridge:
   746         //*PIDE*/XML.Tree GET_FORMULAE_out = null;
   747         //*PIDE*/try { GET_FORMULAE_out = connection_to_kernel_.invoke(Operations.GET_FORMULAE,
   748         //*PIDE*/  JavaToIsa.get_formulae(new scala.math.BigInt(BigInteger.valueOf(sml_id)),
   749         //*PIDE*/  iterator_from.getPosition(), iterator_to.getPosition(), new scala.math.BigInt(BigInteger.valueOf(level)), result_includes_tactics));
   750         //*PIDE*/} catch (RemoteException e1) { e1.printStackTrace(); }
   751         //*PIDE*/bridge_.log(1, "<--ISA: " + GET_FORMULAE_out);
   752         //*PIDE*/IntFormulas calcid_forms = IsaToJava.get_formulae_out(GET_FORMULAE_out);
   753         //*PIDE*/sml_id = calcid_forms.getCalcId();
   754         //*PIDE*/return_val = calcid_forms.getCalcFormulas();
   755         /*---------------------------------------------------------------------------*/
   756         /*---------------------------------------------------------------------------*/
   757         /*TTY*/try { wrapper = interpretSML(id, "getFormulaeFromTo @calcid@ "
   758         /*TTY*/    + iterator_from.toSMLString() + " " + iterator_to.toSMLString()
   759         /*TTY*/    + " " + level + " " + result_includes_tactics + ";", false);
   760         /*TTY*/} catch (RemoteException e) { e.printStackTrace(); }
   761         /*TTY*/if (wrapper == null) return null;
   762         /*TTY*/FormHeadsContainer con = (FormHeadsContainer) wrapper.getResponse();
   763         /*TTY*/if (con != null) return_val = con.getElements();
   764         /*TTY*/else return_val = null;
   765         /*\-------------------------------------------------------------------------/*/
   766         return return_val;
   767     }
   768 
   769     /*
   770      * @see isac.bridge.IBridgeRMI#getTactic(int, int)
   771      * 
   772      * MATH_ENGINE: val getTactic : calcID -> pos' -> XML.tree
   773      */
   774     public Tactic getTactic(int calcTreeID, Position pos) throws RemoteException {
   775     	Tactic return_val = null;
   776     	/*PIDE*/int sml_id = (Integer) java_calcid_to_smlcalcid_.get(new Integer(calcTreeID));
   777     	/*PIDE*/bridge_.log(1, "-->ISA: " + "getTactic " + sml_id + " " + pos.toSMLString() + ";");
   778     	
   779     	/*PIDE*/XML.Tree TODO = JavaToIsa.get_tac(new scala.math.BigInt(BigInteger.valueOf(sml_id)), pos);    	
   780     	/*PIDE*/bridge_.log(1, "-->ISA: " + TODO);
   781 
   782     	/*PIDE*/XML.Tree xml_out = connection_to_kernel_.invoke(Operations.GET_TAC, TODO);
   783 //TODO IsaToJava.fetch_applicable_tacs_out ??? (NO isac.Testall)
   784     	/*PIDE*/bridge_.log(1, "<--ISA: " + xml_out);
   785 
   786     	//*PIDE*/bridge_.log(1, "<--ISA: " + TODOTODOTODOTODO);    	
   787     	//*PIDE*/return_val = TODOTODOTODOTODO;
   788     	/*TTY*/ResponseWrapper wrapper = interpretSML(calcTreeID,
   789     	/*TTY*/  "getTactic @calcid@ " + pos.toSMLString() + ";", false);
   790     	/*TTY*/return_val = (Tactic) wrapper.getResponse();
   791         return return_val;
   792     }
   793 
   794     /** MATH_ENGINE: val initContext : calcID -> ketype -> pos' -> XML.tree */
   795     public Context initContext(int javaCalcID, ContextType type, Position pos) throws RemoteException {
   796     	Context return_val = null;
   797     	/*PIDE*/int sml_id = (Integer) java_calcid_to_smlcalcid_.get(new Integer(javaCalcID));
   798     	/*PIDE*/bridge_.log(1, "-->ISA: " + "initContext " + sml_id + " " + type.toSMLString() + " " + pos.toSMLString() + ";");
   799     	
   800     	/*PIDE*/XML.Tree TODO = JavaToIsa.init_ctxt(new scala.math.BigInt(BigInteger.valueOf(sml_id)), type, pos);    	
   801     	/*PIDE*/bridge_.log(1, "-->ISA: " + TODO);
   802     	/*PIDE*/XML.Tree xml_out = connection_to_kernel_.invoke(Operations.INIT_CTXT, TODO);
   803 
   804 //TODO IsaToJava.init_ctxt_out  tested RED
   805 //    	/*PIDE*/ContextTheory java_out = null;
   806 //    	/*PIDE*/if (!IsaToJava.is_message(xml_out)) {
   807 //    	/*PIDE*/  java_out = IsaToJava.init_ctxt_out(xml_out);
   808 //    	/*PIDE*/  return_val = java_out;
   809 //    	/*PIDE*/bridge_.log(1, "<--ISA: " + xml_out);    	
   810 //    	/*PIDE*/} else
   811 //        /*PIDE*/  bridge_.log(1, "<--ISA: IsaToJava.is_message: REVIEW!");    	
   812 
   813     	/*TTY*/ResponseWrapper wrapper = interpretSML(javaCalcID,
   814     	/*TTY*/  "initContext @calcid@ " + type.toSMLString() + " " + pos.toSMLString() + ";", false);
   815     	/*TTY*/if(wrapper == null) return null;
   816     	/*TTY*/return_val = (Context) wrapper.getResponse();
   817         return return_val;
   818     }
   819 
   820     /** MATH_ENGINE: val inputFillFormula: calcID -> string -> XML.tree 
   821      * only implemented in Math_Engine */
   822 
   823     /** MATH_ENGINE: val interSteps : calcID -> pos' -> XML.tree */
   824     public CEvent intermediateSteps(int id, ICalcIterator ci) {
   825     	CEvent return_val = null;
   826     	/*PIDE*/int sml_id = (Integer) java_calcid_to_smlcalcid_.get(new Integer(id));
   827     	/*PIDE*/XML.Tree TODO = null;
   828     	/*PIDE*/try {
   829     	/*PIDE*/	bridge_.log(1, "-->ISA: " + "interSteps " + sml_id + " " + ci.toSMLString() + ";");
   830     	/*PIDE*/} catch (RemoteException e1) { e1.printStackTrace(); }
   831     	
   832     	/*PIDE*/try {
   833     	/*PIDE*/  TODO = JavaToIsa.inter_steps(new scala.math.BigInt(BigInteger.valueOf(sml_id)), ci.getPosition());
   834     	/*PIDE*/} catch (Exception e1) { e1.printStackTrace();}    	
   835     	/*PIDE*/bridge_.log(1, "-->ISA: " + TODO);
   836     	/*PIDE*/XML.Tree xml_out = connection_to_kernel_.invoke(Operations.INTER_STEPS, TODO);
   837 
   838 //TODO IsaToJava.inter_steps_out  1 Test RED
   839 //    	/*PIDE*/IntCEvent java_out = null;
   840 //    	/*PIDE*/if (!IsaToJava.is_message(xml_out)) {
   841 //    	/*PIDE*/  java_out = IsaToJava.inter_steps_out(xml_out);
   842 //    	/*PIDE*/  return_val = java_out.getCEvent();
   843 //    	/*PIDE*/bridge_.log(1, "<--ISA: " + xml_out);    	
   844 //    	/*PIDE*/} else
   845 //        /*PIDE*/  bridge_.log(1, "<--ISA: IsaToJava.is_message: REVIEW!");    	
   846 
   847     	/*TTY*/ResponseWrapper wrapper = null;
   848         /*TTY*/try {
   849         /*TTY*/    wrapper = interpretSML(id, "interSteps @calcid@ " + ci.toSMLString() + ";", false);
   850         /*TTY*/} catch (RemoteException e) { e.printStackTrace(); }
   851         /*TTY*/if (wrapper == null) return null;
   852         /*TTY*/return_val = (CEvent) wrapper.getResponse();
   853         return return_val;
   854     }
   855 
   856     /** MATH_ENGINE: val Iterator : calcID -> XML.tree */
   857     public int iterator(int id) {
   858         if (logger.isDebugEnabled())
   859           logger.debug("iterator: id=" + id);
   860         int return_val;
   861     	/*PIDE*/int sml_id = (Integer) java_calcid_to_smlcalcid_.get(new Integer(id));
   862     	/*PIDE*/bridge_.log(1, "-->ISA: " + "Iterator " + sml_id + ";");
   863     	
   864     	/*PIDE*/BigInt TODO = new scala.math.BigInt(BigInteger.valueOf(sml_id));    	
   865     	/*PIDE*/bridge_.log(1, "-->ISA: " + TODO);
   866     	/*PIDE*/XML.Tree xml_out = connection_to_kernel_.invoke(Operations.ITERATOR, TODO);
   867 
   868     	/*PIDE*/IntIntCompound java_out = null;
   869     	/*PIDE*/if (!IsaToJava.is_message(xml_out)) {
   870     	/*PIDE*/  java_out = IsaToJava.iterator_out(xml_out);
   871     	/*PIDE*/  return_val = java_out.getCalcId().intValue();
   872     	/*PIDE*/bridge_.log(1, "<--ISA: " + xml_out);    	
   873     	/*PIDE*/} else
   874         /*PIDE*/  bridge_.log(1, "<--ISA: IsaToJava.is_message: REVIEW!");    	
   875 
   876         /*TTY*/if (id == 1) {
   877         /*TTY*/    ResponseWrapper wrapper = interpretSML(id, "Iterator @calcid@;", false);
   878         /*TTY*/    if (wrapper == null) return_val = -1;
   879         /*TTY*/    else return_val = Integer.parseInt(((CalcHeadSimpleID) wrapper .getResponse()).getID());
   880         /*TTY*/} else return_val = 4711;//TODO.WN041208 drop CalcIterator.iteratorID_
   881         return return_val;
   882     }
   883 
   884     /**
   885      * @see isac.interfaces.IToCalc#modelProblem()
   886      * 
   887      * MATH_ENGINE: val modelProblem : calcID -> XML.tree
   888      */
   889     public CalcHead modelProblem(int calc_tree_id) throws RemoteException {
   890     	CalcHead return_val = null;
   891     	/*PIDE*/int sml_id = (Integer) java_calcid_to_smlcalcid_.get(new Integer(calc_tree_id));
   892     	/*PIDE*/bridge_.log(1, "-->ISA: " + "modelProblem " + sml_id + ";");
   893     	
   894     	/*PIDE*/BigInt TODO = new scala.math.BigInt(BigInteger.valueOf(sml_id));    	
   895     	/*PIDE*/bridge_.log(1, "-->ISA: " + TODO);
   896     	/*PIDE*/XML.Tree xml_out = connection_to_kernel_.invoke(Operations.MODEL_PBL, TODO);
   897 
   898     	/*PIDE*/IntCalcHead java_out = null;
   899     	/*PIDE*/if (!IsaToJava.is_message(xml_out)) {
   900     	/*PIDE*/  java_out = IsaToJava.modify_calchead_out(xml_out);
   901     	/*PIDE*/  return_val = java_out.getCalcHead();
   902     	/*PIDE*/bridge_.log(1, "<--ISA: " + xml_out);    	
   903     	/*PIDE*/} else
   904         /*PIDE*/  bridge_.log(1, "<--ISA: IsaToJava.is_message: REVIEW!");    	
   905 
   906     	/*TTY*/ResponseWrapper wrapper = interpretSML(calc_tree_id, "modelProblem @calcid@;", false);
   907     	/*TTY*/return_val = (CalcHead) wrapper.getResponse();
   908         return return_val;
   909     }
   910     
   911     /**
   912      * @see isac.interfaces.IToCalc#checkCalcHead(isac.util.formulae.CalcHead)
   913      * 
   914      * MATH_ENGINE: val modifyCalcHead : calcID -> icalhd -> XML.tree
   915      */
   916     public CalcHead checkCalcHead(int calc_tree_id, CalcHead calchead) throws RemoteException {
   917     	CalcHead return_val = null;
   918     	/*PIDE*/int sml_id = (Integer) java_calcid_to_smlcalcid_.get(new Integer(calc_tree_id));
   919     	/*PIDE*/bridge_.log(1, "-->ISA: " + "modelProblem " + sml_id + ";");
   920     	
   921     	/*PIDE*/XML.Tree TODO = JavaToIsa.modify_calchead(new scala.math.BigInt(BigInteger.valueOf(sml_id)), calchead);    	
   922     	/*PIDE*/bridge_.log(1, "-->ISA: " + TODO);
   923     	/*PIDE*/XML.Tree xml_out = connection_to_kernel_.invoke(Operations.MODIFY_CALCHEAD, TODO);
   924 
   925     	/*PIDE*/IntCalcHead java_out = null;
   926     	/*PIDE*/if (!IsaToJava.is_message(xml_out)) {
   927     	/*PIDE*/  java_out = IsaToJava.modify_calchead_out(xml_out);
   928     	/*PIDE*/  return_val = java_out.getCalcHead();
   929     	/*PIDE*/bridge_.log(1, "<--ISA: " + xml_out);    	
   930     	/*PIDE*/} else
   931         /*PIDE*/  bridge_.log(1, "<--ISA: IsaToJava.is_message: REVIEW!");    	
   932 
   933     	/*TTY*/ResponseWrapper wrapper = interpretSML(calc_tree_id,
   934     	/*TTY*/  "modifyCalcHead @calcid@ " + calchead.toSMLString() + ";", false);
   935     	/*TTY*/return_val = (CalcHead) wrapper.getResponse();
   936         return return_val;
   937     }
   938 
   939     /** MATH_ENGINE: val moveActiveCalcHead : calcID -> XML.tree */
   940     public Position moveCalcHead(int javaCalcID, int iteratorID, Position p) {
   941     	Position return_val = null;
   942     	/*PIDE*/int sml_id = (Integer) java_calcid_to_smlcalcid_.get(new Integer(javaCalcID));
   943 
   944     	/*PIDE*/bridge_.log(1, "-->ISA: " + "moveActiveCalcHead " + sml_id + "" + ";");    	
   945     	/*PIDE*/XML.Tree TODO = JavaToIsa.move_active_calchead(new scala.math.BigInt(BigInteger.valueOf(sml_id)));    	
   946     	/*PIDE*/bridge_.log(1, "-->ISA: " + TODO);
   947     	/*PIDE*/XML.Tree xml_out = connection_to_kernel_.invoke(Operations.MOVE_ACTIVE_FORM, TODO);
   948 //TODO IsaToJava.   POSTPONED TO NEXT STEP
   949     	/*PIDE*/bridge_.log(1, "<--ISA: " + xml_out);
   950     	
   951     	/*PIDE*/bridge_.log(1, "-->ISA: " + "moveCalcHead " + sml_id + " " + " " + p.toSMLString() + ";");
   952     	/*PIDE*/TODO = JavaToIsa.move_calchead(new scala.math.BigInt(BigInteger.valueOf(sml_id)), null);    	
   953     	/*PIDE*/bridge_.log(1, "-->ISA: " + TODO);
   954     	/*PIDE*/xml_out = connection_to_kernel_.invoke(Operations.MOVE_ACTIVE_FORM, TODO);
   955     	/*PIDE*/bridge_.log(1, "<--ISA: " + xml_out);
   956 
   957     	//*PIDE*/bridge_.log(1, "<--ISA: " + TODOTODOTODOTODO);    	
   958     	//*PIDE*/return_val = TODOTODOTODOTODO;
   959     	/*TTY*/ResponseWrapper wrapper = null;
   960     	/*TTY*/if (iteratorID == 1)
   961     	/*TTY*/  wrapper = interpretSML(javaCalcID, "moveActiveCalcHead @calcid@" + ";", false);
   962     	/*TTY*/else
   963     	/*TTY*/  wrapper = interpretSML(javaCalcID, "moveCalcHead @calcid@ " + " " + p.toSMLString() + ";", false);
   964     	/*TTY*/return_val = moveSuccess(wrapper);
   965         return return_val;
   966     }
   967 
   968     /** MATH_ENGINE: val moveActiveDown : calcID -> XML.tree */
   969     public Position moveDown(int javaCalcID, int iteratorID, Position p) {
   970         if (logger.isDebugEnabled())
   971             logger.debug("moveDown: javaCalcID=" + javaCalcID + ", sml_pos=" + p.toSMLString());
   972     	Position return_val = null;
   973     	/*PIDE*/int sml_id = (Integer) java_calcid_to_smlcalcid_.get(new Integer(javaCalcID));
   974     	/*PIDE*/bridge_.log(1, "-->ISA: " + "moveActiveDown " + sml_id + "" + ";");
   975     	/*PIDE*/XML.Tree TODO = JavaToIsa.move_active_down(new scala.math.BigInt(BigInteger.valueOf(sml_id)));    	
   976     	/*PIDE*/bridge_.log(1, "-->ISA: " + TODO);
   977     	/*PIDE*/XML.Tree xml_out = connection_to_kernel_.invoke(Operations.MOVE_ACTIVE_DOWN, TODO);
   978 //TODO IsaToJava.   POSTPONED TO NEXT STEP
   979     	/*PIDE*/bridge_.log(1, "<--ISA: " + xml_out);
   980 
   981     	/*PIDE*/bridge_.log(1, "-->ISA: " + "moveDown " + sml_id + " " + p.toSMLString() + ";");
   982     	/*PIDE*/TODO = JavaToIsa.move_down(new scala.math.BigInt(BigInteger.valueOf(sml_id)), p);    	
   983     	/*PIDE*/bridge_.log(1, "-->ISA: " + TODO);
   984     	/*PIDE*/xml_out = connection_to_kernel_.invoke(Operations.MOVE_DOWN, TODO);
   985     	/*PIDE*/bridge_.log(1, "<--ISA: " + xml_out);
   986 
   987     	//*PIDE*/return_val = TODOTODOTODOTODO;
   988     	/*TTY*/ResponseWrapper wrapper = null;
   989     	/*TTY*/if (iteratorID == 1)
   990     	/*TTY*/    wrapper = interpretSML(javaCalcID, "moveActiveDown @calcid@" + ";", false);
   991     	/*TTY*/else
   992     	/*TTY*/    wrapper = interpretSML(javaCalcID, "moveDown @calcid@ " + p.toSMLString() + ";", false);
   993     	/*TTY*/return_val = moveSuccess(wrapper);
   994         return return_val;
   995     }
   996 
   997     /** 
   998      * returns Position for uniformity with move*; not required elsewhere
   999      * 
  1000      * MATH_ENGINE: val moveActiveFormula : calcID -> pos' -> XML.tree 
  1001      */
  1002     public Position moveActiveFormula(int javaCalcID, Position p) {
  1003         if (logger.isDebugEnabled())
  1004             logger.debug("moveDown: javaCalcID=" + javaCalcID + ", sml_pos=" + p.toSMLString());
  1005     	Position return_val = null;
  1006     	/*PIDE*/int sml_id = (Integer) java_calcid_to_smlcalcid_.get(new Integer(javaCalcID));
  1007     	/*PIDE*/bridge_.log(1, "-->ISA: " + "moveActiveFormula " + sml_id + " " + p.toSMLString() + ";");
  1008     	
  1009     	/*PIDE*/XML.Tree TODO = JavaToIsa.move_active_form(new scala.math.BigInt(BigInteger.valueOf(sml_id)), p);    	
  1010     	/*PIDE*/bridge_.log(1, "-->ISA: " + TODO);
  1011 
  1012     	/*PIDE*/XML.Tree xml_out = connection_to_kernel_.invoke(Operations.MOVE_ACTIVE_FORM, TODO);
  1013 //TODO IsaToJava.  POSTPONED TO NEXT STEP
  1014     	/*PIDE*/bridge_.log(1, "<--ISA: " + xml_out);
  1015 
  1016     	//*PIDE*/return_val = TODOTODOTODOTODO;
  1017     	/*TTY*/ResponseWrapper wrapper = interpretSML(javaCalcID,
  1018     	/*TTY*/  "moveActiveFormula @calcid@ " + p.toSMLString() + ";", false);
  1019     	/*TTY*/return_val = moveSuccess(wrapper);
  1020         return return_val;
  1021     }
  1022 
  1023     /** MATH_ENGINE: val moveActiveLevelDown : calcID -> XML.tree */
  1024     public Position moveLevelDown(int javaCalcID, int iteratorID, Position p) {
  1025     	Position return_val = null;
  1026     	/*PIDE*/int sml_id = (Integer) java_calcid_to_smlcalcid_.get(new Integer(javaCalcID));
  1027     	/*PIDE*/bridge_.log(1, "-->ISA: " + "moveActiveLevelDown " + sml_id + "" + ";");    	
  1028     	/*PIDE*/XML.Tree TODO = JavaToIsa.move_active_levdown(new scala.math.BigInt(BigInteger.valueOf(sml_id)));    	
  1029     	/*PIDE*/bridge_.log(1, "-->ISA: " + TODO);
  1030     	/*PIDE*/XML.Tree xml_out = connection_to_kernel_.invoke(Operations.MOVE_ACTIVE_LEVDN, TODO);
  1031 //TODO IsaToJava.  POSTPONED TO NEXT STEP
  1032     	/*PIDE*/bridge_.log(1, "<--ISA: " + xml_out);
  1033 
  1034     	/*PIDE*/bridge_.log(1, "-->ISA: " + "moveLevelDown " + sml_id + " " + " " + p.toSMLString() + ";");
  1035     	/*PIDE*/TODO = JavaToIsa.move_levdn(new scala.math.BigInt(BigInteger.valueOf(sml_id)), p);    	
  1036     	/*PIDE*/bridge_.log(1, "-->ISA: " + TODO);
  1037     	/*PIDE*/xml_out = connection_to_kernel_.invoke(Operations.MOVE_LEVDN, TODO);
  1038     	/*PIDE*/bridge_.log(1, "<--ISA: " + xml_out);
  1039     	
  1040     	//*PIDE*/return_val = TODOTODOTODOTODO;
  1041     	/*TTY*/ResponseWrapper wrapper = null;
  1042     	/*TTY*/if (iteratorID == 1)
  1043     	/*TTY*/    wrapper = interpretSML(javaCalcID, "moveActiveLevelDown @calcid@" + ";", false);
  1044     	/*TTY*/else
  1045     	/*TTY*/    wrapper = interpretSML(javaCalcID, "moveLevelDown @calcid@ " + " " + p.toSMLString() + ";", false);
  1046     	/*TTY*/return_val = moveSuccess(wrapper);
  1047         return return_val;
  1048     }
  1049 
  1050     /** MATH_ENGINE: val moveActiveLevelUp : calcID -> XML.tree */
  1051     public Position moveLevelUp(int javaCalcID, int iteratorID, Position p) {
  1052     	Position return_val = null;
  1053     	/*PIDE*/int sml_id = (Integer) java_calcid_to_smlcalcid_.get(new Integer(javaCalcID));
  1054     	/*PIDE*/bridge_.log(1, "-->ISA: " + "moveActiveLevelUp " + sml_id + "" + ";");
  1055     	/*PIDE*/XML.Tree TODO = JavaToIsa.move_active_levup(new scala.math.BigInt(BigInteger.valueOf(sml_id)));    	
  1056     	/*PIDE*/bridge_.log(1, "-->ISA: " + TODO);
  1057     	/*PIDE*/XML.Tree xml_out = connection_to_kernel_.invoke(Operations.MOVE_ACTIVE_LEVUP, TODO);
  1058 //TODO IsaToJava.  POSTPONED TO NEXT STEP
  1059     	/*PIDE*/bridge_.log(1, "<--ISA: " + xml_out);
  1060 
  1061     	/*PIDE*/bridge_.log(1, "-->ISA: " + "moveLevelUp " + sml_id + " " + p.toSMLString() + ";");
  1062     	/*PIDE*/TODO = JavaToIsa.move_levup(new scala.math.BigInt(BigInteger.valueOf(sml_id)), p);    	
  1063     	/*PIDE*/bridge_.log(1, "-->ISA: " + TODO);
  1064     	/*PIDE*/xml_out = connection_to_kernel_.invoke(Operations.MOVE_LEVUP, TODO);
  1065     	/*PIDE*/bridge_.log(1, "<--ISA: " + xml_out);
  1066 
  1067     	//*PIDE*/return_val = TODOTODOTODOTODO;
  1068     	/*TTY*/ResponseWrapper wrapper = null;
  1069     	/*TTY*/if (iteratorID == 1)
  1070     	/*TTY*/    wrapper = interpretSML(javaCalcID, "moveActiveLevelUp @calcid@" + ";", false);
  1071     	/*TTY*/else
  1072     	/*TTY*/    wrapper = interpretSML(javaCalcID, "moveLevelUp @calcid@ " + p.toSMLString() + ";", false);
  1073     	/*TTY*/return_val = moveSuccess(wrapper);
  1074         return return_val;
  1075     }
  1076 
  1077     /** MATH_ENGINE: val moveActiveRoot : calcID -> XML.tree */
  1078     public Position moveRoot(int javaCalcID, int iteratorID) {
  1079         if (logger.isDebugEnabled())
  1080             logger.debug("moveRoot: javaCalcID=" + javaCalcID);
  1081     	Position return_val = null;
  1082     	/*PIDE*/int sml_id = (Integer) java_calcid_to_smlcalcid_.get(new Integer(javaCalcID));
  1083     	/*PIDE*/bridge_.log(1, "-->ISA: " + "moveActiveRoot " + sml_id + "" + ";");
  1084     	/*PIDE*/scala.math.BigInt TODO = new scala.math.BigInt(BigInteger.valueOf(sml_id));    	
  1085     	/*PIDE*/bridge_.log(1, "-->ISA: " + TODO);
  1086     	/*PIDE*/XML.Tree xml_out = connection_to_kernel_.invoke(Operations.MOVE_ACTIVE_ROOT, TODO);
  1087 //TODO IsaToJava.  POSTPONED TO NEXT STEP
  1088     	/*PIDE*/bridge_.log(1, "<--ISA: " + xml_out);
  1089 
  1090     	/*PIDE*/bridge_.log(1, "-->ISA: " + "moveRoot " + sml_id + " " + ";");
  1091     	/*PIDE*/XML.Tree TODO2 = JavaToIsa.move_root(new scala.math.BigInt(BigInteger.valueOf(sml_id)));    	
  1092     	/*PIDE*/bridge_.log(1, "-->ISA: " + TODO2);
  1093     	/*PIDE*/xml_out = connection_to_kernel_.invoke(Operations.MOVE_ROOT, TODO2);
  1094     	/*PIDE*/bridge_.log(1, "<--ISA: " + xml_out);
  1095 
  1096     	//*PIDE*/return_val = TODOTODOTODOTODO;
  1097     	/*TTY*/ResponseWrapper wrapper = null;
  1098     	/*TTY*/if (iteratorID == 1)
  1099     	/*TTY*/    wrapper = interpretSML(javaCalcID, "moveActiveRoot @calcid@" + ";", false);
  1100     	/*TTY*/else
  1101     	/*TTY*/    wrapper = interpretSML(javaCalcID, "moveRoot @calcid@ " + ";", false);
  1102     	/*TTY*/return_val = moveSuccess(wrapper);
  1103         return return_val;
  1104     }
  1105 
  1106     /** MATH_ENGINE: val moveActiveRootTEST : calcID -> XML.tree 
  1107      *  used only internally in Math_Engine */
  1108 
  1109     /** MATH_ENGINE: val moveActiveUp : calcID -> XML.tree */
  1110     public Position moveUp(int javaCalcID, int iteratorID, Position p) {
  1111     	Position return_val = null;
  1112     	/*PIDE*/int sml_id = (Integer) java_calcid_to_smlcalcid_.get(new Integer(javaCalcID));
  1113     	/*PIDE*/XML.Tree TODO = JavaToIsa.move_active_up(new scala.math.BigInt(BigInteger.valueOf(sml_id)));    	
  1114     	/*PIDE*/bridge_.log(1, "-->ISA: " + TODO);
  1115     	/*PIDE*/XML.Tree xml_out = connection_to_kernel_.invoke(Operations.MOVE_ACTIVE_UP, TODO);
  1116 //TODO IsaToJava.  POSTPONED TO NEXT STEP
  1117     	/*PIDE*/bridge_.log(1, "<--ISA: " + xml_out);
  1118 
  1119     	/*PIDE*/bridge_.log(1, "-->ISA: " + "moveUp " + sml_id + " " + p.toSMLString() + ";");
  1120     	/*PIDE*/TODO = JavaToIsa.move_up(new scala.math.BigInt(BigInteger.valueOf(sml_id)), p);    	
  1121     	/*PIDE*/bridge_.log(1, "-->ISA: " + TODO);
  1122     	/*PIDE*/xml_out = connection_to_kernel_.invoke(Operations.MOVE_UP, TODO);
  1123     	/*PIDE*/bridge_.log(1, "<--ISA: " + xml_out);
  1124 
  1125     	//*PIDE*/return_val = TODOTODOTODOTODO;
  1126     	/*TTY*/ResponseWrapper wrapper = null;
  1127     	/*TTY*/if (iteratorID == 1)
  1128     	/*TTY*/    wrapper = interpretSML(javaCalcID, "moveActiveUp @calcid@" + ";", false);
  1129     	/*TTY*/else
  1130     	/*TTY*/    wrapper = interpretSML(javaCalcID, "moveUp @calcid@ " + p.toSMLString() + ";", false);
  1131     	/*TTY*/return_val = moveSuccess(wrapper);
  1132         return return_val;
  1133     }
  1134 
  1135     /** MATH_ENGINE: val moveCalcHead : calcID -> pos' -> XML.tree 
  1136      *  does not exist in isac-java, see val moveActiveCalcHead */
  1137 
  1138     /** MATH_ENGINE: val moveDown : calcID -> pos' -> XML.tree 
  1139      *  does not exist in isac-java, see val moveActiveDown */
  1140     
  1141     /** MATH_ENGINE: val val moveLevelDown : calcID -> pos' -> XML.tree 
  1142      *  does not exist in isac-java, see val moveActiveLevelDown */
  1143 
  1144     /** MATH_ENGINE: val moveLevelUp : calcID -> pos' -> XML.tree 
  1145      *  does not exist in isac-java, see val moveActiveLevelUp */
  1146 
  1147     /** MATH_ENGINE: val moveRoot : calcID -> XML.tree
  1148      *  does not exist in isac-java, see val moveActiveRoot */
  1149     
  1150     /** MATH_ENGINE: val moveUp : calcID -> pos' -> XML.tree
  1151      *  does not exist in isac-java, see val moveActiveUp */
  1152 
  1153     /**
  1154      * @see isac.bridge.IBridgeRMI#getElement(int, int)
  1155      * MATH_ENGINE: val refFormula : calcID -> pos' -> XML.tree
  1156      */
  1157     public ICalcElement getElement(int javaCalcID, Position p) {
  1158     	ICalcElement return_val = null;
  1159     	//----- Mini_Test step 6, 10 --------------------------------------------------
  1160     	/*PIDE*/int sml_calcid = ((Integer) java_calcid_to_smlcalcid_.get(new Integer(javaCalcID))).intValue();
  1161     	/*PIDE*/bridge_.log(1, "-->ISA: " + "(*getElement*)refFormula " + sml_calcid
  1162     	/*PIDE*/  + " " + p.toSMLString() + ";");
  1163 
  1164     	/*PIDE*/XML.Tree TODO = JavaToIsa.ref_formula(new scala.math.BigInt(BigInteger.valueOf(sml_calcid)), p);
  1165     	/*PIDE*/bridge_.log(1, "-->ISA: " + TODO);
  1166     	/*PIDE*/XML.Tree xml_out = connection_to_kernel_.invoke(Operations.REF_FORMULA, TODO);
  1167 
  1168 //TODO IsaToJava.ref_formula_out  tested RED
  1169 //    	/*PIDE*/IntFormHead java_out = null;
  1170 //    	/*PIDE*/if (!IsaToJava.is_message(xml_out)) {
  1171 //    	/*PIDE*/  java_out = IsaToJava.ref_formula_out(xml_out);
  1172 //    	/*PIDE*/  return_val = (ICalcElement)java_out.getFormHead();
  1173 //    	/*PIDE*/bridge_.log(1, "<--ISA: " + xml_out);    	
  1174 //    	/*PIDE*/} else
  1175 //        /*PIDE*/  bridge_.log(1, "<--ISA: IsaToJava.is_message: REVIEW!");    	
  1176     	
  1177     	//THIS ALREADY WORKED WITH TestBridge:
  1178     	//*PIDE*/XML.Tree REF_FORMULA_out = connection_to_kernel_.invoke(Operations.REF_FORMULA,
  1179     	//*PIDE*/  JavaToIsa.ref_formula(new scala.math.BigInt(BigInteger.valueOf(sml_calcid)), p));
  1180     	//*PIDE*/bridge_.log(1, "<--ISA: " + REF_FORMULA_out);
  1181     	//*PIDE*/IntFormHead calcid_formhead = IsaToJava.ref_formula_out(REF_FORMULA_out);
  1182     	//*PIDE*/sml_calcid = calcid_formhead.getCalcId();
  1183     	//*PIDE*/return_val = (ICalcElement) calcid_formhead.getFormHead();
  1184     	/*---------------------------------------------------------------------------*/
  1185     	/*---------------------------------------------------------------------------*/
  1186     	/*TTY*/ResponseWrapper wrapper = interpretSML(javaCalcID,
  1187     	/*TTY*/        "(*getElement*)refFormula @calcid@ " + p.toSMLString() + ";", false);
  1188     	/*TTY*/if (wrapper == null) return_val =  null;
  1189     	/*TTY*/return_val =  (ICalcElement) wrapper.getResponse();
  1190     	/*\-------------------------------------------------------------------------/*/
  1191     	return return_val;
  1192     }
  1193     
  1194     /**
  1195      * @see isac.bridge.IBridgeRMI#getFormula(int, int)
  1196      * @deprecated in favour of getElement.
  1197      * ... WN150812: although it is in IBridgeRMI !!
  1198      * 
  1199      * MATH_ENGINE: val refFormula : calcID -> pos' -> XML.tree
  1200      */
  1201     public ICalcElement getFormula(int calcTreeID, Position p) throws RemoteException {
  1202     	ICalcElement return_val = null;
  1203     	/*PIDE*/int sml_id = (Integer) java_calcid_to_smlcalcid_.get(new Integer(calcTreeID));
  1204     	/*PIDE*/bridge_.log(1, "-->ISA: " + "(*getFormula*)refFormula " + sml_id + " " + p.toSMLString() + ";");
  1205 
  1206     	/*PIDE*/XML.Tree TODO = JavaToIsa.ref_formula(new scala.math.BigInt(BigInteger.valueOf(sml_id)), p);
  1207     	/*PIDE*/bridge_.log(1, "-->ISA: " + TODO);
  1208     	/*PIDE*/XML.Tree xml_out = connection_to_kernel_.invoke(Operations.REF_FORMULA, TODO);
  1209 
  1210 //TODO IsaToJava.ref_formula_out  HERE (compare above) tested GREEN: never used ?!?
  1211     	/*PIDE*/IntFormHead java_out = null;
  1212     	/*PIDE*/if (!IsaToJava.is_message(xml_out)) {
  1213     	/*PIDE*/  java_out = IsaToJava.ref_formula_out(xml_out);
  1214     	/*PIDE*/  return_val = (ICalcElement)java_out.getFormHead();
  1215     	/*PIDE*/bridge_.log(1, "<--ISA: " + xml_out);    	
  1216     	/*PIDE*/} else
  1217         /*PIDE*/  bridge_.log(1, "<--ISA: IsaToJava.is_message: REVIEW!");    	
  1218 
  1219     	/*TTY*/ResponseWrapper wrapper = interpretSML(calcTreeID,
  1220     	/*TTY*/  "(*getFormula*)refFormula @calcid@ " + p.toSMLString() + ";", false);
  1221     	/*TTY*/if (wrapper == null) return_val = null;
  1222     	/*TTY*/else return_val = (ICalcElement) wrapper.getResponse();
  1223         return return_val;
  1224     }
  1225 
  1226     /** MATH_ENGINE: val refineProblem : calcID -> pos' -> guh -> XML.tree */
  1227     public Context refineProblem(int javaCalcID, Context context, Position pos) throws RemoteException {
  1228     	Context return_val = null;
  1229     	/*PIDE*/int sml_id = (Integer) java_calcid_to_smlcalcid_.get(new Integer(javaCalcID));
  1230     	/*PIDE*/bridge_.log(1, "-->ISA: " + "refineProblem " + sml_id + " " + pos.toSMLString() + " \"" + context.getKEStoreKey().toString() + "\";");
  1231 
  1232     	/*PIDE*/XML.Tree TODO = JavaToIsa.refine_pbl(new scala.math.BigInt(BigInteger.valueOf(sml_id)), 
  1233     	/*PIDE*/  pos, context.getKEStoreKey().toString() + "\"");
  1234     	/*PIDE*/bridge_.log(1, "-->ISA: " + TODO);
  1235     	/*PIDE*/XML.Tree xml_out = connection_to_kernel_.invoke(Operations.REFINE_PBL, TODO);
  1236 
  1237     	/*PIDE*/IntMatchPbl java_out = null;
  1238     	/*PIDE*/if (!IsaToJava.is_message(xml_out)) {
  1239     	/*PIDE*/  java_out = IsaToJava.refine_pbl_out(xml_out);
  1240 //TODO IsaToJava.refine_pbl_out REPAIR: need getContext() -- see IntMatchPbl
  1241 //    	/*PIDE*/  return_val = java_out.getHead();
  1242 //    	/*PIDE*/bridge_.log(1, "<--ISA: " + xml_out);    	
  1243     	/*PIDE*/} ///////////else
  1244 //        /*PIDE*/  bridge_.log(1, "<--ISA: IsaToJava.is_message: REVIEW!");    	
  1245 
  1246     	/*TTY*/ResponseWrapper wrapper = interpretSML(javaCalcID,
  1247     	/*TTY*/  "refineProblem @calcid@ " + pos.toSMLString() + " \"" + context.getKEStoreKey().toString() + "\";", false); 
  1248     	/*TTY*/if(wrapper == null) return null;
  1249     	/*TTY*/return_val = (Context) wrapper.getResponse();
  1250         return return_val;
  1251     }
  1252     
  1253     /** MATH_ENGINE: val replaceFormula : calcID -> cterm' -> XML.tree */
  1254     public CEvent replaceFormula(int id, CalcFormula f) {
  1255     	CEvent return_val = null;
  1256     	/*PIDE*/int sml_id = (Integer) java_calcid_to_smlcalcid_.get(new Integer(id));
  1257     	/*PIDE*/bridge_.log(1, "-->ISA: " + "replaceFormula " + sml_id + " \"" + f.toSMLString() + "\";");
  1258     	
  1259     	/*PIDE*/XML.Tree TODO = JavaToIsa.replace_form(new scala.math.BigInt(BigInteger.valueOf(sml_id)), f.getFormula());    	
  1260     	/*PIDE*/bridge_.log(1, "-->ISA: " + TODO);
  1261     	/*PIDE*/XML.Tree xml_out = connection_to_kernel_.invoke(Operations.REPLACE_FORM, TODO);
  1262 
  1263     	/*PIDE*/IntCEvent java_out = null;
  1264     	/*PIDE*/if (!IsaToJava.is_message(xml_out)) {
  1265     	/*PIDE*/  java_out = IsaToJava.replace_form_out(xml_out);
  1266     	/*PIDE*/  return_val = java_out.getCEvent();
  1267     	/*PIDE*/bridge_.log(1, "<--ISA: " + xml_out);    	
  1268     	/*PIDE*/} else
  1269         /*PIDE*/  bridge_.log(1, "<--ISA: IsaToJava.is_message: REVIEW!");    	
  1270 
  1271     	/*TTY*/ResponseWrapper wrapper = null;
  1272     	/*TTY*/wrapper = interpretSML(id, "replaceFormula @calcid@ \"" + f.toSMLString() + "\";", false);
  1273     	/*TTY*/if (wrapper == null) return_val = null;
  1274     	/*TTY*/else return_val = (CEvent) wrapper.getResponse();
  1275         return return_val;
  1276     }
  1277 
  1278     /** MATH_ENGINE: val requestFillformula : calcID -> errpatID * fillpatID -> XML.tree 
  1279      * only implemented in Math_Engine */
  1280 
  1281     /** MATH_ENGINE: val resetCalcHead : calcID -> XML.tree */
  1282     /**
  1283      * @see isac.interfaces.IToCalc#resetCalcHead()
  1284      */
  1285     public CalcHead resetCalcHead(int calc_tree_id) throws RemoteException {
  1286     	CalcHead return_val = null;
  1287     	/*PIDE*/int sml_id = (Integer) java_calcid_to_smlcalcid_.get(new Integer(calc_tree_id));
  1288     	/*PIDE*/bridge_.log(1, "-->ISA: " + "resetCalcHead " + sml_id + ";");
  1289     	
  1290     	/*PIDE*/XML.Tree TODO = JavaToIsa.reset_calchead(new scala.math.BigInt(BigInteger.valueOf(sml_id)));    	
  1291     	/*PIDE*/bridge_.log(1, "-->ISA: " + TODO);
  1292     	/*PIDE*/XML.Tree xml_out = connection_to_kernel_.invoke(Operations.RESET_CALCHEAD, TODO);
  1293 
  1294     	/*PIDE*/IntCalcHead java_out = null;
  1295     	/*PIDE*/if (!IsaToJava.is_message(xml_out)) {
  1296     	/*PIDE*/  java_out = IsaToJava.reset_calchead_out(xml_out);
  1297     	/*PIDE*/  return_val = java_out.getCalcHead();
  1298     	/*PIDE*/bridge_.log(1, "<--ISA: " + xml_out);    	
  1299     	/*PIDE*/} else
  1300         /*PIDE*/  bridge_.log(1, "<--ISA: IsaToJava.is_message: REVIEW!");    	
  1301 
  1302     	/*TTY*/ResponseWrapper wrapper = interpretSML(calc_tree_id, "resetCalcHead @calcid@;", false);
  1303     	/*TTY*/return_val = (CalcHead) wrapper.getResponse();
  1304         return return_val;
  1305     }
  1306 
  1307     /** MATH_ENGINE: val setContext : calcID -> pos' -> guh -> XML.tree */
  1308     public CalcHead setContext(int javaCalcID, ContextProblem context, Position pos ) throws RemoteException {
  1309     	CalcHead return_val = null;
  1310     	/*PIDE*/int sml_id = (Integer) java_calcid_to_smlcalcid_.get(new Integer(javaCalcID));
  1311     	/*PIDE*/bridge_.log(1, "-->ISA: " + "setContext " + sml_id + " " + pos.toSMLString() + " \"" + context.getKEStoreKey().toString() + "\";");
  1312     	
  1313     	/*PIDE*/XML.Tree TODO = JavaToIsa.set_ctxt(new scala.math.BigInt(BigInteger.valueOf(sml_id)), 
  1314     	/*PIDE*/  pos, context.getKEStoreKey().toString() + "\"");
  1315     	/*PIDE*/bridge_.log(1, "-->ISA: " + TODO);
  1316     	/*PIDE*/XML.Tree xml_out = connection_to_kernel_.invoke(Operations.SET_CTXT, TODO);
  1317 
  1318     	/*PIDE*/IntCEvent java_out = null;
  1319     	/*PIDE*/if (!IsaToJava.is_message(xml_out)) {
  1320     	/*PIDE*/  java_out = IsaToJava.set_ctxt_out(xml_out);
  1321 //TODO IsaToJava.set_ctxt_out REPAIR: CalcHead instead of CEvent
  1322 //    	/*PIDE*/  return_val = java_out.getCEvent();
  1323 //    	/*PIDE*/bridge_.log(1, "<--ISA: " + xml_out);    	
  1324     	/*PIDE*/} ///////////////else
  1325 //        /*PIDE*/  bridge_.log(1, "<--ISA: IsaToJava.is_message: REVIEW!");    	
  1326 
  1327     	/*TTY*/ResponseWrapper wrapper =  interpretSML(javaCalcID,
  1328     	/*TTY*/  "setContext @calcid@ " + pos.toSMLString() + " \"" + context.getKEStoreKey().toString() + "\";", false);
  1329     	/*TTY*/if(wrapper == null) return_val = null;
  1330     	/*TTY*/else return_val = (CalcHead) wrapper.getResponse();
  1331         return return_val;
  1332     }   
  1333 
  1334     /**
  1335      * @see isac.interfaces.IToCalc#setMethod()
  1336      * 
  1337      * MATH_ENGINE: val setMethod : calcID -> metID -> XML.tree
  1338      */
  1339     public CalcHead setMethod(int calc_tree_id, MethodID id) throws RemoteException {
  1340     	CalcHead return_val = null;
  1341     	/*PIDE*/int sml_id = (Integer) java_calcid_to_smlcalcid_.get(new Integer(calc_tree_id));
  1342     	/*PIDE*/bridge_.log(1, "-->ISA: " + "setMethod " + sml_id + " " + id.toSMLString() + ";");
  1343     	
  1344     	/*PIDE*/XML.Tree TODO = JavaToIsa.set_met(new scala.math.BigInt(BigInteger.valueOf(sml_id)), id.getID());    	
  1345     	/*PIDE*/bridge_.log(1, "-->ISA: " + TODO);
  1346     	/*PIDE*/XML.Tree xml_out = connection_to_kernel_.invoke(Operations.SET_MET, TODO);
  1347 
  1348     	/*PIDE*/IntCalcHead java_out = null;
  1349     	/*PIDE*/if (!IsaToJava.is_message(xml_out)) {
  1350     	/*PIDE*/  java_out = IsaToJava.set_met_out(xml_out);
  1351     	/*PIDE*/  return_val = java_out.getCalcHead();
  1352     	/*PIDE*/bridge_.log(1, "<--ISA: " + xml_out);    	
  1353     	/*PIDE*/} else
  1354         /*PIDE*/  bridge_.log(1, "<--ISA: IsaToJava.is_message: REVIEW!");    	
  1355 
  1356     	/*TTY*/ResponseWrapper wrapper = interpretSML(calc_tree_id,
  1357     	/*TTY*/  "setMethod @calcid@ " + id.toSMLString() + ";", false);
  1358     	/*TTY*/return_val = (CalcHead) wrapper.getResponse();
  1359         return return_val;
  1360     }
  1361 
  1362     /** MATH_ENGINE: val setNextTactic : calcID -> tac -> XML.tree */
  1363     public int setNextTactic(int id, Tactic tactic) {
  1364     	int return_val;
  1365     	/*PIDE*/int sml_id = (Integer) java_calcid_to_smlcalcid_.get(new Integer(id));
  1366     	/*PIDE*/bridge_.log(1, "-->ISA: " + "setNextTactic " + sml_id + " (" + tactic.toSMLString() + ");");    	
  1367 
  1368     	/*PIDE*/XML.Tree TODO = JavaToIsa.set_next_tac(new scala.math.BigInt(BigInteger.valueOf(sml_id)), tactic);    	
  1369     	/*PIDE*/bridge_.log(1, "-->ISA: " + TODO);
  1370     	/*PIDE*/XML.Tree xml_out = connection_to_kernel_.invoke(Operations.SET_NEXT_TAC, TODO);
  1371 //TODO IsaToJava.FOR setNextTactic IS MISSING
  1372     	/*PIDE*/bridge_.log(1, "<--ISA: " + xml_out);
  1373 
  1374     	//*PIDE*/return_val = TODOTODOTODOTODO;
  1375     	/*TTY*/ResponseWrapper wrapper = interpretSML(id, 
  1376     	/*TTY*/  "setNextTactic @calcid@ (" + tactic.toSMLString() + ");", false);
  1377     	/*TTY*/if (wrapper == null) return_val = -1;//WN050223 response ... MESSAGE not parsed
  1378     	/*TTY*/if (wrapper.getResponse() == null) { return_val = 0; //Everything is ok
  1379     	/*TTY*/} else { return_val = -1; } //An Error occcured
  1380         return return_val;
  1381     }
  1382     
  1383     /**
  1384      * @see isac.interfaces.IToCalc#setProblem()
  1385      * 
  1386      * MATH_ENGINE: val setProblem : calcID -> pblID -> XML.tree
  1387      */
  1388     public CalcHead setProblem(int calc_tree_id, ProblemID id) throws RemoteException {
  1389     	CalcHead return_val = null;
  1390     	/*PIDE*/int sml_id = (Integer) java_calcid_to_smlcalcid_.get(new Integer(calc_tree_id));
  1391     	/*PIDE*/bridge_.log(1, "-->ISA: " + "setProblem " + sml_id + " " + id.toSMLString() + ";");
  1392     	
  1393     	/*PIDE*/XML.Tree TODO = JavaToIsa.set_met(new scala.math.BigInt(BigInteger.valueOf(sml_id)), id.getID());    	
  1394     	/*PIDE*/bridge_.log(1, "-->ISA: " + TODO);
  1395     	/*PIDE*/XML.Tree xml_out = connection_to_kernel_.invoke(Operations.SET_PBL, TODO);
  1396 
  1397     	/*PIDE*/IntCalcHead java_out = null;
  1398     	/*PIDE*/if (!IsaToJava.is_message(xml_out)) {
  1399     	/*PIDE*/  java_out = IsaToJava.set_met_out(xml_out);
  1400     	/*PIDE*/  return_val = java_out.getCalcHead();
  1401     	/*PIDE*/bridge_.log(1, "<--ISA: " + xml_out);    	
  1402     	/*PIDE*/} else
  1403         /*PIDE*/  bridge_.log(1, "<--ISA: IsaToJava.is_message: REVIEW!");    	
  1404 
  1405     	/*TTY*/ResponseWrapper wrapper = interpretSML(calc_tree_id,
  1406     	/*TTY*/  "setProblem @calcid@ " + id.toSMLString() + ";", false);
  1407     	/*TTY*/return_val = (CalcHead) wrapper.getResponse();
  1408         return return_val;
  1409     }
  1410 
  1411     /**
  1412      * @see isac.interfaces.IToCalc#setTheory()
  1413      * 
  1414      * TODO/WN150812: use implementation in Math_Engine.
  1415      * MATH_ENGINE: val setTheory : calcID -> thyID -> XML.tree
  1416      */
  1417     public CalcHead setTheory(int calc_tree_id, String thy_id)
  1418             throws RemoteException {
  1419     	CalcHead return_val = null;
  1420     	Position pos = null;
  1421         //---FIXXXME.WN050809 hack until setTheory pushed into SML-kernel
  1422     	/*PIDE*/int sml_id = (Integer) java_calcid_to_smlcalcid_.get(new Integer(calc_tree_id));
  1423 
  1424     	/*PIDE*/bridge_.log(1, "-->ISA: " + "(*setTheory*)setNextTactic " + sml_id + " (Specify_Theory \"" + thy_id + "\");");    	
  1425     	/*PIDE*/SimpleTactic tac = new SimpleTactic("Specify_Theory", thy_id + "\"");
  1426     	/*PIDE*/XML.Tree TODO = JavaToIsa.set_next_tac(new scala.math.BigInt(BigInteger.valueOf(sml_id)), tac);    	
  1427     	/*PIDE*/bridge_.log(1, "-->ISA: " + TODO);
  1428     	/*PIDE*/XML.Tree xml_out = connection_to_kernel_.invoke(Operations.SET_NEXT_TAC, TODO);
  1429 //TODO IsaToJava.  POSTPONED TO NEXT + 1 STEP
  1430     	/*PIDE*/bridge_.log(1, "<--ISA: " + xml_out);
  1431 
  1432     	/*PIDE*/bridge_.log(1, "-->ISA: " + "(*setTheory*)autoCalculate " + sml_id + " (Step 1);");   	
  1433         //----vvv delete at end of phase-2a ------------------------------------------------
  1434     	/*PIDE*/TODO = JavaToIsa.auto_calculate(new scala.math.BigInt(BigInteger.valueOf(sml_id)), 
  1435     	/*PIDE*/  "Step", new scala.math.BigInt(BigInteger.valueOf(1)));
  1436     	/*PIDE*/bridge_.log(1, "-->ISA: " + TODO);
  1437     	/*PIDE*/xml_out = connection_to_kernel_.invoke(Operations.AUTO_CALC, TODO);
  1438 //GOON    	pos = (Position)xml_out;
  1439     	/*PIDE*/bridge_.log(1, "<--ISA: " + xml_out);
  1440 
  1441     	/*PIDE*/bridge_.log(1, "-->ISA: " + "(*setTheory*)getActiveFormula " + sml_id + ";");   	
  1442     	/*PIDE*/TODO = JavaToIsa.get_active_form(new scala.math.BigInt(BigInteger.valueOf(sml_id)));    	
  1443     	/*PIDE*/pos = new Position(); //TODO get from get_active_form_out !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  1444     	/*PIDE*/pos.setKind("DUMMY"); //TODO get from get_active_form_out !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  1445     	/*PIDE*/xml_out = connection_to_kernel_.invoke(Operations.GET_ACTIVE_FORM, TODO);
  1446     	/*PIDE*/bridge_.log(1, "<--ISA: " + xml_out);
  1447     	
  1448     	/*PIDE*/bridge_.log(1, "-->ISA: " + "(*setTheory*)refFormula " + sml_id + " " + pos.toSMLString() + ";");
  1449     	/*PIDE*/TODO = JavaToIsa.ref_formula(new scala.math.BigInt(BigInteger.valueOf(sml_id)), pos);//^^pos.setKind("DUMMY")
  1450     	/*PIDE*/bridge_.log(1, "-->ISA: " + TODO);
  1451     	/*PIDE*/xml_out = connection_to_kernel_.invoke(Operations.REF_FORMULA, TODO);
  1452     	/*PIDE*/bridge_.log(1, "<--ISA: " + xml_out);
  1453 
  1454     	//*PIDE*/return_val = TODOTODOTODOTODO;
  1455        	/*PIDE*///\---End hack
  1456        	/*TTY*///---FIXXXME.WN050809 hack until setTheory pushed into SML-kernel
  1457     	/*TTY*/ResponseWrapper wrapper = interpretSML(calc_tree_id,
  1458     	/*TTY*/  "(*setTheory*)setNextTactic @calcid@ (Specify_Theory \"" + thy_id + "\");", false);
  1459     	/*TTY*/wrapper = interpretSML(calc_tree_id,
  1460     	/*TTY*/  "(*setTheory*)autoCalculate @calcid@ (Step 1);", false);
  1461     	/*TTY*///drop the CalcChanged returned by autoCalculate
  1462     	/*TTY*/wrapper = interpretSML(calc_tree_id, 
  1463     	/*TTY*/  "(*setTheory*)getActiveFormula @calcid@ ;", false);
  1464     	/*TTY*/pos = moveSuccess(wrapper);
  1465     	/*TTY*/wrapper = interpretSML(calc_tree_id,
  1466     	/*TTY*/  "(*setTheory*)refFormula @calcid@ " + pos.toSMLString() + ";", false);
  1467     	/*TTY*/return_val = (CalcHead) wrapper.getResponse();
  1468         //\---End hack
  1469         return return_val;
  1470     }
  1471 
  1472     /***********************************************************************
  1473      * Below are methods not contained in MATH_ENGINE, rather
  1474      * they composed from other methods in Math_Engine. 
  1475      */
  1476 
  1477     /**
  1478      * @see isac.interfaces.IToCalc#completeCalcHead()
  1479      */
  1480     public CalcHead completeCalcHead(int calc_tree_id) {
  1481     	CalcHead return_val = null;
  1482     	Position pos = null;
  1483     	/*PIDE*/int sml_id = (Integer) java_calcid_to_smlcalcid_.get(new Integer(calc_tree_id));
  1484         //---FIXXXME.WN050809 hack until setTheory pushed into SML-kernel
  1485 
  1486     	/*PIDE*/bridge_.log(1, "-->ISA: " + "(*completeCalcHead*)autoCalculate " + sml_id + "CompleteCalcHead;");
  1487     	/*PIDE*/XML.Tree TODO = JavaToIsa.auto_calculate(new scala.math.BigInt(BigInteger.valueOf(sml_id)), 
  1488     	/*PIDE*/  "CompleteCalcHead", new scala.math.BigInt(BigInteger.valueOf(0)));
  1489     	/*PIDE*/bridge_.log(1, "-->ISA: " + TODO);
  1490     	/*PIDE*/XML.Tree xml_out = connection_to_kernel_.invoke(Operations.AUTO_CALC, TODO);
  1491     	/*PIDE*/bridge_.log(1, "<--ISA: " + xml_out);
  1492     	
  1493     	/*PIDE*/bridge_.log(1, "-->ISA: " + "(*completeCalcHead*)getActiveFormula " + sml_id + ";");
  1494     	/*PIDE*/TODO = JavaToIsa.get_active_form(new scala.math.BigInt(BigInteger.valueOf(sml_id)));    	
  1495     	/*PIDE*/pos = new Position(); //TODO get from auto_calculate_out !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  1496     	/*PIDE*/pos.setKind("DUMMY"); //TODO get from auto_calculate_out !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  1497     	/*PIDE*/bridge_.log(1, "-->ISA: " + TODO);
  1498     	/*PIDE*/xml_out = connection_to_kernel_.invoke(Operations.GET_ACTIVE_FORM, TODO);
  1499     	/*PIDE*/bridge_.log(1, "<--ISA: " + xml_out);
  1500     	
  1501     	/*PIDE*/bridge_.log(1, "-->ISA: " + "(*completeCalcHead*)refFormula " + sml_id + pos.toSMLString() + ";");
  1502     	/*PIDE*/TODO = JavaToIsa.ref_formula(new scala.math.BigInt(BigInteger.valueOf(sml_id)), pos);    	
  1503     	/*PIDE*/bridge_.log(1, "-->ISA: " + TODO);
  1504     	/*PIDE*/xml_out = connection_to_kernel_.invoke(Operations.REF_FORMULA, TODO);
  1505     	/*PIDE*/bridge_.log(1, "<--ISA: " + xml_out);
  1506     	
  1507     	//*PIDE*/return_val = TODOTODOTODOTODO;
  1508        	/*PIDE*///\---End hack
  1509        	/*TTY*///---FIXXXME.WN050809 hack until setTheory pushed into SML-kernel
  1510     	/*TTY*/ResponseWrapper wrapper = interpretSML(calc_tree_id,
  1511     	/*TTY*/  "(*completeCalcHead*)autoCalculate @calcid@ CompleteCalcHead;", false);
  1512     	/*TTY*///drop the CalcChanged returned by autoCalculate
  1513     	/*TTY*/wrapper = interpretSML(calc_tree_id,
  1514     	/*TTY*/  "(*completeCalcHead*)getActiveFormula @calcid@ ;", false);
  1515     	/*TTY*/pos = moveSuccess(wrapper);
  1516     	/*TTY*/wrapper = interpretSML(calc_tree_id,
  1517     	/*TTY*/  "(*completeCalcHead*)refFormula @calcid@ " + pos.toSMLString() + ";", false);
  1518     	/*TTY*/return_val = (CalcHead) wrapper.getResponse();
  1519         //\---End hack
  1520         return return_val;
  1521     }
  1522 
  1523     /**
  1524      * @see isac.interfaces.IToCalc#completeModel() WN050809 push this method
  1525      *      through to the SML-kernel
  1526      */
  1527     public CalcHead completeModel(int calc_tree_id) throws RemoteException {
  1528        	CalcHead return_val = null;
  1529     	Position pos = null;
  1530     	/*PIDE*/int sml_id = (Integer) java_calcid_to_smlcalcid_.get(new Integer(calc_tree_id));
  1531         //---FIXXXME.WN050809 hack until setTheory pushed into SML-kernel
  1532 
  1533     	/*PIDE*/bridge_.log(1, "-->ISA: " + "(*completeModel*)autoCalculate " + sml_id + " CompleteModel;");
  1534     	/*PIDE*/XML.Tree TODO = JavaToIsa.auto_calculate(new scala.math.BigInt(BigInteger.valueOf(sml_id)), 
  1535     	/*PIDE*/  "CompleteModel", new scala.math.BigInt(BigInteger.valueOf(0)));
  1536     	/*PIDE*/bridge_.log(1, "-->ISA: " + TODO);
  1537     	/*PIDE*/XML.Tree xml_out = connection_to_kernel_.invoke(Operations.AUTO_CALC, TODO);
  1538     	/*PIDE*/bridge_.log(1, "<--ISA: " + xml_out);
  1539     	
  1540     	/*PIDE*/bridge_.log(1, "-->ISA: " + "(*completeModel*)getActiveFormula " + sml_id + ";");
  1541     	/*PIDE*/TODO = JavaToIsa.get_active_form(new scala.math.BigInt(BigInteger.valueOf(sml_id)));    	
  1542     	/*PIDE*/pos = new Position(); //TODO get from auto_calculate_out !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  1543     	/*PIDE*/pos.setKind("DUMMY"); //TODO get from auto_calculate_out !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  1544     	/*PIDE*/bridge_.log(1, "-->ISA: " + TODO);
  1545     	/*PIDE*/xml_out = connection_to_kernel_.invoke(Operations.GET_ACTIVE_FORM, TODO);
  1546     	/*PIDE*/bridge_.log(1, "<--ISA: " + xml_out);
  1547     	
  1548     	/*PIDE*/bridge_.log(1, "-->ISA: " + "(*completeModel*)refFormula " + sml_id + " " + pos.toSMLString() + ";");
  1549     	/*PIDE*/TODO = JavaToIsa.ref_formula(new scala.math.BigInt(BigInteger.valueOf(sml_id)), pos);    	
  1550     	/*PIDE*/bridge_.log(1, "-->ISA: " + TODO);
  1551     	/*PIDE*/xml_out = connection_to_kernel_.invoke(Operations.REF_FORMULA, TODO);
  1552     	/*PIDE*/bridge_.log(1, "<--ISA: " + xml_out);
  1553     	
  1554     	//*PIDE*/return_val = TODOTODOTODOTODO;
  1555        	/*PIDE*///\---End hack
  1556        	/*TTY*///---FIXXXME.WN050809 hack until setTheory pushed into SML-kernel
  1557        	/*TTY*/ResponseWrapper wrapper = interpretSML(calc_tree_id,
  1558        	/*TTY*/  "(*completeModel*)autoCalculate @calcid@ CompleteModel;", false);
  1559        	/*TTY*///drop the CalcChanged returned by autoCalculate
  1560        	/*TTY*/wrapper = interpretSML(calc_tree_id,
  1561        	/*TTY*/  "(*completeModel*)getActiveFormula @calcid@ ;", false);
  1562        	/*TTY*/pos = moveSuccess(wrapper);
  1563        	/*TTY*/wrapper = interpretSML(calc_tree_id,
  1564        	/*TTY*/  "(*completeModel*)refFormula @calcid@ " + pos.toSMLString() + ";", false);
  1565     	/*TTY*/return_val = (CalcHead) wrapper.getResponse();
  1566         //\---End hack
  1567         return return_val;
  1568     }
  1569 
  1570     /**
  1571      * @see isac.interfaces.IToCalc#nextSpecify() WN050809 push this method
  1572      *      through to the SML-kernel.
  1573      */
  1574     public CalcHead nextSpecify(int calc_tree_id) throws RemoteException {
  1575        	CalcHead return_val = null;
  1576     	Position pos = null;
  1577     	/*PIDE*/int sml_id = (Integer) java_calcid_to_smlcalcid_.get(new Integer(calc_tree_id));
  1578        	/*PIDE*///---FIXXXME.WN050809 hack until setTheory pushed into SML-kernel
  1579 
  1580     	/*PIDE*/bridge_.log(1, "-->ISA: " + "(*nextSpecify*)autoCalculate " + sml_id + " (Step 1);");
  1581     	/*PIDE*/XML.Tree TODO = JavaToIsa.auto_calculate(new scala.math.BigInt(BigInteger.valueOf(sml_id)), 
  1582     	/*PIDE*/  "Step", new scala.math.BigInt(BigInteger.valueOf(1)));
  1583     	/*PIDE*/bridge_.log(1, "-->ISA: " + TODO);
  1584     	/*PIDE*/XML.Tree xml_out = connection_to_kernel_.invoke(Operations.AUTO_CALC, TODO);
  1585     	/*PIDE*/bridge_.log(1, "<--ISA: " + xml_out);
  1586     	
  1587     	/*PIDE*/bridge_.log(1, "-->ISA: " + "(*nextSpecify*)getActiveFormula " + sml_id + ";");
  1588     	/*PIDE*/TODO = JavaToIsa.get_active_form(new scala.math.BigInt(BigInteger.valueOf(sml_id)));    	
  1589     	/*PIDE*/pos = new Position(); //TODO get from get_active_form_out !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  1590     	/*PIDE*/pos.setKind("DUMMY"); //TODO get from get_active_form_out !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  1591     	/*PIDE*/xml_out = connection_to_kernel_.invoke(Operations.GET_ACTIVE_FORM, TODO);
  1592     	/*PIDE*/bridge_.log(1, "<--ISA: " + xml_out);
  1593     	
  1594     	/*PIDE*/bridge_.log(1, "-->ISA: " + "(*nextSpecify*)refFormula " + sml_id + pos.toSMLString() + ";");
  1595     	/*PIDE*/TODO = JavaToIsa.ref_formula(new scala.math.BigInt(BigInteger.valueOf(sml_id)), pos);//^^pos.setKind("DUMMY")
  1596     	/*PIDE*/bridge_.log(1, "-->ISA: " + TODO);
  1597     	/*PIDE*/xml_out = connection_to_kernel_.invoke(Operations.REF_FORMULA, TODO);
  1598     	/*PIDE*/bridge_.log(1, "<--ISA: " + xml_out);
  1599     	
  1600     	//*PIDE*/return_val = TODOTODOTODOTODO;
  1601        	/*PIDE*///\---End hack
  1602        	/*TTY*///---FIXXXME.WN050809 hack until setTheory pushed into SML-kernel
  1603        	/*TTY*/ResponseWrapper wrapper = interpretSML(calc_tree_id,
  1604        	/*TTY*/  "(*nextSpecify*)autoCalculate @calcid@ (Step 1);", false);
  1605        	/*TTY*///drop the CalcChanged returned by autoCalculate
  1606        	/*TTY*/wrapper = interpretSML(calc_tree_id,
  1607        	/*TTY*/  "(*nextSpecify*)getActiveFormula @calcid@ ;", false);
  1608        	/*TTY*/pos = moveSuccess(wrapper);
  1609        	/*TTY*/wrapper = interpretSML(calc_tree_id,
  1610        	/*TTY*/  "(*nextSpecify*)refFormula @calcid@ " + pos.toSMLString() + ";", false);
  1611        	/*TTY*/return_val = (CalcHead) wrapper.getResponse();
  1612        	/*TTY*///\---End hack
  1613         return return_val;
  1614     }
  1615 
  1616     /***********************************************************************
  1617      * Below are methods not implemented in MATH_ENGINE at all,
  1618      * or only very fragmentarily.
  1619      * WN150812 here are also methods, where the status is not clarified. 
  1620      * Some methods seem to be replaced by similar ones.
  1621      * TODO: review IBridgeRMI, MathEngine, etc.
  1622      */
  1623 
  1624     /**
  1625      * @see isac.interfaces.ICalcIterator#tryMatchMethod(MethodID)
  1626      * @deprecated WN150812: not impl. in Math_Engine.
  1627      */
  1628     public Match initMatchMethod(int javaCalcID) throws RemoteException {
  1629         ResponseWrapper wrapper = interpretSML(javaCalcID,
  1630           "initMatchMethod @calcid@ ;", false);
  1631         Object response = wrapper.getResponse();
  1632         CalcHead ch = (CalcHead) response;
  1633         Match m = new Match(ch.getSpecification().getProblem(), ch
  1634                 .getStatusString(), ch.getHeadLine(), ch.getModel());
  1635         return m;
  1636     }
  1637     
  1638     /**
  1639      * @see isac.interfaces.ICalcIterator#tryMatchProblem(HierarchyKey)
  1640      * @deprecated WN150812: not impl. in Math_Engine.
  1641      */
  1642     public Match initMatchProblem(int javaCalcID) {
  1643         ResponseWrapper wrapper = interpretSML(javaCalcID,
  1644           "initMatchProblem @calcid@ ;", false);
  1645         Object response = wrapper.getResponse();
  1646         CalcHead ch = (CalcHead) response;
  1647         Match m = new Match(ch.getSpecification().getProblem(), ch
  1648                 .getStatusString(), ch.getHeadLine(), ch.getModel());
  1649         return m;
  1650     }
  1651 
  1652     /**
  1653      * @deprecated in favour of getFormula
  1654      * WN150812: but used frequently ?!
  1655      */
  1656     public boolean moveFormula(int javaCalcID, int iteratorID) {
  1657         ResponseWrapper wrapper = interpretSML(javaCalcID,
  1658           "moveFormula @calcid@ " + iteratorID + ";", false);
  1659         return true;//WN041208 moveSuccess(wrapper);
  1660     }
  1661 
  1662     /** WN150812 unused ? */
  1663     private Position moveSuccess(ResponseWrapper wrapper) {
  1664         if (wrapper == null)
  1665             return null;
  1666         else {
  1667             Object r = wrapper.getResponse();
  1668             if (r instanceof CMessage)
  1669                 return null;//TODO.WN041209 handle messages
  1670             else {
  1671                 Position p = (Position) wrapper.getResponse();
  1672                 return p;
  1673             }
  1674         }
  1675     }
  1676 
  1677     /**
  1678      * @deprecated in favour of getTactic
  1679      * WN150812: but used frequently ?!
  1680      */
  1681     public boolean moveTactic(int javaCalcID, int iteratorID) {
  1682         ResponseWrapper wrapper = interpretSML(javaCalcID,
  1683                 "moveTactic @calcid@ " + iteratorID + ";", false);
  1684         return true;//WN041208 moveSuccess(wrapper);
  1685     }
  1686 
  1687     /**
  1688      * @see isac.interfaces.ICalcIterator#tryMatchMethod(MethodID)
  1689      * @deprecated is not impl. in math-engine !!!
  1690      */
  1691     public Match tryMatchMethod(int javaCalcID, MethodID keStoreID)
  1692             throws RemoteException {
  1693         ResponseWrapper wrapper = interpretSML(javaCalcID,
  1694                 "tryMatchMethod @calcid@ " + keStoreID.toSMLString() + ";",
  1695                 false);
  1696         Object response = wrapper.getResponse();
  1697         CalcHead ch = (CalcHead) response;
  1698         Match m = new Match(ch.getSpecification().getProblem(), ch
  1699                 .getStatusString(), ch.getHeadLine(), ch.getModel());
  1700         return m;
  1701     }
  1702 
  1703     /** enforced by IBridgeRMI, WN150812: exp-, met-, pbl-, thy-contexts all work --
  1704      * -- so ContextProblem seems to do ContextMethod and ContextTheory, too */
  1705 	@Override
  1706 	public CalcHead setContext(int javaCalcID, ContextMethod context, Position pos) throws RemoteException {
  1707 		return null;
  1708 	}
  1709 
  1710     /** enforced by IBridgeRMI, WN150812: exp-, met-, pbl-, thy-contexts all work --
  1711      * -- so ContextProblem seems to do ContextMethod and ContextTheory, too */
  1712 	@Override
  1713 	public CChanged setContext(int javaCalcID, ContextTheory context, Position pos) throws RemoteException {
  1714 		return null;
  1715 	}
  1716     
  1717     /**
  1718      * @see isac.interfaces.ICalcIterator#tryMatchProblem(HierarchyKey)
  1719      * 
  1720      * WN150812: tryMatchProblem, trymatch only partially implemented in Math_Engine
  1721      */
  1722     public Match tryMatchProblem(int javaCalcID, ProblemID problemID) {
  1723         ResponseWrapper wrapper = interpretSML(javaCalcID,
  1724                 "tryMatchProblem @calcid@ " + problemID.toSMLString() + ";",
  1725                 false);
  1726         Object response = wrapper.getResponse();
  1727         CalcHead ch = (CalcHead) response;
  1728         Match m = new Match(ch.getSpecification().getProblem(), ch
  1729                 .getStatusString(), ch.getHeadLine(), ch.getModel());
  1730         return m;
  1731     }
  1732 
  1733     /**
  1734      * @see isac.interfaces.ICalcIterator#tryRefineProblem(HierarchyKey)
  1735      * @deprecated in favour of refineProblem.
  1736      */
  1737     public Match tryRefineProblem(int javaCalcID, ProblemID problemID) {
  1738         ResponseWrapper wrapper = interpretSML(javaCalcID,
  1739                 "tryRefineProblem @calcid@ " + problemID.toSMLString() + ";",
  1740                 false);
  1741         Object response = wrapper.getResponse();
  1742         CalcHead ch = (CalcHead) response;
  1743         Match m = new Match(ch.getSpecification().getProblem(), ch
  1744                 .getStatusString(), ch.getHeadLine(), ch.getModel());
  1745         return m;
  1746     }
  1747 
  1748     /***********************************************************************
  1749      * Below are methods for restoring Isabelle/Isac after a crash.
  1750      * This never worked, is to be deleted and 
  1751      * to be reconsidered with introduction of libisabelle.
  1752      */
  1753 
  1754     /**
  1755      * This method is used when the kernel crashes and the CalcTrees need to be
  1756      * entered again to the kernel to restore the previous state. The
  1757      * Java-CalcIDs stay the same
  1758      */
  1759     public void restoreExistingCalcTrees() {
  1760         bridge_.log(1, "---- entering restoreExistingCalcTrees");
  1761         Iterator it = java_calcid_to_smlcalcid_.keySet().iterator();
  1762         // keySet = javaCalcIDs
  1763         int javaCalcID, newSmlCalcID;
  1764         Vector v;
  1765         while (it.hasNext()) {
  1766             //bridge.log(1, "1");
  1767             //int i = ((Integer)it.next()).intValue();
  1768             javaCalcID = ((Integer) it.next()).intValue();
  1769             //bridge.log(1, "2");
  1770             v = saveCalcTree(javaCalcID);
  1771             //bridge.log(1, "3");
  1772             this.restoreToSML(javaCalcID, v);
  1773         }
  1774         bridge_.log(1, "---- done restoreExistingCalcTrees");
  1775     }
  1776 
  1777     private void restoreToSML(int javaCalcID, Vector v) {
  1778         Iterator it = ((Vector) v.clone()).iterator();
  1779         CalcTree result = null;
  1780         String s = (String) it.next();
  1781         int smlCalcID = newCalculation(javaCalcID, s, null/*never worked*/, true);
  1782         //javaCalcIDtoSmlCalcID.put(new Integer(javaCalcID), new
  1783         // Integer(smlCalcID));
  1784         //int smlID = ((Integer)javaCalcIDtoSmlCalcID.get(new
  1785         // Integer(calcID))).intValue();
  1786         while (it.hasNext()) {
  1787             s = (String) it.next();
  1788             interpretSML(javaCalcID, s, true);
  1789         }
  1790     }
  1791 
  1792     /**
  1793      * Save a calcTree for later restoring (probably to another SML Kernel)
  1794      * 
  1795      * @param calcTreeID
  1796      *            the ID of the calcTree
  1797      * @return a vector containing strings. This is representatation of the
  1798      *         status of the calcTree
  1799      */
  1800     public Vector saveCalcTree(int calcTreeID) {
  1801         this.bridge_.log(1, "----------------begin saving calcTree "
  1802                 + calcTreeID + "------------");
  1803         return (Vector) inputs_.get(new Integer(calcTreeID));
  1804     }
  1805 
  1806     
  1807 }