KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > corba > se > impl > ior > ObjectKeyTemplateBase


1 /*
2  * @(#)ObjectKeyTemplateBase.java 1.16 04/03/01
3  *
4  * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
5  * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
6  */

7
8 package com.sun.corba.se.impl.ior;
9
10 import java.util.Iterator JavaDoc ;
11
12 import org.omg.CORBA_2_3.portable.InputStream JavaDoc ;
13 import org.omg.CORBA_2_3.portable.OutputStream JavaDoc ;
14
15 import com.sun.corba.se.spi.protocol.CorbaServerRequestDispatcher ;
16
17 import com.sun.corba.se.spi.ior.ObjectId ;
18 import com.sun.corba.se.spi.ior.ObjectAdapterId ;
19 import com.sun.corba.se.spi.ior.ObjectKeyTemplate ;
20
21 import com.sun.corba.se.spi.orb.ORB ;
22 import com.sun.corba.se.spi.orb.ORBVersion ;
23
24 import com.sun.corba.se.spi.logging.CORBALogDomains ;
25
26
27 import com.sun.corba.se.impl.encoding.EncapsOutputStream ;
28
29 import com.sun.corba.se.impl.logging.IORSystemException ;
30
31
32 /**
33  * @author
34  */

35 public abstract class ObjectKeyTemplateBase implements ObjectKeyTemplate
36 {
37     // Fixed constants for Java IDL object key template forms
38
public static final String JavaDoc JIDL_ORB_ID = "" ;
39     private static final String JavaDoc[] JIDL_OAID_STRINGS = { "TransientObjectAdapter" } ;
40     public static final ObjectAdapterId JIDL_OAID = new ObjectAdapterIdArray( JIDL_OAID_STRINGS ) ;
41
42     private ORB orb ;
43     protected IORSystemException wrapper ;
44     private ORBVersion version ;
45     private int magic ;
46     private int scid ;
47     private int serverid ;
48     private String JavaDoc orbid ;
49     private ObjectAdapterId oaid ;
50
51     private byte[] adapterId ;
52
53     public byte[] getAdapterId()
54     {
55     return (byte[])(adapterId.clone()) ;
56     }
57
58     private byte[] computeAdapterId()
59     {
60     // write out serverid, orbid, oaid
61
ByteBuffer buff = new ByteBuffer() ;
62
63     buff.append( getServerId() ) ;
64     buff.append( orbid ) ;
65
66     buff.append( oaid.getNumLevels() ) ;
67     Iterator JavaDoc iter = oaid.iterator() ;
68     while (iter.hasNext()) {
69         String JavaDoc comp = (String JavaDoc)(iter.next()) ;
70         buff.append( comp ) ;
71     }
72
73     buff.trimToSize() ;
74
75     return buff.toArray() ;
76     }
77
78     public ObjectKeyTemplateBase( ORB orb, int magic, int scid, int serverid,
79     String JavaDoc orbid, ObjectAdapterId oaid )
80     {
81     this.orb = orb ;
82     this.wrapper = IORSystemException.get( orb,
83         CORBALogDomains.OA_IOR ) ;
84     this.magic = magic ;
85     this.scid = scid ;
86     this.serverid = serverid ;
87     this.orbid = orbid ;
88     this.oaid = oaid ;
89
90     adapterId = computeAdapterId() ;
91     }
92
93     public boolean equals( Object JavaDoc obj )
94     {
95     if (!(obj instanceof ObjectKeyTemplateBase))
96         return false ;
97
98     ObjectKeyTemplateBase other = (ObjectKeyTemplateBase)obj ;
99
100     return (magic == other.magic) && (scid == other.scid) &&
101         (serverid == other.serverid) && (version.equals( other.version ) &&
102         orbid.equals( other.orbid ) && oaid.equals( other.oaid )) ;
103     }
104    
105     public int hashCode()
106     {
107     int result = 17 ;
108     result = 37*result + magic ;
109     result = 37*result + scid ;
110     result = 37*result + serverid ;
111     result = 37*result + version.hashCode() ;
112     result = 37*result + orbid.hashCode() ;
113     result = 37*result + oaid.hashCode() ;
114     return result ;
115     }
116
117     public int getSubcontractId()
118     {
119     return scid ;
120     }
121
122     public int getServerId()
123     {
124     return serverid ;
125     }
126
127     public String JavaDoc getORBId()
128     {
129     return orbid ;
130     }
131
132     public ObjectAdapterId getObjectAdapterId()
133     {
134     return oaid ;
135     }
136
137     public void write(ObjectId objectId, OutputStream JavaDoc os)
138     {
139     writeTemplate( os ) ;
140     objectId.write( os ) ;
141     }
142
143     public void write( OutputStream JavaDoc os )
144     {
145     writeTemplate( os ) ;
146     }
147
148     abstract protected void writeTemplate( OutputStream JavaDoc os ) ;
149    
150     protected int getMagic()
151     {
152     return magic ;
153     }
154
155     // All subclasses should set the version in their constructors.
156
// Public so it can be used in a white-box test.
157
public void setORBVersion( ORBVersion version )
158     {
159     this.version = version ;
160     }
161
162     public ORBVersion getORBVersion()
163     {
164     return version ;
165     }
166
167     protected byte[] readObjectKey( InputStream JavaDoc is )
168     {
169     int len = is.read_long() ;
170     byte[] result = new byte[len] ;
171     is.read_octet_array( result, 0, len ) ;
172     return result ;
173     }
174
175     public CorbaServerRequestDispatcher getServerRequestDispatcher( ORB orb, ObjectId id )
176     {
177     return orb.getRequestDispatcherRegistry().getServerRequestDispatcher( scid ) ;
178     }
179 }
180
Popular Tags