Source Code Cross Referenced for ServletAdapter.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:        package org.enhydra.util.chiba;
002:
003:        import java.util.HashMap;
004:        import java.util.Map;
005:
006:        import org.chiba.adapter.AbstractChibaAdapter;
007:        import org.chiba.adapter.ChibaEvent;
008:        import org.chiba.xml.xforms.events.XFormsEvent;
009:        import org.chiba.xml.xforms.events.XFormsEventFactory;
010:        import org.chiba.xml.xforms.exception.XFormsException;
011:        import org.w3c.dom.Element;
012:        import org.w3c.dom.events.Event;
013:        import org.w3c.dom.events.EventListener;
014:
015:        /**
016:         * integrates XForms Processor into Web-applications and handles request
017:         * processing. This is the default implementation of ChibaAdapter and besides
018:         * handling the interaction it also manages a UIGenerator to build the rendered
019:         * output for the browser.
020:         *
021:         * @author joern turner
022:         * @version $Id: ServletAdapter.java,v 1.2 2007-05-17 12:52:55 sinisa Exp $
023:         */
024:        public class ServletAdapter extends BaseAdapter implements 
025:                EventListener {
026:
027:            public static final String HTTP_SERVLET_REQUEST = "chiba.web.request";
028:            public static final String HTTP_UPLOAD_DIR = "chiba.web.uploadDir";
029:
030:            public static final String USERAGENT = "chiba.useragent";
031:            private HttpRequestHandler handler;
032:            public static final Object XSLT_PATH = "xslt-path";
033:
034:            /**
035:             * Creates a new ServletAdapter object.
036:             */
037:            public ServletAdapter() {
038:                createXFormsProcessor();
039:                this .context = new HashMap();
040:                chibaBean.setContext(this .context);
041:            }
042:
043:            /**
044:             * place to put application-specific params or configurations before
045:             * actually starting off the XFormsProcessor. It's the responsibility of
046:             * this method to call chibaBean.init() to finish up the processor setup.
047:             *
048:             * @throws XFormsException If an error occurs
049:             */
050:            public void init() throws XFormsException {
051:                this .chibaBean.init();
052:                this .handler = getNewInteractionHandler();
053:                setClean(false);
054:            }
055:
056:            /**
057:             * ServletAdapter knows and executes only one ChibaEvent: 'http-request'
058:             * which will contain the HttpServletRequest as contextInfo.
059:             *
060:             * @param event only events of type 'http-request' will be handled
061:             * @throws XFormsException
062:             */
063:            public void dispatch(ChibaEvent event) throws XFormsException {
064:                if (event.getEventName().equals("http-request")) {
065:                    this .handler.execute(event);
066:                } else {
067:                    //        	Log.log("unknown event: '" + event.getEventName() + "' - ignoring");
068:                }
069:
070:            }
071:
072:            /**
073:             * terminates the XForms processing. right place to do cleanup of
074:             * resources.
075:             *
076:             * @throws org.chiba.xml.xforms.exception.XFormsException
077:             */
078:            public void shutdown() throws XFormsException {
079:                if (isClean())
080:                    return;
081:                this .chibaBean.shutdown();
082:                this .chibaBean = null;
083:                setClean(true);
084:            }
085:
086:            /**
087:             * Instructs the application environment to forward the given response.
088:             *
089:             * @param response a map containing at least a response stream and optional
090:             * header information.
091:             */
092:            public void forward(Map response) {
093:                this .chibaBean.getContext().put(SUBMISSION_RESPONSE, response);
094:            }
095:
096:            // todo: should be set by servlet
097:
098:            /**
099:             * return a new InteractionHandler.
100:             * <p/>
101:             * This method returns a new HttpRequestHandler.
102:             *
103:             * @return returns a new
104:             */
105:            protected HttpRequestHandler getNewInteractionHandler()
106:                    throws XFormsException {
107:                return new HttpRequestHandler(this .chibaBean);
108:            }
109:
110:            public void setUploadDestination(String uploadDir) {
111:                super .setUploadDestination(uploadDir);
112:                //HttpRequestHandler uses this
113:                // todo: should be a member of request handler and set directly
114:                setContextParam(HTTP_UPLOAD_DIR, uploadDir);
115:            }
116:
117:            // event handling
118:            // todo: should be moved up to base class
119:
120:            /**
121:             * This method is called whenever an event occurs of the type for which the
122:             * <code> EventListener</code> interface was registered.
123:             *
124:             * @param event The <code>Event</code> contains contextual information about
125:             * the event. It also contains the <code>stopPropagation</code> and
126:             * <code>preventDefault</code> methods which are used in determining the
127:             * event's flow and default action.
128:             */
129:            public void handleEvent(Event event) {
130:                String type = event.getType();
131:                String targetId = ((Element) event.getTarget()).getAttributeNS(
132:                        null, "id");
133:                XFormsEvent xformsEvent = (XFormsEvent) event;
134:
135:                if (XFormsEventFactory.CHIBA_LOAD_URI.equals(type)) {
136:                    handleLoadURI(targetId, (String) xformsEvent
137:                            .getContextInfo("uri"), (String) xformsEvent
138:                            .getContextInfo("show"));
139:                    return;
140:                }
141:                if (XFormsEventFactory.CHIBA_RENDER_MESSAGE.equals(type)) {
142:                    handleMessage(targetId, (String) xformsEvent
143:                            .getContextInfo("message"), (String) xformsEvent
144:                            .getContextInfo("level"));
145:                    return;
146:                }
147:                if (XFormsEventFactory.CHIBA_REPLACE_ALL.equals(type)) {
148:                    handleReplaceAll(targetId, (Map) xformsEvent
149:                            .getContextInfo("header"), xformsEvent
150:                            .getContextInfo("body"));
151:                    return;
152:                }
153:
154:                // unknown event ignored
155:            }
156:
157:            // todo: *either* move up these three methods as abstract template methods *or* use event log ?
158:            public void handleLoadURI(String targetId, String uri, String show) {
159:                // todo
160:            }
161:
162:            public void handleMessage(String targetId, String message,
163:                    String level) {
164:                // todo
165:            }
166:
167:            public void handleReplaceAll(String targetId, Map header,
168:                    Object body) {
169:                //FIXME
170:
171:                /*if (getContextParam(ChibaAdapter.SUBMISSION_RESPONSE) != null) {
172:                	Map forwardMap = (Map) removeContextParam(ChibaAdapter.SUBMISSION_RESPONSE);
173:                	if (forwardMap.containsKey(ChibaAdapter.SUBMISSION_RESPONSE_STREAM)) {
174:                		forwardResponse(forwardMap,this. response);
175:                		shutdown();
176:                		
177:                	}
178:                }*/
179:
180:            }
181:
182:            public void setBaseURI(String aURI) {
183:                super .setBaseURI(aURI);
184:            }
185:
186:            /**
187:             * passes Map containing arbitrary context parameters to the Adapter.
188:             *
189:             * @param contextParams Map of arbitrary params passed to the processor
190:             */
191:            public void setContext(Map contextParams) {
192:                this.context = contextParams;
193:                chibaBean.setContext(contextParams);
194:            }
195:
196:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.