KickJava   Java API By Example, From Geeks To Geeks.

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


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.Codec JavaDoc;
32 import org.omg.IOP.TaggedComponent JavaDoc;
33 import org.omg.IOP.CodecPackage.InvalidTypeForEncoding JavaDoc;
34
35 import org.omg.CORBA.ORB JavaDoc;
36 import org.omg.CORBA.Any JavaDoc;
37 import org.omg.CORBA.LocalObject JavaDoc;
38 import org.omg.CORBA.INV_POLICY JavaDoc;
39 import org.omg.CORBA.INTERNAL JavaDoc;
40
41 import org.omg.CosTransactions.*;
42
43 import org.omg.CosTSInteroperation.TAG_OTS_POLICY;
44 import org.omg.CosTSInteroperation.TAG_INV_POLICY;
45
46 import org.omg.PortableInterceptor.IORInfo JavaDoc;
47 import org.omg.PortableInterceptor.IORInterceptor JavaDoc;
48
49 /**
50  * This class implements the IORInterceptor for JTS. When an instance of this
51  * class is called by the ORB (during POA creation), it supplies appropriate
52  * IOR TaggedComponents for the OTSPolicy / InvocationPolicy associated
53  * with the POA, which will be used by the ORB while publishing IORs.
54  *
55  * @author Ram Jeyaraman 11/11/2000
56  * @version 1.0
57  */

58 public class IORInterceptorImpl extends LocalObject JavaDoc implements IORInterceptor JavaDoc {
59
60     // class attributes
61

62     private static final String JavaDoc name = "com.sun.jts.pi.IORInterceptor";
63
64     // Instance attributes
65

66     private Codec JavaDoc codec = null;
67
68     public IORInterceptorImpl(Codec JavaDoc codec) {
69         this.codec = codec;
70     }
71
72     // org.omg.PortableInterceptors.IORInterceptorOperations implementation
73

74     public void establish_components (IORInfo JavaDoc info) {
75
76         // get the OTSPolicy and InvocationPolicy objects
77

78         OTSPolicy otsPolicy = null;
79
80         try {
81             otsPolicy = (OTSPolicy)
82                 info.get_effective_policy(OTS_POLICY_TYPE.value);
83         } catch (INV_POLICY JavaDoc e) {
84             // ignore. This implies an policy was not explicitly set.
85
// A default value will be used instead.
86
}
87
88         InvocationPolicy invPolicy = null;
89         try {
90             invPolicy = (InvocationPolicy)
91                 info.get_effective_policy(INVOCATION_POLICY_TYPE.value);
92         } catch (INV_POLICY JavaDoc e) {
93             // ignore. This implies an policy was not explicitly set.
94
// A default value will be used instead.
95
}
96
97         // get OTSPolicyValue and InvocationPolicyValue from policy objects.
98

99         short otsPolicyValue = FORBIDS.value; // default value
100
short invPolicyValue = EITHER.value; // default value
101

102         if (otsPolicy != null) {
103             otsPolicyValue = otsPolicy.value();
104         }
105
106         if (invPolicy != null) {
107             invPolicyValue = invPolicy.value();
108         }
109
110         // use codec to encode policy value into an CDR encapsulation.
111

112         Any JavaDoc otsAny = ORB.init().create_any();
113         Any JavaDoc invAny = ORB.init().create_any();
114
115         otsAny.insert_short(otsPolicyValue);
116         invAny.insert_short(invPolicyValue);
117
118         byte[] otsCompValue = null;
119         byte[] invCompValue = null;
120         try {
121             otsCompValue = this.codec.encode_value(otsAny);
122             invCompValue = this.codec.encode_value(invAny);
123         } catch (InvalidTypeForEncoding JavaDoc e) {
124             throw new INTERNAL JavaDoc();
125         }
126
127         // create IOR TaggedComponents for OTSPolicy and InvocationPolicy.
128

129         TaggedComponent JavaDoc otsComp = new TaggedComponent JavaDoc(TAG_OTS_POLICY.value,
130                                                       otsCompValue);
131         TaggedComponent JavaDoc invComp = new TaggedComponent JavaDoc(TAG_INV_POLICY.value,
132                                                       invCompValue);
133
134         // add ior components.
135

136         info.add_ior_component(otsComp);
137         info.add_ior_component(invComp);
138     }
139
140     // org.omg.PortableInterceptors.InterceptorOperations implementation
141

142     public String JavaDoc name(){
143         return IORInterceptorImpl.name;
144     }
145
146     public void destroy() {}
147 }
148
149
150
Popular Tags