1 22 package org.jboss.system.metadata; 23 24 import org.jboss.beans.info.spi.BeanInfo; 25 import org.jboss.dependency.plugins.AbstractDependencyItem; 26 import org.jboss.dependency.spi.ControllerContext; 27 import org.jboss.dependency.spi.ControllerState; 28 import org.jboss.dependency.spi.DependencyItem; 29 import org.jboss.joinpoint.spi.TargettedJoinpoint; 30 import org.jboss.kernel.spi.config.KernelConfigurator; 31 import org.jboss.kernel.spi.dependency.KernelController; 32 import org.jboss.system.microcontainer.ServiceControllerContext; 33 34 40 public class ServiceInjectionValueMetaData extends AbstractMetaDataVisitorNode implements ServiceValueMetaData 41 { 42 43 private Object dependency; 44 45 46 private String property; 47 48 49 private ControllerState dependentState = ControllerState.INSTALLED; 50 51 54 public ServiceInjectionValueMetaData() 55 { 56 } 57 58 63 public ServiceInjectionValueMetaData(Object dependency) 64 { 65 this(dependency, null); 66 } 67 68 74 public ServiceInjectionValueMetaData(Object dependency, String property) 75 { 76 this(dependency, property, ControllerState.INSTALLED); 77 } 78 79 86 public ServiceInjectionValueMetaData(Object dependency, String property, ControllerState dependentState) 87 { 88 setDependency(dependency); 89 setProperty(property); 90 setDependentState(dependentState); 91 } 92 93 98 public Object getDependency() 99 { 100 return dependency; 101 } 102 103 108 public void setDependency(Object dependency) 109 { 110 if (dependency == null) 111 throw new IllegalArgumentException ("Null dependency"); 112 this.dependency = dependency; 113 } 114 115 120 public String getProperty() 121 { 122 return property; 123 } 124 125 130 public void setProperty(String property) 131 { 132 this.property = property; 133 } 134 135 140 public ControllerState getDependentState() 141 { 142 return dependentState; 143 } 144 145 150 public void setDependentState(ControllerState dependentState) 151 { 152 this.dependentState = dependentState; 153 } 154 155 public Object getValue(ServiceValueContext valueContext) throws Throwable 156 { 157 KernelController controller = valueContext.getController(); 158 159 ControllerState state = dependentState; 160 if (state == null) 161 state = ControllerState.INSTALLED; 162 163 ControllerContext context = controller.getContext(dependency, dependentState); 164 if (context == null) 165 throw new Error ("Should not be here - dependency failed! " + this); 166 Object result = context.getTarget(); 167 if (result != null && property != null) 168 { 169 KernelConfigurator configurator = controller.getKernel().getConfigurator(); 170 BeanInfo beanInfo = configurator.getBeanInfo(result.getClass()); 171 TargettedJoinpoint joinpoint = configurator.getPropertyGetterJoinPoint(beanInfo, property); 172 joinpoint.setTarget(result); 173 return joinpoint.dispatch(); 174 } 175 return result; 176 } 177 178 public void visit(ServiceMetaDataVisitor visitor) 179 { 180 ServiceControllerContext context = visitor.getControllerContext(); 181 Object name = context.getName(); 182 ControllerState whenRequired = visitor.getContextState(); 183 184 DependencyItem item = new AbstractDependencyItem(name, dependency, whenRequired, dependentState); 185 visitor.addDependency(item); 186 187 visitor.visit(this); 188 } 189 } 190 | Popular Tags |