KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > iiop > codebase > CodebaseInterceptor


1 /*
2 * JBoss, Home of Professional Open Source
3 * Copyright 2005, JBoss Inc., and individual contributors as indicated
4 * by the @authors tag. See the copyright.txt in the distribution for a
5 * full listing of individual contributors.
6 *
7 * This is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU Lesser General Public License as
9 * published by the Free Software Foundation; either version 2.1 of
10 * the License, or (at your option) any later version.
11 *
12 * This software is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this software; if not, write to the Free
19 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20 * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21 */

22 package org.jboss.iiop.codebase;
23
24 import org.omg.CORBA.Any JavaDoc;
25 import org.omg.CORBA.LocalObject JavaDoc;
26 import org.omg.CORBA.ORB JavaDoc;
27 import org.omg.IOP.Codec JavaDoc;
28 import org.omg.IOP.CodecPackage.InvalidTypeForEncoding JavaDoc;
29 import org.omg.IOP.TAG_JAVA_CODEBASE JavaDoc;
30 import org.omg.IOP.TaggedComponent JavaDoc;
31 import org.omg.PortableInterceptor.IORInfo JavaDoc;
32 import org.omg.PortableInterceptor.IORInterceptor JavaDoc;
33
34 /**
35  * Implements an <code>org.omg.PortableInterceptor.IORInterceptor</code>
36  * that adds a Java codebase component to an IOR.
37  *
38  * @author <a HREF="mailto:reverbel@ime.usp.br">Francisco Reverbel</a>
39  * @version $Revision: 37459 $
40  */

41 public class CodebaseInterceptor
42       extends LocalObject JavaDoc
43       implements IORInterceptor JavaDoc
44 {
45    private Codec JavaDoc codec;
46
47    public CodebaseInterceptor(Codec JavaDoc codec)
48    {
49       this.codec = codec;
50    }
51
52    // org.omg.PortableInterceptor.IORInterceptor operations -------------------
53

54    public String JavaDoc name()
55    {
56       return CodebaseInterceptor.class.getName();
57    }
58
59    public void destroy()
60    {
61    }
62
63    public void establish_components(IORInfo JavaDoc info)
64    {
65       // Get CodebasePolicy object
66
CodebasePolicy codebasePolicy=
67          (CodebasePolicy)info.get_effective_policy(CodebasePolicy.TYPE);
68
69       if (codebasePolicy != null) {
70          // Get codebase string from CodebasePolicy
71
String JavaDoc codebase = codebasePolicy.getCodebase();
72          
73          // Encapsulate codebase string into TaggedComponent
74
Any JavaDoc any = ORB.init().create_any();
75          any.insert_string(codebase);
76          byte[] taggedComponentData;
77          try {
78             taggedComponentData = codec.encode_value(any);
79          }
80          catch (InvalidTypeForEncoding JavaDoc e) {
81             throw new RuntimeException JavaDoc("Exception establishing " +
82                                        "Java codebase component:" + e);
83          }
84          info.add_ior_component(new TaggedComponent JavaDoc(TAG_JAVA_CODEBASE.value,
85                                                     taggedComponentData));
86       }
87    }
88    
89 }
90
Popular Tags