1 23 24 30 package org.enhydra.dods.xslt; 31 32 import java.io.*; 33 import java.util.*; 34 import org.enhydra.dods.Common; 35 36 41 public class DODSTag { 42 protected DODSTag() {} 43 44 53 static public String superLoadData(String className) throws Exception { 54 if (-1 != className.indexOf("GenericDO")) { 55 return new String (""); 56 } else { 57 return new String ("super.loadData();"); 58 } 59 } 60 static final String defaultStringLength = "32"; 61 62 74 static public String declMaxLength(String name, String size, String dbtype, String type) throws Exception { 75 String valueMaxLength = ""; 76 String declMaxLength = ""; 77 78 if (type.equals("String")) { 79 if (dbtype.equals("LONGVARCHAR")) { 80 valueMaxLength = size = "0"; 81 } else { 82 if (null == size || 0 == size.length()) { 83 size = defaultStringLength; 84 } 85 valueMaxLength = name + "_MaxLength"; 86 declMaxLength = "static public final int " + valueMaxLength 87 + " = " + size + ";"; 88 } 89 } 90 return declMaxLength; 91 } 92 93 105 static public String markNewValueExtras(String name, String dbtype, String type, String canBeeNull) throws Exception { 106 String valueMaxLength = ""; 107 String markNewValue_extraParms = ""; 108 109 if (type.equals("String")) { 110 if (dbtype.equals("LONGVARCHAR")) { 111 valueMaxLength = "0"; 112 } else { 113 valueMaxLength = name + "_MaxLength"; 114 } 115 markNewValue_extraParms = ", 0, " + valueMaxLength + ", " 116 + canBeeNull; 117 } 118 return markNewValue_extraParms; 119 } 120 121 133 static public String bigDecimalScale(String type, String size, String objRef, String foreignKey) throws Exception { 134 String bigDecimalScale = ""; 135 136 if (type.equals("java.math.BigDecimal")) { 137 if (null == size || 0 == size.length()) { 138 bigDecimalScale = ", 0"; 139 } else { 140 bigDecimalScale = ", " + size; 141 } 142 } 143 144 if (objRef.equals("true")) { 145 if (foreignKey.equals("false")) { 146 bigDecimalScale = ", 0"; 147 } 148 } 149 return bigDecimalScale; 150 } 151 152 164 static public String arrayQueryName(String objName, String pack, String name, String isArray) throws Exception { 165 String arrayQueryName = ""; 166 167 if (isArray.equals("true")) { 168 arrayQueryName = pack + "." + objName + "_" + name + "Query"; 169 } 170 return arrayQueryName; 171 } 172 173 184 static public String arrayDOName(String objName, String name, String isArray) throws Exception { 185 String arrayDOName = ""; 186 187 if (isArray.equals("true")) { 188 arrayDOName = objName + "_" + name + "DO"; 189 } 190 return arrayDOName; 191 } 192 public static Vector columnNamesVect; 193 public static Vector primaryKeysVect; 194 public static Vector refsN21Vect; 195 public static Vector refAttrs; 196 197 202 static public void initColumn() throws Exception { 203 columnNamesVect = new Vector(); 204 primaryKeysVect = new Vector(); 205 refsN21Vect = new Vector(); 206 fKGroupedByRefDO = new Hashtable(); 207 } 208 209 221 static public void addColumnName(String name, String isPrimaryKey, String isObjRef, String isUsedForQuery, String isForeignKey, String objRefDOisAbstract) throws Exception { 222 columnNamesVect.add(name); 223 if (isPrimaryKey.equals("true")) { 224 primaryKeysVect.add(name); 225 } 226 } 227 228 233 static public void initRefererr() throws Exception { 234 refsN21Vect = new Vector(); 235 } 236 237 247 static public void addRefAttr(String name, String do_name, String classPackage, String className) throws Exception { 248 if (do_name.equals((classPackage + "." + className))) { 249 String [] pair = new String [2]; 250 251 pair[0] = name; 252 pair[1] = do_name; 253 refsN21Vect.add(pair); 254 } 255 } 256 257 264 static public String insertColumnNames() throws Exception { 265 String sql_insert_column_names = ""; 266 String comma = ""; 267 int i; 268 269 for (i = 0; i < columnNamesVect.size(); i++) { 270 sql_insert_column_names += comma + columnNamesVect.elementAt(i); 271 comma = ", "; 272 } 273 if (0 == primaryKeysVect.size()) { 274 sql_insert_column_names += ", \" + get_OIdColumnName() + \", \" + get_versionColumnName() + \""; 275 } 276 return sql_insert_column_names; 277 } 278 279 286 static public String insertQuestionMarks() throws Exception { 287 String sql_insert_question_marks = ""; 288 String comma = ""; 289 290 if (0 == primaryKeysVect.size()) { 291 sql_insert_question_marks = "?, ?, "; 292 } int i; 294 295 for (i = 0; i < columnNamesVect.size(); i++) { 296 sql_insert_question_marks += comma + "?"; 297 comma = ", "; 298 } 299 return sql_insert_question_marks; 300 } 301 302 309 static public String updateWhereClause() throws Exception { 310 String updateWhereClauseString = "\" + get_OIdColumnName() + \" = ? and \" + get_versionColumnName() + \" = ?"; 311 312 321 return updateWhereClauseString; 322 } 323 324 331 static public String updateQualQuestionMarks() throws Exception { 332 String sql_update_question_marks = ""; 333 String comma = ""; 334 int i; 335 336 for (i = 0; i < columnNamesVect.size(); i++) { 337 sql_update_question_marks += comma + columnNamesVect.elementAt(i) 338 + " = ?"; 339 comma = ", "; 340 } 341 return sql_update_question_marks; 342 } 343 344 354 static public String memberRemarks(String isForeignKey, String isPrimaryKey) throws Exception { 355 String memberRemarks = ""; 356 357 if (isForeignKey.equals("true")) { 358 memberRemarks += "(FK)"; 359 } 360 if (isPrimaryKey.equals("true")) { 361 memberRemarks += "(PK)"; 362 } 363 return memberRemarks; 364 } 365 366 377 static public String dumpMethod(String name, String isObjRef, String isForeignKey) throws Exception { 378 String dumpMethod = ""; 379 380 if (isObjRef.equals("true") && isForeignKey.equals("false")) { 381 dumpMethod = "( null == data." + name + " ? null " + " : data." 382 + name + ".toString( indentCount + 1 ) )"; 383 } else { 384 dumpMethod = "data." + name; 385 } 386 return dumpMethod; 387 } 388 389 402 static public String dumpMethod1(String name, String isObjRef, String isForeignKey) throws Exception { 403 String dumpMethod = ""; 404 405 name = name.toUpperCase(java.util.Locale.ENGLISH).substring(0, 1).concat(name.substring(1)); 406 if (isObjRef.equals("true") && isForeignKey.equals("false")) { 407 dumpMethod = " ( null == get_DataStruct().get" + name + "() ? null " 408 + " : get_DataStruct().get" + name + "().get_OId())"; 409 } else { 410 dumpMethod = "get_DataStruct().get" + name + "()"; 411 } 412 return dumpMethod; 413 } 414 415 425 static public String getArrayDO(String DOName, String attrName) throws Exception { 426 String get_array_DO = "get" + DOName + "DOArray"; 427 428 if (1 < refsN21Vect.size()) { 429 get_array_DO += "_" + attrName; 430 } 431 return get_array_DO; 432 } 433 434 443 static public String getDoName(String fullname) throws Exception { 444 String doName = fullname.substring(fullname.lastIndexOf('.') + 1); 445 446 return doName; 447 } 448 449 459 static public String getArrayDON2N(String name2, String name) throws Exception { 460 String get_array_DO = "get" + name2 + "DOArray_via_" + name; 461 462 return get_array_DO; 463 } 464 465 475 static public String getSingleDO(String DOName, String attrName) throws Exception { 476 String get_single_DO = "get" + DOName + "DO"; 477 478 if (1 < refsN21Vect.size()) { 479 get_single_DO += "_" + attrName; 480 } 481 return get_single_DO; 482 } 483 484 494 static public String addSingleDO(String DOName, String attrName) throws Exception { 495 String add_single_DO = "add" + DOName + "DO"; 496 497 if (1 < refsN21Vect.size()) { 498 add_single_DO += "_" + attrName; 499 } 500 return add_single_DO; 501 } 502 503 513 static public String removeSingleDO(String DOName, String attrName) throws Exception { 514 String remove_single_DO = "remove" + DOName + "DO"; 515 516 if (1 < refsN21Vect.size()) { 517 remove_single_DO += "_" + attrName; 518 } 519 return remove_single_DO; 520 } 521 522 533 static public String compareReferrerDoName(String classPackage, String className, String DOName) throws Exception { 534 if ((classPackage + "." + className).equals(DOName)) { 535 return "true"; 536 } else { 537 return "false"; 538 } 539 } 540 static public Hashtable fKGroupedByRefDO; 541 542 554 static public void addFK(String name, String isRefConstraint, String refName, String pack, String fKeyColName, String foreignKeyGroup) throws Exception { 555 if (isRefConstraint.equals("true")) { 556 String nameOfPKinReferencedTable = fKeyColName; 557 558 if (null != nameOfPKinReferencedTable 559 && 0 != nameOfPKinReferencedTable.length()) { 560 Hashtable groups = (Hashtable) fKGroupedByRefDO.get(refName); 562 563 if (null == groups) { 564 groups = new Hashtable(); 565 fKGroupedByRefDO.put(refName, groups); 566 } 567 Vector pairs = (Vector) groups.get(foreignKeyGroup); 568 569 if (null == pairs) { 570 pairs = new Vector(); 571 groups.put(foreignKeyGroup, pairs); 572 } 573 String [] pk_fk_pair = new String [ 2 ]; 574 575 pk_fk_pair[0] = nameOfPKinReferencedTable; 576 pk_fk_pair[1] = name; pairs.addElement(pk_fk_pair); 578 } 579 } 580 } 581 static public Enumeration enumFKGroupedByRefDOKeys; 582 static public Enumeration enumFKGroupedByRefDOElements; 583 static public FKElements elements; 584 static class FKElements { 585 public String fkRefName; 586 public String getMethodName; 587 public String setMethodName; 588 public StringWriter fKsetQueryCalls; 589 public StringWriter fKsetCalls; 590 public FKElements() { 591 fkRefName = ""; 592 getMethodName = ""; 593 setMethodName = ""; 594 fKsetQueryCalls = new StringWriter(); 595 fKsetCalls = new StringWriter(); 596 } 597 } 598 599 604 static public void initEnumFKGroupedByRefDO() throws Exception { 605 enumFKGroupedByRefDOKeys = fKGroupedByRefDO.keys(); 606 enumFKGroupedByRefDOElements = fKGroupedByRefDO.elements(); 607 elements = new FKElements(); 608 } 609 610 618 static public String hasMoreElements() throws Exception { 619 String ret = "false"; 620 621 if (enumFKGroupedByRefDOKeys.hasMoreElements()) { 622 ret = "true"; 623 enumFKGroupedByRefDOElements.hasMoreElements(); 624 elements.fkRefName = (String ) enumFKGroupedByRefDOKeys.nextElement(); 625 Hashtable fkGroups = (Hashtable) enumFKGroupedByRefDOElements.nextElement(); 626 627 for (Enumeration e2 = fkGroups.keys(); e2.hasMoreElements();) { 628 String fkGroup = (String ) e2.nextElement(); 629 630 elements.getMethodName = "_" + fkGroup; 631 elements.setMethodName = "_" + fkGroup; 632 Vector v = (Vector) fkGroups.get(fkGroup); 633 634 for (int i = 0; i < v.size(); i++) { 635 String [] pk_fk_pair = (String []) v.elementAt(i); 636 String pkName = Common.capitalizeName(pk_fk_pair[0]); 637 String fkName = Common.capitalizeName(pk_fk_pair[1]); 638 639 644 elements.fKsetQueryCalls.write(" q.setQuery" + fkName 646 + "( get" + pkName + "() );\n"); 647 elements.fKsetCalls.write(" _set" + fkName + "( x.get" 648 + pkName + "() );\n"); 649 } } } return ret; 653 } 654 655 662 static public String getFKRef() throws Exception { 663 return elements.fkRefName; 664 } 665 666 673 static public String getMethodName() throws Exception { 674 return elements.getMethodName; 675 } 676 677 684 static public String setMethodName() throws Exception { 685 return elements.setMethodName; 686 } 687 688 695 static public String getFKsetQueryCalls() throws Exception { 696 return elements.fKsetQueryCalls.toString(); 697 } 698 699 706 static public String getFKsetCalls() throws Exception { 707 return elements.fKsetCalls.toString(); 708 } 709 static public int counter = 0; 710 711 716 static public void resetCounter() { 717 counter = 0; 718 } 719 720 723 static public void incCounter() { 724 counter++; 725 } 726 727 732 static public String getCounter() { 733 return "" + counter; 734 } 735 736 741 static public String convertJavaTypes(String typ ) { 742 743 String retValue; 744 745 if(typ.equals("boolean")) 746 retValue = "new Boolean(x)"; 747 else if(typ.equals("int")) 748 retValue = "new Integer(x)"; 749 else if(typ.equals("long")) 750 retValue = "new Long(x)"; 751 else if(typ.equals("float")) 752 retValue = "new Float(x)"; 753 else if(typ.equals("double")) 754 retValue = "new Double(x)"; 755 else if(typ.equals("byte")) 756 retValue = "new Byte(x)"; 757 else if(typ.equals("short")) 758 retValue = "new Short(x)"; 759 else if(typ.equals("char")) 760 retValue = "new Char(x)"; 761 else 762 retValue = "x"; 763 764 return retValue; 765 } 766 } 767 | Popular Tags |