/**
   * Initialize the communication with OMC.
   *
   * @throws ConnectException if we're unable to start communicating with the server
   */
  private void init() throws ConnectException {
    /*
     * Get type of operating system, used for finding object
     * reference and starting OMC if the reference is faulty
     */
    os = getOs();

    /* See if an OMC server is already running */
    File f = new File(getPathToObject());
    String stringifiedObjectReference = null;
    if (!f.exists()) {
      /* If a server isn't running, start it */
      logOMCStatus("No OMC object reference found, starting server.");
      startServer();
    } else {
      logOMCStatus("Old OMC CORBA object reference present," + " assuming OMC is running.");
    }

    /* Read in the CORBA OMC object from a file on disk */
    stringifiedObjectReference = readObjectFromFile();

    /*
     * Setup up OMC object reference by initializing ORB and then
     * converting the string object to a real CORBA object.
     */
    setupOmcc(stringifiedObjectReference);

    try {
      /*
       * Test the server by trying to send an expression to it.
       * This might fail if the object reference found on disk didn't
       * have a corresponding server running. If a server is missing,
       * catch an exception and try starting a server.
       */
      logOMCStatus("Trying to send expression to OMC.");
      omcc.sendExpression("1+1");
      logOMCStatus("Expression sent successfully.");
    } catch (org.omg.CORBA.COMM_FAILURE e) {
      /* Start server and set up omcc */
      logOMCStatus("Failed sending expression, will try to start OMC.");
      existingCorbaFileIsNew = false;
      startServer();
      stringifiedObjectReference = readObjectFromFile();
      setupOmcc(stringifiedObjectReference);

      try {
        /* Once again try to send an expression to OMC. If it fails this
         * time it's time to send back an exception to the caller of
         * this function. */
        logOMCStatus("Trying to send expression to OMC.");
        omcc.sendExpression("1+1");
        logOMCStatus("Expression sent successfully.");
      } catch (org.omg.CORBA.COMM_FAILURE x) {
        logOMCStatus("Failed sending expression, giving up.");
        throw new ConnectException("Unable to start the OpenModelica Compiler.");
      }
    }

    hasInitialized = true;
  }
  // TODO add synchronization so that two threads don't fudge up each others
  // communication with OMC
  // old synchronization aka 'private synchronized String sendExpression(String exp)'
  // doesnt work when there is possibility of multiple instances of OMCProxy objects
  public String sendExpression(String exp) throws ConnectException {
    String retval = null;

    if (hasInitialized == false) {
      init();
    }

    try {
      logOMCCall(exp);
      retval = omcc.sendExpression(exp);
      logOMCReply(retval);
    } catch (org.omg.CORBA.COMM_FAILURE x) {
      logOMCCallError("Error while sending expression " + exp + " [" + x + "]");
      /* lost connection to OMC or something */
      throw new ConnectException(
          "Couldn't send expression to the " + "OpenModelica Compiler. Tried sending: " + exp);
    }

    return retval;
  }