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