01: //THIS SOFTWARE IS PROVIDED BY SOFTARIS PTY.LTD. AND OTHER METABOSS
02: //CONTRIBUTORS ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING,
03: //BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
04: //FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SOFTARIS PTY.LTD.
05: //OR OTHER METABOSS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
06: //INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
07: //LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
08: //OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
09: //LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
10: //NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
11: //EVEN IF SOFTARIS PTY.LTD. OR OTHER METABOSS CONTRIBUTORS ARE ADVISED OF THE
12: //POSSIBILITY OF SUCH DAMAGE.
13: //
14: //Copyright 2000-2005 © Softaris Pty.Ltd. All Rights Reserved.
15: package tudresden.ocl.lib;
16:
17: /** This class represents the undefined object */
18: public class OclUndefined extends OclAnyImpl {
19: private static Object sDummy = new Object();
20: private String mReason;
21: private boolean mIsEmptySupported;
22: private boolean mIsEmpty;
23:
24: /** Constructs the instance of the undefined object which does not support isEmpty()
25: * functionality.
26: * @param pReason the string containing the reason the object was undefined.
27: */
28: public OclUndefined(String pReason) {
29: super (sDummy);
30: mReason = pReason;
31: mIsEmptySupported = false;
32: mIsEmpty = false;
33: }
34:
35: /** Constructs the instance of the undefined object which supports isEmpty()
36: * functionality.
37: * @param pReason the string containing the reason the object was undefined.
38: * @param pIsEmpty Object could be generaly be undefined for two reasons: (a)
39: * reference to it was null or (b) reference was valid but object itself is empty.
40: * In the latter case this parameter must be set to true. This will enable
41: * the isEmpty() method to work for the OclUndefined.
42: */
43: public OclUndefined(String pReason, boolean pIsEmpty) {
44: super (sDummy);
45: mReason = pReason;
46: mIsEmptySupported = true;
47: mIsEmpty = pIsEmpty;
48: }
49:
50: /** Method invoker */
51: public OclRoot getFeature(String methodName, Object[] params) {
52: // Work on oclIsUndefined method
53: if (methodName.equals("oclIsUndefined")
54: && (params == null || params.length == 0)) {
55: return OclBoolean.TRUE;
56: } else if (mIsEmptySupported == true
57: && methodName.equals("isEmpty")
58: && (params == null || params.length == 0)) {
59: return mIsEmpty ? OclBoolean.TRUE : OclBoolean.FALSE;
60: }
61: // Return same, therefore keeping original reason
62: return this ;
63: }
64:
65: /** Attribute getter */
66: public OclRoot getFeature(String attributeName) {
67: // Return same, therefore keeping original reason
68: return this ;
69: }
70:
71: public OclBoolean isEqualTo(Object o) {
72: if (o instanceof OclUndefined) {
73: return OclBoolean.TRUE;
74: }
75: return OclBoolean.FALSE;
76: }
77:
78: public String toString() {
79: return "OclUndefined(Reason = '" + mReason + "')";
80: }
81: }
|