1 10 package org.picocontainer.defaults; 11 12 import org.picocontainer.ComponentAdapter; 13 import org.picocontainer.PicoVisitor; 14 15 import java.io.Serializable ; 16 17 30 public abstract class AbstractComponentAdapter implements ComponentAdapter, Serializable { 31 private Object componentKey; 32 private Class componentImplementation; 33 34 40 protected AbstractComponentAdapter(Object componentKey, Class componentImplementation) throws AssignabilityRegistrationException { 41 if (componentImplementation == null) { 42 throw new NullPointerException ("componentImplementation"); 43 } 44 this.componentKey = componentKey; 45 this.componentImplementation = componentImplementation; 46 checkTypeCompatibility(); 47 } 48 49 53 public Object getComponentKey() { 54 if (componentKey == null) { 55 throw new NullPointerException ("componentKey"); 56 } 57 return componentKey; 58 } 59 60 64 public Class getComponentImplementation() { 65 return componentImplementation; 66 } 67 68 protected void checkTypeCompatibility() throws AssignabilityRegistrationException { 69 if (componentKey instanceof Class ) { 70 Class componentType = (Class ) componentKey; 71 if (!componentType.isAssignableFrom(componentImplementation)) { 72 throw new AssignabilityRegistrationException(componentType, componentImplementation); 73 } 74 } 75 } 76 77 81 public String toString() { 82 return getClass().getName() + "[" + getComponentKey() + "]"; 83 } 84 85 public void accept(PicoVisitor visitor) { 86 visitor.visitComponentAdapter(this); 87 } 88 } 89 | Popular Tags |