KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > iiop > RequestDispatchInfoInterceptor


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 package com.sun.enterprise.iiop;
25
26 import org.omg.CORBA.Any JavaDoc;
27 import org.omg.CORBA.ORB JavaDoc;
28 import org.omg.CORBA.INV_POLICY JavaDoc;
29 import org.omg.CORBA.INTERNAL JavaDoc;
30 import org.omg.IOP.Codec JavaDoc;
31 import org.omg.IOP.Encoding JavaDoc;
32 import org.omg.IOP.TaggedComponent JavaDoc;
33 import org.omg.PortableInterceptor.IORInfo JavaDoc;
34
35 import com.sun.corba.ee.impl.util.SUNVMCID;
36 import com.sun.corba.ee.spi.legacy.connection.ORBSocketFactory;
37 import com.sun.corba.ee.spi.legacy.interceptor.IORInfoExt;
38 import com.sun.corba.ee.impl.interceptors.IORInfoImpl;
39
40 import java.util.logging.*;
41 import com.sun.logging.*;
42
43 public class RequestDispatchInfoInterceptor extends org.omg.CORBA.LocalObject JavaDoc
44                     implements org.omg.PortableInterceptor.IORInterceptor JavaDoc{
45     
46     public static final int TAG_REQUEST_DISPATCH_INFO_ID = SUNVMCID.value + 30;
47
48     public static final String JavaDoc baseMsg = RequestDispatchInfoInterceptor.class.getName();
49     private static Logger _logger=null;
50     static {
51        _logger=LogDomains.getLogger(LogDomains.CORBA_LOGGER);
52     }
53     
54     private Codec JavaDoc codec;
55     
56     
57     /** Creates a new instance of RequestDispatchInfoInterceptor */
58     public RequestDispatchInfoInterceptor(Codec JavaDoc c) {
59         codec = c;
60     }
61     
62    
63     /**
64      * Provides an opportunity to destroy this interceptor.
65      * The destroy method is called during <code>ORB.destroy</code>. When an
66      * application calls <code>ORB.destroy</code>, the ORB:
67      * <ol>
68      * <li>waits for all requests in progress to complete</li>
69      * <li>calls the <code>Interceptor.destroy</code> operation for each
70      * interceptor</li>
71      * <li>completes destruction of the ORB</li>
72      * </ol>
73      * Method invocations from within <code>Interceptor.destroy</code> on
74      * object references for objects implemented on the ORB being destroyed
75      * result in undefined behavior. However, method invocations on objects
76      * implemented on an ORB other than the one being destroyed are
77      * permitted. (This means that the ORB being destroyed is still capable
78      * of acting as a client, but not as a server.)
79      */

80     public void destroy() {
81     }
82     
83     /**
84      * A server side ORB calls the <code>establish_components</code>
85      * operation on all registered <code>IORInterceptor</code> instances
86      * when it is assembling the list of components that will be included
87      * in the profile or profiles of an object reference. This operation
88      * is not necessarily called for each individual object reference.
89      * For example, the POA specifies policies at POA granularity and
90      * therefore, this operation might be called once per POA rather than
91      * once per object. In any case, <code>establish_components</code> is
92      * guaranteed to be called at least once for each distinct set of
93      * server policies.
94      * <p>
95      * An implementation of <code>establish_components</code> must not
96      * throw exceptions. If it does, the ORB shall ignore the exception
97      * and proceed to call the next IOR Interceptor's
98      * <code>establish_components</code> operation.
99      *
100      * @param info The <code>IORInfo</code> instance used by the ORB
101      * service to query applicable policies and add components to be
102      * included in the generated IORs.
103      */

104     public void establish_components(org.omg.PortableInterceptor.IORInfo JavaDoc iorInfo) {
105         try {
106         RequestDispatchPolicy rdPolicy = null;
107         try {
108         rdPolicy = (RequestDispatchPolicy)iorInfo.get_effective_policy(
109                POARemoteReferenceFactory.REQUEST_DISPATCH_POLICY_TYPE);
110         } catch ( INV_POLICY JavaDoc ex ) {return;}
111
112         if ( rdPolicy != null ) {
113         addDispatchInfoComponent(rdPolicy, iorInfo);
114         }
115         } catch (Exception JavaDoc e) {
116             _logger.log(Level.WARNING,"Exception in " + baseMsg, e);
117         }
118     }
119     
120     /**
121      * Returns the name of the interceptor.
122      * <p>
123      * Each Interceptor may have a name that may be used administratively
124      * to order the lists of Interceptors. Only one Interceptor of a given
125      * name can be registered with the ORB for each Interceptor type. An
126      * Interceptor may be anonymous, i.e., have an empty string as the name
127      * attribute. Any number of anonymous Interceptors may be registered with
128      * the ORB.
129      *
130      * @return the name of the interceptor.
131      */

132     public String JavaDoc name() {
133         return baseMsg;
134     }
135
136     
137     private void addDispatchInfoComponent(RequestDispatchPolicy policy,
138         org.omg.PortableInterceptor.IORInfo JavaDoc iorInfo)
139     {
140         Any JavaDoc any = ORB.init().create_any();
141     any.insert_long(policy.getDispatchId());
142
143     byte[] dispatchValue = null;
144         try {
145         dispatchValue = codec.encode_value(any);
146         } catch (org.omg.IOP.CodecPackage.InvalidTypeForEncoding JavaDoc e) {
147             throw new INTERNAL JavaDoc("InvalidTypeForEncoding "+e.getMessage());
148         }
149     TaggedComponent JavaDoc taggedComponent = new TaggedComponent JavaDoc(
150                         TAG_REQUEST_DISPATCH_INFO_ID,
151                         dispatchValue);
152     iorInfo.add_ior_component(taggedComponent);
153     }
154
155 }
156
Popular Tags