1 7 8 package org.dom4j.util; 9 10 21 22 public class SimpleSingleton implements SingletonStrategy { 23 private String singletonClassName = null; 24 25 private Object singletonInstance = null; 26 27 public SimpleSingleton() { 28 } 29 30 public Object instance() { 31 return singletonInstance; 32 } 33 34 public void reset() { 35 if (singletonClassName != null) { 36 Class clazz = null; 37 try { 38 clazz = Thread.currentThread().getContextClassLoader().loadClass( 39 singletonClassName); 40 singletonInstance = clazz.newInstance(); 41 } catch (Exception ignore) { 42 try { 43 clazz = Class.forName(singletonClassName); 44 singletonInstance = clazz.newInstance(); 45 } catch (Exception ignore2) { 46 } 47 } 48 49 } 50 } 51 52 public void setSingletonClassName(String singletonClassName) { 53 this.singletonClassName = singletonClassName; 54 reset(); 55 } 56 57 } 58 59 95 | Popular Tags |