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 CollectionMetaData extends MetaData 20 { 21 protected final Class elementType; 22 protected final boolean embeddedElement; 23 protected final boolean clearOnDelete; 24 25 public CollectionMetaData(FieldMetaData fmd, Element elem) 26 { 27 super(fmd.getClassMetaData().getSourceURL(), elem); 28 29 String typeAttr = elem.getAttribute("element-type"); 30 String embeddedAttr = elem.getAttribute("embedded-element"); 31 32 elementType = getReferencedType(typeAttr, fmd.getClassMetaData()); 33 34 if (embeddedAttr.length() > 0) 35 embeddedElement = Boolean.valueOf(embeddedAttr).booleanValue(); 36 else 37 embeddedElement = Types.isDefaultEmbeddedType(elementType); 38 39 String codAttr = getVendorExtension(MY_VENDOR, "clear-on-delete"); 40 41 clearOnDelete = codAttr == null ? true : Boolean.valueOf(codAttr).booleanValue(); 42 } 43 44 public String getJavaName() 45 { 46 throw new JDOFatalInternalException("CollectionMetaData has no equivalent Java identifier"); 47 } 48 49 public Class getElementType() 50 { 51 return elementType; 52 } 53 54 public boolean isEmbeddedElement() 55 { 56 return embeddedElement; 57 } 58 59 public ColumnOptions getElementColumnOptions() 60 { 61 return new ColumnOptions() 62 { 63 public String getLength() 64 { 65 return getVendorExtension(MY_VENDOR, "length"); 66 } 67 68 public String getPrecision() 69 { 70 return getVendorExtension(MY_VENDOR, "precision"); 71 } 72 73 public String getScale() 74 { 75 return getVendorExtension(MY_VENDOR, "scale"); 76 } 77 }; 78 } 79 80 public boolean isInverseCollection() 81 { 82 return getOwnerField() != null; 83 } 84 85 public boolean clearOnDelete() 86 { 87 return clearOnDelete; 88 } 89 90 public FieldMetaData getOwnerField() 91 { 92 String ownerFieldName = getVendorExtension(MY_VENDOR, "owner-field"); 93 94 if (ownerFieldName == null) 95 ownerFieldName = getVendorExtension("sunw", "element-inverse"); 96 97 return ownerFieldName == null ? null : FieldMetaData.forField(elementType, ownerFieldName); 98 } 99 100 void getReferencedClasses(final String vendorID, final List ordered, final Set referenced) 101 { 102 ClassMetaData cmd = ClassMetaData.forClass(elementType); 103 104 if (cmd != null) 105 cmd.getReferencedClasses(vendorID, ordered, referenced); 106 } 107 } 108 | Popular Tags |