1 6 7 package org.jfox.pool; 8 9 12 13 public class SimpleObjectFactory implements ObjectFactory { 14 protected Class classType = null; 15 16 public SimpleObjectFactory(Class classType) throws Exception { 17 setObjectClass(classType); 18 } 19 20 public Class getObjectClass() { 21 return classType; 22 } 23 24 public PoolableObject makeObject() throws Exception { 25 return (PoolableObject) classType.newInstance(); 26 } 27 28 33 public void destroyObject(PoolableObject object) throws Exception { 34 } 36 37 public boolean validateObject(PoolableObject obj) { 38 return obj.isAvailable() && classType.isAssignableFrom(obj.getClass()); 39 } 40 41 private void setObjectClass(Class classType) throws Exception { 42 if(!validateClassType(classType)) { 43 throw new Exception ("class " + classType.getName() + " not derived from " + PoolableObject.class.getName()); 44 } 45 this.classType = classType; 46 } 47 48 54 private boolean validateClassType(Class classType) { 55 if(PoolableObject.class.isAssignableFrom(classType)) { 56 return true; 57 } 58 return false; 59 } 60 61 public int hashCode() { 62 return classType.hashCode(); 63 } 64 65 public boolean equals(Object obj) { 66 if(!(obj instanceof SimpleObjectFactory)) return false; 67 return classType.equals(((SimpleObjectFactory) obj).classType); 68 } 69 70 } 71 72 | Popular Tags |