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) 1998-2001 by Sun Microsystems, Inc.
  26  * All rights reserved.
  27  */
  28 
  29 package com.sun.dhcpmgr.bridge;
  30 
  31 import java.text.MessageFormat;
  32 
  33 /**
  34  * This class is the superclass for all exceptions (other than core java
  35  * exceptions) thrown by the server and JNI routines.
  36  */
  37 public class BridgeException extends Exception {
  38 
  39     /**
  40      * Arguments to use when formatting the message for the exception.
  41      */
  42     protected Object [] args = null;
  43 
  44     /**
  45      * Simplest constructor.
  46      */
  47     public BridgeException() {
  48         super("internal_error");
  49     } // constructor
  50     
  51     /**
  52      * Constructor that provides a msgid.
  53      * @param msgid ResourceBundle id to link to this exception.
  54      */
  55     public BridgeException(String msgid) {
  56         super(msgid);
  57     } // constructor
  58 
  59     /**
  60      * Constructor that provides a msgid and an argument to the message.
  61      * @param msgid ResourceBundle id to link to this exception.
  62      * @param args array of arguments to be used in format of message.
  63      */
  64     public BridgeException(String msgid, Object [] args) {
  65         super(msgid);
  66         this.args = args;
  67     } // constructor
  68 
  69     /**
  70      * Constructor that provides a msgid and an argument to the message.
  71      * @param msgid ResourceBundle id to link to this exception.
  72      * @param arg argument to be used in format of exception message.
  73      */
  74     public BridgeException(String msgid, String arg) {
  75         super(msgid);
  76         args = new Object[1];
  77         args[0] = arg;
  78     } // constructor
  79 
  80     /**
  81      * Override of superclass getMessage(). Builds a message using the
  82      * msgid and args (if any) that were provided at instantiation.
  83      * @return message for the exception.
  84      */
  85     public String getMessage() {
  86         String message = null;
  87         String messageId = super.getMessage();
  88 
  89         try {
  90             if (args != null) {
  91                 MessageFormat form = new MessageFormat(
  92                     ResourceStrings.getString(messageId));
  93                 message = form.format(args);
  94             } else {
  95                 message = ResourceStrings.getString(messageId);
  96             }
  97         } catch (Throwable e) {
  98             message = messageId;
  99         }
 100 
 101         return (message);
 102     } // getMessage
 103 
 104 } // BridgeException