Package com.sun.star.lib.uno.environments.remote

Examples of com.sun.star.lib.uno.environments.remote.IMessage


      Throwable throwable = null;

      try {
        do {
          // Use the protocol to read a job.
          IMessage iMessage = _iProtocol.readMessage(_inputStream);
         
         
          if(iMessage.getThreadId().equals(_threadId)) {
            continue;
          }
         
          // Take care of special methods release and acquire
          if(iMessage.getOperation() != null && iMessage.getOperation().equals("release")) {
            _java_environment.revokeInterface(iMessage.getOid(), new Type(iMessage.getInterface()));
            remRefHolder(new Type(iMessage.getInterface()), iMessage.getOid());
           
            if(iMessage.mustReply())
              sendReply(false, iMessage.getThreadId(), null);
          }
          else if(iMessage.getOperation() != null && iMessage.getOperation().equals("acquire")) {
            String oid_o[] = new String[]{iMessage.getOid()};
            _java_environment.registerInterface(null, oid_o, new Type(iMessage.getInterface()));
           
            addRefHolder(new Type(iMessage.getInterface()), iMessage.getOid());
          }
          else {
            Object object = null;
           
            if(iMessage.getOperation() != null) { // is it a request
              object = _java_environment.getRegisteredInterface(iMessage.getOid(), new Type(iMessage.getInterface()));
             
              Object xexception = null;
             
              if(object == null) { // this is an unknown oid, so we may have to ask the XInstanceProvider
                if(_xInstanceProvider == null) // we have neither an object nor an instance provider -> exception
                  xexception = new com.sun.star.uno.RuntimeException(getClass().getName() + ".dispatch - no instance provider set and unknown object:" + iMessage.getOid());
               
                else {
                  try {
                    object = _xInstanceProvider.getInstance(iMessage.getOid());
                   
                    if(object == null && !iMessage.getOperation().equals("queryInterface"))
                      xexception = new com.sun.star.uno.RuntimeException(
                        getClass().getName()
                        + ".dispatch: instance provider returned null and operation >"
                        + iMessage.getOperation()
                        + "< not supported on null");
                  }
                  catch(com.sun.star.container.NoSuchElementException noSuchElementException) {
                    xexception = new com.sun.star.uno.RuntimeException(getClass().getName() + ".dispatch - wrapped exception:" + noSuchElementException);
                  }
                  catch(com.sun.star.uno.RuntimeException runtimeException) {
                    xexception = runtimeException;
                  }
                }
              }
             
              if(xexception != null) {
                // an exception occurred while trying to get an instance.
                // propagate it.
                sendReply(true, iMessage.getThreadId(), xexception);
                iMessage = null;
              }
            }           
           
            if(iMessage != null) {
View Full Code Here


   * @return  thread read job.
   * @see     com.sun.star.lib.uno.environments.remote.Job
   * @see                  com.sun.star.lib.uno.environments.remote.IProtocol#readJob
   */
  public IMessage readMessage(InputStream inputStream) throws IOException {
    IMessage iMessage = null;

      while(iMessage == null) { // try hard to get a message
      if(_unmarshal.bytesLeft() <= 0) { // the last block is empty, get a new one
        byte bytes[] = readBlock(new DataInputStream(inputStream));
        _unmarshal.reset(bytes);
View Full Code Here

  }

  static boolean testCall(IProtocol iSender, IProtocol iReciever, String oId) throws Exception {
    System.err.println("\t\ttesting testCall:");
    // send an ordinary request
    IMessage iMessage = receiveMessage(iReciever, sendRequest(iSender,
                                  oId,
                                  TypeDescription.getTypeDescription(test.XTestInterface.class),
                                  "method",
                                  new ThreadId(new byte[]{0, 1}),
                                  new Object[0],
                                  new Boolean[1],
                                  new Boolean[1]));
    iMessage.getData(new Object[1][]);

    // send a reply
    iMessage = receiveMessage(iSender, sendReply(iReciever,
                           false,
                           new ThreadId(new byte[]{0, 1}),
                           null));
    iMessage.getData(new Object[1][]);

    System.err.println("\t\tpassed? " + true);

    return true;
  }
View Full Code Here

  static boolean testCallWithInParameter(IProtocol iSender, IProtocol iReciever, String oId) throws Exception {
    boolean passed = true;

    System.err.println("\t\ttesting testCallWithInParameter:");
    // send an ordinary request
    IMessage iMessage = receiveMessage(iReciever, sendRequest(iSender,
                                  oId,
                                  TypeDescription.getTypeDescription(test.XTestInterface.class),
                                  "methodWithInParameter",
                                  new ThreadId(new byte[]{0, 1}),
                                  new Object[]{"hallo"},
                                  new Boolean[1],
                                  new Boolean[1]));
    Object t_params[][] = new Object[1][];
    iMessage.getData(t_params);
    System.err.println("\t\t\tgot in request: " + ((String)t_params[0][0]) + " expected: hallo");
    passed = passed && "hallo".equals((String)t_params[0][0]);

    // send a reply
    iMessage = receiveMessage(iSender, sendReply(iReciever,
                           false,
                           new ThreadId(new byte[]{0, 1}),
                           null));
    iMessage.getData(new Object[1][]);

    System.err.println("\t\tpassed? " + passed);

    return passed;
  }
View Full Code Here

  static boolean testCallWithOutParameter(IProtocol iSender, IProtocol iReciever, String oId) throws Exception {
    boolean passed = true;

    System.err.println("\t\ttesting testCallWithOutParameter:");
    Object params[] = new Object[]{new String[1]};
    IMessage iMessage = receiveMessage(iReciever, sendRequest(iSender,
                                  oId,
                                  TypeDescription.getTypeDescription(test.XTestInterface.class),
                                  "methodWithOutParameter",
                                  new ThreadId(new byte[]{0, 1}),
                                  params,
                                  new Boolean[1],
                                  new Boolean[1]));


    Object t_params[][] = new Object[1][];
    iMessage.getData(t_params);
    ((String [])t_params[0][0])[0] = "testString";

    // send an exception as reply
    iMessage = receiveMessage(iSender, sendReply(iReciever,
                           false,
                           new ThreadId(new byte[]{0, 1}),
                           null));

    iMessage.getData(new Object[1][]);

    System.err.println("\t\t\tgot in reply:" + ((String [])params[0])[0] + " expected: testString");
    passed = passed && "testString".equals(((String [])params[0])[0]);

    System.err.println("\t\tpassed? " + passed);
View Full Code Here

  static boolean testCallWithInOutParameter(IProtocol iSender, IProtocol iReciever, String oId) throws Exception {
    boolean passed = true;

    System.err.println("\t\ttesting testCallWithInOutParameter:");
    Object params[] = new Object[]{new String[]{"inString"}};
    IMessage iMessage = receiveMessage(iReciever, sendRequest(iSender,
                                  oId,
                                  TypeDescription.getTypeDescription(test.XTestInterface.class),
                                  "methodWithInOutParameter",
                                  new ThreadId(new byte[]{0, 1}),
                                  params,
                                  new Boolean[1],
                                  new Boolean[1]));


    Object t_params[][] = new Object[1][];
    iMessage.getData(t_params);
    System.err.println("\t\t\tgot in request:" + ((String [])t_params[0][0])[0] + " expected: inString");
    passed = passed && "inString".equals(((String [])t_params[0][0])[0]);

    // provide reply
    ((String [])t_params[0][0])[0] = "outString";

    // send an exception as reply
    iMessage = receiveMessage(iSender, sendReply(iReciever,
                           false,
                           new ThreadId(new byte[]{0, 1}),
                           null));

    iMessage.getData(new Object[1][]);

    System.err.println("\t\t\tgot in reply:" + ((String [])params[0])[0] + " expected: outString");
    passed = passed && "outString".equals(((String [])params[0])[0]);

    System.err.println("\t\tpassed? " + passed);
View Full Code Here

  static boolean testCallWithResult(IProtocol iSender, IProtocol iReciever, String oId) throws Exception {
    boolean passed = true;

    System.err.println("\t\ttesting testCallWithResult:");
    // send an ordinary request
    IMessage iMessage = receiveMessage(iReciever, sendRequest(iSender,
                                  oId,
                                  TypeDescription.getTypeDescription(test.XTestInterface.class),
                                  "methodWithResult",
                                  new ThreadId(new byte[]{0, 1}),
                                  new Object[0],
                                  new Boolean[1],
                                  new Boolean[1]));
    iMessage.getData(new Object[1][]);

    // send a reply
    iMessage = receiveMessage(iSender, sendReply(iReciever,
                           false,
                           new ThreadId(new byte[]{0, 1}),
                           "resultString"));
    Object result = iMessage.getData(new Object[1][]);

    System.err.println("\t\t\tgot as result:" + result + " expected: resultString");
    passed = passed && "resultString".equals(result);

    System.err.println("\t\tpassed? " + passed);
View Full Code Here

    boolean passed = true;

    System.err.println("\t\ttesting testCallWhichRaisesException:");

    // send a second request
    IMessage iMessage = receiveMessage(iReciever, sendRequest(iSender,
                                  oId,
                                  TypeDescription.getTypeDescription(test.XTestInterface.class),
                                  "method",
                                  new ThreadId(new byte[]{0, 1}),
                                  new Object[0],
                                  new Boolean[1],
                                  new Boolean[1]));
    iMessage.getData(new Object[1][]);

    // send an exception as reply
    iMessage = receiveMessage(iSender, sendReply(iReciever,
                           true,
                           new ThreadId(new byte[]{0, 1}),
                           new com.sun.star.uno.RuntimeException("test the exception")));

    Object result = iMessage.getData(new Object[1][]);

    System.err.println("\t\t\tgot as result:" + result + " expected: a RuntimeException");
    passed = passed && (result instanceof com.sun.star.uno.RuntimeException);

    System.err.println("\t\tpassed? " + passed);
View Full Code Here

    boolean passed = true;

    System.err.println("\t\ttesting testCallWithIn_Out_InOut_Paramters_and_result:");

    Object params[] = new Object[]{"hallo", new String[1], new String[]{"inOutString"}};
    IMessage iMessage = receiveMessage(iReciever, sendRequest(iSender,
                                  oId,
                                  TypeDescription.getTypeDescription(test.XTestInterface.class),
                                  "methodWithIn_Out_InOut_Paramters_and_result",
                                  new ThreadId(new byte[]{0, 1}),
                                  params,
                                  new Boolean[1],
                                  new Boolean[1]));

    Object t_params[][] = new Object[1][];
    iMessage.getData(t_params);


    System.err.println("\t\t\tgot in request: " + ((String)t_params[0][0]) + " expected: hallo");
    passed = passed && "hallo".equals((String)t_params[0][0]);

    System.err.println("\t\t\tgot in request:" + ((String [])t_params[0][2])[0] + " expected: inOutString");
    passed = passed && "inOutString".equals(((String [])t_params[0][2])[0]);

    ((String [])t_params[0][1])[0] = "outString";
    ((String [])t_params[0][2])[0] = "inOutString_res";

    // send an exception as reply
    iMessage = receiveMessage(iSender, sendReply(iReciever,
                           false,
                           new ThreadId(new byte[]{0, 1}),
                           "resultString"));

    Object result = iMessage.getData(new Object[1][]);
    System.err.println("\t\t\tgot in reply:" + ((String [])params[1])[0] + " expected: outString");
    passed = passed && "outString".equals(((String [])params[1])[0]);

    System.err.println("\t\t\tgot in reply:" + ((String [])params[2])[0] + " expected: inOutString_res");
    passed = passed && "inOutString_res".equals(((String [])params[2])[0]);
View Full Code Here

    System.err.println("\t\ttesting testCallWhichReturnsAny:");

    System.err.println("\t\t\tvoid-any:");
    // send an ordinary request
    IMessage iMessage = receiveMessage(iReciever, sendRequest(iSender,
                                  oId,
                                  TypeDescription.getTypeDescription(test.XTestInterface.class),
                                  "returnAny",
                                  new ThreadId(new byte[]{0, 1}),
                                  null,
                                  new Boolean[1],
                                  new Boolean[1]));
    // send a reply
    iMessage = receiveMessage(iSender, sendReply(iReciever,
                           false,
                           new ThreadId(new byte[]{0, 1}),
                           new com.sun.star.uno.Any(Void.class, null)));
    Object result = iMessage.getData(new Object[1][]);
    System.err.println("\t\t\tgot as result:" + result + " expected: void-any");
    boolean tmp_passed = (result instanceof Any) && (((Any)result).getType().getTypeDescription().getZClass() == void.class);
    System.err.println("\t\t\tpassed? " + tmp_passed);
    passed = passed && tmp_passed;

    System.err.println("\t\t\tnull interface:");
    // send an ordinary request
    iMessage = receiveMessage(iReciever, sendRequest(iSender,
                                  oId,
                                  TypeDescription.getTypeDescription(test.XTestInterface.class),
                                  "returnAny",
                                  new ThreadId(new byte[]{0, 1}),
                                  null,
                                  new Boolean[1],
                                  new Boolean[1]));
    // send a reply
    iMessage = receiveMessage(iSender, sendReply(iReciever,
                           false,
                           new ThreadId(new byte[]{0, 1}),
                           new Any(XInterface.class, null)));
    result = iMessage.getData(new Object[1][]);
    System.err.println("\t\t\tgot as result:" + result + " expected: null interface");
    tmp_passed = result == null;
    System.err.println("\t\t\tpassed? " + tmp_passed);
    passed = passed && tmp_passed;

    System.err.println("\t\t\tinteger object:");
    // send an ordinary request
    iMessage = receiveMessage(iReciever, sendRequest(iSender,
                                  oId,
                                  TypeDescription.getTypeDescription(test.XTestInterface.class),
                                  "returnAny",
                                  new ThreadId(new byte[]{0, 1}),
                                  null,
                                  new Boolean[1],
                                  new Boolean[1]));
    // send a reply
    iMessage = receiveMessage(iSender, sendReply(iReciever,
                           false,
                           new ThreadId(new byte[]{0, 1}),
                           new Integer(501)));
    result = iMessage.getData(new Object[1][]);
    System.err.println("\t\t\tgot as result:" + result + " expected: Integer(501)");
    tmp_passed = result.equals(new Integer(501));
    System.err.println("\t\t\tpassed? " + tmp_passed);
    passed = passed && tmp_passed;
View Full Code Here

TOP

Related Classes of com.sun.star.lib.uno.environments.remote.IMessage

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.