KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > jts > pi > ORBInitializerImpl


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the License). You may not use this file except in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * Header Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

23
24 /*
25  * Copyright 2004-2005 Sun Microsystems, Inc. All rights reserved.
26  * Use is subject to license terms.
27  */

28
29 package com.sun.jts.pi;
30
31 import org.omg.IOP.*;
32 import org.omg.IOP.CodecFactoryPackage.UnknownEncoding JavaDoc;
33
34 import org.omg.CORBA.*;
35
36 import org.omg.CosTransactions.OTS_POLICY_TYPE;
37 import org.omg.CosTransactions.INVOCATION_POLICY_TYPE;
38
39 import org.omg.PortableInterceptor.Current JavaDoc;
40 import org.omg.PortableInterceptor.*;
41 //import org.omg.CORBA.ORBPackage.InvalidName;
42
import org.omg.PortableInterceptor.ORBInitInfoPackage.InvalidName JavaDoc;
43 import org.omg.PortableInterceptor.ORBInitInfoPackage.DuplicateName JavaDoc;
44
45 import com.sun.jts.CosTransactions.MinorCode;
46
47 /**
48  * This class implements the ORBInitializer for JTS. When an instance of this
49  * class is called during ORB initialization, it registers the IORInterceptors
50  * and the JTS request/reply interceptors with the ORB.
51  *
52  * @author Ram Jeyaraman 11/11/2000
53  * @version 1.0
54  */

55 public class ORBInitializerImpl extends LocalObject implements ORBInitializer {
56
57     public ORBInitializerImpl() {}
58
59     public void pre_init(ORBInitInfo info) {}
60
61     public void post_init(ORBInitInfo info) {
62
63         // get hold of the codec instance to pass onto interceptors.
64

65         CodecFactory codecFactory = info.codec_factory();
66         Encoding JavaDoc enc = new Encoding JavaDoc(
67                             ENCODING_CDR_ENCAPS.value, (byte) 1, (byte) 2);
68         Codec codec = null;
69         try {
70             codec = codecFactory.create_codec(enc);
71         } catch (UnknownEncoding JavaDoc e) {
72             throw new INTERNAL(MinorCode.TSCreateFailed,
73                                CompletionStatus.COMPLETED_NO);
74         }
75
76         // get hold of PICurrent to allocate a slot for JTS service.
77

78         Current JavaDoc pic = null;
79         try {
80             pic = (Current JavaDoc) info.resolve_initial_references("PICurrent");
81         } catch (InvalidName JavaDoc e) {
82             throw new INTERNAL(MinorCode.TSCreateFailed,
83                                CompletionStatus.COMPLETED_NO);
84         }
85
86         // allocate a PICurrent slotId for the transaction service.
87

88         int[] slotIds = new int[2];
89         try {
90             slotIds[0] = info.allocate_slot_id();
91             slotIds[1] = info.allocate_slot_id();
92         } catch (BAD_INV_ORDER e) {
93             throw new INTERNAL(MinorCode.TSCreateFailed,
94                                CompletionStatus.COMPLETED_NO);
95         }
96
97         // get hold of the TSIdentification instance to pass onto interceptors.
98

99         TSIdentification tsi = null;
100         try {
101             tsi = (TSIdentification)
102                     info.resolve_initial_references("TSIdentification");
103         } catch (InvalidName JavaDoc e) {
104             // the TransactionService is unavailable.
105
}
106
107         // register the policy factories.
108

109         try {
110             info.register_policy_factory(OTS_POLICY_TYPE.value,
111                                          new OTSPolicyFactory());
112         } catch (BAD_INV_ORDER e) {
113             // ignore, policy factory already exists.
114
}
115
116         try {
117             info.register_policy_factory(INVOCATION_POLICY_TYPE.value,
118                                          new InvocationPolicyFactory());
119         } catch (BAD_INV_ORDER e) {
120             // ignore, policy factory already exists.
121
}
122
123         // register the interceptors.
124

125         try {
126             info.add_ior_interceptor(new IORInterceptorImpl(codec));
127             InterceptorImpl interceptor =
128                 new InterceptorImpl(pic, codec, slotIds, tsi);
129             info.add_client_request_interceptor(interceptor);
130             info.add_server_request_interceptor(interceptor);
131         } catch (DuplicateName JavaDoc e) {
132             throw new INTERNAL(MinorCode.TSCreateFailed,
133                                CompletionStatus.COMPLETED_NO);
134         }
135     }
136 }
137
Popular Tags