1 /* 2 * CDDL HEADER START 3 * 4 * The contents of this file are subject to the terms of the 5 * Common Development and Distribution License, Version 1.0 only 6 * (the "License"). You may not use this file except in compliance 7 * with the License. 8 * 9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10 * or http://www.opensolaris.org/os/licensing. 11 * See the License for the specific language governing permissions 12 * and limitations under the License. 13 * 14 * When distributing Covered Code, include this CDDL HEADER in each 15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16 * If applicable, add the following below this CDDL HEADER, with the 17 * fields enclosed by brackets "[]" replaced with your own identifying 18 * information: Portions Copyright [yyyy] [name of copyright owner] 19 * 20 * CDDL HEADER END 21 */ 22 /* 23 * ident "%Z%%M% %I% %E% SMI" 24 * 25 * Copyright (c) 1999 by Sun Microsystems, Inc. 26 * All rights reserved. 27 * 28 */ 29 30 // SCCS Status: %W% %G% 31 // %M : All SLP exceptions are derived from this base class. 32 // Author: Erik Guttman 33 // 34 35 package com.sun.slp; 36 37 import java.util.*; 38 import java.text.*; 39 40 /** 41 * The ServiceLocationException class is thrown when an error occurs 42 * during SLP operation. The exact nature of the error is indicated 43 * by the integer error codes. 44 * 45 * @version %R%.%L% %D% 46 * @author Erik Guttman 47 */ 48 49 public class ServiceLocationException extends Exception { 50 51 // Error codes. 52 53 /** 54 * No error. 55 */ 56 57 static final short OK = 0; 58 59 /** 60 * The DA did not have a registration in the language locale of 61 * the request, although it did have one in another language locale. 62 */ 63 64 public static final short LANGUAGE_NOT_SUPPORTED = 1; 65 66 /** 67 * An error occured while parsing a URL, attribute list, or a 68 * service location template document. This error is also returned 69 * from DA's when an otherwise unclassifiable internal error occurs. 70 */ 71 72 public static final short PARSE_ERROR = 2; 73 74 /** 75 * Upon registration, this error is returned if the URL is invalid or 76 * if some other problem occurs with the registration. Upon deregistration 77 * it is also returned if the URL is not registered. 78 */ 79 80 81 public static final short INVALID_REGISTRATION = 3; 82 83 /** 84 * An attempt was made to register in a scope not supported by the DA. 85 * This error is also returned if an attempt is made to perform a 86 * registration or deregistration on a machine where a DA is running, 87 * since DA machines don't support SA functionality. 88 */ 89 90 public static final short SCOPE_NOT_SUPPORTED = 4; 91 92 /** 93 * The DA or SA receives a request for an unsupported SLP SPI. 94 */ 95 public static final short AUTHENTICATION_UNKNOWN = 5; 96 97 /** 98 * A message for which an signature block was required is missing 99 * the block. 100 */ 101 102 public static final short AUTHENTICATION_ABSENT = 6; 103 104 /** 105 * A signature block failed to authenticate. 106 */ 107 108 public static final short AUTHENTICATION_FAILED = 7; 109 110 /** 111 * The version was not supported. This is surfaced to the client as a 112 * no results. 113 */ 114 115 static final short VERSION_NOT_SUPPORTED = 9; 116 117 /** 118 * The DA encountered an internal error. 119 */ 120 121 static final short INTERNAL_ERROR = 10; 122 123 /** 124 * The DA was busy. This is not surfaced to the client. 125 */ 126 127 128 static final short DA_BUSY = 11; 129 130 /** 131 * An option was received by the DA that wasn't supported. This is 132 * surfaced to the client as no results. 133 */ 134 135 static final short OPTION_NOT_SUPPORTED = 12; 136 137 138 /** 139 * An attempt was made to update a nonexisting registration. 140 */ 141 142 public static final short INVALID_UPDATE = 13; 143 144 /** 145 * The remote agent doesn't support the request. Not surfaced to 146 * the client. 147 */ 148 149 static final short REQUEST_NOT_SUPPORTED = 14; 150 151 /** 152 * For SA, the DA valid lifetime intervals for 153 * different DAs do not overlap. 154 */ 155 156 public static final short INVALID_LIFETIME = 15; 157 158 // Internal error codes. 159 160 /** 161 * Operation isn't implemented. 162 */ 163 164 public static final short NOT_IMPLEMENTED = 16; 165 166 /** 167 * Initialization of the network failed. 168 */ 169 170 public static final short NETWORK_INIT_FAILED = 17; 171 172 /** 173 * A TCP connection timed out. 174 */ 175 176 public static final short NETWORK_TIMED_OUT = 18; 177 178 /** 179 * An error occured during networking. 180 */ 181 182 public static final short NETWORK_ERROR = 19; 183 184 /** 185 * An error occured in the client-side code. 186 */ 187 188 public static final short INTERNAL_SYSTEM_ERROR = 20; 189 190 /* 191 * Registration failed to match the service type template. 192 */ 193 194 public static final short TYPE_ERROR = 21; 195 196 /** 197 * Packet size overflow. 198 */ 199 200 public static final short BUFFER_OVERFLOW = 22; 201 202 /** 203 * Overflow due to previous responder list being too long. 204 */ 205 206 static final short PREVIOUS_RESPONDER_OVERFLOW = 100; 207 208 // The error code for this exception. 209 210 private short errorCode = OK; 211 212 // The message arguments. 213 214 private Object[] params = null; 215 216 // allows additional information to be added to the message 217 218 private String addendum = ""; 219 220 ServiceLocationException(short errorCode, String msgTag, Object[] params) { 221 super(msgTag); 222 223 this.params = params; 224 this.errorCode = errorCode; 225 } 226 227 // Return true if this is a vaild on-the-wire error code. 228 229 static boolean validWireErrorCode(int code) { 230 return ((code >= OK) && (code <= REQUEST_NOT_SUPPORTED)); 231 232 } 233 234 /** 235 * Return the error code. 236 * 237 * @return The integer error code. 238 */ 239 240 public short getErrorCode() { 241 return errorCode; 242 243 } 244 245 /** 246 * Return the localized message, in the default locale. 247 * 248 * @return The localized message. 249 */ 250 251 public String getMessage() { 252 return getLocalizedMessage(SLPConfig.getSLPConfig().getLocale()) + 253 addendum; 254 255 } 256 257 public String getLocalizedMessage(Locale locale) { 258 SLPConfig conf = SLPConfig.getSLPConfig(); 259 return conf.formatMessage(super.getMessage(), params); 260 261 } 262 263 void makeAddendum(String addendum) { 264 this.addendum = addendum; 265 } 266 267 } 268