Source Code Cross Referenced for ScriptFacade.java in  » J2EE » Enhydra-Application-Framework » org » enhydra » util » chiba » 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 Application Framework » org.enhydra.util.chiba 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         *
003:         */
004:        package org.enhydra.util.chiba;
005:
006:        import java.util.Locale;
007:        import java.util.ResourceBundle;
008:
009:        import javax.servlet.http.HttpSession;
010:
011:        import org.chiba.adapter.ChibaAdapter;
012:        import org.chiba.adapter.ChibaEvent;
013:        import org.chiba.adapter.DefaultChibaEventImpl;
014:        import org.chiba.xml.xforms.exception.XFormsException;
015:        import org.w3c.dom.Element;
016:
017:        import uk.ltd.getahead.dwr.ExecutionContext;
018:
019:        import com.lutris.appserver.server.session.Session;
020:
021:        /**
022:         * AJAX Facade class to hide the full functionality from the web-client.
023:         * 
024:         * @author Slobodan Vujasinovic
025:         * 
026:         */
027:        public class ScriptFacade {
028:            // this is a custom event to activate a trigger in XForms.
029:            public static final String FLUX_ACTIVATE_EVENT = "flux-action-event";
030:
031:            private static final String SESSION_ERROR = "SESSION_ERROR";
032:
033:            private static final String SESSION_ERROR_DEFAULT = "Session expired! Please start again.";
034:
035:            private static final String INFO = "INFO";
036:
037:            private static final String INFO_DEFAULT = "FluxFacade using";
038:
039:            private BaseAdapter adapter = null;
040:
041:            private HttpSession session;
042:
043:            private ResourceBundle rb = null;
044:
045:            /**
046:             * grabs the actual adapter from the session.
047:             */
048:            public ScriptFacade() {
049:                session = ExecutionContext.get().getSession(); // get current session
050:                try {
051:                    rb = ResourceBundle
052:                            .getBundle("org.enhydra.util.chiba.message");
053:                } catch (Exception ex) {
054:                    rb = ResourceBundle.getBundle(
055:                            "org.enhydra.util.chiba.message", new Locale(""));
056:                }
057:
058:                try {
059:                    adapter = ((ChibaAdapterContainer) ((Session) session
060:                            .getAttribute("session")).getSessionData().get(
061:                            "chiba.adapter.container")).getFirstChibaAdapter();
062:                } catch (Exception e) {
063:                    adapter = null;
064:                    // e.printStackTrace();
065:                }
066:            }
067:
068:            /**
069:             * executes a trigger
070:             * 
071:             * @param id
072:             *            the id of the trigger to execute
073:             * @return the list of events that may result through this action
074:             * @throws FluxException
075:             */
076:            public org.w3c.dom.Element fireAction(String id) throws Exception {
077:                ChibaEvent chibaActivateEvent = new DefaultChibaEventImpl();
078:                chibaActivateEvent.initEvent(FLUX_ACTIVATE_EVENT, id, null);
079:                return dispatch(chibaActivateEvent);
080:            }
081:
082:            /**
083:             * sets the value of a control in the processor.
084:             * 
085:             * @param id
086:             *            the id of the control in the host document
087:             * @param value
088:             *            the new value
089:             * @return the list of events that may result through this action
090:             * @throws FluxException
091:             */
092:            public org.w3c.dom.Element setXFormsValue(String id, String value)
093:                    throws Exception {
094:                ChibaEvent event = new DefaultChibaEventImpl();
095:                event.initEvent("SETVALUE", id, value);
096:                return dispatch(event);
097:            }
098:
099:            public org.w3c.dom.Element setRepeatIndex(String id, String position)
100:                    throws Exception {
101:                ChibaEvent event = new DefaultChibaEventImpl();
102:                event.initEvent("SETINDEX", id, position);
103:                return dispatch(event);
104:            }
105:
106:            /**
107:             * fetches the progress of a running upload.
108:             * 
109:             * @param id
110:             *            id of the upload control in use
111:             * @param filename
112:             *            filename for uploaded data
113:             * @return a array containing two elements for evaluation in browser. First
114:             *         param is the upload control id and second will be the current
115:             *         progress of the upload.
116:             */
117:            public org.w3c.dom.Element fetchProgress(String id, String filename) {
118:                String progress;
119:
120:                if (session.getAttribute(filename) != null) {
121:                    progress = ((Integer) session.getAttribute(filename))
122:                            .toString();
123:                } else {
124:                    progress = "0";
125:                }
126:                EventLog eventLog = null;
127:                try {
128:                    eventLog = (EventLog) adapter.getContextParam("EVENT-LOG");
129:                } catch (Exception ex) {
130:                    // ex.printStackTrace();
131:                }
132:                if (eventLog == null) {
133:                    eventLog = new EventLog();
134:                }
135:                Element eventlogElement = eventLog.getLog();
136:                eventLog.flush();
137:
138:                Element progressEvent = eventLog.add("upload-progress-event",
139:                        id, "upload");
140:                eventLog.addProperty(progressEvent, "progress", progress);
141:                return eventlogElement;
142:            }
143:
144:            private org.w3c.dom.Element dispatch(ChibaEvent event)
145:                    throws Exception {
146:
147:                if (adapter != null && !adapter.isClean()) {
148:                    session.setAttribute("chiba.ScriptFacade.errorMessage",
149:                            new Boolean(true));
150:                    try {
151:                        adapter.dispatch(event);
152:                    } catch (Exception e) {
153:                        //				 throw new Exception(e);
154:                        return null;
155:                    }
156:
157:                    EventLog eventLog = (EventLog) adapter
158:                            .getContextParam("EVENT-LOG");
159:                    if (eventLog == null) {
160:                        eventLog = new EventLog();
161:                    }
162:                    Element eventlogElement = eventLog.getLog();
163:                    return eventlogElement;
164:                } else {
165:                    // session expired or cookie got lost
166:                    // check if we have already shown error message 
167:                    boolean errorMessage = false;
168:                    Boolean errorMessageObject = (Boolean) session
169:                            .getAttribute("chiba.ScriptFacade.errorMessage");
170:                    if (errorMessageObject == null) {
171:                        errorMessage = true;
172:                    } else {
173:                        errorMessage = errorMessageObject.booleanValue();
174:                    }
175:                    if (adapter == null && errorMessage) {
176:                        String message = SESSION_ERROR_DEFAULT;
177:                        try {
178:                            message = rb.getString(SESSION_ERROR);
179:                        } catch (Exception ex) {
180:                            ex.printStackTrace();
181:                        }
182:                        session.setAttribute("chiba.ScriptFacade.errorMessage",
183:                                new Boolean(false));
184:
185:                        throw new Exception(message);
186:                    }
187:                    return null;
188:                }
189:
190:            }
191:
192:            public String getInfo() {
193:                String message = INFO_DEFAULT;
194:                try {
195:                    message = rb.getString(INFO);
196:                } catch (Exception ex) {
197:                    ex.printStackTrace();
198:                }
199:
200:                return message + " " + adapter.toString();
201:            }
202:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.