classpath-patches
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[cp-patches] FYI: Completing DynamicImplementation


From: Meskauskas Audrius
Subject: [cp-patches] FYI: Completing DynamicImplementation
Date: Sat, 15 Oct 2005 20:19:14 +0200
User-agent: Mozilla Thunderbird 1.0.2 (Windows/20050317)

DynamicImplementation must be concrete, not abstract. This patch implements the previously abstract method invoke and makes the whole class no longer abstract. As a side effect, it was required to implements Simple_delegate.request that was previously never used.

2005-10-15  Audrius Meskauskas  <address@hidden>

   * org/omg/CORBA/DynamicImplementation.java: Made concrete.
   (invoke): Implemented.
   gnu/CORBA/Simple_delegate.java (request): Implemented.
Index: gnu/CORBA/Simple_delegate.java
===================================================================
RCS file: /cvsroot/classpath/classpath/gnu/CORBA/Simple_delegate.java,v
retrieving revision 1.5
diff -u -r1.5 Simple_delegate.java
--- gnu/CORBA/Simple_delegate.java      2 Oct 2005 19:58:00 -0000       1.5
+++ gnu/CORBA/Simple_delegate.java      15 Oct 2005 17:49:30 -0000
@@ -266,12 +266,19 @@
   }
 
   /**
-   * This should never be called this type delegate.
-   *
-   * @throws InternalError, always.
+   * This method assumes that the target is local and connected to the ORB.
    */
   public Request request(org.omg.CORBA.Object target, String operation)
   {
-    throw new InternalError();
+    if (orb instanceof Functional_ORB)
+      {
+        ((Functional_ORB) orb).ensureRunning();
+      }
+    gnuRequest g = new gnuRequest();
+    g.setORB(orb);
+    g.setOperation(operation);
+    g.setIor(ior);
+    g.m_target = target;
+    return g;
   }
 }
Index: org/omg/CORBA/DynamicImplementation.java
===================================================================
RCS file: 
/cvsroot/classpath/classpath/org/omg/CORBA/DynamicImplementation.java,v
retrieving revision 1.2
diff -u -r1.2 DynamicImplementation.java
--- org/omg/CORBA/DynamicImplementation.java    2 Jul 2005 20:32:56 -0000       
1.2
+++ org/omg/CORBA/DynamicImplementation.java    15 Oct 2005 17:32:38 -0000
@@ -38,7 +38,12 @@
 
 package org.omg.CORBA;
 
+import gnu.CORBA.Unexpected;
+import gnu.CORBA.gnuAny;
+import gnu.CORBA.gnuNVList;
+
 import org.omg.CORBA.portable.ObjectImpl;
+import org.omg.CORBA.portable.OutputStream;
 
 /**
  * This class was probably originally thinked as a base of all CORBA
@@ -51,18 +56,110 @@
  *
  * @author Audrius Meskauskas, Lithuania (address@hidden)
  */
-public abstract class DynamicImplementation
+public class DynamicImplementation
   extends ObjectImpl
 {
   /**
-   * Invoke the method of the CORBA object.
-   *
+   * Invoke the method of the CORBA object. After converting the parameters,
+   * this method delegates call to the address@hidden ObjectImpl#invoke}.
+   * 
    * @deprecated since 1.4.
-   *
-   * @param request the container for both passing and returing the
-   * parameters, also contains the method name and thrown exceptions.
+   * 
+   * @param request the container for both passing and returing the parameters,
+   * also contains the method name and thrown exceptions.
    */
-  public abstract void invoke(ServerRequest request);
+  public void invoke(ServerRequest request)
+  {
+    Request r = _request(request.operation());
+
+    // Copy the parameters.
+    NVList args = new gnuNVList();
+    request.arguments(args);
+    NamedValue v;
+    int i = 0;
+
+    try
+      {
+        // Set the arguments.
+        for (i = 0; i < args.count(); i++)
+          {
+            v = args.item(i);
+            Any n;
+            OutputStream out;
+
+            switch (v.flags())
+              {
+                case ARG_IN.value:
+                  out = v.value().create_output_stream();
+                  v.value().write_value(out);
+                  n = r.add_named_in_arg(v.name());
+                  n.read_value(out.create_input_stream(), v.value().type());   
               
+                  break;
+                case ARG_INOUT.value:
+                  out = v.value().create_output_stream();
+                  v.value().write_value(out);
+                  n = r.add_named_inout_arg(v.name());
+                  n.read_value(out.create_input_stream(), v.value().type());   
               
+                  break;
+                case ARG_OUT.value:
+                  r.add_named_out_arg(v.name());
+                  break;
+
+                default:
+                  throw new InternalError("Invalid flags " + v.flags());
+              }
+          }
+      }
+    catch (Bounds b)
+      {
+        throw new Unexpected(args.count() + "[" + i + "]", b);
+      }
+
+    // Set context.
+    r.ctx(request.ctx());
+    
+    // Set the return type (expects that the ServerRequest will initialise
+    // the passed Any.
+    
+    gnuAny g = new gnuAny();
+    request.result(g);
+    r.set_return_type(g.type());
+
+    // Invoke the method.
+    r.invoke();
+
+    // Transfer the returned values.
+    NVList r_args = r.arguments();
+
+    try
+      {
+        // API states that the ServerRequest.arguments must be called only
+        // once. Hence we assume we can just modify the previously returned
+        // value <code>args</code>, and the ServerRequest will preserve the 
+        // reference.
+        for (i = 0; i < args.count(); i++)
+          {
+            v = args.item(i);
+
+            if (v.flags() == ARG_OUT.value || v.flags() == ARG_INOUT.value)
+              {
+                OutputStream out = 
r_args.item(i).value().create_output_stream();
+                r_args.item(i).value().write_value(out);
+                v.value().read_value(out.create_input_stream(),
+                  v.value().type());
+              }
+          }
+      }
+    catch (Bounds b)
+      {
+        throw new Unexpected(args.count() + "[" + i + "]", b);
+      }
+
+    // Set the returned result (if any).
+    NamedValue returns = r.result();
+    if (returns != null)
+      request.set_result(returns.value());
+  }
 
   /**
    * Returns the array of the repository ids, supported by this object.

reply via email to

[Prev in Thread] Current Thread [Next in Thread]