1 22 package org.jboss.beans.metadata.plugins; 23 24 import java.util.Set ; 25 import java.util.Stack ; 26 27 import org.jboss.beans.metadata.spi.MetaDataVisitor; 28 import org.jboss.beans.metadata.spi.MetaDataVisitorNode; 29 import org.jboss.beans.metadata.spi.ParameterMetaData; 30 import org.jboss.beans.metadata.spi.ValueMetaData; 31 import org.jboss.kernel.plugins.config.Configurator; 32 import org.jboss.kernel.spi.config.KernelConfigurator; 33 import org.jboss.kernel.spi.dependency.KernelController; 34 import org.jboss.kernel.spi.dependency.KernelControllerContext; 35 import org.jboss.util.JBossStringBuilder; 36 37 43 public class AbstractParameterMetaData extends AbstractFeatureMetaData implements ParameterMetaData 44 { 45 48 protected String type; 49 50 53 protected ValueMetaData value; 54 55 58 protected int index; 59 60 63 public AbstractParameterMetaData() 64 { 65 } 66 67 72 public AbstractParameterMetaData(Object value) 73 { 74 this.type = value.getClass().getName(); 75 this.value = new AbstractValueMetaData(value); 76 } 77 78 83 public AbstractParameterMetaData(ValueMetaData value) 84 { 85 this.value = value; 86 } 87 88 94 public AbstractParameterMetaData(String type, Object value) 95 { 96 this.type = type; 97 this.value = new AbstractValueMetaData(value); 98 } 99 100 106 public AbstractParameterMetaData(String type, String value) 107 { 108 this.type = type; 109 this.value = new StringValueMetaData(value); 110 } 111 112 118 public AbstractParameterMetaData(String type, ValueMetaData value) 119 { 120 this.type = type; 121 this.value = value; 122 } 123 124 public String getType() 125 { 126 return type; 127 } 128 129 public void setType(String type) 130 { 131 this.type = type; 132 flushJBossObjectCache(); 133 } 134 135 public ValueMetaData getValue() 136 { 137 return value; 138 } 139 140 public int getIndex() 141 { 142 return index; 143 } 144 145 public void setIndex(int index) 146 { 147 this.index = index; 148 } 149 150 public void setValue(ValueMetaData value) 151 { 152 this.value = value; 153 flushJBossObjectCache(); 154 } 155 156 protected void addChildren(Set <MetaDataVisitorNode> children) 157 { 158 super.addChildren(children); 159 if (value != null) 160 children.add(value); 161 } 162 163 public Class getType(MetaDataVisitor visitor, MetaDataVisitorNode previous) throws Throwable 164 { 165 if (type != null) 166 { 167 KernelControllerContext context = visitor.getControllerContext(); 168 ClassLoader cl = Configurator.getClassLoader(context.getBeanMetaData()); 169 KernelController controller = (KernelController) context.getController(); 170 KernelConfigurator configurator = controller.getKernel().getConfigurator(); 171 return applyCollectionOrMapCheck(configurator.getClassInfo(type, cl).getType()); 172 } 173 else 174 { 175 Stack <MetaDataVisitorNode> visitorNodeStack = visitor.visitorNodeStack(); 176 MetaDataVisitorNode node = visitorNodeStack.pop(); 178 try 179 { 180 if (node instanceof TypeProvider) 181 { 182 TypeProvider typeProvider = (TypeProvider) node; 183 return typeProvider.getType(visitor, this); 184 } 185 else 186 { 187 throw new IllegalArgumentException (TypeProvider.ERROR_MSG); 188 } 189 } 190 finally 191 { 192 visitorNodeStack.push(node); 193 } 194 } 195 } 196 197 public void toString(JBossStringBuilder buffer) 198 { 199 buffer.append("type=").append(type); 200 buffer.append(" value=").append(value); 201 super.toString(buffer); 202 } 203 204 public void toShortString(JBossStringBuilder buffer) 205 { 206 buffer.append(type); 207 } 208 } 209 | Popular Tags |