1 6 package org.jfox.ioc.depend; 7 8 import org.jfox.ioc.ComponentName; 9 import org.jfox.ioc.Registry; 10 import org.jfox.ioc.exception.ComponentException; 11 12 17 18 public class ComponentRefDependency implements RefDependency { 19 private Class type = null; 20 23 private ComponentName refCompName; 24 private Object value; 25 26 public ComponentRefDependency(ComponentName refComponentName) { 27 this.refCompName = refComponentName; 28 this.type = refCompName.getType(); 29 } 30 31 public Class getType() { 32 return type; 33 } 34 35 public String getLiteralValue() { 36 return refCompName.toString(); 37 } 38 39 public ComponentName getRefComponentName() { 40 return refCompName; 41 } 42 43 48 public Object resolveValue(Registry registry) throws ComponentException { 49 if(value != null) return value; 50 value = registry.getComponentInstance(refCompName); 51 return value; 52 } 53 54 public String toString() { 55 return "ComponentRefParameter{" + 56 "type=" + type.getName() + 57 ", refCompName='" + refCompName + "'" + 58 ", value=" + (value == null ? "NOT RESOVLED" : value.toString()) + 59 "}"; 60 } 61 62 public static void main(String [] args) { 63 64 } 65 66 } 67 | Popular Tags |