Source Code Cross Referenced for CollectionTag.java in  » Portal » Open-Portal » com » sun » portal » wireless » taglibs » base » 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 » Portal » Open Portal » com.sun.portal.wireless.taglibs.base 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /**
002:         * $Id: CollectionTag.java,v 1.8 2005/09/21 10:50:30 dg154973 Exp $
003:         * Copyright 2002 Sun Microsystems, Inc. All
004:         * rights reserved. Use of this product is subject
005:         * to license terms. Federal Acquisitions:
006:         * Commercial Software -- Government Users
007:         * Subject to Standard License Terms and
008:         * Conditions.
009:         *
010:         * Sun, Sun Microsystems, the Sun logo, and Sun ONE
011:         * are trademarks or registered trademarks of Sun Microsystems,
012:         * Inc. in the United States and other countries.
013:         */package com.sun.portal.wireless.taglibs.base;
014:
015:        import com.sun.portal.log.common.PortalLogger;
016:
017:        import java.util.*;
018:        import java.util.logging.Logger;
019:        import java.util.logging.Level;
020:        import javax.servlet.jsp.*;
021:        import javax.servlet.jsp.tagext.*;
022:
023:        public abstract class CollectionTag extends BaseBodyTagSupport
024:                implements  BeanHolder {
025:
026:            // Create a logger for this class
027:            private static Logger debugLogger = PortalLogger
028:                    .getLogger(CollectionTag.class);
029:
030:            String beanid = null;
031:
032:            /**
033:             * Start index
034:             */
035:            int start = 0;
036:            boolean doIteration = false;
037:
038:            /**
039:             * Internal iterator over the items in the collection
040:             */
041:            CollectionIterator iterator = null;
042:
043:            /**
044:             * The current item in the iteration
045:             */
046:            Object item;
047:
048:            /**
049:             * Get the collection-iterator as a bean
050:             * 
051:             * @return the collection-iterator bean
052:             */
053:            public Object getBean() {
054:                return iterator;
055:            }
056:
057:            /**
058:             * Get the current item in the iteration
059:             * 
060:             * @return the current item
061:             */
062:            public Object getItem() {
063:                return item;
064:            }
065:
066:            /**
067:             * Find the collection this tag represents
068:             * 
069:             * @return the collection
070:             */
071:            public abstract Collection findCollection() throws Exception;
072:
073:            /**
074:             * Prepare to iterate over the collection
075:             * 
076:             * @return EVAL_BODY_INCLUDE to iterate over the collection
077:             *         SKIP_BODY if the collection is empty
078:             */
079:            public int doStartTag() throws JspException {
080:                Collection collection;
081:
082:                if (name != null) {
083:                    Object col = pageContext.getAttribute(name);
084:                    if (col instanceof  CollectionIterator) {
085:                        iterator = (CollectionIterator) col;
086:                        collection = iterator.getCollection();
087:                    } else if (col == null) {
088:                        // null collection: just skip body via an empty collection
089:                        collection = new Vector();
090:                        // Array - convert to collection
091:                    } else if (col instanceof  Object[]) {
092:                        collection = new Vector(Arrays.asList((Object[]) col));
093:                    } else if (col instanceof  Collection) {
094:                        // behavior described in taglibs docs: any arbitrary collection
095:                        collection = (Collection) col;
096:                        iterator = new CollectionIterator(collection);
097:                    } else {
098:                        debugLogger.log(Level.FINE, "PSMA_CSPWTB0012");
099:                        throw new JspException(this .getClass().getName()
100:                                + ".doStartTag():  failed: " + col
101:                                + " is not a collection");
102:                    }
103:                } else {
104:                    try {
105:                        collection = findCollection();
106:                        iterator = new CollectionIterator(collection);
107:                    } catch (Exception e) {
108:                        debugLogger.log(Level.FINE, "PSMA_CSPWTB0001", e);
109:                        throw new JspException(this .getClass().getName()
110:                                + ".doStartTag():  failed:  " + e.getMessage());
111:                    }
112:                }
113:
114:                if (collection == null) {
115:                    debugLogger.fine("PSMA_CSPWTB0012");
116:                    throw new JspException(this .getClass().getName()
117:                            + ".doStartTag():  No collection found");
118:                }
119:
120:                if (doIteration) {
121:                    if ((collection.isEmpty())
122:                            || (iterator.getStartInt() >= collection.size()))
123:                        return SKIP_BODY;
124:                }
125:
126:                if (id != null) {
127:                    pageContext.setAttribute(id, iterator);
128:                }
129:
130:                return EVAL_BODY_TAG;
131:            }
132:
133:            /**
134:             * Start the iteration by getting the first object
135:             * 
136:             * @exception JspException
137:             */
138:            public void doInitBody() throws JspException {
139:                if (doIteration && iterator.hasNext()) {
140:                    item = iterator.next();
141:                    if (beanid != null) {
142:                        pageContext.setAttribute(beanid, item);
143:                    }
144:                }
145:            }
146:
147:            /**
148:             * Iterate through the items in the collection.
149:             * 
150:             * Write the previous body context to the page output
151:             * and if there are still more items then return
152:             * EVAL_BODY_TAG to loop again.  When all the
153:             * items have been consumed return SKIP_BODY to
154:             * end the loop.
155:             * 
156:             * @return EVAL_BODY_TAG if there are more items
157:             *         SKIP_BODY when the iteration is complete
158:             * @exception JspException
159:             */
160:            public int doAfterBody() throws JspException {
161:                BodyContent body = getBodyContent();
162:
163:                try {
164:                    body.writeOut(getPreviousOut());
165:                    body.clearBody();
166:                } catch (Exception e) {
167:                    debugLogger.log(Level.FINE, "PSMA_CSPWTB0013", e);
168:                    throw new JspException(this .getClass().getName()
169:                            + ".doAfterBody(): couldn't write previous out"
170:                            + e.getMessage());
171:                }
172:
173:                if (doIteration && iterator.hasNext()) {
174:                    item = iterator.next();
175:                    if (beanid != null) {
176:                        pageContext.setAttribute(beanid, item);
177:                    }
178:                    return EVAL_BODY_TAG;
179:                } else {
180:                    return SKIP_BODY;
181:                }
182:            }
183:
184:            /**
185:             * Continue evaluating the page
186:             * 
187:             * @return EVAL_PAGE
188:             */
189:            public int doEndTag() {
190:                return EVAL_PAGE;
191:            }
192:
193:            /**
194:             * Cleanup
195:             */
196:            public void release() {
197:                super .release();
198:                iterator = null;
199:                item = null;
200:                start = 0;
201:                doIteration = false;
202:                beanid = null;
203:            }
204:
205:            /***********************
206:             * Process attributes...
207:             **********************/
208:
209:            /**
210:             * Process "iterate" attribute...
211:             */
212:
213:            public void setIterate(String s) {
214:                if (s != null && s.equalsIgnoreCase("true"))
215:                    doIteration = true;
216:                else
217:                    doIteration = false;
218:            }
219:
220:            /*
221:             * Process "beanid" attribute...
222:             */
223:            public void setBeanid(String s) {
224:                beanid = s;
225:            }
226:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.