01: /*=============================================================================
02: * Copyright Texas Instruments 2002. All Rights Reserved.
03: *
04: * This program is free software; you can redistribute it and/or modify
05: * it under the terms of the GNU General Public License as published by
06: * the Free Software Foundation; either version 2 of the License, or
07: * (at your option) any later version.
08: *
09: * This program is distributed in the hope that it will be useful,
10: * but WITHOUT ANY WARRANTY; without even the implied warranty of
11: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12: * GNU General Public License for more details.
13: *
14: * You should have received a copy of the GNU General Public License
15: * along with this program; if not, write to the Free Software
16: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17: */
18:
19: package ti.chimera.registry;
20:
21: /**
22: * A <code>NodeContract</code> establishes what sorts of values can be stored
23: * in a node in the registry. The contract is set at node creation time, and
24: * does not change during the node's lifecycle. (But, from the consumer's
25: * point of view, the node <i>instance</i> at a particular path may change,
26: * and bring with it a new contract.)
27: * <p>
28: * Also, contracts are comparable, so that the consumer of node data can
29: * provide a contract... if the consumer's contract is equal to, or a subset
30: * of, the node's contract, then the consumer is happy. In other words, the
31: * consumer wants to know that there is no value that will pass the node's
32: * contract, but not the consumer's contract.
33: *
34: * @author ;Rob Clark;a0873619;San Diego;;
35: * @version 0.1
36: */
37: public interface NodeContract {
38: /**
39: * A contract that checks that the type of the value is a {@link #java.lang.String}.
40: */
41: public NodeContract STRING_CONTRACT = new TypeNodeContract(
42: String.class);
43:
44: /**
45: * A contract that checks that the type of the value is a {@link #java.lang.Boolean}.
46: */
47: public NodeContract BOOLEAN_CONTRACT = new TypeNodeContract(
48: Boolean.class);
49:
50: /**
51: * A contract that checks that the type of the value is a {@link #java.lang.Number}.
52: */
53: public NodeContract NUMBER_CONTRACT = new TypeNodeContract(
54: Number.class);
55:
56: /**
57: * A contract that accepts any change.
58: */
59: public NodeContract NULL_CONTRACT = new NullNodeContract();
60:
61: /**
62: * Determine if the specified <code>value</code> meets this contract.
63: *
64: * @param value the value to check
65: * @return <code>true</code> if meets contract
66: */
67: public boolean accepts(Object value);
68:
69: /**
70: * The contract implementation should overload <code>toString</code> so
71: * the contract can be displayed to the user in a sane format, for use
72: * in error messages, etc.
73: */
74: public String toString();
75: }
76:
77: class NullNodeContract implements NodeContract {
78: public boolean accepts(Object value) {
79: return true;
80: }
81:
82: public String toString() {
83: return "(value == value)";
84: }
85: }
86:
87: /*
88: * Local Variables:
89: * tab-width: 2
90: * indent-tabs-mode: nil
91: * mode: java
92: * c-indentation-style: java
93: * c-basic-offset: 2
94: * eval: (c-set-offset 'substatement-open '0)
95: * eval: (c-set-offset 'case-label '+)
96: * eval: (c-set-offset 'inclass '+)
97: * eval: (c-set-offset 'inline-open '0)
98: * End:
99: */
|