1 27 package com.genimen.djeneric.repository; 28 29 import java.io.UnsupportedEncodingException ; 30 import java.math.BigDecimal ; 31 import java.text.ParseException ; 32 import java.text.SimpleDateFormat ; 33 import java.util.ArrayList ; 34 import java.util.Arrays ; 35 import java.util.Collections ; 36 import java.util.Date ; 37 38 import org.apache.regexp.RE; 39 import org.apache.regexp.RESyntaxException; 40 41 import com.genimen.djeneric.language.Messages; 42 import com.genimen.djeneric.repository.exceptions.CatalogException; 43 import com.genimen.djeneric.repository.exceptions.DjenericException; 44 import com.genimen.djeneric.repository.exceptions.DomainViolationException; 45 import com.genimen.djeneric.util.DjLogger; 46 47 56 public class DjDomain implements Comparable , DjPropertyType 57 { 58 private static SimpleDateFormat sf = new SimpleDateFormat ("yyyy.MM.dd HH:mm:ss.SSS"); 59 60 public static final String CASE_NONE = "N"; 61 public static final String CASE_UPPER = "U"; 62 public static final String CASE_LOWER = "L"; 63 64 68 public final static int COMP_TEXTFIELD = 0; 69 72 public final static int COMP_COMBOBOX = 1; 73 76 public final static int COMP_CHOOSER = 2; 77 80 public final static int COMP_CHECKBOX = 3; 81 84 public final static int COMP_DATECHOOSER = 4; 85 88 public final static int COMP_MEMO = 5; 89 92 public final static int COMP_HTML_MEMO = 6; 93 96 public final static int COMP_PASSWORD = 7; 97 100 public final static int COMP_LABEL = 8; 101 102 public final static int COMP_CUSTOM = 9; 103 104 public final static int COMP_CUSTOM_MEMO = 10; 105 106 private static String [] compTypes = {"TextField", "Combobox", "Chooser", "Checkbox", "DateChooser", 108 "Memo", "HTML", "Password", "Label", "[Custom]", "[CustomMemo]"}; 109 110 113 public final static int STRING_TYPE = 1; 114 117 public final static int INT_TYPE = 2; 118 121 public final static int LONG_TYPE = 3; 122 125 public final static int DATE_TYPE = 4; 126 129 public final static int BIGDECIMAL_TYPE = 5; 130 133 public final static int BYTE_TYPE = 6; 134 135 private static String [] nativeTypes = {"String", "int", "long", "Date", "BigDecimal", "byte[]"}; 136 137 String _name; 138 String _description; 139 String _formatMask; 140 int _componentType; 141 int _nativeTypeId; 142 int _length; 143 int _decimals; 144 int _displayWidth; 145 int _displayHeight; 146 boolean _enforce; 147 boolean _isDynamic = false; 148 DjDomain _superDomain; 149 String _reValidationMask; 150 String _reFailureMessage; 151 String _caseConversion; 152 DjPackage _package = null; 153 154 ArrayList _domainValues = new ArrayList (); 155 156 public void copyInto(DjDomain dest) 157 { 158 dest._name = _name; 159 dest._description = _description; 160 dest._formatMask = _formatMask; 161 dest._componentType = _componentType; 162 dest._nativeTypeId = _nativeTypeId; 163 dest._length = _length; 164 dest._decimals = _decimals; 165 dest._displayWidth = _displayWidth; 166 dest._displayHeight = _displayHeight; 167 dest._enforce = _enforce; 168 dest._isDynamic = _isDynamic; 169 dest._superDomain = _superDomain; 170 dest._reValidationMask = _reValidationMask; 171 dest._reFailureMessage = _reFailureMessage; 172 dest._caseConversion = _caseConversion; 173 dest._package = _package; 174 dest._domainValues = new ArrayList (); 175 dest._domainValues.addAll(_domainValues); 176 } 177 178 181 public DjDomain() 182 { 183 _name = ""; 184 _nativeTypeId = STRING_TYPE; 185 _enforce = true; 186 _description = ""; 187 _length = 0; 188 _decimals = 0; 189 _formatMask = ""; 190 _displayWidth = 0; 191 _displayHeight = 0; 192 _reValidationMask = ""; 193 _reFailureMessage = ""; 194 _caseConversion = CASE_NONE; 195 } 196 197 219 public DjDomain(String name, String type, int length, int decimals, String formatMask, String description, 220 boolean enforce) throws CatalogException 221 { 222 _name = name; 223 _nativeTypeId = translateType(type); 224 _enforce = enforce; 225 _description = description; 226 _length = length; 227 _decimals = decimals; 228 _formatMask = formatMask; 229 _displayWidth = 0; 230 _displayHeight = 0; 231 _caseConversion = CASE_NONE; 232 } 233 234 253 public DjDomain(String name, int nativeType, int length, int decimals, String formatMask, String description, 254 boolean enforce) 255 { 256 _name = name; 257 _nativeTypeId = nativeType; 258 _enforce = enforce; 259 _description = description; 260 _length = length; 261 _decimals = decimals; 262 _formatMask = formatMask; 263 _displayWidth = 0; 264 _displayHeight = 0; 265 _caseConversion = CASE_NONE; 266 } 267 268 291 public DjDomain(DjDomain superDomain, String name, String type, int length, int decimals, String formatMask, 292 String description, boolean enforce) throws CatalogException 293 { 294 this(name, type, length, decimals, formatMask, description, enforce); 295 _superDomain = superDomain; 296 } 297 298 305 public boolean isBuiltIn() 306 { 307 return isDynamic() || getName().equals("String") || getName().equals("int") || getName().equals("long") 308 || getName().equals("BigDecimal") || getName().equals("byte[]") || getName().equals("Date"); 309 } 310 311 323 protected Date convertString2Date(String dateString, String mask) throws ParseException 324 { 325 if (mask == null) return sf.parse(dateString); 326 327 SimpleDateFormat m = new SimpleDateFormat (mask); 328 return m.parse(dateString); 329 } 330 331 343 public Object coerse(Object obj) throws DjenericException 344 { 345 int tc = getTypeCode(); 346 347 if (obj == null) return null; 348 349 if (obj.toString().trim().length() == 0) return null; 350 351 if (tc == DjDomain.STRING_TYPE) 352 { 353 return obj.toString(); 354 } 355 356 try 357 { 358 if (tc == DjDomain.BIGDECIMAL_TYPE) 359 { 360 if (obj instanceof BigDecimal ) return obj; 361 return new BigDecimal (obj.toString()); 362 } 363 else if (tc == DjDomain.BYTE_TYPE) 364 { 365 if (obj instanceof byte[]) return obj; 366 try 367 { 368 return obj.toString().getBytes(DjPersistenceManager.ENCODING_METHOD); 369 } 370 catch (UnsupportedEncodingException uee) 371 { 372 DjLogger.log(uee); 373 return obj.toString().getBytes(); 374 } 375 } 376 else if (tc == DjDomain.DATE_TYPE) 377 { 378 if (obj instanceof Date ) return obj; 379 return convertString2Date(obj.toString(), null); 380 } 381 else if (tc == DjDomain.INT_TYPE) 382 { 383 if (obj instanceof Integer ) return obj; 384 return new Integer (obj.toString()); 385 } 386 else if (tc == DjDomain.LONG_TYPE) 387 { 388 if (obj instanceof Long ) return obj; 389 return new Long (obj.toString()); 390 } 391 } 392 catch (ParseException x) 393 { 394 throw new DjenericException(Messages.getString("DjDomain.InvalidValue", obj, int2nativeType(tc))); 395 } 396 throw new CatalogException(Messages.getString("DjDomain.CannotCoerse", String.valueOf(tc))); 397 } 398 399 406 public void setDisplayWidth(int w) 407 { 408 _displayWidth = w; 409 } 410 411 416 public int getDisplayWidth() 417 { 418 return _displayWidth; 419 } 420 421 428 public void setDisplayHeight(int h) 429 { 430 _displayHeight = h; 431 } 432 433 438 public int getDisplayHeight() 439 { 440 return _displayHeight; 441 } 442 443 448 public String getTypeName() 449 { 450 return _name; 451 } 452 453 public String getTypeClassName() 454 { 455 return getNativeTypeClass().getName(); 456 } 457 458 464 public int getTypeCode() 465 { 466 if (_superDomain != null) return _superDomain.getTypeCode(); 467 return _nativeTypeId; 468 } 469 470 475 public String getFormatMask() 476 { 477 return _formatMask; 478 } 479 480 486 public void setFormatMask(String mask) 487 { 488 _formatMask = mask; 489 } 490 491 498 public int compareTo(Object o) 499 { 500 if (!(o instanceof DjDomain)) return -1; 501 502 return getName().toLowerCase().compareTo(o.toString().toLowerCase()); 503 } 504 505 511 public void addDomainValue(DjDomainValue dv) 512 { 513 _domainValues.add(dv); 514 } 515 516 525 public void addDomainValue(int atIdx, DjDomainValue dv) 526 { 527 _domainValues.add(atIdx, dv); 528 } 529 530 536 public void removeDomainValue(DjDomainValue dv) 537 { 538 _domainValues.remove(dv); 539 } 540 541 546 public String getName() 547 { 548 return _name; 549 } 550 551 557 public void setName(String name) 558 { 559 _name = name; 560 } 561 562 569 public void setSuperDomain(DjDomain s) 570 { 571 _superDomain = s; 572 } 573 574 580 public DjDomain getSuperDomain() 581 { 582 return _superDomain; 583 } 584 585 590 public String getDescription() 591 { 592 return _description; 593 } 594 595 602 public boolean isEnforced() 603 { 604 return _enforce; 605 } 606 607 615 public void setEnforced(boolean b) 616 { 617 _enforce = b; 618 } 619 620 626 public void setDescription(String descr) 627 { 628 _description = descr; 629 } 630 631 636 public int getDomainValueCount() 637 { 638 int count = 0; 639 if (_superDomain != null) count = _superDomain.getDomainValueCount(); 640 return _domainValues.size() + count; 641 } 642 643 648 public int getPersonalDomainValueCount() 649 { 650 return _domainValues.size(); 651 } 652 653 659 public ArrayList getPersonalDomainValues() 660 { 661 return _domainValues; 662 } 663 664 676 protected int translateType(String type) throws CatalogException 677 { 678 if (type.equals("String")) 679 { 680 return STRING_TYPE; 681 } 682 if (type.equals("int")) 683 { 684 return INT_TYPE; 685 } 686 if (type.equals("Integer")) 687 { 688 return INT_TYPE; 689 } 690 if (type.equals("long")) 691 { 692 return LONG_TYPE; 693 } 694 if (type.equals("Long")) 695 { 696 return LONG_TYPE; 697 } 698 if (type.equals("Date")) 699 { 700 return DATE_TYPE; 701 } 702 if (type.equals("BigDecimal")) 703 { 704 return BIGDECIMAL_TYPE; 705 } 706 if (type.equals("byte[]")) 707 { 708 return BYTE_TYPE; 709 } 710 throw new CatalogException(Messages.getString("DjDomain.Unsupported_type", type)); 711 } 712 713 720 public String getNativeType() 721 { 722 if (_superDomain != null) return _superDomain.getNativeType(); 723 724 if (_nativeTypeId == STRING_TYPE) return "String"; 725 if (_nativeTypeId == INT_TYPE) return "int"; 726 if (_nativeTypeId == LONG_TYPE) return "long"; 727 if (_nativeTypeId == DATE_TYPE) return "Date"; 728 if (_nativeTypeId == BYTE_TYPE) return "byte[]"; 729 if (_nativeTypeId == BIGDECIMAL_TYPE) return "BigDecimal"; 730 731 return "String"; 732 } 733 734 public Class getNativeTypeClass() 735 { 736 if (_superDomain != null) return _superDomain.getNativeTypeClass(); 737 738 if (_nativeTypeId == STRING_TYPE) return String .class; 739 if (_nativeTypeId == INT_TYPE) return Integer .class; 740 if (_nativeTypeId == LONG_TYPE) return Long .class; 741 if (_nativeTypeId == DATE_TYPE) return Date .class; 742 if (_nativeTypeId == BYTE_TYPE) return Byte [].class; 743 if (_nativeTypeId == BIGDECIMAL_TYPE) return BigDecimal .class; 744 745 return String .class; 746 } 747 748 755 public String getNativeTypeAsObject() 756 { 757 if (_superDomain != null) return _superDomain.getNativeType(); 758 759 if (_nativeTypeId == STRING_TYPE) return "String"; 760 if (_nativeTypeId == INT_TYPE) return "Integer"; 761 if (_nativeTypeId == LONG_TYPE) return "Long"; 762 if (_nativeTypeId == DATE_TYPE) return "Date"; 763 if (_nativeTypeId == BYTE_TYPE) return "byte[]"; 764 if (_nativeTypeId == BIGDECIMAL_TYPE) return "BigDecimal"; 765 766 return "String"; 767 } 768 769 778 public void setNativeType(String str) throws DjenericException 779 { 780 _nativeTypeId = translateType(str); 781 } 782 783 792 public DjDomainValue getDomainValue(int idx) 793 { 794 int count = 0; 795 if (_superDomain != null) 796 { 797 count = _superDomain.getDomainValueCount(); 798 if (idx < count) return _superDomain.getDomainValue(idx); 799 } 800 idx -= count; 801 return (DjDomainValue) _domainValues.get(idx); 802 } 803 804 814 public DjDomainValue getPersonalDomainValue(int idx) 815 { 816 return (DjDomainValue) _domainValues.get(idx); 817 } 818 819 826 public void removeDomainValue(int idx) 827 { 828 int count = 0; 829 if (_superDomain != null) 830 { 831 count = _superDomain.getDomainValueCount(); 832 if (idx < count) _superDomain.removeDomainValue(idx); 833 } 834 idx -= count; 835 _domainValues.remove(idx); 836 } 837 838 845 public void removePersonalDomainValue(int idx) 846 { 847 _domainValues.remove(idx); 848 } 849 850 860 public void validateValue(Object value) throws DomainViolationException 861 { 862 if (value == null) return; 863 864 if (getReValidationMask() != null) 865 { 866 String regExp = getReValidationMask().trim(); 867 try 868 { 869 RE re = new RE("^" + regExp.trim() + "$"); 870 if (!re.match(value.toString())) 871 { 872 String errMsg = getReFailureMessage(); 873 if (errMsg == null || errMsg.trim().length() == 0) 874 { 875 errMsg = Messages.getString("DjDomain.ValueInvalid"); 876 } 877 throw new DomainViolationException(errMsg); 878 } 879 } 880 catch (RESyntaxException rese) 881 { 882 throw new DomainViolationException(Messages.getString("global.CheckMask", getName(), regExp)); 883 } 884 } 885 int propType = getTypeCode(); 887 if (getLength() != 0) 888 { 889 try 890 { 891 value = coerse(value); 892 if (value == null) return; 893 } 894 catch (DjenericException de) 895 { 896 throw new DomainViolationException(de); 897 } 898 899 if (propType == DjDomain.BIGDECIMAL_TYPE) 900 { 901 BigDecimal bdv = (BigDecimal ) value; 902 if (bdv.doubleValue() >= Math.pow(10, getLength())) 903 { 904 throw new DomainViolationException(Messages.getString("DjDomain.NumericLengthExceeded", String 905 .valueOf(getLength()))); 906 } 907 } 908 else if (propType == DjDomain.STRING_TYPE) 909 { 910 if (value.toString().length() > getLength()) 911 { 912 throw new DomainViolationException(Messages.getString("DjDomain.StringLengthExceeded", String 913 .valueOf(getLength()))); 914 } 915 } 916 else if (propType == DjDomain.INT_TYPE) 917 { 918 Integer iv = (Integer ) value; 919 920 if (iv.intValue() >= Math.pow(10, getLength())) 921 { 922 throw new DomainViolationException(Messages.getString("DjDomain.NumericLengthExceeded", String 923 .valueOf(getLength()))); 924 } 925 } 926 else if (propType == DjDomain.LONG_TYPE) 927 { 928 Long lv = (Long ) value; 929 if (lv.longValue() >= Math.pow(10, getLength())) 930 { 931 throw new DomainViolationException(Messages.getString("DjDomain.NumericLengthExceeded", String 932 .valueOf(getLength()))); 933 } 934 } 935 } 936 937 if (_enforce) 938 { 939 boolean matched = false; 940 941 int valueCount = getDomainValueCount(); 942 943 if (valueCount == 0) return; 944 945 for (int i = 0; i < valueCount && !matched; i++) 946 { 947 matched = getDomainValue(i).isValid(value); 948 } 949 if (!matched) throw new DomainViolationException(Messages.getString("DjDomain.IsNotValidValue", value)); 950 } 951 } 952 953 958 public int getLength() 959 { 960 return _length; 961 } 962 963 969 public void setLength(int length) 970 { 971 _length = length; 972 } 973 974 979 public int getDecimals() 980 { 981 return _decimals; 982 } 983 984 990 public void setDecimals(int decimals) 991 { 992 _decimals = decimals; 993 } 994 995 1001 public boolean hasValidValues() 1002 { 1003 boolean has = false; 1004 if (_superDomain != null) 1005 { 1006 has |= _superDomain.hasValidValues(); 1007 } 1008 if (has) return true; 1009 has |= getDomainValueCount() > 0; 1010 return has; 1011 } 1012 1013 1021 public String translateCode(String code) 1022 { 1023 DjDomainValue[] vals = getValidValues(); 1024 for (int i = 0; i < vals.length; i++) 1025 { 1026 if (vals[i].getValue().toString().equals(code)) 1027 { 1028 String descr = vals[i].getDescription(); 1029 if (descr != null && descr.length() > 0) return descr; 1030 return code; 1031 } 1032 } 1033 return null; 1034 } 1035 1036 1045 public String translateDescription(String description) 1046 { 1047 if (description == null) return null; 1048 1049 DjDomainValue[] vals = getValidValues(); 1050 for (int i = 0; i < vals.length; i++) 1051 { 1052 String descr = vals[i].getDescription(); 1053 if (descr == null || descr.length() == 0) descr = vals[i].getValue().toString(); 1054 1055 if (descr.equals(description)) 1056 { 1057 return vals[i].getValue().toString(); 1058 } 1059 } 1060 return null; 1061 } 1062 1063 1070 public DjDomainValue[] getValidValues() 1071 { 1072 ArrayList result = new ArrayList (); 1073 1074 if (_superDomain != null) 1075 { 1076 DjDomainValue[] sups = _superDomain.getValidValues(); 1077 for (int i = 0; i < sups.length; i++) 1078 { 1079 result.add(sups[i]); 1080 } 1081 } 1082 1083 for (int i = 0; i < getPersonalDomainValueCount(); i++) 1084 { 1085 DjDomainValue dv = getPersonalDomainValue(i); 1086 if (!dv.isRange()) result.add(dv); 1087 } 1088 1089 Collections.sort(result, new DomainValueComparator()); 1090 1091 return (DjDomainValue[]) result.toArray(new DjDomainValue[0]); 1092 } 1093 1094 1099 public String toString() 1100 { 1101 return _name; 1102 } 1103 1104 1116 protected void validate(DjPersistenceManager mgr, boolean strictChecking) throws CatalogException 1117 { 1118 if (_name.trim().length() == 0) throw new CatalogException(Messages.getString("DjDomain.NameUnique")); 1119 for (int i = 0; i < mgr.getDomainCount(); i++) 1120 { 1121 if (mgr.getDomain(i) != this && mgr.getDomain(i).getName().toLowerCase().equals(getName())) 1122 { 1123 throw new CatalogException(Messages.getString("DjDomain.NameUniqueNotUnqiue", getName())); 1124 } 1125 } 1126 1127 if ((getTypeCode() != BIGDECIMAL_TYPE) && (getDecimals() != 0)) 1128 { 1129 throw new CatalogException(Messages.getString("DjDomain.ShouldNotHaveDecs", getName(), getNativeType())); 1130 } 1131 1132 if ((getTypeCode() == DATE_TYPE) && (getLength() != 0)) 1133 { 1134 throw new CatalogException(Messages.getString("DjDomain.ShouldNotHaveLen", getName())); 1135 } 1136 1137 for (int i = 0; i < getDomainValueCount(); i++) 1138 { 1139 DjDomainValue dv = getDomainValue(i); 1140 if (dv.getValue() == null) 1141 { 1142 throw new CatalogException(Messages.getString("DjDomain.DomainValueNull", getName())); 1143 } 1144 1145 if (dv.getDescription() == null || dv.getDescription().trim().length() == 0) 1146 { 1147 throw new CatalogException(Messages.getString("DjDomain.DomainValueDescrNull", (getName() + "." + dv.getValue() 1148 .toString()))); 1149 } 1150 } 1151 1152 for (int i = 0; i < getDomainValueCount(); i++) 1153 { 1154 DjDomainValue dv1 = getDomainValue(i); 1155 String code = dv1.getValue().toString(); 1156 code = dv1.getValue().toString(); 1157 1158 if (getTypeCode() == INT_TYPE || getTypeCode() == LONG_TYPE || getTypeCode() == STRING_TYPE) 1159 { 1160 if (getLength() != 0 && code.length() > getLength()) 1161 { 1162 throw new CatalogException(Messages.getString("DjDomain.DomainMaxLengthExceeded", (getName() + "." + dv1 1163 .getValue().toString()))); 1164 } 1165 } 1166 for (int j = 0; j < getDomainValueCount(); j++) 1167 { 1168 DjDomainValue dv2 = getDomainValue(j); 1169 if (dv1 != dv2 && dv1.getDescription().trim().equals(dv2.getDescription().trim())) 1170 { 1171 throw new CatalogException(Messages.getString("DjDomain.ValueDescrUnique", getName() + "." 1172 + dv1.getValue().toString())); 1173 } 1174 } 1175 } 1176 1177 if (getReValidationMask() != null) 1178 { 1179 String regExp = getReValidationMask().trim(); 1180 1181 try 1182 { 1183 RE re = new RE("^" + regExp.trim() + "$"); 1184 1185 for (int j = 0; j < getDomainValueCount(); j++) 1186 { 1187 DjDomainValue dv = getDomainValue(j); 1188 if (!re.match(dv.getValue().toString())) 1189 { 1190 throw new CatalogException(Messages.getString("DjDomain.MaskFails", getName() + "." 1191 + dv.getValue().toString())); 1192 } 1193 } 1194 } 1195 catch (RESyntaxException rese) 1196 { 1197 throw new CatalogException(Messages.getString("global.CheckMask", getName(), regExp)); 1198 } 1199 } 1200 1201 } 1210 1211 1221 public void setComponentType(String typeName) throws DjenericException 1222 { 1223 _componentType = componentType2int(typeName); 1224 } 1225 1226 1234 public void setComponentType(int type) 1235 { 1236 _componentType = type; 1237 } 1238 1239 1246 public int getComponentType() 1247 { 1248 return _componentType; 1249 } 1250 1251 1257 public String getComponentTypeName() 1258 { 1259 return int2componentType(_componentType); 1260 } 1261 1262 1271 public static String int2componentType(int componentType) 1272 { 1273 return compTypes[componentType]; 1274 } 1275 1276 1285 public static String int2nativeType(int typeCode) 1286 { 1287 return nativeTypes[typeCode]; 1288 } 1289 1290 1301 public static int componentType2int(String typeName) throws CatalogException 1302 { 1303 if (typeName == null) typeName = ""; 1304 if (typeName.length() == 0) 1305 { 1306 return COMP_TEXTFIELD; 1307 } 1308 1309 for (int i = 0; i < compTypes.length; i++) 1310 { 1311 if (compTypes[i].equalsIgnoreCase(typeName)) 1312 { 1313 return i; 1314 } 1315 } 1316 throw new CatalogException(Messages.getString("DjDomain.InvalidComponentType", typeName)); 1317 } 1318 1319 1325 public static String [] getComponentTypeNames() 1326 { 1327 return compTypes; 1328 } 1329 1330 1333 public void sort() 1334 { 1335 Collections.sort(_domainValues, new DomainValueComparator()); 1336 } 1337 1338 1346 public DjDomainValue looselyMatchValue(String value) 1347 { 1348 return looselyMatchValue(getValidValues(), value); 1349 } 1350 1351 1359 public DjDomainValue looselyMatchDescription(String value) 1360 { 1361 return looselyMatchDescription(getValidValues(), value); 1362 } 1363 1364 1374 public static DjDomainValue[] convertToValueList(DjList list) throws DjenericException 1375 { 1376 DjDomainValue[] valids = new DjDomainValue[list.size()]; 1377 for (int i = 0; i < list.size(); i++) 1378 { 1379 valids[i] = new DjDomainValue(null, list.getDjenericObjectAt(i), list.getDjenericObjectAt(i).getDescriptor()); 1380 } 1381 Arrays.sort(valids, new DomainValueDescrComparator()); 1382 return valids; 1383 } 1384 1385 1395 public static DjDomainValue looselyMatchValue(DjDomainValue[] values, String value) 1396 { 1397 if (value == null) return null; 1398 1399 for (int i = 0; i < values.length; i++) 1401 { 1402 if (values[i] == null || values[i].getValue() == null) continue; 1403 if (values[i].getValue().toString().equals(value)) return values[i]; 1404 } 1405 for (int i = 0; i < values.length; i++) 1407 { 1408 if (values[i] == null || values[i].getValue() == null) continue; 1409 if (values[i].getValue().toString().startsWith(value)) return values[i]; 1410 } 1411 for (int i = 0; i < values.length; i++) 1413 { 1414 if (values[i] == null || values[i].getValue() == null) continue; 1415 if (values[i].getValue().toString().equalsIgnoreCase(value)) return values[i]; 1416 } 1417 for (int i = 0; i < values.length; i++) 1419 { 1420 if (values[i] == null || values[i].getValue() == null) continue; 1421 if (values[i].getValue().toString().toLowerCase().startsWith(value.toLowerCase())) return values[i]; 1422 } 1423 return null; 1424 } 1425 1426 1436 public static DjDomainValue looselyMatchDescription(DjDomainValue[] values, String value) 1437 { 1438 if (value == null || value.length() == 0) return null; 1439 1440 for (int i = 0; i < values.length; i++) 1442 { 1443 String descr = values[i].getDescription(); 1444 if (descr == null) descr = ""; 1445 1446 if (descr.equals(value)) return values[i]; 1447 } 1448 for (int i = 0; i < values.length; i++) 1450 { 1451 String descr = values[i].getDescription(); 1452 if (descr == null) descr = ""; 1453 1454 if (descr.startsWith(value)) return values[i]; 1455 } 1456 for (int i = 0; i < values.length; i++) 1458 { 1459 String descr = values[i].getDescription(); 1460 if (descr == null) descr = ""; 1461 1462 if (descr.equalsIgnoreCase(value)) return values[i]; 1463 } 1464 for (int i = 0; i < values.length; i++) 1466 { 1467 String descr = values[i].getDescription(); 1468 if (descr == null) descr = ""; 1469 1470 if (descr.toLowerCase().startsWith(value.toLowerCase())) return values[i]; 1471 } 1472 return null; 1473 } 1474 1475 public static boolean isMemoComponent(int type) 1476 { 1477 return type == COMP_MEMO || type == COMP_HTML_MEMO || type == COMP_CUSTOM_MEMO; 1478 } 1479 1480 public String getReFailureMessage() 1481 { 1482 return _reFailureMessage; 1483 } 1484 1485 public String getReValidationMask() 1486 { 1487 return _reValidationMask; 1488 } 1489 1490 public void setReFailureMessage(String msg) 1491 { 1492 if (msg != null && msg.trim().length() == 0) msg = null; 1493 _reFailureMessage = msg; 1494 } 1495 1496 public void setReValidationMask(String mask) 1497 { 1498 if (mask != null && mask.trim().length() == 0) mask = null; 1499 _reValidationMask = mask; 1500 } 1501 1502 public String getCaseConversion() 1503 { 1504 return _caseConversion; 1505 } 1506 1507 public void setCaseConversion(String caseConversion) 1508 { 1509 _caseConversion = caseConversion; 1510 } 1511 1512 public boolean hasListValues() 1513 { 1514 boolean has = false; 1515 if (_superDomain != null) 1516 { 1517 has |= _superDomain.hasListValues(); 1518 } 1519 if (has) return true; 1520 for (int i = 0; !has && i < getDomainValueCount(); i++) 1521 { 1522 has = getDomainValue(i).getHigh() == null; 1523 } 1524 return has; 1525 } 1526 1527 public boolean isDynamic() 1530 { 1531 return _isDynamic; 1532 } 1533 1534 public void setDynamic(boolean isDynamic) 1535 { 1536 _isDynamic = isDynamic; 1537 } 1538 1539 public DjPackage getPackage() 1540 { 1541 return _package; 1542 } 1543 1544 public void setPackage(DjPackage pack) 1545 { 1546 _package = pack; 1547 } 1548 1549} | Popular Tags |