KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > exoplatform > services > organization > ldap > OrganizationServiceListenerImpl


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.ldap;
6
7 import java.util.List JavaDoc;
8
9 import org.exoplatform.commons.utils.ExoProperties;
10 import org.exoplatform.container.configuration.ConfigurationManager;
11 import org.exoplatform.container.configuration.ServiceConfiguration;
12 import org.exoplatform.services.organization.Group;
13 import org.exoplatform.services.organization.MembershipType;
14 import org.exoplatform.services.organization.OrganizationService;
15 import org.exoplatform.services.organization.OrganizationServiceListener;
16 import org.exoplatform.services.organization.User;
17 import org.picocontainer.Startable;
18 /**
19  * Jul 20, 2004
20  * @author: Tuan Nguyen
21  * @email: tuan08@users.sourceforge.net
22  * @version: $Id: OrganizationServiceListenerImpl.java,v 1.5 2004/11/03 11:37:21 danny_xcz Exp $
23  */

24 public class OrganizationServiceListenerImpl extends OrganizationServiceListener
25   implements Startable {
26   
27   private ServiceConfiguration sconfiguration_ ;
28   
29   public OrganizationServiceListenerImpl(OrganizationService orgService,
30                                          ConfigurationManager cService) throws Exception JavaDoc {
31     /*
32     Query q = new Query() ;
33     q.setFrom(0) ;
34     q.setTo(5) ;
35     List users = orgService.findUsers(q);
36     if(users.size() > 0) return ; //Not new database
37     orgService.addListener(this);
38     sconfiguration_ = cService.getServiceConfiguration(getClass()) ;
39     */

40   }
41   
42   public void start() { }
43   public void stop() {}
44   
45   public void inititalize(OrganizationService service) {
46     /*
47     if(sconfiguration_ == null) return ;
48     try {
49         InitParam param = sconfiguration_.getInitParam("group") ;
50         if(param != null) createGroups(service, param.getValues()) ;
51       param = sconfiguration_.getInitParam("role") ;
52       param = sconfiguration_.getInitParam("membership") ;
53       if(param != null) createMembershipTypes(service, param.getValues()) ;
54       param = sconfiguration_.getInitParam("users") ;
55       if(param != null) createUsers(service, param.getValues(), true) ;
56     } catch (Exception ex) {
57         ex.printStackTrace() ;
58     }
59     */

60   }
61   
62   private void createGroups(OrganizationService orgService, List JavaDoc groups) throws Exception JavaDoc {
63     ExoProperties props = new ExoProperties() ;
64     for(int i = 0 ; i < groups.size() ; i++) {
65       props.clear() ;
66       props.addPropertiesFromText((String JavaDoc) groups.get(i)) ;
67       Group group = orgService.createGroupInstance();
68       group.setGroupName(props.getProperty("name"));
69       orgService.createGroup(group);
70     }
71   }
72   
73   private void createMembershipTypes(OrganizationService orgService, List JavaDoc types) throws Exception JavaDoc {
74     ExoProperties props = new ExoProperties() ;
75     for(int i = 0 ; i < types.size() ; i++) {
76       props.clear() ;
77       props.addPropertiesFromText((String JavaDoc) types.get(i)) ;
78       MembershipType type = orgService.createMembershipTypeInstance();
79       type.setName(props.getProperty("membership-type")) ;
80       type.setDescription(props.getProperty("description")) ;
81       orgService.createMembershipType(type) ;
82     }
83   }
84   
85   private void createUsers(OrganizationService service, List JavaDoc users, boolean admin) throws Exception JavaDoc {
86     ExoProperties props = new ExoProperties() ;
87     for(int i = 0 ; i < users.size() ; i++) {
88       props.clear() ;
89         props.addPropertiesFromText((String JavaDoc) users.get(i)) ;
90         User user = service.createUserInstance() ;
91         user.setUserName(props.getProperty("user-name")) ;
92         user.setPassword(props.getProperty("password")) ;
93         user.setFirstName(props.getProperty("first-name")) ;
94         user.setLastName(props.getProperty("last-name")) ;
95         user.setEmail(props.getProperty("email")) ;
96         service.createUser(user);
97     }
98   }
99 }
Popular Tags