KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > exoplatform > services > organization > hibernate > OrganizationServiceImpl


1 /**
2  * Copyright 2001-2003 The eXo Platform SARL All rights reserved.
3  * Please look at license.txt in info directory for more license detail.
4  **/

5 package org.exoplatform.services.organization.hibernate;
6
7 import java.util.Collection JavaDoc;
8 import java.util.List JavaDoc;
9
10 import org.exoplatform.commons.utils.ListenerStack;
11 import org.exoplatform.commons.utils.PageList;
12 import org.exoplatform.services.database.HibernateService;
13 import org.exoplatform.services.organization.Group;
14 import org.exoplatform.services.organization.GroupEventListener;
15 import org.exoplatform.services.organization.Membership;
16 import org.exoplatform.services.organization.MembershipEventListener;
17 import org.exoplatform.services.organization.MembershipType;
18 import org.exoplatform.services.organization.OrganizationService;
19 import org.exoplatform.services.organization.OrganizationServiceListener;
20 import org.exoplatform.services.organization.Query;
21 import org.exoplatform.services.organization.User;
22 import org.exoplatform.services.organization.UserEventListener;
23 import org.exoplatform.services.organization.UserProfile;
24 import org.exoplatform.services.organization.UserProfileEventListener;
25 import org.exoplatform.services.organization.impl.GroupImpl;
26 import org.exoplatform.services.organization.impl.MembershipImpl;
27 import org.exoplatform.services.organization.impl.MembershipTypeImpl;
28 import org.exoplatform.services.organization.impl.UserImpl;
29 import org.exoplatform.services.organization.impl.UserProfileImpl;
30 import org.picocontainer.Startable;
31
32
33 /**
34  * Created by The eXo Platform SARL
35  * Author : Mestrallet Benjamin
36  * benjmestrallet@users.sourceforge.net
37  * Author : Tuan Nguyen
38  * tuan08@users.sourceforge.net
39  * Date: Aug 22, 2003
40  * Time: 4:51:21 PM
41  */

42 public class OrganizationServiceImpl implements OrganizationService, Startable {
43   
44   static private String JavaDoc[] MAPPING =
45    {
46      "org/exoplatform/services/organization/impl/UserImpl.hbm.xml",
47      "org/exoplatform/services/organization/impl/MembershipImpl.hbm.xml" ,
48      "org/exoplatform/services/organization/impl/GroupImpl.hbm.xml" ,
49      "org/exoplatform/services/organization/impl/MembershipTypeImpl.hbm.xml" ,
50      "org/exoplatform/services/organization/hibernate/UserProfileData.hbm.xml"
51    } ;
52   
53   UserQueryHandler userQueryHandler_ ;
54   UserProfileQueryHandler userProfileQueryHandler_ ;
55   GroupQueryHandler groupQueryHandler_ ;
56   MembershipQueryHandler membershipQueryHandler_ ;
57   MembershipTypeQueryHandler membershipTypeQueryHandler_ ;
58   private List JavaDoc listeners_ ;
59
60   public OrganizationServiceImpl(HibernateService hibernateService,
61                                  UserQueryHandler userQueryHandler,
62                                  GroupQueryHandler groupQueryHandler,
63                                  MembershipQueryHandler membershipQueryHandler,
64                                  MembershipTypeQueryHandler membershipTypeQueryHandler,
65                                  UserProfileQueryHandler userProfileQueryHandler) {
66     hibernateService.addMappingFiles(MAPPING) ;
67     
68     userQueryHandler_ = userQueryHandler ;
69     userProfileQueryHandler_ = userProfileQueryHandler ;
70     groupQueryHandler_ = groupQueryHandler ;
71     membershipQueryHandler_ = membershipQueryHandler ;
72     membershipTypeQueryHandler_ = membershipTypeQueryHandler ;
73     listeners_ = new ListenerStack(5) ;
74   }
75   
76   public void start() {
77     for(int i = 0 ; i < listeners_.size(); i++) {
78         OrganizationServiceListener listener = (OrganizationServiceListener) listeners_.get(i) ;
79       listener.inititalize(this) ;
80     }
81   }
82   
83   public void stop() {}
84   
85   synchronized public void addListener(OrganizationServiceListener listener) {
86     listeners_.add(listener) ;
87   }
88   
89   
90   synchronized public void removeListener(OrganizationServiceListener listener) {
91      listeners_.remove(listener) ;
92   }
93   
94   public User createUserInstance() {
95     return new UserImpl() ;
96   }
97
98   final public List JavaDoc getUserEventListeners() {
99     return userQueryHandler_.getUserEventListeners() ;
100   }
101   
102   public void addUserEventListener(UserEventListener listener) {
103     userQueryHandler_.addUserEventListener(listener) ;
104   }
105
106   final public void createUser(User user) throws Exception JavaDoc {
107     userQueryHandler_.createUser(user) ;
108   }
109
110   final public void saveUser(User user) throws Exception JavaDoc {
111     userQueryHandler_.saveUser(user) ;
112   }
113   
114
115   final public User removeUser(String JavaDoc user) throws Exception JavaDoc {
116     return userQueryHandler_.removeUser(user) ;
117   }
118
119
120   final public User findUserByName(String JavaDoc userName) throws Exception JavaDoc {
121     return userQueryHandler_.findUserByName(userName) ;
122   }
123
124   public PageList getUserPageList(int pageSize) throws Exception JavaDoc {
125     return userQueryHandler_.getUserPageList(pageSize) ;
126   }
127   
128   final public PageList findUsers(Query query) throws Exception JavaDoc {
129     return userQueryHandler_.findUsers(query) ;
130   }
131
132   final public PageList findUsersByGroup(String JavaDoc groupId) throws Exception JavaDoc {
133     return userQueryHandler_.findUsersByGroup(groupId) ;
134   }
135
136   public void addUserProfileEventListener(UserProfileEventListener listener) {
137     userProfileQueryHandler_.addUserProfileEventListener(listener) ;
138   }
139
140
141   final public UserProfile createUserProfileInstance() {
142     return new UserProfileImpl() ;
143   }
144
145   final public void saveUserProfile(UserProfile profile) throws Exception JavaDoc {
146     userProfileQueryHandler_.saveUserProfile(profile) ;
147   }
148
149   final public UserProfile removeUserProfile(String JavaDoc user) throws Exception JavaDoc {
150     return userProfileQueryHandler_.removeUserProfile(user) ;
151   }
152
153   final public UserProfile findUserProfileByName(String JavaDoc userName) throws Exception JavaDoc {
154     return userProfileQueryHandler_.findUserProfileByName(userName) ;
155   }
156
157   final public Collection JavaDoc findUserProfiles() throws Exception JavaDoc {
158     return userProfileQueryHandler_.findUserProfiles() ;
159   }
160
161   public void addGroupEventListener(GroupEventListener listener) {
162     groupQueryHandler_.addGroupEventListener(listener) ;
163   }
164
165   final public Group createGroupInstance() {
166     return new GroupImpl();
167   }
168
169   final public void createGroup(Group group) throws Exception JavaDoc {
170     groupQueryHandler_.createGroup(group) ;
171   }
172
173   final public void addChild(Group parent, Group child) throws Exception JavaDoc {
174     groupQueryHandler_.addChild(parent, child) ;
175   }
176
177   final public void saveGroup(Group group) throws Exception JavaDoc {
178     groupQueryHandler_.saveGroup(group) ;
179   }
180
181   final public Group removeGroup(Group group) throws Exception JavaDoc {
182     return groupQueryHandler_.removeGroup(group) ;
183   }
184
185   final public Collection JavaDoc findGroupByMembership(String JavaDoc userName, String JavaDoc membershipType) throws Exception JavaDoc {
186     return groupQueryHandler_.findGroupByMembership(userName, membershipType) ;
187   }
188   
189   public Group findGroupById(String JavaDoc groupId) throws Exception JavaDoc {
190     return groupQueryHandler_.findGroupById(groupId) ;
191   }
192   
193   final public Collection JavaDoc findGroups(Group parent) throws Exception JavaDoc {
194     return groupQueryHandler_.findGroups(parent) ;
195   }
196   
197   final public Collection JavaDoc findGroupsOfUser(String JavaDoc user) throws Exception JavaDoc {
198     return groupQueryHandler_.findGroupsOfUser(user) ;
199   }
200
201   public void addMembershipEventListener(MembershipEventListener listener) {
202     membershipQueryHandler_.addMembershipEventListener(listener) ;
203   }
204
205   final public Membership createMembershipInstance() {
206     return new MembershipImpl();
207   }
208
209   final public void createMembership(Membership m) throws Exception JavaDoc {
210     membershipQueryHandler_.createMembership(m) ;
211   }
212
213   final public void linkMembership(String JavaDoc userName, Group group, Membership m) throws Exception JavaDoc {
214     membershipQueryHandler_.linkMembership(userName, group, m) ;
215   }
216
217   final public void saveMembership(Membership m) throws Exception JavaDoc {
218     membershipQueryHandler_.saveMembership( m) ;
219   }
220
221   final public Membership removeMembership(String JavaDoc id) throws Exception JavaDoc {
222     return membershipQueryHandler_.removeMembership(id) ;
223   }
224
225   public Membership findMembershipByUserGroupAndType(String JavaDoc userName,
226                                                      String JavaDoc groupId,
227                                                      String JavaDoc type) throws Exception JavaDoc {
228     return membershipQueryHandler_.findMembershipByUserGroupAndType(userName, groupId, type) ;
229   }
230   
231   final public Collection JavaDoc findMembershipsByUserAndGroup(String JavaDoc userName, String JavaDoc groupId) throws Exception JavaDoc {
232     return membershipQueryHandler_.findMembershipsByUserAndGroup(userName, groupId) ;
233   }
234
235   final public Collection JavaDoc findMembershipsByUser(String JavaDoc userName) throws Exception JavaDoc {
236     return membershipQueryHandler_.findMembershipsByUser(userName) ;
237   }
238
239   final public Collection JavaDoc findMembershipsByGroup(Group group) throws Exception JavaDoc {
240     return membershipQueryHandler_.findMembershipsByGroup(group) ;
241   }
242   
243   final public Membership findMembership(String JavaDoc id) throws Exception JavaDoc {
244     return membershipQueryHandler_.findMembership(id) ;
245   }
246
247   final public MembershipType createMembershipTypeInstance() {
248     return new MembershipTypeImpl() ;
249   }
250   
251   final public MembershipType createMembershipType(MembershipType mt) throws Exception JavaDoc {
252     return membershipTypeQueryHandler_.createMembershipType(mt) ;
253   }
254   
255   final public MembershipType saveMembershipType(MembershipType mt) throws Exception JavaDoc {
256     return membershipTypeQueryHandler_.saveMembershipType(mt) ;
257   }
258   
259   final public MembershipType findMembershipType(String JavaDoc name) throws Exception JavaDoc {
260     return membershipTypeQueryHandler_.findMembershipType(name) ;
261   }
262
263   final public MembershipType removeMembershipType(String JavaDoc name) throws Exception JavaDoc {
264     return membershipTypeQueryHandler_.removeMembershipType(name) ;
265   }
266   
267   final public Collection JavaDoc findMembershipTypes() throws Exception JavaDoc {
268     return membershipTypeQueryHandler_.findMembershipTypes() ;
269   }
270   
271   public boolean authenticate(String JavaDoc username, String JavaDoc password) throws Exception JavaDoc {
272     User user = findUserByName(username);
273     if(user == null) return false ;
274     return user.getPassword().equals(password) ;
275   }
276 }
Popular Tags