org.scopemvc.core
Class Selector

java.lang.Object
  |
  +--org.scopemvc.core.Selector
Direct Known Subclasses:
IntIndexSelector, StringIndexSelector

public abstract class Selector
extends java.lang.Object

An identifier for model properties. Selectors are created by the factory methods fromString(java.lang.String) and fromInt(int). Properties can be identified by a String name (eg the "address" property of a Customer) or an integer index (eg element 1 of a List).

Selectors can be assembled in a list to identify a property in a model contained within another model. For example, the name of the pet of a Person. This Selector would be created by Selector.fromString("pet.name") and applied to a Person model object. Similarly, the name of a Person's first pet could be identified using Selector.fromString("pets.0.name") assuming that Person contains a List or array of Pets that contain a name property.

Version:
$Revision: 1.10 $ $Date: 2002/09/12 18:23:54 $
Author:
Steve Meyfroidt

Field Summary
static java.lang.String DELIMITER
          Separator character between Selectors expressed as a String.
 
Method Summary
static java.lang.String asString(Selector inSelector)
          Flatten the Selector list to a String that could be passed into fromString(java.lang.String) to recreate it.
 void chain(Selector inSelector)
           Add a Selector on the end of this list.
 Selector deepClone()
          Return a clone of the entire list of Selectors from this.
 boolean equals(java.lang.Object inObject)
           A deep compare, following down the list of selectors.
static IntIndexSelector fromInt(int inIndex)
          Make a simple Selector to identify a property at an int index.
static Selector fromString(java.lang.String inSelectorDescription)
          Make a Selector to identify a property by its String name, or to create a Selector list that identifies a property by navigating a hierarchy of submodels.
 Selector getLast()
          Get the last Selector in the list.
abstract  java.lang.String getName()
          Used to serialise Selectors asString(org.scopemvc.core.Selector) and for debug by toString().
 Selector getNext()
          Get the next Selector in the list, if any.
protected abstract  Selector getShallowCopy()
          Return a shallow copy of the head of this.
 void removeLast()
          Remove the terminal Selector.
 void removeLast(Selector terminalSelector)
          Remove the terminal Selector.
protected  void setNext(Selector inSelector)
          Set the next Selector in the list.
protected abstract  boolean shallowEquals(Selector inSelector)
          Compare the head Selector of this against the head of another Selector list -- ie a shallow compare operation (not including the chained selectors).
 boolean startsWith(Selector inSelector)
           Does this Selector list start with the list passed in?
 java.lang.String toString()
          For debug.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

DELIMITER

public static final java.lang.String DELIMITER
Separator character between Selectors expressed as a String.

See Also:
fromString(java.lang.String), asString(org.scopemvc.core.Selector), Constant Field Values
Method Detail

fromInt

public static IntIndexSelector fromInt(int inIndex)
Make a simple Selector to identify a property at an int index. eg this returns a Selector that identifies the first element of a List:
 return Selector.fromInt(0);
 

Parameters:
inIndex - The index of the property in a List
Returns:
A selector identifying a property in a List

fromString

public static Selector fromString(java.lang.String inSelectorDescription)
Make a Selector to identify a property by its String name, or to create a Selector list that identifies a property by navigating a hierarchy of submodels. For example:

Parameters:
inSelectorDescription - The string representation of a Selector
Returns:
A selector identifying a property

asString

public static java.lang.String asString(Selector inSelector)
Flatten the Selector list to a String that could be passed into fromString(java.lang.String) to recreate it.

Parameters:
inSelector - flatten this Selector to a String representation.
Returns:
String representation of the passed Selector suitable for passing back into fromString(java.lang.String) to recreate the Selector list. Return "" for null Selector.

getNext

public final Selector getNext()
Get the next Selector in the list, if any. For example,
 Selector petNameSelector = Selector.fromString("pet.name");
 return petNameSelector.getNext();
 
returns a Selector that is equals() the following Selector:
 Selector.fromString("name");
 

Returns:
The next value

getLast

public final Selector getLast()
Get the last Selector in the list. For example,
 Selector petNameSelector = Selector.fromString("pets.1.name");
 return petNameSelector.getLast();
 
returns a Selector that is equals() the following Selector:
 Selector.fromString("name");
 

Returns:
The last value

getName

public abstract java.lang.String getName()
Used to serialise Selectors asString(org.scopemvc.core.Selector) and for debug by toString().

Returns:
The name value

chain

public final void chain(Selector inSelector)

Add a Selector on the end of this list.

For example:

 Selector petSelector = Selector.fromString("pet");
 Selector nameSelector = Selector.fromString("name");
 petSelector.chain(nameSelector);
 return petSelector;
 
returns a Selector that is equals() this one:
 Selector.fromString("pet.name");
 

Parameters:
inSelector - The Selector to chain at the end of the current Selector

removeLast

public final void removeLast()
Remove the terminal Selector. Throws UnsupportedOperationException if Selector has no chain.


removeLast

public final void removeLast(Selector terminalSelector)
Remove the terminal Selector. Throws UnsupportedOperationException if Selector has no chain or does no ends with the passed terminal selector.

Parameters:
terminalSelector - TODO: Describe the Parameter

startsWith

public final boolean startsWith(Selector inSelector)

Does this Selector list start with the list passed in?

For example, this returns true:

 Selector petSelector = Selector.fromString("pet");
 Selector petNameSelector = Selector.fromString("pet.name");
 return (petNameSelector.startsWith(petSelector));
 
but this returns false:
 Selector nameSelector = Selector.fromString("name");
 Selector petNameSelector = Selector.fromString("pet.name");
 return (petNameSelector.startsWith(nameSelector));
 

Parameters:
inSelector - A Selector
Returns:
True if this Selector list start with the list passed in

equals

public final boolean equals(java.lang.Object inObject)

A deep compare, following down the list of selectors.

For example, this returns true:

 Selector petSelector = Selector.fromString("pet");
 Selector nameSelector = Selector.fromString("name");
 Selector petNameSelector = Selector.fromString("pet.name");
 petSelector.chain(nameSelector);
 return (petSelector.equals(petNameSelector));
 
but this returns false:
 Selector petSelector = Selector.fromString("pet");
 Selector petNameSelector = Selector.fromString("pet.name");
 return (petSelector.equals(petNameSelector));
 

Overrides:
equals in class java.lang.Object
Parameters:
inObject - An Object to test for equality, mostly another Selector
Returns:
true if this Selector and the passed object are equal, including the chained Selectors in the list.

deepClone

public final Selector deepClone()
Return a clone of the entire list of Selectors from this.

Returns:
A complete close of this Selector.

toString

public final java.lang.String toString()
For debug.

Overrides:
toString in class java.lang.Object
Returns:
A string representation of this Selector

getShallowCopy

protected abstract Selector getShallowCopy()
Return a shallow copy of the head of this.

Returns:
The shallowCopy value

setNext

protected final void setNext(Selector inSelector)
Set the next Selector in the list.

Parameters:
inSelector - Selector to set as the next in the list after this
See Also:
chain(org.scopemvc.core.Selector)

shallowEquals

protected abstract boolean shallowEquals(Selector inSelector)
Compare the head Selector of this against the head of another Selector list -- ie a shallow compare operation (not including the chained selectors).

Parameters:
inSelector - The Selector to test
Returns:
true if there is equality between this Selector and the other Selector, excluding the other chained Selectors.


Copyright © 2000-2002 The Scope Team. All Rights Reserved.