1 package org.objectweb.modfact.jmi.reflect; 2 3 import java.util.*; 4 import javax.jmi.reflect.*; 5 6 public abstract class DataTypeContainer extends RefBaseObjectImpl { 7 8 List structNames = new Vector(); 9 List[] structQNames = null;; 10 List[] structFieldNameLists = null; 11 12 List enumTypeNames = new Vector(); 13 Object [] enumTypes = null; 14 15 void readDataTypeContents() { 16 17 List structList = new Vector(); 18 List enumList = new Vector(); 19 20 Iterator it = ((Collection)metaObject.refGetValue("contents")).iterator(); 21 22 while(it.hasNext()) { 23 RefObject content = (RefObject)it.next(); 24 String contentName = (String ) content.refGetValue("name"); 25 String contentType = (String ) content.refMetaObject().refGetValue("name"); 26 27 if(contentType.equals("StructureType")) { 28 structNames.add(contentName); 29 List fieldNames = new Vector(); 30 Iterator it2 = ((Collection) content.refGetValue("contents")).iterator(); 31 while(it2.hasNext()) { 32 RefObject cc = (RefObject)it2.next(); 33 String ccType = (String ) cc.refMetaObject().refGetValue("name"); 34 if(ccType.equals("StructureField")) { 35 fieldNames.add(cc.refGetValue("name")); 36 } 38 } 39 structList.add(fieldNames); 40 41 } else if(contentType.equals("EnumerationType")) { 42 enumTypeNames.add(contentName); 43 List labels = (List) content.refGetValue("labels"); 44 Object m = newEnum(contentName); 45 List typeName = this.refTypeName(); typeName.add(contentName); if(m==null) { 48 m = new EnumType(typeName,labels); 49 } 50 enumList.add( m ); 51 } 52 } 53 structFieldNameLists = (List[]) structList.toArray(new List[0]); 54 enumTypes = (Object []) enumList.toArray(new Object [0]); 55 56 } 57 58 public RefStruct refCreateStruct(javax.jmi.reflect.RefObject refObject, java.util.List list) { 59 String name = (String ) refObject.refGetValue("name"); 60 return refCreateStruct(name, list); 61 } 62 63 public RefStruct refCreateStruct(String type, java.util.List list) { 64 int index = structNames.indexOf(type); 65 if(index==-1) { 66 throw new RuntimeException ("Illegal struct type: " +type); 67 } 68 if(structQNames==null) { 69 List containerQName = refTypeName(); 70 structQNames = new List[structNames.size()]; 71 for(int i=0; i<structQNames.length; i++) { 72 List l = new Vector(containerQName); 73 l.add(structNames.get(i)); 74 structQNames[i] = l; 75 } 76 } 77 78 RefStructImpl s = newStruct(type); 79 s.typeNames = structQNames[index]; 80 s.fieldNames = structFieldNameLists[index]; 81 s.setValues(list); 82 return s; 83 } 84 85 public RefEnum refGetEnum(javax.jmi.reflect.RefObject refObject, String val) { 86 String type = (String ) refObject.refGetValue("name"); 87 return refGetEnum(type, val); 88 } 89 90 public RefEnum refGetEnum(String type, String val) { 91 int index = enumTypeNames.indexOf(type); 92 if(index==-1) { 93 throw new RuntimeException ("Invalide Enum type: " +type); 94 } 95 if(enumTypes[index] instanceof EnumType) 96 return ((EnumType)enumTypes[index]).getEnum(val); 97 Class [] argType = { String .class }; 98 Object [] args = { val }; 99 try { 100 return (RefEnum) ((Class )enumTypes[index]) 101 .getMethod("forName", argType) 102 .invoke( 103 null, args 104 ); 105 } catch(Exception e) { 106 System.out.println("error at " +enumTypes[index]); 107 throw new RuntimeException (e); 108 } 109 } 110 111 public Class newEnum(String name) { 113 return null; 114 } 115 116 public RefStructImpl newStruct(String name) { 117 return new RefStructImpl(); 118 } 119 120 } 121 | Popular Tags |