public void run()

in core/src/main/java/org/apache/commons/jelly/impl/TagScript.java [511:596]


    public void run(JellyContext context, XMLOutput output) throws JellyTagException {
        URL rootURL = context.getRootURL();
        URL currentURL = context.getCurrentURL();
        if ( ! context.isCacheTags() ) {
            clearTag();
        }
        try {
            Tag tag = getTag(context);
            if ( tag == null ) {
                return;
            }
            tag.setContext(context);
            setContextURLs(context);

            if ( tag instanceof DynaTag ) {
                DynaTag dynaTag = (DynaTag) tag;

                // ### probably compiling this to 2 arrays might be quicker and smaller
                for (Iterator iter = attributes.entrySet().iterator(); iter.hasNext();) {
                    Map.Entry entry = (Map.Entry) iter.next();
                    String name = (String) entry.getKey();
                    Expression expression = ((ExpressionAttribute) entry.getValue()).exp;

                    Class type = dynaTag.getAttributeType(name);
                    Object value = null;
                    if (type != null && type.isAssignableFrom(Expression.class) && !type.isAssignableFrom(Object.class)) {
                        value = expression;
                    }
                    else {
                        value = expression.evaluateRecurse(context);
                    }
                    dynaTag.setAttribute(name, value);
                }
            }
            else {
                // treat the tag as a bean
                DynaBean dynaBean = new ConvertingWrapDynaBean( tag );
                for (Iterator iter = attributes.entrySet().iterator(); iter.hasNext();) {
                    Map.Entry entry = (Map.Entry) iter.next();
                    String name = (String) entry.getKey();
                    Expression expression = ((ExpressionAttribute) entry.getValue()).exp;

                    DynaProperty property = dynaBean.getDynaClass().getDynaProperty(name);
                    if (property == null) {
                        throw new JellyException("This tag does not understand the '" + name + "' attribute" );
                    }
                    Class type = property.getType();

                    Object value = null;
                    if (type.isAssignableFrom(Expression.class) && !type.isAssignableFrom(Object.class)) {
                        value = expression;
                    }
                    else {
                        value = expression.evaluateRecurse(context);
                    }
                    dynaBean.set(name, value);
                }
            }

            tag.doTag(output);
            if (output != null) {
                output.flush();
            }
        }
        catch (JellyTagException e) {
            handleException(e);
        } catch (JellyException e) {
            handleException(e);
        } catch (IOException e) {
            handleException(e);
        } catch (RuntimeException e) {
            handleException(e);
        }
        catch (Error e) {
           /*
            * Not sure if we should be converting errors to exceptions,
            * but not trivial to remove because JUnit tags throw
            * Errors in the normal course of operation.  Hmm...
            */
            handleException(e);
        } finally {
            context.setRootURL(rootURL);
            context.setCurrentURL(currentURL);
        }

    }