1 23 24 26 27 29 package com.sun.jdo.api.persistence.enhancer.meta; 30 31 32 34 import java.lang.reflect.Modifier ; 35 36 import java.util.Comparator ; 37 import java.util.Iterator ; 38 import java.util.Enumeration ; 39 import java.util.Map ; 40 import java.util.List ; 41 import java.util.Collection ; 42 import java.util.Collections ; 43 import java.util.HashSet ; 44 import java.util.HashMap ; 45 import java.util.ArrayList ; 46 import java.util.Properties ; 47 import java.util.StringTokenizer ; 48 49 import java.text.MessageFormat ; 50 51 52 102 104 public final class JDOMetaDataProperties 105 { 106 107 108 111 private static final char FIELD_DELIMITER = '#'; 112 113 116 private static final String PROPERTY_DELIMITERS = " \t,;"; 117 118 121 private static final char PROPERTY_ASSIGNER = ':'; 122 123 124 private static final String PROPERTY_ACCESS_MODIFIER = "access"; 126 private static final String PROPERTY_JDO_MODIFIER = "jdo"; 127 private static final String PROPERTY_SUPER_CLASSNAME = "super"; 128 private static final String PROPERTY_OID_CLASSNAME = "oid"; 129 private static final String PROPERTY_TYPE = "type"; 130 private static final String PROPERTY_ANNOTATION_TYPE = "annotation"; 131 132 private static final String ACCESS_PRIVATE = "private"; 134 private static final String ACCESS_PACKAGE_LOCAL = "package"; 135 private static final String ACCESS_PROTECTED = "protected"; 136 private static final String ACCESS_PUBLIC = "public"; 137 138 private static final String JDO_TRANSIENT = "transient"; 140 private static final String JDO_PERSISTENT = "persistent"; 141 private static final String JDO_TRANSACTIONAL = "transactional"; 142 143 private static final String ANNOTATION_TYPE_PK = "pk"; 145 private static final String ANNOTATION_TYPE_DFG = "dfg"; 146 private static final String ANNOTATION_TYPE_MEDIATED = "mediated"; 147 148 149 152 private Properties properties; 153 154 155 160 private final Map cachedJDOClasses = new HashMap (); 161 162 163 167 private static final JDOClass NULL = new JDOClass (null); 168 169 170 174 private final List tmpTokens = new ArrayList (); 175 176 177 184 185 public JDOMetaDataProperties (Properties props) 186 { 187 188 this.properties = props; 189 190 } 192 193 204 205 public final JDOClass getJDOClass (String classname) 206 throws JDOMetaDataUserException 207 { 208 209 classname = toCanonicalClassName (classname); 210 JDOClass clazz = (JDOClass) this.cachedJDOClasses.get (classname); 211 if (clazz == NULL) { 213 return null; 214 } 215 if (clazz != null) 216 { 217 return clazz; 218 } 219 220 String s = this.properties.getProperty (classname); 222 if (s == null) { 224 this.cachedJDOClasses.put (classname, NULL); 225 return null; 226 } 227 228 clazz = parseJDOClass (classname, s); parseJDOFields (clazz); validateDependencies (clazz); this.cachedJDOClasses.put (clazz.getName (), clazz); 233 234 return clazz; 235 236 } 238 239 251 252 public final JDOField getJDOField (String fieldname, 253 String classname) 254 throws JDOMetaDataUserException 255 { 256 257 JDOClass clazz = getJDOClass (classname); 258 return (clazz != null ? clazz.getField (fieldname) : null); 259 260 } 262 263 268 269 public final String [] getKnownClassNames () 270 { 271 272 Collection classnames = new HashSet (); 273 for (Enumeration names = this.properties.propertyNames (); names.hasMoreElements ();) 274 { 275 String name = (String ) names.nextElement (); 276 if (name.indexOf (FIELD_DELIMITER) < 0) 277 { 278 classnames.add (fromCanonicalClassName (name)); 279 } 280 } 281 282 return (String []) classnames.toArray (new String [classnames.size ()]); 283 284 } 286 287 297 298 private static final String toCanonicalClassName (String classname) 299 { 300 301 return classname.replace ('/', '.'); 302 303 } 305 306 316 317 private static final String fromCanonicalClassName (String classname) 318 { 319 320 return classname.replace ('.', '/'); 321 322 } 324 325 337 338 private final JDOClass parseJDOClass (String classname, 339 String attributes) 340 throws JDOMetaDataUserException 341 { 342 343 List props = parseProperties (attributes); 344 345 for (int i = 0; i < props.size (); i++) 347 { 348 Property prop = (Property) props.get (i); 349 validateClassProperty (prop, classname); 350 } 351 352 checkForDuplicateProperties (props, classname); 354 355 JDOClass clazz = new JDOClass (classname); 357 for (int i = 0; i < props.size (); i++) 358 { 359 Property prop = (Property) props.get (i); 360 if (prop.name.equals (PROPERTY_ACCESS_MODIFIER)) 361 { 362 clazz.modifiers = getModifiers (prop.value); 363 } 364 else if (prop.name.equals (PROPERTY_JDO_MODIFIER)) 365 { 366 clazz.isPersistent = prop.value.equals (JDO_PERSISTENT); 367 } 368 else if (prop.name.equals (PROPERTY_SUPER_CLASSNAME)) 369 { 370 clazz.setSuperClassName (prop.value); 371 } 372 else if (prop.name.equals(PROPERTY_OID_CLASSNAME)) { 373 clazz.setOidClassName(prop.value); 374 } 375 376 } 377 378 return clazz; 379 380 } 382 383 391 392 private static final void validateClassProperty (Property prop, 393 String classname) 394 throws JDOMetaDataUserException 395 { 396 397 String value = prop.value; 398 if (prop.name == null) { 400 if (value.equals (ACCESS_PUBLIC) || 402 value.equals (ACCESS_PROTECTED) || 403 value.equals (ACCESS_PACKAGE_LOCAL) || 404 value.equals (ACCESS_PRIVATE)) 405 { 406 prop.name = PROPERTY_ACCESS_MODIFIER; 407 } 408 409 else if (value.equals (JDO_PERSISTENT) || 411 value.equals (JDO_TRANSIENT)) 412 { 413 prop.name = PROPERTY_JDO_MODIFIER; 414 } 415 416 else 418 { 419 prop.name = PROPERTY_SUPER_CLASSNAME; 420 } 421 } 422 else 423 { 424 String name = prop.name; 426 checkPropertyName (prop.name, new String [] 427 { 428 PROPERTY_OID_CLASSNAME, 429 PROPERTY_ACCESS_MODIFIER, 430 PROPERTY_JDO_MODIFIER, 431 PROPERTY_SUPER_CLASSNAME 432 }, classname); 433 434 checkPropertyValue (prop, 436 new String [] 437 { 438 ACCESS_PUBLIC, 439 ACCESS_PROTECTED, 440 ACCESS_PACKAGE_LOCAL, 441 ACCESS_PRIVATE 442 }, 443 PROPERTY_ACCESS_MODIFIER, 444 classname); 445 checkPropertyValue (prop, 446 new String [] { JDO_TRANSIENT, JDO_PERSISTENT }, 447 PROPERTY_JDO_MODIFIER, 448 classname); 449 } 450 451 } 453 454 462 463 private final void parseJDOFields (JDOClass clazz) 464 throws JDOMetaDataUserException 465 { 466 467 for (Enumeration names = this.properties.propertyNames (); names.hasMoreElements ();) 469 { 470 String name = (String ) names.nextElement (); 471 if (name.startsWith (clazz.getName () + FIELD_DELIMITER)) { 473 String fieldname = name.substring (name.indexOf (FIELD_DELIMITER) + 1, name.length ()); 474 validateFieldName (fieldname, clazz.getName ()); 475 clazz.addField (parseJDOField (this.properties.getProperty (name), fieldname, clazz)); 476 } 477 } 478 clazz.sortFields (); 479 480 } 482 483 493 494 private final JDOField parseJDOField (String attributes, 495 String fieldname, 496 JDOClass clazz) 497 throws JDOMetaDataUserException 498 { 499 500 List props = parseProperties (attributes); 501 502 for (int i = 0; i < props.size (); i++) 504 { 505 Property prop = (Property) props.get (i); 506 validateFieldProperty (prop, fieldname, clazz.getName ()); 507 } 508 509 checkForDuplicateProperties (props, clazz.getName () + FIELD_DELIMITER + fieldname); 511 512 JDOField field = new JDOField (fieldname); 514 for (int i = 0; i < props.size (); i++) 515 { 516 Property prop = (Property) props.get (i); 517 if (prop.name.equals (PROPERTY_ACCESS_MODIFIER)) 518 { 519 field.modifiers = getModifiers (prop.value); 520 } 521 else if (prop.name.equals (PROPERTY_JDO_MODIFIER)) 522 { 523 field.jdoModifier = prop.value; 524 } 525 else if (prop.name.equals (PROPERTY_TYPE)) 526 { 527 field.setType (prop.value); 528 } 529 else if (prop.name.equals (PROPERTY_ANNOTATION_TYPE)) 530 { 531 field.annotationType = prop.value; 532 } 533 } 534 535 return field; 536 537 } 539 540 549 550 private final void validateFieldProperty (Property prop, 551 String fieldname, 552 String classname) 553 throws JDOMetaDataUserException 554 { 555 556 String value = prop.value; 557 if (prop.name == null) { 559 if (value.equals (ACCESS_PUBLIC) || 561 value.equals (ACCESS_PROTECTED) || 562 value.equals (ACCESS_PACKAGE_LOCAL) || 563 value.equals (ACCESS_PRIVATE)) 564 { 565 prop.name = PROPERTY_ACCESS_MODIFIER; 566 } 567 568 else if (value.equals (JDO_PERSISTENT) || 570 value.equals (JDO_TRANSIENT) || 571 value.equals (JDO_TRANSACTIONAL)) 572 { 573 prop.name = PROPERTY_JDO_MODIFIER; 574 } 575 576 else if (value.equals (ANNOTATION_TYPE_PK) || 578 value.equals (ANNOTATION_TYPE_DFG) || 579 value.equals (ANNOTATION_TYPE_MEDIATED)) 580 { 581 prop.name = PROPERTY_ANNOTATION_TYPE; 582 } 583 584 else 585 { 586 prop.name = PROPERTY_TYPE; 588 } 589 } 590 else 591 { 592 String entry = classname + FIELD_DELIMITER + fieldname; 593 594 checkPropertyName (prop.name, 596 new String [] 597 { 598 PROPERTY_ACCESS_MODIFIER, 599 PROPERTY_JDO_MODIFIER, 600 PROPERTY_TYPE, 601 PROPERTY_ANNOTATION_TYPE 602 }, 603 entry); 604 605 checkPropertyValue (prop, 607 new String [] 608 { 609 ACCESS_PUBLIC, 610 ACCESS_PROTECTED, 611 ACCESS_PACKAGE_LOCAL, 612 ACCESS_PRIVATE 613 }, 614 PROPERTY_ACCESS_MODIFIER, 615 entry); 616 checkPropertyValue (prop, 617 new String [] 618 { 619 JDO_PERSISTENT, 620 JDO_TRANSIENT, 621 JDO_TRANSACTIONAL 622 }, 623 PROPERTY_JDO_MODIFIER, 624 entry); 625 checkPropertyValue (prop, 626 new String [] 627 { 628 ANNOTATION_TYPE_PK, 629 ANNOTATION_TYPE_DFG, 630 ANNOTATION_TYPE_MEDIATED 631 }, 632 PROPERTY_ANNOTATION_TYPE, 633 entry); 634 } 635 636 } 638 639 646 647 private final void validateDependencies (JDOClass clazz) 648 throws JDOMetaDataUserException 649 { 650 651 for (int i = clazz.fields.size () - 1; i >= 0; i--) 652 { 653 JDOField field = (JDOField) clazz.fields.get (i); 654 655 if (field.jdoModifier == null) 657 { 658 field.jdoModifier = (clazz.isPersistent () ? JDO_PERSISTENT : JDO_TRANSIENT); 659 } 660 else if (clazz.isTransient ()) 662 { 663 if (field.isPersistent ()) 665 { 666 throw new JDOMetaDataUserException (getErrorMsg (IErrorMessages.ERR_TRANSIENT_CLASS_WITH_PERSISTENT_FIELD, 667 new String [] { clazz.getName (), field.getName () })); 668 } 669 if (field.isTransactional ()) 671 { 672 throw new JDOMetaDataUserException (getErrorMsg (IErrorMessages.ERR_TRANSIENT_CLASS_WITH_TRANSACTIONAL_FIELD, 673 new String [] { clazz.getName (), field.getName () })); 674 } 675 } 676 677 if (field.isAnnotated () && clazz.isTransient ()) 679 { 680 throw new JDOMetaDataUserException (getErrorMsg (IErrorMessages.ERR_TRANSIENT_CLASS_WITH_ANNOTATED_FIELD, 681 new String [] { clazz.getName (), field.getName () })); 682 } 683 684 if ( ! field.isPersistent () && field.isAnnotated ()) 686 { 687 field.annotationType = ANNOTATION_TYPE_MEDIATED; 688 } 689 690 if ( ! field.isAnnotated () && clazz.isPersistent ()) 692 { 693 field.annotationType = ANNOTATION_TYPE_MEDIATED; 694 } 695 } 696 697 } 699 700 708 709 private static final void validateFieldName (String fieldname, 710 String classname) 711 throws JDOMetaDataUserException 712 { 713 714 if (fieldname.length () == 0) 715 { 716 throw new JDOMetaDataUserException (getErrorMsg (IErrorMessages.ERR_EMPTY_FIELDNAME, 717 new String [] { classname })); 718 } 719 if ( ! Character.isJavaIdentifierStart (fieldname.charAt (0))) 720 { 721 throw new JDOMetaDataUserException (getErrorMsg (IErrorMessages.ERR_INVALID_FIELDNAME, 722 new String [] { classname, fieldname })); 723 } 724 for (int i = fieldname.length () - 1; i >= 0; i--) 725 { 726 final char c = fieldname.charAt (i); 727 if ( ! Character.isJavaIdentifierPart (c)) 728 { 729 throw new JDOMetaDataUserException (getErrorMsg (IErrorMessages.ERR_INVALID_FIELDNAME, 730 new String [] { classname, fieldname })); 731 } 732 } 733 734 } 736 737 745 746 private static final void checkForDuplicateProperties (List props, 747 String entry) 748 throws JDOMetaDataUserException 749 { 750 751 for (int i = 0; i < props.size (); i++) 752 { 753 for (int j = i + 1; j < props.size (); j++) 754 { 755 Property p1 = (Property) props.get (i); 756 Property p2 = (Property) props.get (j); 757 if (p1.name.equals (p2.name) && ! p1.value.equals (p2.value)) 758 { 759 throw new JDOMetaDataUserException (getErrorMsg (IErrorMessages.ERR_DUPLICATE_PROPERTY_NAME, 760 new String [] { entry, p1.name, p1.value, p2.value })); 761 } 762 } 763 } 764 765 } 767 768 778 779 private static final void checkPropertyName (String name, 780 String [] validnames, 781 String entry) 782 throws JDOMetaDataUserException 783 { 784 785 for (int i = 0; i < validnames.length; i++) 786 { 787 if (name.equals (validnames [i])) 788 { 789 return; 790 } 791 } 792 793 throw new JDOMetaDataUserException (getErrorMsg (IErrorMessages.ERR_INVALID_PROPERTY_NAME, 794 new String [] { entry, name })); 795 796 } 798 799 810 811 private static final void checkPropertyValue (Property prop, 812 String [] validvalues, 813 String name, 814 String entry) 815 throws JDOMetaDataUserException 816 { 817 818 if ( ! prop.name.equals (name)) 819 { 820 return; 821 } 822 823 for (int i = 0; i < validvalues.length; i++) 824 { 825 if (prop.value.equals (validvalues [i])) 826 { 827 return; 828 } 829 } 830 831 throw new JDOMetaDataUserException (getErrorMsg (IErrorMessages.ERR_INVALID_PROPERTY_VALUE, 832 new String [] { entry, name, prop.value })); 833 834 } 836 837 845 846 static final String getErrorMsg (String msg, 847 String [] params) 848 { 849 850 return MessageFormat.format (msg, (Object []) params); 851 852 } 854 855 864 865 final List parseProperties (String attributes) 866 throws JDOMetaDataUserException 867 { 868 869 this.tmpTokens.clear (); 870 StringTokenizer t = new StringTokenizer (attributes, PROPERTY_DELIMITERS); 871 while (t.hasMoreTokens ()) 872 { 873 this.tmpTokens.add (parseProperty (t.nextToken ())); 874 } 875 876 return this.tmpTokens; 877 878 } 880 881 890 891 private final Property parseProperty (String attribute) 892 throws JDOMetaDataUserException 893 { 894 895 Property prop = new Property (); 896 int idx = attribute.indexOf (PROPERTY_ASSIGNER); 897 if (idx < 0) 898 { 899 prop.value = attribute; 900 } 901 else 902 { 903 prop.name = attribute.substring (0, idx); 904 prop.value = attribute.substring (idx + 1, attribute.length ()); 905 if (prop.name.length () == 0 || prop.value.length () == 0) 906 { 907 throw new JDOMetaDataUserException (getErrorMsg (IErrorMessages.ERR_EMPTY_PROPERTY_NAME_OR_VALUE, 908 new String [] { attribute })); 909 } 910 } 911 912 return prop; 913 914 } 916 917 920 921 private static final int getModifiers (String modifier) 922 { 923 924 if (modifier.equals (ACCESS_PUBLIC)) 925 { 926 return Modifier.PUBLIC; 927 } 928 if (modifier.equals (ACCESS_PRIVATE)) 929 { 930 return Modifier.PRIVATE; 931 } 932 if (modifier.equals (ACCESS_PROTECTED)) 933 { 934 return Modifier.PROTECTED; 935 } 936 return 0; 937 938 } 940 941 946 947 979 980 981 985 987 private static final class Property 988 { 989 990 991 994 String name = null; 995 996 997 1000 String value = null; 1001 1002 1003 1008 1009 public final String toString () 1010 { 1011 1012 return '<' + name + ':' + value + '>'; 1013 1014 } 1016 1017 } 1019 1020 1024 1026 private static interface IErrorMessages 1027 { 1028 1029 1030 static final String PREFIX = "Error Parsing meta data properties: "; 1032 static final String ERR_EMPTY_FIELDNAME = 1033 PREFIX + "The class ''{0}'' may not have an empty fieldname."; 1034 static final String ERR_INVALID_FIELDNAME = 1035 PREFIX + "The field name ''{1}'' of class ''{0}'' is not valid."; 1036 static final String ERR_EMPTY_PROPERTY_NAME_OR_VALUE = 1037 PREFIX + "The property name and value may not be empty if a ''" + PROPERTY_ASSIGNER + "'' is specified: ''{0}''."; 1038 static final String ERR_INVALID_PROPERTY_NAME = 1039 PREFIX + "Invalid property name for entry ''{0}'': ''{1}''."; 1040 static final String ERR_INVALID_PROPERTY_VALUE = 1041 PREFIX + "Invalid value for property ''{1}'' of entry ''{0}'': ''{2}''."; 1042 static final String ERR_DUPLICATE_PROPERTY_NAME = 1043 PREFIX + "The property ''{1}'' for the entry ''{0}'' entered twice with values: ''{2}'' and ''{3}''."; 1044 static final String ERR_TRANSIENT_CLASS_WITH_PERSISTENT_FIELD = 1045 PREFIX + "A non-persistent class cannot have a persistent field (class ''{0}'' with field ''{1})''."; 1046 static final String ERR_TRANSIENT_CLASS_WITH_TRANSACTIONAL_FIELD = 1047 PREFIX + "A non-persistent class cannot have a transactional field (class ''{0}'' with field ''{1})''."; 1048 static final String ERR_TRANSIENT_CLASS_WITH_ANNOTATED_FIELD = 1049 PREFIX + "A non-persistent class cannot have an annotated field (''{1}'' of class ''{0}'') can''t have a fetch group."; 1050 static final String ERR_NON_PERSISTENT_ANNOTATED_FIELD = 1051 PREFIX + "A non-persistent field (''{1}'' of class ''{0}'') can''t be a annotated."; 1052 1053 1054 } 1056 1057 1061 1063 static final class JDOClass 1064 { 1065 1066 1067 1070 private String name; 1071 1072 1073 1076 private String superClassName = null; 1077 1078 1079 1082 private String oidClassName = null; 1083 1084 1085 1088 private int modifiers = Modifier.PUBLIC; 1089 1090 1091 1094 private boolean isPersistent = true; 1095 1096 1097 1100 private final List fields = new ArrayList (); 1101 1102 1103 1106 private String [] managedFieldNames = null; 1107 1108 1109 1112 private String [] fieldNames = null; 1113 1114 1115 1122 1123 JDOClass (String name) 1124 { 1125 1126 this.name = name; 1127 1128 } 1130 1131 1138 1139 public final String getName () 1140 { 1141 1142 return this.name; 1143 1144 } 1146 1147 1150 1151 public final int getModifiers () 1152 { 1153 1154 return this.modifiers; 1155 1156 } 1158 1159 1168 1169 private final void setSuperClassName (String classname) 1170 { 1171 1172 this.superClassName = fromCanonicalClassName (classname); 1173 1174 } 1176 1177 1184 1185 public final String getSuperClassName () 1186 { 1187 1188 return this.superClassName; 1189 1190 } 1192 1193 1202 1203 public void setOidClassName(String classname) 1204 { 1205 this.oidClassName = fromCanonicalClassName(classname); 1206 } 1207 1208 1209 1216 1217 public String getOidClassName() 1218 { 1219 return oidClassName; 1220 } 1221 1222 1223 1230 1231 public final boolean isPersistent () 1232 { 1233 1234 return this.isPersistent; 1235 1236 } 1238 1239 1246 1247 public final boolean isTransient () 1248 { 1249 1250 return ! isPersistent (); 1251 1252 } 1254 1255 1262 1263 private final void addField (JDOField field) 1264 { 1265 1266 this.fields.add (field); 1267 1268 } 1270 1271 1280 1281 public final JDOField getField (String name) 1282 { 1283 1284 int idx = getIndexOfField (name); 1285 return (idx > -1 ? (JDOField) this.fields.get (idx) : null); 1286 1287 } 1289 1290 1299 1300 public final int getIndexOfField (String name) 1301 { 1302 1303 for (int i = 0; i < this.fields.size (); i++) 1304 { 1305 JDOField field = (JDOField) this.fields.get (i); 1306 if (field.getName ().equals (name)) 1307 { 1308 return i; 1309 } 1310 } 1311 1312 return -1; 1313 1314 } 1316 1317 1324 1325 public final String [] getFields () 1326 { 1327 1328 if (this.fieldNames == null) 1329 { 1330 final int n = this.fields.size (); 1331 String [] fields = new String [n]; 1332 for (int i = 0; i < n; i++) 1333 { 1334 fields [i] = ((JDOField) this.fields.get (i)).getName (); 1335 } 1336 this.fieldNames = fields; 1337 } 1338 1339 return this.fieldNames; 1340 1341 } 1343 1344 1351 1352 private final void sortFields () 1353 { 1354 1355 Collections.sort (this.fields, 1356 new Comparator () 1357 { 1358 public final int compare (Object f1, Object f2) 1359 { 1360 JDOField field1 = (JDOField) f1; 1361 JDOField field2 = (JDOField) f2; 1362 if ( ! (field1.isManaged () && field2.isManaged ())) 1364 { 1365 return (field1.isManaged () ? -1 : 1); 1366 } 1367 return (field1).getName ().compareTo (field2.getName ()); 1368 } 1369 }); 1370 1371 } 1373 1374 1381 1382 public final String [] getManagedFieldNames () 1383 { 1384 1385 if (this.managedFieldNames == null) 1386 { 1387 final int n = this.fields.size (); 1388 List tmp = new ArrayList (n); 1389 for (int i = 0; i < n; i++) 1390 { 1391 JDOField field = (JDOField) this.fields.get (i); 1392 if (field.isManaged ()) 1393 { 1394 tmp.add (field.getName ()); 1395 } 1396 } 1397 this.managedFieldNames = (String []) tmp.toArray (new String [tmp.size ()]); 1398 } 1399 1400 return this.managedFieldNames; 1401 1402 } 1404 1405 1410 1411 public final String toString () 1412 { 1413 1414 return '<' + PROPERTY_SUPER_CLASSNAME + ':' + this.superClassName + ',' + 1415 PROPERTY_ACCESS_MODIFIER + ':' + Modifier.toString (this.modifiers) + ',' + 1416 PROPERTY_JDO_MODIFIER + ':' + this.isPersistent + ',' + 1417 "fields:" + this.fields + '>'; 1418 1419 } 1421 1422 } 1424 1425 1429 1431 static final class JDOField 1432 { 1433 1434 1435 1438 private String name; 1439 1440 1441 1444 private String type = null; 1445 1446 1447 1450 private int modifiers = Modifier.PRIVATE; 1451 1452 1453 1456 private String jdoModifier = null; 1457 1458 1459 1462 private String annotationType = null; 1463 1464 1465 1472 1473 JDOField (String name) 1474 { 1475 1476 this.name = name; 1477 1478 } 1480 1481 1488 1489 public final String getName () 1490 { 1491 1492 return this.name; 1493 1494 } 1496 1497 1506 1507 public final void setType (String type) 1508 { 1509 1510 this.type = fromCanonicalClassName (type); 1511 1512 } 1514 1515 1522 1523 public final String getType () 1524 { 1525 1526 return this.type; 1527 1528 } 1530 1531 1534 1535 public final int getModifiers () 1536 { 1537 1538 return this.modifiers; 1539 1540 } 1542 1543 1550 1551 public final boolean isAnnotated () 1552 { 1553 1554 return this.annotationType != null; 1555 1556 } 1558 1559 1566 1567 public final boolean isPk () 1568 { 1569 1570 return (this.annotationType != null && this.annotationType.equals (ANNOTATION_TYPE_PK)); 1571 1572 } 1574 1575 1582 1583 public final boolean isInDefaultFetchGroup () 1584 { 1585 1586 return (this.annotationType != null && this.annotationType.equals (ANNOTATION_TYPE_DFG)); 1587 1588 } 1590 1591 1597 public boolean isKnownTransient() 1598 { 1599 return (jdoModifier != null 1600 && jdoModifier.equals(JDO_TRANSIENT)); 1601 } 1602 1603 1604 1611 1612 public final boolean isPersistent () 1613 { 1614 1615 return (this.jdoModifier != null && this.jdoModifier.equals (JDO_PERSISTENT)); 1616 1617 } 1619 1620 1627 1628 public final boolean isTransactional () 1629 { 1630 1631 return (this.jdoModifier != null && this.jdoModifier.equals (JDO_TRANSACTIONAL)); 1632 1633 } 1635 1636 1641 1642 public final boolean isManaged () 1643 { 1644 1645 return (isPersistent () || isTransactional ()); 1646 1647 } 1649 1650 1655 1656 public final String toString () 1657 { 1658 1659 return '<' + "name:" + this.name + ',' + 1660 PROPERTY_TYPE + ':' + this.type + ',' + 1661 PROPERTY_ACCESS_MODIFIER + ':' + Modifier.toString (this.modifiers) + ',' + 1662 PROPERTY_JDO_MODIFIER + ':' + this.jdoModifier + ',' + 1663 PROPERTY_ANNOTATION_TYPE + ':' + this.annotationType + 1664 '>'; 1665 1666 } 1668 1669 } 1671 1672} | Popular Tags |