1 19 package org.openharmonise.rm.metadata; 20 21 import java.sql.*; 22 import java.util.*; 23 import java.util.logging.*; 24 25 import org.openharmonise.commons.cache.*; 26 import org.openharmonise.commons.dsi.*; 27 import org.openharmonise.commons.dsi.dml.*; 28 import org.openharmonise.commons.xml.XMLUtils; 29 import org.openharmonise.rm.*; 30 import org.openharmonise.rm.dsi.DataStoreObject; 31 import org.openharmonise.rm.factory.*; 32 import org.openharmonise.rm.publishing.*; 33 import org.openharmonise.rm.resources.*; 34 import org.openharmonise.rm.resources.lifecycle.EditException; 35 import org.openharmonise.rm.resources.metadata.properties.*; 36 import org.openharmonise.rm.resources.metadata.properties.domains.Domain; 37 import org.openharmonise.rm.resources.publishing.Template; 38 import org.w3c.dom.*; 39 40 41 49 public abstract class AbstractPropertyInstance 50 implements Cloneable , DataStoreObject, Publishable { 51 52 55 private String m_sVersionComment; 56 57 61 protected static final String EXT_HIST = "_hist"; 62 63 67 private static final String [] saValidOperators = 68 { 69 ">", 70 "<", 71 "=", 72 ">=", 73 "<=", 74 "!=", 75 "<>", 76 "IN", 77 "CONTAINS", 78 "BETWEEN", 79 "STARTS_WITH", 80 "LOGINEQUALS", 81 "LOGINNOT", 82 "NOT IN", 83 "NULL" }; 84 85 89 protected static final String CLMN_ID = "id"; 90 91 94 protected static final String CLMN_PROFILE_ID = "profile_id"; 95 96 99 protected static final String CLMN_PROPERTY_ID = "property_id"; 100 101 104 protected static final String CLMN_VERSION_COMMENT = "version_comment"; 105 106 109 protected static final String SEQ_PROFILE_DATA = "seq_profile_data"; 110 111 115 public static final String ATTRIB_OBJECT_TYPE = "objectType"; 116 117 120 public static final String ATTRIB_PROPERTY_ID = "propId"; 121 122 125 public static final String ATTRIB_OPERATOR = "operator"; 126 127 130 public static final String TAG_PROP_INSTANCE_VALUES = 131 "PropertyInstanceValues"; 132 135 public static final String TAG_PROPERTYINSTANCE = "PropertyInstance"; 136 137 140 public static final String TAG_VALUE = "Value"; 141 142 145 public static final String TAG_ATTACH = "Attach"; 146 147 150 public static final String TAG_DETACH = "Detach"; 151 152 156 protected Profile m_profile = null; 159 160 164 protected CachePointer m_property_ptr = null; 165 166 169 protected List m_values = null; 170 171 175 protected List m_values2Add = null; 176 177 181 protected List m_values2Remove = null; 182 183 187 protected List m_valueIds = null; 188 189 192 protected String m_sOperator = "="; 193 194 198 protected boolean m_bIsTemporary = false; 199 200 203 protected AbstractDataStoreInterface m_dsi = null; 204 205 209 private boolean m_bIsChanged = false; 210 211 215 private boolean m_bIsPopulated = false; 216 217 221 private boolean m_bIsHistorical = false; 222 223 226 protected String m_sDataTable = null; 227 228 231 private static final String CONST_UNKNOWN = "unknown"; 232 233 236 private static final Logger m_logger = Logger.getLogger(AbstractPropertyInstance.class.getName()); 237 238 { 240 m_values = new Vector(); 241 m_valueIds = new Vector(); 242 m_values2Add = new Vector(); 243 m_values2Remove = new Vector(); 244 } 245 246 249 public AbstractPropertyInstance() { 250 } 251 252 257 public AbstractPropertyInstance(AbstractDataStoreInterface dbint) { 258 m_dsi = dbint; 259 } 260 261 269 public AbstractPropertyInstance( 270 AbstractDataStoreInterface dbintrf, 271 Profile profile) { 272 this(dbintrf); 273 m_profile = profile; 274 setDBTable(profile); 275 } 276 277 284 public AbstractPropertyInstance( 285 AbstractDataStoreInterface dbintrf, 286 Property prop) { 287 this(dbintrf); 288 289 try { 290 m_property_ptr = 291 CacheHandler.getInstance(m_dsi).getCachePointer(prop); 292 } catch (CacheException e) { 293 m_logger.log(Level.WARNING, e.getLocalizedMessage(), e); 294 } 295 } 296 297 307 public AbstractPropertyInstance( 308 AbstractDataStoreInterface dbintrf, 309 int nPropertyId, 310 Profile profile) { 311 this(dbintrf); 312 Property prop = new Property(dbintrf, nPropertyId); 313 try { 314 m_property_ptr = 315 CacheHandler.getInstance(m_dsi).getCachePointer(prop); 316 } catch (CacheException e) { 317 m_logger.log(Level.WARNING, e.getLocalizedMessage(), e); 318 } 319 m_profile = profile; 320 setDBTable(profile); 321 } 322 323 333 public AbstractPropertyInstance( 334 AbstractDataStoreInterface dbintrf, 335 Property property, 336 Profile profile) { 337 this(dbintrf, property); 338 m_profile = profile; 339 setDBTable(profile); 340 } 341 342 347 abstract protected void setDBTable(Profile profile); 348 349 356 public Property getProperty() throws DataAccessException { 357 Property prop = null; 358 try { 359 if (m_property_ptr != null) { 360 prop = (Property) m_property_ptr.getObject(); 361 362 if(prop.exists() == false) { 363 m_logger.logp(Level.INFO, this.getClass().getName(), "getProperty", "Property " + m_property_ptr.getKey() + " for property instance no longer exists"); 364 prop = null; 365 } 366 } 367 368 } catch (CacheException e) { 369 throw new DataAccessException(e.getLocalizedMessage(), e); 370 } 371 372 return prop; 373 } 374 375 382 public void setProperty(Property prop) throws PopulateException { 383 try { 384 m_property_ptr = 385 CacheHandler.getInstance(m_dsi).getCachePointer(prop); 386 } catch (CacheException e) { 387 throw new PopulateException(e.getLocalizedMessage(), e); 388 } 389 } 390 391 398 public void setProfile(Profile prof) { 399 this.m_profile = prof; 400 setDBTable(prof); 401 } 402 403 409 public Profile getProfile() { 410 return m_profile; 411 } 412 413 419 public boolean isTemporary() { 420 return m_bIsTemporary; 421 } 422 423 430 public void setIsTemporary(boolean bIsTemporary) { 431 m_bIsTemporary = bIsTemporary; 432 } 433 434 439 public void setVersionComment(String sComment) { 440 m_sVersionComment = sComment; 441 } 442 443 448 public String getVersionComment() { 449 return m_sVersionComment; 450 } 451 452 458 public String getOperator() { 459 return m_sOperator; 460 } 461 462 471 public String getName() throws DataAccessException { 472 String sName = null; 473 Property prop = getProperty(); 474 475 if(prop != null) { 476 sName = prop.getName(); 477 } 478 479 return sName; 480 } 481 482 485 public String getDBTableName() { 486 487 return m_sDataTable; 488 } 489 490 497 public void setOperator(String sOperator) { 498 m_sOperator = sOperator; 499 } 500 501 506 public List getValues() { 507 return m_values; 508 } 509 510 515 public void setValues(List values) throws InvalidPropertyValueException { 516 m_values = new Vector(); 517 m_values.addAll(values); 518 519 if (values.size() != 0) { 520 if (m_bIsPopulated == true) { 521 setIsChanged(true); 522 } 523 } 524 } 525 526 531 public void removeValue(Object val) { 532 if (m_values != null && m_values.contains(val) == true) { 533 m_values.remove(val); 534 535 if (m_bIsPopulated == true) { 536 setIsChanged(true); 537 m_values2Remove.add(val); 538 } 539 } 540 } 541 542 549 public Object getValue() { 550 Object objReturn = null; 551 552 if (m_values != null && m_values.size() > 0) { 553 objReturn = m_values.get(0); 554 } 555 556 return objReturn; 557 } 558 559 562 public void clearValues() { 563 if (m_values != null) { 564 m_values.clear(); 565 } 566 } 567 568 573 public boolean hasValues() { 574 boolean bReturn = true; 575 576 if ((m_values == null) || (m_values.size() == 0)) { 577 bReturn = false; 578 } 579 580 return bReturn; 581 } 582 583 589 public Object getValue(int nIndex) { 590 Object objReturn = null; 591 592 if (m_values != null) { 593 if (m_values.size() > nIndex) { 594 objReturn = m_values.get(nIndex); 595 } 596 } 597 598 return objReturn; 599 } 600 601 606 public boolean merge(AbstractPropertyInstance property) { 607 boolean bReturn = false; 608 609 if (m_property_ptr.equals(property.m_property_ptr)) { 610 int nNumberValues = property.getValues().size(); 611 612 for (int i = 0; i < nNumberValues; i++) { 613 if (m_values.contains(property.getValue(i)) == false) { 614 m_values.add(property.getValue(i)); 615 bReturn = true; 616 } 617 } 618 } 619 620 return bReturn; 621 } 622 623 624 627 public boolean equals(Object obj) { 628 boolean bRtn = false; 629 630 AbstractPropertyInstance propInstance = (AbstractPropertyInstance) obj; 631 632 if ((propInstance.hasValues() == false) 633 && (this.hasValues() == false)) { 634 bRtn = true; 635 } else if (propInstance.hasValues() != this.hasValues()) { 636 bRtn = false; 637 } else { 638 if (m_property_ptr.equals(propInstance.m_property_ptr)) { 639 List vLocalValues = this.getValues(); 640 List vRemoteValues = propInstance.getValues(); 641 642 if (vLocalValues.containsAll(vRemoteValues) 643 && vRemoteValues.containsAll(vLocalValues)) { 644 bRtn = true; 645 } 646 } 647 } 648 649 return bRtn; 650 } 651 652 661 abstract public boolean match(AbstractPropertyInstance propInst) 662 throws ProfileException; 663 664 667 public Object clone() { 668 669 AbstractPropertyInstance other = null; 670 try { 673 674 other = (AbstractPropertyInstance) super.clone(); 675 676 if (m_values != null) { 678 679 other.m_values = new Vector(); 680 681 Iterator iter = m_values.iterator(); 682 683 while (iter.hasNext()) { 684 Object objVal = (Object ) iter.next(); 685 686 if (objVal instanceof AbstractObject) { 687 other.m_values.add(((AbstractObject) objVal).clone()); 688 } else { 689 other.m_values.add(objVal); 690 } 691 } 692 693 if (m_valueIds != null) { 694 other.setValueIds(m_valueIds); 695 } 696 } 697 698 if (m_values2Add != null) { 699 other.m_values2Add = new Vector(m_values2Add); 700 } 701 702 if (m_values2Remove != null) { 703 other.m_values2Remove = new Vector(m_values2Remove); 704 } 705 } catch (CloneNotSupportedException cu_e) { 706 m_logger.log(Level.WARNING, cu_e.getLocalizedMessage(), cu_e); 707 throw new IllegalStateException ( 708 "Problem occured during clone:" + cu_e.getLocalizedMessage()); 709 } 710 711 return other; 712 } 713 714 717 public ColumnRef getInstanceColumnRef(String sColumn, boolean bIsHist) 718 throws DataStoreException { 719 ColumnRef returnColRef = null; 720 String sDBTable = getDBTableName(); 721 722 if (sColumn.equals(AbstractObject.ATTRIB_ID) == true 723 || sColumn.equals(CLMN_ID) == true) { 724 returnColRef = new ColumnRef(sDBTable, CLMN_ID, ColumnRef.NUMBER); 725 } else if ( 726 sColumn.equals(CLMN_PROFILE_ID) == true 727 || sColumn.equals(Profile.TAG_PROFILE) == true) { 728 returnColRef = 729 new ColumnRef(sDBTable, CLMN_PROFILE_ID, ColumnRef.NUMBER); 730 } else if ( 731 sColumn.equals(CLMN_PROPERTY_ID) == true 732 || sColumn.equals(Property.TAG_PROPERTY) == true) { 733 returnColRef = 734 new ColumnRef(sDBTable, CLMN_PROPERTY_ID, ColumnRef.NUMBER); 735 } else if ( 736 sColumn.equals(AbstractEditableObject.TAG_VERSION_COMMENT) == true 737 || sColumn.equals(CLMN_VERSION_COMMENT) == true) { 738 returnColRef = 739 new ColumnRef(sDBTable, CLMN_VERSION_COMMENT, ColumnRef.TEXT); 740 } 741 742 if (returnColRef != null) { 743 return returnColRef; 744 } else { 745 throw new InvalidColumnReferenceException(sColumn); 746 } 747 } 748 749 752 public Element publish(Template template, HarmoniseOutput xmlDoc, State state) 753 throws PublishException { 754 Element resultEl = null; 755 756 try { 757 758 resultEl = 759 publish(template.getTemplateRootElement(), xmlDoc, state); 760 } catch (Exception e) { 761 throw new PublishException( 762 "Error occured while publishing",e); 763 } 764 765 return resultEl; 766 } 767 768 771 public Element publish(Element formEl, HarmoniseOutput xmlDoc, State state) 772 throws PublishException { 773 774 Element el = null; 775 776 String sTagname = formEl.getTagName(); 777 778 if (sTagname.equals(TAG_PROPERTYINSTANCE) == true) { 779 780 el = xmlDoc.createElement(TAG_PROPERTYINSTANCE); 781 String sPropName = CONST_UNKNOWN; 782 try { 783 sPropName = getProperty().getName(); 784 } catch (DataAccessException da_e) { 785 m_logger.log(Level.WARNING, da_e.getLocalizedMessage(), da_e); 786 sPropName = CONST_UNKNOWN; 787 } 788 Property prop = null; 789 790 try { 791 prop = getProperty(); 792 el.setAttribute(AbstractObject.ATTRIB_NAME, sPropName); 793 el.setAttribute( 794 AbstractObject.ATTRIB_ID, 795 (String ) m_property_ptr.getKey()); 796 797 el.setAttribute( 798 ATTRIB_OBJECT_TYPE, 799 prop.getRange().getObject()); 800 } catch (DataAccessException e) { 801 throw new PublishException( 802 "Error occured acessing range object:" 803 + e.getLocalizedMessage()); 804 } 805 806 Vector vIgnoreTags = new Vector(); 808 vIgnoreTags.add(TAG_PROP_INSTANCE_VALUES); 809 vIgnoreTags.add(Property.TAG_PROPERTY); 810 xmlDoc.copyChildren(el, formEl, vIgnoreTags); 811 812 NodeList nodes = formEl.getChildNodes(); 814 815 for (int i = 0; i < nodes.getLength(); i++) { 816 if (nodes.item(i).getNodeType() == Node.ELEMENT_NODE) { 817 Element tempEl = (Element) nodes.item(i); 818 el.appendChild(publish(tempEl, xmlDoc, state)); 819 } 820 } 821 822 } else if (sTagname.equals(Property.TAG_PROPERTY)) { 823 824 825 try { 826 Property prop = getProperty(); 827 828 if(prop != null) { 829 Element templateEl = (Element) XMLUtils.getFirstNamedChild(formEl, Template.TAG_TEMPLATE); 830 831 Template template = null; 832 if(templateEl != null) { 833 try { 834 template = 835 (Template) HarmoniseObjectFactory.instantiateHarmoniseObject( 836 m_dsi, 837 templateEl, 838 state); 839 } catch (HarmoniseFactoryException e) { 840 throw new PublishException(e.getLocalizedMessage(),e); 841 } 842 } 843 844 if(template != null) { 845 el = prop.publish(template, xmlDoc, state); 846 } else { 847 el = xmlDoc.createElement(Property.TAG_PROPERTY); 848 849 el.setAttribute(AbstractObject.ATTRIB_ID, String.valueOf(prop.getId())); 850 851 Element nameEl = xmlDoc.createElement(AbstractObject.TAG_NAME); 852 853 nameEl.appendChild(xmlDoc.createTextNode(prop.getName())); 854 855 el.appendChild(nameEl); 856 857 Element displayNameEl = xmlDoc.createElement(AbstractChildObject.TAG_DISPLAY_NAME); 858 859 displayNameEl.appendChild(xmlDoc.createTextNode(prop.getDisplayName())); 860 861 el.appendChild(displayNameEl); 862 } 863 } else { 864 el = xmlDoc.createElement(Property.TAG_PROPERTY); 865 } 866 } catch (DataAccessException e) { 867 throw new PublishException(e.getLocalizedMessage(),e); 868 } 869 } 870 871 return el; 872 } 873 874 877 public void populate(Element xmlElement, State state) 878 throws PopulateException { 879 String sTagName = xmlElement.getTagName(); 880 881 try { 882 if (sTagName.equals(TAG_PROPERTYINSTANCE) == true) { 883 String sOperator = xmlElement.getAttribute(ATTRIB_OPERATOR); 884 886 if (sOperator != null && sOperator.length() > 0) { 887 setOperator(sOperator); 889 } 890 891 NodeList nodes = xmlElement.getChildNodes(); 893 894 for (int i = 0; i < nodes.getLength(); i++) { 895 if (nodes.item(i).getNodeType() != Node.ELEMENT_NODE) { 896 continue; 897 } 898 899 Element el = (Element) nodes.item(i); 900 populate(el, state); 901 } 902 } else if (sTagName.equals(Property.TAG_PROPERTY) == true) { 903 Element nameElm = 904 XMLUtils.getFirstNamedChild( 905 xmlElement, 906 AbstractObject.TAG_NAME); 907 Property prop = null; 908 909 if (nameElm != null) { 910 String sPropName = nameElm.getFirstChild().getNodeValue(); 911 prop = 913 PropertyFactory.getPropertyFromName(m_dsi, sPropName); 914 } else { 915 prop = 916 ( 917 Property) HarmoniseObjectFactory 918 .instantiatePublishableObject( 919 m_dsi, 920 xmlElement, 921 state); 922 } 923 924 prop.populate(xmlElement, state); 925 setProperty(prop); 927 } else if (sTagName.equals(TAG_PROP_INSTANCE_VALUES) == true) { 929 populate(xmlElement, state); 930 } else { 931 throw new PopulateException("Invalid Tag name: " + sTagName); 932 } 933 } catch (HarmoniseFactoryException e) { 934 throw new PopulateException( 935 "Error getting property from factory:", 936 e); 937 } 938 } 939 940 943 944 956 protected void save(Profile prof) throws ProfileException, EditException { 957 if ((m_bIsTemporary == false) && hasValues() == true) { 958 setDBTable(prof); 960 961 ResultSet rs = null; 962 InsertStatement insert = new InsertStatement(); 963 int i = 0; 964 String sTable = getDBTableName(); 965 boolean bIsHist = isHistorical(); 966 967 int nId = 0; 968 969 m_valueIds.clear(); 970 971 for (i = 0; i < m_values.size(); i++) { 972 Object objVal = m_values.get(i); 973 974 insert.clear(); 975 try { 976 if (i >= m_valueIds.size()) { 977 nId = m_dsi.getSequenceNextValue(SEQ_PROFILE_DATA); 978 979 m_valueIds.add(new Integer (nId)); 980 } else { 981 982 nId = ((Integer ) m_valueIds.get(i)).intValue(); 983 984 } 985 986 int nPropId = getProperty().getId(); 987 int nProfId = prof.getId(); 988 989 991 if (nPropId <= 0) { 992 throw new InvalidPropertyInstanceException( 993 "Property had invalid id - " 994 + m_property_ptr.getKey()); 995 } 996 997 if (nProfId <= 0) { 998 throw new InvalidPropertyInstanceException( 999 "Profile had invalid id - " + nProfId); 1000 } 1001 1002 insert.setTable(sTable); 1003 1004 insert.addColumnValue( 1005 this.getInstanceColumnRef(CLMN_PROFILE_ID, bIsHist), 1006 nProfId); 1007 insert.addColumnValue( 1008 this.getInstanceColumnRef(CLMN_PROPERTY_ID, bIsHist), 1009 nPropId); 1010 insert.addColumnValue( 1011 this.getInstanceColumnRef(CLMN_ID, bIsHist), 1012 nId); 1013 insert.addColumnValue( 1014 this.getColumnForData(), 1015 this.getValueToStoreForValue(objVal)); 1016 if (m_sVersionComment != null) { 1017 1018 insert.addColumnValue( 1019 getInstanceColumnRef( 1020 AbstractEditableObject.TAG_VERSION_COMMENT, 1021 bIsHist), 1022 m_sVersionComment); 1023 } 1024 1025 m_dsi.execute(insert); 1026 1027 } catch (DataStoreException e) { 1028 throw new ProfileException( 1029 "Error occurred processing insert", 1030 e); 1031 } catch (SQLException sql_e) { 1032 throw new ProfileException( 1033 "Error occurred processing insert", 1034 sql_e); 1035 } catch (DataAccessException e) { 1036 throw new ProfileException( 1037 "Error occurred processing insert", 1038 e); 1039 } 1040 } 1041 1042 m_values2Add.clear(); 1043 m_values2Remove.clear(); 1044 1045 m_bIsChanged = false; 1046 m_bIsPopulated = true; 1047 } 1048 } 1049 1050 1057 protected void update(Profile prof) 1058 throws ProfileException, EditException { 1059 1060 if (isPopulated() == true && isChanged() == true) { 1061 InsertStatement insert = new InsertStatement(); 1062 DeleteStatement delete = new DeleteStatement(); 1063 1064 int i = 0; 1065 String sTable = getDBTableName(); 1066 1067 boolean bIsHist = isHistorical(); 1068 int nId = 0; 1070 for (i = 0; i < m_values2Add.size(); i++) { 1072 Object objVal = m_values2Add.get(i); 1073 1074 insert.clear(); 1075 1076 try { 1077 if (isHistorical() == false) { 1078 nId = m_dsi.getSequenceNextValue(SEQ_PROFILE_DATA); 1079 1080 m_valueIds.add(new Integer (nId)); 1081 } else { 1082 1083 nId = ((Integer ) m_valueIds.get(i)).intValue(); 1084 1085 } 1086 1087 insert.setTable(sTable); 1088 1089 insert.addColumnValue( 1090 this.getInstanceColumnRef(CLMN_PROFILE_ID, bIsHist), 1091 prof.getId()); 1092 insert.addColumnValue( 1093 this.getInstanceColumnRef(CLMN_PROPERTY_ID, bIsHist), 1094 getProperty().getId()); 1095 insert.addColumnValue( 1096 this.getInstanceColumnRef(CLMN_ID, bIsHist), 1097 nId); 1098 insert.addColumnValue( 1099 this.getColumnForData(), 1100 this.getValueToStoreForValue(objVal)); 1101 if (m_sVersionComment != null) { 1102 1103 insert.addColumnValue( 1104 getInstanceColumnRef( 1105 AbstractEditableObject.TAG_VERSION_COMMENT, 1106 bIsHist), 1107 m_sVersionComment); 1108 } 1109 1110 m_dsi.execute(insert); 1111 1112 } catch (DataStoreException e) { 1113 throw new ProfileException( 1114 "Error occurred processing insert", 1115 e); 1116 } catch (SQLException sql_e) { 1117 throw new ProfileException( 1118 "Error occurred processing insert", 1119 sql_e); 1120 } catch (DataAccessException e) { 1121 throw new ProfileException( 1122 "Error occurred processing insert", 1123 e); 1124 } 1125 } 1126 1127 for (i = 0; i < m_values2Remove.size(); i++) { 1128 Object objVal = m_values2Remove.get(i); 1129 1130 delete.clear(); 1131 1132 try { 1133 delete.setTable(sTable); 1134 1135 delete.addWhereCondition( 1136 getColumnForData(), 1137 "=", 1138 getValueToStoreForValue(objVal)); 1139 1140 delete.addWhereCondition( 1141 this.getInstanceColumnRef(CLMN_PROFILE_ID, bIsHist), 1142 "=", 1143 prof.getId()); 1144 1145 m_dsi.execute(delete); 1146 } catch (DataStoreException e) { 1147 throw new ProfileException( 1148 "Error occurred processing insert", 1149 e); 1150 } 1151 } 1152 } else if (isPopulated() == false) { 1153 save(prof); 1155 } 1156 1157 m_values2Add.clear(); 1158 m_values2Remove.clear(); 1159 1160 m_bIsChanged = false; 1161 m_bIsPopulated = true; 1162 1163 } 1164 1165 1172 protected void setIsChanged(boolean bIsChanged) { 1173 m_bIsChanged = true; 1174 } 1175 1176 1182 protected boolean isChanged() { 1183 return m_bIsChanged; 1184 } 1185 1186 1192 protected boolean isHistorical() { 1193 return m_bIsHistorical; 1194 } 1195 1196 1202 protected void setHistorical(boolean bIsHist) { 1203 m_bIsHistorical = bIsHist; 1204 1205 } 1206 1207 1214 protected void addValue(Object obj) throws PopulateException { 1215 if ((m_values.contains(obj) == false)) { 1216 1217 if(m_logger.isLoggable(Level.FINE)) { 1218 1219 try { 1220 StringBuffer sbuf = new StringBuffer (); 1221 1222 sbuf.append("adding value ") 1223 .append(obj) 1224 .append(" to property instance ") 1225 .append(getName()); 1226 1227 AbstractProfiledObject profObj = getProfiledObject(); 1228 1229 if(profObj != null) { 1230 sbuf.append("for ") 1231 .append(profObj.getClass().getName()) 1232 .append(" ") 1233 .append(profObj.getKey()); 1234 } 1235 1236 m_logger.logp(Level.FINE, this.getClass().getName(),"addValue",sbuf.toString()); 1237 } catch (DataAccessException e) { 1238 m_logger.log(Level.WARNING, e.getLocalizedMessage(), e); 1239 } 1240 } 1241 1242 if (m_profile != null) { 1250 AbstractProfiledObject profObj = m_profile.getProfiledObject(); 1251 1252 try { 1253 Property prop = getProperty(); 1254 Domain domain = prop.getDomain(profObj); 1255 1256 if (domain != null) { 1257 int nMax = domain.getMaxOccurs(); 1258 1259 if (nMax > 0 && m_values.size() >= nMax) { 1260 String sPropName = prop.getName(); 1261 1262 if(m_logger.isLoggable(Level.INFO)) { 1263 StringBuffer sbuf = new StringBuffer (); 1264 1265 sbuf.append("Have reached maximum number of values for this property - ") 1266 .append(sPropName) 1267 .append(" on object "); 1268 1269 if(profObj != null) { 1270 sbuf.append(profObj.getClass().getName()) 1271 .append(" key - ") 1272 .append(profObj.getKey()); 1273 } 1274 1275 m_logger.logp(Level.INFO, this.getClass().getName(),"addValue",sbuf.toString()); 1276 1277 } 1278 1279 throw new InvalidPropertyValueException("Have reached maximum number of values for this property - " + sPropName); 1280 } 1281 } 1282 } catch (DataAccessException e) { 1283 if(m_logger.isLoggable(Level.WARNING)) { 1284 StringBuffer sbuf = new StringBuffer (); 1285 1286 sbuf.append("Have reached maximum number of values for a property") 1287 .append(" on object "); 1288 1289 if(profObj != null) { 1290 try { 1291 sbuf.append(profObj.getClass().getName()) 1292 .append(" key - ") 1293 .append(profObj.getKey()); 1294 } catch (DataAccessException e1) { 1295 m_logger.log(Level.WARNING, e1.getLocalizedMessage(), e1); 1296 } 1297 } 1298 1299 m_logger.logp(Level.WARNING, this.getClass().getName(),"addValue",sbuf.toString()); 1300 1301 } 1302 1303 throw new PopulateException( 1304 "Had problem getting domain for this profiled object - " 1305 + profObj.getClass().getName(), 1306 e); 1307 } 1308 } 1309 1310 m_values.add(obj); 1311 1312 if (m_bIsPopulated == true) { 1313 1314 setIsChanged(true); 1315 m_values2Add.add(obj); 1316 } 1317 } 1318 } 1319 1320 1330 protected void addValue(Object val, int nId) 1331 throws PopulateException { 1332 if (val != null) { 1333 if (m_values == null) { 1334 m_values = new Vector(); 1335 } 1336 1337 if (m_valueIds == null) { 1338 m_valueIds = new Vector(); 1339 } 1340 1341 addValue(val); 1342 m_valueIds.add(new Integer (nId)); 1343 } 1344 } 1345 1346 1352 protected void setIsPopulated(boolean bIsPopulated) { 1353 m_bIsPopulated = bIsPopulated; 1354 m_bIsChanged = false; 1355 } 1356 1357 1370 abstract protected ColumnRef getColumnForData() throws DataStoreException; 1371 1372 1382 abstract protected Object getValueToStoreForValue(Object val) 1383 throws ProfileException; 1384 1385 1388 1389 1397 private void setValueIds(List valueIds) { 1398 m_valueIds = new Vector(); 1399 1400 m_valueIds.addAll(valueIds); 1401 } 1402 1403 1406 public String getTagName() { 1407 return TAG_PROPERTYINSTANCE; 1408 } 1409 1410 1417 public boolean isPopulated() { 1418 return m_bIsPopulated; 1419 } 1420 1421 1426 public void setDataStoreInterface(AbstractDataStoreInterface dsi) { 1427 m_dsi = dsi; 1428 1429 } 1430 1431 1438 protected AbstractProfiledObject getProfiledObject() { 1439 AbstractProfiledObject profObj = null; 1440 1441 if(m_profile != null) { 1442 profObj = m_profile.getProfiledObject(); 1443 } 1444 return profObj; 1445 } 1446 1447 1450 public int getId() { 1451 return -1; 1454 } 1455 1456} | Popular Tags |