corba/src/java.corba/share/classes/com/sun/corba/se/impl/ior/ObjectKeyTemplateBase.java
author avstepan
Tue, 05 May 2015 15:17:13 +0400
changeset 30383 45960fdbe465
parent 25862 a5e25d68f971
permissions -rw-r--r--
8079075: some docs cleanup for CORBA - part 1 Summary: some fix for CORBA docs Reviewed-by: rriggs
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
4
02bb8761fcce Initial load
duke
parents:
diff changeset
     1
/*
5555
b2b5ed3f0d0d 6943119: Rebrand source copyright notices
ohair
parents: 4
diff changeset
     2
 * Copyright (c) 2000, 2003, Oracle and/or its affiliates. All rights reserved.
4
02bb8761fcce Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
02bb8761fcce Initial load
duke
parents:
diff changeset
     4
 *
02bb8761fcce Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
02bb8761fcce Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5555
b2b5ed3f0d0d 6943119: Rebrand source copyright notices
ohair
parents: 4
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
4
02bb8761fcce Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5555
b2b5ed3f0d0d 6943119: Rebrand source copyright notices
ohair
parents: 4
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
4
02bb8761fcce Initial load
duke
parents:
diff changeset
    10
 *
02bb8761fcce Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
02bb8761fcce Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
02bb8761fcce Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
02bb8761fcce Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
02bb8761fcce Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
02bb8761fcce Initial load
duke
parents:
diff changeset
    16
 *
02bb8761fcce Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
02bb8761fcce Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
02bb8761fcce Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
02bb8761fcce Initial load
duke
parents:
diff changeset
    20
 *
5555
b2b5ed3f0d0d 6943119: Rebrand source copyright notices
ohair
parents: 4
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
b2b5ed3f0d0d 6943119: Rebrand source copyright notices
ohair
parents: 4
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
b2b5ed3f0d0d 6943119: Rebrand source copyright notices
ohair
parents: 4
diff changeset
    23
 * questions.
4
02bb8761fcce Initial load
duke
parents:
diff changeset
    24
 */
02bb8761fcce Initial load
duke
parents:
diff changeset
    25
02bb8761fcce Initial load
duke
parents:
diff changeset
    26
package com.sun.corba.se.impl.ior;
02bb8761fcce Initial load
duke
parents:
diff changeset
    27
02bb8761fcce Initial load
duke
parents:
diff changeset
    28
import java.util.Iterator ;
02bb8761fcce Initial load
duke
parents:
diff changeset
    29
02bb8761fcce Initial load
duke
parents:
diff changeset
    30
import org.omg.CORBA_2_3.portable.InputStream ;
02bb8761fcce Initial load
duke
parents:
diff changeset
    31
import org.omg.CORBA_2_3.portable.OutputStream ;
02bb8761fcce Initial load
duke
parents:
diff changeset
    32
02bb8761fcce Initial load
duke
parents:
diff changeset
    33
import com.sun.corba.se.spi.protocol.CorbaServerRequestDispatcher ;
02bb8761fcce Initial load
duke
parents:
diff changeset
    34
02bb8761fcce Initial load
duke
parents:
diff changeset
    35
import com.sun.corba.se.spi.ior.ObjectId ;
02bb8761fcce Initial load
duke
parents:
diff changeset
    36
import com.sun.corba.se.spi.ior.ObjectAdapterId ;
02bb8761fcce Initial load
duke
parents:
diff changeset
    37
import com.sun.corba.se.spi.ior.ObjectKeyTemplate ;
02bb8761fcce Initial load
duke
parents:
diff changeset
    38
02bb8761fcce Initial load
duke
parents:
diff changeset
    39
import com.sun.corba.se.spi.orb.ORB ;
02bb8761fcce Initial load
duke
parents:
diff changeset
    40
import com.sun.corba.se.spi.orb.ORBVersion ;
02bb8761fcce Initial load
duke
parents:
diff changeset
    41
02bb8761fcce Initial load
duke
parents:
diff changeset
    42
import com.sun.corba.se.spi.logging.CORBALogDomains ;
02bb8761fcce Initial load
duke
parents:
diff changeset
    43
02bb8761fcce Initial load
duke
parents:
diff changeset
    44
02bb8761fcce Initial load
duke
parents:
diff changeset
    45
import com.sun.corba.se.impl.encoding.EncapsOutputStream ;
02bb8761fcce Initial load
duke
parents:
diff changeset
    46
02bb8761fcce Initial load
duke
parents:
diff changeset
    47
import com.sun.corba.se.impl.logging.IORSystemException ;
02bb8761fcce Initial load
duke
parents:
diff changeset
    48
02bb8761fcce Initial load
duke
parents:
diff changeset
    49
02bb8761fcce Initial load
duke
parents:
diff changeset
    50
public abstract class ObjectKeyTemplateBase implements ObjectKeyTemplate
02bb8761fcce Initial load
duke
parents:
diff changeset
    51
{
02bb8761fcce Initial load
duke
parents:
diff changeset
    52
    // Fixed constants for Java IDL object key template forms
02bb8761fcce Initial load
duke
parents:
diff changeset
    53
    public static final String JIDL_ORB_ID = "" ;
02bb8761fcce Initial load
duke
parents:
diff changeset
    54
    private static final String[] JIDL_OAID_STRINGS = { "TransientObjectAdapter" } ;
02bb8761fcce Initial load
duke
parents:
diff changeset
    55
    public static final ObjectAdapterId JIDL_OAID = new ObjectAdapterIdArray( JIDL_OAID_STRINGS ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
    56
02bb8761fcce Initial load
duke
parents:
diff changeset
    57
    private ORB orb ;
02bb8761fcce Initial load
duke
parents:
diff changeset
    58
    protected IORSystemException wrapper ;
02bb8761fcce Initial load
duke
parents:
diff changeset
    59
    private ORBVersion version ;
02bb8761fcce Initial load
duke
parents:
diff changeset
    60
    private int magic ;
02bb8761fcce Initial load
duke
parents:
diff changeset
    61
    private int scid ;
02bb8761fcce Initial load
duke
parents:
diff changeset
    62
    private int serverid ;
02bb8761fcce Initial load
duke
parents:
diff changeset
    63
    private String orbid ;
02bb8761fcce Initial load
duke
parents:
diff changeset
    64
    private ObjectAdapterId oaid ;
02bb8761fcce Initial load
duke
parents:
diff changeset
    65
02bb8761fcce Initial load
duke
parents:
diff changeset
    66
    private byte[] adapterId ;
02bb8761fcce Initial load
duke
parents:
diff changeset
    67
02bb8761fcce Initial load
duke
parents:
diff changeset
    68
    public byte[] getAdapterId()
02bb8761fcce Initial load
duke
parents:
diff changeset
    69
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
    70
        return (byte[])(adapterId.clone()) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
    71
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
    72
02bb8761fcce Initial load
duke
parents:
diff changeset
    73
    private byte[] computeAdapterId()
02bb8761fcce Initial load
duke
parents:
diff changeset
    74
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
    75
        // write out serverid, orbid, oaid
02bb8761fcce Initial load
duke
parents:
diff changeset
    76
        ByteBuffer buff = new ByteBuffer() ;
02bb8761fcce Initial load
duke
parents:
diff changeset
    77
02bb8761fcce Initial load
duke
parents:
diff changeset
    78
        buff.append( getServerId() ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
    79
        buff.append( orbid ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
    80
02bb8761fcce Initial load
duke
parents:
diff changeset
    81
        buff.append( oaid.getNumLevels() ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
    82
        Iterator iter = oaid.iterator() ;
02bb8761fcce Initial load
duke
parents:
diff changeset
    83
        while (iter.hasNext()) {
02bb8761fcce Initial load
duke
parents:
diff changeset
    84
            String comp = (String)(iter.next()) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
    85
            buff.append( comp ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
    86
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
    87
02bb8761fcce Initial load
duke
parents:
diff changeset
    88
        buff.trimToSize() ;
02bb8761fcce Initial load
duke
parents:
diff changeset
    89
02bb8761fcce Initial load
duke
parents:
diff changeset
    90
        return buff.toArray() ;
02bb8761fcce Initial load
duke
parents:
diff changeset
    91
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
    92
02bb8761fcce Initial load
duke
parents:
diff changeset
    93
    public ObjectKeyTemplateBase( ORB orb, int magic, int scid, int serverid,
02bb8761fcce Initial load
duke
parents:
diff changeset
    94
        String orbid, ObjectAdapterId oaid )
02bb8761fcce Initial load
duke
parents:
diff changeset
    95
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
    96
        this.orb = orb ;
02bb8761fcce Initial load
duke
parents:
diff changeset
    97
        this.wrapper = IORSystemException.get( orb,
02bb8761fcce Initial load
duke
parents:
diff changeset
    98
            CORBALogDomains.OA_IOR ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
    99
        this.magic = magic ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   100
        this.scid = scid ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   101
        this.serverid = serverid ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   102
        this.orbid = orbid ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   103
        this.oaid = oaid ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   104
02bb8761fcce Initial load
duke
parents:
diff changeset
   105
        adapterId = computeAdapterId() ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   106
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   107
02bb8761fcce Initial load
duke
parents:
diff changeset
   108
    public boolean equals( Object obj )
02bb8761fcce Initial load
duke
parents:
diff changeset
   109
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   110
        if (!(obj instanceof ObjectKeyTemplateBase))
02bb8761fcce Initial load
duke
parents:
diff changeset
   111
            return false ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   112
02bb8761fcce Initial load
duke
parents:
diff changeset
   113
        ObjectKeyTemplateBase other = (ObjectKeyTemplateBase)obj ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   114
02bb8761fcce Initial load
duke
parents:
diff changeset
   115
        return (magic == other.magic) && (scid == other.scid) &&
02bb8761fcce Initial load
duke
parents:
diff changeset
   116
            (serverid == other.serverid) && (version.equals( other.version ) &&
02bb8761fcce Initial load
duke
parents:
diff changeset
   117
            orbid.equals( other.orbid ) && oaid.equals( other.oaid )) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   118
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   119
02bb8761fcce Initial load
duke
parents:
diff changeset
   120
    public int hashCode()
02bb8761fcce Initial load
duke
parents:
diff changeset
   121
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   122
        int result = 17 ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   123
        result = 37*result + magic ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   124
        result = 37*result + scid ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   125
        result = 37*result + serverid ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   126
        result = 37*result + version.hashCode() ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   127
        result = 37*result + orbid.hashCode() ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   128
        result = 37*result + oaid.hashCode() ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   129
        return result ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   130
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   131
02bb8761fcce Initial load
duke
parents:
diff changeset
   132
    public int getSubcontractId()
02bb8761fcce Initial load
duke
parents:
diff changeset
   133
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   134
        return scid ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   135
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   136
02bb8761fcce Initial load
duke
parents:
diff changeset
   137
    public int getServerId()
02bb8761fcce Initial load
duke
parents:
diff changeset
   138
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   139
        return serverid ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   140
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   141
02bb8761fcce Initial load
duke
parents:
diff changeset
   142
    public String getORBId()
02bb8761fcce Initial load
duke
parents:
diff changeset
   143
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   144
        return orbid ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   145
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   146
02bb8761fcce Initial load
duke
parents:
diff changeset
   147
    public ObjectAdapterId getObjectAdapterId()
02bb8761fcce Initial load
duke
parents:
diff changeset
   148
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   149
        return oaid ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   150
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   151
02bb8761fcce Initial load
duke
parents:
diff changeset
   152
    public void write(ObjectId objectId, OutputStream os)
02bb8761fcce Initial load
duke
parents:
diff changeset
   153
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   154
        writeTemplate( os ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   155
        objectId.write( os ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   156
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   157
02bb8761fcce Initial load
duke
parents:
diff changeset
   158
    public void write( OutputStream os )
02bb8761fcce Initial load
duke
parents:
diff changeset
   159
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   160
        writeTemplate( os ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   161
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   162
02bb8761fcce Initial load
duke
parents:
diff changeset
   163
    abstract protected void writeTemplate( OutputStream os ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   164
02bb8761fcce Initial load
duke
parents:
diff changeset
   165
    protected int getMagic()
02bb8761fcce Initial load
duke
parents:
diff changeset
   166
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   167
        return magic ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   168
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   169
02bb8761fcce Initial load
duke
parents:
diff changeset
   170
    // All subclasses should set the version in their constructors.
02bb8761fcce Initial load
duke
parents:
diff changeset
   171
    // Public so it can be used in a white-box test.
02bb8761fcce Initial load
duke
parents:
diff changeset
   172
    public void setORBVersion( ORBVersion version )
02bb8761fcce Initial load
duke
parents:
diff changeset
   173
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   174
        this.version = version ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   175
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   176
02bb8761fcce Initial load
duke
parents:
diff changeset
   177
    public ORBVersion getORBVersion()
02bb8761fcce Initial load
duke
parents:
diff changeset
   178
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   179
        return version ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   180
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   181
02bb8761fcce Initial load
duke
parents:
diff changeset
   182
    protected byte[] readObjectKey( InputStream is )
02bb8761fcce Initial load
duke
parents:
diff changeset
   183
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   184
        int len = is.read_long() ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   185
        byte[] result = new byte[len] ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   186
        is.read_octet_array( result, 0, len ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   187
        return result ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   188
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   189
02bb8761fcce Initial load
duke
parents:
diff changeset
   190
    public CorbaServerRequestDispatcher getServerRequestDispatcher( ORB orb, ObjectId id )
02bb8761fcce Initial load
duke
parents:
diff changeset
   191
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   192
        return orb.getRequestDispatcherRegistry().getServerRequestDispatcher( scid ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   193
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   194
}