tests/libjava-mauve/src/gnu/testlet/org/omg/PortableServer/POA/TestDSIRef_impl.java
branchjk_new_structure
changeset 1541 75c2e24dea9a
parent 1540 92ac284961c1
child 1542 be11db817bcf
equal deleted inserted replaced
1540:92ac284961c1 1541:75c2e24dea9a
     1 // Tags: not-a-test
       
     2 // Copyright (c) Object Oriented Concepts, Inc. Billerica, MA, USA
       
     3 
       
     4 // Adapted for Mauve by Audrius Meskauskas <audriusa@bluewin.ch>
       
     5 
       
     6 // This file is part of Mauve.
       
     7 
       
     8 // Mauve is free software; you can redistribute it and/or modify
       
     9 // it under the terms of the GNU General Public License as published by
       
    10 // the Free Software Foundation; either version 2, or (at your option)
       
    11 // any later version.
       
    12 
       
    13 // Mauve is distributed in the hope that it will be useful,
       
    14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
       
    15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
       
    16 // GNU General Public License for more details.
       
    17 
       
    18 // You should have received a copy of the GNU General Public License
       
    19 // along with Mauve; see the file COPYING.  If not, write to
       
    20 // the Free Software Foundation, 59 Temple Place - Suite 330,
       
    21 // Boston, MA 02111-1307, USA.
       
    22 
       
    23 /*
       
    24 This code originally came from the OMG's CORBA Open Source Testing project,
       
    25 which lived at cost.omg.org. That site no longer exists.
       
    26 
       
    27 All the contributing companies agreed to release their tests under the
       
    28 terms of the GNU Lesser General Public License, available in the file
       
    29 COPYING.LIB.
       
    30 
       
    31 The code has been modified integrating into Mauve test environment and
       
    32 removing tests that are not yet supported by Suns jre 1.4. Hence the license
       
    33 is now GPL.
       
    34 
       
    35 We downloaded the code from http://sourceforge.net/projects/corba-cost/,
       
    36 administrated by Duncan Grisby.
       
    37 */
       
    38 
       
    39 
       
    40 // **********************************************************************
       
    41 //
       
    42 // Copyright (c) 2000
       
    43 // Object Oriented Concepts, Inc.
       
    44 // Billerica, MA, USA
       
    45 //
       
    46 // All Rights Reserved
       
    47 //
       
    48 // **********************************************************************
       
    49 
       
    50 
       
    51 package gnu.testlet.org.omg.PortableServer.POA;
       
    52 
       
    53 import org.omg.CORBA.BAD_OPERATION;
       
    54 import org.omg.CORBA.NVList;
       
    55 import org.omg.CORBA.ORB;
       
    56 import org.omg.CORBA.ServerRequest;
       
    57 import org.omg.CORBA.UserException;
       
    58 import org.omg.PortableServer.DynamicImplementation;
       
    59 import org.omg.PortableServer.POA;
       
    60 import org.omg.PortableServer.POAPackage.ServantNotActive;
       
    61 import org.omg.PortableServer.POAPackage.WrongPolicy;
       
    62 
       
    63 final class TestDSIRef_impl
       
    64   extends org.omg.PortableServer.DynamicImplementation
       
    65 {
       
    66   private ORB orb_;
       
    67   private String name_;
       
    68   private boolean compare_;
       
    69   private boolean defaultServant_;
       
    70 
       
    71   //
       
    72   // From TestBase (no multiple inheritance)
       
    73   //
       
    74   public static void TEST(boolean expr)
       
    75   {
       
    76     if (!expr)
       
    77       throw new TestException();
       
    78   }
       
    79 
       
    80   TestDSIRef_impl(ORB orb, String name, boolean compare)
       
    81   {
       
    82     orb_ = orb;
       
    83     name_ = name;
       
    84     compare_ = compare;
       
    85   }
       
    86 
       
    87   void setDefaultServant(boolean b)
       
    88   {
       
    89     defaultServant_ = b;
       
    90   }
       
    91 
       
    92   //
       
    93   // Standard IDL to Java Mapping
       
    94   //
       
    95   public void invoke(ServerRequest request)
       
    96   {
       
    97     String name = request.operation();
       
    98 
       
    99     if (!name.equals("aMethod"))
       
   100       {
       
   101         throw new BAD_OPERATION();
       
   102       }
       
   103 
       
   104     //
       
   105     // 8.3.1: "Unless it calls set_exception, the DIR must call arguments
       
   106     // exactly once, even if the operation signature contains no
       
   107     // parameters."
       
   108     //
       
   109     NVList list = orb_.create_list(0);
       
   110     request.arguments(list);
       
   111 
       
   112     org.omg.CORBA.Object currentObj = null;
       
   113     try
       
   114       {
       
   115         currentObj = orb_.resolve_initial_references("POACurrent");
       
   116       }
       
   117     catch (UserException ex)
       
   118       {
       
   119       }
       
   120 
       
   121     org.omg.PortableServer.Current current = null;
       
   122     if (currentObj != null)
       
   123       current = org.omg.PortableServer.CurrentHelper.narrow(currentObj);
       
   124     TEST(current != null);
       
   125 
       
   126     byte[] oid = null;
       
   127     try
       
   128       {
       
   129         oid = current.get_object_id();
       
   130       }
       
   131     catch (org.omg.PortableServer.CurrentPackage.NoContext ex)
       
   132       {
       
   133         throw new RuntimeException();
       
   134       }
       
   135 
       
   136     String oidString = new String(oid);
       
   137 
       
   138     if (compare_)
       
   139       TEST(oidString.equals(name_));
       
   140 
       
   141     //
       
   142     // Disabled since it is CORBA 2.4
       
   143     //
       
   144 
       
   145     /*
       
   146             org.omg.PortableServer.Servant servant = null;
       
   147             try
       
   148             {
       
   149                 servant = current.get_servant();
       
   150             }
       
   151             catch(org.omg.PortableServer.CurrentPackage.NoContext ex)
       
   152             {
       
   153                 throw new RuntimeException();
       
   154             }
       
   155             TEST(servant == this);
       
   156     */
       
   157     if (defaultServant_)
       
   158       {
       
   159         POA poa = null;
       
   160         try
       
   161           {
       
   162             poa = current.get_POA();
       
   163           }
       
   164         catch (org.omg.PortableServer.CurrentPackage.NoContext ex)
       
   165           {
       
   166             throw new RuntimeException();
       
   167           }
       
   168 
       
   169         byte[] servantId = null;
       
   170         try
       
   171           {
       
   172             servantId = poa.servant_to_id(this);
       
   173           }
       
   174         catch (ServantNotActive ex)
       
   175           {
       
   176             throw new RuntimeException();
       
   177           }
       
   178         catch (WrongPolicy ex)
       
   179           {
       
   180             throw new RuntimeException();
       
   181           }
       
   182         TEST(servantId.length == oid.length);
       
   183         TEST(servantId.equals(oid));
       
   184       }
       
   185   }
       
   186 
       
   187   static final String[] interfaces_ = { "IDL:Test:1.0" };
       
   188 
       
   189   public String[] _all_interfaces(POA poa, byte[] oid)
       
   190   {
       
   191     return interfaces_;
       
   192   }
       
   193 }