Class Scopes
Scope).
Since 10.0.0, there two library properties to control the scope lock cache:
- org.zkoss.zk.ui.ext.Scopes.maxLockSize: the maximum number of locks to be cached. (Default: 10,000)
- org.zkoss.zk.ui.ext.Scopes.maxTimeout: the maximum time a lock can be cached in minutes after accessing it. (Default: 60 minutes)
- Since:
- 5.0.0
- Author:
- tomyeh
-
Method Summary
Modifier and TypeMethodDescriptionstatic final voidUsed withbeforeInterpret(org.zkoss.zk.ui.ext.Scope)to clean up implicit variables.static final ScopebeforeInterpret(Scope scope) Prepares implicit variable before callingPage.interpret(java.lang.String, java.lang.String, org.zkoss.zk.ui.ext.Scope).static final ScopegetCurrent(Page page) Returns the current scope.static ObjectgetImplicit(String name, Object defValue) Returns the implicit object.static ObjectgetLockForScopeIfAny(Scope scope) Returns a consistent lock for a given scope, if available.static voidsetImplicit(String name, Object value) Sets an implicit object.
-
Method Details
-
getLockForScopeIfAny
Returns a consistent lock for a given scope, if available.The method returns a lock object specific to the provided scope, allowing for fine-grained synchronization control. If no lock is associated with the scope, the method returns a fallback lock instead.
Usage of this method is preferred over manual synchronization or lock management, as it provides a standardized approach to handling concurrency in a scope-based context.
- Parameters:
scope- The scope for which the lock is to be acquired.- Returns:
- The lock object associated with the given scope, if any; otherwise, a static fallback lock.
- Since:
- 10.0.0
-
beforeInterpret
Prepares implicit variable before callingPage.interpret(java.lang.String, java.lang.String, org.zkoss.zk.ui.ext.Scope).Typical use:
final Scope scope = Scopes.beforeInterpret(comp); try { Scopes.setImplicit("some", value); page.interpret(zslang, zscript, scope); //it will push scope as the current scope } finally { Scopes.afterInterpret(); }Another example:
Scopes.beforeInterpret(comp); try { constr.validate(comp); //if constr might be an instance of a class implemented in zscript } finally { Scopess.afterInterpret(); }If you need to set some implicit variables, you can invoke
setImplicit(java.lang.String, java.lang.Object)betweenbeforeInterpret(org.zkoss.zk.ui.ext.Scope)andafterInterpret().- Parameters:
scope- the scope, never null.- Returns:
- the scope used for interpretation. It is the same as the scope parameter if it is not null. Otherwise, a temporary scope is created.
-
afterInterpret
public static final void afterInterpret()Used withbeforeInterpret(org.zkoss.zk.ui.ext.Scope)to clean up implicit variables. -
setImplicit
Sets an implicit object. It can be called only betweenbeforeInterpret(org.zkoss.zk.ui.ext.Scope)andafterInterpret(). -
getImplicit
Returns the implicit object.It searches the implicit object stored with
setImplicit(java.lang.String, java.lang.Object), and also searches the system implicit objects by use ofComponents.getImplicit(Page, Component, String).- Parameters:
name- the variable to retrievedefValue- the default vale that is used if the implicit object is not defined.
-
getCurrent
Returns the current scope. The current scope is the event target's scope if this thread is processing an event (Event.getTarget(). Otherwise, the scope of the page specified is assumed.This method is used only to implement
Interpreter. You rarely need to access it other than implementing an interpreter.- Parameters:
page- the page. It is used ifbeforeInterpret(org.zkoss.zk.ui.ext.Scope)is not called before. If null, the current page (ExecutionCtrl.getCurrentPage()is assumed.
-