IORFactories.java revision 608:7e06bf1dcb09
1/* 2 * Copyright (c) 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.spi.ior ; 27 28import java.io.Serializable ; 29 30import org.omg.CORBA_2_3.portable.InputStream ; 31 32import org.omg.CORBA.BAD_PARAM ; 33import org.omg.CORBA.portable.ValueFactory ; 34 35import org.omg.PortableInterceptor.ObjectReferenceTemplate ; 36import org.omg.PortableInterceptor.ObjectReferenceFactory ; 37 38import com.sun.corba.se.impl.ior.ObjectIdImpl ; 39import com.sun.corba.se.impl.ior.ObjectKeyImpl ; 40import com.sun.corba.se.impl.ior.IORImpl ; 41import com.sun.corba.se.impl.ior.IORTemplateImpl ; 42import com.sun.corba.se.impl.ior.IORTemplateListImpl ; 43import com.sun.corba.se.impl.ior.ObjectReferenceProducerBase ; 44import com.sun.corba.se.impl.ior.ObjectReferenceFactoryImpl ; 45import com.sun.corba.se.impl.ior.ObjectReferenceTemplateImpl ; 46import com.sun.corba.se.impl.ior.ObjectKeyFactoryImpl ; 47 48import com.sun.corba.se.impl.orbutil.ORBUtility ; 49 50import com.sun.corba.se.spi.orb.ORB ; 51 52/** This class provides a number of factory methods for creating 53 * various IOR SPI classes which are not subclassed for specific protocols. 54 * The following types must be created using this class: 55 * <ul> 56 * <li>ObjectId</li> 57 * <li>ObjectKey</li> 58 * <li>IOR</li> 59 * <li>IORTemplate</li> 60 * </ul> 61 */ 62public class IORFactories { 63 private IORFactories() {} 64 65 /** Create an ObjectId for the given byte sequence. 66 */ 67 public static ObjectId makeObjectId( byte[] id ) 68 { 69 return new ObjectIdImpl( id ) ; 70 } 71 72 /** Create an ObjectKey for the given ObjectKeyTemplate and 73 * ObjectId. 74 */ 75 public static ObjectKey makeObjectKey( ObjectKeyTemplate oktemp, ObjectId oid ) 76 { 77 return new ObjectKeyImpl( oktemp, oid ) ; 78 } 79 80 /** Create an empty IOR for the given orb and typeid. The result is mutable. 81 */ 82 public static IOR makeIOR( ORB orb, String typeid ) 83 { 84 return new IORImpl( orb, typeid ) ; 85 } 86 87 /** Create an empty IOR for the given orb with a null typeid. The result is mutable. 88 */ 89 public static IOR makeIOR( ORB orb ) 90 { 91 return new IORImpl( orb ) ; 92 } 93 94 /** Read an IOR from an InputStream. ObjectKeys are not shared. 95 */ 96 public static IOR makeIOR( InputStream is ) 97 { 98 return new IORImpl( is ) ; 99 } 100 101 /** Create an IORTemplate with the given ObjectKeyTemplate. The result 102 * is mutable. 103 */ 104 public static IORTemplate makeIORTemplate( ObjectKeyTemplate oktemp ) 105 { 106 return new IORTemplateImpl( oktemp ) ; 107 } 108 109 /** Read an IORTemplate from an InputStream. 110 */ 111 public static IORTemplate makeIORTemplate( InputStream is ) 112 { 113 return new IORTemplateImpl( is ) ; 114 } 115 116 public static IORTemplateList makeIORTemplateList() 117 { 118 return new IORTemplateListImpl() ; 119 } 120 121 public static IORTemplateList makeIORTemplateList( InputStream is ) 122 { 123 return new IORTemplateListImpl( is ) ; 124 } 125 126 public static IORFactory getIORFactory( ObjectReferenceTemplate ort ) 127 { 128 if (ort instanceof ObjectReferenceTemplateImpl) { 129 ObjectReferenceTemplateImpl orti = 130 (ObjectReferenceTemplateImpl)ort ; 131 return orti.getIORFactory() ; 132 } 133 134 throw new BAD_PARAM() ; 135 } 136 137 public static IORTemplateList getIORTemplateList( ObjectReferenceFactory orf ) 138 { 139 if (orf instanceof ObjectReferenceProducerBase) { 140 ObjectReferenceProducerBase base = 141 (ObjectReferenceProducerBase)orf ; 142 return base.getIORTemplateList() ; 143 } 144 145 throw new BAD_PARAM() ; 146 } 147 148 public static ObjectReferenceTemplate makeObjectReferenceTemplate( ORB orb, 149 IORTemplate iortemp ) 150 { 151 return new ObjectReferenceTemplateImpl( orb, iortemp ) ; 152 } 153 154 public static ObjectReferenceFactory makeObjectReferenceFactory( ORB orb, 155 IORTemplateList iortemps ) 156 { 157 return new ObjectReferenceFactoryImpl( orb, iortemps ) ; 158 } 159 160 public static ObjectKeyFactory makeObjectKeyFactory( ORB orb ) 161 { 162 return new ObjectKeyFactoryImpl( orb ) ; 163 } 164 165 public static IOR getIOR( org.omg.CORBA.Object obj ) 166 { 167 return ORBUtility.getIOR( obj ) ; 168 } 169 170 public static org.omg.CORBA.Object makeObjectReference( IOR ior ) 171 { 172 return ORBUtility.makeObjectReference( ior ) ; 173 } 174 175 /** This method must be called in order to register the value 176 * factories for the ObjectReferenceTemplate and ObjectReferenceFactory 177 * value types. 178 */ 179 public static void registerValueFactories( ORB orb ) 180 { 181 // Create and register the factory for the Object Reference Template 182 // implementation. 183 ValueFactory vf = new ValueFactory() { 184 public Serializable read_value( InputStream is ) 185 { 186 return new ObjectReferenceTemplateImpl( is ) ; 187 } 188 } ; 189 190 orb.register_value_factory( ObjectReferenceTemplateImpl.repositoryId, vf ) ; 191 192 // Create and register the factory for the Object Reference Factory 193 // implementation. 194 vf = new ValueFactory() { 195 public Serializable read_value( InputStream is ) 196 { 197 return new ObjectReferenceFactoryImpl( is ) ; 198 } 199 } ; 200 201 orb.register_value_factory( ObjectReferenceFactoryImpl.repositoryId, vf ) ; 202 } 203} 204