1 5 package xdoclet.modules.solarmetric.jdo; 6 7 import java.util.ArrayList ; 8 import java.util.Collection ; 9 import java.util.Iterator ; 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 29 public class KodoSubTask extends VendorExtensionsSubTask 30 { 31 32 private final static Log LOG = LogFactory.getLog(KodoSubTask.class); 33 34 private String version = KodoVersionTypes.VERSION_2_3; 35 36 41 public String getVersion() 42 { 43 return version; 44 } 45 46 50 public String getVendorName() 51 { 52 return "kodo"; 53 } 54 55 public String getVendorDescription() 56 { 57 return "KODO by SolarMetric"; 58 } 59 60 66 public void setVersion(KodoVersionTypes version) 67 { 68 this.version = version.getValue(); 69 } 70 71 76 protected Collection getClassExtensions() throws XDocletException 77 { 78 Collection extensions = new ArrayList (); 79 XDoc doc = getCurrentClass().getDoc(); 80 81 if (doc.hasTag(SQL_TABLE_TAG)) { 82 String 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 pkColumn = tag.getAttributeValue("pk-column"); 88 String lockColumn = tag.getAttributeValue("lock-column"); 89 String classColumn = tag.getAttributeValue("class-column"); 90 91 if (pkColumn != null) { 92 extensions.add(new VendorExtension(getVendorName(), "pk-column", pkColumn)); 93 94 String 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 117 protected Collection getFieldExtensions() throws XDocletException 118 { 119 Collection extensions = new ArrayList (); 120 XDoc doc = getCurrentField().getDoc(); 121 String collectionType = doc.getTagAttributeValue("jdo.field", "collection-type"); 122 123 if (doc.hasTag(SQL_RELATION_TAG)) { 124 if (collectionType == null) { 125 String style = doc.getTagAttributeValue(SQL_RELATION_TAG, STYLE_ATTR); 126 127 if (STYLE_FOREIGN_KEY_VALUE.equals(style)) { 128 Collection tags = doc.getTags(SQL_FIELD_TAG); 129 130 for (Iterator i = tags.iterator(); i.hasNext(); ) { 131 XTag tag = (XTag)i.next(); 132 String columnName = tag.getAttributeValue(COLUMN_NAME_ATTR); 133 String 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 []{SQL_RELATION_TAG, STYLE_ATTR, style, getVendorDescription()})); 142 } 143 } 144 else if ("collection".equals(collectionType) || "array".equals(collectionType)) { 145 String style = doc.getTagAttributeValue(SQL_RELATION_TAG, STYLE_ATTR); 146 147 if (STYLE_FOREIGN_KEY_VALUE.equals(style)) { 148 String 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 embeddedClassName = doc.getTagAttributeValue("jdo.field", "element-type"); 154 XClass embeddedClass = getXJavaDoc().getXClass(embeddedClassName); 155 String 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 relationTable = doc.getTagAttributeValue(SQL_RELATION_TAG, TABLE_NAME_ATTR); 161 162 extensions.add(new VendorExtension(getVendorName(), "table", relationTable)); 163 164 Collection tags = doc.getTags(SQL_FIELD_TAG); 165 166 for (Iterator i = tags.iterator(); i.hasNext(); ) { 167 XTag tag = (XTag)i.next(); 168 String columnName = tag.getAttributeValue(COLUMN_NAME_ATTR); 169 String relatedField = tag.getAttributeValue(RELATED_FIELD_ATTR); 170 171 extensions.add(new VendorExtension(getVendorName(), relatedField + "-ref-column", columnName)); 172 } 173 174 Collection targetTags = relatedDoc.getTags(SQL_FIELD_TAG); 175 176 for (Iterator i = targetTags.iterator(); i.hasNext(); ) { 177 XTag tag = (XTag)i.next(); 178 String columnName = tag.getAttributeValue(COLUMN_NAME_ATTR); 179 String 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 []{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 []{"jdo.field", "collection-type", collectionType, getVendorDescription()})); 194 } 195 196 } 197 else if (doc.hasTag(SQL_FIELD_TAG)) { 198 String tableName = doc.getTagAttributeValue(SQL_FIELD_TAG, TABLE_NAME_ATTR); 199 String 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 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 blob = tag.getAttributeValue("blob"); 218 String columnLength = tag.getAttributeValue("column-length"); 219 String columnIndex = tag.getAttributeValue("column-index"); 220 String ordered = tag.getAttributeValue("ordered"); 221 String orderColumn = tag.getAttributeValue("order-column"); 222 String 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 getCollectionExtensions() throws XDocletException 250 { 251 Collection extensions = new ArrayList (); 252 XDoc doc = getCurrentField().getDoc(); 253 254 return extensions; 255 } 256 257 protected Collection getArrayExtensions() throws XDocletException 258 { 259 Collection extensions = new ArrayList (); 260 261 return extensions; 262 } 263 264 269 protected Collection getMapExtensions() throws XDocletException 270 { 271 Collection extensions = new ArrayList (); 272 273 LOG.warn(Translator.getString(XDocletModulesJdoMessages.class, XDocletModulesJdoMessages.NOT_YET_SUPPORTED, 274 new String []{getVendorDescription()})); 275 276 return extensions; 277 } 278 279 283 public static class KodoVersionTypes extends org.apache.tools.ant.types.EnumeratedAttribute 284 { 285 public final static String VERSION_2_3 = "2.3"; 286 public final static String VERSION_2_3_1 = "2.3.1"; 287 public final static String VERSION_2_3_2 = "2.3.2"; 288 public final static String VERSION_2_3_3 = "2.3.3"; 289 290 295 public String [] getValues() 296 { 297 return new String []{VERSION_2_3, VERSION_2_3_1, VERSION_2_3_2, VERSION_2_3_3}; 298 } 299 } 300 301 } 302 | Popular Tags |