10Sstevel@tonic-gate /*
20Sstevel@tonic-gate  * CDDL HEADER START
30Sstevel@tonic-gate  *
40Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*7298SMark.J.Nelson@Sun.COM  * Common Development and Distribution License (the "License").
6*7298SMark.J.Nelson@Sun.COM  * You may not use this file except in compliance with the License.
70Sstevel@tonic-gate  *
80Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
90Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
100Sstevel@tonic-gate  * See the License for the specific language governing permissions
110Sstevel@tonic-gate  * and limitations under the License.
120Sstevel@tonic-gate  *
130Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
140Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
150Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
160Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
170Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
180Sstevel@tonic-gate  *
190Sstevel@tonic-gate  * CDDL HEADER END
200Sstevel@tonic-gate  */
210Sstevel@tonic-gate /*
220Sstevel@tonic-gate  * Copyright (c) 1999 by Sun Microsystems, Inc.
230Sstevel@tonic-gate  * All rights reserved.
240Sstevel@tonic-gate  *
250Sstevel@tonic-gate  */
260Sstevel@tonic-gate 
27*7298SMark.J.Nelson@Sun.COM //  ServiceLocationException.java : All SLP exceptions are derived from
28*7298SMark.J.Nelson@Sun.COM //                                  this base class.
290Sstevel@tonic-gate //  Author:           Erik Guttman
300Sstevel@tonic-gate //
310Sstevel@tonic-gate 
320Sstevel@tonic-gate package com.sun.slp;
330Sstevel@tonic-gate 
340Sstevel@tonic-gate import java.util.*;
350Sstevel@tonic-gate import java.text.*;
360Sstevel@tonic-gate 
370Sstevel@tonic-gate /**
380Sstevel@tonic-gate  * The ServiceLocationException class is thrown when an error occurs
390Sstevel@tonic-gate  * during SLP operation. The exact nature of the error is indicated
400Sstevel@tonic-gate  * by the integer error codes.
410Sstevel@tonic-gate  *
420Sstevel@tonic-gate  * @author  Erik Guttman
430Sstevel@tonic-gate  */
440Sstevel@tonic-gate 
450Sstevel@tonic-gate public class ServiceLocationException extends Exception {
460Sstevel@tonic-gate 
470Sstevel@tonic-gate     // Error codes.
480Sstevel@tonic-gate 
490Sstevel@tonic-gate     /**
500Sstevel@tonic-gate      * No error.
510Sstevel@tonic-gate      */
520Sstevel@tonic-gate 
530Sstevel@tonic-gate     static final short OK                     = 0;
540Sstevel@tonic-gate 
550Sstevel@tonic-gate     /**
560Sstevel@tonic-gate      * The DA did not have a registration in the language locale of
570Sstevel@tonic-gate      * the request, although it did have one in another language locale.
580Sstevel@tonic-gate      */
590Sstevel@tonic-gate 
600Sstevel@tonic-gate     public static final short LANGUAGE_NOT_SUPPORTED     = 1;
610Sstevel@tonic-gate 
620Sstevel@tonic-gate     /**
630Sstevel@tonic-gate      * An error occured while parsing a URL, attribute list, or a
640Sstevel@tonic-gate      * service location template document. This error is also returned
650Sstevel@tonic-gate      * from DA's when an otherwise unclassifiable internal error occurs.
660Sstevel@tonic-gate      */
670Sstevel@tonic-gate 
680Sstevel@tonic-gate     public static final short PARSE_ERROR            = 2;
690Sstevel@tonic-gate 
700Sstevel@tonic-gate     /**
710Sstevel@tonic-gate      * Upon registration, this error is returned if the URL is invalid or
720Sstevel@tonic-gate      * if some other problem occurs with the registration. Upon deregistration
730Sstevel@tonic-gate      * it is also returned if the URL is not registered.
740Sstevel@tonic-gate      */
750Sstevel@tonic-gate 
760Sstevel@tonic-gate 
770Sstevel@tonic-gate     public static final short INVALID_REGISTRATION   = 3;
780Sstevel@tonic-gate 
790Sstevel@tonic-gate     /**
800Sstevel@tonic-gate      * An attempt was made to register in a scope not supported by the DA.
810Sstevel@tonic-gate      * This error is also returned if an attempt is made to perform a
820Sstevel@tonic-gate      * registration or deregistration on a machine where a DA is running,
830Sstevel@tonic-gate      * since DA machines don't support SA functionality.
840Sstevel@tonic-gate      */
850Sstevel@tonic-gate 
860Sstevel@tonic-gate     public static final short SCOPE_NOT_SUPPORTED    = 4;
870Sstevel@tonic-gate 
880Sstevel@tonic-gate     /**
890Sstevel@tonic-gate      * The DA or SA receives a request for an unsupported SLP SPI.
900Sstevel@tonic-gate      */
910Sstevel@tonic-gate     public static final short AUTHENTICATION_UNKNOWN = 5;
920Sstevel@tonic-gate 
930Sstevel@tonic-gate     /**
940Sstevel@tonic-gate      * A message for which an signature block was required is missing
950Sstevel@tonic-gate      * the block.
960Sstevel@tonic-gate      */
970Sstevel@tonic-gate 
980Sstevel@tonic-gate     public static final short AUTHENTICATION_ABSENT  = 6;
990Sstevel@tonic-gate 
1000Sstevel@tonic-gate     /**
1010Sstevel@tonic-gate      * A signature block failed to authenticate.
1020Sstevel@tonic-gate      */
1030Sstevel@tonic-gate 
1040Sstevel@tonic-gate     public static final short AUTHENTICATION_FAILED  = 7;
1050Sstevel@tonic-gate 
1060Sstevel@tonic-gate     /**
1070Sstevel@tonic-gate      * The version was not supported. This is surfaced to the client as a
1080Sstevel@tonic-gate      * no results.
1090Sstevel@tonic-gate      */
1100Sstevel@tonic-gate 
1110Sstevel@tonic-gate     static final short VERSION_NOT_SUPPORTED  = 9;
1120Sstevel@tonic-gate 
1130Sstevel@tonic-gate     /**
1140Sstevel@tonic-gate      * The DA encountered an internal error.
1150Sstevel@tonic-gate      */
1160Sstevel@tonic-gate 
1170Sstevel@tonic-gate     static final short INTERNAL_ERROR	   = 10;
1180Sstevel@tonic-gate 
1190Sstevel@tonic-gate     /**
1200Sstevel@tonic-gate      * The DA was busy. This is not surfaced to the client.
1210Sstevel@tonic-gate      */
1220Sstevel@tonic-gate 
1230Sstevel@tonic-gate 
1240Sstevel@tonic-gate     static final short DA_BUSY		   = 11;
1250Sstevel@tonic-gate 
1260Sstevel@tonic-gate     /**
1270Sstevel@tonic-gate      * An option was received by the DA that wasn't supported. This is
1280Sstevel@tonic-gate      * surfaced to the client as no results.
1290Sstevel@tonic-gate      */
1300Sstevel@tonic-gate 
1310Sstevel@tonic-gate     static final short OPTION_NOT_SUPPORTED   = 12;
1320Sstevel@tonic-gate 
1330Sstevel@tonic-gate 
1340Sstevel@tonic-gate     /**
1350Sstevel@tonic-gate      * An attempt was made to update a nonexisting registration.
1360Sstevel@tonic-gate      */
1370Sstevel@tonic-gate 
1380Sstevel@tonic-gate     public static final short INVALID_UPDATE	   = 13;
1390Sstevel@tonic-gate 
1400Sstevel@tonic-gate     /**
1410Sstevel@tonic-gate      * The remote agent doesn't support the request. Not surfaced to
1420Sstevel@tonic-gate      * the client.
1430Sstevel@tonic-gate      */
1440Sstevel@tonic-gate 
1450Sstevel@tonic-gate     static final short REQUEST_NOT_SUPPORTED = 14;
1460Sstevel@tonic-gate 
1470Sstevel@tonic-gate     /**
1480Sstevel@tonic-gate      * For SA, the DA valid lifetime intervals for
1490Sstevel@tonic-gate      * different DAs do not overlap.
1500Sstevel@tonic-gate      */
1510Sstevel@tonic-gate 
1520Sstevel@tonic-gate     public static final short INVALID_LIFETIME = 15;
1530Sstevel@tonic-gate 
1540Sstevel@tonic-gate     // Internal error codes.
1550Sstevel@tonic-gate 
1560Sstevel@tonic-gate     /**
1570Sstevel@tonic-gate      * Operation isn't implemented.
1580Sstevel@tonic-gate      */
1590Sstevel@tonic-gate 
1600Sstevel@tonic-gate     public static final short NOT_IMPLEMENTED = 16;
1610Sstevel@tonic-gate 
1620Sstevel@tonic-gate     /**
1630Sstevel@tonic-gate      * Initialization of the network failed.
1640Sstevel@tonic-gate      */
1650Sstevel@tonic-gate 
1660Sstevel@tonic-gate     public static final short NETWORK_INIT_FAILED = 17;
1670Sstevel@tonic-gate 
1680Sstevel@tonic-gate     /**
1690Sstevel@tonic-gate      * A TCP connection timed out.
1700Sstevel@tonic-gate      */
1710Sstevel@tonic-gate 
1720Sstevel@tonic-gate     public static final short NETWORK_TIMED_OUT = 18;
1730Sstevel@tonic-gate 
1740Sstevel@tonic-gate     /**
1750Sstevel@tonic-gate      * An error occured during networking.
1760Sstevel@tonic-gate      */
1770Sstevel@tonic-gate 
1780Sstevel@tonic-gate     public static final short NETWORK_ERROR 	= 19;
1790Sstevel@tonic-gate 
1800Sstevel@tonic-gate     /**
1810Sstevel@tonic-gate      * An error occured in the client-side code.
1820Sstevel@tonic-gate      */
1830Sstevel@tonic-gate 
1840Sstevel@tonic-gate     public static final short INTERNAL_SYSTEM_ERROR	= 20;
1850Sstevel@tonic-gate 
1860Sstevel@tonic-gate     /*
1870Sstevel@tonic-gate      * Registration failed to match the service type template.
1880Sstevel@tonic-gate      */
1890Sstevel@tonic-gate 
1900Sstevel@tonic-gate     public static final short TYPE_ERROR			= 21;
1910Sstevel@tonic-gate 
1920Sstevel@tonic-gate     /**
1930Sstevel@tonic-gate      * Packet size overflow.
1940Sstevel@tonic-gate      */
1950Sstevel@tonic-gate 
1960Sstevel@tonic-gate     public static final short BUFFER_OVERFLOW 		= 22;
1970Sstevel@tonic-gate 
1980Sstevel@tonic-gate     /**
1990Sstevel@tonic-gate      * Overflow due to previous responder list being too long.
2000Sstevel@tonic-gate      */
2010Sstevel@tonic-gate 
2020Sstevel@tonic-gate     static final short PREVIOUS_RESPONDER_OVERFLOW = 100;
2030Sstevel@tonic-gate 
2040Sstevel@tonic-gate     // The error code for this exception.
2050Sstevel@tonic-gate 
2060Sstevel@tonic-gate     private short errorCode = OK;
2070Sstevel@tonic-gate 
2080Sstevel@tonic-gate     // The message arguments.
2090Sstevel@tonic-gate 
2100Sstevel@tonic-gate     private Object[] params = null;
2110Sstevel@tonic-gate 
2120Sstevel@tonic-gate     // allows additional information to be added to the message
2130Sstevel@tonic-gate 
2140Sstevel@tonic-gate     private String addendum = "";
2150Sstevel@tonic-gate 
ServiceLocationException(short errorCode, String msgTag, Object[] params)2160Sstevel@tonic-gate     ServiceLocationException(short errorCode, String msgTag, Object[] params) {
2170Sstevel@tonic-gate 	super(msgTag);
2180Sstevel@tonic-gate 
2190Sstevel@tonic-gate 	this.params = params;
2200Sstevel@tonic-gate 	this.errorCode = errorCode;
2210Sstevel@tonic-gate     }
2220Sstevel@tonic-gate 
2230Sstevel@tonic-gate     // Return true if this is a vaild on-the-wire error code.
2240Sstevel@tonic-gate 
validWireErrorCode(int code)2250Sstevel@tonic-gate     static boolean validWireErrorCode(int code) {
2260Sstevel@tonic-gate 	return ((code >= OK) && (code <= REQUEST_NOT_SUPPORTED));
2270Sstevel@tonic-gate 
2280Sstevel@tonic-gate     }
2290Sstevel@tonic-gate 
2300Sstevel@tonic-gate     /**
2310Sstevel@tonic-gate      * Return the error code.
2320Sstevel@tonic-gate      *
2330Sstevel@tonic-gate      * @return The integer error code.
2340Sstevel@tonic-gate      */
2350Sstevel@tonic-gate 
getErrorCode()2360Sstevel@tonic-gate     public short getErrorCode() {
2370Sstevel@tonic-gate 	return errorCode;
2380Sstevel@tonic-gate 
2390Sstevel@tonic-gate     }
2400Sstevel@tonic-gate 
2410Sstevel@tonic-gate     /**
2420Sstevel@tonic-gate      * Return the localized message, in the default locale.
2430Sstevel@tonic-gate      *
2440Sstevel@tonic-gate      * @return The localized message.
2450Sstevel@tonic-gate      */
2460Sstevel@tonic-gate 
getMessage()2470Sstevel@tonic-gate     public String getMessage() {
2480Sstevel@tonic-gate 	return getLocalizedMessage(SLPConfig.getSLPConfig().getLocale()) +
2490Sstevel@tonic-gate 	    addendum;
2500Sstevel@tonic-gate 
2510Sstevel@tonic-gate     }
2520Sstevel@tonic-gate 
getLocalizedMessage(Locale locale)2530Sstevel@tonic-gate     public String getLocalizedMessage(Locale locale) {
2540Sstevel@tonic-gate 	SLPConfig conf = SLPConfig.getSLPConfig();
2550Sstevel@tonic-gate 	return conf.formatMessage(super.getMessage(), params);
2560Sstevel@tonic-gate 
2570Sstevel@tonic-gate     }
2580Sstevel@tonic-gate 
makeAddendum(String addendum)2590Sstevel@tonic-gate     void makeAddendum(String addendum) {
2600Sstevel@tonic-gate 	this.addendum = addendum;
2610Sstevel@tonic-gate     }
2620Sstevel@tonic-gate 
2630Sstevel@tonic-gate }
264