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 ; 8 import org.omg.PortableInterceptor.IORInterceptor ; 9 10 import org.jacorb.orb.IIOPAddress; 11 import org.jacorb.orb.portableInterceptor.IORInfoExt; 12 import org.jacorb.orb.iiop.IIOPProfile; 13 14 21 public class IIOPProfileInterceptor 22 extends LocalObject 23 implements IORInterceptor 24 { 25 public List alternateAddresses = IIOPAddressInterceptor.alternateAddresses; 26 27 public void establish_components(IORInfo info) 28 { 29 IORInfoExt infoExt = (IORInfoExt) info; 30 int nrOfProf = infoExt.get_number_of_profiles(TAG_INTERNET_IOP.value); 32 if( nrOfProf != 1 ) 33 { 34 throw new RuntimeException ("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 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 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 ex ) 60 { 61 throw new RuntimeException ("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 ("unexpected number of IOP Profiles after addition: " 69 + nrOfProf 70 + ", where number of alternates was: " 71 + alternateAddresses.size()); 72 } 73 74 primaryProf = (IIOPProfile) infoExt.get_profile(TAG_INTERNET_IOP.value, 0); 76 IIOPProfile primaryProf2 = (IIOPProfile) infoExt.get_profile(TAG_INTERNET_IOP.value); 77 if ( ! primaryProf.equals(primaryProf2) ) 79 { 80 throw new RuntimeException ("difference between " 81 + "get_profile(tag, idx) and " 82 + "get_profile(tag): "); 83 } 84 85 } 86 87 public String name() 88 { 89 return "IIOPProfileInterceptor"; 90 } 91 92 public void destroy() 93 { 94 alternateAddresses.clear(); 95 } 96 97 } 98 | Popular Tags |