Source Code Cross Referenced for ExampleServlet.java in  » J2EE » ow2-easybeans » org » ow2 » easybeans » examples » ear » 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 » ow2 easybeans » org.ow2.easybeans.examples.ear 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /**
002:         * EasyBeans
003:         * Copyright (C) 2007 Bull S.A.S.
004:         * Contact: easybeans@ow2.org
005:         *
006:         * This library 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.1 of the License, or any later version.
010:         *
011:         * This library 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
019:         * USA
020:         *
021:         * --------------------------------------------------------------------------
022:         * $Id: ExampleServlet.java 1970 2007-10-16 11:49:25Z benoitf $
023:         * --------------------------------------------------------------------------
024:         */package org.ow2.easybeans.examples.ear;
025:
026:        import java.io.IOException;
027:        import java.io.PrintWriter;
028:        import java.util.Collection;
029:        import java.util.List;
030:
031:        import javax.naming.Context;
032:        import javax.naming.InitialContext;
033:        import javax.servlet.ServletException;
034:        import javax.servlet.http.HttpServlet;
035:        import javax.servlet.http.HttpServletRequest;
036:        import javax.servlet.http.HttpServletResponse;
037:
038:        /**
039:         * Defines a servlet that is accessing the two entities through a local session
040:         * bean.
041:         * @author Florent Benoit
042:         */
043:        public class ExampleServlet extends HttpServlet {
044:
045:            /**
046:             * Serializable class uid.
047:             */
048:            private static final long serialVersionUID = -3172627111841538912L;
049:
050:            /**
051:             * Called by the server (via the service method) to allow a servlet to
052:             * handle a GET request.
053:             * @param request an HttpServletRequest object that contains the request the
054:             *        client has made of the servlet
055:             * @param response an HttpServletResponse object that contains the response
056:             *        the servlet sends to the client
057:             * @throws IOException if an input or output error is detected when the
058:             *         servlet handles the GET request
059:             * @throws ServletException if the request for the GET could not be handled
060:             */
061:            @Override
062:            public void doGet(final HttpServletRequest request,
063:                    final HttpServletResponse response) throws IOException,
064:                    ServletException {
065:
066:                response.setContentType("text/html");
067:                PrintWriter out = response.getWriter();
068:                out.println("<html>");
069:                out.println("<head>");
070:                out.println("<title>");
071:                out
072:                        .println("Client of Local session bean - EAR example</title>");
073:                out.println("</head>");
074:                out.println("<body>");
075:
076:                initAuthorBooks(out);
077:                out.println("<br /><br />");
078:                displayAuthors(out);
079:
080:                out.println("</body>");
081:                out.println("</html>");
082:                out.close();
083:            }
084:
085:            /**
086:             * Init list of authors/books.
087:             * @param out the given writer
088:             */
089:            private void initAuthorBooks(final PrintWriter out) {
090:                out.println("Initialize authors and their books...<br/>");
091:
092:                List<Author> authors;
093:                try {
094:                    authors = getBean().listOfAuthors();
095:                } catch (Exception e) {
096:                    displayException(out, "Cannot Access to the bean", e);
097:                    return;
098:                }
099:
100:                if (authors != null && authors.size() > 0) {
101:                    out.println("Already initialized !<br/>");
102:                    return;
103:                }
104:
105:                try {
106:                    getBean().init();
107:                } catch (Exception e) {
108:                    displayException(out,
109:                            "Cannot init list of authors with their books", e);
110:                    return;
111:                }
112:            }
113:
114:            /**
115:             * Display authors.
116:             * @param out the given writer
117:             */
118:            private void displayAuthors(final PrintWriter out) {
119:                out.println("Get authors");
120:                out.println("<br /><br />");
121:
122:                // Get list of Authors
123:                List<Author> authors = null;
124:                try {
125:                    authors = getBean().listOfAuthors();
126:                } catch (Exception e) {
127:                    displayException(out,
128:                            "Cannot call listeOfAuthors on the bean", e);
129:                    return;
130:                }
131:
132:                // List for each author, the name of books
133:                if (authors != null) {
134:                    for (Author author : authors) {
135:                        out.println("List of books with author '"
136:                                + author.getName() + "' :");
137:                        out.println("<ul>");
138:                        Collection<Book> books = author.getBooks();
139:                        if (books == null) {
140:                            out.println("<li>No book !</li>");
141:                        } else {
142:                            for (Book book : books) {
143:                                out.println("<li>Title '" + book.getTitle()
144:                                        + "'.</li>");
145:                            }
146:                        }
147:                        out.println("</ul>");
148:
149:                    }
150:                } else {
151:                    out.println("No author found !");
152:                }
153:
154:            }
155:
156:            /**
157:             * If there is an exception, print the exception.
158:             * @param out the given writer
159:             * @param errMsg the error message
160:             * @param e the content of the exception
161:             */
162:            private void displayException(final PrintWriter out,
163:                    final String errMsg, final Exception e) {
164:                out.println("<p>Exception : " + errMsg);
165:                out.println("<pre>");
166:                e.printStackTrace(out);
167:                out.println("</pre></p>");
168:            }
169:
170:            /**
171:             * Lookup the stateless bean and gets a reference on it.
172:             * @return the stateless bean business interface.
173:             * @throws Exception if the bean cannot be retrieved.
174:             */
175:            private StatelessLocal getBean() throws Exception {
176:                Context initialContext = new InitialContext();
177:                Object o = initialContext
178:                        .lookup("org.ow2.easybeans.examples.ear.StatelessBean"
179:                                + "_" + StatelessLocal.class.getName()
180:                                + "@Local");
181:
182:                if (o instanceof  StatelessLocal) {
183:                    StatelessLocal statelessBean = (StatelessLocal) o;
184:                    return statelessBean;
185:                }
186:                throw new Exception("Cannot cast object into StatelessLocal");
187:
188:            }
189:
190:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.