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