1 package org.objectweb.modfact.jmi.xmi; 2 3 import java.util.*; 4 5 import javax.jmi.reflect.*; 6 7 import org.objectweb.modfact.jmi.reflect.ReflectHelper; 8 9 10 public class PropertyTypeManager { 11 12 Hashtable typeCach = new Hashtable(); 13 14 public PropertyTypeManager() { 15 } 16 17 18 19 public TypeInfo findTypeFor(RefObject metaObjectOwner, String unqPropName ) { 20 RefObject propMeta = (RefObject) ReflectHelper.lookupElementExtended(metaObjectOwner, unqPropName); 21 return findTypeFor(propMeta); 22 } 23 24 25 private TypeInfo findTypeFor(RefObject propMetaObject) { 30 return findTypeFor(propMetaObject, false); 31 } 32 33 34 private TypeInfo findTypeFor(RefObject propMetaObject, boolean isStructField) { 35 TypeInfo typeInfo = (TypeInfo)typeCach.get(propMetaObject); 37 if(typeInfo!=null) return typeInfo; 38 typeInfo = new TypeInfo(); 41 if(!isStructField) { 42 typeInfo.isMultiValued = ( 43 ((Integer )((RefStruct)propMetaObject.refGetValue("multiplicity")).refGetValue("upper")).intValue()!=1 44 ); 45 } 46 RefObject type= (RefObject)propMetaObject.refGetValue("type"); 47 typeInfo.name = (String ) type.refGetValue("name"); 48 typeInfo.qname = (String ) ReflectHelper.dotQName(ReflectHelper.getQualifiedName(type)); 49 String typeKind = (String ) type.refMetaObject().refGetValue("name"); 50 if(typeKind.equals("PrimitiveType")) { 51 typeInfo.isPrimitive = true; 52 } else if(typeKind.equals("EnumerationType")) { 53 typeInfo.isEnum = true; 54 typeInfo.enumUnprefix = ReflectHelper.findTagValue(type,"org.omg.xmi.enumerationUnprefix"); 55 56 } else if(typeKind.equals("StructureType")) { 57 typeInfo.isStruct = true; 58 List fieldTypes = new Vector(); 59 List fieldNames = new Vector(); 60 Iterator it = ((List)type.refGetValue("contents")).iterator(); 61 while(it.hasNext()) { 62 RefObject content = (RefObject)it.next(); 63 if(content.refMetaObject().refGetValue("name").equals("StructureField")) { 64 fieldTypes.add(findTypeFor(content, true)); 65 fieldNames.add(content.refGetValue("name")); 66 } 67 } 68 typeInfo.structFieldTypes = (TypeInfo[]) fieldTypes.toArray(new TypeInfo[0]); 69 typeInfo.structFieldNames = (String []) fieldNames.toArray(new String [0]); 70 } 71 typeCach.put(propMetaObject, typeInfo); 73 return typeInfo; 74 } 75 76 77 78 79 80 public static class TypeInfo { 81 public String name; 82 public String qname; 83 public boolean isMultiValued = false; 84 public boolean isEnum = false; 85 public String enumUnprefix = null; public boolean isStruct = false; 87 public boolean isPrimitive = false; 88 public TypeInfo[] structFieldTypes = null; 89 public String [] structFieldNames = null; 90 } 91 } 92 | Popular Tags |