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