src/share/classes/com/sun/corba/se/spi/ior/IORFactories.java

Thu, 31 Aug 2017 18:10:36 +0800

author
aoqi
date
Thu, 31 Aug 2017 18:10:36 +0800
changeset 748
6845b95cba6b
parent 158
91006f157c46
parent 0
7ef37b2cdcad
permissions
-rw-r--r--

merge

aoqi@0 1 /*
aoqi@0 2 * Copyright (c) 2003, Oracle and/or its affiliates. All rights reserved.
aoqi@0 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
aoqi@0 4 *
aoqi@0 5 * This code is free software; you can redistribute it and/or modify it
aoqi@0 6 * under the terms of the GNU General Public License version 2 only, as
aoqi@0 7 * published by the Free Software Foundation. Oracle designates this
aoqi@0 8 * particular file as subject to the "Classpath" exception as provided
aoqi@0 9 * by Oracle in the LICENSE file that accompanied this code.
aoqi@0 10 *
aoqi@0 11 * This code is distributed in the hope that it will be useful, but WITHOUT
aoqi@0 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
aoqi@0 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
aoqi@0 14 * version 2 for more details (a copy is included in the LICENSE file that
aoqi@0 15 * accompanied this code).
aoqi@0 16 *
aoqi@0 17 * You should have received a copy of the GNU General Public License version
aoqi@0 18 * 2 along with this work; if not, write to the Free Software Foundation,
aoqi@0 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
aoqi@0 20 *
aoqi@0 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
aoqi@0 22 * or visit www.oracle.com if you need additional information or have any
aoqi@0 23 * questions.
aoqi@0 24 */
aoqi@0 25
aoqi@0 26 package com.sun.corba.se.spi.ior ;
aoqi@0 27
aoqi@0 28 import java.io.Serializable ;
aoqi@0 29
aoqi@0 30 import org.omg.CORBA_2_3.portable.InputStream ;
aoqi@0 31
aoqi@0 32 import org.omg.CORBA.BAD_PARAM ;
aoqi@0 33 import org.omg.CORBA.portable.ValueFactory ;
aoqi@0 34
aoqi@0 35 import org.omg.PortableInterceptor.ObjectReferenceTemplate ;
aoqi@0 36 import org.omg.PortableInterceptor.ObjectReferenceFactory ;
aoqi@0 37
aoqi@0 38 import com.sun.corba.se.impl.ior.ObjectIdImpl ;
aoqi@0 39 import com.sun.corba.se.impl.ior.ObjectKeyImpl ;
aoqi@0 40 import com.sun.corba.se.impl.ior.IORImpl ;
aoqi@0 41 import com.sun.corba.se.impl.ior.IORTemplateImpl ;
aoqi@0 42 import com.sun.corba.se.impl.ior.IORTemplateListImpl ;
aoqi@0 43 import com.sun.corba.se.impl.ior.ObjectReferenceProducerBase ;
aoqi@0 44 import com.sun.corba.se.impl.ior.ObjectReferenceFactoryImpl ;
aoqi@0 45 import com.sun.corba.se.impl.ior.ObjectReferenceTemplateImpl ;
aoqi@0 46 import com.sun.corba.se.impl.ior.ObjectKeyFactoryImpl ;
aoqi@0 47
aoqi@0 48 import com.sun.corba.se.impl.orbutil.ORBUtility ;
aoqi@0 49
aoqi@0 50 import com.sun.corba.se.spi.orb.ORB ;
aoqi@0 51
aoqi@0 52 /** This class provides a number of factory methods for creating
aoqi@0 53 * various IOR SPI classes which are not subclassed for specific protocols.
aoqi@0 54 * The following types must be created using this class:
aoqi@0 55 * <ul>
aoqi@0 56 * <li>ObjectId</li>
aoqi@0 57 * <li>ObjectKey</li>
aoqi@0 58 * <li>IOR</li>
aoqi@0 59 * <li>IORTemplate</li>
aoqi@0 60 * </ul>
aoqi@0 61 */
aoqi@0 62 public class IORFactories {
aoqi@0 63 private IORFactories() {}
aoqi@0 64
aoqi@0 65 /** Create an ObjectId for the given byte sequence.
aoqi@0 66 */
aoqi@0 67 public static ObjectId makeObjectId( byte[] id )
aoqi@0 68 {
aoqi@0 69 return new ObjectIdImpl( id ) ;
aoqi@0 70 }
aoqi@0 71
aoqi@0 72 /** Create an ObjectKey for the given ObjectKeyTemplate and
aoqi@0 73 * ObjectId.
aoqi@0 74 */
aoqi@0 75 public static ObjectKey makeObjectKey( ObjectKeyTemplate oktemp, ObjectId oid )
aoqi@0 76 {
aoqi@0 77 return new ObjectKeyImpl( oktemp, oid ) ;
aoqi@0 78 }
aoqi@0 79
aoqi@0 80 /** Create an empty IOR for the given orb and typeid. The result is mutable.
aoqi@0 81 */
aoqi@0 82 public static IOR makeIOR( ORB orb, String typeid )
aoqi@0 83 {
aoqi@0 84 return new IORImpl( orb, typeid ) ;
aoqi@0 85 }
aoqi@0 86
aoqi@0 87 /** Create an empty IOR for the given orb with a null typeid. The result is mutable.
aoqi@0 88 */
aoqi@0 89 public static IOR makeIOR( ORB orb )
aoqi@0 90 {
aoqi@0 91 return new IORImpl( orb ) ;
aoqi@0 92 }
aoqi@0 93
aoqi@0 94 /** Read an IOR from an InputStream. ObjectKeys are not shared.
aoqi@0 95 */
aoqi@0 96 public static IOR makeIOR( InputStream is )
aoqi@0 97 {
aoqi@0 98 return new IORImpl( is ) ;
aoqi@0 99 }
aoqi@0 100
aoqi@0 101 /** Create an IORTemplate with the given ObjectKeyTemplate. The result
aoqi@0 102 * is mutable.
aoqi@0 103 */
aoqi@0 104 public static IORTemplate makeIORTemplate( ObjectKeyTemplate oktemp )
aoqi@0 105 {
aoqi@0 106 return new IORTemplateImpl( oktemp ) ;
aoqi@0 107 }
aoqi@0 108
aoqi@0 109 /** Read an IORTemplate from an InputStream.
aoqi@0 110 */
aoqi@0 111 public static IORTemplate makeIORTemplate( InputStream is )
aoqi@0 112 {
aoqi@0 113 return new IORTemplateImpl( is ) ;
aoqi@0 114 }
aoqi@0 115
aoqi@0 116 public static IORTemplateList makeIORTemplateList()
aoqi@0 117 {
aoqi@0 118 return new IORTemplateListImpl() ;
aoqi@0 119 }
aoqi@0 120
aoqi@0 121 public static IORTemplateList makeIORTemplateList( InputStream is )
aoqi@0 122 {
aoqi@0 123 return new IORTemplateListImpl( is ) ;
aoqi@0 124 }
aoqi@0 125
aoqi@0 126 public static IORFactory getIORFactory( ObjectReferenceTemplate ort )
aoqi@0 127 {
aoqi@0 128 if (ort instanceof ObjectReferenceTemplateImpl) {
aoqi@0 129 ObjectReferenceTemplateImpl orti =
aoqi@0 130 (ObjectReferenceTemplateImpl)ort ;
aoqi@0 131 return orti.getIORFactory() ;
aoqi@0 132 }
aoqi@0 133
aoqi@0 134 throw new BAD_PARAM() ;
aoqi@0 135 }
aoqi@0 136
aoqi@0 137 public static IORTemplateList getIORTemplateList( ObjectReferenceFactory orf )
aoqi@0 138 {
aoqi@0 139 if (orf instanceof ObjectReferenceProducerBase) {
aoqi@0 140 ObjectReferenceProducerBase base =
aoqi@0 141 (ObjectReferenceProducerBase)orf ;
aoqi@0 142 return base.getIORTemplateList() ;
aoqi@0 143 }
aoqi@0 144
aoqi@0 145 throw new BAD_PARAM() ;
aoqi@0 146 }
aoqi@0 147
aoqi@0 148 public static ObjectReferenceTemplate makeObjectReferenceTemplate( ORB orb,
aoqi@0 149 IORTemplate iortemp )
aoqi@0 150 {
aoqi@0 151 return new ObjectReferenceTemplateImpl( orb, iortemp ) ;
aoqi@0 152 }
aoqi@0 153
aoqi@0 154 public static ObjectReferenceFactory makeObjectReferenceFactory( ORB orb,
aoqi@0 155 IORTemplateList iortemps )
aoqi@0 156 {
aoqi@0 157 return new ObjectReferenceFactoryImpl( orb, iortemps ) ;
aoqi@0 158 }
aoqi@0 159
aoqi@0 160 public static ObjectKeyFactory makeObjectKeyFactory( ORB orb )
aoqi@0 161 {
aoqi@0 162 return new ObjectKeyFactoryImpl( orb ) ;
aoqi@0 163 }
aoqi@0 164
aoqi@0 165 public static IOR getIOR( org.omg.CORBA.Object obj )
aoqi@0 166 {
aoqi@0 167 return ORBUtility.getIOR( obj ) ;
aoqi@0 168 }
aoqi@0 169
aoqi@0 170 public static org.omg.CORBA.Object makeObjectReference( IOR ior )
aoqi@0 171 {
aoqi@0 172 return ORBUtility.makeObjectReference( ior ) ;
aoqi@0 173 }
aoqi@0 174
aoqi@0 175 /** This method must be called in order to register the value
aoqi@0 176 * factories for the ObjectReferenceTemplate and ObjectReferenceFactory
aoqi@0 177 * value types.
aoqi@0 178 */
aoqi@0 179 public static void registerValueFactories( ORB orb )
aoqi@0 180 {
aoqi@0 181 // Create and register the factory for the Object Reference Template
aoqi@0 182 // implementation.
aoqi@0 183 ValueFactory vf = new ValueFactory() {
aoqi@0 184 public Serializable read_value( InputStream is )
aoqi@0 185 {
aoqi@0 186 return new ObjectReferenceTemplateImpl( is ) ;
aoqi@0 187 }
aoqi@0 188 } ;
aoqi@0 189
aoqi@0 190 orb.register_value_factory( ObjectReferenceTemplateImpl.repositoryId, vf ) ;
aoqi@0 191
aoqi@0 192 // Create and register the factory for the Object Reference Factory
aoqi@0 193 // implementation.
aoqi@0 194 vf = new ValueFactory() {
aoqi@0 195 public Serializable read_value( InputStream is )
aoqi@0 196 {
aoqi@0 197 return new ObjectReferenceFactoryImpl( is ) ;
aoqi@0 198 }
aoqi@0 199 } ;
aoqi@0 200
aoqi@0 201 orb.register_value_factory( ObjectReferenceFactoryImpl.repositoryId, vf ) ;
aoqi@0 202 }
aoqi@0 203 }

mercurial