1 18 package org.apache.geronimo.interop.rmi.iiop.client; 19 20 import java.net.URL ; 21 import java.util.ArrayList ; 22 import java.util.Iterator ; 23 import java.util.List ; 24 25 import org.apache.geronimo.interop.SystemException; 26 import org.apache.geronimo.interop.properties.PropertyMap; 27 import org.apache.geronimo.interop.rmi.iiop.Protocol; 28 import org.apache.geronimo.interop.util.ListUtil; 29 import org.apache.geronimo.interop.util.NamedValueList; 30 import org.apache.geronimo.interop.util.StringUtil; 31 32 public class UrlInfo { 33 34 private String namePrefix = ""; 35 private int ver; 36 37 final static int IIOP_1_0 = 0; 38 final static int IIOP_1_1 = 1; 39 final static int IIOP_1_2 = 2; 40 41 public static UrlInfo getInstance(String url) { 42 UrlInfo object = new UrlInfo(); 43 object.init(url); 44 return object; 45 } 46 47 public static List getList(String urls) { 48 ArrayList list = new ArrayList (3); 49 for (Iterator i = ListUtil.getCommaSeparatedList(urls).iterator(); i.hasNext();) { 50 String url = (String ) i.next(); 51 list.add(getInstance(url)); 52 } 53 return list; 54 } 55 56 private int protocol; 57 58 private String host; 59 60 private int port; 61 62 private String objectKey; 63 64 private PropertyMap properties; 65 66 private boolean handleUrl(String url) 67 { 68 if(!UrlScheme.canProcess(url)) 69 return false; 70 71 UrlScheme us = new UrlScheme(url); 72 us.process(); 73 74 host = us.getHost(0); 75 port = us.getPort(0); 76 ver = us.getVersion(0); 77 objectKey = us.getObjectKey(); 78 namePrefix = us.getNamePrefix(); 79 properties = new PropertyMap(); 80 protocol = Protocol.IIOP; 81 82 return true; 83 } 84 85 protected void init(String urlString) 86 { 87 if(handleUrl(urlString)) 88 { 89 return; 90 } 91 92 int cssPos = urlString.indexOf("://"); 93 if (cssPos == -1) { 94 throw new IllegalArgumentException (urlString); 95 } 96 protocol = Protocol.getNumber(urlString.substring(0, cssPos)); 97 try { 98 URL url = new URL ("http" + urlString.substring(cssPos)); 99 host = url.getHost(); 100 port = url.getPort(); 101 if (port == -1) { 102 switch (protocol) { 103 case Protocol.HTTP: 104 port = 80; break; 106 case Protocol.HTTPS: 107 port = 443; break; 109 case Protocol.IIOP: 110 port = 683; break; 112 case Protocol.IIOPS: 113 port = 684; break; 115 default: 116 throw new IllegalStateException ("url = " + urlString); 117 } 118 } 119 objectKey = url.getFile(); 120 if (objectKey == null) { 121 objectKey = ""; 122 } 123 int queryPos = objectKey.indexOf('?'); 124 if (queryPos != -1) { 125 objectKey = objectKey.substring(0, queryPos); 126 } 127 objectKey = StringUtil.removePrefix(objectKey, "/"); 128 if (objectKey.length() == 0) { 129 objectKey = "NameService"; 130 } 131 String query = url.getQuery(); 132 if (query == null) { 133 query = ""; 134 } 135 String props = StringUtil.removePrefix(query, "?").replace('&', ','); 136 properties = new NamedValueList(props).getProperties(); 137 } catch (Exception ex) { 138 throw new SystemException(ex); 139 } 140 } 141 142 public int getProtocol() { 143 return protocol; 144 } 145 146 public String getHost() { 147 return host; 148 } 149 150 public int getPort() { 151 return port; 152 } 153 154 public String getObjectKey() { 155 return objectKey; 156 } 157 158 public PropertyMap getProperties() { 159 return properties; 160 } 161 162 public String getNamePrefix() 163 { 164 return namePrefix; 165 } 166 167 public int getVersion() 168 { 169 return ver; 170 } 171 172 public String toString() { 173 return Protocol.getName(protocol) + "://" + host + ":" + port + "/" + objectKey; 174 } 175 } 176 | Popular Tags |