001: /*
002: * $Id: MissingRequiredPropertyException.java,v 1.20 2007/05/21 08:34:42 agoubard Exp $
003: *
004: * Copyright 2003-2007 Orange Nederland Breedband B.V.
005: * See the COPYRIGHT file for redistribution and use restrictions.
006: */
007: package org.xins.common.collections;
008:
009: import org.xins.common.text.TextUtils;
010:
011: /**
012: * Exception thrown to indicate a required property has no value set for it.
013: *
014: * @version $Revision: 1.20 $ $Date: 2007/05/21 08:34:42 $
015: * @author <a href="mailto:ernst@ernstdehaan.com">Ernst de Haan</a>
016: *
017: * @since XINS 1.0.0
018: *
019: * @see InvalidPropertyValueException
020: */
021: public final class MissingRequiredPropertyException extends Exception {
022:
023: /**
024: * The name of the property. Never <code>null</code>.
025: */
026: private final String _propertyName;
027:
028: /**
029: * Detailed description of why this property is required in the current
030: * context. Can be <code>null</code>.
031: */
032: private final String _detail;
033:
034: /**
035: * Constructs a new <code>MissingRequiredPropertyException</code>, with the
036: * specified detail message.
037: *
038: * @param propertyName
039: * the name of the required property, not <code>null</code>.
040: *
041: * @param detail
042: * a more detailed description of why this property is required in this
043: * context, can be <code>null</code>.
044: *
045: * @throws IllegalArgumentException
046: * if <code>propertyName == null</code>.
047: *
048: * @since XINS 1.3.0
049: */
050: public MissingRequiredPropertyException(String propertyName,
051: String detail) throws IllegalArgumentException {
052:
053: // Construct message and call superclass constructor
054: super (createMessage(propertyName, detail));
055:
056: // Store data
057: _propertyName = propertyName;
058: _detail = TextUtils.trim(detail, null);
059: }
060:
061: /**
062: * Constructs a new <code>MissingRequiredPropertyException</code>.
063: *
064: * @param propertyName
065: * the name of the required property, not <code>null</code>.
066: *
067: * @throws IllegalArgumentException
068: * if <code>propertyName == null</code>.
069: */
070: public MissingRequiredPropertyException(String propertyName)
071: throws IllegalArgumentException {
072: this (propertyName, null);
073: }
074:
075: /**
076: * Creates message based on the specified constructor argument.
077: *
078: * @param propertyName
079: * the name of the property, cannot be <code>null</code>.
080: *
081: * @param detail
082: * a more detailed description of why this property is required in this
083: * context, can be <code>null</code>.
084: *
085: * @return
086: * the message, never <code>null</code>.
087: */
088: private static String createMessage(String propertyName,
089: String detail) {
090:
091: // Construct the message
092: String message = "No value is set for the required property \""
093: + propertyName;
094:
095: // Append the detail message, if any
096: detail = TextUtils.trim(detail, null);
097: if (detail != null) {
098: message += "\": " + detail;
099: } else {
100: message += "\".";
101: }
102:
103: return message;
104: }
105:
106: /**
107: * Returns the name of the property.
108: *
109: * @return
110: * the name of the property, never <code>null</code>.
111: */
112: public String getPropertyName() {
113: return _propertyName;
114: }
115:
116: /**
117: * Returns the detail message.
118: *
119: * @return
120: * the trimmed detail message, can be <code>null</code>.
121: *
122: * @since XINS 1.3.0
123: */
124: public String getDetail() {
125: return _detail;
126: }
127: }
|