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