Source Code Cross Referenced for UserManager.java in  » J2EE » JOnAS-4.8.6 » olstore » domain » manager » 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 » JOnAS 4.8.6 » olstore.domain.manager 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /**
002:         * Copyright (c) 2004 Red Hat, Inc. All rights reserved.
003:         *
004:         * This library is free software; you can redistribute it and/or
005:         * modify it under the terms of the GNU Lesser General Public
006:         * License as published by the Free Software Foundation; either
007:         * version 2.1 of the License, or any later version.
008:         *
009:         * This library is distributed in the hope that it will be useful,
010:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
011:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
012:         * Lesser General Public License for more details.
013:         *
014:         * You should have received a copy of the GNU Lesser General Public
015:         * License along with this library; if not, write to the Free Software
016:         * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
017:         * USA
018:         *
019:         * Component of: Red Hat Application Server
020:         * 
021:         * Initial Developers: Greg Lapouchnian
022:         *                     Patrick Smith
023:         *
024:         */package olstore.domain.manager;
025:
026:        import java.util.ArrayList;
027:        import java.util.Collection;
028:        import java.util.Iterator;
029:
030:        import javax.ejb.EJBException;
031:        import javax.ejb.FinderException;
032:
033:        import olstore.dto.AddressValue;
034:        import olstore.dto.CreateUserValue;
035:        import olstore.dto.OrderEntry;
036:        import olstore.dto.UserValue;
037:        import olstore.entity.OrderLocal;
038:        import olstore.entity.UserLocal;
039:        import olstore.entity.UserLocalHome;
040:        import olstore.session.helper.UserHelper;
041:
042:        /**
043:         * A wrapper class for user actions so that there is no need to reference the
044:         * beans directly, allowing us to swap out the backend beans for a different
045:         * implementation.
046:         */
047:        public class UserManager {
048:
049:            /** A reference to the LocalHome inteface of the user EJB */
050:            private UserLocalHome home;
051:            /** A refernce to the user helper object */
052:            private UserHelper helper;
053:
054:            /**
055:             * Constructor for the manager which is populated by Spring.
056:             * @param home a reference to the LocalHome interface
057:             * @param helper a helper object
058:             */
059:            public UserManager(UserLocalHome home, UserHelper helper) {
060:                this .home = home;
061:                this .helper = helper;
062:            }
063:
064:            /**
065:             * Find a user by their username.
066:             * @param username the username to lookup
067:             * @return the UserLocal object for the user with the given username
068:             */
069:            public UserLocal findByUsername(String username) {
070:                UserLocal user;
071:                try {
072:                    user = home.findByUsername(username);
073:                } catch (FinderException ex) {
074:                    throw new EJBException("Unable to find user", ex);
075:                }
076:
077:                return user;
078:
079:            }
080:
081:            /**
082:             * Find all registered users in this store.
083:             * @return a collection of all users.
084:             */
085:            public Collection findAll() {
086:                Collection c;
087:                try {
088:                    c = home.findAll();
089:                } catch (FinderException ex) {
090:                    throw new EJBException("Unable to find users", ex);
091:                }
092:                return c;
093:            }
094:
095:            /**
096:             * Find a user with given name and return a POJO for that user.
097:             * @param username the username to lookup
098:             * @return a plain java object for the user with the given username
099:             */
100:            public UserValue findUserValue(String username) {
101:                UserValue user;
102:                try {
103:                    user = helper.UserToDTO(home.findByUsername(username));
104:                } catch (Exception ex) {
105:                    throw new EJBException("Unable to find user", ex);
106:                }
107:
108:                return user;
109:            }
110:
111:            /**
112:             * Return all the orders that belong to the user.
113:             * @param username the username of the user whose orders are required
114:             * @return a collection of OrderEntry objects that belong to this user
115:             */
116:            public Collection getOrders(String username) {
117:                UserLocal user;
118:                try {
119:                    user = home.findByUsername(username);
120:                } catch (FinderException ex) {
121:                    throw new EJBException("Unable to find user", ex);
122:                }
123:
124:                Collection entries = new ArrayList();
125:                Collection orderLocals = user.getOrders();
126:
127:                Iterator orderIterator = orderLocals.iterator();
128:                while (orderIterator.hasNext()) {
129:                    OrderLocal orderLocal = (OrderLocal) orderIterator.next();
130:                    OrderEntry orderEntry = new OrderEntry(orderLocal);
131:                    entries.add(orderEntry);
132:                }
133:
134:                return entries;
135:            }
136:
137:            public Collection getUserPurchased(String username) {
138:                UserLocal user;
139:                try {
140:                    user = home.findByUsername(username);
141:                } catch (FinderException ex) {
142:                    throw new EJBException("Unable to find user", ex);
143:                }
144:                return user.getPurchased();
145:            }
146:
147:            /**
148:             * Save a user with the given username and all of their profile information
149:             * @param user the object representing the user
150:             * @param address the object that contains the user's address
151:             * @param username user's username
152:             * @throws Exception if an error occurs while saving user's information
153:             */
154:            public void saveUser(UserValue user, AddressValue address,
155:                    String username) throws Exception {
156:                helper.SaveUser(user, address, username);
157:            }
158:
159:            /**
160:             * Create a new user for customer in the store.
161:             * @param user the object representing the user
162:             * @param address the object representing the customer
163:             * @throws Exception if an error occures while creating the new user
164:             */
165:            public void createUser(UserValue user, AddressValue address)
166:                    throws Exception {
167:                CreateUserValue userValue = new CreateUserValue();
168:                userValue.setUsername(user.getUsername());
169:                userValue.setPhoneNum(user.getPhoneNum());
170:                userValue.setPasswd1(user.getPasswd());
171:                userValue.setLname(user.getLname());
172:                userValue.setFname(user.getFname());
173:                userValue.setEmailAdd(user.getEmailAdd());
174:                helper.CreateUser(userValue, address);
175:            }
176:
177:            /**
178:             * Returns a collection of all friends that have purchased the given item, and
179:             * are friends of the given user.
180:             * @param username the user whose friends we are interested in.
181:             * @param itemId the item ID to see which friends have purchased.
182:             * @return a collection of all friends that have purchased the given item, and
183:             * are friends of the given user.
184:             */
185:            public Collection findFriendsThatPurchasedItem(String username,
186:                    Integer itemId) {
187:                Collection c;
188:                ArrayList friends = new ArrayList();
189:                try {
190:                    c = home.findFriendsThatPurchasedItem(username, itemId);
191:                } catch (FinderException ex) {
192:                    throw new EJBException("Unable to find user/item", ex);
193:                }
194:
195:                Iterator i = c.iterator();
196:                while (i.hasNext()) {
197:                    friends.add(((UserLocal) i.next()).getUsername());
198:                }
199:
200:                return friends;
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.