1 5 package xdoclet.modules.libelis.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 LidoSubTask extends VendorExtensionsSubTask 30 { 31 32 private final static Log LOG = LogFactory.getLog(LidoSubTask.class); 33 34 private String version = LidoVersionTypes.VERSION_1_3; 35 36 41 public String getVersion() 42 { 43 return version; 44 } 45 46 50 public String getVendorName() 51 { 52 return "libelis"; 53 } 54 55 public String getVendorDescription() 56 { 57 return "LIDO by Libelis"; 58 } 59 60 66 public void setVersion(LidoVersionTypes version) 67 { 68 this.version = version.getValue(); 69 } 70 71 protected Collection getClassExtensions() throws XDocletException 72 { 73 Collection extensions = new ArrayList (); 74 XDoc doc = getCurrentClass().getDoc(); 75 76 if (doc.hasTag(SQL_TABLE_TAG)) { 77 String sqlName = doc.getTagAttributeValue(SQL_TABLE_TAG, TABLE_NAME_ATTR); 78 79 extensions.add(new VendorExtension(getVendorName(), "sql-name", sqlName)); 80 } 81 return extensions; 82 } 83 84 protected Collection getFieldExtensions() throws XDocletException 85 { 86 Collection extensions = new ArrayList (); 87 XDoc doc = getCurrentField().getDoc(); 88 89 if (doc.hasTag(SQL_RELATION_TAG)) { 90 String style = doc.getTagAttributeValue(SQL_RELATION_TAG, STYLE_ATTR); 91 92 if (STYLE_FOREIGN_KEY_VALUE.equals(style)) { 93 if (doc.getTagAttributeValue("jdo.field", "collection-type") == null) { 94 Collection tags = doc.getTags(SQL_FIELD_TAG); 95 String sqlName = getSqlNames(tags.iterator()); 96 97 extensions.add(new VendorExtension(getVendorName(), "sql-name", sqlName)); 98 } 99 } 101 else if (STYLE_RELATION_TABLE_VALUE.equals(style)) { 102 String tableName = doc.getTagAttributeValue(SQL_RELATION_TAG, TABLE_NAME_ATTR); 103 104 extensions.add(new VendorExtension(getVendorName(), "sql-name", tableName)); 105 } 106 else { 107 LOG.warn(Translator.getString(XDocletModulesJdoMessages.class, XDocletModulesJdoMessages.NOT_SUPPORTED_TAG_ATTRIBUTE_VALUE, 108 new String []{SQL_RELATION_TAG, STYLE_ATTR, style, getVendorDescription()})); 109 } 110 111 } 112 else if (doc.hasTag(SQL_FIELD_TAG)) { 113 String tableName = doc.getTagAttributeValue(SQL_FIELD_TAG, TABLE_NAME_ATTR); 116 String sqlName = doc.getTagAttributeValue(SQL_FIELD_TAG, COLUMN_NAME_ATTR); 117 118 if (tableName != null && 119 !tableName.equals(doc.getTagAttributeValue(SQL_TABLE_TAG, TABLE_NAME_ATTR))) { 120 LOG.warn(Translator.getString(XDocletModulesJdoMessages.class, XDocletModulesJdoMessages.NOT_SUPPORTED_MULTIPLE_TABLE_MAPPING, 121 new String []{getVendorDescription()})); 122 } 123 extensions.add(new VendorExtension(getVendorName(), "sql-name", sqlName)); 124 } 125 return extensions; 126 } 127 128 protected Collection getCollectionExtensions() throws XDocletException 129 { 130 Collection extensions = new ArrayList (); 131 XDoc doc = getCurrentField().getDoc(); 132 133 if (doc.hasTag(SQL_RELATION_TAG)) { 134 String style = doc.getTagAttributeValue(SQL_RELATION_TAG, STYLE_ATTR); 135 136 if (STYLE_FOREIGN_KEY_VALUE.equals(style)) { 137 String relatedField = doc.getTagAttributeValue(SQL_RELATION_TAG, RELATED_FIELD_ATTR); 138 139 extensions.add(new VendorExtension(getVendorName(), "sql-reverse", "javaField:" + relatedField)); 140 } 141 else if (STYLE_RELATION_TABLE_VALUE.equals(style)) { 142 Collection tags = doc.getTags(SQL_FIELD_TAG); 143 String sqlName = getSqlNames(tags.iterator()); 144 145 extensions.add(new VendorExtension(getVendorName(), "sql-owner-name", sqlName)); 146 147 String embeddedClassName = doc.getTagAttributeValue("jdo.field", "element-type"); 148 XClass embeddedClass = getXJavaDoc().getXClass(embeddedClassName); 149 String relatedCollection = doc.getTagAttributeValue(SQL_RELATION_TAG, RELATED_FIELD_ATTR); 150 XDoc relatedDoc = embeddedClass.getField(relatedCollection).getDoc(); 151 Collection targetTags = relatedDoc.getTags(SQL_FIELD_TAG); 152 String targetSqlName = getSqlNames(targetTags.iterator()); 153 154 extensions.add(new VendorExtension(getVendorName(), "sql-value-name", targetSqlName)); 155 } 156 else { 157 LOG.warn(Translator.getString(XDocletModulesJdoMessages.class, XDocletModulesJdoMessages.NOT_SUPPORTED_TAG_ATTRIBUTE_VALUE, 158 new String []{SQL_RELATION_TAG, STYLE_ATTR, style, getVendorDescription()})); 159 } 160 161 } 162 return extensions; 163 } 164 165 protected Collection getArrayExtensions() throws XDocletException 166 { 167 Collection extensions = new ArrayList (); 168 169 LOG.warn(Translator.getString(XDocletModulesJdoMessages.class, XDocletModulesJdoMessages.NOT_SUPPORTED_ARRAY, 170 new String []{getVendorDescription()})); 171 172 return extensions; 173 } 174 175 protected Collection getMapExtensions() throws XDocletException 176 { 177 Collection extensions = new ArrayList (); 178 179 LOG.warn(Translator.getString(XDocletModulesJdoMessages.class, XDocletModulesJdoMessages.NOT_SUPPORTED_MAP, 180 new String []{getVendorDescription()})); 181 182 return extensions; 183 } 184 185 private String getSqlNames(Iterator i) 186 { 187 StringBuffer sqlNames = new StringBuffer (); 188 189 while (i.hasNext()) { 190 XTag tag = (XTag)i.next(); 191 String columnName = tag.getAttributeValue(COLUMN_NAME_ATTR); 192 String relatedField = tag.getAttributeValue(RELATED_FIELD_ATTR); 193 194 if (sqlNames.length() > 0) 195 sqlNames.append(", "); 196 sqlNames.append(relatedField + ":" + columnName); 197 } 198 return sqlNames.toString(); 199 } 200 201 205 public static class LidoVersionTypes extends org.apache.tools.ant.types.EnumeratedAttribute 206 { 207 public final static String VERSION_1_3 = "1.3"; 208 209 214 public String [] getValues() 215 { 216 return new String []{VERSION_1_3}; 217 } 218 } 219 220 } 221 | Popular Tags |