001: /*
002: * (c) Copyright 2006 by Volker Bergmann. All rights reserved.
003: *
004: * Redistribution and use in source and binary forms, with or without
005: * modification, is permitted under the terms of the
006: * GNU General Public License.
007: *
008: * For redistributing this software or a derivative work under a license other
009: * than the GPL-compatible Free Software License as defined by the Free
010: * Software Foundation or approved by OSI, you must first obtain a commercial
011: * license to this software product from Volker Bergmann.
012: *
013: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
014: * WITHOUT A WARRANTY OF ANY KIND. ALL EXPRESS OR IMPLIED CONDITIONS,
015: * REPRESENTATIONS AND WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF
016: * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE
017: * HEREBY EXCLUDED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
018: * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
019: * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
020: * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
021: * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
022: * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
023: * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
024: * POSSIBILITY OF SUCH DAMAGE.
025: */
026:
027: package org.databene.benerator;
028:
029: import org.databene.commons.ConfigurationError;
030:
031: import java.util.List;
032: import java.util.Arrays;
033:
034: /**
035: * Indicates invalid setup of a Generator.<br/>
036: * <br/>
037: * Created: 21.12.2006 08:04:49
038: */
039: public class InvalidGeneratorSetupException extends ConfigurationError {
040:
041: private List<PropertyMessage> propertyMessages;
042:
043: // constructors ----------------------------------------------------------------------------------------------------
044:
045: public InvalidGeneratorSetupException(
046: PropertyMessage propertyMessage) {
047: this (new PropertyMessage[] { propertyMessage });
048: }
049:
050: public InvalidGeneratorSetupException(
051: PropertyMessage... propertyMessages) {
052: this (propertyMessages, null, null);
053: }
054:
055: public InvalidGeneratorSetupException(String propertyName,
056: String propertyMessage) {
057: this (new PropertyMessage(propertyName, propertyMessage));
058: }
059:
060: public InvalidGeneratorSetupException(String textMessage) {
061: this (textMessage, (Throwable) null);
062: }
063:
064: public InvalidGeneratorSetupException(Throwable cause) {
065: this (null, cause);
066: }
067:
068: public InvalidGeneratorSetupException(String textMessage,
069: Throwable cause) {
070: this (new PropertyMessage[0], textMessage, cause);
071: }
072:
073: public InvalidGeneratorSetupException(
074: PropertyMessage[] propertyMessages, String textMessage,
075: Throwable cause) {
076: super (textMessage, cause);
077: this .propertyMessages = Arrays.asList(propertyMessages);
078: }
079:
080: // interface -------------------------------------------------------------------------------------------------------
081:
082: public PropertyMessage[] getPropertyMessages() {
083: PropertyMessage[] array = new PropertyMessage[propertyMessages
084: .size()];
085: return propertyMessages.toArray(array);
086: }
087:
088: public String toString() {
089: StringBuilder buffer = new StringBuilder(this .getClass()
090: .getName()).append(": ");
091: String textMessage = getMessage();
092: if (textMessage != null)
093: buffer.append(textMessage);
094: if (propertyMessages.size() > 0)
095: buffer.append(": ");
096: for (int i = 0; i < propertyMessages.size(); i++) {
097: PropertyMessage propertyMessage = propertyMessages.get(i);
098: buffer.append(propertyMessage);
099: if (i < propertyMessages.size())
100: buffer.append(", ");
101: }
102: return buffer.toString();
103: }
104: }
|