01: /* Copyright 2004 The JA-SIG Collaborative. All rights reserved.
02: * See license distributed with this file and
03: * available online at http://www.uportal.org/license.html
04: */
05:
06: package org.jasig.portal.properties;
07:
08: /**
09: * An undeclared (Runtime) exception to be thrown by the PropertiesManager
10: * when a property is requested but cannot be found.
11: * @author andrew.petro@yale.edu
12: * @version $Revision: 35626 $ $Date: 2005-04-18 18:19:03 -0700 (Mon, 18 Apr 2005) $
13: * @since uPortal 2.4
14: */
15: public class MissingPropertyException extends RuntimeException {
16:
17: /** The name of the missing property.*/
18: private final String propertyName;
19:
20: /** True if a prior MissingPropertyException has been thrown for this
21: * missing property by the throwing object if it keeps track. False otherwise.
22: */
23: private final boolean alreadyReported;
24:
25: /**
26: * Instantiate a MissingPropertyException for a particular missing property.
27: * @param propertyName - the name of the property the value of which could not be found.
28: */
29: public MissingPropertyException(String propertyName) {
30: this .propertyName = propertyName;
31: this .alreadyReported = false;
32: }
33:
34: /**
35: * Instantiate a MissingPropertyException for a particular missing property,
36: * indicating whether the throwing object has already thrown a MissingPropertyException for this
37: * property.
38: * @param propertyName name of missing property
39: * @param alreadyReported true if already reported
40: */
41: public MissingPropertyException(String propertyName,
42: boolean alreadyReported) {
43: this .propertyName = propertyName;
44: this .alreadyReported = alreadyReported;
45: }
46:
47: /**
48: * Instantiate a MissingPropertyException for a particular missing property,
49: * indicating whether the throwing object has already thrown a MissingPropertyException for this
50: * property, and supplying an underlying cause.
51: * @param propertyName name of missing property
52: * @param alreadyReported true if already reported
53: * @param cause underlying cause
54: */
55: public MissingPropertyException(String propertyName,
56: boolean alreadyReported, Throwable cause) {
57: super (cause);
58: this .propertyName = propertyName;
59: this .alreadyReported = alreadyReported;
60: }
61:
62: public String getMessage() {
63: return "The property [" + this .propertyName
64: + "] could not be found.";
65: }
66:
67: /**
68: * Has the throwing object already reported (thrown a MissingPropertyException for) this
69: * particular missing property.
70: * Objects handling this exception might choose to predicate their logging detail on this
71: * property, for instance.
72: * @return Returns true this property has already
73: * been reported as missing by the throwing object.
74: */
75: public boolean isAlreadyReported() {
76: return this .alreadyReported;
77: }
78:
79: /**
80: * Get the name of the missing property.
81: * @return Returns the name of the missing property.
82: */
83: public String getPropertyName() {
84: return this.propertyName;
85: }
86: }
|