KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > opensymphony > user > provider > file > FileProfileProvider


1 /*
2  * Copyright (c) 2002-2003 by OpenSymphony
3  * All rights reserved.
4  */

5 package com.opensymphony.user.provider.file;
6
7 import com.opensymphony.module.propertyset.PropertySet;
8 import com.opensymphony.module.propertyset.PropertySetManager;
9
10 import com.opensymphony.user.Entity;
11
12 import org.apache.commons.logging.Log;
13 import org.apache.commons.logging.LogFactory;
14
15
16 import java.util.ArrayList JavaDoc;
17 import java.util.Collections JavaDoc;
18 import java.util.List JavaDoc;
19 import java.util.Properties JavaDoc;
20
21
22 /**
23 * Following properties are <b>required</b>:
24 * <ul>
25 * <li><b>storeFile</b> - the absolute path to the store file
26 (<i>ex:c:\properties.store</i>)</li>
27 * </ul>
28 */

29 public class FileProfileProvider implements com.opensymphony.user.provider.ProfileProvider {
30     //~ Static fields/initializers /////////////////////////////////////////////
31

32     protected static final Log log = LogFactory.getLog(FileProfileProvider.class);
33     
34     protected FilePropertySetCache propertySetCache;
35
36     //~ Methods ////////////////////////////////////////////////////////////////
37

38     public PropertySet getPropertySet(String JavaDoc name) {
39         if (!propertySetCache.propertySets.containsKey(name)) {
40             return null;
41         }
42
43         return (PropertySet) propertySetCache.propertySets.get(name);
44     }
45
46     public boolean create(String JavaDoc name) {
47         if (propertySetCache.propertySets.containsKey(name)) {
48             return false;
49         }
50
51         PropertySet propertySet = PropertySetManager.getInstance("serializable", null);
52         propertySetCache.propertySets.put(name, propertySet);
53
54         return propertySetCache.store();
55     }
56
57     public void flushCaches() {
58         propertySetCache.store();
59     }
60
61     public boolean handles(String JavaDoc name) {
62         return propertySetCache.propertySets.containsKey(name);
63     }
64
65     public boolean init(Properties JavaDoc properties) {
66         return true;
67     }
68
69     public List JavaDoc list() {
70         return Collections.unmodifiableList(new ArrayList JavaDoc(propertySetCache.propertySets.keySet()));
71     }
72
73     public boolean load(String JavaDoc name, Entity.Accessor accessor) {
74         return true;
75     }
76
77     public boolean remove(String JavaDoc name) {
78         boolean rv = propertySetCache.propertySets.remove(name) != null;
79
80         return rv && propertySetCache.store();
81     }
82
83     public boolean store(String JavaDoc name, Entity.Accessor accessor) {
84         return propertySetCache.store();
85     }
86 }
87
88
Popular Tags