Source Code Cross Referenced for AbstractWidget.java in  » Content-Management-System » apache-lenya-2.0 » org » apache » cocoon » woody » 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.woody.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.woody.formmodel;
018:
019:        import java.util.ArrayList;
020:        import java.util.Iterator;
021:        import java.util.List;
022:        import java.util.Locale;
023:
024:        import org.apache.cocoon.woody.Constants;
025:        import org.apache.cocoon.woody.FormContext;
026:        import org.apache.cocoon.woody.event.WidgetEvent;
027:        import org.apache.cocoon.woody.validation.WidgetValidator;
028:        import org.apache.cocoon.xml.AttributesImpl;
029:        import org.xml.sax.ContentHandler;
030:        import org.xml.sax.SAXException;
031:
032:        /**
033:         * Abstract base class for Widget implementations. Provides functionality
034:         * common to many widgets.
035:         * 
036:         * @version $Id: AbstractWidget.java 433543 2006-08-22 06:22:54Z crossley $
037:         */
038:        public abstract class AbstractWidget implements  Widget {
039:            private String location;
040:            private Widget parent;
041:            private Form form;
042:            protected AbstractWidgetDefinition definition;
043:
044:            private List validators;
045:
046:            /**
047:             * Sets the definition of this widget.
048:             */
049:            protected void setDefinition(AbstractWidgetDefinition definition) {
050:                this .definition = definition;
051:            }
052:
053:            /**
054:             * Gets the id of this widget.
055:             */
056:            public String getId() {
057:                return definition.getId();
058:            }
059:
060:            /**
061:             * Sets the source location of this widget.
062:             */
063:            protected void setLocation(String location) {
064:                this .location = location;
065:            }
066:
067:            /**
068:             * Gets the source location of this widget.
069:             */
070:            public String getLocation() {
071:                return this .location;
072:            }
073:
074:            public Widget getParent() {
075:                return parent;
076:            }
077:
078:            public void setParent(Widget widget) {
079:                this .parent = widget;
080:            }
081:
082:            public Form getForm() {
083:                if (this .form == null) {
084:                    if (parent == null) {
085:                        this .form = (Form) this ;
086:                    } else {
087:                        this .form = parent.getForm();
088:                    }
089:                }
090:                return this .form;
091:            }
092:
093:            public String getNamespace() {
094:                if (getParent() != null
095:                        && getParent().getNamespace().length() > 0) {
096:                    return getParent().getNamespace() + "." + getId();
097:                } else {
098:                    return getId();
099:                }
100:            }
101:
102:            public String getFullyQualifiedId() {
103:                if (parent != null) {
104:                    String namespace = parent.getNamespace();
105:                    if (namespace.length() > 0) {
106:                        return namespace + "." + getId();
107:                    }
108:                }
109:                return getId();
110:            }
111:
112:            public Object getValue() {
113:                return null;
114:            }
115:
116:            public void setValue(Object object) {
117:                throw new RuntimeException("Cannot set the value of widget "
118:                        + getFullyQualifiedId());
119:            }
120:
121:            public boolean isRequired() {
122:                return false;
123:            }
124:
125:            public Widget getWidget(String id) {
126:                return null;
127:            }
128:
129:            public void broadcastEvent(WidgetEvent event) {
130:                throw new UnsupportedOperationException("Widget "
131:                        + this .getFullyQualifiedId()
132:                        + " doesn't handle events.");
133:            }
134:
135:            /**
136:             * Add a validator to this widget instance.
137:             * 
138:             * @param validator
139:             */
140:            public void addValidator(WidgetValidator validator) {
141:                if (this .validators == null) {
142:                    this .validators = new ArrayList();
143:                }
144:
145:                this .validators.add(validator);
146:            }
147:
148:            /**
149:             * Remove a validator from this widget instance
150:             * 
151:             * @param validator
152:             * @return <code>true</code> if the validator was found.
153:             */
154:            public boolean removeValidator(WidgetValidator validator) {
155:                return (this .validators == null) ? false : this .validators
156:                        .remove(validator);
157:            }
158:
159:            public boolean validate(FormContext context) {
160:                // Test validators from the widget definition
161:                if (!this .definition.validate(this , context)) {
162:                    // Failed
163:                    return false;
164:                } else {
165:                    // Definition sussessful, test local validators
166:                    if (this .validators == null) {
167:                        // No local validators
168:                        return true;
169:                    } else {
170:                        // Iterate on local validators
171:                        Iterator iter = this .validators.iterator();
172:                        while (iter.hasNext()) {
173:                            WidgetValidator validator = (WidgetValidator) iter
174:                                    .next();
175:                            if (!validator.validate(this , context)) {
176:                                return false;
177:                            }
178:                        }
179:                        // All local iterators successful
180:                        return true;
181:                    }
182:                }
183:            }
184:
185:            public void generateLabel(ContentHandler contentHandler)
186:                    throws SAXException {
187:                if (definition != null) {
188:                    definition.generateDisplayData("label", contentHandler);
189:                }
190:            }
191:
192:            public void generateItemSaxFragment(ContentHandler contentHandler,
193:                    Locale locale) throws SAXException {
194:                // Do nothing
195:            }
196:
197:            public void generateSaxFragment(ContentHandler contentHandler,
198:                    Locale locale, String element, WidgetDefinition definition)
199:                    throws SAXException {
200:                AttributesImpl attrs = new AttributesImpl();
201:                attrs.addCDATAAttribute("id", getFullyQualifiedId());
202:                contentHandler.startElement(Constants.WI_NS, element,
203:                        Constants.WI_PREFIX_COLON + element, attrs);
204:                generateItemSaxFragment(contentHandler, locale);
205:                contentHandler.endElement(Constants.WI_NS, element,
206:                        Constants.WI_PREFIX_COLON + element);
207:            }
208:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.