KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > rift > coad > lib > interceptor > iiop > InterceptorIntializer


1 /*
2  * CoadunationLib: The coaduntion implementation library.
3  * Copyright (C) 2006 Rift IT Contracting
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18  *
19  * InterceptorIntializer.java
20  *
21  * This class is responsible for initializing all the IIOP interceptors.
22  */

23
24 // package path
25
package com.rift.coad.lib.interceptor.iiop;
26
27 // imports
28
import java.util.StringTokenizer JavaDoc;
29 import org.omg.CORBA.LocalObject JavaDoc;
30 import org.omg.PortableInterceptor.ORBInitInfo JavaDoc;
31 import org.omg.PortableInterceptor.ORBInitializer JavaDoc;
32 import org.omg.PortableInterceptor.ClientRequestInterceptor JavaDoc;
33 import org.omg.PortableInterceptor.ServerRequestInterceptor JavaDoc;
34 import java.lang.reflect.Constructor JavaDoc;
35 import org.omg.IOP.Codec JavaDoc;
36 import org.omg.IOP.Encoding JavaDoc;
37 import org.omg.IOP.ENCODING_CDR_ENCAPS JavaDoc;
38
39 // coadunation imports
40
import com.rift.coad.lib.configuration.Configuration;
41 import com.rift.coad.lib.configuration.ConfigurationFactory;
42
43 /**
44  * This class is responsible for initializing all the IIOP interceptors.
45  *
46  * @author Brett Chaldecott
47  */

48 public class InterceptorIntializer extends LocalObject JavaDoc implements
49         ORBInitializer JavaDoc {
50     
51     // class constants
52
private static final String JavaDoc CLIENT_INTERCEPTORS = "client_interceptors";
53     private static final String JavaDoc SERVER_INTERCEPTORS = "server_interceptors";
54     
55     // local configuration
56
private Configuration config = null;
57     
58     /**
59      * Creates a new instance of InterceptorIntializer
60      *
61      * @exception SecurityInterceptorException
62      */

63     public InterceptorIntializer() throws SecurityInterceptorException {
64         try {
65             config = ConfigurationFactory.getInstance().getConfig(
66                     this.getClass());
67         } catch (Exception JavaDoc ex) {
68             throw new SecurityInterceptorException(
69                     "Failed to retrieve the configuration : " + ex.getMessage(),
70                     ex);
71         }
72     }
73     
74     
75     /**
76      * Called during ORB initialization.
77      *
78      * @param info The object to add the interceptors to
79      */

80     public void pre_init(ORBInitInfo JavaDoc info) {
81         
82     }
83     
84     
85     /**
86      * Called during ORB initialization.
87      *
88      * @param info The object to add the interceptors to
89      */

90     public void post_init(ORBInitInfo JavaDoc info) {
91         try {
92             StringTokenizer JavaDoc tokenizer = new StringTokenizer JavaDoc(config.getString(
93                     CLIENT_INTERCEPTORS),",");
94             while (tokenizer.hasMoreTokens()) {
95                 Class JavaDoc ref = Class.forName(tokenizer.nextToken().trim());
96                 System.out.println("Retrieve interceptor class : " +
97                         ref.getName());
98                 Constructor JavaDoc constructor = ref.getConstructor(
99                         ORBInitInfo JavaDoc.class);
100                 info.add_client_request_interceptor(
101                         (ClientRequestInterceptor JavaDoc)constructor.newInstance(info));
102                 
103             }
104             tokenizer = new StringTokenizer JavaDoc(config.getString(
105                     SERVER_INTERCEPTORS),",");
106             while (tokenizer.hasMoreTokens()) {
107                 Class JavaDoc ref = Class.forName(tokenizer.nextToken().trim());
108                 System.out.println("Retrieve interceptor class : " +
109                         ref.getName());
110                 Constructor JavaDoc constructor = ref.getConstructor(
111                         ORBInitInfo JavaDoc.class);
112                 info.add_server_request_interceptor(
113                         (ServerRequestInterceptor JavaDoc)constructor.newInstance(info));
114                 System.out.println("Add interceptor : " + ref.getName());
115             }
116             
117             // add in the ior interceptor
118
Encoding JavaDoc encoding = new Encoding JavaDoc(ENCODING_CDR_ENCAPS.value,
119                     (byte)1,/* GIOP version */
120                     (byte)2 /* GIOP version */);
121             Codec JavaDoc codec = info.codec_factory().create_codec(encoding);
122             info.add_ior_interceptor(new CodebaseIORInterceptor(codec));
123         } catch (Exception JavaDoc ex) {
124             System.out.println("Failed to initialize the interceptor");
125             ex.printStackTrace(System.out);
126             throw new SecurityInterceptorException(
127                     "Failed to init the interceptors : " + ex.getMessage(),ex);
128         }
129     }
130     
131     
132     
133     
134 }
135
Popular Tags