com.threerings.expr
Class DynamicScope

java.lang.Object
  extended by com.threerings.expr.DynamicScope
All Implemented Interfaces:
Scope, ScopeUpdateListener
Direct Known Subclasses:
GlApp, Model, RenderEffect, Scene, TudeySceneView

public class DynamicScope
extends Object
implements Scope, ScopeUpdateListener

A Scope that allows dynamic reparenting and the addition and removal of symbols. Can be used either as a base class or as a contained object.


Field Summary
protected  int _compoundDepth
          The compound update depth.
protected  WeakObserverList<ScopeUpdateListener> _listeners
          The listeners to this scope.
protected  Object _owner
          The owner of this scope.
protected  Scope _parentScope
          A reference to the parent scope.
protected  String _scopeName
          The name of this scope.
protected  HashMap<String,Object> _symbols
          The mappings for the dynamic symbols in this scope.
protected static Scope INVALID_SCOPE
          Used to force initialization.
 
Fields inherited from interface com.threerings.expr.Scope
EPOCH, NOW
 
Constructor Summary
DynamicScope(Object owner, String name)
          Creates a new scope.
DynamicScope(Object owner, String name, Scope parent)
          Creates a new scope with the supplied scope as its parent.
DynamicScope(String name)
          Creates a new scope that is its own owner.
DynamicScope(String name, Scope parent)
          Creates a new scope that is its own owner with the supplied scope as its parent.
 
Method Summary
 void addListener(ScopeUpdateListener listener)
          Adds a listener for changes in scope.
 void dispose()
          Releases the resources associated with this scope.
 void endCompoundUpdate()
          Ends a compound update.
<T> T
get(String name, Class<T> clazz)
          Looks up a symbol in this scope.
 Scope getParentScope()
          Returns a reference to the parent scope, or null if this is the top level.
 String getScopeName()
          Returns the name of this scope for purposes of qualification.
 void put(String name, Object value)
          Sets the mapping for the named symbol in this scope.
 void remove(String name)
          Removes the named symbol from this scope.
 void removeListener(ScopeUpdateListener listener)
          Removes a listener for changes in scope.
 void scopeUpdated(ScopeEvent event)
          Called when the scope has been updated.
 void setParentScope(Scope parent)
          Sets the parent of this scope.
 void startCompoundUpdate()
          Starts a compound update.
 void wasUpdated()
          Notes that this scope has been updated.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

_owner

protected Object _owner
The owner of this scope.


_scopeName

protected String _scopeName
The name of this scope.


_parentScope

protected Scope _parentScope
A reference to the parent scope.


_compoundDepth

protected int _compoundDepth
The compound update depth.


_symbols

protected HashMap<String,Object> _symbols
The mappings for the dynamic symbols in this scope.


_listeners

protected WeakObserverList<ScopeUpdateListener> _listeners
The listeners to this scope.


INVALID_SCOPE

protected static final Scope INVALID_SCOPE
Used to force initialization.

Constructor Detail

DynamicScope

public DynamicScope(String name)
Creates a new scope that is its own owner.


DynamicScope

public DynamicScope(String name,
                    Scope parent)
Creates a new scope that is its own owner with the supplied scope as its parent.


DynamicScope

public DynamicScope(Object owner,
                    String name)
Creates a new scope.


DynamicScope

public DynamicScope(Object owner,
                    String name,
                    Scope parent)
Creates a new scope with the supplied scope as its parent.

Method Detail

setParentScope

public void setParentScope(Scope parent)
Sets the parent of this scope.


put

public void put(String name,
                Object value)
Sets the mapping for the named symbol in this scope.


remove

public void remove(String name)
Removes the named symbol from this scope.


startCompoundUpdate

public void startCompoundUpdate()
Starts a compound update. Update notifications will be deferred until endCompoundUpdate() is called.


endCompoundUpdate

public void endCompoundUpdate()
Ends a compound update.


wasUpdated

public void wasUpdated()
Notes that this scope has been updated.


dispose

public void dispose()
Releases the resources associated with this scope.


getScopeName

public String getScopeName()
Description copied from interface: Scope
Returns the name of this scope for purposes of qualification. Can return null if qualified symbols cannot specifically address this scope.

Specified by:
getScopeName in interface Scope

getParentScope

public Scope getParentScope()
Description copied from interface: Scope
Returns a reference to the parent scope, or null if this is the top level.

Specified by:
getParentScope in interface Scope

get

public <T> T get(String name,
                 Class<T> clazz)
Description copied from interface: Scope
Looks up a symbol in this scope.

Specified by:
get in interface Scope
Returns:
the mapping for the requested symbol, or null if not found.

addListener

public void addListener(ScopeUpdateListener listener)
Description copied from interface: Scope
Adds a listener for changes in scope. The listener will be notified when symbols are added or removed and whenever the scope hierarchy changes.

Specified by:
addListener in interface Scope

removeListener

public void removeListener(ScopeUpdateListener listener)
Description copied from interface: Scope
Removes a listener for changes in scope.

Specified by:
removeListener in interface Scope

scopeUpdated

public void scopeUpdated(ScopeEvent event)
Description copied from interface: ScopeUpdateListener
Called when the scope has been updated.

Specified by:
scopeUpdated in interface ScopeUpdateListener