Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * Copyright 2002,2004 The Apache Software Foundation.
   *
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   *
   *      http://www.apache.org/licenses/LICENSE-2.0
   *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
 package org.apache.commons.jelly.impl;
 
 import java.util.Map;
 

DynamicTagLibrary represents a TagLibrary which gets created by running a Jelly script.

Author(s):
James Strachan
Version:
$Revision: 155420 $
 
 public class DynamicTagLibrary extends TagLibrary {
 
     private String uri;
     private Map templates = new HashMap();
     private TagLibrary parent;
 
     public DynamicTagLibrary() {
     }
 
     public DynamicTagLibrary(String uri) {
         this. = uri;
     }

    
Creates a new script to execute the given tag name and attributes
 
     public TagScript createTagScript(final String namefinal Attributes attributes)
         throws JellyException {
 
         return new TagScript(
             new TagFactory() {
                 public Tag createTag(String nameAttributes attributesthrows JellyException {
                     return DynamicTagLibrary.this.createTag(nameattributes);
                 }
             }
         );
     }

    
Creates a new Tag for the given tag name if it exists
 
     public Tag createTag(String nameAttributes attributes)
         throws JellyException {
 
         Object value = .get(name);
         if ( value instanceof Script ) {
             Script template = (Scriptvalue;
             return new DynamicTag(template);
         }
         else if ( value instanceof TagFactory ) {
             TagFactory factory = (TagFactoryvalue;
             return factory.createTag(nameattributes);
         }
         else if (  != null ) {
             // delegate to the parent
             return .createTag(nameattributes);
         }
 
         return null;
     }

    
Creates a new tag with the given name and template
 
     public void registerDynamicTag(String nameScript template) {
         .put(nametemplate);
     }

    
Creates a new Jelly Bean Tag with the given name
 
     public void registerBeanTag(String nameTagFactory factory) {
         .put(namefactory);
     }

    
Returns the script associated with the given tag name

Parameters:
name The tag name
Returns:
The script associated with name, or null if the tag doesn't exist or isn't a script
    public Script getDynamicTag(String name) {
        Object result = .get(name);
        return (result instanceof Script) ? (Scriptresult : null;
    }

    
Returns the tag library instance which contains the named tag.

If the tag is not registered within this library, the set of parent libraries will be searched.

Parameters:
name The tag name
Returns:
The tag library containing the named tag, or null if the tag is not registered.
    public DynamicTagLibrary find(String name) {
        DynamicTagLibrary result = null;
        if (.get(name) != null) {
            result = this;
        }
        else if ( instanceof DynamicTagLibrary) {
            result = ((DynamicTagLibrary).find(name);
        }
        return result;
    }
    // Properties
    //-------------------------------------------------------------------------
    public String getUri() {
        return ;
    }
    public void setUri(String uri) {
        this. = uri;
    }


    
Returns the parent library which will be used to resolve unknown tags.

Returns:
TagLibrary
    public TagLibrary getParent() {
        return ;
    }

    
Sets the parent to inherit tags from that are not defined in this library.

Parameters:
parent The parent to set
    public void setParent(TagLibrary parent) {
        this. = parent;
    }
New to GrepCode? Check out our FAQ X