/*
* 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.
*
*/
// SLPTemplateRegistry.java: Service object for registering a new service
// template.
// Author: James Kempf
// Created On: Tue May 27 15:04:35 1997
// Last Modified By: James Kempf
// Last Modified On: Thu Jan 7 14:25:20 1999
// Update Count: 134
//
/**
* The SLPTemplateRegistry class registers and unregisters service templates,
* looks up the template based on the service type name, and returns an
* attribute verifier for the service.It subclasses the TemplateRegistry
* abstract class.
*
* An slp-template URL has the following format:
*
* service:slp-template:<document URL>;type=<service type>;
* version=<version no.>;
* language=<language locale>
*
* @author James Kempf
*
*/
/**
* Attribute id for attribute describing service type name.
* String, single valued attribute.
*/
/**
* Attribute id for attribute describing help text.
* String, single valued, required attribute, .
*/
/**
* Attribute id for attribute describing service version. The
* version number is of the form ``n.m'', where n and m are integers.
* String, single valued, required attribute.
*/
/**
* Attribute id for attribute describing service URL url part grammer.
* String, single valued, required attribute.
*/
/**
* The service type name for the template type.
*/
// The distinguished template registry object.
// Package private constructor for singleton pattern maintained
// by the ServiceLocationManager.
}
//
// Public implementation.
//
/**
* Register the new service.
*
* @param serviceType Name of the service.
* @param documentURL URL of the template document.
* @param languageLocale Locale of the template langugae.
* @param version Version number of template document.
* @exception ServiceLocationException Error code is
* INVALID_REGISTRATION
* if the service already exists or
* the registration fails.
* Throws
* SYSTEM_ERROR
* if the scope vector is null or
* empty.
* Throws
* PARSE_ERROR
* if an attribute is bad.
* @exception IllegalArgumentException Thrown if any parameters are null.
*
*/
throws ServiceLocationException {
// Check for illegal parameters.
throw
new Object[] {
documentURL}));
}
try {
version);
} catch (ServiceLocationException ex) {
// Ignore if language not supported, it just means there
// isn't any.
if (ex.getErrorCode() !=
throw ex;
}
}
// Throw an exception if it exists.
throw
"template_already_registered",
new Object[] {
}
// Construct attributes for the registration.
// Add the service type name.
// Add the version.
attr =
// Construct a service URL for the template.
":"+
";"+
"="+
";"+
"="+
// Do the registration.
if (serviceAgent == null) {
throw
"no_advertiser",
new Object[0]);
}
// Note that the assumption here is that the URL containing the
// path to the template document is written "somehow".
// It is up to the client to make sure that the template document
// has been written.
}
/**
* Deregister the template for service type.
*
* @param serviceType Name of service.
* @param <i>languageLocale</i> Language locale of template.
* @param <i>version</i> Version of the template, null for latest.
* @exception ServiceLocationException Thrown if the deregistration
* fails.
* @exception IllegalArgumentException Thrown if the parameter is null.
*
*/
throws ServiceLocationException {
// Check the parameter.
// Get the template document URL for the service.
version);
// If there's no template, then throw an exception.
throw
"template_not_registered",
new Object[] {
}
// Deregister in all scopes.
if (serviceAgent == null) {
throw
"no_advertiser",
new Object[0]);
}
// Deregister the service URL.
}
/**
* Find the service URL for the service.
*
* @param serviceType Name of service.
* @param <i>languageLocale</i> Language locale of template.
* @param <i>version</i> Version of the template, null for latest.
* @return ServiceURL for the service template. If the service doesn't
* exist, returns null.
* @exception ServiceLocationException Error code is
* SYSTEM_ERROR
* if the scope vector is null or
* empty or if more than one
* template URL is returned.
* @exception IllegalArgumentException Thrown if any parameters are null.
*
*/
throws ServiceLocationException {
// Check the parameter.
version);
// If nothing returned, then simply return.
return null;
}
// Form the document URL.
throw
"template_url_malformed",
}
// Parse off the URL path.
if (idx == -1) {
throw
"template_url_malformed",
}
// Return the document URL.
}
// Return a URL given a version and language locale.
throws ServiceLocationException {
// Templates should be registered in all scopes. Look for them
// in all.
// Set up query.
}
// Get user agent for query.
throw
"no_locator",
new Object[0]);
}
try {
results =
query);
} catch (ServiceLocationException ex) {
// If language not supported, it just means none there.
if (ex.getErrorCode() !=
throw ex;
}
}
// If nothing came back, then return null.
if (!results.hasMoreElements()) {
return null;
}
float highest = (float)-1.0;
// If there's more than one service of this type registered, then
// take highest version if version number was null.
while (results.hasMoreElements()) {
// Get the version attribute from the URL.
continue;
}
urlPath =
continue;
}
float current = (float)0.0;
// Convert to float.
try {
} catch (NumberFormatException ex) {
continue; // ignore, there may be more...
}
// Identify if this is the highest version number so far.
}
} else {
// If we found more than one, may be a problem.
throw
"template_multiple",
new Object[] {
}
}
}
return turl;
}
/**
* Create an attribute verifier for the template document URL.
*
* @param documentURL A URL for the template document URL.
* @return An attribute verifier for the service
* @exception ServiceLocationException Throws
* PARSE_ERROR
* if any syntax errors
* are encountered during parsing
* of service's template definition.
* Throws
* SYSTEM_ERROR
* if URL parsing error occurs.
* Throws ServiceLocationException
* if any other errors occur.
* @exception IllegalArgumentException Thrown if any parameters are null.
*
*/
throws ServiceLocationException {
// Check the parameter.
// Create a URL attribute parser to parse the document.
return new URLAttributeVerifier(documentURL);
}
}