tests/libjava-mauve/src/gnu/testlet/javax/rmi/CORBA/Tie/RMI_testImpl.java
branchjk_new_structure
changeset 1541 75c2e24dea9a
parent 1540 92ac284961c1
child 1542 be11db817bcf
equal deleted inserted replaced
1540:92ac284961c1 1541:75c2e24dea9a
     1 // Not a test, required by RMI_IIOP.java.
       
     2 
       
     3 // Copyright (C) 2005 Audrius Meskauskas (AudriusA@Bioinformatics.org)
       
     4 
       
     5 // Mauve is free software; you can redistribute it and/or modify
       
     6 // it under the terms of the GNU General Public License as published by
       
     7 // the Free Software Foundation; either version 2, or (at your option)
       
     8 // any later version.
       
     9 
       
    10 // Mauve is distributed in the hope that it will be useful,
       
    11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
       
    12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
       
    13 // GNU General Public License for more details.
       
    14 
       
    15 // You should have received a copy of the GNU General Public License
       
    16 // along with Mauve; see the file COPYING.  If not, write to
       
    17 // the Free Software Foundation, 59 Temple Place - Suite 330,
       
    18 // Boston, MA 02111-1307, USA.  */
       
    19 
       
    20 
       
    21 package gnu.testlet.javax.rmi.CORBA.Tie;
       
    22 
       
    23 import gnu.testlet.org.omg.CORBA_2_3.ORB.Valtype.Info;
       
    24 import gnu.testlet.org.omg.CORBA_2_3.ORB.Valtype.cmInfo;
       
    25 
       
    26 import java.io.Serializable;
       
    27 import java.rmi.ConnectException;
       
    28 import java.rmi.RemoteException;
       
    29 import java.util.Collection;
       
    30 import java.util.Iterator;
       
    31 
       
    32 import javax.rmi.PortableRemoteObject;
       
    33 import javax.xml.parsers.ParserConfigurationException;
       
    34 
       
    35 import org.omg.CORBA.Object;
       
    36 import org.omg.CORBA.portable.ObjectImpl;
       
    37 
       
    38 /**
       
    39  * This file is part of the CORBA RMI over IIOP the test executable
       
    40  * class being gnu.testlet.javax.rmi.CORBA.Tie.RMI_IIOP.
       
    41  *
       
    42  * @author Audrius Meskauskas (AudriusA@bluewin.ch)
       
    43  */
       
    44 public class RMI_testImpl
       
    45   extends PortableRemoteObject
       
    46   implements RMI_test, Serializable
       
    47 {
       
    48   String ego = "<unassigned>";
       
    49 
       
    50   RMI_test other = null;
       
    51 
       
    52   public String getEgo()
       
    53     throws RemoteException
       
    54   {
       
    55     return ego;
       
    56   }
       
    57 
       
    58   public String passCorbaCMValueType(cmInfo info)
       
    59   {
       
    60     return "" + info;
       
    61   }
       
    62 
       
    63   public String passCorbaValueType(Info info)
       
    64   {
       
    65     return "" + info;
       
    66   }
       
    67 
       
    68   public String passCorbaValueTypeArray(Info[] infos)
       
    69   {
       
    70     if (infos == null)
       
    71       return "null";
       
    72     StringBuffer b = new StringBuffer();
       
    73     for (int i = 0; i < infos.length; i++)
       
    74       {
       
    75         b.append(infos[i]);
       
    76         b.append(":");
       
    77       }
       
    78     return b.toString();
       
    79   }
       
    80 
       
    81   public String passStructure(myStructure s)
       
    82     throws RemoteException
       
    83   {
       
    84     return "" + s;
       
    85   }
       
    86 
       
    87   public String passStructureArray(myStructure[] infos)
       
    88   {
       
    89     if (infos == null)
       
    90       return "null";
       
    91     StringBuffer b = new StringBuffer();
       
    92     for (int i = 0; i < infos.length; i++)
       
    93       {
       
    94         b.append(infos[i]);
       
    95         b.append(":");
       
    96       }
       
    97     return b.toString();
       
    98   }
       
    99 
       
   100   public RMI_testImpl()
       
   101     throws RemoteException
       
   102   {
       
   103     super();
       
   104   }
       
   105 
       
   106   public String joinStrings(String a, String b)
       
   107     throws RemoteException
       
   108   {
       
   109     if (a != null && a.equals("throw_remote"))
       
   110       {
       
   111         RemoteException t;
       
   112         try
       
   113           {
       
   114             Throwable cause = new ParserConfigurationException("Uje!");
       
   115             cause.initCause(new OutOfMemoryError("OOO!"));
       
   116             cause.fillInStackTrace();
       
   117             t = new RemoteException("Thrown remote AUDRIUS" + b, cause);
       
   118 
       
   119           }
       
   120         catch (Exception ex)
       
   121           {
       
   122             return "Unable to instantiate " + b + ": " + ex;
       
   123           }
       
   124         throw t;
       
   125       }
       
   126     else if (a != null && a.equals("throw_runtime"))
       
   127       {
       
   128         RuntimeException t;
       
   129         try
       
   130           {
       
   131             t = new ArrayIndexOutOfBoundsException(
       
   132               "Thrown ArrayIndexOutOfBoundsException AUDRIUS");
       
   133           }
       
   134         catch (Exception ex)
       
   135           {
       
   136             return "Unable to instantiate " + b + ": " + ex;
       
   137           }
       
   138         throw t;
       
   139       }
       
   140     else if (a != null && a.equals("throw_error"))
       
   141       {
       
   142         Error t;
       
   143         try
       
   144           {
       
   145             t = new InternalError("Thrown InternalError Audrius");
       
   146           }
       
   147         catch (Exception ex)
       
   148           {
       
   149             return "Unable to instantiate " + b + ": " + ex;
       
   150           }
       
   151         throw t;
       
   152       }
       
   153     else if (a != null && a.equals("throw_cex"))
       
   154       {
       
   155         throw new ConnectException("Connect exception message");
       
   156       }
       
   157     else
       
   158 
       
   159       return "'" + a + "' and '" + b + "'";
       
   160   }
       
   161 
       
   162   public long multiply(byte a, long b)
       
   163     throws RemoteException
       
   164   {
       
   165     return a * b;
       
   166   }
       
   167 
       
   168   public int passArray(int[] array)
       
   169     throws RemoteException
       
   170   {
       
   171     int s = 0;
       
   172     for (int i = 0; i < array.length; i++)
       
   173       {
       
   174         s += array[i];
       
   175       }
       
   176     return s;
       
   177   }
       
   178 
       
   179   public String passPrimitives(byte b, double d, int i, String s, float f,
       
   180     char c, short sh)
       
   181     throws RemoteException
       
   182   {
       
   183     return "byte " + b + ", double " + d + ", int " + i + ", string  " + s
       
   184       + ", float " + f + ", char " + c + "(" + Long.toHexString(c) + ")"
       
   185       + ", short " + sh;
       
   186   }
       
   187 
       
   188   public String passStringArray(String[] array)
       
   189     throws RemoteException
       
   190   {
       
   191     StringBuffer b = new StringBuffer();
       
   192 
       
   193     for (int i = 0; i < array.length; i++)
       
   194       {
       
   195         b.append(array[i]);
       
   196         b.append(".");
       
   197       }
       
   198 
       
   199     return b.toString();
       
   200   }
       
   201 
       
   202   public String sayHello(RMI_test h)
       
   203     throws RemoteException
       
   204   {
       
   205     if (h == null)
       
   206       return "null";
       
   207     else
       
   208       return h.getEgo();
       
   209   }
       
   210 
       
   211   public String passCorbaObject(Object object)
       
   212   {
       
   213     if (object == null)
       
   214       return "null passed";
       
   215     return ((ObjectImpl) object)._ids()[0];
       
   216   }
       
   217 
       
   218   public NodeObject exchangeNodeObject(NodeObject nx)
       
   219     throws RemoteException
       
   220   {
       
   221     try
       
   222       {
       
   223         if (nx.z_anotherTest != null)
       
   224           {
       
   225             nx.z_anotherTest = this;
       
   226             return nx;
       
   227           }
       
   228         else if (nx.anotherTestArray != null)
       
   229           {
       
   230             StringBuffer rv = new StringBuffer();
       
   231 
       
   232             for (int i = 0; i < nx.anotherTestArray.length; i++)
       
   233               {
       
   234                 if (nx.anotherTestArray[i] != null)
       
   235                   rv.append(nx.anotherTestArray[i].getEgo());
       
   236                 else
       
   237                   rv.append("null");
       
   238                 rv.append(".");
       
   239               }
       
   240 
       
   241             nx.label = rv.toString();
       
   242             nx.z_anotherTest = this;
       
   243             return nx;
       
   244           }
       
   245         else
       
   246           {
       
   247             if (!nx.toString().equals(NodeObject.create1().toString()))
       
   248               {
       
   249                 String msg = "Incorrect graph received " + nx + " expected "
       
   250                   + NodeObject.create1();
       
   251                 System.out.println();
       
   252                 System.out.println(msg);
       
   253 
       
   254                 throw new RemoteException(msg);
       
   255               }
       
   256             else
       
   257               return NodeObject.create2();
       
   258           }
       
   259       }
       
   260     catch (Exception e)
       
   261       {
       
   262         throw new RemoteException("Exception has been thrown: " + e);
       
   263       }
       
   264   }
       
   265 
       
   266   /**
       
   267    * Same, the idea is just to test arrays.
       
   268    */
       
   269   public String passArrayOfRemotes(RMI_test[] tests)
       
   270     throws RemoteException
       
   271   {
       
   272     String[] expected = new String[] { "Local client object",
       
   273       "Client implementation instance", null, "Local client object",
       
   274       "Server side object" };
       
   275 
       
   276     if (tests.length != expected.length)
       
   277       return "Length mismatch, must be " + expected.length + " but "
       
   278         + tests.length;
       
   279 
       
   280     for (int i = 0; i < tests.length; i++)
       
   281       {
       
   282         if (tests[i] == null)
       
   283           {
       
   284             if (expected[i] != null)
       
   285               return i + ":" + tests[i] + " versus " + expected[i];
       
   286           }
       
   287         else
       
   288           {
       
   289             if (!expected[i].equals(tests[i].getEgo()))
       
   290               return i + ":" + tests[i].getEgo() + " versus " + expected[i];
       
   291           }
       
   292       }
       
   293     return "ok";
       
   294   }
       
   295 
       
   296   /**
       
   297    * Create and return new Remote.
       
   298    */
       
   299   public RMI_test passReturnRemote(RMI_test test)
       
   300     throws RemoteException
       
   301   {
       
   302     if (test == null)
       
   303       return null;
       
   304     else
       
   305       {
       
   306         RMI_testImpl impl = new RMI_testImpl();
       
   307         impl.ego = "ab (" + ego + ":" + (test == null ? "null" : test.getEgo())
       
   308           + ")";
       
   309         return impl;
       
   310       }
       
   311   }
       
   312 
       
   313   public String passCollection(Collection cx)
       
   314     throws RemoteException
       
   315   {
       
   316     StringBuffer b = new StringBuffer();
       
   317     b.append(cx.getClass().getName() + ":");
       
   318 
       
   319     Iterator iter = cx.iterator();
       
   320 
       
   321     while (iter.hasNext())
       
   322       {
       
   323         b.append(iter.next());
       
   324         b.append(".");
       
   325       }
       
   326     return b.toString();
       
   327   }
       
   328 
       
   329 }