Source code: com/webobjects/woextensions/WOKeyValueConditional.java
1 /*
2 * WOKeyValueConditional.java
3 * © Copyright 2001 Apple Computer, Inc. All rights reserved.
4 * This a modified version.
5 * Original license: http://www.opensource.apple.com/apsl/
6 */
7
8 package com.webobjects.woextensions;
9
10 import com.webobjects.appserver.*;
11 import com.webobjects.foundation.*;
12
13 public class WOKeyValueConditional extends WOComponent {
14 protected String _key;
15 protected int _negate = -1; // -1 is invalid, 0 is false, and 1 is true
16
17 public WOKeyValueConditional(WOContext aContext) {
18 super(aContext);
19 }
20
21 public boolean condition() {
22 Object parentValue = parent().valueForKeyPath(key());
23 Object thisValue = valueForBinding("value");
24 return (parentValue == null) ? (thisValue == null) : (parentValue.equals(thisValue));
25 }
26
27 public String key() {
28 if (_key == null) {
29 _key = (String)_WOJExtensionsUtil.valueForBindingOrNull("key",this);
30 }
31 return _key;
32 }
33
34 public boolean negate() {
35 if (_negate == -1) {
36 Object thisNegate = valueForBinding("negate");
37 if (thisNegate == null) {
38 _negate = 0;
39 } else if (thisNegate instanceof Boolean) {
40 _negate = (((Boolean) thisNegate).booleanValue()) ? 1 : 0;
41 } else if (thisNegate instanceof Integer) {
42 _negate = (((Integer) thisNegate).intValue() == 0) ? 0 : 1;
43 } else if (thisNegate instanceof String) {
44 _negate = (new Boolean((String) thisNegate)).booleanValue() ? 1 : 0;
45 } else {
46 _negate = 0;
47 }
48 }
49 return _negate != 0;
50 }
51
52 public boolean isStateless() {
53 return true;
54 }
55
56 protected void _invalidateCaches() {
57 // In order for this to behave like an element, all instance
58 // variables need to be flushed when this component sleeps
59 // so that it will pull via association.
60 _key = null;
61 _negate = -1;
62 }
63
64 public void reset() {
65 _invalidateCaches();
66 }
67 }