001: /*
002: * Copyright 2004 (C) TJDO.
003: * All rights reserved.
004: *
005: * This software is distributed under the terms of the TJDO License version 1.0.
006: * See the terms of the TJDO License in the documentation provided with this software.
007: *
008: * $Id: CollectionMetaData.java,v 1.6 2004/01/18 03:01:06 jackknifebarber Exp $
009: */
010:
011: package com.triactive.jdo.model;
012:
013: import java.util.List;
014: import java.util.Set;
015: import javax.jdo.JDOFatalInternalException;
016: import org.w3c.dom.Element;
017:
018: public class CollectionMetaData extends MetaData {
019: protected final Class elementType;
020: protected final boolean embeddedElement;
021: protected final boolean clearOnDelete;
022:
023: public CollectionMetaData(FieldMetaData fmd, Element elem) {
024: super (fmd.getClassMetaData().getSourceURL(), elem);
025:
026: String typeAttr = elem.getAttribute("element-type");
027: String embeddedAttr = elem.getAttribute("embedded-element");
028:
029: elementType = getReferencedType(typeAttr, fmd
030: .getClassMetaData());
031:
032: if (embeddedAttr.length() > 0)
033: embeddedElement = Boolean.valueOf(embeddedAttr)
034: .booleanValue();
035: else
036: embeddedElement = Types.isDefaultEmbeddedType(elementType);
037:
038: String codAttr = getVendorExtension(MY_VENDOR,
039: "clear-on-delete");
040:
041: clearOnDelete = codAttr == null ? true : Boolean.valueOf(
042: codAttr).booleanValue();
043: }
044:
045: public String getJavaName() {
046: throw new JDOFatalInternalException(
047: "CollectionMetaData has no equivalent Java identifier");
048: }
049:
050: public Class getElementType() {
051: return elementType;
052: }
053:
054: public boolean isEmbeddedElement() {
055: return embeddedElement;
056: }
057:
058: public ColumnOptions getElementColumnOptions() {
059: return new ColumnOptions() {
060: public String getLength() {
061: return getVendorExtension(MY_VENDOR, "length");
062: }
063:
064: public String getPrecision() {
065: return getVendorExtension(MY_VENDOR, "precision");
066: }
067:
068: public String getScale() {
069: return getVendorExtension(MY_VENDOR, "scale");
070: }
071: };
072: }
073:
074: public boolean isInverseCollection() {
075: return getOwnerField() != null;
076: }
077:
078: public boolean clearOnDelete() {
079: return clearOnDelete;
080: }
081:
082: public FieldMetaData getOwnerField() {
083: String ownerFieldName = getVendorExtension(MY_VENDOR,
084: "owner-field");
085:
086: if (ownerFieldName == null)
087: ownerFieldName = getVendorExtension("sunw",
088: "element-inverse");
089:
090: return ownerFieldName == null ? null : FieldMetaData.forField(
091: elementType, ownerFieldName);
092: }
093:
094: void getReferencedClasses(final String vendorID,
095: final List ordered, final Set referenced) {
096: ClassMetaData cmd = ClassMetaData.forClass(elementType);
097:
098: if (cmd != null)
099: cmd.getReferencedClasses(vendorID, ordered, referenced);
100: }
101: }
|