Source Code Cross Referenced for ScriptBean.java in  » J2EE » fleXive » com » flexive » war » beans » admin » main » 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 » fleXive » com.flexive.war.beans.admin.main 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /***************************************************************
002:         *  This file is part of the [fleXive](R) project.
003:         *
004:         *  Copyright (c) 1999-2007
005:         *  UCS - unique computing solutions gmbh (http://www.ucs.at)
006:         *  All rights reserved
007:         *
008:         *  The [fleXive](R) project is free software; you can redistribute
009:         *  it and/or modify it under the terms of the GNU General Public
010:         *  License as published by the Free Software Foundation;
011:         *  either version 2 of the License, or (at your option) any
012:         *  later version.
013:         *
014:         *  The GNU General Public License can be found at
015:         *  http://www.gnu.org/copyleft/gpl.html.
016:         *  A copy is found in the textfile GPL.txt and important notices to the
017:         *  license from the author are found in LICENSE.txt distributed with
018:         *  these libraries.
019:         *
020:         *  This library is distributed in the hope that it will be useful,
021:         *  but WITHOUT ANY WARRANTY; without even the implied warranty of
022:         *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
023:         *  GNU General Public License for more details.
024:         *
025:         *  For further information about UCS - unique computing solutions gmbh,
026:         *  please see the company website: http://www.ucs.at
027:         *
028:         *  For further information about [fleXive](R), please see the
029:         *  project website: http://www.flexive.org
030:         *
031:         *
032:         *  This copyright notice MUST APPEAR in all copies of the file!
033:         ***************************************************************/package com.flexive.war.beans.admin.main;
034:
035:        import com.flexive.shared.CacheAdmin;
036:        import com.flexive.shared.EJBLookup;
037:        import com.flexive.shared.FxContext;
038:        import com.flexive.shared.security.UserTicket;
039:        import com.flexive.shared.security.Role;
040:        import com.flexive.shared.exceptions.FxLoadException;
041:        import com.flexive.shared.exceptions.FxApplicationException;
042:        import com.flexive.shared.interfaces.ScriptingEngine;
043:        import com.flexive.shared.scripting.*;
044:        import com.flexive.faces.FxJsfUtils;
045:        import com.flexive.faces.beans.MessageBean;
046:        import com.flexive.faces.messages.FxFacesMsgErr;
047:        import com.flexive.faces.messages.FxFacesMsgInfo;
048:
049:        import javax.faces.context.FacesContext;
050:        import javax.faces.event.ActionEvent;
051:        import javax.faces.model.SelectItem;
052:        import java.util.*;
053:        import java.sql.SQLException;
054:
055:        /**
056:         * JSF scripting bean
057:         *
058:         * @author Johannes Wernig-Pichler (johannes.wernig-pichler@flexive.com), UCS - unique computing solutions gmbh (http://www.ucs.at)
059:         * @version $Rev: 203 $
060:         */
061:        public class ScriptBean {
062:
063:            private long id = -1;
064:            private String name;
065:            private String desc;
066:            private String code;
067:            private boolean active;
068:            private FxScriptInfoEdit sinfo;
069:            private ScriptingEngine scriptInterface;
070:            private FxScriptMapping mapping;
071:            private Map<Long, String> typeMappingNames;
072:            private Map<Long, String> assignmentMappingNames;
073:            private FxScriptScope selectedScope = null;
074:            private long selectedScriptEventId = -1;
075:
076:            private static final String ID_CACHE_KEY = ScriptBean.class + "_id";
077:
078:            // constructor
079:            public ScriptBean() {
080:                this .scriptInterface = EJBLookup.getScriptingEngine();
081:                this .sinfo = new FxScriptInfo().asEditable();
082:            }
083:
084:            public FxScriptScope getSelectedScope() {
085:                if (selectedScope == null)
086:                    selectedScope = FxScriptScope.All;
087:                return selectedScope;
088:            }
089:
090:            public List<SelectItem> getEventsForScope() {
091:                //if the selected event is not in the list of events for the currently selected scope
092:                //reset the selected event id to default -1==all events
093:                boolean selectedEventFound = false;
094:                FxScriptScope scope = getSelectedScope();
095:                List<SelectItem> eventsForScope = new ArrayList<SelectItem>();
096:                eventsForScope.add(new SelectItem(-1, MessageBean.getInstance()
097:                        .getMessage("Script.selectItem.allEvents")));
098:                for (FxScriptEvent e : FxScriptEvent.values()) {
099:                    if (e.getScope().compareTo(scope) == 0
100:                            || scope.compareTo(FxScriptScope.All) == 0) {
101:                        eventsForScope.add(new SelectItem(e.getId(), e
102:                                .getName()));
103:                        if (getSelectedScriptEventId() == e.getId())
104:                            selectedEventFound = true;
105:                    }
106:                }
107:
108:                if (!selectedEventFound)
109:                    this .selectedScriptEventId = -1;
110:
111:                return eventsForScope;
112:            }
113:
114:            public void setSelectedScope(FxScriptScope selectedScope) {
115:                this .selectedScope = selectedScope;
116:            }
117:
118:            public long getSelectedScriptEventId() {
119:                return selectedScriptEventId;
120:            }
121:
122:            public void setSelectedScriptEventId(long selectedScriptEventId) {
123:                this .selectedScriptEventId = selectedScriptEventId;
124:            }
125:
126:            public List<FxScriptInfo> getScriptsForEvent() {
127:                long eventId = getSelectedScriptEventId();
128:                List<FxScriptInfo> scriptsForEvent = new ArrayList<FxScriptInfo>();
129:                for (FxScriptInfo s : CacheAdmin.getFilteredEnvironment()
130:                        .getScripts())
131:                    if ((eventId == -1 && getSelectedScope().compareTo(
132:                            FxScriptScope.All) == 0)
133:                            || (eventId == -1 && s.getEvent().getScope()
134:                                    .compareTo(getSelectedScope()) == 0)
135:                            || (s.getEvent().getId() == eventId && getSelectedScope()
136:                                    .compareTo(FxScriptScope.All) == 0)
137:                            || (s.getEvent().getId() == eventId && s.getEvent()
138:                                    .getScope().compareTo(getSelectedScope()) == 0))
139:                        scriptsForEvent.add(s);
140:                return scriptsForEvent;
141:            }
142:
143:            public long getId() {
144:                return id;
145:            }
146:
147:            public void setId(long id) {
148:                this .id = id;
149:            }
150:
151:            public boolean isActive() {
152:                return active;
153:            }
154:
155:            public void setActive(boolean active) {
156:                this .active = active;
157:            }
158:
159:            /**
160:             * Loads the script specified by the parameter id.
161:             *
162:             * @return the next page to render
163:             */
164:
165:            public String editScript() {
166:                ensureScriptIdSet();
167:                setSinfo(CacheAdmin.getEnvironment().getScript(id).asEditable());
168:                try {
169:                    this .mapping = scriptInterface.loadScriptMapping(null, id);
170:                    this .typeMappingNames = new HashMap<Long, String>();
171:                    // we need the type names for the user interface and the type ids for the links
172:                    for (FxScriptMappingEntry entry : this .mapping
173:                            .getMappedTypes()) {
174:                        this .typeMappingNames.put(entry.getId(), CacheAdmin
175:                                .getEnvironment().getType(entry.getId())
176:                                .getName());
177:                        for (long id : entry.getDerivedIds())
178:                            this .typeMappingNames.put(id, CacheAdmin
179:                                    .getEnvironment().getType(id).getName());
180:                    }
181:                    this .assignmentMappingNames = new HashMap<Long, String>();
182:                    for (FxScriptMappingEntry entry : this .mapping
183:                            .getMappedAssignments()) {
184:                        this .assignmentMappingNames.put(entry.getId(),
185:                                CacheAdmin.getEnvironment().getAssignment(
186:                                        entry.getId()).getXPath());
187:                        for (long id : entry.getDerivedIds())
188:                            this .assignmentMappingNames.put(id, CacheAdmin
189:                                    .getEnvironment().getAssignment(id)
190:                                    .getXPath());
191:                    }
192:                } catch (FxLoadException e) {
193:                    new FxFacesMsgErr("Script.err.loadMap").addToContext();
194:                } catch (SQLException e) {
195:                    new FxFacesMsgErr("Script.err.loadMap").addToContext();
196:                }
197:                setName(sinfo.getName());
198:                setDesc(sinfo.getDescription());
199:                setCode(sinfo.getCode());
200:                setActive(sinfo.isActive());
201:                return "scriptEdit";
202:            }
203:
204:            public FxScriptInfo getSinfo() {
205:                return sinfo;
206:            }
207:
208:            public void setSinfo(FxScriptInfoEdit sinfo) {
209:                this .sinfo = sinfo;
210:            }
211:
212:            public String getName() {
213:                return name;
214:            }
215:
216:            public void setName(String name) {
217:                this .name = name;
218:            }
219:
220:            public String getDesc() {
221:                return desc;
222:            }
223:
224:            public void setDesc(String desc) {
225:                this .desc = desc;
226:            }
227:
228:            public String getCode() {
229:                return code;
230:            }
231:
232:            public void setCode(String code) {
233:                this .code = code;
234:            }
235:
236:            private void ensureScriptIdSet() {
237:                if (this .id <= 0) {
238:                    this .id = (Long) FxJsfUtils
239:                            .getSessionAttribute(ID_CACHE_KEY);
240:                }
241:            }
242:
243:            /**
244:             * Deletes a script, with the id specified by id.
245:             *
246:             * @return the next pageto render
247:             */
248:            public String deleteScript() {
249:
250:                final UserTicket ticket = FxContext.get().getTicket();
251:                if (!ticket.isInRole(Role.ScriptManagement)) {
252:                    new FxFacesMsgErr("Script.err.deletePerm").addToContext();
253:                    return "scriptOverview";
254:                }
255:
256:                ensureScriptIdSet();
257:                try {
258:                    scriptInterface.removeScript(id);
259:                    // display updated script list  -->handled via a4j now
260:                    //updateScriptList();  -->handled via a4j now
261:                    new FxFacesMsgInfo("Script.nfo.deleted").addToContext();
262:                } catch (FxApplicationException e) {
263:                    new FxFacesMsgErr("Script.err.delete").addToContext();
264:                }
265:                return "scriptOverview";
266:            }
267:
268:            /**
269:             * Executes a script, with the id specified by id.
270:             *
271:             * @return the next page to render
272:             */
273:            public String runScript() {
274:
275:                final UserTicket ticket = FxContext.get().getTicket();
276:                if (!ticket.isInRole(Role.ScriptExecution)) {
277:                    new FxFacesMsgErr("Script.err.runPerm").addToContext();
278:                    return "scriptOverview";
279:                }
280:
281:                ensureScriptIdSet();
282:                try {
283:                    scriptInterface.runScript(id);
284:                    new FxFacesMsgInfo("Script.nfo.executed", CacheAdmin
285:                            .getEnvironment().getScript(id).getName())
286:                            .addToContext();
287:                } catch (FxApplicationException e) {
288:                    new FxFacesMsgErr("Script.err.run").addToContext();
289:                }
290:                return "scriptOverview";
291:            }
292:
293:            /**
294:             * Creates a new script from the beans data.
295:             *
296:             * @return the next jsf page to render
297:             */
298:            public String createScript() {
299:                final UserTicket ticket = FxContext.get().getTicket();
300:                if (!ticket.isInRole(Role.ScriptManagement)) {
301:                    new FxFacesMsgErr("Script.err.createPerm").addToContext();
302:                    return "scriptOverview";
303:                }
304:
305:                if (sinfo.getName().length() < 1 || sinfo.getEvent() == null) {
306:                    new FxFacesMsgErr("Script.err.createMiss").addToContext();
307:                    return "scriptCreate";
308:                }
309:
310:                try {
311:                    setId(scriptInterface.createScript(sinfo.getEvent(),
312:                            sinfo.getName(), sinfo.getDescription(),
313:                            sinfo.getCode()).getId());
314:                    setSinfo(CacheAdmin.getEnvironment().getScript(id)
315:                            .asEditable());
316:                    // display updated script list
317:                    //updateScriptList();
318:                    new FxFacesMsgInfo("Script.nfo.created", sinfo.getName())
319:                            .addToContext();
320:                } catch (FxApplicationException e) {
321:                    new FxFacesMsgErr("Script.err.create").addToContext();
322:                }
323:                return "scriptOverview";
324:            }
325:
326:            /**
327:             * Saves the edited script
328:             *
329:             * @return the next page to render
330:             */
331:            public String saveScript() {
332:
333:                final UserTicket ticket = FxContext.get().getTicket();
334:                if (!ticket.isInRole(Role.ScriptManagement)) {
335:                    new FxFacesMsgErr("Script.err.editPerm").addToContext();
336:                    return "scriptOverview";
337:                }
338:
339:                ensureScriptIdSet();
340:
341:                try {
342:                    scriptInterface.updateScriptInfo(id, sinfo.getEvent(),
343:                            sinfo.getName(), sinfo.getDescription(), sinfo
344:                                    .getCode(), sinfo.isActive());
345:                    //updateScriptList(); needed (see mandators) ???
346:                    new FxFacesMsgInfo("Script.nfo.updated").addToContext();
347:                    return "scriptOverview";
348:                } catch (FxApplicationException e) {
349:                    new FxFacesMsgErr("Script.err.save").addToContext();
350:                    return "scriptOverview";
351:                }
352:            }
353:
354:            public List<Map.Entry<Long, String>> getTypeMappingNames() {
355:                ArrayList<Map.Entry<Long, String>> list = new ArrayList<Map.Entry<Long, String>>(
356:                        this .typeMappingNames.entrySet().size());
357:                for (Map.Entry<Long, String> entry : this .typeMappingNames
358:                        .entrySet()) {
359:                    list.add(entry);
360:                }
361:                return list;
362:            }
363:
364:            public List<Map.Entry<Long, String>> getAssignmentMappingNames() {
365:                ArrayList<Map.Entry<Long, String>> list = new ArrayList<Map.Entry<Long, String>>(
366:                        this .assignmentMappingNames.entrySet().size());
367:                for (Map.Entry<Long, String> entry : this .assignmentMappingNames
368:                        .entrySet()) {
369:                    list.add(entry);
370:                }
371:                return list;
372:            }
373:
374:            public FxScriptMapping getMapping() {
375:                return mapping;
376:            }
377:
378:            /**
379:             * called from the structure editor -> get the oid of the script to show from the request parameters
380:             *
381:             * @param e
382:             */
383:            public void structureListen(ActionEvent e) {
384:                FacesContext context = FacesContext.getCurrentInstance();
385:                Map requestParams = context.getExternalContext()
386:                        .getRequestParameterMap();
387:                long oid = -1;
388:                if (requestParams.get("oid") != null) {
389:                    oid = Long.valueOf(requestParams.get("oid").toString());
390:                }
391:                if (oid != -1) {
392:                    // this specifies the script to work on...
393:                    this.id = oid;
394:                }
395:            }
396:
397:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.