KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jacorb > test > orb > IIOPProfileInterceptor


1 package org.jacorb.test.orb;
2
3 import java.util.*;
4
5 import org.omg.CORBA.*;
6 import org.omg.IOP.*;
7 import org.omg.PortableInterceptor.IORInfo JavaDoc;
8 import org.omg.PortableInterceptor.IORInterceptor JavaDoc;
9
10 import org.jacorb.orb.IIOPAddress;
11 import org.jacorb.orb.portableInterceptor.IORInfoExt;
12 import org.jacorb.orb.iiop.IIOPProfile;
13
14 /**
15  * An IOR Interceptor that adds alternate addresses to IIOP Profiles,
16  * using the special JacORB mechanism via IORInfoExt.
17  *
18  * @author Marc Heide
19  * @version $Id: IIOPProfileInterceptor.java,v 1.1 2003/12/16 13:38:04 andre.spiegel Exp $
20  */

21 public class IIOPProfileInterceptor
22     extends LocalObject
23     implements IORInterceptor JavaDoc
24 {
25    public List alternateAddresses = IIOPAddressInterceptor.alternateAddresses;
26
27     public void establish_components(IORInfo JavaDoc info)
28     {
29        IORInfoExt infoExt = (IORInfoExt) info;
30        // ORB should have added already 1 profile with IOP tag
31
int nrOfProf = infoExt.get_number_of_profiles(TAG_INTERNET_IOP.value);
32        if( nrOfProf != 1 )
33        {
34           throw new RuntimeException JavaDoc ("unexpected number of IOP Profiles: " + nrOfProf);
35        }
36
37        IIOPProfile primaryProf = (IIOPProfile) infoExt.get_profile(TAG_INTERNET_IOP.value, 0);
38        try
39        {
40           IIOPProfile cloneOfPrimary = (IIOPProfile) primaryProf.clone();
41
42           // now add alternate addresses to primary profile
43
for (Iterator i = alternateAddresses.iterator(); i.hasNext();)
44           {
45              IIOPAddress addr = (IIOPAddress)i.next();
46              primaryProf.addComponent( TAG_ALTERNATE_IIOP_ADDRESS.value, addr.toCDR() );
47              System.out.println("adding alternate to primary");
48           }
49
50           // now add a secondary and third profile like used e.g. by Visibroker 4.5
51
for (Iterator i = alternateAddresses.iterator(); i.hasNext();)
52           {
53              IIOPAddress addr = (IIOPAddress)i.next();
54              IIOPProfile additionalProfile = (IIOPProfile) cloneOfPrimary.clone();
55              additionalProfile.patchPrimaryAddress(addr.getIP(), addr.getPort());
56              infoExt.add_profile(additionalProfile);
57           }
58        }
59        catch ( CloneNotSupportedException JavaDoc ex )
60        {
61           throw new RuntimeException JavaDoc ("Exception during cloning of profile: "
62                                       + ex);
63        }
64
65        nrOfProf = infoExt.get_number_of_profiles(TAG_INTERNET_IOP.value);
66        if( nrOfProf != 1 + alternateAddresses.size())
67        {
68           throw new RuntimeException JavaDoc ("unexpected number of IOP Profiles after addition: "
69                                       + nrOfProf
70                                       + ", where number of alternates was: "
71                                       + alternateAddresses.size());
72        }
73
74        // check access functions
75
primaryProf = (IIOPProfile) infoExt.get_profile(TAG_INTERNET_IOP.value, 0);
76        IIOPProfile primaryProf2 = (IIOPProfile) infoExt.get_profile(TAG_INTERNET_IOP.value);
77        // they should be equal to primary
78
if ( ! primaryProf.equals(primaryProf2) )
79        {
80           throw new RuntimeException JavaDoc ("difference between "
81                                       + "get_profile(tag, idx) and "
82                                       + "get_profile(tag): ");
83        }
84
85     }
86
87     public String JavaDoc name()
88     {
89       return "IIOPProfileInterceptor";
90     }
91
92     public void destroy()
93     {
94       alternateAddresses.clear();
95     }
96
97 }
98
Popular Tags