1 22 package org.jboss.beans.metadata.plugins; 23 24 import java.util.Iterator ; 25 import java.util.Set ; 26 27 import org.jboss.beans.info.spi.PropertyInfo; 28 import org.jboss.beans.metadata.spi.MetaDataVisitor; 29 import org.jboss.beans.metadata.spi.MetaDataVisitorNode; 30 import org.jboss.beans.metadata.spi.PropertyMetaData; 31 import org.jboss.beans.metadata.spi.ValueMetaData; 32 import org.jboss.dependency.spi.ControllerState; 33 import org.jboss.kernel.spi.dependency.KernelControllerContext; 34 import org.jboss.util.JBossStringBuilder; 35 36 42 public class AbstractPropertyMetaData extends AbstractFeatureMetaData implements PropertyMetaData, TypeProvider 43 { 44 45 protected String name; 46 47 48 protected ValueMetaData value; 49 50 53 public AbstractPropertyMetaData() 54 { 55 } 56 57 63 public AbstractPropertyMetaData(String name, Object value) 64 { 65 this.name = name; 66 this.value = new AbstractValueMetaData(value); 67 } 68 69 75 public AbstractPropertyMetaData(String name, String value) 76 { 77 this.name = name; 78 this.value = new StringValueMetaData(value); 79 } 80 81 87 public AbstractPropertyMetaData(String name, ValueMetaData value) 88 { 89 this.name = name; 90 this.value = value; 91 } 92 93 100 public AbstractPropertyMetaData(String name, String value, String type) 101 { 102 this.name = name; 103 StringValueMetaData svmd = new StringValueMetaData(value); 104 svmd.setType(type); 105 this.value = svmd; 106 } 107 108 public String getName() 109 { 110 return name; 111 } 112 113 118 public void setName(String name) 119 { 120 this.name = name; 121 flushJBossObjectCache(); 122 } 123 124 public ValueMetaData getValue() 125 { 126 return value; 127 } 128 129 134 public void setValue(ValueMetaData value) 135 { 136 this.value = value; 137 flushJBossObjectCache(); 138 } 139 140 public void initialVisit(MetaDataVisitor visitor) 141 { 142 visitor.setContextState(ControllerState.CONFIGURED); 143 super.initialVisit(visitor); 144 } 145 146 public void addChildren(Set <MetaDataVisitorNode> children) 147 { 148 if (value != null) 149 children.add(value); 150 } 151 152 public Class getType(MetaDataVisitor visitor, MetaDataVisitorNode previous) throws Throwable 153 { 154 KernelControllerContext context = visitor.getControllerContext(); 155 Set propertyInfos = context.getBeanInfo().getProperties(); 156 if (propertyInfos != null) 157 { 158 for(Iterator it = propertyInfos.iterator(); it.hasNext();) 159 { 160 PropertyInfo pi = (PropertyInfo) it.next(); 161 if (getName().equals(pi.getName())) 162 { 163 return applyCollectionOrMapCheck(pi.getType().getType()); 164 } 165 } 166 } 167 throw new IllegalArgumentException ("Should not be here - no matching propertyInfo: " + this); 168 } 169 170 public void toString(JBossStringBuilder buffer) 171 { 172 buffer.append("name=").append(name); 173 if (value != null) 174 buffer.append(" value=").append(value); 175 super.toString(buffer); 176 } 177 178 public void toShortString(JBossStringBuilder buffer) 179 { 180 buffer.append(name); 181 } 182 } 183 | Popular Tags |