com.sas.collection
Class CollectionMirror

com.sas.collection.CollectionMirror
All Implemented Interfaces:
com.sas.beans.PropertyChangeSource, com.sas.beans.VetoableChangeSource, com.sas.collection.ContentsChangedListener, com.sas.collection.ContentsChangedSource, StaticCollectionInterface, ComponentInterface, LinkPropertiesInterface, ModelInterface, com.sas.PublicClonable, com.sas.util.Countable, com.sas.util.Enumerable, com.sas.util.EventGateInterface, ViewInterface, MultipleValueEventSourceInterface, java.beans.PropertyChangeListener, java.io.ObjectInputValidation, java.io.Serializable, java.lang.Cloneable, java.util.EventListener
Direct Known Subclasses:
StaticCollection, StaticStringList

public abstract class CollectionMirror
implements com.sas.collection.ContentsChangedListener

A CollectionMirror is an abstract base class for other read-only collections which "reflect" other collections. That is, the mirror class provides read-only access to another collection, but does not provide update methods. A CollectionMirror is useful for classes which wish to provide read-only access to collections they manage internally, but do not wish to allow other objects to change those internal collection.

See StaticOrderedCollection for a case when a CollectionMirror is used.

The CollectionMirror manages ContentsChangedEvents. The mirror allows listeners to listen for ContentsChangeEvents. If the mirror has listeners, then the mirror will itself listen for ContentsChangeEvents from the original collection, and when it changes, the mirror will send a ContentsChangeEvent to all listeners. If all listeners detach from the mirror, the mirror will remove itself from the original collection.

This is an important note, because as long as there are listeners, the mirror object will itself be a listener on the original collection, which means the mirror cannot be garbage collected (the reflected collection has a reference to the mirror in its ContentsChangedEvent listener list.)

See Also:
StaticCollection, StaticOrderedCollection, StaticDictionary, StaticStringList, Serialized Form

Field Summary
 
Fields inherited from class com.sas.collection.BaseCollection
allContentsChangedListeners, mappingObject
 
Constructor Summary
protected CollectionMirror(com.sas.collection.ContentsChangedSource source)
          Construct a collection mirror.
 
Method Summary
 void addContentsChangedListener(com.sas.collection.ContentsChangedListener listener)
          Add a listener for the com.sas.util.ContentsChangedEvent event.
 java.lang.Object clone()
          Clone the collection.
 void contentsChanged(com.sas.collection.ContentsChangedEvent event)
          Handle a change event from the original collection.
 boolean equals(java.lang.Object object)
          Test object equality.
protected  com.sas.collection.ContentsChangedSource getSource()
          Return the source object that was passed in to the constructor.
 int hashCode()
          Compute the object's hash code.
 void removeContentsChangedListener(com.sas.collection.ContentsChangedListener listener)
          Remove a listener for the com.sas.util.ContentsChangedEvent event.
 java.lang.String toString()
          Convert the object to a string.
 
Methods inherited from class com.sas.collection.BaseCollection
anyContentsChangedListeners, apply, contains, count, disableEvents, enableEvents, enableEvents, fireContentsChanged, getItems, map, unmap
 
Methods inherited from class com.sas.Component
addLink, addPropertyChangeListener, addVetoableChangeListener, anyPropertyChangeListeners, attachModel, attachView, beansIsDesignTime, beansSetDesignTime, clone, detachModel, detachView, dumpComponent, firePropertyChange, firePropertyChange, fireVetoableChange, getComponentDescription, getComponentSupportInfo, getEventMethod, getEventValues, getExtendedBeanInfo, getLinkInfo, getModelInterface, getRequiredInterfaces, getResources, getStringResource, getViewInterfaceSupportInfo, initialize, initializeComponent, isDesignTime, isLinked, propertyChange, queryLinks, queryLinks, refresh, removeAllLinks, removeInterfaceTraps, removeLink, removePropertyChangeListener, removeVetoableChangeListener, setComponentDescription, setComponentSupportInfo, setDefaultValues, setLinkInfo, setModelInterface, setRequiredInterfaces, setViewInterfaceSupportInfo, supportsListenerInterface, supportsRequiredInterfaces, trapInterfaceEvents, validateObject
 
Methods inherited from interface com.sas.beans.PropertyChangeSource
addPropertyChangeListener, removePropertyChangeListener
 

Constructor Detail

CollectionMirror

protected CollectionMirror(com.sas.collection.ContentsChangedSource source)
Construct a collection mirror. This object will reflect the source collection.

Parameters:
source - another collection that acts as a source of ContentsChangedEvent events.
Method Detail

getSource

protected final com.sas.collection.ContentsChangedSource getSource()
Return the source object that was passed in to the constructor. This method is not public, because the mirror owner may not want to reveal the source collection.

Returns:
the source collection that this mirror reflects.

addContentsChangedListener

public void addContentsChangedListener(com.sas.collection.ContentsChangedListener listener)
Add a listener for the com.sas.util.ContentsChangedEvent event.

Specified by:
addContentsChangedListener in interface com.sas.collection.ContentsChangedSource
Overrides:
addContentsChangedListener in class BaseCollection
Parameters:
listener - an object which handles ContentsChangedEvent events the listener is not added a second time if it already exists in the list of listeners for this event.
See Also:
ContentsChangedSource

removeContentsChangedListener

public void removeContentsChangedListener(com.sas.collection.ContentsChangedListener listener)
Remove a listener for the com.sas.util.ContentsChangedEvent event. Nothing happens if the listener is not in the list of listeners for this event.

Specified by:
removeContentsChangedListener in interface com.sas.collection.ContentsChangedSource
Overrides:
removeContentsChangedListener in class BaseCollection
Parameters:
listener - an object which handles ContentsChangedEvent events
See Also:
ContentsChangedSource

contentsChanged

public void contentsChanged(com.sas.collection.ContentsChangedEvent event)
Handle a change event from the original collection. A new ContentsChangedEvent is fired, with this mirror as the source (since this mirror is what the listener is listening to, we should not simply resend the event, since it's getSourc() method would then reveal the identity of the actual collection we're mirroring.)

Specified by:
contentsChanged in interface com.sas.collection.ContentsChangedListener
Parameters:
event - an event from the original source.

toString

public java.lang.String toString()
Convert the object to a string. This defers to the underlying collection.

Overrides:
toString in class java.lang.Object

clone

public java.lang.Object clone()
                       throws java.lang.CloneNotSupportedException
Clone the collection.

Specified by:
clone in interface StaticCollectionInterface
Specified by:
clone in interface com.sas.PublicClonable
Overrides:
clone in class BaseCollection
Returns:
a clone of the mirror. The underlying collection is also cloned, if it is PublicClonable.
Throws:
java.lang.CloneNotSupportedException - is the mirror or the underlying collection cannot be cloned.

hashCode

public int hashCode()
Compute the object's hash code.

Overrides:
hashCode in class java.lang.Object
Returns:
the underlying component's hash code.

equals

public boolean equals(java.lang.Object object)
Test object equality.

Overrides:
equals in class java.lang.Object
Returns:
true if this object equals another object, else return false



Copyright © 2009 SAS Institute Inc. All Rights Reserved.