KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > corba > se > impl > ior > ObjectReferenceFactoryImpl


1 /*
2  * @(#)ObjectReferenceFactoryImpl.java 1.9 03/12/19
3  *
4  * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
5  * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
6  */

7
8 package com.sun.corba.se.impl.ior ;
9
10 import java.util.Iterator JavaDoc ;
11
12 import org.omg.CORBA.portable.InputStream JavaDoc ;
13 import org.omg.CORBA.portable.OutputStream JavaDoc ;
14 import org.omg.CORBA.portable.StreamableValue JavaDoc ;
15
16 import org.omg.CORBA.TypeCode JavaDoc ;
17
18 import org.omg.PortableInterceptor.ObjectReferenceFactory JavaDoc ;
19 import org.omg.PortableInterceptor.ObjectReferenceFactoryHelper JavaDoc ;
20
21 import com.sun.corba.se.spi.oa.ObjectAdapter ;
22
23 import com.sun.corba.se.spi.ior.ObjectId ;
24 import com.sun.corba.se.spi.ior.ObjectKeyTemplate ;
25 import com.sun.corba.se.spi.ior.ObjectAdapterId ;
26 import com.sun.corba.se.spi.ior.IOR;
27 import com.sun.corba.se.spi.ior.IORFactory;
28 import com.sun.corba.se.spi.ior.IORTemplateList;
29 import com.sun.corba.se.spi.ior.IORFactories;
30
31 import com.sun.corba.se.impl.orbutil.ORBUtility ;
32
33 import com.sun.corba.se.spi.orb.ORB ;
34
35 /** This is an implementation of the ObjectReferenceFactory abstract value
36 * type defined by the portable interceptors IDL.
37 * Note that this is a direct Java implementation
38 * of the abstract value type: there is no stateful value type defined in IDL,
39 * since defining the state in IDL is awkward and inefficient. The best way
40 * to define the state is to use internal data structures that can be written
41 * to and read from CORBA streams.
42 */

43 public class ObjectReferenceFactoryImpl extends ObjectReferenceProducerBase
44     implements ObjectReferenceFactory JavaDoc, StreamableValue JavaDoc
45 {
46     transient private IORTemplateList iorTemplates ;
47
48     public ObjectReferenceFactoryImpl( InputStream JavaDoc is )
49     {
50     super( (ORB)(is.orb()) ) ;
51     _read( is ) ;
52     }
53
54     public ObjectReferenceFactoryImpl( ORB orb, IORTemplateList iortemps )
55     {
56     super( orb ) ;
57     iorTemplates = iortemps ;
58     }
59
60     public boolean equals( Object JavaDoc obj )
61     {
62     if (!(obj instanceof ObjectReferenceFactoryImpl))
63         return false ;
64
65     ObjectReferenceFactoryImpl other = (ObjectReferenceFactoryImpl)obj ;
66
67     return (iorTemplates != null) &&
68         iorTemplates.equals( other.iorTemplates ) ;
69     }
70
71     public int hashCode()
72     {
73     return iorTemplates.hashCode() ;
74     }
75
76     // Note that this repository ID must reflect the implementation
77
// of the abstract valuetype (that is, this class), not the
78
// repository ID of the org.omg.PortableInterceptor.ObjectReferenceFactory
79
// class. This allows for multiple independent implementations
80
// of the abstract valuetype, should that become necessary.
81
public static final String JavaDoc repositoryId =
82     "IDL:com/sun/corba/se/impl/ior/ObjectReferenceFactoryImpl:1.0" ;
83
84     public String JavaDoc[] _truncatable_ids()
85     {
86     return new String JavaDoc[] { repositoryId } ;
87     }
88
89     public TypeCode JavaDoc _type()
90     {
91     return ObjectReferenceFactoryHelper.type() ;
92     }
93
94     /** Read the data into a (presumably) empty ObjectReferenceFactoryImpl.
95     * This sets the orb to the ORB of the InputStream.
96     */

97     public void _read( InputStream JavaDoc is )
98     {
99     org.omg.CORBA_2_3.portable.InputStream JavaDoc istr =
100         (org.omg.CORBA_2_3.portable.InputStream JavaDoc)is ;
101
102     iorTemplates = IORFactories.makeIORTemplateList( istr ) ;
103     }
104
105     /** Write the state to the OutputStream.
106      */

107     public void _write( OutputStream JavaDoc os )
108     {
109     org.omg.CORBA_2_3.portable.OutputStream JavaDoc ostr =
110         (org.omg.CORBA_2_3.portable.OutputStream JavaDoc)os ;
111
112     iorTemplates.write( ostr ) ;
113     }
114
115     public IORFactory getIORFactory()
116     {
117     return iorTemplates ;
118     }
119
120     public IORTemplateList getIORTemplateList()
121     {
122     return iorTemplates ;
123     }
124 }
125
Popular Tags