xref: /illumos-gate/usr/src/lib/libslp/javalib/com/sun/slp/Assert.java (revision efd4c9b63ad77503c101fc6c2ed8ba96c9d52964)
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) 2001 by Sun Microsystems, Inc.
23  * All rights reserved.
24  */
25 
26 //
27 // Assert.java : Handles assertions in a central fashion.
28 //
29 //  Author:           Erik Guttman
30 //
31 //
32 
33 package com.sun.slp;
34 
35 import java.util.*;
36 import java.text.*;
37 
38 /**
39  * The Assert class is used to test assertions and end the program
40  * execution if the assertion fails.
41  *
42  * @author  Erik Guttman
43  */
44 
45 class Assert {
46     static void slpassert(boolean bool, String msgTag, Object[] params) {
47 	if (bool == false) {
48 	    SLPConfig conf = SLPConfig.getSLPConfig();
49 	    printMessageAndDie(conf, msgTag, params);
50 	}
51     }
52 
53     // Print message and die. Used within SLPConfig during initialization.
54     static void
55 	printMessageAndDie(SLPConfig conf, String msgTag, Object[] params) {
56 	ResourceBundle msgs = conf.getMessageBundle(conf.getLocale());
57 	String failed = msgs.getString("assert_failed");
58 	String msg = conf.formatMessage(msgTag, params);
59 	System.err.println(failed+msg);
60 	(new Exception()).printStackTrace();  // tells where we are at...
61 	System.exit(-1);
62     }
63 
64     // Assert that a parameter is nonnull.
65     // Throw IllegalArgumentException if so.
66 
67     static void nonNullParameter(Object obj, String param) {
68 	if (obj == null) {
69 	    SLPConfig conf = SLPConfig.getSLPConfig();
70 	    String msg =
71 		conf.formatMessage("null_parameter", new Object[] {param});
72 	    throw
73 		new IllegalArgumentException(msg);
74 	}
75     }
76 }
77