Source Code Cross Referenced for NestedStandardTag.java in  » Testing » mockrunner-0.4 » com » mockrunner » tag » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Testing » mockrunner 0.4 » com.mockrunner.tag 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package com.mockrunner.tag;
002:
003:        import java.util.ArrayList;
004:        import java.util.Enumeration;
005:        import java.util.HashMap;
006:        import java.util.List;
007:        import java.util.Map;
008:
009:        import javax.servlet.jsp.JspException;
010:        import javax.servlet.jsp.PageContext;
011:        import javax.servlet.jsp.tagext.IterationTag; //import javax.servlet.jsp.tagext.JspTag;
012:        //import javax.servlet.jsp.tagext.SimpleTag;
013:        import javax.servlet.jsp.tagext.Tag;
014:        import javax.servlet.jsp.tagext.TagSupport;
015:
016:        /**
017:         * Implementation of {@link NestedTag} wrapping tags of
018:         * type <code>Tag</code>. <code>NestedStandardTag</code> instances 
019:         * are created with the help of {@link TagTestModule#createNestedTag}. 
020:         * You do not need to create them on your own in the tests.
021:         */
022:        public class NestedStandardTag extends TagSupport implements  NestedTag {
023:            private Tag tag;
024:            private PageContext pageContext;
025:            private Map attributes;
026:            private List childs;
027:            private boolean doRelease;
028:
029:            /**
030:             * Constructor for a tag with an empty attribute map.
031:             * If the specified tag is not an instance of <code>TagSupport</code>,
032:             * the methods that delegate to <code>TagSupport</code> specific methods
033:             * throw an exception.
034:             * @param tag the tag
035:             * @param pageContext the corresponding <code>PageContext</code>
036:             */
037:            public NestedStandardTag(Tag tag, PageContext pageContext) {
038:                this (tag, pageContext, new HashMap());
039:            }
040:
041:            /**
042:             * Constructor for a tag with the specified attribute map.
043:             * If the specified tag is not an instance of <code>TagSupport</code>,
044:             * the methods that delegate to <code>TagSupport</code> specific methods
045:             * throw an exception.
046:             * @param tag the tag
047:             * @param pageContext the corresponding <code>PageContext</code>
048:             * @param attributes the attribute map
049:             */
050:            public NestedStandardTag(Tag tag, PageContext pageContext,
051:                    Map attributes) {
052:                this .tag = tag;
053:                this .pageContext = pageContext;
054:                tag.setPageContext(pageContext);
055:                childs = new ArrayList();
056:                this .attributes = attributes;
057:                doRelease = false;
058:            }
059:
060:            /**
061:             * Constructor for a tag with an empty attribute map.
062:             * @param tag the tag
063:             * @param pageContext the corresponding <code>PageContext</code>
064:             */
065:            public NestedStandardTag(TagSupport tag, PageContext pageContext) {
066:                this (tag, pageContext, new HashMap());
067:            }
068:
069:            /**
070:             * Constructor for a tag with the specified attribute map.
071:             * @param tag the tag
072:             * @param pageContext the corresponding <code>PageContext</code>
073:             * @param attributes the attribute map
074:             */
075:            public NestedStandardTag(TagSupport tag, PageContext pageContext,
076:                    Map attributes) {
077:                this ((Tag) tag, pageContext, attributes);
078:            }
079:
080:            /**
081:             * @inheritDoc
082:             */
083:            public void setDoRelease(boolean doRelease) {
084:                this .doRelease = doRelease;
085:            }
086:
087:            /**
088:             * @inheritDoc
089:             */
090:            public void setDoReleaseRecursive(boolean doRelease) {
091:                this .doRelease = doRelease;
092:                for (int ii = 0; ii < childs.size(); ii++) {
093:                    Object child = childs.get(ii);
094:                    if (child instanceof  NestedTag) {
095:                        ((NestedTag) child).setDoReleaseRecursive(doRelease);
096:                    }
097:                }
098:            }
099:
100:            /**
101:             * @inheritDoc
102:             */
103:            public void populateAttributes() {
104:                TagUtil.populateTag(tag, attributes);
105:            }
106:
107:            /**
108:             * @inheritDoc
109:             */
110:            public int doLifecycle() throws JspException {
111:                populateAttributes();
112:                int returnValue = -1;
113:                try {
114:                    int result = tag.doStartTag();
115:                    if (Tag.EVAL_BODY_INCLUDE == result) {
116:                        TagUtil.evalBody(childs, pageContext);
117:                        if (tag instanceof  IterationTag) {
118:                            while (IterationTag.EVAL_BODY_AGAIN == doAfterBody()) {
119:                                TagUtil.evalBody(childs, pageContext);
120:                            }
121:                        }
122:                    }
123:                    returnValue = tag.doEndTag();
124:                } catch (Throwable exc) {
125:                    TagUtil.handleException(tag, exc);
126:                } finally {
127:                    TagUtil.handleFinally(tag);
128:                }
129:                if (doRelease)
130:                    tag.release();
131:                return returnValue;
132:            }
133:
134:            /**
135:             * @inheritDoc
136:             * @throws <code>RuntimeException</code>, if the wrapped tag
137:             *         is not an instance of <code>TagSupport</code>
138:             */
139:            public TagSupport getTag() {
140:                checkTagSupport();
141:                return (TagSupport) tag;
142:            }
143:
144:            /**
145:             * @inheritDoc
146:             */
147:            /*public JspTag getWrappedTag()
148:            {
149:                return tag;
150:            }*/
151:
152:            /**
153:             * @inheritDoc
154:             */
155:            public void removeChilds() {
156:                childs.clear();
157:            }
158:
159:            /**
160:             * @inheritDoc
161:             */
162:            public List getChilds() {
163:                return childs;
164:            }
165:
166:            /**
167:             * @inheritDoc
168:             */
169:            public Object getChild(int index) {
170:                return childs.get(index);
171:            }
172:
173:            /**
174:             * @inheritDoc
175:             */
176:            public void addTextChild(String text) {
177:                if (null == text)
178:                    text = "";
179:                childs.add(text);
180:            }
181:
182:            /**
183:             * @inheritDoc
184:             */
185:            public void addDynamicChild(DynamicChild child) {
186:                if (null == child)
187:                    return;
188:                childs.add(child);
189:            }
190:
191:            /**
192:             * @inheritDoc
193:             */
194:            public NestedTag addTagChild(Class tag) {
195:                return addTagChild(tag, new HashMap());
196:            }
197:
198:            /**
199:             * @inheritDoc
200:             */
201:            public NestedTag addTagChild(Class tag, Map attributeMap) {
202:                Object childTag = TagUtil.createNestedTagInstance(tag,
203:                        this .pageContext, attributeMap);
204:                return addChild(childTag);
205:            }
206:
207:            /**
208:             * @inheritDoc
209:             */
210:            public NestedTag addTagChild(TagSupport tag) {
211:                return addTagChild(tag, new HashMap());
212:            }
213:
214:            /**
215:             * @inheritDoc
216:             */
217:            public NestedTag addTagChild(TagSupport tag, Map attributeMap) {
218:                Object childTag = TagUtil.createNestedTagInstance(tag,
219:                        this .pageContext, attributeMap);
220:                return addChild(childTag);
221:            }
222:
223:            /**
224:             * @inheritDoc
225:             */
226:            /*public NestedTag addTagChild(JspTag tag)
227:            {
228:                return addTagChild(tag, new HashMap());
229:            }*/
230:
231:            /**
232:             * @inheritDoc
233:             */
234:            /*public NestedTag addTagChild(JspTag tag, Map attributeMap)
235:            {
236:                Object childTag = TagUtil.createNestedTagInstance(tag, this.pageContext, attributeMap);   
237:                return addChild(childTag);
238:            }*/
239:
240:            /**
241:             * Delegates to wrapped tag.
242:             * @throws <code>RuntimeException</code>, if the wrapped tag
243:             *         is not an instance of <code>IterationTag</code>
244:             */
245:            public int doAfterBody() throws JspException {
246:                checkIterationTag();
247:                return ((IterationTag) tag).doAfterBody();
248:            }
249:
250:            /**
251:             * Delegates to wrapped tag.
252:             */
253:            public int doEndTag() throws JspException {
254:                return tag.doEndTag();
255:            }
256:
257:            /**
258:             * Delegates to wrapped tag.
259:             */
260:            public int doStartTag() throws JspException {
261:                return tag.doStartTag();
262:            }
263:
264:            /**
265:             * Delegates to wrapped tag.
266:             * @throws <code>RuntimeException</code>, if the wrapped tag
267:             *         is not an instance of <code>TagSupport</code>
268:             */
269:            public String getId() {
270:                checkTagSupport();
271:                return ((TagSupport) tag).getId();
272:            }
273:
274:            /**
275:             * Delegates to wrapped tag.
276:             */
277:            public Tag getParent() {
278:                return tag.getParent();
279:            }
280:
281:            /**
282:             * Delegates to wrapped tag.
283:             * @throws <code>RuntimeException</code>, if the wrapped tag
284:             *         is not an instance of <code>TagSupport</code>
285:             */
286:            public Object getValue(String key) {
287:                checkTagSupport();
288:                return ((TagSupport) tag).getValue(key);
289:            }
290:
291:            /**
292:             * Delegates to wrapped tag.
293:             * @throws <code>RuntimeException</code>, if the wrapped tag
294:             *         is not an instance of <code>TagSupport</code>
295:             */
296:            public Enumeration getValues() {
297:                checkTagSupport();
298:                return ((TagSupport) tag).getValues();
299:            }
300:
301:            /**
302:             * Delegates to wrapped tag.
303:             */
304:            public void release() {
305:                tag.release();
306:            }
307:
308:            /**
309:             * Delegates to wrapped tag.
310:             * @throws <code>RuntimeException</code>, if the wrapped tag
311:             *         is not an instance of <code>TagSupport</code>
312:             */
313:            public void removeValue(String value) {
314:                checkTagSupport();
315:                ((TagSupport) tag).removeValue(value);
316:            }
317:
318:            /**
319:             * Delegates to wrapped tag.
320:             * @throws <code>RuntimeException</code>, if the wrapped tag
321:             *         is not an instance of <code>TagSupport</code>
322:             */
323:            public void setId(String id) {
324:                checkTagSupport();
325:                ((TagSupport) tag).setId(id);
326:            }
327:
328:            /**
329:             * Delegates to wrapped tag. Also calls <code>setPageContext</code>
330:             * for all child tags.
331:             */
332:            public void setPageContext(PageContext pageContext) {
333:                this .pageContext = pageContext;
334:                tag.setPageContext(pageContext);
335:                for (int ii = 0; ii < childs.size(); ii++) {
336:                    Object child = childs.get(ii);
337:                    if (child instanceof  Tag) {
338:                        ((Tag) child).setPageContext(pageContext);
339:                    }
340:                    /*else if(child instanceof SimpleTag)
341:                    {
342:                        ((SimpleTag)child).setJspContext(pageContext);
343:                    }*/
344:                }
345:            }
346:
347:            /**
348:             * Delegates to wrapped tag.
349:             */
350:            public void setParent(Tag parent) {
351:                tag.setParent(parent);
352:            }
353:
354:            /**
355:             * Delegates to wrapped tag.
356:             */
357:            public void setValue(String key, Object value) {
358:                checkTagSupport();
359:                ((TagSupport) tag).setValue(key, value);
360:            }
361:
362:            /**
363:             * Dumps the content of this and the nested tags.
364:             */
365:            public String toString() {
366:                return TagUtil.dumpTag(this , new StringBuffer(), 0);
367:            }
368:
369:            private NestedTag addChild(Object childTag) {
370:                if (childTag instanceof  Tag) {
371:                    ((Tag) childTag).setParent(this .tag);
372:                }
373:                /*else if(childTag instanceof SimpleTag)
374:                {
375:                    ((SimpleTag)childTag).setParent(this.tag);
376:                }*/
377:                childs.add(childTag);
378:                return (NestedTag) childTag;
379:            }
380:
381:            private void checkIterationTag() {
382:                if (!(tag instanceof  IterationTag)) {
383:                    throw new RuntimeException(
384:                            "This method can only be called if the wrapped tag is an instance of IterationTag.");
385:                }
386:            }
387:
388:            private void checkTagSupport() {
389:                if (!(tag instanceof  TagSupport)) {
390:                    throw new RuntimeException(
391:                            "This method can only be called if the wrapped tag is an instance of TagSupport.");
392:                }
393:            }
394:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.