Source Code Cross Referenced for DataConfig.java in  » J2EE » Enhydra-Demos » org » enhydra » barracuda » config » 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 » J2EE » Enhydra Demos » org.enhydra.barracuda.config 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Enhydra Java Application Server Project
003:         * 
004:         * The contents of this file are subject to the Enhydra Public License
005:         * Version 1.1 (the "License"); you may not use this file except in
006:         * compliance with the License. You may obtain a copy of the License on
007:         * the Enhydra web site (http://www.enhydra.org/).
008:         * 
009:         * Software distributed under the License is distributed on an "AS IS"
010:         * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See 
011:         * the License for the specific terms governing rights and limitations
012:         * under the License.
013:         * 
014:         * The Initial Developer of the Enhydra Application Server is Lutris
015:         * Technologies, Inc. The Enhydra Application Server and portions created
016:         * by Lutris Technologies, Inc. are Copyright Lutris Technologies, Inc.
017:         * All Rights Reserved.
018:         * 
019:         * Contributor(s):
020:         * 
021:         * $Id: DataConfig.java,v 1.1 2006-09-11 12:30:02 sinisa Exp $
022:         */
023:        package org.enhydra.barracuda.config;
024:
025:        import java.io.*;
026:        import java.util.*;
027:        import javax.servlet.*;
028:        import javax.servlet.http.*;
029:
030:        import org.apache.log4j.*;
031:
032:        import org.enhydra.barracuda.config.events.*;
033:        import org.barracudamvc.core.comp.*;
034:        import org.barracudamvc.core.event.*;
035:        import org.barracudamvc.core.forms.*;
036:        import org.barracudamvc.plankton.data.*;
037:        import org.barracudamvc.plankton.http.*;
038:
039:        /**
040:         * This class provides the methods needed to configure the data
041:         * screen
042:         */
043:        public class DataConfig extends DefaultEventGateway {
044:
045:            protected static final Logger logger = Logger
046:                    .getLogger(DataConfig.class.getName());
047:
048:            //form id (must be unique)
049:            public static final String FORM = DataConfig.class.getName()
050:                    + ".Form";
051:
052:            //model name
053:            public static final String MODEL_NAME = "Data";
054:
055:            //model elements (these are the data items supported)
056:            public static final String DEFAULT_STATE_MAP_DL = "DefaultStateMap_DebugLevel";
057:            public static final String ERROR_MESSAGE = "ErrorMessage";
058:            public static final String SUCCESS_MESSAGE = "SuccessMessage";
059:            public static final String UPDATE_BUTTON = "UpdateButton";
060:
061:            //private vars
062:            private ListenerFactory updateConfigFactory = new DefaultListenerFactory() {
063:                public BaseEventListener getInstance() {
064:                    return new UpdateConfigHandler();
065:                }
066:
067:                public String getListenerID() {
068:                    return getID(UpdateConfigHandler.class);
069:                }
070:            };
071:
072:            public DataConfig() {
073:                //specify generic interest
074:                specifyLocalEventInterests(updateConfigFactory);
075:            }
076:
077:            //------------------------------------------------------------
078:            //                       Data Models
079:            //------------------------------------------------------------
080:            /**
081:             * define the template model that backs this screen
082:             */
083:            class DataModel extends AbstractTemplateModel {
084:
085:                //register the model by name
086:                public String getName() {
087:                    return MODEL_NAME;
088:                }
089:
090:                //provide items by key
091:                public Object getItem(String key) {
092:                    if (logger.isDebugEnabled())
093:                        logger.debug("Asking for key:" + key);
094:                    ViewContext vc = getViewContext();
095:
096:                    //Handle requests for data
097:                    if (key.equals(DEFAULT_STATE_MAP_DL)) {
098:                        return ScreenUtil.getDebugLevelComp2(vc, key,
099:                                DefaultStateMap.class);
100:                    } else if (key.equals(ERROR_MESSAGE)) {
101:                        return ScreenUtil.getErrMsg(vc, FORM, ERROR_MESSAGE);
102:                    } else if (key.equals(SUCCESS_MESSAGE)) {
103:                        return ScreenUtil.getSuccessMsg(vc, FORM,
104:                                SUCCESS_MESSAGE);
105:                    } else if (key.equals(UPDATE_BUTTON)) {
106:                        return ScreenUtil.getUpdateButtonComp(vc,
107:                                updateConfigFactory);
108:                    } else
109:                        return super .getItem(key);
110:                }
111:            }
112:
113:            //------------------------------------------------------------
114:            //                  Form Mappings, Validators
115:            //------------------------------------------------------------
116:            /**
117:             * define the form map that backs the model
118:             */
119:            class DataForm extends DefaultFormMap {
120:                public DataForm() {
121:                    //define the elements (note: these don't need any validators). Note
122:                    //also that we set the defaults to the current values. This allows
123:                    //us just to reset all current values down below without checking to
124:                    //see if the elements actually got passed in from the form.
125:                    if (logger.isDebugEnabled())
126:                        logger.debug("Defining form elements");
127:                    this .defineElement(new DefaultFormElement(
128:                            DEFAULT_STATE_MAP_DL, FormType.INTEGER,
129:                            new Integer(ScreenUtil
130:                                    .cvtLevelToInt(DefaultStateMap.class)),
131:                            null, false));
132:                }
133:            }
134:
135:            //------------------------------------------------------------
136:            //             Model 2 - Controller Event Handlers
137:            //------------------------------------------------------------
138:            /**
139:             * UpdateConfigHandler - handle the request to update the config 
140:             * screen.
141:             */
142:            class UpdateConfigHandler extends DefaultBaseEventListener {
143:                public void handleControlEvent(ControlEventContext context)
144:                        throws EventException, ServletException, IOException {
145:                    //figure out our target locale and get the appropriate screen
146:                    Locale locale = context.getViewCapabilities()
147:                            .getClientLocale();
148:                    MasterScreen screen = new MasterScreenFactory()
149:                            .getInstance(DataConfig.this , context, locale);
150:                    if (logger.isDebugEnabled())
151:                        ServletUtil.showParams(context.getRequest(), logger);
152:
153:                    //create the login form
154:                    ValidationException ve = null;
155:                    DataForm formMap = new DataForm();
156:                    try {
157:                        //map/validate the form
158:                        formMap.map(context.getRequest()).validate(true);
159:
160:                        //If there were no errors, update the data. Note that we just
161:                        //assume that all the data is here. The reason we can do this is
162:                        //because we prepopulated the form up above with the default values.
163:                        //The more proper way would be to check each value, see if it's set,
164:                        //and then only update it if the value has actually changed. Lot more
165:                        //code to do that though, and since we're just setting statics, the
166:                        //cost of doing it this way is minimal.
167:                        ScreenUtil
168:                                .setLevel(DefaultStateMap.class,
169:                                        ((Integer) formMap
170:                                                .getVal(DEFAULT_STATE_MAP_DL))
171:                                                .intValue());
172:
173:                        //remember our success
174:                        formMap.putState(SUCCESS_MESSAGE, new Boolean(true));
175:
176:                    } catch (ValidationException e) {
177:                        ve = e;
178:                    }
179:
180:                    //store the error message in the form and then put the form in the
181:                    //the event context
182:                    formMap.putState(ERROR_MESSAGE, ve);
183:                    context.putState(FORM, formMap);
184:
185:                    //fire an update so that the screen will redraw
186:                    ((DataModel) screen.dataModel).fireModelChanged();
187:
188:                    //redirect to the get screen again
189:                    throw new ClientSideRedirectException(new GetBConfig());
190:                }
191:            }
192:
193:            //------------------------------------------------------------
194:            //                         Utility Methods
195:            //------------------------------------------------------------
196:            public TemplateModel getModel() {
197:                return new DataModel();
198:            }
199:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.