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) 2001 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 // Assert.java : Handles assertions in a central fashion. 280Sstevel@tonic-gate // 290Sstevel@tonic-gate // Author: Erik Guttman 300Sstevel@tonic-gate // 310Sstevel@tonic-gate // 320Sstevel@tonic-gate 330Sstevel@tonic-gate package com.sun.slp; 340Sstevel@tonic-gate 350Sstevel@tonic-gate import java.util.*; 360Sstevel@tonic-gate import java.text.*; 370Sstevel@tonic-gate 380Sstevel@tonic-gate /** 390Sstevel@tonic-gate * The Assert class is used to test assertions and end the program 400Sstevel@tonic-gate * execution if the assertion fails. 410Sstevel@tonic-gate * 420Sstevel@tonic-gate * @author Erik Guttman 430Sstevel@tonic-gate */ 440Sstevel@tonic-gate 450Sstevel@tonic-gate class Assert { slpassert(boolean bool, String msgTag, Object[] params)460Sstevel@tonic-gate static void slpassert(boolean bool, String msgTag, Object[] params) { 470Sstevel@tonic-gate if (bool == false) { 480Sstevel@tonic-gate SLPConfig conf = SLPConfig.getSLPConfig(); 490Sstevel@tonic-gate printMessageAndDie(conf, msgTag, params); 500Sstevel@tonic-gate } 510Sstevel@tonic-gate } 520Sstevel@tonic-gate 530Sstevel@tonic-gate // Print message and die. Used within SLPConfig during initialization. 540Sstevel@tonic-gate static void printMessageAndDie(SLPConfig conf, String msgTag, Object[] params)550Sstevel@tonic-gate printMessageAndDie(SLPConfig conf, String msgTag, Object[] params) { 560Sstevel@tonic-gate ResourceBundle msgs = conf.getMessageBundle(conf.getLocale()); 570Sstevel@tonic-gate String failed = msgs.getString("assert_failed"); 580Sstevel@tonic-gate String msg = conf.formatMessage(msgTag, params); 590Sstevel@tonic-gate System.err.println(failed+msg); 600Sstevel@tonic-gate (new Exception()).printStackTrace(); // tells where we are at... 610Sstevel@tonic-gate System.exit(-1); 620Sstevel@tonic-gate } 630Sstevel@tonic-gate 640Sstevel@tonic-gate // Assert that a parameter is nonnull. 650Sstevel@tonic-gate // Throw IllegalArgumentException if so. 660Sstevel@tonic-gate nonNullParameter(Object obj, String param)670Sstevel@tonic-gate static void nonNullParameter(Object obj, String param) { 680Sstevel@tonic-gate if (obj == null) { 690Sstevel@tonic-gate SLPConfig conf = SLPConfig.getSLPConfig(); 700Sstevel@tonic-gate String msg = 710Sstevel@tonic-gate conf.formatMessage("null_parameter", new Object[] {param}); 720Sstevel@tonic-gate throw 730Sstevel@tonic-gate new IllegalArgumentException(msg); 740Sstevel@tonic-gate } 750Sstevel@tonic-gate } 760Sstevel@tonic-gate } 77