001 /** 002 * Copyright 2004-2012 The Kuali Foundation 003 * 004 * Licensed under the Educational Community License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.opensource.org/licenses/ecl2.php 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016 package org.apache.torque.mojo; 017 018 import java.util.Properties; 019 020 import org.apache.commons.lang.StringUtils; 021 022 public class ImpexError { 023 Throwable throwable; 024 String message; 025 Properties info; 026 String url; 027 String driver; 028 boolean showPassword; 029 030 public Throwable getThrowable() { 031 return throwable; 032 } 033 034 public void setThrowable(Throwable throwable) { 035 this.throwable = throwable; 036 } 037 038 public String getMessage() { 039 return message; 040 } 041 042 public void setMessage(String message) { 043 this.message = message; 044 } 045 046 public Properties getInfo() { 047 return info; 048 } 049 050 public void setInfo(Properties info) { 051 this.info = info; 052 } 053 054 public String toString() { 055 StringBuffer sb = new StringBuffer(); 056 sb.append("\n\n"); 057 if (!StringUtils.isEmpty(message)) { 058 sb.append(message + "\n\n"); 059 } 060 if (getThrowable() != null) { 061 sb.append("------------------------------------------------------\n"); 062 String emsg = getThrowable().getMessage(); 063 sb.append(emsg); 064 if (!emsg.endsWith("\n")) { 065 sb.append("\n"); 066 } 067 } 068 sb.append(toString(getInfo())); 069 return sb.toString(); 070 } 071 072 public String toString(Properties info) { 073 StringBuffer sb = new StringBuffer(); 074 sb.append("------------------------------------------------------\n\n"); 075 sb.append("The following information was provided to JDBC:\n"); 076 sb.append("------------------------------------------------------\n"); 077 sb.append("URL: " + getUrl() + "\n"); 078 sb.append("Driver: " + getDriver() + "\n"); 079 String username = info.getProperty(AbstractSQLExecutorMojo.DRIVER_INFO_PROPERTIES_USER); 080 if (StringUtils.isEmpty(username)) { 081 sb.append("Username: [No username was supplied]\n"); 082 } else { 083 sb.append("Username: " + username + "\n"); 084 } 085 String password = info.getProperty(AbstractSQLExecutorMojo.DRIVER_INFO_PROPERTIES_PASSWORD); 086 if (isShowPassword()) { 087 sb.append("Password: " + password + "\n"); 088 } else { 089 if (StringUtils.isEmpty(password)) { 090 sb.append("Password: [No password was supplied]\n"); 091 } else { 092 sb.append("Password: *******\n"); 093 } 094 } 095 sb.append("------------------------------------------------------\n"); 096 sb.append("\n"); 097 return sb.toString(); 098 099 } 100 101 public String getUrl() { 102 return url; 103 } 104 105 public void setUrl(String url) { 106 this.url = url; 107 } 108 109 public String getDriver() { 110 return driver; 111 } 112 113 public void setDriver(String driver) { 114 this.driver = driver; 115 } 116 117 public boolean isShowPassword() { 118 return showPassword; 119 } 120 121 public void setShowPassword(boolean showPassword) { 122 this.showPassword = showPassword; 123 } 124 125 }