View Javadoc

1   /*
2    * ------------------------------------------------------------------------------
3    * Hermes FTP Server
4    * Copyright (c) 2005-2007 Lars Behnke
5    * ------------------------------------------------------------------------------
6    * 
7    * This file is part of Hermes FTP Server.
8    * 
9    * Hermes FTP Server is free software; you can redistribute it and/or modify
10   * it under the terms of the GNU General Public License as published by
11   * the Free Software Foundation; either version 2 of the License, or
12   * (at your option) any later version.
13   * 
14   * Hermes FTP Server is distributed in the hope that it will be useful,
15   * but WITHOUT ANY WARRANTY; without even the implied warranty of
16   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17   * GNU General Public License for more details.
18   * 
19   * You should have received a copy of the GNU General Public License
20   * along with Hermes FTP Server; if not, write to the Free Software
21   * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
22   * ------------------------------------------------------------------------------
23   */
24  
25  package net.sf.hermesftp.usermanager.model;
26  
27  import java.util.ArrayList;
28  import java.util.Collections;
29  import java.util.List;
30  
31  /***
32   * Data Model for the user manager configuration.
33   * 
34   * @author Lars Behnke
35   */
36  public class UserManagerData {
37  
38      private GroupDataList  groupDataList;
39  
40      private List<UserData> userData;
41  
42      /***
43       * Getter method for the java bean <code>groupData</code>.
44       * 
45       * @return Returns the value of the java bean <code>groupData</code>.
46       */
47      public GroupDataList getGroupData() {
48          if (groupDataList == null) {
49              groupDataList = new GroupDataList();
50          }
51          return groupDataList;
52      }
53  
54      /***
55       * Getter method for the java bean <code>userData</code>.
56       * 
57       * @return Returns the value of the java bean <code>userData</code>.
58       */
59      public List<UserData> getUserData() {
60          if (userData == null) {
61              userData = Collections.synchronizedList(new ArrayList<UserData>());
62          }
63          return userData;
64      }
65  
66      /***
67       * Returns the user object by the username.
68       * 
69       * @param username The user's name.
70       * @return The user object.
71       */
72      public UserData getUserData(String username) {
73          username = username.trim();
74          for (UserData user : getUserData()) {
75              if (user.getUid().equals(username)) {
76                  return user;
77              }
78          }
79          return null;
80      }
81  
82      /***
83       * Returns the group object by the group name.
84       * 
85       * @param groupname The group's name.
86       * @return The group object.
87       */
88      public GroupData getGroupData(String groupname) {
89          return groupDataList.getGroup(groupname.trim());
90      }
91  
92  }