KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > corba > se > spi > ior > IORFactories


1 /*
2  * @(#)IORFactories.java 1.15 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.spi.ior ;
9
10 import java.io.Serializable JavaDoc ;
11
12 import org.omg.CORBA_2_3.portable.InputStream JavaDoc ;
13
14 import org.omg.CORBA.BAD_PARAM JavaDoc ;
15 import org.omg.CORBA.portable.ValueFactory JavaDoc ;
16
17 import org.omg.PortableInterceptor.ObjectReferenceTemplate JavaDoc ;
18 import org.omg.PortableInterceptor.ObjectReferenceFactory JavaDoc ;
19
20 import com.sun.corba.se.impl.ior.ObjectIdImpl ;
21 import com.sun.corba.se.impl.ior.ObjectKeyImpl ;
22 import com.sun.corba.se.impl.ior.IORImpl ;
23 import com.sun.corba.se.impl.ior.IORTemplateImpl ;
24 import com.sun.corba.se.impl.ior.IORTemplateListImpl ;
25 import com.sun.corba.se.impl.ior.ObjectReferenceProducerBase ;
26 import com.sun.corba.se.impl.ior.ObjectReferenceFactoryImpl ;
27 import com.sun.corba.se.impl.ior.ObjectReferenceTemplateImpl ;
28 import com.sun.corba.se.impl.ior.ObjectKeyFactoryImpl ;
29
30 import com.sun.corba.se.impl.orbutil.ORBUtility ;
31
32 import com.sun.corba.se.spi.orb.ORB ;
33
34 /** This class provides a number of factory methods for creating
35  * various IOR SPI classes which are not subclassed for specific protocols.
36  * The following types must be created using this class:
37  * <ul>
38  * <li>ObjectId</li>
39  * <li>ObjectKey</li>
40  * <li>IOR</li>
41  * <li>IORTemplate</li>
42  * </ul>
43  */

44 public class IORFactories {
45     private IORFactories() {}
46
47     /** Create an ObjectId for the given byte sequence.
48      */

49     public static ObjectId makeObjectId( byte[] id )
50     {
51     return new ObjectIdImpl( id ) ;
52     }
53
54     /** Create an ObjectKey for the given ObjectKeyTemplate and
55      * ObjectId.
56      */

57     public static ObjectKey makeObjectKey( ObjectKeyTemplate oktemp, ObjectId oid )
58     {
59     return new ObjectKeyImpl( oktemp, oid ) ;
60     }
61
62     /** Create an empty IOR for the given orb and typeid. The result is mutable.
63      */

64     public static IOR makeIOR( ORB orb, String JavaDoc typeid )
65     {
66     return new IORImpl( orb, typeid ) ;
67     }
68
69     /** Create an empty IOR for the given orb with a null typeid. The result is mutable.
70      */

71     public static IOR makeIOR( ORB orb )
72     {
73     return new IORImpl( orb ) ;
74     }
75
76     /** Read an IOR from an InputStream. ObjectKeys are not shared.
77      */

78     public static IOR makeIOR( InputStream JavaDoc is )
79     {
80     return new IORImpl( is ) ;
81     }
82
83     /** Create an IORTemplate with the given ObjectKeyTemplate. The result
84      * is mutable.
85      */

86     public static IORTemplate makeIORTemplate( ObjectKeyTemplate oktemp )
87     {
88     return new IORTemplateImpl( oktemp ) ;
89     }
90
91     /** Read an IORTemplate from an InputStream.
92      */

93     public static IORTemplate makeIORTemplate( InputStream JavaDoc is )
94     {
95     return new IORTemplateImpl( is ) ;
96     }
97
98     public static IORTemplateList makeIORTemplateList()
99     {
100     return new IORTemplateListImpl() ;
101     }
102
103     public static IORTemplateList makeIORTemplateList( InputStream JavaDoc is )
104     {
105     return new IORTemplateListImpl( is ) ;
106     }
107
108     public static IORFactory getIORFactory( ObjectReferenceTemplate JavaDoc ort )
109     {
110     if (ort instanceof ObjectReferenceTemplateImpl) {
111         ObjectReferenceTemplateImpl orti =
112         (ObjectReferenceTemplateImpl)ort ;
113         return orti.getIORFactory() ;
114     }
115
116     throw new BAD_PARAM JavaDoc() ;
117     }
118
119     public static IORTemplateList getIORTemplateList( ObjectReferenceFactory JavaDoc orf )
120     {
121     if (orf instanceof ObjectReferenceProducerBase) {
122         ObjectReferenceProducerBase base =
123         (ObjectReferenceProducerBase)orf ;
124         return base.getIORTemplateList() ;
125     }
126
127     throw new BAD_PARAM JavaDoc() ;
128     }
129
130     public static ObjectReferenceTemplate JavaDoc makeObjectReferenceTemplate( ORB orb,
131     IORTemplate iortemp )
132     {
133     return new ObjectReferenceTemplateImpl( orb, iortemp ) ;
134     }
135
136     public static ObjectReferenceFactory JavaDoc makeObjectReferenceFactory( ORB orb,
137     IORTemplateList iortemps )
138     {
139     return new ObjectReferenceFactoryImpl( orb, iortemps ) ;
140     }
141
142     public static ObjectKeyFactory makeObjectKeyFactory( ORB orb )
143     {
144     return new ObjectKeyFactoryImpl( orb ) ;
145     }
146
147     public static IOR getIOR( org.omg.CORBA.Object JavaDoc obj )
148     {
149     return ORBUtility.getIOR( obj ) ;
150     }
151
152     public static org.omg.CORBA.Object JavaDoc makeObjectReference( IOR ior )
153     {
154     return ORBUtility.makeObjectReference( ior ) ;
155     }
156
157     /** This method must be called in order to register the value
158      * factories for the ObjectReferenceTemplate and ObjectReferenceFactory
159      * value types.
160      */

161     public static void registerValueFactories( ORB orb )
162     {
163     // Create and register the factory for the Object Reference Template
164
// implementation.
165
ValueFactory JavaDoc vf = new ValueFactory JavaDoc() {
166         public Serializable JavaDoc read_value( InputStream JavaDoc is )
167         {
168         return new ObjectReferenceTemplateImpl( is ) ;
169         }
170     } ;
171
172     orb.register_value_factory( ObjectReferenceTemplateImpl.repositoryId, vf ) ;
173
174     // Create and register the factory for the Object Reference Factory
175
// implementation.
176
vf = new ValueFactory JavaDoc() {
177         public Serializable JavaDoc read_value( InputStream JavaDoc is )
178         {
179         return new ObjectReferenceFactoryImpl( is ) ;
180         }
181     } ;
182
183     orb.register_value_factory( ObjectReferenceFactoryImpl.repositoryId, vf ) ;
184     }
185 }
186
Popular Tags