* @todo column-length is likely to be standardizable
*/
protected Collection getFieldExtensions() throws XDocletException
{
Collection extensions = new ArrayList();
XDoc doc = getCurrentField().getDoc();
String collectionType = doc.getTagAttributeValue("jdo.field", "collection-type");
if (doc.hasTag(SQL_RELATION_TAG)) {
if (collectionType == null) {
String style = doc.getTagAttributeValue(SQL_RELATION_TAG, STYLE_ATTR);
if (STYLE_FOREIGN_KEY_VALUE.equals(style)) {
Collection tags = doc.getTags(SQL_FIELD_TAG);
for (Iterator i = tags.iterator(); i.hasNext(); ) {
XTag tag = (XTag)i.next();
String columnName = tag.getAttributeValue(COLUMN_NAME_ATTR);
String relatedField = tag.getAttributeValue(RELATED_FIELD_ATTR);
extensions.add(new VendorExtension(getVendorName(), relatedField + "-data-column", columnName));
}
}
else {
LOG.warn(Translator.getString(XDocletModulesJdoMessages.class,
XDocletModulesJdoMessages.NOT_SUPPORTED_TAG_ATTRIBUTE_VALUE,
new String[]{SQL_RELATION_TAG, STYLE_ATTR, style, getVendorDescription()}));
}
}
else if ("collection".equals(collectionType) || "array".equals(collectionType)) {
String style = doc.getTagAttributeValue(SQL_RELATION_TAG, STYLE_ATTR);
if (STYLE_FOREIGN_KEY_VALUE.equals(style)) {
String relatedField = doc.getTagAttributeValue(SQL_RELATION_TAG, RELATED_FIELD_ATTR);
extensions.add(new VendorExtension(getVendorName(), "inverse", relatedField));
}
else if (STYLE_RELATION_TABLE_VALUE.equals(style)) {
String embeddedClassName = doc.getTagAttributeValue("jdo.field", "element-type");
XClass embeddedClass = getXJavaDoc().getXClass(embeddedClassName);
String relatedCollection = doc.getTagAttributeValue(SQL_RELATION_TAG, RELATED_FIELD_ATTR);
XDoc relatedDoc = embeddedClass.getField(relatedCollection).getDoc();
extensions.add(new VendorExtension(getVendorName(), "inverse", relatedCollection));
String relationTable = doc.getTagAttributeValue(SQL_RELATION_TAG, TABLE_NAME_ATTR);
extensions.add(new VendorExtension(getVendorName(), "table", relationTable));
Collection tags = doc.getTags(SQL_FIELD_TAG);
for (Iterator i = tags.iterator(); i.hasNext(); ) {
XTag tag = (XTag)i.next();
String columnName = tag.getAttributeValue(COLUMN_NAME_ATTR);
String relatedField = tag.getAttributeValue(RELATED_FIELD_ATTR);
extensions.add(new VendorExtension(getVendorName(), relatedField + "-ref-column", columnName));
}
Collection targetTags = relatedDoc.getTags(SQL_FIELD_TAG);
for (Iterator i = targetTags.iterator(); i.hasNext(); ) {
XTag tag = (XTag)i.next();
String columnName = tag.getAttributeValue(COLUMN_NAME_ATTR);
String relatedField = tag.getAttributeValue(RELATED_FIELD_ATTR);
extensions.add(new VendorExtension(getVendorName(), relatedField + "-data-column", columnName));
}
}
else {
LOG.warn(Translator.getString(XDocletModulesJdoMessages.class,
XDocletModulesJdoMessages.NOT_SUPPORTED_TAG_ATTRIBUTE_VALUE,
new String[]{SQL_RELATION_TAG, STYLE_ATTR, style, getVendorDescription()}));
}
}
else {
LOG.warn(Translator.getString(XDocletModulesJdoMessages.class,
XDocletModulesJdoMessages.NOT_SUPPORTED_TAG_ATTRIBUTE_VALUE,
new String[]{"jdo.field", "collection-type", collectionType, getVendorDescription()}));
}
}
else if (doc.hasTag(SQL_FIELD_TAG)) {
String tableName = doc.getTagAttributeValue(SQL_FIELD_TAG, TABLE_NAME_ATTR);
String columnName = doc.getTagAttributeValue(SQL_FIELD_TAG, COLUMN_NAME_ATTR);
if ("true".equals(doc.getTagAttributeValue("jdo.field", "primary-key"))) {
XDoc classDoc = getCurrentClass().getDoc();
String identity = classDoc.getTagAttributeValue("jdo.persistence-capable", "identity-type");
if (identity == null || "datastore".equals(identity)) {
LOG.warn(Translator.getString(XDocletModulesSolarmetricMessages.class,
XDocletModulesSolarmetricMessages.NOT_SUPPORTED_PK_FIELD_AND_DATASTORE_IDENTITY));
}