001: package com.mockrunner.tag;
002:
003: import java.util.List;
004: import java.util.Map;
005:
006: import javax.servlet.jsp.JspException; //import javax.servlet.jsp.tagext.JspTag;
007: import javax.servlet.jsp.tagext.TagSupport;
008:
009: /**
010: * <code>NestedTag</code> is used to simulate tags with static body
011: * content and child tags. It can be used to test the interaction
012: * of different tags. A <code>NestedTag</code> always wraps a real tag
013: * class (the actual testee).
014: * {@link TagTestModule} works with <code>NestedTag</code> instances
015: * internally. If you only want to test the ouptput of one single tag
016: * without interaction with other tags, you do not have to care about
017: * <code>NestedTag</code>. Use it, if you want to write sophisticated
018: * tests of body tags. <code>NestedTag</code> instances are created using
019: * {@link TagTestModule#createNestedTag}. You do not need to create them
020: * on your own in the tests.
021: */
022: public interface NestedTag {
023: /**
024: * Specify if the <code>release</code> method should be called
025: * after processing the tag lifecycle. Defaults to <code>false</code>.
026: * It's the container behaviour to call <code>release</code> when the tag
027: * goes back to the pool. It's usually not necessary in the tests
028: * to call this method, because the tag instances are not pooled and
029: * reused during a test run.
030: * This method sets the <code>doRelease</code> flag for this tag but
031: * does not set the flag for child tags.
032: * @param doRelease should release be called, default is <code>false</code>
033: */
034: public void setDoRelease(boolean doRelease);
035:
036: /**
037: * Specify if the <code>release</code> method should be called
038: * after processing the tag lifecycle. Defaults to <code>false</code>.
039: * It's the container behaviour to call <code>release</code> when the tag
040: * goes back to the pool. It's usually not necessary in the tests
041: * to call this method, because the tag instances are not pooled and
042: * reused during a test run.
043: * This method sets the <code>doRelease</code> flag for this
044: * tag and all child tags recursively.
045: * @param doRelease should release be called, default is <code>false</code>
046: */
047: public void setDoReleaseRecursive(boolean doRelease);
048:
049: /**
050: * Populates the attributes of the underlying tag. The setters
051: * of the tag are called. Please note that child tags are not
052: * populated.
053: */
054: public void populateAttributes();
055:
056: /**
057: * Performs the tag lifecycle. All <code>doBody</code> and <code>doTag</code>
058: * methods are called as in the real web container. The evaluation of the body
059: * is simulated by performing the lifecycle recursively for all childs of the
060: * <code>NestedTag</code>. Calls <code>release</code> on the tag after
061: * processing the tag lifecycle, if <code>doRelease</code> is <code>true</code>
062: * (use {@link #setDoRelease(boolean)}).
063: * @return the result of the final <code>doEndTag</code> call
064: */
065: public int doLifecycle() throws JspException;
066:
067: /**
068: * Returns the wrapped tag (the testee).
069: * @return the wrapped tag
070: */
071: public TagSupport getTag();
072:
073: /**
074: * Returns the wrapped tag (the testee).
075: * @return the wrapped tag
076: */
077: //public JspTag getWrappedTag();
078: /**
079: * Removes all childs.
080: */
081: public void removeChilds();
082:
083: /**
084: * Returns the <code>List</code> of childs.
085: * @return the <code>List</code> of childs
086: */
087: public List getChilds();
088:
089: /**
090: * Returns a child specified by its index.
091: * @param index the index
092: * @return the child
093: */
094: public Object getChild(int index);
095:
096: /**
097: * Adds a text child simulating static body content.
098: * @param text the static text
099: */
100: public void addTextChild(String text);
101:
102: /**
103: * Adds a dynamic child simulating scriptlets and
104: * EL expressions. Check out
105: * {@link com.mockrunner.tag.TagUtil#evalBody(List, Object)}
106: * for details about child handling.
107: * @param child the dynamic child instance
108: */
109: public void addDynamicChild(DynamicChild child);
110:
111: /**
112: * Adds a tag child simulating nested tags.
113: * The corresponding <code>NestedTag</code> will be created
114: * automatically wrapping the specified tag. An empty attribute
115: * <code>Map</code> will be used for the tag.
116: * @param tag the tag class
117: */
118: public NestedTag addTagChild(Class tag);
119:
120: /**
121: * Adds a tag child simulating nested tags.
122: * The corresponding <code>NestedTag</code> will be created
123: * automatically wrapping the specified tag. The attributes
124: * <code>Map</code> contains the attributes of this tag
125: * (<i>propertyname</i> maps to <i>propertyvalue</i>).
126: * @param tag the tag class
127: * @param attributeMap the attribute map
128: */
129: public NestedTag addTagChild(Class tag, Map attributeMap);
130:
131: /**
132: * Adds a tag child simulating nested tags.
133: * <code>NestedTag</code> will be created automatically
134: * wrapping the specified tag. An empty attribute <code>Map</code>
135: * will be used for the tag.
136: * @param tag the tag
137: */
138: public NestedTag addTagChild(TagSupport tag);
139:
140: /**
141: * Adds a tag child simulating nested tags.
142: * The corresponding <code>NestedTag</code> will be created
143: * automatically wrapping the specified tag. The attributes
144: * <code>Map</code> contains the attributes of this tag
145: * (<i>propertyname</i> maps to <i>propertyvalue</i>).
146: * @param tag the tag
147: * @param attributeMap the attribute map
148: */
149: public NestedTag addTagChild(TagSupport tag, Map attributeMap);
150:
151: /**
152: * Adds a tag child simulating nested tags.
153: * <code>NestedTag</code> will be created automatically
154: * wrapping the specified tag. An empty attribute <code>Map</code>
155: * will be used for the tag.
156: * @param tag the tag
157: */
158: //public NestedTag addTagChild(JspTag tag);
159: /**
160: * Adds a tag child simulating nested tags.
161: * The corresponding <code>NestedTag</code> will be created
162: * automatically wrapping the specified tag. The attributes
163: * <code>Map</code> contains the attributes of this tag
164: * (<i>propertyname</i> maps to <i>propertyvalue</i>).
165: * @param tag the tag
166: * @param attributeMap the attribute map
167: */
168: //public NestedTag addTagChild(JspTag tag, Map attributeMap);
169: }
|