001 /** 002 * Copyright (c) 2003 Daffodil Software Ltd all rights reserved, 003 * Modifications Copyright (c) 2008 Regiscope Digital Imaging Co, LLC, All rights reserved. 004 * This program is free software; you can redistribute it and/or modify 005 * it under the terms of version 2 of the GNU General Public License as 006 * published by the Free Software Foundation. 007 * There are special exceptions to the terms and conditions of the GPL 008 * as it is applied to this software. See the GNU General Public License for more details. 009 * 010 * This program is distributed in the hope that it will be useful, 011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 013 * GNU General Public License for more details. 014 * 015 * You should have received a copy of the GNU General Public License 016 * along with this program; if not, write to the Free Software 017 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 018 */ 019 020 package org.dbreplicator.replication; 021 022 import java.text.*; 023 import java.util.*; 024 025 /** 026 * This is the replicator's exception class, It extends Exception class. 027 * When some repException occurs it's object is returned. This class 028 * overrides some standard exception methods. 029 * 030 */ 031 032 public class RepException extends Exception 033 { 034 035 private String repCode; 036 private Object[] params; 037 038 public RepException(String repCode0, Object[] params0) { 039 repCode = repCode0; 040 params = params0; 041 } 042 043 public String getMessage() 044 { 045 return getMessage(null); 046 } 047 048 public String getMessage(Locale locale) 049 { 050 ResourceBundle manager = null; 051 if (locale != null) 052 { 053 manager = ResourceBundle.getBundle("org.dbreplicator.replication.RepCode", locale); 054 } 055 else 056 { 057 manager = ResourceBundle.getBundle("org.dbreplicator.replication.RepCode"); 058 } 059 try 060 { 061 MessageFormat mf = new MessageFormat(manager.getString(repCode)); 062 return "\n\t" + mf.format(getParametersAsString()); 063 } 064 catch (Exception ex) 065 { 066 return "\n\t" + "Code \"" + repCode + "\" is not defined"; 067 } 068 } 069 070 private String[] getParametersAsString() { 071 if (params == null) { 072 return null; 073 } 074 int length = params.length; 075 String[] str = new String[length]; 076 for (int i = 0; i < length; i++) { 077 String temp = "" + params[i]; 078 temp = temp.trim(); 079 if (temp.startsWith("the keyword")) 080 { 081 String asd = temp.substring(12); 082 asd = asd.trim(); 083 str[i] = "the keyword '" + asd + "'"; 084 } 085 else 086 { 087 088 str[i] = "'" + temp + "'"; 089 } 090 } 091 return str; 092 } 093 094 public String getRepCode() { 095 return repCode; 096 } 097 098 public void SetStackTrace(RepException ex) { 099 setStackTrace(ex.getStackTrace()); 100 } 101 }

