KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > mmbase > applications > packaging > sharehandlers > ShareInfo


1 /*
2  * This software is OSI Certified Open Source Software.
3  * OSI Certified is a certification mark of the Open Source Initiative.
4  * The license (Mozilla version 1.0) can be read at the MMBase site.
5  * See http://www.MMBase.org/license
6  */

7 package org.mmbase.applications.packaging.sharehandlers;
8
9 import java.util.HashMap JavaDoc;
10 import java.util.Iterator JavaDoc;
11
12 import org.mmbase.applications.packaging.ShareManager;
13
14 /**
15  * @author Daniel Ockeloen
16  */

17 public class ShareInfo {
18
19     // even if we have a share we have active boolean to allow
20
// people to turn of a share without loosing all its setup(s).
21
// this works the same way as windows shares.
22
private boolean active;
23
24     private HashMap JavaDoc users = new HashMap JavaDoc();
25
26     private HashMap JavaDoc groups = new HashMap JavaDoc();
27
28     /**
29      * Constructor for the ShareInfo object
30      */

31     public ShareInfo() { }
32
33
34     /**
35      * Gets the active attribute of the ShareInfo object
36      *
37      * @return The active value
38      */

39     public boolean isActive() {
40         return active;
41     }
42
43
44     /**
45      * Sets the active attribute of the ShareInfo object
46      *
47      * @param wantedstate The new active value
48      */

49     public void setActive(boolean wantedstate) {
50         active = wantedstate;
51     }
52
53
54     /**
55      * Adds a feature to the User attribute of the ShareInfo object
56      *
57      * @param name The feature to be added to the User attribute
58      * @return Description of the Return Value
59      */

60     public boolean addUser(String JavaDoc name) {
61         ShareUser su = ShareManager.getShareUser(name);
62         if (su != null) {
63             users.put(name, su);
64             return true;
65         }
66         return false;
67     }
68
69
70     /**
71      * Description of the Method
72      *
73      * @param name Description of the Parameter
74      * @return Description of the Return Value
75      */

76     public boolean removeUser(String JavaDoc name) {
77         users.remove(name);
78         return true;
79     }
80
81
82     /**
83      * Description of the Method
84      *
85      * @param name Description of the Parameter
86      * @return Description of the Return Value
87      */

88     public boolean removeGroup(String JavaDoc name) {
89         groups.remove(name);
90         return true;
91     }
92
93
94     /**
95      * Description of the Method
96      *
97      * @param user Description of the Parameter
98      * @return Description of the Return Value
99      */

100     public boolean containsUser(String JavaDoc user) {
101         if (users.containsKey(user)) {
102             return true;
103         }
104         return false;
105     }
106
107
108
109     /**
110      * Description of the Method
111      *
112      * @param group Description of the Parameter
113      * @return Description of the Return Value
114      */

115     public boolean containsGroup(String JavaDoc group) {
116         if (groups.containsKey(group)) {
117             return true;
118         }
119         return false;
120     }
121
122
123     /**
124      * Adds a feature to the Group attribute of the ShareInfo object
125      *
126      * @param name The feature to be added to the Group attribute
127      * @return Description of the Return Value
128      */

129     public boolean addGroup(String JavaDoc name) {
130         ShareGroup sg = ShareManager.getShareGroup(name);
131         if (sg != null) {
132             groups.put(name, sg);
133             return true;
134         }
135         return false;
136     }
137
138
139     /**
140      * Gets the shareUsers attribute of the ShareInfo object
141      *
142      * @return The shareUsers value
143      */

144     public Iterator JavaDoc getShareUsers() {
145         return users.values().iterator();
146     }
147
148
149     /**
150      * Description of the Method
151      *
152      * @param user Description of the Parameter
153      * @param password Description of the Parameter
154      * @param method Description of the Parameter
155      * @param host Description of the Parameter
156      * @return Description of the Return Value
157      */

158     public boolean sharedForUser(String JavaDoc user, String JavaDoc password, String JavaDoc method, String JavaDoc host) {
159         ShareUser su = (ShareUser) users.get(user);
160         if (su != null && password.equals(su.getPassword())) {
161             return true;
162         }
163         return false;
164     }
165
166
167     /**
168      * Gets the shareGroups attribute of the ShareInfo object
169      *
170      * @return The shareGroups value
171      */

172     public Iterator JavaDoc getShareGroups() {
173         return groups.values().iterator();
174     }
175 }
176
177
Popular Tags