1 /*
   2  * Copyright (c) 2000, 2004, 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 
  26 package com.sun.corba.se.spi.ior.iiop ;
  27 
  28 import org.omg.CORBA_2_3.portable.InputStream ;
  29 
  30 import com.sun.corba.se.spi.ior.Identifiable ;
  31 import com.sun.corba.se.spi.ior.IdentifiableFactory ;
  32 import com.sun.corba.se.spi.ior.EncapsulationFactoryBase ;
  33 import com.sun.corba.se.spi.ior.ObjectId ;
  34 import com.sun.corba.se.spi.ior.ObjectKeyTemplate ;
  35 
  36 import com.sun.corba.se.spi.ior.iiop.IIOPAddress ;
  37 import com.sun.corba.se.spi.ior.iiop.IIOPProfileTemplate ;
  38 import com.sun.corba.se.spi.ior.iiop.GIOPVersion ;
  39 
  40 import com.sun.corba.se.spi.orb.ORB ;
  41 
  42 import com.sun.corba.se.impl.encoding.MarshalInputStream ;
  43 
  44 import com.sun.corba.se.impl.ior.iiop.IIOPAddressImpl ;
  45 import com.sun.corba.se.impl.ior.iiop.CodeSetsComponentImpl ;
  46 import com.sun.corba.se.impl.ior.iiop.AlternateIIOPAddressComponentImpl ;
  47 import com.sun.corba.se.impl.ior.iiop.JavaCodebaseComponentImpl ;
  48 import com.sun.corba.se.impl.ior.iiop.MaxStreamFormatVersionComponentImpl ;
  49 import com.sun.corba.se.impl.ior.iiop.JavaSerializationComponent;
  50 import com.sun.corba.se.impl.ior.iiop.ORBTypeComponentImpl ;
  51 import com.sun.corba.se.impl.ior.iiop.IIOPProfileImpl ;
  52 import com.sun.corba.se.impl.ior.iiop.IIOPProfileTemplateImpl ;
  53 import com.sun.corba.se.impl.ior.iiop.RequestPartitioningComponentImpl ;
  54 import com.sun.corba.se.impl.orbutil.ORBConstants;
  55 import com.sun.corba.se.impl.orbutil.ORBConstants;
  56 
  57 import org.omg.IOP.TAG_ALTERNATE_IIOP_ADDRESS ;
  58 import org.omg.IOP.TAG_CODE_SETS ;
  59 import org.omg.IOP.TAG_JAVA_CODEBASE ;
  60 import org.omg.IOP.TAG_RMI_CUSTOM_MAX_STREAM_FORMAT ;
  61 import org.omg.IOP.TAG_ORB_TYPE ;
  62 import org.omg.IOP.TAG_INTERNET_IOP ;
  63 
  64 /** This class provides all of the factories for the IIOP profiles and
  65  * components.  This includes direct construction of profiles and templates,
  66  * as well as constructing factories that can be registered with an
  67  * IdentifiableFactoryFinder.
  68  */
  69 public abstract class IIOPFactories {
  70     private IIOPFactories() {}
  71 
  72     public static IdentifiableFactory makeRequestPartitioningComponentFactory()
  73     {
  74         return new EncapsulationFactoryBase(ORBConstants.TAG_REQUEST_PARTITIONING_ID) {
  75             public Identifiable readContents(InputStream in)
  76             {
  77                 int threadPoolToUse = in.read_ulong();
  78                 Identifiable comp =
  79                     new RequestPartitioningComponentImpl(threadPoolToUse);
  80                 return comp;
  81             }
  82         };
  83     }
  84 
  85     public static RequestPartitioningComponent makeRequestPartitioningComponent(
  86             int threadPoolToUse)
  87     {
  88         return new RequestPartitioningComponentImpl(threadPoolToUse);
  89     }
  90 
  91     public static IdentifiableFactory makeAlternateIIOPAddressComponentFactory()
  92     {
  93         return new EncapsulationFactoryBase(TAG_ALTERNATE_IIOP_ADDRESS.value) {
  94             public Identifiable readContents( InputStream in )
  95             {
  96                 IIOPAddress addr = new IIOPAddressImpl( in ) ;
  97                 Identifiable comp =
  98                     new AlternateIIOPAddressComponentImpl( addr ) ;
  99                 return comp ;
 100             }
 101         } ;
 102     }
 103 
 104     public static AlternateIIOPAddressComponent makeAlternateIIOPAddressComponent(
 105         IIOPAddress addr )
 106     {
 107         return new AlternateIIOPAddressComponentImpl( addr ) ;
 108     }
 109 
 110     public static IdentifiableFactory makeCodeSetsComponentFactory()
 111     {
 112         return new EncapsulationFactoryBase(TAG_CODE_SETS.value) {
 113             public Identifiable readContents( InputStream in )
 114             {
 115                 return new CodeSetsComponentImpl( in ) ;
 116             }
 117         } ;
 118     }
 119 
 120     public static CodeSetsComponent makeCodeSetsComponent( ORB orb )
 121     {
 122         return new CodeSetsComponentImpl( orb ) ;
 123     }
 124 
 125     public static IdentifiableFactory makeJavaCodebaseComponentFactory()
 126     {
 127         return new EncapsulationFactoryBase(TAG_JAVA_CODEBASE.value) {
 128             public Identifiable readContents( InputStream in )
 129             {
 130                 String url = in.read_string() ;
 131                 Identifiable comp = new JavaCodebaseComponentImpl( url ) ;
 132                 return comp ;
 133             }
 134         } ;
 135     }
 136 
 137     public static JavaCodebaseComponent makeJavaCodebaseComponent(
 138         String codebase )
 139     {
 140         return new JavaCodebaseComponentImpl( codebase ) ;
 141     }
 142 
 143     public static IdentifiableFactory makeORBTypeComponentFactory()
 144     {
 145         return new EncapsulationFactoryBase(TAG_ORB_TYPE.value) {
 146             public Identifiable readContents( InputStream in )
 147             {
 148                 int type = in.read_ulong() ;
 149                 Identifiable comp = new ORBTypeComponentImpl( type ) ;
 150                 return comp ;
 151             }
 152         } ;
 153     }
 154 
 155     public static ORBTypeComponent makeORBTypeComponent( int type )
 156     {
 157         return new ORBTypeComponentImpl( type ) ;
 158     }
 159 
 160     public static IdentifiableFactory makeMaxStreamFormatVersionComponentFactory()
 161     {
 162         return new EncapsulationFactoryBase(TAG_RMI_CUSTOM_MAX_STREAM_FORMAT.value) {
 163             public Identifiable readContents(InputStream in)
 164             {
 165                 byte version = in.read_octet() ;
 166                 Identifiable comp = new MaxStreamFormatVersionComponentImpl(version);
 167                 return comp ;
 168             }
 169         };
 170     }
 171 
 172     public static MaxStreamFormatVersionComponent makeMaxStreamFormatVersionComponent()
 173     {
 174         return new MaxStreamFormatVersionComponentImpl() ;
 175     }
 176 
 177     public static IdentifiableFactory makeJavaSerializationComponentFactory() {
 178         return new EncapsulationFactoryBase(
 179                                 ORBConstants.TAG_JAVA_SERIALIZATION_ID) {
 180             public Identifiable readContents(InputStream in) {
 181                 byte version = in.read_octet();
 182                 Identifiable cmp = new JavaSerializationComponent(version);
 183                 return cmp;
 184             }
 185         };
 186     }
 187 
 188     public static JavaSerializationComponent makeJavaSerializationComponent() {
 189         return JavaSerializationComponent.singleton();
 190     }
 191 
 192     public static IdentifiableFactory makeIIOPProfileFactory()
 193     {
 194         return new EncapsulationFactoryBase(TAG_INTERNET_IOP.value) {
 195             public Identifiable readContents( InputStream in )
 196             {
 197                 Identifiable result = new IIOPProfileImpl( in ) ;
 198                 return result ;
 199             }
 200         } ;
 201     }
 202 
 203     public static IIOPProfile makeIIOPProfile( ORB orb, ObjectKeyTemplate oktemp,
 204         ObjectId oid, IIOPProfileTemplate ptemp )
 205     {
 206         return new IIOPProfileImpl( orb, oktemp, oid, ptemp ) ;
 207     }
 208 
 209     public static IIOPProfile makeIIOPProfile( ORB orb,
 210         org.omg.IOP.TaggedProfile profile )
 211     {
 212         return new IIOPProfileImpl( orb, profile ) ;
 213     }
 214 
 215     public static IdentifiableFactory makeIIOPProfileTemplateFactory()
 216     {
 217         return new EncapsulationFactoryBase(TAG_INTERNET_IOP.value) {
 218             public Identifiable readContents( InputStream in )
 219             {
 220                 Identifiable result = new IIOPProfileTemplateImpl( in ) ;
 221                 return result ;
 222             }
 223         } ;
 224     }
 225 
 226     public static IIOPProfileTemplate makeIIOPProfileTemplate( ORB orb,
 227         GIOPVersion version, IIOPAddress primary )
 228     {
 229         return new IIOPProfileTemplateImpl( orb, version, primary ) ;
 230     }
 231 
 232     public static IIOPAddress makeIIOPAddress( ORB orb, String host, int port )
 233     {
 234         return new IIOPAddressImpl( orb, host, port ) ;
 235     }
 236 
 237     public static IIOPAddress makeIIOPAddress( InputStream is )
 238     {
 239         return new IIOPAddressImpl( is ) ;
 240     }
 241 }