Thu, 31 Aug 2017 18:10:36 +0800
merge
1 /*
2 * Copyright (c) 2004, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
26 package com.sun.corba.se.impl.transport;
28 import java.util.ArrayList;
29 import java.util.Iterator;
30 import java.util.List;
32 import org.omg.IOP.TAG_ALTERNATE_IIOP_ADDRESS ;
34 import com.sun.corba.se.spi.ior.IOR;
35 import com.sun.corba.se.spi.ior.ObjectKeyTemplate;
36 import com.sun.corba.se.spi.ior.iiop.IIOPProfile ;
37 import com.sun.corba.se.spi.ior.iiop.IIOPProfileTemplate ;
38 import com.sun.corba.se.spi.ior.iiop.IIOPAddress ;
39 import com.sun.corba.se.spi.ior.iiop.AlternateIIOPAddressComponent;
40 import com.sun.corba.se.spi.transport.IORToSocketInfo;
41 import com.sun.corba.se.spi.transport.SocketInfo;
43 public class DefaultIORToSocketInfoImpl
44 implements IORToSocketInfo
45 {
46 public List getSocketInfo(IOR ior)
47 {
48 SocketInfo socketInfo;
49 List result = new ArrayList();
51 IIOPProfileTemplate iiopProfileTemplate = (IIOPProfileTemplate)
52 ior.getProfile().getTaggedProfileTemplate() ;
53 IIOPAddress primary = iiopProfileTemplate.getPrimaryAddress() ;
54 String hostname = primary.getHost().toLowerCase();
55 int port = primary.getPort();
56 // NOTE: we could check for 0 (i.e., CSIv2) but, for a
57 // non-CSIv2-configured client ORB talking to a CSIv2 configured
58 // server ORB you might end up with an empty contact info list
59 // which would then report a failure which would not be as
60 // instructive as leaving a ContactInfo with a 0 port in the list.
61 socketInfo = createSocketInfo(hostname, port);
62 result.add(socketInfo);
64 Iterator iterator = iiopProfileTemplate.iteratorById(
65 TAG_ALTERNATE_IIOP_ADDRESS.value);
67 while (iterator.hasNext()) {
68 AlternateIIOPAddressComponent alternate =
69 (AlternateIIOPAddressComponent) iterator.next();
70 hostname = alternate.getAddress().getHost().toLowerCase();
71 port = alternate.getAddress().getPort();
72 socketInfo= createSocketInfo(hostname, port);
73 result.add(socketInfo);
74 }
75 return result;
76 }
78 private SocketInfo createSocketInfo(final String hostname, final int port)
79 {
80 return new SocketInfo() {
81 public String getType() { return SocketInfo.IIOP_CLEAR_TEXT; }
82 public String getHost() { return hostname; }
83 public int getPort() { return port; }};
84 }
85 }
87 // End of file.