/*=============================================================================
* Copyright Texas Instruments 2002. All Rights Reserved.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package ti.chimera.registry;
/**
* A <code>NodeContract</code> establishes what sorts of values can be stored
* in a node in the registry. The contract is set at node creation time, and
* does not change during the node's lifecycle. (But, from the consumer's
* point of view, the node <i>instance</i> at a particular path may change,
* and bring with it a new contract.)
* <p>
* Also, contracts are comparable, so that the consumer of node data can
* provide a contract... if the consumer's contract is equal to, or a subset
* of, the node's contract, then the consumer is happy. In other words, the
* consumer wants to know that there is no value that will pass the node's
* contract, but not the consumer's contract.
*
* @author ;Rob Clark;a0873619;San Diego;;
* @version 0.1
*/
public interface NodeContract
{
/**
* A contract that checks that the type of the value is a {@link #java.lang.String}.
*/
public NodeContract STRING_CONTRACT = new TypeNodeContract( String.class );
/**
* A contract that checks that the type of the value is a {@link #java.lang.Boolean}.
*/
public NodeContract BOOLEAN_CONTRACT = new TypeNodeContract( Boolean.class );
/**
* A contract that checks that the type of the value is a {@link #java.lang.Number}.
*/
public NodeContract NUMBER_CONTRACT = new TypeNodeContract( Number.class );
/**
* A contract that accepts any change.
*/
public NodeContract NULL_CONTRACT = new NullNodeContract();
/**
* Determine if the specified <code>value</code> meets this contract.
*
* @param value the value to check
* @return <code>true</code> if meets contract
*/
public boolean accepts( Object value );
/**
* The contract implementation should overload <code>toString</code> so
* the contract can be displayed to the user in a sane format, for use
* in error messages, etc.
*/
public String toString();
}
class NullNodeContract
implements NodeContract
{
public boolean accepts( Object value )
{
return true;
}
public String toString()
{
return "(value == value)";
}
}
/*
* Local Variables:
* tab-width: 2
* indent-tabs-mode: nil
* mode: java
* c-indentation-style: java
* c-basic-offset: 2
* eval: (c-set-offset 'substatement-open '0)
* eval: (c-set-offset 'case-label '+)
* eval: (c-set-offset 'inclass '+)
* eval: (c-set-offset 'inline-open '0)
* End:
*/
|