KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > xdoclet > modules > triactive > jdo > TJDOSubTask


1 /*
2  * Copyright (c) 2001, 2002 The XDoclet team
3  * All rights reserved.
4  */

5 package xdoclet.modules.triactive.jdo;
6
7 import java.util.ArrayList JavaDoc;
8 import java.util.Collection JavaDoc;
9
10 import org.apache.commons.logging.Log;
11 import org.apache.commons.logging.LogFactory;
12 import xjavadoc.XDoc;
13 import xjavadoc.XTag;
14 import xdoclet.XDocletException;
15 import xdoclet.modules.jdo.VendorExtension;
16 import xdoclet.modules.jdo.VendorExtensionsSubTask;
17
18 /**
19  * @author Ludovic Claude (ludovicc@users.sourceforge.net)
20  * @author <a HREF="mailto:d_jencks@users.sourceforge.net">David Jencks</a>
21  * @created 7 November 2002
22  * @version $Revision: 1.3 $
23  * @ant.element display-name="Triactive TJDO support" name="triactive" parent="xdoclet.modules.jdo.JdoDocletTask"
24  */

25 public class TJDOSubTask extends VendorExtensionsSubTask
26 {
27
28     private final static Log LOG = LogFactory.getLog(TJDOSubTask.class);
29
30     private String JavaDoc version = TJDOVersionTypes.VERSION_2_0;
31
32     /**
33      * Gets the Version attribute of the TJDOSubTask object
34      *
35      * @return The Version value
36      */

37     public String JavaDoc getVersion()
38     {
39         return version;
40     }
41
42     /**
43      * @return
44      * @see xdoclet.modules.jdo.VendorExtensionsSubTask#getVendorName()
45      */

46     public String JavaDoc getVendorName()
47     {
48         return "triactive";
49     }
50
51     public String JavaDoc getVendorDescription()
52     {
53         return "TJDO open source JDO implementation initially developed by Triactive";
54     }
55
56     /**
57      * The version of TJDO. Supported versions are 2.0.
58      *
59      * @param version The new Version value
60      * @ant.not-required No, default is "2.0".
61      */

62     public void setVersion(TJDOVersionTypes version)
63     {
64         this.version = version.getValue();
65     }
66
67     /**
68      * @return
69      * @exception XDocletException
70      */

71     protected Collection JavaDoc getClassExtensions() throws XDocletException
72     {
73         Collection JavaDoc extensions = new ArrayList JavaDoc();
74
75         return extensions;
76     }
77
78     /**
79      * @return
80      * @exception XDocletException
81      * @todo column-length is likely to be standardizable
82      */

83     protected Collection JavaDoc getFieldExtensions() throws XDocletException
84     {
85         Collection JavaDoc extensions = new ArrayList JavaDoc();
86         XDoc doc = getCurrentField().getDoc();
87
88         if (doc.hasTag("tjdo.field")) {
89             XTag tag = doc.getTag("tjdo.field");
90
91             addSizeExtensions(extensions, tag, "column-", "");
92
93             String JavaDoc collectionField = tag.getAttributeValue("collection-field");
94             String JavaDoc mapField = tag.getAttributeValue("map-field");
95
96             if (collectionField != null) {
97                 extensions.add(new VendorExtension(getVendorName(), "collection-field", collectionField));
98             }
99             if (mapField != null) {
100                 extensions.add(new VendorExtension(getVendorName(), "map-field", mapField));
101             }
102         }
103
104         return extensions;
105     }
106
107     protected Collection JavaDoc getCollectionExtensions() throws XDocletException
108     {
109         Collection JavaDoc extensions = new ArrayList JavaDoc();
110         XDoc doc = getCurrentField().getDoc();
111
112         if (doc.hasTag("tjdo.field")) {
113             XTag tag = doc.getTag("tjdo.field");
114             String JavaDoc ownerField = tag.getAttributeValue("owner-field");
115
116             if (ownerField != null) {
117                 extensions.add(new VendorExtension(getVendorName(), "owner-field", ownerField));
118             }
119             addSizeExtensions(extensions, tag, "element-", "");
120         }
121
122         return extensions;
123     }
124
125     protected Collection JavaDoc getArrayExtensions() throws XDocletException
126     {
127         Collection JavaDoc extensions = new ArrayList JavaDoc();
128
129         return extensions;
130     }
131
132     /**
133      * @return
134      * @exception XDocletException
135      */

136     protected Collection JavaDoc getMapExtensions() throws XDocletException
137     {
138         Collection JavaDoc extensions = new ArrayList JavaDoc();
139         XDoc doc = getCurrentField().getDoc();
140
141         if (doc.hasTag("tjdo.field")) {
142             XTag tag = doc.getTag("tjdo.field");
143             String JavaDoc ownerField = tag.getAttributeValue("owner-field");
144             String JavaDoc keyField = tag.getAttributeValue("key-field");
145
146             if (ownerField != null) {
147                 extensions.add(new VendorExtension(getVendorName(), "owner-field", ownerField));
148             }
149             if (keyField != null) {
150                 extensions.add(new VendorExtension(getVendorName(), "key-field", keyField));
151             }
152             addSizeExtensions(extensions, tag, "key-", "key-");
153
154             addSizeExtensions(extensions, tag, "value-", "value-");
155
156         }
157
158         return extensions;
159     }
160
161     protected void addSizeExtensions(Collection JavaDoc extensions, XTag tag, String JavaDoc sourcePrefix, String JavaDoc targetPrefix)
162     {
163         String JavaDoc length = tag.getAttributeValue(sourcePrefix + "length");
164         String JavaDoc precision = tag.getAttributeValue(sourcePrefix + "precision");
165         String JavaDoc scale = tag.getAttributeValue(sourcePrefix + "scale");
166
167         if (length != null) {
168             extensions.add(new VendorExtension(getVendorName(), targetPrefix + "length", length));
169         }
170         if (precision != null) {
171             extensions.add(new VendorExtension(getVendorName(), targetPrefix + "precision", precision));
172         }
173         if (scale != null) {
174             extensions.add(new VendorExtension(getVendorName(), targetPrefix + "scale", scale));
175         }
176
177     }
178
179     /**
180      * @created November 7, 2002
181      */

182     public static class TJDOVersionTypes extends org.apache.tools.ant.types.EnumeratedAttribute
183     {
184         public final static String JavaDoc VERSION_2_0 = "2.0";
185
186         /**
187          * Gets the Values attribute of the TJDOVersionTypes object
188          *
189          * @return The Values value
190          */

191         public String JavaDoc[] getValues()
192         {
193             return new String JavaDoc[]{VERSION_2_0};
194         }
195     }
196
197 }
198
Popular Tags