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/impl DynamicTagLibrary.java
Date Thu, 05 Sep 2002 13:31:36 GMT
jstrachan    2002/09/05 06:31:36

  Modified:    jelly/src/java/org/apache/commons/jelly/impl
                        DynamicTagLibrary.java
  Log:
  Added support for inheritence of dynamic tag libraries. This allows individual tags to be
overloaded from an existing library or from a dynamic library.
  
  Revision  Changes    Path
  1.2       +30 -4     jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/impl/DynamicTagLibrary.java
  
  Index: DynamicTagLibrary.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/impl/DynamicTagLibrary.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- DynamicTagLibrary.java	9 Aug 2002 17:26:40 -0000	1.1
  +++ DynamicTagLibrary.java	5 Sep 2002 13:31:35 -0000	1.2
  @@ -85,6 +85,7 @@
   
       private String uri;
       private Map templates = new HashMap();
  +    private TagLibrary parent;
   
       public DynamicTagLibrary() {
       }
  @@ -94,13 +95,23 @@
       }
   
       /** Creates a new script to execute the given tag name and attributes */
  -    public TagScript createTagScript(final String name, Attributes attributes)
  +    public TagScript createTagScript(final String name, final Attributes attributes)
           throws Exception {
   
           return new DynaTagScript(
               new TagFactory() {
                   public Tag createTag() throws Exception {
  -                    return DynamicTagLibrary.this.createTag(name);
  +                    Tag answer = DynamicTagLibrary.this.createTag(name);
  +                    
  +                    // delegate to my parent instead
  +                    if ( answer == null && parent != null ) {
  +                        // #### this is a bit ugly.
  +                        // #### maybe we could refactor this so that a TagScript
  +                        // #### is constructed from a TagFactory instance
  +                        TagScript tagScript = parent.createTagScript(name, attributes);
  +                        return tagScript.getTag();
  +                    }
  +                    return answer;
                   }
               }
           );
  @@ -146,6 +157,21 @@
           this.uri = uri;
       }
   
  -    // Implementation methods
  -    //-------------------------------------------------------------------------     
  +
  +    /**
  +     * Returns the parent library which will be used to resolve unknown tags.
  +     * @return TagLibrary
  +     */
  +    public TagLibrary getParent() {
  +        return parent;
  +    }
  +
  +    /**
  +     * Sets the parent to inherit tags from that are not defined in this library.
  +     * @param parent The parent to set
  +     */
  +    public void setParent(TagLibrary parent) {
  +        this.parent = parent;
  +    }
  +
   }
  
  
  

--
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