WireObjectKeyTemplate.java revision 608:7e06bf1dcb09
1/*
2 * Copyright (c) 2000, 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
26package com.sun.corba.se.impl.ior;
27
28import org.omg.CORBA.OctetSeqHolder ;
29
30import org.omg.CORBA_2_3.portable.OutputStream ;
31import org.omg.CORBA_2_3.portable.InputStream ;
32
33import com.sun.corba.se.spi.protocol.CorbaServerRequestDispatcher ;
34
35import com.sun.corba.se.spi.ior.ObjectKeyTemplate ;
36import com.sun.corba.se.spi.ior.ObjectId ;
37import com.sun.corba.se.spi.ior.ObjectAdapterId ;
38
39import com.sun.corba.se.spi.orb.ORB ;
40import com.sun.corba.se.spi.orb.ORBVersion ;
41import com.sun.corba.se.spi.orb.ORBVersionFactory ;
42
43import com.sun.corba.se.spi.logging.CORBALogDomains ;
44
45import com.sun.corba.se.impl.orbutil.ORBConstants ;
46
47import com.sun.corba.se.impl.encoding.CDRInputStream ;
48
49import com.sun.corba.se.impl.logging.IORSystemException ;
50
51/**
52 * @author Ken Cavanaugh
53 */
54public class WireObjectKeyTemplate implements ObjectKeyTemplate
55{
56    private ORB orb ;
57    private IORSystemException wrapper ;
58
59    public boolean equals( Object obj )
60    {
61        if (obj == null)
62            return false ;
63
64        return obj instanceof WireObjectKeyTemplate ;
65    }
66
67    public int hashCode()
68    {
69        return 53 ; // All WireObjectKeyTemplates are the same, so they should
70                    // have the same hashCode.
71    }
72
73    private byte[] getId( InputStream is )
74    {
75        CDRInputStream cis = (CDRInputStream)is ;
76        int len = cis.getBufferLength() ;
77        byte[] result = new byte[ len ] ;
78        cis.read_octet_array( result, 0, len ) ;
79        return result ;
80    }
81
82    public WireObjectKeyTemplate( ORB orb )
83    {
84        initORB( orb ) ;
85    }
86
87    public WireObjectKeyTemplate( InputStream is, OctetSeqHolder osh )
88    {
89        osh.value = getId( is ) ;
90        initORB( (ORB)(is.orb())) ;
91    }
92
93    private void initORB( ORB orb )
94    {
95        this.orb = orb ;
96        wrapper = IORSystemException.get( orb,
97            CORBALogDomains.OA_IOR ) ;
98    }
99
100    public void write( ObjectId id, OutputStream os )
101    {
102        byte[] key = id.getId() ;
103        os.write_octet_array( key, 0, key.length ) ;
104    }
105
106    public void write( OutputStream os )
107    {
108        // Does nothing
109    }
110
111    public int getSubcontractId()
112    {
113        return ORBConstants.DEFAULT_SCID ;
114    }
115
116    /** While it might make sense to throw an exception here, this causes
117    * problems since we need to check whether unusual object references
118    * are local or not.  It seems that the easiest way to handle this is
119    * to return an invalid server id.
120    */
121    public int getServerId()
122    {
123        return -1 ;
124    }
125
126    public String getORBId()
127    {
128        throw wrapper.orbIdNotAvailable() ;
129    }
130
131    public ObjectAdapterId getObjectAdapterId()
132    {
133        throw wrapper.objectAdapterIdNotAvailable() ;
134    }
135
136    /** Adapter ID is not available, since our
137    * ORB did not implement the object carrying this key.
138    */
139    public byte[] getAdapterId()
140    {
141        throw wrapper.adapterIdNotAvailable() ;
142    }
143
144    public ORBVersion getORBVersion()
145    {
146        return ORBVersionFactory.getFOREIGN() ;
147    }
148
149    public CorbaServerRequestDispatcher getServerRequestDispatcher( ORB orb, ObjectId id )
150    {
151        byte[] bid = id.getId() ;
152        String str = new String( bid ) ;
153        return orb.getRequestDispatcherRegistry().getServerRequestDispatcher( str ) ;
154    }
155}
156