1 5 package xdoclet.modules.jboss.ejb; 6 7 import java.util.*; 8 import xjavadoc.*; 9 10 import xdoclet.XDocletException; 11 import xdoclet.modules.ejb.dd.RelationTagsHandler; 12 13 19 public class JBossRelationTagsHandler extends RelationTagsHandler 20 { 21 private String currentFKRelField = null; 22 private String currentFKCol = null; 23 private String currentJdbcType = null; 24 private String currentSqlType = null; 25 26 public String relationTableAttribute(Properties attributes) throws XDocletException 27 { 28 String attribute = null; 29 30 String paramName = attributes.getProperty("paramName"); 31 32 XMethod leftMethod = currentRelation.getLeftMethod(); 33 XMethod rightMethod = currentRelation.getRightMethod(); 34 35 attribute = leftMethod == null ? null : 36 leftMethod.getDoc().getTagAttributeValue("jboss.relation-table", paramName, false); 37 38 attribute = attribute != null ? attribute : rightMethod == null ? null : 39 rightMethod.getDoc().getTagAttributeValue("jboss.relation-table", paramName, false); 40 41 return attribute; 42 } 43 44 public void ifHasRelationTableAttribute(String template, Properties attributes) throws XDocletException 45 { 46 if (relationTableAttribute(attributes) != null) { 47 generate(template); 48 } 49 } 50 51 57 public void ifNotLeftHasFK(String template) throws XDocletException 58 { 59 if (!hasFK(true)) { 60 generate(template); 61 } 62 } 63 64 70 public void ifNotRightHasFK(String template) throws XDocletException 71 { 72 if (!hasFK(false)) { 73 generate(template); 74 } 75 } 76 77 83 public void ifLeftHasFK(String template) throws XDocletException 84 { 85 if (hasFK(true)) { 86 generate(template); 87 } 88 } 89 90 96 public void ifRightHasFK(String template) throws XDocletException 97 { 98 if (hasFK(false)) { 99 generate(template); 100 } 101 } 102 103 public void ifLeftHasReadAhead(String template) throws XDocletException 104 { 105 if (readAheadStrategy(true) != null) { 106 generate(template); 107 } 108 } 109 110 public void ifRightHasReadAhead(String template) throws XDocletException 111 { 112 if (readAheadStrategy(false) != null) { 113 generate(template); 114 } 115 } 116 117 public void ifLeftHasReadAheadPageSize(String template) throws XDocletException 118 { 119 if (readAheadPageSize(true) != null) { 120 generate(template); 121 } 122 } 123 124 public void ifRightHasReadAheadPageSize(String template) throws XDocletException 125 { 126 if (readAheadPageSize(false) != null) { 127 generate(template); 128 } 129 } 130 131 public void ifLeftHasReadAheadEagerLoadGroup(String template) throws XDocletException 132 { 133 if (readAheadEagerLoadGroup(true) != null) { 134 generate(template); 135 } 136 } 137 138 public void ifRightHasReadAheadEagerLoadGroup(String template) throws XDocletException 139 { 140 if (readAheadEagerLoadGroup(false) != null) { 141 generate(template); 142 } 143 } 144 145 151 public void forAllLeftForeignKeys(String template) throws XDocletException 152 { 153 forAllForeignKeys(template, true); 154 } 155 156 162 public void forAllRightForeignKeys(String template) throws XDocletException 163 { 164 forAllForeignKeys(template, false); 165 } 166 167 172 public String relatedPKField() 173 { 174 return currentFKRelField; 175 } 176 177 182 public String fkColumn() 183 { 184 return currentFKCol; 185 } 186 187 193 public void ifLeftHasFKConstraint(String template) throws XDocletException 194 { 195 if (hasFKConstraint(true)) { 196 generate(template); 197 } 198 } 199 200 206 public void ifRightHasFKConstraint(String template) throws XDocletException 207 { 208 if (hasFKConstraint(false)) { 209 generate(template); 210 } 211 } 212 213 219 public String leftFKConstraint() throws XDocletException 220 { 221 return fkConstraint(true); 222 } 223 224 230 public String rightFKConstraint() throws XDocletException 231 { 232 return fkConstraint(false); 233 } 234 235 public String leftReadAheadStrategy() throws XDocletException 236 { 237 return readAheadStrategy(true); 238 } 239 240 public String rightReadAheadStrategy() throws XDocletException 241 { 242 return readAheadStrategy(false); 243 } 244 245 public String leftReadAheadPageSize() throws XDocletException 246 { 247 return readAheadPageSize(true); 248 } 249 250 public String rightReadAheadPageSize() throws XDocletException 251 { 252 return readAheadPageSize(false); 253 } 254 255 public String leftReadAheadEagerLoadGroup() throws XDocletException 256 { 257 return readAheadEagerLoadGroup(true); 258 } 259 260 public String rightReadAheadEagerLoadGroup() throws XDocletException 261 { 262 return readAheadEagerLoadGroup(false); 263 } 264 265 public void ifIsRelationTableMapping(String template) throws XDocletException 266 { 267 if (isRelationTableMapping()) 268 generate(template); 269 } 270 271 public void ifNotIsRelationTableMapping(String template) throws XDocletException 272 { 273 if (!isRelationTableMapping()) 274 generate(template); 275 } 276 277 public void ifIsRightBatchCascadeDelete(String template) throws XDocletException 278 { 279 if (hasBatchCascadeDelete(false)) 280 generate(template); 281 } 282 283 public void ifIsLeftBatchCascadeDelete(String template) throws XDocletException 284 { 285 if (hasBatchCascadeDelete(true)) 286 generate(template); 287 } 288 289 290 public void ifIsForeignKeyMapping(String template) throws XDocletException 291 { 292 if (isForeignKeyMapping()) 293 generate(template); 294 } 295 296 public void ifNotIsForeignKeyMapping(String template) throws XDocletException 297 { 298 if (!isForeignKeyMapping()) 299 generate(template); 300 } 301 302 public void ifHasJdbcType(String template, Properties attributes) throws XDocletException 303 { 304 if (currentJdbcType != null) { 305 generate(template); 306 } 307 } 308 309 public String jdbcType() 310 { 311 return currentJdbcType; 312 } 313 314 315 public void ifHasSqlType(String template, Properties attributes) throws XDocletException 316 { 317 if (currentSqlType != null) { 318 generate(template); 319 } 320 } 321 322 public String sqlType() 323 { 324 return currentSqlType; 325 } 326 327 334 private boolean isRelationTableMapping() throws XDocletException 335 { 336 if (currentRelation.isMany2Many()) 337 return true; 338 if (currentRelation.getLeftMethod() != null) 339 if ("relation-table".equals(currentRelation.getLeftMethod().getDoc().getTagAttributeValue("jboss.relation-mapping", "style"))) 340 return true; 341 if (currentRelation.getRightMethod() != null) 342 if ("relation-table".equals(currentRelation.getRightMethod().getDoc().getTagAttributeValue("jboss.relation-mapping", "style"))) 343 return true; 344 345 return false; 346 } 347 348 355 private boolean isForeignKeyMapping() throws XDocletException 356 { 357 if (currentRelation.getLeftMethod() != null) 358 if ("foreign-key".equals(currentRelation.getLeftMethod().getDoc().getTagAttributeValue("jboss.relation-mapping", "style"))) 359 return true; 360 if (currentRelation.getRightMethod() != null) 361 if ("foreign-key".equals(currentRelation.getRightMethod().getDoc().getTagAttributeValue("jboss.relation-mapping", "style"))) 362 return true; 363 364 return false; 365 } 366 367 private String fkConstraint(boolean left) 368 { 369 XMethod methodA = null; 370 XMethod methodB = null; 371 372 if (left) { 373 methodA = currentRelation.getLeftMethod(); 374 methodB = currentRelation.getRightMethod(); 375 } 376 else { 377 methodA = currentRelation.getRightMethod(); 378 methodB = currentRelation.getLeftMethod(); 379 } 380 381 if (methodA != null) 382 return methodA.getDoc().getTagAttributeValue("jboss.relation", "fk-constraint"); 383 else 384 return methodB.getDoc().getTagAttributeValue("jboss.target-relation", "fk-constraint"); 385 } 386 387 private String readAheadStrategy(boolean left) 388 { 389 XMethod methodA = null; 390 XMethod methodB = null; 391 392 if (left) { 393 methodA = currentRelation.getLeftMethod(); 394 methodB = currentRelation.getRightMethod(); 395 } 396 else { 397 methodA = currentRelation.getRightMethod(); 398 methodB = currentRelation.getLeftMethod(); 399 } 400 401 if (methodA != null) 402 return methodA.getDoc().getTagAttributeValue("jboss.relation-read-ahead", "strategy"); 403 else 404 return methodB.getDoc().getTagAttributeValue("jboss.target-relation-read-ahead", "strategy"); 405 } 406 407 private String readAheadPageSize(boolean left) 408 { 409 XMethod methodA = null; 410 XMethod methodB = null; 411 412 if (left) { 413 methodA = currentRelation.getLeftMethod(); 414 methodB = currentRelation.getRightMethod(); 415 } 416 else { 417 methodA = currentRelation.getRightMethod(); 418 methodB = currentRelation.getLeftMethod(); 419 } 420 421 if (methodA != null) 422 return methodA.getDoc().getTagAttributeValue("jboss.relation-read-ahead", "page-size"); 423 else 424 return methodB.getDoc().getTagAttributeValue("jboss.target-relation-read-ahead", "page-size"); 425 } 426 427 private String readAheadEagerLoadGroup(boolean left) 428 { 429 XMethod methodA = null; 430 XMethod methodB = null; 431 432 if (left) { 433 methodA = currentRelation.getLeftMethod(); 434 methodB = currentRelation.getRightMethod(); 435 } 436 else { 437 methodA = currentRelation.getRightMethod(); 438 methodB = currentRelation.getLeftMethod(); 439 } 440 441 if (methodA != null) 442 return methodA.getDoc().getTagAttributeValue("jboss.relation-read-ahead", "eager-load-group"); 443 else 444 return methodB.getDoc().getTagAttributeValue("jboss.target-relation-read-ahead", "eager-load-group"); 445 } 446 447 453 private boolean hasFKConstraint(boolean left) 454 { 455 XMethod methodA = null; 456 XMethod methodB = null; 457 458 if (left) { 459 methodA = currentRelation.getLeftMethod(); 460 methodB = currentRelation.getRightMethod(); 461 } 462 else { 463 methodA = currentRelation.getRightMethod(); 464 methodB = currentRelation.getLeftMethod(); 465 } 466 467 if (methodA != null) 468 return methodA.getDoc().getTagAttributeValue("jboss.relation", "fk-constraint") != null; 469 else 470 return methodB.getDoc().getTagAttributeValue("jboss.target-relation", "fk-constraint") != null; 471 } 472 473 474 480 private boolean hasFK(boolean left) 481 { 482 XMethod methodA = null; 483 XMethod methodB = null; 484 485 if (left) { 486 methodA = currentRelation.getLeftMethod(); 487 methodB = currentRelation.getRightMethod(); 488 } 489 else { 490 methodA = currentRelation.getRightMethod(); 491 methodB = currentRelation.getLeftMethod(); 492 } 493 494 if (methodA != null) 495 return methodA.getDoc().hasTag("jboss.relation"); 496 else 497 return methodB.getDoc().hasTag("jboss.target-relation"); 498 } 499 500 506 private boolean hasBatchCascadeDelete(boolean left) 507 { 508 XMethod methodA = null; 509 XMethod methodB = null; 510 511 if (left) { 512 methodA = currentRelation.getLeftMethod(); 513 methodB = currentRelation.getRightMethod(); 514 } 515 else { 516 methodA = currentRelation.getRightMethod(); 517 methodB = currentRelation.getLeftMethod(); 518 } 519 520 if (methodA != null) 521 return methodA.getDoc().getTagAttributeValue("jboss.relation", "batch-cascade-delete") != null; 522 else 523 return methodB.getDoc().getTagAttributeValue("jboss.target-relation", "batch-cascade-delete") != null; 524 } 525 526 533 private void forAllForeignKeys(String template, boolean left) throws XDocletException 534 { 535 Collection fktags = null; 536 XMethod methodA = null; 537 XMethod methodB = null; 538 539 if (left) { 540 methodA = currentRelation.getLeftMethod(); 541 methodB = currentRelation.getRightMethod(); 542 } 543 else { 544 methodA = currentRelation.getRightMethod(); 545 methodB = currentRelation.getLeftMethod(); 546 } 547 548 if (methodA != null) 549 fktags = methodA.getDoc().getTags("jboss.relation"); 550 else 551 fktags = methodB.getDoc().getTags("jboss.target-relation"); 552 553 if (fktags == null) { 555 return; 556 } 557 558 for (Iterator i = fktags.iterator(); i.hasNext(); ) { 559 XTag fktag = (XTag) i.next(); 560 561 currentFKRelField = fktag.getAttributeValue("related-pk-field"); 562 currentFKCol = fktag.getAttributeValue("fk-column"); 563 currentJdbcType = fktag.getAttributeValue("jdbc-type"); 564 currentSqlType = fktag.getAttributeValue("sql-type"); 565 generate(template); 566 } 567 } 568 569 } 570 | Popular Tags |