1 22 package org.jboss.beans.metadata.plugins; 23 24 import java.util.ArrayList ; 25 import java.util.Collection ; 26 27 import org.jboss.reflect.spi.ClassInfo; 28 import org.jboss.reflect.spi.TypeInfo; 29 import org.jboss.util.JBossStringBuilder; 30 31 37 public class AbstractArrayMetaData extends AbstractListMetaData 38 { 39 42 public AbstractArrayMetaData() 43 { 44 } 45 46 public Object getValue(TypeInfo info, ClassLoader cl) throws Throwable 47 { 48 Collection <? extends Object > result = (Collection <? extends Object >) super.getValue(info, cl); 49 50 TypeInfo typeInfo = getClassInfo(cl); 51 52 if (typeInfo != null && typeInfo instanceof ClassInfo == false) 53 throw new IllegalArgumentException (typeInfo.getName() + " is not a class"); 54 55 if (typeInfo == null) 56 { 57 if (info == null) 59 { 60 info = getElementClassInfo(cl); 61 if (info == null) 62 return null; 63 info = info.getArrayType(0); 64 } 65 if (info instanceof ClassInfo == false) 67 return null; 68 if (((ClassInfo) info).isInterface()) 70 return null; 71 if (Object .class.getName().equals(info.getName())) 73 return null; 74 typeInfo = info; 76 } 77 78 Object [] array = new Object [result.size()]; 79 if (typeInfo != null) 80 array = typeInfo.newArrayInstance(result.size()); 81 82 return result.toArray(array); 83 } 84 85 protected Collection <Object > getCollectionInstance(TypeInfo info, ClassLoader cl, Class expected) throws Throwable 86 { 87 Collection <Object > result = new ArrayList <Object >(); 88 Object preinstantiatedObject = preinstantiatedLookup(cl, null); 89 if (preinstantiatedObject != null) 90 { 91 if (preinstantiatedObject.getClass().isArray() == false) 92 throw new ClassCastException ("Preinstantiated property is not an array: " + propertyName); 93 Object [] preinstantiatedArray = (Object []) preinstantiatedObject; 94 for(Object previous : preinstantiatedArray) 95 { 96 result.add(previous); 97 } 98 } 99 return result; 100 } 101 102 public void toString(JBossStringBuilder buffer) 103 { 104 super.toString(buffer); 105 } 106 } | Popular Tags |