Source Code Cross Referenced for ConfigActionLoader.java in  » Web-Framework » JAT » com » jat » presentation » controller » 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 » JAT » com.jat.presentation.controller 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package com.jat.presentation.controller;
002:
003:        import java.io.IOException;
004:        import java.util.Enumeration;
005:        import java.util.Hashtable;
006:        import java.util.Vector;
007:
008:        import com.jat.core.config.Config;
009:        import com.jat.core.log.LogManager;
010:
011:        /**
012:         * <p>Title: JAT</p>
013:         * <p>Description: </p>
014:         * <p>Copyright: Copyright (c) 2004 -2005 Stefano Fratini (stefano.fratini@gmail.com)</p>
015:         * <p>Distributed under the terms of the GNU Lesser General Public License, v2.1 or later</p>
016:         * @author stf
017:         * @version 1.0
018:         * @since 1.2
019:         */
020:
021:        public class ConfigActionLoader implements  ActionLoader {
022:
023:            public final static String ACTION_KEY = "action";
024:            public final static String ACTION_NAME = ".name";
025:            public final static String ACTION_CLASS_NAME = ".class_name";
026:            public final static String ACTION_NEXT_PAGE = ".next_page";
027:            public final static String ACTION_ERROR_PAGE = ".error_page";
028:            public final static String ACTION_LOG_REQUIRED = ".log_required";
029:            public final static String ACTION_PRIVILEGE = ".privilege";
030:            public final static String ACTION_METHOD = ".method";
031:            public final static String ACTION_FLOW = ".previous_page";
032:
033:            public ConfigActionLoader() {
034:            }
035:
036:            public Hashtable getActionList() throws Exception {
037:                LogManager.sendDebug(this .getClass().getName()
038:                        + "::getActionList: start");
039:                Hashtable ret = new Hashtable();
040:                Config config = this .getConfig();
041:                Vector keys = config.getSubKeys(SECTION, ACTION_KEY);
042:                for (Enumeration e = keys.elements(); e.hasMoreElements();) {
043:                    String key = (String) e.nextElement();
044:                    String className = config.getValue(SECTION, key
045:                            + ACTION_CLASS_NAME);
046:                    Action action = (Action) Class.forName(className)
047:                            .newInstance();
048:                    action.setName(config.getValue(SECTION, key + ACTION_NAME));
049:                    action.setNextPage(config.getValue(SECTION, key
050:                            + ACTION_NEXT_PAGE));
051:                    action.setErrorPage(config.getValue(SECTION, key
052:                            + ACTION_ERROR_PAGE));
053:                    action
054:                            .setLogRequired(config.getValue(SECTION,
055:                                    key + ACTION_LOG_REQUIRED)
056:                                    .equalsIgnoreCase("TRUE"));
057:                    try {
058:                        action.setPrivilege(config.getValue(SECTION, key
059:                                + ACTION_PRIVILEGE));
060:                    } catch (Exception ignored) {
061:                    }
062:                    action.setMethods(config.getSubValues(SECTION, key
063:                            + ACTION_METHOD));
064:                    try {
065:                        Vector flows = config.getSubValues(SECTION, key
066:                                + ACTION_FLOW);
067:                        if (flows != null && flows.size() > 0)
068:                            action.setPreviousPages(flows);
069:                    } catch (Exception ignored) {
070:                    }
071:                    LogManager.sendDebug(this .getClass().getName()
072:                            + "::getActionList: Action: " + action);
073:                    ret.put(action.getName(), action);
074:                }
075:                LogManager.sendDebug(this .getClass().getName()
076:                        + "::getActionList: end");
077:                return ret;
078:            }
079:
080:            public void persist() throws Exception {
081:                LogManager.sendDebug(this .getClass().getName()
082:                        + "::persist: start");
083:                Config config = this .getConfig();
084:                config.save();
085:                LogManager.sendDebug(this .getClass().getName()
086:                        + "::persist: end");
087:            }
088:
089:            public void remove(Action action) throws Exception {
090:                LogManager.sendDebug(this .getClass().getName()
091:                        + "::remove: start for action: " + action);
092:                String key = this .getIndexKey(action.getName());
093:                this .removeAction(key);
094:                LogManager.sendDebug(this .getClass().getName()
095:                        + "::remove: end");
096:            }
097:
098:            public void modify(String name, Action action) throws Exception {
099:                LogManager.sendDebug(this .getClass().getName()
100:                        + "::modify: start for name '" + name
101:                        + "' and action: " + action);
102:                String key = this .getIndexKey(name);
103:                this .removeAction(key);
104:                this .addAction(action, key);
105:                LogManager.sendDebug(this .getClass().getName()
106:                        + "::modify: end");
107:            }
108:
109:            public void add(Action action) throws Exception {
110:                LogManager.sendDebug(this .getClass().getName()
111:                        + "::add: start for action: " + action);
112:                int index = 1;
113:                String key = null;
114:                while (key == null) {
115:                    String k = ACTION_KEY + (index++);
116:                    if (!this .getConfig().existsValue(SECTION, k + ACTION_NAME))
117:                        key = k;
118:                }
119:                this .addAction(action, key);
120:                LogManager.sendDebug(this .getClass().getName() + "::add: end");
121:            }
122:
123:            private void addAction(Action action, String key) throws Exception {
124:                try {
125:                    Config config = this .getConfig();
126:                    config.addValue(SECTION, key + ACTION_NAME, action
127:                            .getName());
128:                    config.addValue(SECTION, key + ACTION_CLASS_NAME, action
129:                            .getClass().getName());
130:                    config.addValue(SECTION, key + ACTION_NEXT_PAGE, action
131:                            .getNextPage());
132:                    config.addValue(SECTION, key + ACTION_ERROR_PAGE, action
133:                            .getErrorPage());
134:                    config.addValue(SECTION, key + ACTION_LOG_REQUIRED, ""
135:                            + action.isLogRequired());
136:                    if (action.getPrivilege() != null)
137:                        config.addValue(SECTION, key + ACTION_PRIVILEGE, action
138:                                .getPrivilege());
139:                    int index = 1;
140:                    for (Enumeration e = action.getMethods().elements(); e
141:                            .hasMoreElements();)
142:                        config.addValue(SECTION, key + ACTION_METHOD
143:                                + (index++), (String) e.nextElement());
144:                    for (Enumeration e = action.getPreviousPages().elements(); e
145:                            .hasMoreElements();)
146:                        config.addValue(SECTION, key + ACTION_FLOW + (index++),
147:                                (String) e.nextElement());
148:                } catch (Exception ex) {
149:                    throw new Exception(this .getClass().getName()
150:                            + "::addAction: exception: " + ex);
151:                }
152:            }
153:
154:            private void removeAction(String key) throws Exception {
155:                try {
156:                    Config config = this .getConfig();
157:                    config.removeKeys(SECTION, key);
158:                } catch (Exception ex) {
159:                    throw new Exception(this .getClass().getName()
160:                            + "::removeAction: exception: " + ex);
161:                }
162:            }
163:
164:            private Config getConfig() throws Exception {
165:                String name = Config.getCurrent().getValue(SECTION,
166:                        "config.name");
167:                Config config = Config.getCurrent().getConfig(name);
168:                if (config == null) {
169:                    LogManager.sendError(this .getClass().getName()
170:                            + "::getConfig: exception: Config file " + name
171:                            + " not found");
172:                    throw new Exception("Config file " + name + " not found");
173:                }
174:                return config;
175:            }
176:
177:            private String getIndexKey(String actionName) throws Exception {
178:                for (Enumeration e = this .getConfig().getSubKeys(SECTION,
179:                        ACTION_KEY).elements(); e.hasMoreElements();) {
180:                    String key = (String) e.nextElement();
181:                    if (this .getConfig().getValue(SECTION, key + ACTION_NAME)
182:                            .equalsIgnoreCase(actionName))
183:                        return key;
184:                }
185:                throw new Exception("config key not found for " + actionName);
186:            }
187:
188:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.