1 5 package xdoclet.modules.bea.wls.ejb; 6 7 import java.util.*; 8 9 import xjavadoc.*; 10 import xdoclet.XDocletException; 11 import xdoclet.modules.ejb.EjbTagsHandler; 12 import xdoclet.modules.ejb.dd.RelationTagsHandler; 13 14 import xdoclet.util.Translator; 15 16 24 public class WeblogicRelationTagsHandler extends RelationTagsHandler 25 { 26 private Collection columnMapTags = null; 27 private Iterator columnMapTagIterator = null; 28 private XClass pkClass; 29 private String currentKeyColumn = null; 30 private String currentForeignKeyColumn = null; 31 32 39 public void forAllColumnMaps(String template, boolean left) throws XDocletException 40 { 41 XMethod methodA; 42 XMethod methodB; 43 XClass classA; 44 XClass classB; 45 46 if (left) { 47 methodA = currentRelation.getLeftMethod(); 48 methodB = currentRelation.getRightMethod(); 49 classA = currentRelation.getLeft(); 50 classB = currentRelation.getRight(); 51 } 52 else { 53 methodA = currentRelation.getRightMethod(); 54 methodB = currentRelation.getLeftMethod(); 55 classA = currentRelation.getRight(); 56 classB = currentRelation.getLeft(); 57 } 58 59 if (methodA != null) { 60 columnMapTags = methodA.getDoc().getTags("weblogic.column-map"); 62 63 columnMapTagIterator = columnMapTags.iterator(); 64 pkClass = classB; 65 if (pkClass == null) { 66 pkClass = EjbTagsHandler.getEjb(methodA.getDoc().getTagAttributeValue("ejb.relation", "target-ejb")); 67 } 68 if (columnMapTags.size() == 0) { 69 } 71 } 72 else { 73 columnMapTags = methodB.getDoc().getTags("weblogic:target-column-map"); 75 76 columnMapTagIterator = columnMapTags.iterator(); 77 pkClass = classB; 78 if (columnMapTags.size() == 0) { 79 } 81 } 82 83 while (columnMapTagIterator.hasNext()) { 84 XTag columnMapTag = (XTag) columnMapTagIterator.next(); 85 86 currentKeyColumn = columnMapTag.getAttributeValue("key-column"); 87 currentForeignKeyColumn = columnMapTag.getAttributeValue("foreign-key-column"); 88 generate(template); 89 } 90 } 91 92 public void forAllLeftColumnMaps(String template) throws XDocletException 93 { 94 forAllColumnMaps(template, true); 95 } 96 97 103 public void forAllRightColumnMaps(String template) throws XDocletException 104 { 105 forAllColumnMaps(template, false); 106 } 107 108 111 public void ensureColumnMapTagsRight() 112 { 113 boolean rightHasTargetColumnMapTags = false; 114 boolean leftHasColumnMapTags = false; 115 116 if (currentRelation.getLeftMethod() != null) { 117 rightHasTargetColumnMapTags = currentRelation.getLeftMethod().getDoc().getTags("weblogic.target-column-map").size() != 0; 118 } 119 if (currentRelation.getRightMethod() != null) { 120 leftHasColumnMapTags = currentRelation.getRightMethod().getDoc().getTags("weblogic.column-map").size() != 0; 121 } 122 if (rightHasTargetColumnMapTags || leftHasColumnMapTags) { 123 currentRelation.swap(); 124 } 125 } 126 127 133 public String joinTableName() throws XDocletException 134 { 135 String leftJoinTableName = currentRelation.getLeftMethod().getDoc().getTagAttributeValue("weblogic:relation", "join-table-name", false); 137 String joinTableName = leftJoinTableName; 138 String rightJoinTableName = null; 139 140 if (leftJoinTableName == null && currentRelation.getRightMethod() != null) { 142 rightJoinTableName = currentRelation.getRightMethod().getDoc().getTagAttributeValue("weblogic:relation", "join-table-name", false); 143 joinTableName = rightJoinTableName; 144 } 145 if (leftJoinTableName != null && rightJoinTableName != null) { 146 throw new XDocletException(Translator.getString(XDocletModulesBeaWlsEjbMessages.class, XDocletModulesBeaWlsEjbMessages.JOIN_TABLE_NAME_ONLY_ONE_SIDE)); 147 } 148 if (leftJoinTableName == null && rightJoinTableName == null) { 149 throw new XDocletException(Translator.getString(XDocletModulesBeaWlsEjbMessages.class, XDocletModulesBeaWlsEjbMessages.JOIN_TABLE_NAME_NEEDED, new String []{relationName()})); 150 } 151 return joinTableName; 152 } 153 154 160 public String leftGroupName() throws XDocletException 161 { 162 if (currentRelation.getLeftMethod() != null) { 163 return currentRelation.getLeftMethod().getDoc().getTagAttributeValue("weblogic:relation", "group-name", false); 164 } 165 else { 166 return null; 167 } 168 } 169 170 176 public void ifHasLeftGroupName(String template) throws XDocletException 177 { 178 if (leftGroupName() != null) { 179 generate(template); 180 } 181 } 182 183 189 public String rightGroupName() throws XDocletException 190 { 191 String groupName = null; 192 193 if (currentRelation.getRightMethod() != null) { 194 groupName = currentRelation.getRightMethod().getDoc().getTagAttributeValue("weblogic:relation", "group-name", false); 196 } 197 else { 198 groupName = currentRelation.getLeftMethod().getDoc().getTagAttributeValue("weblogic:relation", "group-name", false); 200 } 201 return groupName; 202 } 203 204 210 public void ifHasRightGroupName(String template) throws XDocletException 211 { 212 if (rightGroupName() != null) { 213 generate(template); 214 } 215 } 216 217 223 public void ifHasKeyColumn(String template) throws XDocletException 224 { 225 if (keyColumn() != null) { 226 generate(template); 227 } 228 } 229 230 236 public String keyColumn() throws XDocletException 237 { 238 if (currentKeyColumn == null) { 239 if (columnMapTags.size() > 1) { 241 throw new XDocletException(Translator.getString(XDocletModulesBeaWlsEjbMessages.class, XDocletModulesBeaWlsEjbMessages.CANT_GUESS_PK_FIELD)); 242 } 243 244 Collection methods = pkClass.getMethods(); 245 246 for (Iterator i = methods.iterator(); i.hasNext(); ) { 247 XMethod method = (XMethod) i.next(); 248 boolean isPk = method.getDoc().getTag("ejb.pk-field") != null; 249 String tmpKeyColumn = method.getDoc().getTagAttributeValue("ejb.persistence", "column-name"); 250 251 if (isPk) { 253 if (currentKeyColumn != null) { 254 throw new XDocletException(Translator.getString(XDocletModulesBeaWlsEjbMessages.class, XDocletModulesBeaWlsEjbMessages.MORE_THAN_ONE_PK_FIELD, new String []{pkClass.getQualifiedName()})); 255 } 256 else { 257 currentKeyColumn = tmpKeyColumn; 258 } 259 } 260 } 261 if (currentKeyColumn == null) { 262 throw new XDocletException(Translator.getString(XDocletModulesBeaWlsEjbMessages.class, XDocletModulesBeaWlsEjbMessages.NO_PK_FIELD, new String []{pkClass.getQualifiedName()})); 263 } 264 } 265 return currentKeyColumn; 266 } 267 268 273 public String foreignKeyColumn() 274 { 275 return currentForeignKeyColumn; 276 } 277 } 278 | Popular Tags |