1 /*
   2  * Copyright (c) 1998, 2003, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package com.sun.corba.se.impl.protocol ;
  27 
  28 import javax.rmi.CORBA.Tie;
  29 
  30 import org.omg.CORBA.SystemException ;
  31 import org.omg.CORBA.NO_IMPLEMENT ;
  32 import org.omg.CORBA.OBJECT_NOT_EXIST ;
  33 import org.omg.CORBA.CompletionStatus ;
  34 import org.omg.CORBA.portable.InputStream;
  35 import org.omg.CORBA.portable.OutputStream;
  36 
  37 import com.sun.corba.se.spi.oa.ObjectAdapter;
  38 import com.sun.corba.se.spi.orb.ORB;
  39 
  40 import com.sun.corba.se.spi.protocol.CorbaMessageMediator;
  41 
  42 import com.sun.corba.se.spi.logging.CORBALogDomains;
  43 
  44 import com.sun.corba.se.impl.logging.ORBUtilSystemException;
  45 
  46 import com.sun.corba.se.spi.oa.NullServant ;
  47 
  48 public abstract class SpecialMethod {
  49     public abstract boolean isNonExistentMethod() ;
  50     public abstract String getName();
  51     public abstract CorbaMessageMediator invoke(java.lang.Object servant,
  52                                                 CorbaMessageMediator request,
  53                                                 byte[] objectId,
  54                                                 ObjectAdapter objectAdapter);
  55 
  56     public static final SpecialMethod getSpecialMethod(String operation) {
  57         for(int i = 0; i < methods.length; i++)
  58             if (methods[i].getName().equals(operation))
  59                 return methods[i];
  60         return null;
  61     }
  62 
  63     static SpecialMethod[] methods = {
  64         new IsA(),
  65         new GetInterface(),
  66         new NonExistent(),
  67         new NotExistent()
  68     };
  69 }
  70 
  71 class NonExistent extends SpecialMethod {
  72     public boolean isNonExistentMethod()
  73     {
  74         return true ;
  75     }
  76 
  77     public String getName() {           // _non_existent
  78         return "_non_existent";
  79     }
  80 
  81     public CorbaMessageMediator invoke(java.lang.Object servant,
  82                                        CorbaMessageMediator request,
  83                                        byte[] objectId,
  84                                        ObjectAdapter objectAdapter)
  85     {
  86         boolean result = (servant == null) || (servant instanceof NullServant) ;
  87         CorbaMessageMediator response =
  88             request.getProtocolHandler().createResponse(request, null);
  89         ((OutputStream)response.getOutputObject()).write_boolean(result);
  90         return response;
  91     }
  92 }
  93 
  94 class NotExistent extends NonExistent {
  95     public String getName() {           // _not_existent
  96         return "_not_existent";
  97     }
  98 }
  99 
 100 class IsA extends SpecialMethod  {      // _is_a
 101     public boolean isNonExistentMethod()
 102     {
 103         return false ;
 104     }
 105 
 106     public String getName() {
 107         return "_is_a";
 108     }
 109     public CorbaMessageMediator invoke(java.lang.Object servant,
 110                                        CorbaMessageMediator request,
 111                                        byte[] objectId,
 112                                        ObjectAdapter objectAdapter)
 113     {
 114         if ((servant == null) || (servant instanceof NullServant)) {
 115             ORB orb = (ORB)request.getBroker() ;
 116             ORBUtilSystemException wrapper = ORBUtilSystemException.get( orb,
 117                 CORBALogDomains.OA_INVOCATION ) ;
 118 
 119             return request.getProtocolHandler().createSystemExceptionResponse(
 120                 request, wrapper.badSkeleton(), null);
 121         }
 122 
 123         String[] ids = objectAdapter.getInterfaces( servant, objectId );
 124         String clientId =
 125             ((InputStream)request.getInputObject()).read_string();
 126         boolean answer = false;
 127         for(int i = 0; i < ids.length; i++)
 128             if (ids[i].equals(clientId)) {
 129                 answer = true;
 130                 break;
 131             }
 132 
 133         CorbaMessageMediator response =
 134             request.getProtocolHandler().createResponse(request, null);
 135         ((OutputStream)response.getOutputObject()).write_boolean(answer);
 136         return response;
 137     }
 138 }
 139 
 140 class GetInterface extends SpecialMethod  {     // _get_interface
 141     public boolean isNonExistentMethod()
 142     {
 143         return false ;
 144     }
 145 
 146     public String getName() {
 147         return "_interface";
 148     }
 149     public CorbaMessageMediator invoke(java.lang.Object servant,
 150                                        CorbaMessageMediator request,
 151                                        byte[] objectId,
 152                                        ObjectAdapter objectAdapter)
 153     {
 154         ORB orb = (ORB)request.getBroker() ;
 155         ORBUtilSystemException wrapper = ORBUtilSystemException.get( orb,
 156             CORBALogDomains.OA_INVOCATION ) ;
 157 
 158         if ((servant == null) || (servant instanceof NullServant)) {
 159             return request.getProtocolHandler().createSystemExceptionResponse(
 160                 request, wrapper.badSkeleton(), null);
 161         } else {
 162             return request.getProtocolHandler().createSystemExceptionResponse(
 163                 request, wrapper.getinterfaceNotImplemented(), null);
 164         }
 165     }
 166 }
 167 
 168 // End of file.