/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright (c) 1999 by Sun Microsystems, Inc.
* All rights reserved.
*
*/
// ServiceURL.java : The service URL.
// Author: James Kempf, Erik Guttman
//
/**
* The ServiceURL object models the SLP service URL. Both service: URLs
* and regular URLs are handled by this class.
*
* @author James Kempf, Erik Guttman
*/
// Recognized transports.
/**
* Indicates that no port information is required or was returned
* for this service URL.
*/
/**
* No life time parameter is given.
*/
/**
* Default lifetime, 3 hours.
*/
/**
* Maximum lifetime, approximately 18 hours.
*/
/**
* Reregister periodically.
*/
// Maximum port size.
//
// data fields
//
private boolean isPermanent = false;
private boolean noDoubleSlash = false;
/**
* Construct a service URL object.
*
* @param URL The service URL as a string.
* @param iLifetime The service advertisement lifetime.
* @exception IllegalArgumentException Thrown if parse
* errors occur in the
* parameter.
*/
throws IllegalArgumentException {
if ((iLifetime > LIFETIME_MAXIMUM) ||
(iLifetime < LIFETIME_PERMANENT)) {
throw
new Object[0]));
}
if (iLifetime == LIFETIME_PERMANENT) {
isPermanent = true;
}
}
//
// ------------------------------------------------------------------
// Accessors
// ------------------------------------------------------------------
//
/**
* @return The service type name.
*/
return serviceType;
}
/**
* Set service type and naming authority if this is not a service: URL.
*
* @param type The new ServiceType object.
* @exception IllegalArgumentException If the service type name or
* naming authority name is invalid.
*/
if (!serviceType.isServiceURL()) {
serviceType = type;
}
}
/**
* @return The machine name or IP address.
*/
return host;
}
/**
* @return The port number, if any.
*/
public int getPort() {
return port;
}
/**
* @return The URL path description, if any.
*/
return URLPath;
}
/**
* @return The service advertisement lifetime.
*/
public int getLifetime() {
return lifetime;
}
/**
* Formats the service URL into standard URL form.
*
* @return Formatted string with the service URL.
*/
return
}
public int hashCode() {
return
serviceType.hashCode() +
port +
}
if (obj == this) {
return true;
}
if (!(obj instanceof ServiceURL)) {
return false;
}
return
}
// Return permanent status.
boolean getIsPermanent() {
return isPermanent;
}
// Check URL characters for correctness.
throws IllegalArgumentException {
for (int i = 0; i < s.length(); i++) {
char c = s.charAt(i);
// allowed by RFC1738
if (c == '/' || c == ':' || c == '-' || c == ':' ||
c == '.' || c == '%' || c == '_' || c == '\'' ||
c == '*' || c == '(' || c == ')' || c == '$' ||
c == '!' || c == ',' || c == '+' || c == '\\') {
// defer to Windows
continue;
}
// reserved by RFC1738, and thus allowed, pg. 20
if (c == ';' || c == '@' || c == '?' || c == '&' || c == '=') {
continue;
}
if (Character.isLetterOrDigit(c)) {
continue;
}
throw
new Object[] {
new Character(c)}));
}
}
// Parse the incoming service URL specification.
throws IllegalArgumentException {
try {
// This loop is a kludgy way to break out of the parse so
// we only throw at one location in the code.
do {
// First token must be service type name.
break; // error!
}
// Check for colon terminator, not part of service
// type name.
break; // error!
}
// Create service type, remove trailing colon.
// Separator between service type name and transport.
break; // error!
}
// Check for abstract type or alternate transport.
// If this is an abstract type, then we could have
// This is OK. Also, if this is a non-service: URL,
if (!serviceType.isServiceURL()) {
noDoubleSlash = true;
} else {
// We only recognize IPX and Appletalk at this point.
// Abstract type is OK. We must check here because
// something like
// is allowed.
if (serviceType.isAbstractType()) {
noDoubleSlash = true;
} else {
break; // error!
}
} else {
// Check for separator between transport and host.
break; // error!
}
}
}
} else {
// Not abstract type, no alternate transport. Get host.
}
return; // we're done!
}
// Need to check for port number if this is an IP transport.
// Get port if any.
if (tk.hasMoreTokens()) {
if (tk.hasMoreTokens()) {
break; // error!
}
try {
} catch (NumberFormatException ex) {
break; // error!
}
break; // error!
}
}
}
//
// after this point we have to check if there is a token
// remaining before we read it: It is legal to stop at any
// point now. Before all the tokens were required, so
// missing any was an error.
//
if (st.hasMoreTokens() == false) {
// minimal url service:t:// a
return; // we're done!
}
break; // error!
}
// there is a URL path
// URLPath is all remaining tokens
if (st.hasMoreTokens()) {
}
return; // done!
} while (false); // done with parse.
} catch (NoSuchElementException ex) {
throw
}
// The only way to get here is if there was an error in the
// parse.
throw
}
}