Source Code Cross Referenced for WidgetList.java in  » Content-Management-System » apache-lenya-2.0 » org » apache » cocoon » forms » formmodel » 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 » Content Management System » apache lenya 2.0 » org.apache.cocoon.forms.formmodel 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Licensed to the Apache Software Foundation (ASF) under one or more
003:         * contributor license agreements.  See the NOTICE file distributed with
004:         * this work for additional information regarding copyright ownership.
005:         * The ASF licenses this file to You under the Apache License, Version 2.0
006:         * (the "License"); you may not use this file except in compliance with
007:         * the License.  You may obtain a copy of the License at
008:         *
009:         *      http://www.apache.org/licenses/LICENSE-2.0
010:         *
011:         * Unless required by applicable law or agreed to in writing, software
012:         * distributed under the License is distributed on an "AS IS" BASIS,
013:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014:         * See the License for the specific language governing permissions and
015:         * limitations under the License.
016:         */
017:        package org.apache.cocoon.forms.formmodel;
018:
019:        import java.util.ArrayList;
020:        import java.util.Collections;
021:        import java.util.HashMap;
022:        import java.util.Iterator;
023:        import java.util.List;
024:        import java.util.Locale;
025:        import java.util.Map;
026:
027:        import org.apache.cocoon.forms.FormsConstants;
028:        import org.apache.cocoon.forms.FormContext;
029:        import org.apache.cocoon.xml.XMLUtils;
030:        import org.xml.sax.ContentHandler;
031:        import org.xml.sax.SAXException;
032:
033:        /**
034:         * Helper class for the implementation of widgets containing other widgets.
035:         * This implements a type-aware List of Widgets that automatically can distribute
036:         * the common Widget operations over the contained Widgets.
037:         *
038:         * @version $Id: WidgetList.java 449149 2006-09-23 03:58:05Z crossley $
039:         */
040:        public class WidgetList {
041:
042:            private static final String WIDGETS_EL = "widgets";
043:
044:            /** 
045:             * List of the contained widgets.
046:             * This maintains the original order of the widgets to garantee order of
047:             * validation and generation of SAXFragments
048:             */
049:            private List widgets;
050:
051:            /** 
052:             * Map of the contained widgets using its id as the lookup key.
053:             */
054:            private Map widgetsById;
055:
056:            /**
057:             * Constructs ContainerDelegate to store and jointly manage a list of 
058:             * contained widgets.
059:             */
060:            public WidgetList() {
061:                widgets = new ArrayList();
062:                widgetsById = new HashMap();
063:            }
064:
065:            /**
066:             * Get the (unmodifiable) list of widgets
067:             * 
068:             * @return the widget list
069:             */
070:            public List getWidgetList() {
071:                return Collections.unmodifiableList(this .widgets);
072:            }
073:
074:            /**
075:             * Get the (unmodifiable) map of widgets
076:             * 
077:             * @return the widget map
078:             */
079:            public Map getWidgetMap() {
080:                return Collections.unmodifiableMap(this .widgetsById);
081:            }
082:
083:            /** 
084:             * Adds a widget to the list of contained {@link Widget}'s
085:             * 
086:             * @param widget
087:             */
088:            public void addWidget(Widget widget) {
089:                widgets.add(widget);
090:                widgetsById.put(widget.getId(), widget);
091:            }
092:
093:            /**
094:             * Performs the {@link Widget#readFromRequest(FormContext)} on all the 
095:             * contained widgets.
096:             * 
097:             * @param formContext to pass to the {@link Widget#readFromRequest(FormContext)}
098:             * 
099:             * @see Widget#readFromRequest(FormContext)
100:             */
101:            public void readFromRequest(FormContext formContext) {
102:                Iterator widgetIt = iterator();
103:                while (widgetIt.hasNext()) {
104:                    Widget widget = (Widget) widgetIt.next();
105:                    widget.readFromRequest(formContext);
106:                }
107:            }
108:
109:            /** 
110:             * Validates all contained widgets and returns the combined result.
111:             * 
112:             * @return <code>false</code> if at least one of the contained widgets is not valid.
113:             * 
114:             * @see Widget#validate()
115:             */
116:            public boolean validate() {
117:                boolean valid = true;
118:                Iterator widgetIt = iterator();
119:                while (widgetIt.hasNext()) {
120:                    Widget widget = (Widget) widgetIt.next();
121:                    valid = valid & widget.validate();
122:                }
123:                return valid;
124:            }
125:
126:            /**
127:             * Checks if a widget with the provided id is contained in the list.
128:             *
129:             * @param id of the widget to look for.
130:             * @return true if the widget was found
131:             */
132:            public boolean hasWidget(String id) {
133:                return widgetsById.containsKey(id);
134:            }
135:
136:            /** 
137:             * Looks for a widget in this list by using the provided id as a lookup key.
138:             * 
139:             * @param id of the widget to look for
140:             * @return the found widget or <code>null</code> if it could not be found.
141:             */
142:            public Widget getWidget(String id) {
143:                return (Widget) widgetsById.get(id);
144:            }
145:
146:            /** 
147:             * @return an iterator over the contained {@link Widget}'s
148:             */
149:            public Iterator iterator() {
150:                return widgets.iterator();
151:            }
152:
153:            /**
154:             * @return <code>false</code> if at least one of the contained widgets has no value.
155:             */
156:            public boolean widgetsHaveValues() {
157:                Iterator widgetsIt = iterator();
158:                while (widgetsIt.hasNext()) {
159:                    Widget widget = (Widget) widgetsIt.next();
160:                    if (widget.getValue() == null)
161:                        return false;
162:                }
163:                return true;
164:            }
165:
166:            /**
167:             * Generates the SAXfragments of the contained widgets
168:             * 
169:             * @param contentHandler
170:             * @param locale
171:             * @throws SAXException
172:             * 
173:             * @see Widget#generateSaxFragment(ContentHandler, Locale)
174:             */
175:            public void generateSaxFragment(ContentHandler contentHandler,
176:                    Locale locale) throws SAXException {
177:                contentHandler.startElement(FormsConstants.INSTANCE_NS,
178:                        WIDGETS_EL, FormsConstants.INSTANCE_PREFIX_COLON
179:                                + WIDGETS_EL, XMLUtils.EMPTY_ATTRIBUTES);
180:                Iterator widgetIt = widgets.iterator();
181:                while (widgetIt.hasNext()) {
182:                    Widget widget = (Widget) widgetIt.next();
183:                    widget.generateSaxFragment(contentHandler, locale);
184:                }
185:                contentHandler.endElement(FormsConstants.INSTANCE_NS,
186:                        WIDGETS_EL, FormsConstants.INSTANCE_PREFIX_COLON
187:                                + WIDGETS_EL);
188:            }
189:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.