commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jstrac...@apache.org
Subject cvs commit: jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly JellyContext.java
Date Mon, 15 Jul 2002 16:56:49 GMT
jstrachan    2002/07/15 09:56:49

  Modified:    jelly/src/java/org/apache/commons/jelly JellyContext.java
  Log:
  Removed unnecessary methods getScopedVariable() and setScopedVariable().
  Also provided support for 'scopes' such as {parent, application, session, request} and so
forth. 
  
  Revision  Changes    Path
  1.16      +55 -14    jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/JellyContext.java
  
  Index: JellyContext.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/JellyContext.java,v
  retrieving revision 1.15
  retrieving revision 1.16
  diff -u -r1.15 -r1.16
  --- JellyContext.java	15 Jul 2002 12:13:20 -0000	1.15
  +++ JellyContext.java	15 Jul 2002 16:56:49 -0000	1.16
  @@ -181,22 +181,18 @@
           return this.shouldInherit;
       }
   
  -    public Object getScopedVariable(String name) {
  -        if ( getInherit() ) {
  -            return findVariable( name );
  -        }
  -
  -        return getVariable( name );
  -    }
  -
  -    public void setScopedVariable(String name, Object value) {
  -        if ( getExport() && getParent() != null ) {
  -            getParent().setScopedVariable( name, value );
  -        } else {
  -            setVariable( name, value );
  +    /**
  +     * @return the scope of the given name, such as the 'parent' scope.
  +     * If Jelly is used in a Servlet situation then 'request', 'session' and 'application'
are other names 
  +     * for scopes
  +     */
  +    public JellyContext getScope(String name) {
  +        if ( "parent".equals( name ) ) {
  +            return getParent();
           }
  +        return null;
       }
  -
  +    
       /** 
        * Finds the variable value of the given name in this context or in any other parent
context.
        * If this context does not contain the variable, then its parent is used and then
its parent 
  @@ -226,6 +222,22 @@
   
           return value;
       }
  +    
  +    /** 
  +     * @return the value of the given variable name in the given variable scope 
  +     * @param name is the name of the variable
  +     * @param scopeName is the optional scope name such as 'parent'. For servlet environments
  +     * this could be 'application', 'session' or 'request'.
  +     */
  +    public Object getVariable(String name, String scopeName) {
  +        JellyContext scope = getScope(scopeName);
  +        if ( scope != null ) {
  +            return scope.getVariable(name);
  +        }
  +        return null;
  +    }
  +    
  +    
   
       /** Sets the value of the given variable name */
       public void setVariable(String name, Object value) {
  @@ -241,11 +253,40 @@
           }
       }
   
  +    /** 
  +     * Sets the value of the given variable name in the given variable scope 
  +     * @param name is the name of the variable
  +     * @param scopeName is the optional scope name such as 'parent'. For servlet environments
  +     *  this could be 'application', 'session' or 'request'.
  +     * @param value is the value of the attribute
  +     */
  +    public void setVariable(String name, String scopeName, Object value) {
  +        JellyContext scope = getScope(scopeName);
  +        if ( scope != null ) {
  +            scope.setVariable(name, value);
  +        }
  +    }
  +    
       /** Removes the given variable */
       public void removeVariable(String name) {
           variables.remove(name);
       }
   
  +    /** 
  +     * Removes the given variable in the specified scope.
  +     * 
  +     * @param name is the name of the variable
  +     * @param scopeName is the optional scope name such as 'parent'. For servlet environments
  +     *  this could be 'application', 'session' or 'request'.
  +     * @param value is the value of the attribute
  +     */
  +    public void removeVariable(String name, String scopeName) {
  +        JellyContext scope = getScope(scopeName);
  +        if ( scope != null ) {
  +            scope.removeVariable(name);
  +        }
  +    }
  +    
       /** 
        * @return an Iterator over the current variable names in this
        * context 
  
  
  

--
To unsubscribe, e-mail:   <mailto:commons-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:commons-dev-help@jakarta.apache.org>


Mime
View raw message