KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > xdoclet > modules > solarmetric > jdo > KodoSubTask


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

5 package xdoclet.modules.solarmetric.jdo;
6
7 import java.util.ArrayList JavaDoc;
8 import java.util.Collection JavaDoc;
9 import java.util.Iterator JavaDoc;
10
11 import org.apache.commons.logging.Log;
12 import org.apache.commons.logging.LogFactory;
13
14 import xjavadoc.XClass;
15 import xjavadoc.XDoc;
16 import xjavadoc.XTag;
17 import xdoclet.XDocletException;
18 import xdoclet.modules.jdo.VendorExtension;
19 import xdoclet.modules.jdo.VendorExtensionsSubTask;
20 import xdoclet.modules.jdo.XDocletModulesJdoMessages;
21 import xdoclet.util.Translator;
22
23 /**
24  * @author Ludovic Claude (ludovicc@users.sourceforge.net)
25  * @created 10 October 2002
26  * @version $Revision: 1.3 $
27  * @ant.element display-name="Solarmetric Kodo support" name="kodo" parent="xdoclet.modules.jdo.JdoDocletTask"
28  */

29 public class KodoSubTask extends VendorExtensionsSubTask
30 {
31
32     private final static Log LOG = LogFactory.getLog(KodoSubTask.class);
33
34     private String JavaDoc version = KodoVersionTypes.VERSION_2_3;
35
36     /**
37      * Gets the Version attribute of the KodoSubTask object
38      *
39      * @return The Version value
40      */

41     public String JavaDoc getVersion()
42     {
43         return version;
44     }
45
46     /**
47      * @return
48      * @see xdoclet.modules.jdo.VendorExtensionsSubTask#getVendorName()
49      */

50     public String JavaDoc getVendorName()
51     {
52         return "kodo";
53     }
54
55     public String JavaDoc getVendorDescription()
56     {
57         return "KODO by SolarMetric";
58     }
59
60     /**
61      * The version of Kodo. Supported versions are 2.3.
62      *
63      * @param version The new Version value
64      * @ant.not-required No, default is "2.3".
65      */

66     public void setVersion(KodoVersionTypes version)
67     {
68         this.version = version.getValue();
69     }
70
71     /**
72      * @return
73      * @exception XDocletException
74      * @todo lock-column is likely to be standardizable
75      */

76     protected Collection JavaDoc getClassExtensions() throws XDocletException
77     {
78         Collection JavaDoc extensions = new ArrayList JavaDoc();
79         XDoc doc = getCurrentClass().getDoc();
80
81         if (doc.hasTag(SQL_TABLE_TAG)) {
82             String JavaDoc sqlName = doc.getTagAttributeValue(SQL_TABLE_TAG, TABLE_NAME_ATTR);
83
84             extensions.add(new VendorExtension(getVendorName(), "table", sqlName));
85             if (doc.hasTag("kodo.table")) {
86                 XTag tag = doc.getTag("kodo.table");
87                 String JavaDoc pkColumn = tag.getAttributeValue("pk-column");
88                 String JavaDoc lockColumn = tag.getAttributeValue("lock-column");
89                 String JavaDoc classColumn = tag.getAttributeValue("class-column");
90
91                 if (pkColumn != null) {
92                     extensions.add(new VendorExtension(getVendorName(), "pk-column", pkColumn));
93
94                     String JavaDoc identity = doc.getTagAttributeValue("jdo.persistence-capable", "identity-type");
95
96                     if (identity == null || "datastore".equals(identity)) {
97                         LOG.warn(Translator.getString(XDocletModulesSolarmetricMessages.class,
98                             XDocletModulesSolarmetricMessages.NOT_SUPPORTED_PK_COLUMN_AND_DATASTORE_IDENTITY));
99                     }
100                 }
101                 if (lockColumn != null) {
102                     extensions.add(new VendorExtension(getVendorName(), "lock-column", lockColumn));
103                 }
104                 if (classColumn != null) {
105                     extensions.add(new VendorExtension(getVendorName(), "class-column", classColumn));
106                 }
107             }
108         }
109         return extensions;
110     }
111
112     /**
113      * @return
114      * @exception XDocletException
115      * @todo column-length is likely to be standardizable
116      */

117     protected Collection JavaDoc getFieldExtensions() throws XDocletException
118     {
119         Collection JavaDoc extensions = new ArrayList JavaDoc();
120         XDoc doc = getCurrentField().getDoc();
121         String JavaDoc collectionType = doc.getTagAttributeValue("jdo.field", "collection-type");
122
123         if (doc.hasTag(SQL_RELATION_TAG)) {
124             if (collectionType == null) {
125                 String JavaDoc style = doc.getTagAttributeValue(SQL_RELATION_TAG, STYLE_ATTR);
126
127                 if (STYLE_FOREIGN_KEY_VALUE.equals(style)) {
128                     Collection JavaDoc tags = doc.getTags(SQL_FIELD_TAG);
129
130                     for (Iterator JavaDoc i = tags.iterator(); i.hasNext(); ) {
131                         XTag tag = (XTag)i.next();
132                         String JavaDoc columnName = tag.getAttributeValue(COLUMN_NAME_ATTR);
133                         String JavaDoc relatedField = tag.getAttributeValue(RELATED_FIELD_ATTR);
134
135                         extensions.add(new VendorExtension(getVendorName(), relatedField + "-data-column", columnName));
136                     }
137                 }
138                 else {
139                     LOG.warn(Translator.getString(XDocletModulesJdoMessages.class,
140                         XDocletModulesJdoMessages.NOT_SUPPORTED_TAG_ATTRIBUTE_VALUE,
141                         new String JavaDoc[]{SQL_RELATION_TAG, STYLE_ATTR, style, getVendorDescription()}));
142                 }
143             }
144             else if ("collection".equals(collectionType) || "array".equals(collectionType)) {
145                 String JavaDoc style = doc.getTagAttributeValue(SQL_RELATION_TAG, STYLE_ATTR);
146
147                 if (STYLE_FOREIGN_KEY_VALUE.equals(style)) {
148                     String JavaDoc relatedField = doc.getTagAttributeValue(SQL_RELATION_TAG, RELATED_FIELD_ATTR);
149
150                     extensions.add(new VendorExtension(getVendorName(), "inverse", relatedField));
151                 }
152                 else if (STYLE_RELATION_TABLE_VALUE.equals(style)) {
153                     String JavaDoc embeddedClassName = doc.getTagAttributeValue("jdo.field", "element-type");
154                     XClass embeddedClass = getXJavaDoc().getXClass(embeddedClassName);
155                     String JavaDoc relatedCollection = doc.getTagAttributeValue(SQL_RELATION_TAG, RELATED_FIELD_ATTR);
156                     XDoc relatedDoc = embeddedClass.getField(relatedCollection).getDoc();
157
158                     extensions.add(new VendorExtension(getVendorName(), "inverse", relatedCollection));
159
160                     String JavaDoc relationTable = doc.getTagAttributeValue(SQL_RELATION_TAG, TABLE_NAME_ATTR);
161
162                     extensions.add(new VendorExtension(getVendorName(), "table", relationTable));
163
164                     Collection JavaDoc tags = doc.getTags(SQL_FIELD_TAG);
165
166                     for (Iterator JavaDoc i = tags.iterator(); i.hasNext(); ) {
167                         XTag tag = (XTag)i.next();
168                         String JavaDoc columnName = tag.getAttributeValue(COLUMN_NAME_ATTR);
169                         String JavaDoc relatedField = tag.getAttributeValue(RELATED_FIELD_ATTR);
170
171                         extensions.add(new VendorExtension(getVendorName(), relatedField + "-ref-column", columnName));
172                     }
173
174                     Collection JavaDoc targetTags = relatedDoc.getTags(SQL_FIELD_TAG);
175
176                     for (Iterator JavaDoc i = targetTags.iterator(); i.hasNext(); ) {
177                         XTag tag = (XTag)i.next();
178                         String JavaDoc columnName = tag.getAttributeValue(COLUMN_NAME_ATTR);
179                         String JavaDoc relatedField = tag.getAttributeValue(RELATED_FIELD_ATTR);
180
181                         extensions.add(new VendorExtension(getVendorName(), relatedField + "-data-column", columnName));
182                     }
183                 }
184                 else {
185                     LOG.warn(Translator.getString(XDocletModulesJdoMessages.class,
186                         XDocletModulesJdoMessages.NOT_SUPPORTED_TAG_ATTRIBUTE_VALUE,
187                         new String JavaDoc[]{SQL_RELATION_TAG, STYLE_ATTR, style, getVendorDescription()}));
188                 }
189             }
190             else {
191                 LOG.warn(Translator.getString(XDocletModulesJdoMessages.class,
192                     XDocletModulesJdoMessages.NOT_SUPPORTED_TAG_ATTRIBUTE_VALUE,
193                     new String JavaDoc[]{"jdo.field", "collection-type", collectionType, getVendorDescription()}));
194             }
195
196         }
197         else if (doc.hasTag(SQL_FIELD_TAG)) {
198             String JavaDoc tableName = doc.getTagAttributeValue(SQL_FIELD_TAG, TABLE_NAME_ATTR);
199             String JavaDoc columnName = doc.getTagAttributeValue(SQL_FIELD_TAG, COLUMN_NAME_ATTR);
200
201             if ("true".equals(doc.getTagAttributeValue("jdo.field", "primary-key"))) {
202                 XDoc classDoc = getCurrentClass().getDoc();
203                 String JavaDoc identity = classDoc.getTagAttributeValue("jdo.persistence-capable", "identity-type");
204
205                 if (identity == null || "datastore".equals(identity)) {
206                     LOG.warn(Translator.getString(XDocletModulesSolarmetricMessages.class,
207                         XDocletModulesSolarmetricMessages.NOT_SUPPORTED_PK_FIELD_AND_DATASTORE_IDENTITY));
208                 }
209             }
210             if (tableName != null) {
211                 extensions.add(new VendorExtension(getVendorName(), "table", tableName));
212             }
213             extensions.add(new VendorExtension(getVendorName(), "data-column", columnName));
214
215             if (doc.hasTag("kodo.field")) {
216                 XTag tag = doc.getTag("kodo.field");
217                 String JavaDoc blob = tag.getAttributeValue("blob");
218                 String JavaDoc columnLength = tag.getAttributeValue("column-length");
219                 String JavaDoc columnIndex = tag.getAttributeValue("column-index");
220                 String JavaDoc ordered = tag.getAttributeValue("ordered");
221                 String JavaDoc orderColumn = tag.getAttributeValue("order-column");
222                 String JavaDoc readOnly = tag.getAttributeValue("read-only");
223
224                 if (blob != null) {
225                     extensions.add(new VendorExtension(getVendorName(), "blob", blob));
226                 }
227                 if (columnLength != null) {
228                     extensions.add(new VendorExtension(getVendorName(), "column-length", columnLength));
229                 }
230                 if (columnIndex != null) {
231                     extensions.add(new VendorExtension(getVendorName(), "column-index", columnIndex));
232                 }
233                 if (ordered != null) {
234                     extensions.add(new VendorExtension(getVendorName(), "ordered", ordered));
235                 }
236                 if (orderColumn != null) {
237                     extensions.add(new VendorExtension(getVendorName(), "order-column", orderColumn));
238                 }
239                 if (readOnly != null) {
240                     extensions.add(new VendorExtension(getVendorName(), "read-only", readOnly));
241                 }
242             }
243
244         }
245
246         return extensions;
247     }
248
249     protected Collection JavaDoc getCollectionExtensions() throws XDocletException
250     {
251         Collection JavaDoc extensions = new ArrayList JavaDoc();
252         XDoc doc = getCurrentField().getDoc();
253
254         return extensions;
255     }
256
257     protected Collection JavaDoc getArrayExtensions() throws XDocletException
258     {
259         Collection JavaDoc extensions = new ArrayList JavaDoc();
260
261         return extensions;
262     }
263
264     /**
265      * @return
266      * @exception XDocletException
267      * @todo Kodo actually supports the maps, need to implement it here
268      */

269     protected Collection JavaDoc getMapExtensions() throws XDocletException
270     {
271         Collection JavaDoc extensions = new ArrayList JavaDoc();
272
273         LOG.warn(Translator.getString(XDocletModulesJdoMessages.class, XDocletModulesJdoMessages.NOT_YET_SUPPORTED,
274             new String JavaDoc[]{getVendorDescription()}));
275
276         return extensions;
277     }
278
279     /**
280      * @author Ludovic Claude (ludovicc@users.sourceforge.net)
281      * @created 10 October 2002
282      */

283     public static class KodoVersionTypes extends org.apache.tools.ant.types.EnumeratedAttribute
284     {
285         public final static String JavaDoc VERSION_2_3 = "2.3";
286         public final static String JavaDoc VERSION_2_3_1 = "2.3.1";
287         public final static String JavaDoc VERSION_2_3_2 = "2.3.2";
288         public final static String JavaDoc VERSION_2_3_3 = "2.3.3";
289
290         /**
291          * Gets the Values attribute of the KodoVersionTypes object
292          *
293          * @return The Values value
294          */

295         public String JavaDoc[] getValues()
296         {
297             return new String JavaDoc[]{VERSION_2_3, VERSION_2_3_1, VERSION_2_3_2, VERSION_2_3_3};
298         }
299     }
300
301 }
302
Popular Tags