KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > triactive > jdo > model > CollectionMetaData


1 /*
2  * Copyright 2004 (C) TJDO.
3  * All rights reserved.
4  *
5  * This software is distributed under the terms of the TJDO License version 1.0.
6  * See the terms of the TJDO License in the documentation provided with this software.
7  *
8  * $Id: CollectionMetaData.java,v 1.6 2004/01/18 03:01:06 jackknifebarber Exp $
9  */

10
11 package com.triactive.jdo.model;
12
13 import java.util.List JavaDoc;
14 import java.util.Set JavaDoc;
15 import javax.jdo.JDOFatalInternalException;
16 import org.w3c.dom.Element JavaDoc;
17
18
19 public class CollectionMetaData extends MetaData
20 {
21     protected final Class JavaDoc elementType;
22     protected final boolean embeddedElement;
23     protected final boolean clearOnDelete;
24
25     public CollectionMetaData(FieldMetaData fmd, Element JavaDoc elem)
26     {
27         super(fmd.getClassMetaData().getSourceURL(), elem);
28
29         String JavaDoc typeAttr = elem.getAttribute("element-type");
30         String JavaDoc 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 JavaDoc codAttr = getVendorExtension(MY_VENDOR, "clear-on-delete");
40
41         clearOnDelete = codAttr == null ? true : Boolean.valueOf(codAttr).booleanValue();
42     }
43
44     public String JavaDoc getJavaName()
45     {
46         throw new JDOFatalInternalException("CollectionMetaData has no equivalent Java identifier");
47     }
48
49     public Class JavaDoc 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 JavaDoc getLength()
64             {
65                 return getVendorExtension(MY_VENDOR, "length");
66             }
67
68             public String JavaDoc getPrecision()
69             {
70                 return getVendorExtension(MY_VENDOR, "precision");
71             }
72
73             public String JavaDoc 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 JavaDoc 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 JavaDoc vendorID, final List JavaDoc ordered, final Set JavaDoc referenced)
101     {
102         ClassMetaData cmd = ClassMetaData.forClass(elementType);
103
104         if (cmd != null)
105             cmd.getReferencedClasses(vendorID, ordered, referenced);
106     }
107 }
108
Popular Tags