1 19 20 package org.netbeans.modules.websvc.api.jaxws.wsdlmodel; 21 22 import java.lang.ref.WeakReference ; 23 import java.net.URL ; 24 import java.util.WeakHashMap ; 25 26 30 public class WsdlModelerFactory { 31 32 private static WsdlModelerFactory factory; 33 WeakHashMap <URL , WeakReference <WsdlModeler>> modelers; 34 35 36 private WsdlModelerFactory() { 37 modelers = new WeakHashMap <URL , WeakReference <WsdlModeler>>(5); 38 } 39 40 44 public static synchronized WsdlModelerFactory getDefault() { 45 if (factory==null) factory = new WsdlModelerFactory(); 46 return factory; 47 } 48 49 51 public WsdlModeler getWsdlModeler(URL wsdlUrl) { 52 WsdlModeler modeler = null; 53 synchronized (modelers) { 54 modeler = getFromCache(wsdlUrl); 55 if (modeler!=null) { 56 return modeler; 57 } 58 modeler = new WsdlModeler(wsdlUrl); 59 modelers.put(wsdlUrl, new WeakReference <WsdlModeler>(modeler)); 60 } 61 return modeler; 62 } 63 64 private WsdlModeler getFromCache (URL url) { 65 if (url == null) { 66 return null; 67 } 68 WeakReference wr = modelers.get(url); 69 if (wr == null) { 70 return null; 71 } 72 WsdlModeler modeler = (WsdlModeler) wr.get(); 73 if (modeler == null) { 74 modelers.remove(url); 75 } 76 return modeler; 77 } 78 79 int mapLength() { 80 return modelers.size(); 81 } 82 83 84 } 85 | Popular Tags |