org.zkoss.zk.ui.impl
Class SimpleScope

java.lang.Object
  extended by org.zkoss.zk.ui.impl.SimpleScope
All Implemented Interfaces:
Scope

public class SimpleScope
extends java.lang.Object
implements Scope

A simple implementation of Scope. It supports ScopeListener, but it doesn't support the concept of parent scope. Thus, the deriving class can override getAttribute(String,boolean), hasAttribute(String,boolean), and invoke notifyParentChanged(org.zkoss.zk.ui.ext.Scope) if the parent is changed.

Not thread safe.

Since:
5.0.0
Author:
tomyeh

Constructor Summary
SimpleScope(Scope owner)
          Constructor.
 
Method Summary
 boolean addScopeListener(ScopeListener listener)
          Adds a listener to listen whether this scope is changed.
 SimpleScope clone(Scope owner)
          Clones this scope.
 java.lang.Object getAttribute(java.lang.String name)
          Returns the custom attribute associated with this object (scope).
 java.lang.Object getAttribute(java.lang.String name, boolean recurse)
          The same as getAttribute(name).
 java.util.Map<java.lang.String,java.lang.Object> getAttributes()
          Returns all custom attributes associated with this object (scope).
 java.util.List<ScopeListener> getListeners()
          Returns a ist of all scope listners (never null).
 boolean hasAttribute(java.lang.String name)
          Returns if a custom attribute is associated with this object (scope).
 boolean hasAttribute(java.lang.String name, boolean recurse)
          The same as hasAttribute(name).
 void notifyIdSpaceChanged(IdSpace newIdSpace)
          Invokes ScopeListener.idSpaceChanged(org.zkoss.zk.ui.ext.Scope, org.zkoss.zk.ui.IdSpace) for registered listeners.
 void notifyParentChanged(Scope newparent)
          Invokes ScopeListener.parentChanged(org.zkoss.zk.ui.ext.Scope, org.zkoss.zk.ui.ext.Scope) for registered listeners.
 java.lang.Object removeAttribute(java.lang.String name)
          Removes the attribute from the current scope if any.
 java.lang.Object removeAttribute(java.lang.String name, boolean recurse)
          The same as removeAttribute(name).
 boolean removeScopeListener(ScopeListener listener)
          Removes a change listener from this scope.
 java.lang.Object setAttribute(java.lang.String name, java.lang.Object value)
          Sets (aka., associates) the value for a custom attribute with this object (scope).
 java.lang.Object setAttribute(java.lang.String name, java.lang.Object value, boolean recurse)
          The same as setAttribute(name, value).
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

SimpleScope

public SimpleScope(Scope owner)
Constructor.

Parameters:
owner - the real scope that an user can access. If this object is the scope that an user accesses directly, pass null
Method Detail

getAttributes

public java.util.Map<java.lang.String,java.lang.Object> getAttributes()
Description copied from interface: Scope
Returns all custom attributes associated with this object (scope).

Specified by:
getAttributes in interface Scope

getAttribute

public java.lang.Object getAttribute(java.lang.String name)
Description copied from interface: Scope
Returns the custom attribute associated with this object (scope).

Specified by:
getAttribute in interface Scope

hasAttribute

public boolean hasAttribute(java.lang.String name)
Description copied from interface: Scope
Returns if a custom attribute is associated with this object (scope).

Notice that null is a valid value, so you can tell if an attribute is assoicated by examining the return value of Scope.getAttribute(java.lang.String).

Specified by:
hasAttribute in interface Scope

setAttribute

public java.lang.Object setAttribute(java.lang.String name,
                                     java.lang.Object value)
Description copied from interface: Scope
Sets (aka., associates) the value for a custom attribute with this object (scope).

Specified by:
setAttribute in interface Scope
Returns:
the previous value associated with the attribute, if any

removeAttribute

public java.lang.Object removeAttribute(java.lang.String name)
Description copied from interface: Scope
Removes the attribute from the current scope if any.

Specified by:
removeAttribute in interface Scope
Returns:
the previous value associated with the attribute, if any,

getAttribute

public java.lang.Object getAttribute(java.lang.String name,
                                     boolean recurse)
The same as getAttribute(name).

Specified by:
getAttribute in interface Scope
recurse - whether to search its ancestor scope. If true and the current scope doen't define the attribute, it searches up its ancestor to see any of them has defined the specified attribute.

hasAttribute

public boolean hasAttribute(java.lang.String name,
                            boolean recurse)
The same as hasAttribute(name).

Specified by:
hasAttribute in interface Scope
recurse - whether to search its ancestor scope. If true and the current scope doen't define the attribute, it searches up its ancestor to see any of them has defined the specified attribute.

setAttribute

public java.lang.Object setAttribute(java.lang.String name,
                                     java.lang.Object value,
                                     boolean recurse)
The same as setAttribute(name, value).

Specified by:
setAttribute in interface Scope
recurse - whether to look up the parent scope for the existence of the attribute.
If recurse is true and the attribute is defined in one of its ancestor (including page), the attribute is replaced. Otherwise, it is the same as Scope.setAttribute(String,Object).

removeAttribute

public java.lang.Object removeAttribute(java.lang.String name,
                                        boolean recurse)
The same as removeAttribute(name).

Specified by:
removeAttribute in interface Scope
recurse - whether to look up the parent scope for the existence of the attribute.
If recurse is true and the attribute is defined in one of its ancestor (including page), the attribute is removed. Otherwise, it is the same as Scope.removeAttribute(String).

addScopeListener

public boolean addScopeListener(ScopeListener listener)
Description copied from interface: Scope
Adds a listener to listen whether this scope is changed. The listener is called when a custom attribute is added, removed, or the parent is changed.

Specified by:
addScopeListener in interface Scope
Returns:
wether the listener is added successfully. Note: if the resolver was added before, it won't be added again and this method returns false.

removeScopeListener

public boolean removeScopeListener(ScopeListener listener)
Description copied from interface: Scope
Removes a change listener from this scope.

Specified by:
removeScopeListener in interface Scope
Returns:
false if listener is not added before.

notifyParentChanged

public void notifyParentChanged(Scope newparent)
Invokes ScopeListener.parentChanged(org.zkoss.zk.ui.ext.Scope, org.zkoss.zk.ui.ext.Scope) for registered listeners.

See Also:
addScopeListener(org.zkoss.zk.ui.ext.ScopeListener)

notifyIdSpaceChanged

public void notifyIdSpaceChanged(IdSpace newIdSpace)
Invokes ScopeListener.idSpaceChanged(org.zkoss.zk.ui.ext.Scope, org.zkoss.zk.ui.IdSpace) for registered listeners.

Since:
5.0.1
See Also:
addScopeListener(org.zkoss.zk.ui.ext.ScopeListener)

getListeners

public java.util.List<ScopeListener> getListeners()
Returns a ist of all scope listners (never null).


clone

public SimpleScope clone(Scope owner)
Clones this scope.

Parameters:
owner - the owner of the cloned scope.

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object


Copyright © 2005-2011 Potix Corporation. All Rights Reserved. SourceForge.net Logo