51 * The default port is 9999. The default version is "1.0"
52 * US-ASCII alphanumeric characters are not escaped. Any characters outside
53 * of this range are escaped except for the following:
54 * ; / : ? : @ & = + $ , - _ . ! ~ * ' ( )
55 * Escaped characters is escaped by using a % followed by its 2 hexadecimal
56 * numbers representing the octet.
57 *
58 * For backward compatibility, the "iiop" URL as defined in INS 97-6-6
59 * is also supported:
60 *
61 * iiop url = "iiop://" [host [":" port]] ["/" string_name]
62 * The default port is 900.
63 *
64 * @author Rosanna Lee
65 */
66
67 public final class IiopUrl {
68 static final private int DEFAULT_IIOPNAME_PORT = 9999;
69 static final private int DEFAULT_IIOP_PORT = 900;
70 static final private String DEFAULT_HOST = "localhost";
71 private Vector addresses;
72 private String stringName;
73
74 public static class Address {
75 public int port = -1;
76 public int major, minor;
77 public String host;
78
79 public Address(String hostPortVers, boolean oldFormat)
80 throws MalformedURLException {
81 // [version host [":" port]]
82 int start;
83
84 // Parse version
85 int at;
86 if (oldFormat || (at = hostPortVers.indexOf('@')) < 0) {
87 major = 1;
88 minor = 0;
89 start = 0; // start at the beginning
90 } else {
91 int dot = hostPortVers.indexOf('.');
132 if ( hostPortVers.startsWith(":", start)) { // parse port
133 start++; // skip past ":"
134 port = Integer.parseInt(hostPortVers.
135 substring(start, slash));
136 } else {
137 throw new IllegalArgumentException(
138 "IiopURL: name is an Invalid URL: " + hostPortVers);
139 }
140 }
141 start = slash;
142 if ("".equals(host) || host == null) {
143 host = DEFAULT_HOST ;
144 }
145 if (port == -1) {
146 port = (oldFormat ? DEFAULT_IIOP_PORT :
147 DEFAULT_IIOPNAME_PORT);
148 }
149 }
150 }
151
152 public Vector getAddresses() {
153 return addresses;
154 }
155
156 /**
157 * Returns a possibly empty but non-null string that is the "string_name"
158 * portion of the URL.
159 */
160 public String getStringName() {
161 return stringName;
162 }
163
164 public Name getCosName() throws NamingException {
165 return CNCtx.parser.parse(stringName);
166 }
167
168 public IiopUrl(String url) throws MalformedURLException {
169 int addrStart;
170 boolean oldFormat;
171
172 if (url.startsWith("iiopname://")) {
173 oldFormat = false;
174 addrStart = 11;
175 } else if (url.startsWith("iiop://")) {
176 oldFormat = true;
177 addrStart = 7;
178 } else {
179 throw new MalformedURLException("Invalid iiop/iiopname URL: " + url);
180 }
181 int addrEnd = url.indexOf('/', addrStart);
182 if (addrEnd < 0) {
183 addrEnd = url.length();
184 stringName = "";
185 } else {
186 stringName = UrlUtil.decode(url.substring(addrEnd+1));
187 }
188 addresses = new Vector(3);
189 if (oldFormat) {
190 // Only one host:port part, not multiple
191 addresses.addElement(
192 new Address(url.substring(addrStart, addrEnd), oldFormat));
193 } else {
194 StringTokenizer tokens =
195 new StringTokenizer(url.substring(addrStart, addrEnd), ",");
196 while (tokens.hasMoreTokens()) {
197 addresses.addElement(new Address(tokens.nextToken(), oldFormat));
198 }
199 if (addresses.size() == 0) {
200 addresses.addElement(new Address("", oldFormat));
201 }
202 }
203 }
204
205 // for testing only
206 /*public static void main(String[] args) {
207 try {
208 IiopUrl url = new IiopUrl(args[0]);
|
51 * The default port is 9999. The default version is "1.0"
52 * US-ASCII alphanumeric characters are not escaped. Any characters outside
53 * of this range are escaped except for the following:
54 * ; / : ? : @ & = + $ , - _ . ! ~ * ' ( )
55 * Escaped characters is escaped by using a % followed by its 2 hexadecimal
56 * numbers representing the octet.
57 *
58 * For backward compatibility, the "iiop" URL as defined in INS 97-6-6
59 * is also supported:
60 *
61 * iiop url = "iiop://" [host [":" port]] ["/" string_name]
62 * The default port is 900.
63 *
64 * @author Rosanna Lee
65 */
66
67 public final class IiopUrl {
68 static final private int DEFAULT_IIOPNAME_PORT = 9999;
69 static final private int DEFAULT_IIOP_PORT = 900;
70 static final private String DEFAULT_HOST = "localhost";
71 private Vector<Address> addresses;
72 private String stringName;
73
74 public static class Address {
75 public int port = -1;
76 public int major, minor;
77 public String host;
78
79 public Address(String hostPortVers, boolean oldFormat)
80 throws MalformedURLException {
81 // [version host [":" port]]
82 int start;
83
84 // Parse version
85 int at;
86 if (oldFormat || (at = hostPortVers.indexOf('@')) < 0) {
87 major = 1;
88 minor = 0;
89 start = 0; // start at the beginning
90 } else {
91 int dot = hostPortVers.indexOf('.');
132 if ( hostPortVers.startsWith(":", start)) { // parse port
133 start++; // skip past ":"
134 port = Integer.parseInt(hostPortVers.
135 substring(start, slash));
136 } else {
137 throw new IllegalArgumentException(
138 "IiopURL: name is an Invalid URL: " + hostPortVers);
139 }
140 }
141 start = slash;
142 if ("".equals(host) || host == null) {
143 host = DEFAULT_HOST ;
144 }
145 if (port == -1) {
146 port = (oldFormat ? DEFAULT_IIOP_PORT :
147 DEFAULT_IIOPNAME_PORT);
148 }
149 }
150 }
151
152 public Vector<Address> getAddresses() {
153 return addresses;
154 }
155
156 /**
157 * Returns a possibly empty but non-null string that is the "string_name"
158 * portion of the URL.
159 */
160 public String getStringName() {
161 return stringName;
162 }
163
164 public Name getCosName() throws NamingException {
165 return CNCtx.parser.parse(stringName);
166 }
167
168 public IiopUrl(String url) throws MalformedURLException {
169 int addrStart;
170 boolean oldFormat;
171
172 if (url.startsWith("iiopname://")) {
173 oldFormat = false;
174 addrStart = 11;
175 } else if (url.startsWith("iiop://")) {
176 oldFormat = true;
177 addrStart = 7;
178 } else {
179 throw new MalformedURLException("Invalid iiop/iiopname URL: " + url);
180 }
181 int addrEnd = url.indexOf('/', addrStart);
182 if (addrEnd < 0) {
183 addrEnd = url.length();
184 stringName = "";
185 } else {
186 stringName = UrlUtil.decode(url.substring(addrEnd+1));
187 }
188 addresses = new Vector<>(3);
189 if (oldFormat) {
190 // Only one host:port part, not multiple
191 addresses.addElement(
192 new Address(url.substring(addrStart, addrEnd), oldFormat));
193 } else {
194 StringTokenizer tokens =
195 new StringTokenizer(url.substring(addrStart, addrEnd), ",");
196 while (tokens.hasMoreTokens()) {
197 addresses.addElement(new Address(tokens.nextToken(), oldFormat));
198 }
199 if (addresses.size() == 0) {
200 addresses.addElement(new Address("", oldFormat));
201 }
202 }
203 }
204
205 // for testing only
206 /*public static void main(String[] args) {
207 try {
208 IiopUrl url = new IiopUrl(args[0]);
|