ObjectReferenceTemplateImpl.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 java.util.Iterator ; 29 30import org.omg.CORBA.portable.InputStream ; 31import org.omg.CORBA.portable.OutputStream ; 32import org.omg.CORBA.portable.StreamableValue ; 33 34import org.omg.CORBA.TypeCode ; 35 36import org.omg.PortableInterceptor.ObjectReferenceTemplate ; 37import org.omg.PortableInterceptor.ObjectReferenceTemplateHelper ; 38 39import com.sun.corba.se.spi.oa.ObjectAdapter ; 40 41import com.sun.corba.se.spi.ior.ObjectId ; 42import com.sun.corba.se.spi.ior.ObjectKeyTemplate ; 43import com.sun.corba.se.spi.ior.ObjectAdapterId ; 44import com.sun.corba.se.spi.ior.IOR; 45import com.sun.corba.se.spi.ior.IORFactory; 46import com.sun.corba.se.spi.ior.IORTemplate; 47import com.sun.corba.se.spi.ior.IORTemplateList; 48import com.sun.corba.se.spi.ior.IORFactories; 49 50import com.sun.corba.se.impl.orbutil.ORBUtility ; 51 52import com.sun.corba.se.spi.orb.ORB ; 53 54/** This is an implementation of the ObjectReferenceTemplate abstract value 55* type defined by the portable interceptors IDL. 56* Note that this is a direct Java implementation 57* of the abstract value type: there is no stateful value type defined in IDL, 58* since defining the state in IDL is awkward and inefficient. The best way 59* to define the state is to use internal data structures that can be written 60* to and read from CORBA streams. 61*/ 62public class ObjectReferenceTemplateImpl extends ObjectReferenceProducerBase 63 implements ObjectReferenceTemplate, StreamableValue 64{ 65 transient private IORTemplate iorTemplate ; 66 67 public ObjectReferenceTemplateImpl( InputStream is ) 68 { 69 super( (ORB)(is.orb()) ) ; 70 _read( is ) ; 71 } 72 73 public ObjectReferenceTemplateImpl( ORB orb, IORTemplate iortemp ) 74 { 75 super( orb ) ; 76 iorTemplate = iortemp ; 77 } 78 79 public boolean equals( Object obj ) 80 { 81 if (!(obj instanceof ObjectReferenceTemplateImpl)) 82 return false ; 83 84 ObjectReferenceTemplateImpl other = (ObjectReferenceTemplateImpl)obj ; 85 86 return (iorTemplate != null) && 87 iorTemplate.equals( other.iorTemplate ) ; 88 } 89 90 public int hashCode() 91 { 92 return iorTemplate.hashCode() ; 93 } 94 95 // Note that this repository ID must reflect the implementation 96 // of the abstract valuetype (that is, this class), not the 97 // repository ID of the org.omg.PortableInterceptor.ObjectReferenceTemplate 98 // class. This allows for multiple independent implementations 99 // of the abstract valuetype, should that become necessary. 100 public static final String repositoryId = 101 "IDL:com/sun/corba/se/impl/ior/ObjectReferenceTemplateImpl:1.0" ; 102 103 public String[] _truncatable_ids() 104 { 105 return new String[] { repositoryId } ; 106 } 107 108 public TypeCode _type() 109 { 110 return ObjectReferenceTemplateHelper.type() ; 111 } 112 113 /** Read the data into a (presumably) empty ORTImpl. This sets the 114 * orb to the ORB of the InputStream. 115 */ 116 public void _read( InputStream is ) 117 { 118 org.omg.CORBA_2_3.portable.InputStream istr = 119 (org.omg.CORBA_2_3.portable.InputStream)is ; 120 iorTemplate = IORFactories.makeIORTemplate( istr ) ; 121 orb = (ORB)(istr.orb()) ; 122 } 123 124 /** Write the state to the OutputStream. 125 */ 126 public void _write( OutputStream os ) 127 { 128 org.omg.CORBA_2_3.portable.OutputStream ostr = 129 (org.omg.CORBA_2_3.portable.OutputStream)os ; 130 131 iorTemplate.write( ostr ) ; 132 } 133 134 public String server_id () 135 { 136 int val = iorTemplate.getObjectKeyTemplate().getServerId() ; 137 return Integer.toString( val ) ; 138 } 139 140 public String orb_id () 141 { 142 return iorTemplate.getObjectKeyTemplate().getORBId() ; 143 } 144 145 public String[] adapter_name() 146 { 147 ObjectAdapterId poaid = 148 iorTemplate.getObjectKeyTemplate().getObjectAdapterId() ; 149 150 return poaid.getAdapterName() ; 151 } 152 153 public IORFactory getIORFactory() 154 { 155 return iorTemplate ; 156 } 157 158 public IORTemplateList getIORTemplateList() 159 { 160 IORTemplateList tl = IORFactories.makeIORTemplateList() ; 161 tl.add( iorTemplate ) ; 162 tl.makeImmutable() ; 163 return tl ; 164 } 165} 166