Source Code Cross Referenced for TableRule.java in  » Web-Framework » argun » biz » hammurapi » web » mda » db » 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 » argun » biz.hammurapi.web.mda.db 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * argun 1.0
003:         * Web 2.0 delivery framework 
004:         * Copyright (C) 2007  Hammurapi Group
005:         *
006:         * This program is free software; you can redistribute it and/or
007:         * modify it under the terms of the GNU Lesser General Public
008:         * License as published by the Free Software Foundation; either
009:         * version 2 of the License, or (at your option) any later version.
010:         *
011:         * This program is distributed in the hope that it will be useful,
012:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
013:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
014:         * Lesser General Public License for more details.
015:         *
016:         * You should have received a copy of the GNU Lesser General Public
017:         * License along with this library; if not, write to the Free Software
018:         * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
019:         *
020:         * URL: http://www.hammurapi.biz
021:         * e-Mail: support@hammurapi.biz 
022:         */
023:        package biz.hammurapi.web.mda.db;
024:
025:        import java.io.IOException;
026:        import java.sql.Connection;
027:        import java.sql.SQLException;
028:        import java.util.HashMap;
029:        import java.util.Iterator;
030:        import java.util.Map;
031:
032:        import org.apache.log4j.Logger;
033:
034:        import biz.hammurapi.config.ConfigurationException;
035:        import biz.hammurapi.rules.Rule;
036:        import biz.hammurapi.sql.IdentityGenerator;
037:        import biz.hammurapi.sql.IdentityManager;
038:        import biz.hammurapi.sql.IdentityRetriever;
039:        import biz.hammurapi.sql.SQLProcessor;
040:        import biz.hammurapi.web.ActionsBase;
041:        import biz.hammurapi.web.HammurapiWebException;
042:        import biz.hammurapi.web.eval.EvaluationResult;
043:        import biz.hammurapi.web.eval.EvaluatorFactory;
044:        import biz.hammurapi.web.eval.ResourceLocator;
045:        import biz.hammurapi.web.mda.db.model.Column;
046:        import biz.hammurapi.web.mda.db.model.Table;
047:        import biz.hammurapi.web.menu.sql.HelpTopicImpl;
048:        import biz.hammurapi.web.menu.sql.MenuEngine;
049:        import biz.hammurapi.web.menu.sql.XmenuImpl;
050:        import biz.hammurapi.web.util.GuidGenerator;
051:
052:        /**
053:         * Rule to generate system objects from table.
054:         * @author Pavel
055:         *
056:         */
057:        public class TableRule extends Rule {
058:            private static final Logger logger = Logger
059:                    .getLogger(TableRule.class);
060:
061:            private ResourceLocator resourceLocator;
062:            private EvaluatorFactory evaluatorFactory;
063:            private SQLProcessor sqlProcessor;
064:            private IdentityManager identityManager;
065:            private GuidGenerator guidGenerator;
066:            private String tablePackage;
067:
068:            public void start() throws ConfigurationException {
069:                super .start();
070:                resourceLocator = (ResourceLocator) get("/@resource-locator");
071:                if (resourceLocator == null) {
072:                    throw new ConfigurationException(
073:                            "Resource locator not found");
074:                }
075:                evaluatorFactory = (EvaluatorFactory) get("/@evaluator-factory");
076:                if (evaluatorFactory == null) {
077:                    throw new ConfigurationException(
078:                            "Evaluator factory not found");
079:                }
080:                sqlProcessor = (SQLProcessor) get("/@sql-processor");
081:                if (sqlProcessor == null) {
082:                    throw new ConfigurationException("SQL Processor not found");
083:                }
084:                identityManager = (IdentityManager) get("/@identity-manager");
085:                if (identityManager == null) {
086:                    throw new ConfigurationException(
087:                            "Identity manager not found");
088:                }
089:                guidGenerator = (GuidGenerator) get("/@guid-generator");
090:                if (guidGenerator == null) {
091:                    guidGenerator = new GuidGenerator();
092:                }
093:                tablePackage = (String) get("/@table-package");
094:            }
095:
096:            public Object infer(Table table) {
097:                //		System.out.println("Processing table "+table.getName());
098:                Integer parent = (Integer) get("/@parent-menu");
099:
100:                // Menu entries
101:
102:                try {
103:                    // List
104:                    if (table.hasView("list")) {
105:                        XmenuImpl listMenu = createMenu("list", table);
106:                        if (parent != null) {
107:                            listMenu.setParent(parent);
108:                        }
109:                        listMenu.setScope("Public");
110:                        listMenu.setName(table.getLabel());
111:                        insertMenu(listMenu);
112:
113:                        parent = new Integer(listMenu.getId());
114:
115:                        // Help
116:                        MenuEngine engine = new MenuEngine(sqlProcessor);
117:                        if (!ActionsBase.isBlank(table.getDescription())) {
118:                            HelpTopicImpl helpTopic = new HelpTopicImpl(true);
119:                            helpTopic.setMenuId(listMenu.getId());
120:                            helpTopic.setType("Content");
121:                            helpTopic.setName("main");
122:                            helpTopic.setContent(table.getDescription());
123:                            engine.insertHelpTopic(helpTopic);
124:                        }
125:
126:                        // Menu entries
127:
128:                        // Columns
129:                        Iterator it = table.getColumns().iterator();
130:                        while (it.hasNext()) {
131:                            Column column = (Column) it.next();
132:                            if (!ActionsBase.isBlank(column.getDescription())) {
133:                                HelpTopicImpl helpTopic = new HelpTopicImpl(
134:                                        true);
135:                                helpTopic.setMenuId(listMenu.getId());
136:                                helpTopic.setType("Content");
137:                                helpTopic.setName("#Attributes#"
138:                                        + column.getLabel());
139:                                helpTopic.setContent(column.getDescription());
140:                                engine.insertHelpTopic(helpTopic);
141:                            }
142:                        }
143:                    }
144:
145:                    // View
146:                    if (table.hasView("view")) {
147:                        XmenuImpl viewMenu = createMenu("view", table);
148:                        viewMenu.setParent(parent);
149:                        viewMenu.setScope("Hidden");
150:                        insertMenu(viewMenu);
151:                    }
152:
153:                    // Create
154:                    if (table.hasView("create")) {
155:                        XmenuImpl createMenu = createMenu("create", table);
156:                        createMenu.setParent(parent);
157:                        createMenu.setScope("Public");
158:                        insertMenu(createMenu);
159:                    }
160:
161:                    // Edit
162:                    if (table.hasView("edit")) {
163:                        XmenuImpl editMenu = createMenu("edit", table);
164:                        editMenu.setParent(parent);
165:                        editMenu.setScope("Hidden");
166:                        insertMenu(editMenu);
167:                    }
168:
169:                    // Delete
170:                    if (table.hasView("delete")) {
171:                        XmenuImpl deleteMenu = createMenu("delete", table);
172:                        deleteMenu.setParent(parent);
173:                        deleteMenu.setScope("Hidden");
174:                        deleteMenu.setType("action");
175:                        deleteMenu.setXid("delete");
176:                        insertMenu(deleteMenu);
177:                    }
178:                    return new GenerationResult("Generation successful");
179:                } catch (Throwable e) {
180:                    logger.error(e);
181:                    return new GenerationResult(e);
182:                }
183:            }
184:
185:            public static class GenerationResult {
186:                private Object result;
187:
188:                public GenerationResult(Object result) {
189:                    this .result = result;
190:                }
191:
192:                public Object getResult() {
193:                    return result;
194:                }
195:            }
196:
197:            /**
198:             * Creates menu and populates standard values.
199:             * @param name
200:             * @param prefix
201:             * @param table
202:             * @return
203:             * @throws HammurapiWebException 
204:             */
205:            private XmenuImpl createMenu(String name, Table table)
206:                    throws HammurapiWebException {
207:                logger.info("Generating " + name);
208:                XmenuImpl menu = new XmenuImpl(true);
209:                String xidPrefix = tablePackage == null ? table.getJavaName()
210:                        + "." : tablePackage + "." + table.getJavaName() + ".";
211:                menu.setXid(xidPrefix + name);
212:                menu.setName(name);
213:                menu.setDescription(name + " " + table.getLabel());
214:                menu.setTitle(menu.getDescription());
215:                Map context = new HashMap();
216:                context.put("result", table);
217:                context.put("xidPrefix", xidPrefix);
218:                context.put("view", name);
219:                EvaluationResult matchHandler = evaluatorFactory.evaluate(name
220:                        + "MatchHandler", context, getClass().getClassLoader(),
221:                        resourceLocator);
222:                if (matchHandler != null) {
223:                    menu.setMatchHandler(matchHandler.getOutput());
224:                }
225:                String[] content = instantiateTemplate(name + "Content",
226:                        context);
227:                if (content != null) {
228:                    menu.setContentType(content[0]);
229:                    menu.setContent(content[1]);
230:                }
231:                String[] formHandler = instantiateTemplate(
232:                        name + "FormHandler", context);
233:                if (formHandler != null) {
234:                    menu.setFormHandlerType(formHandler[0]);
235:                    menu.setFormHandlerCode(formHandler[1]);
236:                }
237:                menu.setType("item");
238:                menu.setGuid(guidGenerator.nextGUID());
239:
240:                return menu;
241:            }
242:
243:            /**
244:             * Finds a template by extension and evaluates it.
245:             * @param name Short template name. E.g. "main"
246:             * @param context 
247:             * @return
248:             * @throws IOException 
249:             * @throws HammurapiWebException 
250:             */
251:            private String[] instantiateTemplate(String name, Map context)
252:                    throws HammurapiWebException {
253:                Iterator it = evaluatorFactory.getNames().iterator();
254:                while (it.hasNext()) {
255:                    String language = (String) it.next();
256:                    String extension = evaluatorFactory.getExtension(language);
257:                    EvaluationResult result = evaluatorFactory.evaluate(name
258:                            + extension, context, getClass().getClassLoader(),
259:                            resourceLocator);
260:                    if (result != null) {
261:                        return new String[] { language, result.getOutput() };
262:                    }
263:                }
264:                return null;
265:            }
266:
267:            private void insertMenu(XmenuImpl menu) throws SQLException {
268:                Connection con = sqlProcessor.getConnection();
269:                if (identityManager instanceof  IdentityGenerator) {
270:                    menu.setId(((IdentityGenerator) identityManager).generate(
271:                            con, "XMENU"));
272:                }
273:                menu.insert(new SQLProcessor(con, null), "XMENU");
274:                if (identityManager instanceof  IdentityRetriever) {
275:                    menu.setId(((IdentityRetriever) identityManager)
276:                            .retrieve(con));
277:                }
278:                sqlProcessor.releaseConnection(con);
279:            }
280:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.