KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sslexplorer > boot > PropertyClassManager


1 package com.sslexplorer.boot;
2
3 import java.util.ArrayList JavaDoc;
4 import java.util.Collection JavaDoc;
5 import java.util.HashMap JavaDoc;
6 import java.util.List JavaDoc;
7 import java.util.Map JavaDoc;
8
9 import org.apache.commons.logging.Log;
10 import org.apache.commons.logging.LogFactory;
11
12
13 public class PropertyClassManager {
14     
15     final static Log log = LogFactory.getLog(PropertyClassManager.class);
16     
17     // Private statics
18
private static PropertyClassManager instance;
19     
20     
21     // Private instance variables
22
private Map JavaDoc<String JavaDoc, PropertyClass> propertyClasses = new HashMap JavaDoc<String JavaDoc, PropertyClass>();
23     
24     /*
25      * Prevent instantiation
26      */

27     private PropertyClassManager() {
28     }
29     
30     /**
31      * Get an instance of the property class manager, lazily creating it.
32      *
33      * @return instance
34      */

35     public static PropertyClassManager getInstance() {
36         
37         synchronized(PropertyClassManager.class) {
38             if(instance == null) {
39                instance = new PropertyClassManager();
40             }
41             return instance;
42         }
43         
44     }
45
46     /**
47      * Register a new property class
48      *
49      * @param propertyClass property class
50      */

51     public void registerPropertyClass(PropertyClass propertyClass) {
52         propertyClasses.put(propertyClass.getName(), propertyClass);
53     }
54
55     /**
56      * Deregister an existing property classes.
57      *
58      * @param propertyClassName
59      */

60     public void deregisterPropertyClass(String JavaDoc propertyClassName) {
61         propertyClasses.remove(propertyClassName);
62     }
63
64     /**
65      * Get a property type given its name.
66      *
67      * @param name property class name
68      * @return property classes
69      */

70     public PropertyClass getPropertyClass(String JavaDoc name) {
71         return propertyClasses.get(name);
72     }
73
74     /**
75      * Get an unmodifiable collection of all registered
76      * property classes.
77      *
78      * @return collection of registered property classes
79      */

80     public Collection JavaDoc<PropertyClass> getPropertyClasses() {
81         return propertyClasses.values();
82     }
83     
84     /**
85      * Set whether the setting of property values should be persisted immediately
86      * to the underlying store or deferred until the {@link #commit()} method is
87      * called.
88      *
89      * NOTE This is not proper transaction support and should only be used
90      * in a single user instance of SSL-Explorer such as the installation wizard.
91      *
92      * @param autoCommit <true>code</code> to persist properties immediately
93      */

94     public synchronized void setAutoCommit(boolean autoCommit) {
95         for(PropertyClass propertyClass : propertyClasses.values()) {
96             propertyClass.setAutoCommit(autoCommit);
97         }
98     }
99
100     /**
101      * Commits any stored properties to the underlying store.
102      *
103      * @see #setAutoCommit(boolean)
104      */

105     public synchronized void commit() {
106         for(PropertyClass propertyClass : propertyClasses.values()) {
107             propertyClass.commit();
108         }
109     }
110
111     /**
112      * Get all definitions for the specified property class and any property classes
113      * that extend or implement the supplied Java class.
114      *
115      * @param clazz class
116      * @return list of property definitions
117      */

118     public Collection JavaDoc<PropertyDefinition> getDefinitions(Class JavaDoc clazz) {
119         List JavaDoc<PropertyDefinition> l = new ArrayList JavaDoc<PropertyDefinition>();
120         for(PropertyClass propertyClass : propertyClasses.values()) {
121             if(clazz.isAssignableFrom(propertyClass.getClass())) {
122                 l.addAll(propertyClass.getDefinitions());
123             }
124         }
125         return l;
126     }
127 }
128
Popular Tags