Source Code Cross Referenced for BaseControl.java in  » Web-Framework » aranea-mvc-1.1.1 » org » araneaframework » uilib » form » control » 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 » Web Framework » aranea mvc 1.1.1 » org.araneaframework.uilib.form.control 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /**
002:         * Copyright 2006 Webmedia Group Ltd.
003:         *
004:         * Licensed under the Apache License, Version 2.0 (the "License");
005:         * you may not use this file except in compliance with the License.
006:         * You may obtain a copy of the License at
007:         *
008:         *  http://www.apache.org/licenses/LICENSE-2.0
009:         *
010:         * Unless required by applicable law or agreed to in writing, software
011:         * distributed under the License is distributed on an "AS IS" BASIS,
012:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013:         * See the License for the specific language governing permissions and
014:         * limitations under the License.
015:         **/package org.araneaframework.uilib.form.control;
016:
017:        import org.araneaframework.InputData;
018:        import org.araneaframework.OutputData;
019:        import org.araneaframework.Path;
020:        import org.araneaframework.Scope;
021:        import org.araneaframework.Widget;
022:        import org.araneaframework.core.Assert;
023:        import org.araneaframework.core.BaseApplicationWidget;
024:        import org.araneaframework.core.BaseWidget;
025:        import org.araneaframework.http.HttpInputData;
026:        import org.araneaframework.uilib.form.Control;
027:        import org.araneaframework.uilib.form.FormElement;
028:        import org.araneaframework.uilib.form.FormElementContext;
029:
030:        /**
031:         * This class is a control generalization that provides methods common to all HTML form controls.
032:         * The methods include XML output and error handling.
033:         * 
034:         * @author Jevgeni Kabanov (ekabanov <i>at</i> araneaframework <i>dot</i> org)
035:         * 
036:         */
037:        public abstract class BaseControl extends BaseApplicationWidget
038:                implements  java.io.Serializable, Control {
039:            //*******************************************************************
040:            // FIELDS
041:            //*******************************************************************
042:
043:            protected Object value;
044:            protected Object innerData;
045:            protected boolean isReadFromRequest = false;
046:
047:            private FormElementContext feCtx;
048:
049:            //*********************************************************************
050:            //* PUBLIC METHODS
051:            //*********************************************************************
052:
053:            /**
054:             * Returns the value of the control (value read from the request). Type of value depends on the
055:             * type of control.
056:             * 
057:             * @return Returns the value of the control (value read from the request).
058:             */
059:            public Object getRawValue() {
060:                return value;
061:            }
062:
063:            /**
064:             * Sets the raw control value (as it was read from request/written to response).
065:             * It is usually set by {@link org.araneaframework.uilib.form.Converter} when
066:             * value of {@link FormElement} that owns this {@link BaseControl} changes.
067:             * 
068:             * @param value control value.
069:             * @see #getRawValue()
070:             */
071:            public void setRawValue(Object value) {
072:                BaseControl.this .value = value;
073:            }
074:
075:            /**
076:             * Returns {@link ViewModel}.
077:             * @return {@link ViewModel}.
078:             * @throws Exception 
079:             */
080:            public Object getViewModel() throws Exception {
081:                return new ViewModel();
082:            }
083:
084:            public void setFormElementCtx(FormElementContext formElementContext) {
085:                this .feCtx = formElementContext;
086:            }
087:
088:            public FormElementContext getFormElementCtx() {
089:                return feCtx;
090:            }
091:
092:            /**
093:             * By default the control is considered read if it has a not null data read from request.
094:             */
095:            public boolean isRead() {
096:                return isReadFromRequest;
097:            }
098:
099:            //*********************************************************************
100:            //* OVERRIDABLE METHODS
101:            //*********************************************************************  
102:
103:            public void convertAndValidate() {
104:                convert();
105:                validate();
106:            }
107:
108:            public void convert() {
109:            }
110:
111:            public void validate() {
112:            }
113:
114:            protected void readFromRequest(HttpInputData request) {
115:            }
116:
117:            //*********************************************************************
118:            //* INTERNAL METHODS
119:            //*********************************************************************  
120:
121:            protected void init() throws Exception {
122:                super .init();
123:
124:                Assert
125:                        .notNull(
126:                                this ,
127:                                getFormElementCtx(),
128:                                "Form element context must be assigned to the control before it can be initialized! "
129:                                        + "Make sure that the control is associated with a form element!");
130:
131:            }
132:
133:            protected void action(Path path, InputData input, OutputData output)
134:                    throws Exception {
135:                if (!isDisabled())
136:                    super .action(path, input, output);
137:            }
138:
139:            protected void update(InputData input) throws Exception {
140:                super .update(input);
141:
142:                if (!isDisabled())
143:                    readFromRequest((HttpInputData) input);
144:            }
145:
146:            protected void handleEvent(InputData input) throws Exception {
147:                if (!isDisabled())
148:                    super .handleEvent(input);
149:            }
150:
151:            /**
152:             * Returns control label.
153:             * 
154:             * @return control label.
155:             */
156:            protected String getLabel() {
157:                return feCtx.getLabel();
158:            }
159:
160:            /**
161:             * * Returns whether the control is mandatory, that is must be inserted by user.
162:             * 
163:             * @return whether the control is mandatory, that is must be inserted by user.
164:             */
165:            protected boolean isMandatory() {
166:                return feCtx.isMandatory();
167:            }
168:
169:            protected void addError(String error) {
170:                feCtx.addError(error);
171:            }
172:
173:            /**
174:             * Returns whether the control is disabled.
175:             * @return whether the control is disabled
176:             * 
177:             * @since 1.1 this method is public and part of {@link Control} interface
178:             */
179:            public boolean isDisabled() {
180:                return feCtx.isDisabled();
181:            }
182:
183:            protected boolean isValid() {
184:                return feCtx.isValid();
185:            }
186:
187:            public Widget.Interface _getWidget() {
188:                return new WidgetImpl();
189:            }
190:
191:            protected class WidgetImpl extends BaseWidget.WidgetImpl {
192:                public void update(InputData input) {
193:                    isReadFromRequest = false;
194:                    super .update(input);
195:                }
196:            }
197:
198:            //*********************************************************************
199:            //* VIEW MODEL
200:            //*********************************************************************    
201:
202:            /**
203:             * Represents a general control view model.
204:             * 
205:             * @author Jevgeni Kabanov (ekabanov <i>at</i> araneaframework <i>dot</i> org)
206:             */
207:            public class ViewModel implements  Control.ViewModel {
208:                protected String controlType;
209:                protected boolean mandatory;
210:                protected boolean disabled;
211:                protected String label;
212:
213:                /**
214:                 * Takes an outer class snapshot.     
215:                 */
216:                public ViewModel() {
217:                    String className = BaseControl.this .getClass().getName();
218:                    // Recognizes Controls that are defined as (anonymous) nested classes.
219:                    // Prior to 1.5 getDeclaringClass() does not exist, so just look for '$'.
220:                    if (className.indexOf('$') != -1)
221:                        className = BaseControl.this .getClass().getSuperclass()
222:                                .getName();
223:                    className = className
224:                            .substring(className.lastIndexOf(".") + 1);
225:                    this .controlType = className;
226:
227:                    this .mandatory = BaseControl.this .isMandatory();
228:                    this .disabled = BaseControl.this .isDisabled();
229:
230:                    this .label = BaseControl.this .getLabel();
231:                }
232:
233:                /** @since 1.1 */
234:                public Scope getScope() {
235:                    return BaseControl.this .getScope();
236:                }
237:
238:                /**
239:                 * Returns control type.
240:                 * @return control type.
241:                 */
242:                public String getControlType() {
243:                    return controlType;
244:                }
245:
246:                /**
247:                 * Returns whether the control is mandatory.
248:                 * @return whether the control is mandatory.
249:                 */
250:                public boolean isMandatory() {
251:                    return mandatory;
252:                }
253:
254:                /**
255:                 * Returns control label.
256:                 * @return control label.
257:                 */
258:                public String getLabel() {
259:                    return label;
260:                }
261:
262:                /**
263:                 * Returns whether the control is disabled.
264:                 * @return whether the control is disabled.
265:                 */
266:                public boolean isDisabled() {
267:                    return disabled;
268:                }
269:            }
270:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.