1 package com.sslexplorer.boot; 2 3 import java.util.ArrayList ; 4 import java.util.Collection ; 5 import java.util.HashMap ; 6 import java.util.List ; 7 import java.util.Map ; 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 static PropertyClassManager instance; 19 20 21 private Map <String , PropertyClass> propertyClasses = new HashMap <String , PropertyClass>(); 23 24 27 private PropertyClassManager() { 28 } 29 30 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 51 public void registerPropertyClass(PropertyClass propertyClass) { 52 propertyClasses.put(propertyClass.getName(), propertyClass); 53 } 54 55 60 public void deregisterPropertyClass(String propertyClassName) { 61 propertyClasses.remove(propertyClassName); 62 } 63 64 70 public PropertyClass getPropertyClass(String name) { 71 return propertyClasses.get(name); 72 } 73 74 80 public Collection <PropertyClass> getPropertyClasses() { 81 return propertyClasses.values(); 82 } 83 84 94 public synchronized void setAutoCommit(boolean autoCommit) { 95 for(PropertyClass propertyClass : propertyClasses.values()) { 96 propertyClass.setAutoCommit(autoCommit); 97 } 98 } 99 100 105 public synchronized void commit() { 106 for(PropertyClass propertyClass : propertyClasses.values()) { 107 propertyClass.commit(); 108 } 109 } 110 111 118 public Collection <PropertyDefinition> getDefinitions(Class clazz) { 119 List <PropertyDefinition> l = new ArrayList <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 |