Source Code Cross Referenced for AbstractInputCollection.java in  » Development » jReform » org » jreform » internal » 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 » Development » jReform » org.jreform.internal 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package org.jreform.internal;
002:
003:        import java.util.HashMap;
004:        import java.util.HashSet;
005:        import java.util.Iterator;
006:        import java.util.Map;
007:        import java.util.Set;
008:
009:        import org.jreform.Checkbox;
010:        import org.jreform.Criterion;
011:        import org.jreform.DuplicateNameException;
012:        import org.jreform.Input;
013:        import org.jreform.InputCollection;
014:        import org.jreform.InputControl;
015:        import org.jreform.InputDataType;
016:        import org.jreform.MultiCheckbox;
017:        import org.jreform.MultiSelect;
018:        import org.jreform.Radio;
019:        import org.jreform.Select;
020:        import org.jreform.UndefinedInputControlException;
021:
022:        /**
023:         * @author armandino (at) gmail.com
024:         */
025:        public abstract class AbstractInputCollection implements 
026:                InputCollection {
027:            private final Map<String, InputControl<?>> inputs;
028:            private final Set<String> errors;
029:            private boolean isValid;
030:
031:            AbstractInputCollection() {
032:                inputs = new HashMap<String, InputControl<?>>();
033:                errors = new HashSet<String>();
034:                isValid = false;
035:            }
036:
037:            /**
038:             * Adds the specified input to the collection.
039:             * 
040:             * @throws DuplicateNameException if there is an existing input
041:             *         with the same name in this collection
042:             */
043:            <T> void add(InputControl<T> input) {
044:                String name = input.getInputName();
045:
046:                if (inputs.containsKey(name))
047:                    throw new DuplicateNameException(
048:                            "Duplicate input name within the same form: "
049:                                    + name);
050:
051:                inputs.put(name, input);
052:            }
053:
054:            final InputControl<?> getInputControl(String name) {
055:                InputControl<?> input = inputs.get(name);
056:
057:                if (input == null)
058:                    throw new UndefinedInputControlException(
059:                            "Undefined input control: " + name);
060:
061:                return input;
062:            }
063:
064:            public final Set<String> getErrors() {
065:                return errors;
066:            }
067:
068:            public final void addError(String errorKey) {
069:                errors.add(errorKey);
070:            }
071:
072:            public final boolean isValid() {
073:                return isValid;
074:            }
075:
076:            final Map<String, InputControl<?>> getInputs() {
077:                return inputs;
078:            }
079:
080:            final void setValid(boolean isValid) {
081:                this .isValid = isValid;
082:            }
083:
084:            /**
085:             * Perform additional validation of form data where necessary.
086:             */
087:            protected void additionalValidate() {
088:            }
089:
090:            //
091:            // ----------------------------------------------------------------
092:            // ------------------InputCollection methods ----------------------
093:            // ----------------------------------------------------------------
094:            //
095:
096:            //
097:            // Getters
098:            //
099:
100:            @SuppressWarnings("unchecked")
101:            public final <T> Input<T> getInput(String name) {
102:                return (Input<T>) getInputControl(name);
103:            }
104:
105:            @SuppressWarnings("unchecked")
106:            public final <T> Checkbox<T> getCheckbox(String name) {
107:                return (Checkbox<T>) getInputControl(name);
108:            }
109:
110:            @SuppressWarnings("unchecked")
111:            public final <T> MultiCheckbox<T> getMultiCheckbox(String name) {
112:                return (MultiCheckbox<T>) getInputControl(name);
113:            }
114:
115:            @SuppressWarnings("unchecked")
116:            public final <T> Radio<T> getRadio(String name) {
117:                return (Radio<T>) getInputControl(name);
118:            }
119:
120:            @SuppressWarnings("unchecked")
121:            public final <T> Select<T> getSelect(String name) {
122:                return (Select<T>) getInputControl(name);
123:            }
124:
125:            @SuppressWarnings("unchecked")
126:            public final <T> MultiSelect<T> getMultiSelect(String name) {
127:                return (MultiSelect<T>) getInputControl(name);
128:            }
129:
130:            //
131:            // Add methods
132:            //
133:
134:            public final <T> InputControlModifier<T> input(
135:                    InputDataType<T> type, String name,
136:                    Criterion<T>... criteria) {
137:                return create(new InputImpl<T>(type, name, criteria));
138:            }
139:
140:            public final <T> InputControlModifier<T> checkbox(
141:                    InputDataType<T> type, String name,
142:                    Criterion<T>... criteria) {
143:                return create(new CheckboxImpl<T>(type, name, criteria));
144:            }
145:
146:            public final <T> InputControlModifier<T> multiCheckbox(
147:                    InputDataType<T> type, String name,
148:                    Criterion<T>... criteria) {
149:                return create(new MultiCheckboxImpl<T>(type, name, criteria));
150:            }
151:
152:            public final <T> InputControlModifier<T> radio(
153:                    InputDataType<T> type, String name,
154:                    Criterion<T>... criteria) {
155:                return create(new RadioImpl<T>(type, name, criteria));
156:            }
157:
158:            public final <T> InputControlModifier<T> select(
159:                    InputDataType<T> type, String name,
160:                    Criterion<T>... criteria) {
161:                return create(new SelectImpl<T>(type, name, criteria));
162:            }
163:
164:            public final <T> InputControlModifier<T> multiSelect(
165:                    InputDataType<T> type, String name,
166:                    Criterion<T>... criteria) {
167:                return create(new MultiSelectImpl<T>(type, name, criteria));
168:            }
169:
170:            private <T> InputControlModifier<T> create(
171:                    AbstractInputControl<T> input) {
172:                add(input);
173:                return new InputControlModifier<T>(input);
174:            }
175:
176:            @Override
177:            public String toString() {
178:                StringBuilder sb = new StringBuilder();
179:                Iterator<String> iter = inputs.keySet().iterator();
180:
181:                while (iter.hasNext()) {
182:                    String inputName = iter.next();
183:                    InputControl<?> input = inputs.get(inputName);
184:                    sb.append(inputName).append(": ").append(
185:                            input.getStringValue()).append(
186:                            System.getProperty("line.separator"));
187:                }
188:
189:                return sb.toString();
190:            }
191:
192:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.