1 10 11 package com.triactive.jdo.model; 12 13 import java.util.List ; 14 import java.util.Set ; 15 import javax.jdo.JDOFatalInternalException; 16 import org.w3c.dom.Element ; 17 18 19 public class MapMetaData extends MetaData 20 { 21 protected final Class keyType; 22 protected final Class valueType; 23 protected final boolean embeddedKey; 24 protected final boolean embeddedValue; 25 protected final boolean allowsNullValues; 26 27 public MapMetaData(FieldMetaData fmd, Element elem) 28 { 29 super(fmd.getClassMetaData().getSourceURL(), elem); 30 31 String typeAttr = elem.getAttribute("key-type"); 32 String embeddedAttr = elem.getAttribute("embedded-key"); 33 34 keyType = getReferencedType(typeAttr, fmd.getClassMetaData()); 35 36 if (embeddedAttr.length() > 0) 37 embeddedKey = Boolean.valueOf(embeddedAttr).booleanValue(); 38 else 39 embeddedKey = Types.isDefaultEmbeddedType(keyType); 40 41 typeAttr = elem.getAttribute("value-type"); 42 embeddedAttr = elem.getAttribute("embedded-value"); 43 44 valueType = getReferencedType(typeAttr, fmd.getClassMetaData()); 45 46 if (embeddedAttr.length() > 0) 47 embeddedValue = Boolean.valueOf(embeddedAttr).booleanValue(); 48 else 49 embeddedValue = Types.isDefaultEmbeddedType(valueType); 50 51 if (fmd.getType() == java.util.Hashtable .class) 52 allowsNullValues = false; 53 else 54 allowsNullValues = true; 55 } 56 57 public String getJavaName() 58 { 59 throw new JDOFatalInternalException("MapMetaData has no equivalent Java identifier"); 60 } 61 62 public Class getKeyType() 63 { 64 return keyType; 65 } 66 67 public Class getValueType() 68 { 69 return valueType; 70 } 71 72 public boolean isEmbeddedKey() 73 { 74 return embeddedKey; 75 } 76 77 public boolean isEmbeddedValue() 78 { 79 return embeddedValue; 80 } 81 82 public boolean allowsNullValues() 83 { 84 return allowsNullValues; 85 } 86 87 public ColumnOptions getKeyColumnOptions() 88 { 89 return new ColumnOptions() 90 { 91 public String getLength() 92 { 93 String length = getVendorExtension(MY_VENDOR, "key-length"); 94 95 if (length == null) 96 length = getVendorExtension(MY_VENDOR, "length"); 97 98 return length; 99 } 100 101 public String getPrecision() 102 { 103 String precision = getVendorExtension(MY_VENDOR, "key-precision"); 104 105 if (precision == null) 106 precision = getVendorExtension(MY_VENDOR, "precision"); 107 108 return precision; 109 } 110 111 public String getScale() 112 { 113 String scale = getVendorExtension(MY_VENDOR, "key-scale"); 114 115 if (scale == null) 116 scale = getVendorExtension(MY_VENDOR, "scale"); 117 118 return scale; 119 } 120 }; 121 } 122 123 public ColumnOptions getValueColumnOptions() 124 { 125 return new ColumnOptions() 126 { 127 public String getLength() 128 { 129 return getVendorExtension(MY_VENDOR, "value-length"); 130 } 131 132 public String getPrecision() 133 { 134 return getVendorExtension(MY_VENDOR, "value-precision"); 135 } 136 137 public String getScale() 138 { 139 return getVendorExtension(MY_VENDOR, "value-scale"); 140 } 141 }; 142 } 143 144 public boolean isInverseMap() 145 { 146 return getOwnerField() != null; 147 } 148 149 public boolean clearOnDelete() 150 { 151 String codAttr = getVendorExtension(MY_VENDOR, "clear-on-delete"); 152 153 return codAttr == null ? true : Boolean.valueOf(codAttr).booleanValue(); 154 } 155 156 public FieldMetaData getOwnerField() 157 { 158 String ownerFieldName = getVendorExtension(MY_VENDOR, "owner-field"); 159 160 return ownerFieldName == null ? null : FieldMetaData.forField(valueType, ownerFieldName); 161 } 162 163 public FieldMetaData getKeyField() 164 { 165 String keyFieldName = getVendorExtension(MY_VENDOR, "key-field"); 166 167 return keyFieldName == null ? null : FieldMetaData.forField(valueType, keyFieldName); 168 } 169 170 void getReferencedClasses(final String vendorID, final List ordered, final Set referenced) 171 { 172 ClassMetaData cmd = ClassMetaData.forClass(keyType); 173 174 if (cmd != null) 175 cmd.getReferencedClasses(vendorID, ordered, referenced); 176 177 cmd = ClassMetaData.forClass(valueType); 178 179 if (cmd != null) 180 cmd.getReferencedClasses(vendorID, ordered, referenced); 181 } 182 } 183 | Popular Tags |