1 22 package org.jboss.beans.metadata.plugins; 23 24 import org.jboss.beans.info.spi.BeanInfo; 25 import org.jboss.beans.metadata.spi.MetaDataVisitor; 26 import org.jboss.dependency.plugins.AbstractDependencyItem; 27 import org.jboss.dependency.spi.ControllerContext; 28 import org.jboss.dependency.spi.ControllerState; 29 import org.jboss.dependency.spi.DependencyItem; 30 import org.jboss.joinpoint.spi.TargettedJoinpoint; 31 import org.jboss.kernel.spi.config.KernelConfigurator; 32 import org.jboss.kernel.spi.dependency.KernelController; 33 import org.jboss.kernel.spi.dependency.KernelControllerContext; 34 import org.jboss.reflect.spi.TypeInfo; 35 import org.jboss.util.JBossStringBuilder; 36 37 43 public class AbstractDependencyValueMetaData extends AbstractValueMetaData 44 { 45 46 protected KernelController controller; 47 48 49 protected String property; 50 51 52 protected ControllerState whenRequiredState; 53 54 55 protected ControllerState dependentState = ControllerState.INSTALLED; 56 57 60 public AbstractDependencyValueMetaData() 61 { 62 } 63 64 69 public AbstractDependencyValueMetaData(Object value) 70 { 71 super(value); 72 } 73 74 80 public AbstractDependencyValueMetaData(Object value, String property) 81 { 82 super(value); 83 this.property = property; 84 } 85 86 91 public String getProperty() 92 { 93 return property; 94 } 95 96 101 public void setProperty(String property) 102 { 103 this.property = property; 104 } 105 106 111 public void setWhenRequiredState(ControllerState whenRequiredState) 112 { 113 this.whenRequiredState = whenRequiredState; 114 flushJBossObjectCache(); 115 } 116 117 public ControllerState getWhenRequiredState() 118 { 119 return whenRequiredState; 120 } 121 122 127 public void setDependentState(ControllerState dependentState) 128 { 129 this.dependentState = dependentState; 130 flushJBossObjectCache(); 131 } 132 133 public ControllerState getDependentState() 134 { 135 return dependentState; 136 } 137 138 public Object getValue(TypeInfo info, ClassLoader cl) throws Throwable 139 { 140 ControllerState state = dependentState; 141 if (state == null) 142 state = ControllerState.INSTALLED; 143 ControllerContext context = controller.getContext(value, state); 144 if (context == null) 145 throw new Error ("Should not be here - dependency failed! " + this); 146 Object result = context.getTarget(); 147 if (result != null && property != null) 148 { 149 KernelConfigurator configurator = controller.getKernel().getConfigurator(); 150 BeanInfo beanInfo = configurator.getBeanInfo(result.getClass()); 151 TargettedJoinpoint joinpoint = configurator.getPropertyGetterJoinPoint(beanInfo, property); 152 joinpoint.setTarget(result); 153 return joinpoint.dispatch(); 154 } 155 return result; 156 } 157 158 public void initialVisit(MetaDataVisitor visitor) 159 { 160 KernelControllerContext controllerContext = visitor.getControllerContext(); 161 controller = (KernelController) controllerContext.getController(); 162 Object name = controllerContext.getName(); 163 Object iDependOn = getUnderlyingValue(); 164 ControllerState whenRequired = whenRequiredState; 165 if (whenRequired == null) 166 { 167 whenRequired = visitor.getContextState(); 168 } 169 170 DependencyItem item = new AbstractDependencyItem(name, iDependOn, whenRequired, dependentState); 171 visitor.addDependency(item); 172 173 super.initialVisit(visitor); 174 } 175 176 public void toString(JBossStringBuilder buffer) 177 { 178 super.toString(buffer); 179 if (property != null) 180 buffer.append(" property=").append(property); 181 if (whenRequiredState != null) 182 buffer.append(" whenRequiredState=").append(whenRequiredState.getStateString()); 183 if (dependentState != null) 184 buffer.append(" dependentState=").append(dependentState.getStateString()); 185 } 186 } 187 | Popular Tags |