DefaultIORToSocketInfoImpl.java revision 608:7e06bf1dcb09
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 */ 25 26package com.sun.corba.se.impl.transport; 27 28import java.util.ArrayList; 29import java.util.Iterator; 30import java.util.List; 31 32import org.omg.IOP.TAG_ALTERNATE_IIOP_ADDRESS ; 33 34import com.sun.corba.se.spi.ior.IOR; 35import com.sun.corba.se.spi.ior.ObjectKeyTemplate; 36import com.sun.corba.se.spi.ior.iiop.IIOPProfile ; 37import com.sun.corba.se.spi.ior.iiop.IIOPProfileTemplate ; 38import com.sun.corba.se.spi.ior.iiop.IIOPAddress ; 39import com.sun.corba.se.spi.ior.iiop.AlternateIIOPAddressComponent; 40import com.sun.corba.se.spi.transport.IORToSocketInfo; 41import com.sun.corba.se.spi.transport.SocketInfo; 42 43public class DefaultIORToSocketInfoImpl 44 implements IORToSocketInfo 45{ 46 public List getSocketInfo(IOR ior) 47 { 48 SocketInfo socketInfo; 49 List result = new ArrayList(); 50 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); 63 64 Iterator iterator = iiopProfileTemplate.iteratorById( 65 TAG_ALTERNATE_IIOP_ADDRESS.value); 66 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 } 77 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} 86 87// End of file. 88