KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > corba > se > impl > transport > DefaultIORToSocketInfoImpl


1 /*
2  * @(#)DefaultIORToSocketInfoImpl.java 1.4 04/07/26
3  *
4  * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
5  * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
6  */

7
8 package com.sun.corba.se.impl.transport;
9
10 import java.util.ArrayList JavaDoc;
11 import java.util.Iterator JavaDoc;
12 import java.util.List JavaDoc;
13
14 import org.omg.IOP.TAG_ALTERNATE_IIOP_ADDRESS JavaDoc ;
15
16 import com.sun.corba.se.spi.ior.IOR;
17 import com.sun.corba.se.spi.ior.ObjectKeyTemplate;
18 import com.sun.corba.se.spi.ior.iiop.IIOPProfile ;
19 import com.sun.corba.se.spi.ior.iiop.IIOPProfileTemplate ;
20 import com.sun.corba.se.spi.ior.iiop.IIOPAddress ;
21 import com.sun.corba.se.spi.ior.iiop.AlternateIIOPAddressComponent;
22 import com.sun.corba.se.spi.transport.IORToSocketInfo;
23 import com.sun.corba.se.spi.transport.SocketInfo;
24
25 public class DefaultIORToSocketInfoImpl
26     implements IORToSocketInfo
27 {
28     public List JavaDoc getSocketInfo(IOR ior)
29     {
30     SocketInfo socketInfo;
31     List JavaDoc result = new ArrayList JavaDoc();
32
33     IIOPProfileTemplate iiopProfileTemplate = (IIOPProfileTemplate)
34         ior.getProfile().getTaggedProfileTemplate() ;
35     IIOPAddress primary = iiopProfileTemplate.getPrimaryAddress() ;
36     String JavaDoc hostname = primary.getHost().toLowerCase();
37     int port = primary.getPort();
38     // NOTE: we could check for 0 (i.e., CSIv2) but, for a
39
// non-CSIv2-configured client ORB talking to a CSIv2 configured
40
// server ORB you might end up with an empty contact info list
41
// which would then report a failure which would not be as
42
// instructive as leaving a ContactInfo with a 0 port in the list.
43
socketInfo = createSocketInfo(hostname, port);
44     result.add(socketInfo);
45
46     Iterator JavaDoc iterator = iiopProfileTemplate.iteratorById(
47             TAG_ALTERNATE_IIOP_ADDRESS.value);
48
49     while (iterator.hasNext()) {
50         AlternateIIOPAddressComponent alternate =
51         (AlternateIIOPAddressComponent) iterator.next();
52         hostname = alternate.getAddress().getHost().toLowerCase();
53         port = alternate.getAddress().getPort();
54         socketInfo= createSocketInfo(hostname, port);
55         result.add(socketInfo);
56     }
57     return result;
58     }
59
60     private SocketInfo createSocketInfo(final String JavaDoc hostname, final int port)
61     {
62     return new SocketInfo() {
63         public String JavaDoc getType() { return SocketInfo.IIOP_CLEAR_TEXT; }
64         public String JavaDoc getHost() { return hostname; }
65         public int getPort() { return port; }};
66     }
67 }
68
69 // End of file.
70
Popular Tags