1 16 package org.apache.commons.chain; 17 18 import java.util.HashMap ; 19 import java.util.Iterator ; 20 import java.util.Map ; 21 import org.apache.commons.chain.impl.CatalogFactoryBase; 22 23 32 33 public abstract class CatalogFactory { 34 35 36 38 39 45 public abstract Catalog getCatalog(); 46 47 48 53 public abstract void setCatalog(Catalog catalog); 54 55 56 63 public abstract Catalog getCatalog(String name); 64 65 66 73 public abstract void addCatalog(String name, Catalog catalog); 74 75 76 81 public abstract Iterator getNames(); 82 83 84 86 87 91 private static Map factories = new HashMap (); 92 93 94 96 97 107 public static CatalogFactory getInstance() { 108 109 CatalogFactory factory = null; 110 ClassLoader cl = getClassLoader(); 111 synchronized (factories) { 112 factory = (CatalogFactory) factories.get(cl); 113 if (factory == null) { 114 factory = new CatalogFactoryBase(); 115 factories.put(cl, factory); 116 } 117 } 118 return factory; 119 120 } 121 122 123 129 public static void clear() { 130 131 synchronized (factories) { 132 factories.remove(getClassLoader()); 133 } 134 135 } 136 137 138 140 141 146 private static ClassLoader getClassLoader() { 147 148 ClassLoader cl = Thread.currentThread().getContextClassLoader(); 149 if (cl == null) { 150 cl = CatalogFactory.class.getClassLoader(); 151 } 152 return cl; 153 154 } 155 156 157 } 158 | Popular Tags |