1 package org.enhydra.shark.xpdl.elements; 2 3 import java.util.HashMap ; 4 import java.util.Map ; 5 6 import org.enhydra.shark.xpdl.XMLComplexElement; 7 import org.enhydra.shark.xpdl.XMLElement; 8 import org.enhydra.shark.xpdl.XMLUtil; 9 10 15 public class DataType extends XMLComplexElement { 16 17 private static Map basicTypesMap=new HashMap (); 18 static { 19 basicTypesMap.put("BOOLEAN","java.lang.Boolean"); 20 basicTypesMap.put("STRING","java.lang.String"); 21 basicTypesMap.put("INTEGER","java.lang.Long"); 22 basicTypesMap.put("FLOAT","java.lang.Double"); 23 basicTypesMap.put("DATETIME","java.util.Date"); 24 } 25 26 protected transient String javaType; 27 28 public DataType (XMLComplexElement parent) { 29 super(parent, true); 30 } 31 32 protected void fillStructure () { 33 DataTypes refDataTypes=new DataTypes(this); 34 35 add(refDataTypes); 36 } 37 38 public void initCaches () { 39 super.initCaches(); 40 javaType=getChoosenType(getDataTypes(), XMLUtil.getPackage(this)); 41 } 42 43 public void clearCaches () { 44 javaType=null; 45 super.clearCaches(); 46 } 47 48 public String getJavaType () { 49 if (!isReadOnly) { 50 throw new RuntimeException ("This method can be used only in read-only mode!"); 51 } 52 return javaType; 53 } 54 55 private static String getChoosenType (DataTypes types,Package pkg) { 56 XMLElement choosenType=types.getChoosen(); 57 if (choosenType instanceof BasicType) { 58 String subTypeName=((BasicType)choosenType).getType(); 59 if (DataType.basicTypesMap.containsKey(subTypeName)) { 60 return (String )DataType.basicTypesMap.get(subTypeName); 61 } 62 } else if (choosenType instanceof DeclaredType) { 63 TypeDeclaration td=pkg.getTypeDeclaration(((DeclaredType)choosenType).getId()); 64 DataTypes dtypes=td.getDataTypes(); 65 return getChoosenType(dtypes,pkg); 66 } else if (choosenType instanceof ExternalReference) { 67 return ((ExternalReference)choosenType).getLocation(); 68 } 69 return "java.lang.Object"; 70 71 } 72 73 public DataTypes getDataTypes() { 74 return (DataTypes)get("Type"); 75 } 76 77 } 78 | Popular Tags |