1 22 package org.jboss.beans.metadata.plugins; 23 24 import org.jboss.beans.metadata.spi.MetaDataVisitor; 25 import org.jboss.beans.metadata.spi.MetaDataVisitorNode; 26 import org.jboss.dependency.spi.ControllerContext; 27 import org.jboss.dependency.spi.DependencyItem; 28 import org.jboss.kernel.plugins.dependency.ClassContextDependencyItem; 29 import org.jboss.kernel.spi.dependency.KernelController; 30 import org.jboss.kernel.spi.dependency.KernelControllerContext; 31 import org.jboss.reflect.spi.TypeInfo; 32 import org.jboss.util.JBossStringBuilder; 33 34 39 public class AbstractInjectionValueMetaData extends AbstractDependencyValueMetaData 40 { 41 protected InjectionType injectionType = InjectionType.BY_CLASS; 42 43 46 protected AbstractPropertyMetaData propertyMetaData; 47 48 51 public AbstractInjectionValueMetaData() 52 { 53 } 54 55 60 public AbstractInjectionValueMetaData(Object value) 61 { 62 super(value); 63 } 64 65 71 public AbstractInjectionValueMetaData(Object value, String property) 72 { 73 super(value, property); 74 } 75 76 public InjectionType getInjectionType() 77 { 78 return injectionType; 79 } 80 81 public void setInjectionType(InjectionType injectionType) 82 { 83 this.injectionType = injectionType; 84 } 85 86 public AbstractPropertyMetaData getPropertyMetaData() 87 { 88 return propertyMetaData; 89 } 90 91 public void setPropertyMetaData(AbstractPropertyMetaData propertyMetaData) 92 { 93 this.propertyMetaData = propertyMetaData; 94 } 95 96 public Object getValue(TypeInfo info, ClassLoader cl) throws Throwable 97 { 98 if (value == null) 99 { 100 ControllerContext context = controller.getInstalledContext(info.getType()); 101 if (context == null) 102 { 103 throw new IllegalArgumentException ("Possible multiple matching beans, see log for info."); 104 } 105 return context.getTarget(); 106 } 107 return super.getValue(info, cl); 108 } 109 110 public void initialVisit(MetaDataVisitor visitor) 111 { 112 if (getUnderlyingValue() == null) 113 { 114 if (property != null) 116 { 117 property = null; 118 log.warn("Ignoring property - contextual injection: " + this); 119 } 120 121 if (InjectionType.BY_NAME.equals(injectionType)) 122 { 123 if (propertyMetaData == null) 124 { 125 throw new IllegalArgumentException ("Illegal usage of type ByName - injection not used with property = " + this); 126 } 127 setValue(propertyMetaData.getName()); 128 } 129 130 visitor.initialVisit(this); 131 } 132 if (getUnderlyingValue() != null) 134 { 135 super.initialVisit(visitor); 136 } 137 } 138 139 public void describeVisit(MetaDataVisitor visitor) 140 { 141 if (getUnderlyingValue() == null) 142 { 143 if (InjectionType.BY_CLASS.equals(injectionType)) 144 { 145 KernelControllerContext context = visitor.getControllerContext(); 146 controller = (KernelController) context.getController(); 148 MetaDataVisitorNode node = visitor.visitorNodeStack().pop(); 155 try 156 { 157 if (node instanceof TypeProvider) 158 { 159 TypeProvider typeProvider = (TypeProvider) node; 160 DependencyItem item = new ClassContextDependencyItem( 161 context.getName(), 162 typeProvider.getType(visitor, this), 163 visitor.getContextState(), 164 dependentState); 165 visitor.addDependency(item); 166 } 167 else 168 { 169 throw new Error (TypeProvider.ERROR_MSG); 170 } 171 } 172 catch (Error error) 173 { 174 throw error; 175 } 176 catch (Throwable throwable) 177 { 178 throw new Error (throwable); 179 } 180 finally 181 { 182 visitor.visitorNodeStack().push(node); 183 } 184 } 185 else 186 { 187 throw new IllegalArgumentException ("Unknown injection type=" + injectionType); 188 } 189 } 190 super.describeVisit(visitor); 191 } 192 193 public void toString(JBossStringBuilder buffer) 194 { 195 super.toString(buffer); 196 if (injectionType != null) 197 buffer.append(" injectionType=").append(injectionType); 198 if (propertyMetaData != null) 199 buffer.append(" propertyMetaData=").append(propertyMetaData.getName()); } 201 202 } 203 | Popular Tags |