1 19 package org.openharmonise.rm.resources.metadata.properties.domains; 20 21 import java.sql.*; 22 import java.util.*; 23 import java.util.logging.*; 24 25 import org.openharmonise.commons.dsi.*; 26 import org.openharmonise.commons.dsi.dml.*; 27 import org.openharmonise.commons.dsi.dml.functions.*; 28 import org.openharmonise.commons.xml.XMLUtils; 29 import org.openharmonise.rm.*; 30 import org.openharmonise.rm.factory.*; 31 import org.openharmonise.rm.publishing.*; 32 import org.openharmonise.rm.resources.*; 33 import org.openharmonise.rm.resources.lifecycle.EditException; 34 import org.openharmonise.rm.resources.metadata.properties.Property; 35 import org.openharmonise.rm.resources.publishing.Template; 36 import org.w3c.dom.*; 37 38 39 50 public class Domain implements Publishable, Cloneable { 51 52 55 public String TAG_PATHRESTRICTION = "PathRestriction"; 56 57 60 public static final int UNBOUNDED = -1; 61 62 66 public static final String TAG_DOMAIN = "Domain"; 67 68 71 public static final String TAG_DOMAIN_OBJECT = "DomainObject"; 72 73 76 public static final String TAG_DOMAIN_DETAILS = "DomainDetails"; 77 80 public static final String TAG_PATH = "Path"; 81 84 public static final String TAG_CONTENT_RESTRICTIONS = "ContentRestrictions"; 85 88 public static final String ATTRIB_MIN_OCCURS = "minOccurs"; 89 90 93 public static final String ATTRIB_MAX_OCCURS = "maxOccurs"; 94 95 98 public static final String ATTRIB_DEPTH = "depth"; 99 100 104 public static final String SEQ_DOMAIN = "seq_property_domain"; 105 106 109 public static final String TBL_NAME = "property_domain"; 110 111 114 public static final String TBL_DOMAIN_DETAILS = "domain_details"; 115 116 119 public static final String TBL_DOMAIN_CONTENT_RESTRICTIONS = "domain_content_details"; 120 121 124 public static final String CLMN_DOMAIN_ID = "id"; 125 126 129 public static final String CLMN_DETAILS_DOMAIN_ID = "domain_id"; 130 131 134 public static final String CLMN_CONTENT_TYPE = "content_type"; 135 136 139 public static final String CLMN_DOMAIN_OBJECT = "domain_object"; 140 141 144 public static final String CLMN_DOMAIN_DETAILS = "domain_details"; 145 146 149 public static final String CLMN_PROPERTY_KEY = "property_key"; 150 151 154 public static final String CLMN_MIN_OCCURS = "minOccurs"; 155 156 159 public static final String CLMN_MAX_OCCURS = "maxOccurs"; 160 161 164 public static final String CLMN_DEPTH = "depth"; 165 166 169 public static Map m_child_parent_mappings = new Hashtable(); 170 171 174 private int m_nId = -1; 175 176 179 private String m_sObjectName = null; 180 181 186 private List m_details = null; 187 188 192 private List m_contentRestrictions = null; 193 194 198 private int m_nMinOccurs = 0; 199 200 206 private int m_nMaxOccurs = -1; 207 208 212 private boolean m_bIsDetailsPopulated = false; 213 214 218 private boolean m_bIsContentRestrictPopulated = false; 219 220 223 private boolean m_bIsHistorical = false; 224 225 228 private AbstractDataStoreInterface m_dsi = null; 229 230 235 private int m_nDepth = -1; 236 237 241 private boolean m_bIsChanged = false; 242 243 246 private static final Logger m_logger = Logger.getLogger(Domain.class.getName()); 247 248 253 public Domain() { 254 } 255 256 261 public Domain(AbstractDataStoreInterface dsi) { 262 m_dsi = dsi; 263 } 264 265 272 public Domain(AbstractDataStoreInterface dsi, String sClassName) { 273 m_dsi = dsi; 274 m_sObjectName = sClassName; 275 } 276 277 284 public Domain(AbstractDataStoreInterface dsi, int nId) { 285 m_dsi = dsi; 286 m_nId = nId; 287 } 288 289 293 public void markAsNew() { 294 m_nId = -1; 295 } 296 297 302 public int getId() { 303 return m_nId; 304 } 305 306 311 public void setId(int nId) { 312 m_nId = nId; 313 } 314 315 320 public int getDepth() { 321 return m_nDepth; 322 } 323 324 329 public void setDepth(int nDepth) { 330 m_nDepth = nDepth; 331 } 332 333 338 public String getDomainClass() { 339 return m_sObjectName; 340 } 341 342 347 public void setDomainClass(String objectName) { 348 this.m_sObjectName = objectName; 349 } 350 351 358 public List getDetails() throws DataAccessException { 359 if (m_bIsDetailsPopulated == false) { 360 try { 361 populateDetails(); 362 } catch (DataStoreException e) { 363 throw new DataAccessException("Error populating details", e); 364 } 365 } 366 367 try { 368 List detailsToRemove = new ArrayList(); 369 370 ListIterator iter = m_details.listIterator(); 371 372 String domainClassName = getDomainClass(); 373 String parentClassName = domainClassName; 374 375 Class domainClass = Class.forName(domainClassName); 376 377 if(AbstractParentObject.class.isAssignableFrom(domainClass) == false) { 378 379 parentClassName = (String ) m_child_parent_mappings.get(domainClass); 380 381 if(parentClassName == null) { 382 parentClassName = ((AbstractChildObject)domainClass.newInstance()).getParentObjectClassName(); 383 m_child_parent_mappings.put(domainClass, parentClassName); 384 } 385 386 } 387 388 while (iter.hasNext()) { 389 String sDetail = (String ) iter.next(); 390 AbstractObject obj = HarmoniseObjectFactory.instantiateHarmoniseObject(m_dsi,parentClassName, sDetail); 391 392 if(obj == null || obj.exists() == false) { 393 detailsToRemove.add(sDetail); 394 iter.remove(); 395 } 396 } 397 398 if(detailsToRemove.size() > 0) { 399 DeleteStatement delete = new DeleteStatement(); 400 401 delete.addWhereCondition(getDetailsColumnRef(CLMN_DOMAIN_DETAILS, m_bIsHistorical), "IN", detailsToRemove); 402 403 m_dsi.execute(delete); 404 } 405 } catch (HarmoniseFactoryException e) { 406 throw new DataAccessException(e); 407 } catch (DataStoreException e) { 408 throw new DataAccessException(e); 409 } catch (ClassNotFoundException e) { 410 throw new DataAccessException(e); 411 } catch (InstantiationException e) { 412 throw new DataAccessException(e); 413 } catch (IllegalAccessException e) { 414 throw new DataAccessException(e); 415 } 416 417 return m_details; 418 } 419 420 426 public void addDetails(String sDetails) throws PopulateException { 427 if (m_bIsDetailsPopulated == false) { 428 try { 429 populateDetails(); 430 } catch (DataStoreException e) { 431 throw new PopulateException("Error populating details", e); 432 } 433 } 434 435 if (m_details.contains(sDetails) == false) { 436 m_details.add(sDetails); 437 m_bIsChanged = true; 438 } 439 } 440 441 447 public boolean isChanged() { 448 return m_bIsChanged; 449 } 450 451 458 public List getContentRestrictions() throws DataAccessException { 459 if (m_bIsContentRestrictPopulated == false) { 460 try { 461 populateContentRestrictions(); 462 } catch (DataStoreException e) { 463 throw new DataAccessException("Error populating details", e); 464 } 465 } 466 467 return this.m_contentRestrictions; 468 } 469 470 476 public void addContentTypeRestriction(String sContentType) 477 throws PopulateException { 478 if (m_bIsDetailsPopulated == false) { 479 try { 480 populateContentRestrictions(); 481 } catch (DataStoreException e) { 482 throw new PopulateException("Error populating details", e); 483 } 484 } 485 486 if (m_contentRestrictions.contains(sContentType) == false) { 487 m_contentRestrictions.add(sContentType); 488 m_bIsChanged = true; 489 } 490 491 } 492 493 498 private void populateContentRestrictions() throws DataStoreException { 499 ResultSet rs = null; 500 501 if (m_bIsContentRestrictPopulated == false) { 502 503 if (m_contentRestrictions == null) { 504 m_contentRestrictions = new Vector(); 505 } 506 507 SelectStatement select = new SelectStatement(); 508 509 select.addSelectColumn( 510 getContentRestrictionsColumnRef( 511 CLMN_CONTENT_TYPE, 512 m_bIsHistorical)); 513 514 select.addWhereCondition( 515 getContentRestrictionsColumnRef( 516 CLMN_DETAILS_DOMAIN_ID, 517 m_bIsHistorical), 518 "=", 519 this.m_nId); 520 521 rs = m_dsi.execute(select); 522 523 try { 524 while (rs.next()) { 525 String sDetail = rs.getString(1); 526 527 m_contentRestrictions.add(sDetail); 528 } 529 } catch (SQLException e) { 530 throw new DataStoreException( 531 "Error populating domain details", 532 e); 533 } finally { 534 if(rs!=null) { 535 try { 536 rs.close(); 537 } catch (SQLException e1) { 538 throw new DataStoreException( 539 "Error occured closing result set",e1); 540 } 541 } 542 } 543 544 m_bIsContentRestrictPopulated = true; 545 } 546 547 } 548 549 554 public int getMinOccurs() { 555 return m_nMinOccurs; 556 } 557 558 565 public int getMaxOccurs() { 566 return m_nMaxOccurs; 567 } 568 569 574 public void setMinOccurs(int nMinOccurs) { 575 m_nMinOccurs = nMinOccurs; 576 } 577 578 583 public void setMaxOccurs(int nMaxOccurs) { 584 m_nMaxOccurs = nMaxOccurs; 585 } 586 587 593 public void setHistorical(boolean bIsHist) { 594 m_bIsHistorical = bIsHist; 595 } 596 597 600 public Element publish(Template template, HarmoniseOutput output, State state) 601 throws PublishException { 602 Element resultEl = null; 603 604 try { 605 resultEl = 606 publish(template.getTemplateRootElement(), output, state); 607 } catch (DataAccessException e) { 608 throw new PublishException(e); 609 } 610 611 612 return resultEl; 613 } 614 615 618 public Element publish(Element topEl, HarmoniseOutput output, State state) 619 throws PublishException { 620 Element docEl = null; 621 NodeList nodes = null; 622 Text txt = null; 623 String sTagName = topEl.getTagName(); 624 625 try { 626 627 if (topEl.getTagName().equals(getTagName())) { 628 docEl = output.createElement(getTagName()); 629 630 if (m_nMinOccurs > 0) { 631 docEl.setAttribute( 632 ATTRIB_MIN_OCCURS, 633 String.valueOf(m_nMinOccurs)); 634 } 635 636 if (m_nMaxOccurs > 0) { 637 docEl.setAttribute( 638 ATTRIB_MAX_OCCURS, 639 String.valueOf(m_nMaxOccurs)); 640 } 641 642 nodes = topEl.getChildNodes(); 643 } else if (sTagName.equals(TAG_DOMAIN_DETAILS)) { 644 docEl = output.createElement(sTagName); 645 646 if (m_bIsDetailsPopulated == false) { 647 populateDetails(); 648 } 649 650 Iterator iter = m_details.iterator(); 651 652 while (iter.hasNext()) { 653 String sDetail = (String ) iter.next(); 654 Element pathEl = 655 output.createElement(TAG_PATH); 656 txt = output.createTextNode(sDetail); 657 pathEl.appendChild(txt); 658 docEl.appendChild(pathEl); 659 } 660 } else if (sTagName.equals(TAG_CONTENT_RESTRICTIONS)) { 661 docEl = output.createElement(sTagName); 662 if (m_bIsContentRestrictPopulated == false) { 663 populateContentRestrictions(); 664 } 665 Iterator iter = m_contentRestrictions.iterator(); 666 while (iter.hasNext()) { 667 String sDetail = (String ) iter.next(); 668 Element pathEl = 669 output.createElement(TAG_PATH); 670 txt = output.createTextNode(sDetail); 671 pathEl.appendChild(txt); 672 docEl.appendChild(pathEl); 673 } 674 } else if (sTagName.equals(TAG_DOMAIN_OBJECT)) { 675 docEl = output.createElement(sTagName); 676 txt = output.createTextNode(getDomainClass()); 677 docEl.appendChild(txt); 678 } 679 680 Element formEl; 682 Element el; 683 684 if (nodes != null) { 685 for (int i = 0; i < nodes.getLength(); i++) { 686 if (nodes.item(i).getNodeType() != Node.ELEMENT_NODE) { 687 continue; 688 } 689 690 formEl = (Element) nodes.item(i); 691 el = publish(formEl, output, state); 692 693 if (el != null) { 694 docEl.appendChild(el); 695 } 696 } 697 } 698 699 } catch (DataStoreException e) { 700 throw new PublishException(e); 701 } 702 703 return docEl; 704 } 705 706 709 public void populate(Element xmlElement, State state) 710 throws PopulateException { 711 String sTagName = xmlElement.getTagName(); 712 Text txt = null; 713 String sTemp = null; 714 715 if (sTagName.equals(getTagName()) == true) { 716 717 String sMinOccurs = xmlElement.getAttribute(ATTRIB_MIN_OCCURS); 718 719 if (sMinOccurs != null && sMinOccurs.length() > 0) { 720 m_nMinOccurs = Integer.parseInt(sMinOccurs); 721 } 722 723 String sMaxOccurs = xmlElement.getAttribute(ATTRIB_MAX_OCCURS); 724 725 if (sMaxOccurs != null && sMaxOccurs.length() > 0) { 726 m_nMaxOccurs = Integer.parseInt(sMaxOccurs); 727 } 728 729 NodeList nodes = xmlElement.getChildNodes(); 730 731 for (int i = 0; i < nodes.getLength(); i++) { 732 if (nodes.item(i).getNodeType() != Node.ELEMENT_NODE) { 733 continue; 734 } 735 736 Element el = (Element) nodes.item(i); 737 populate(el, state); 738 } 739 } else if (sTagName.equals(TAG_DOMAIN_OBJECT)) { 740 NodeList nodes = xmlElement.getChildNodes(); 741 742 for(int i=0;i<nodes.getLength();i++) { 743 Node node = nodes.item(i); 744 745 if(node.getNodeType() == Node.TEXT_NODE) { 746 txt = (Text) node; 747 String sVal = txt.getNodeValue().trim(); 748 749 if(sVal.length()>0) { 750 setDomainClass(sVal); 751 break; 752 } 753 754 } else if(node.getNodeType() == Node.ELEMENT_NODE) { 755 try { 756 String sClassname = HarmoniseObjectFactory.getClassName(m_dsi, (Element)node); 757 setDomainClass(sClassname); 758 break; 759 } catch (HarmoniseFactoryException e) { 760 throw new PopulateException(e); 761 } 762 } 763 } 764 765 766 767 } else if (sTagName.equals(TAG_DOMAIN_DETAILS)) { 768 769 List nodes = XMLUtils.getChildrenByName(xmlElement, TAG_PATHRESTRICTION); 770 771 for (Iterator iter = nodes.iterator(); iter.hasNext();) { 772 Element pathEl = (Element) iter.next(); 773 txt = (Text) pathEl.getFirstChild(); 774 addDetails(txt.getNodeValue()); 775 } 776 777 } 778 779 } 780 781 790 static public List getAvailableProperties( 791 AbstractDataStoreInterface dsi, 792 Class clss) 793 throws DataAccessException { 794 return getAvailableProperties(dsi, clss, (String ) null); 795 } 796 797 807 static public List getAvailableProperties( 808 AbstractDataStoreInterface dsi, 809 Class clss, 810 String sPath) 811 throws DataAccessException { 812 Vector result = new Vector(); 813 ResultSet rs = null; 814 SelectStatement select = new SelectStatement(); 815 816 try { 817 select.addSelectColumn( 818 AbstractObject.getColumnRef( 819 Property.class.getName(), 820 AbstractObject.ATTRIB_ID)); 821 select.addSelectColumn( 822 AbstractObject.getColumnRef( 823 Property.class.getName(), 824 AbstractObject.ATTRIB_TYPE)); 825 826 ColumnRef colDomDetails = new ColumnRef( 827 TBL_DOMAIN_DETAILS, 828 CLMN_DOMAIN_DETAILS, 829 ColumnRef.TEXT); 830 831 select.addSelectColumn(colDomDetails); 832 833 select.addJoinCondition( 834 AbstractObject.getColumnRef( 835 Property.class.getName(), 836 AbstractObject.ATTRIB_KEY), 837 new ColumnRef(TBL_NAME, CLMN_PROPERTY_KEY, ColumnRef.NUMBER)); 838 839 select.addJoinCondition( 840 getDetailsColumnRef(CLMN_DETAILS_DOMAIN_ID, false), 841 getColumnRef(CLMN_DOMAIN_ID, false)); 842 843 select.addWhereCondition( 844 new ColumnRef(TBL_NAME, CLMN_DOMAIN_OBJECT, ColumnRef.TEXT), 845 "=", 846 clss.getName()); 847 848 if(sPath != null) { 849 Substring substr = new Substring(sPath,new Integer (1),new Length(colDomDetails)); 850 851 select.addWhereCondition(colDomDetails, "=", substr); 852 } 853 854 855 } catch (DataStoreException e) { 856 throw new DataAccessException("Error occured building query", e); 857 } 858 859 try { 860 861 rs = dsi.execute(select); 862 863 while (rs.next()) { 864 int nPropId = rs.getInt(1); 865 String sPropType = rs.getString(2); 866 867 Property prop = 868 ( 869 org.openharmonise.rm.resources.metadata.properties.Property) HarmoniseObjectFactory 870 .instantiateHarmoniseObject( 871 dsi, 872 sPropType, 873 nPropId); 874 875 result.add(prop); 876 877 } 878 } catch (HarmoniseFactoryException e) { 879 throw new DataAccessException( 880 "Error occured getting property from factory",e); 881 } catch (DataStoreException e) { 882 throw new DataAccessException( 883 "Error occured executing query",e); 884 } catch (SQLException e) { 885 throw new DataAccessException( 886 "Error occured executing query",e); 887 } finally { 888 if(rs!=null) { 889 try { 890 rs.close(); 891 } catch (SQLException e) { 892 m_logger.log(Level.WARNING, e.getLocalizedMessage(), e); 893 } 894 } 895 } 896 897 return result; 898 } 899 900 910 static public List getAvailableProperties( 911 AbstractDataStoreInterface dsi, 912 Class clss, 913 List paths) 914 throws DataAccessException { 915 Vector result = new Vector(); 916 ResultSet rs = null; 917 SelectStatement select = new SelectStatement(); 918 919 try { 920 select.addSelectColumn( 921 AbstractObject.getColumnRef( 922 Property.class.getName(), 923 AbstractObject.ATTRIB_ID)); 924 select.addSelectColumn( 925 AbstractObject.getColumnRef( 926 Property.class.getName(), 927 AbstractObject.ATTRIB_TYPE)); 928 929 ColumnRef colDomDetails = new ColumnRef( 930 TBL_DOMAIN_DETAILS, 931 CLMN_DOMAIN_DETAILS, 932 ColumnRef.TEXT); 933 934 select.addSelectColumn(colDomDetails); 935 936 select.addJoinCondition( 937 AbstractObject.getColumnRef( 938 Property.class.getName(), 939 AbstractObject.ATTRIB_KEY), 940 new ColumnRef(TBL_NAME, CLMN_PROPERTY_KEY, ColumnRef.NUMBER)); 941 942 select.addJoinCondition( 943 getDetailsColumnRef(CLMN_DETAILS_DOMAIN_ID, false), 944 getColumnRef(CLMN_DOMAIN_ID, false)); 945 946 select.addWhereCondition( 947 new ColumnRef(TBL_NAME, CLMN_DOMAIN_OBJECT, ColumnRef.TEXT), 948 "=", 949 clss.getName()); 950 951 if(paths != null) { 952 953 if(paths.size() == 1) { 954 Substring substr = new Substring((String )paths.get(0),new Integer (1),new Length(colDomDetails)); 955 956 select.addWhereCondition(colDomDetails, "=", substr); 957 958 } else if(paths.size() > 1) { 959 WhereConditionGroup wheres = new WhereConditionGroup(); 960 wheres.setStringingOperator("or"); 961 962 Iterator iter = paths.iterator(); 963 964 while (iter.hasNext()) { 965 String sPath = (String ) iter.next(); 966 967 Substring substr = new Substring(sPath,new Integer (1),new Length(colDomDetails)); 968 wheres.addCondition(colDomDetails, "=", substr); 969 970 } 971 select.addWhereCondition(wheres); 972 } 973 974 } 975 976 } catch (DataStoreException e) { 977 throw new DataAccessException( 978 "Error occured building query",e); 979 } 980 981 try { 982 983 rs = dsi.execute(select); 984 985 while (rs.next()) { 986 int nPropId = rs.getInt(1); 987 String sPropType = rs.getString(2); 988 Property prop = 989 ( 990 org.openharmonise.rm.resources.metadata.properties.Property) HarmoniseObjectFactory 991 .instantiateHarmoniseObject( 992 dsi, 993 sPropType, 994 nPropId); 995 996 result.add(prop); 997 } 998 } catch (HarmoniseFactoryException e) { 999 throw new DataAccessException( 1000 "Error occured getting property from factory",e); 1001 } catch (DataStoreException e) { 1002 throw new DataAccessException( 1003 "Error occured executing query",e); 1004 } catch (SQLException e) { 1005 throw new DataAccessException( 1006 "Error occured executing query",e); 1007 } finally { 1008 if(rs!=null) { 1009 try { 1010 rs.close(); 1011 } catch (SQLException e) { 1012 m_logger.log(Level.WARNING, e.getLocalizedMessage(), e); 1013 } 1014 } 1015 } 1016 1017 return result; 1018 } 1019 1020 1029 static public List getAvailableProperties( 1030 AbstractDataStoreInterface dsi, 1031 AbstractProfiledObject profObj) 1032 throws DataAccessException { 1033 List result = null; 1034 if(profObj instanceof AbstractChildObject) { 1035 result = getAvailableProperties( 1036 dsi, 1037 profObj.getClass(), 1038 ((AbstractChildObject)profObj).getAllFullPaths()); 1039 } else { 1040 result = getAvailableProperties( 1041 dsi, 1042 profObj.getClass()); 1043 } 1044 1045 return result; 1046 } 1047 1048 1051 public String getTagName() { 1052 return TAG_DOMAIN; 1053 } 1054 1055 1058 public boolean equals(Object obj) { 1059 boolean bResult = false; 1060 1061 if (obj instanceof Domain) { 1062 Domain domain = (Domain) obj; 1063 1064 if (this == domain) { 1065 bResult = true; 1066 } else { 1067 try { 1068 if (this.m_bIsContentRestrictPopulated == false) { 1069 this.populateContentRestrictions(); 1070 } 1071 if (this.m_bIsDetailsPopulated == false) { 1072 this.populateDetails(); 1073 } 1074 1075 if (m_nDepth == domain.getDepth()) { 1076 if (m_nMaxOccurs == domain.getMaxOccurs()) { 1077 if (m_nMinOccurs == domain.getMinOccurs()) { 1078 if (m_sObjectName.equals(domain.getDomainClass())) { 1079 if (m_contentRestrictions 1080 .equals( 1081 domain.getContentRestrictions())) { 1082 if (m_details 1083 .equals(domain.getDetails())) { 1084 bResult = true; 1085 } 1086 } 1087 } 1088 } 1089 } 1090 } 1091 1092 } catch (DataStoreException e) { 1093 m_logger.log(Level.WARNING, e.getLocalizedMessage(), e); 1094 } catch (DataAccessException e) { 1095 m_logger.log(Level.WARNING, e.getLocalizedMessage(), e); 1096 } 1097 1098 } 1099 1100 } 1101 1102 return bResult; 1103 } 1104 1105 1112 public void save(Property prop) throws EditException { 1113 try { 1114 InsertStatement insert = new InsertStatement(); 1115 1116 if (m_nId < 0) { 1117 m_nId = m_dsi.getSequenceNextValue(SEQ_DOMAIN); 1118 } 1119 1120 insert.addColumnValue( 1121 getColumnRef(CLMN_DOMAIN_ID, m_bIsHistorical), 1122 m_nId); 1123 1124 insert.addColumnValue( 1125 getColumnRef(Domain.CLMN_PROPERTY_KEY, m_bIsHistorical), 1126 prop.getKey()); 1127 insert.addColumnValue( 1128 getColumnRef(Domain.CLMN_DOMAIN_OBJECT, m_bIsHistorical), 1129 this.m_sObjectName); 1130 1131 insert.addColumnValue( 1132 getColumnRef(Domain.CLMN_MIN_OCCURS, m_bIsHistorical), 1133 this.m_nMinOccurs); 1134 1135 insert.addColumnValue( 1136 getColumnRef(Domain.CLMN_MAX_OCCURS, m_bIsHistorical), 1137 this.m_nMaxOccurs); 1138 1139 m_dsi.execute(insert); 1140 1141 if (m_details != null) { 1142 1143 Iterator iter = m_details.iterator(); 1144 1145 while (iter.hasNext()) { 1146 String sDetail = (String ) iter.next(); 1147 1148 insert.clear(); 1149 1150 insert.addColumnValue( 1151 getDetailsColumnRef( 1152 Domain.CLMN_DETAILS_DOMAIN_ID, 1153 m_bIsHistorical), 1154 m_nId); 1155 1156 insert.addColumnValue( 1157 getDetailsColumnRef( 1158 Domain.CLMN_DOMAIN_DETAILS, 1159 m_bIsHistorical), 1160 sDetail); 1161 1162 m_dsi.execute(insert); 1163 } 1164 } 1165 1166 if (m_contentRestrictions != null) { 1167 1168 Iterator iter = m_contentRestrictions.iterator(); 1169 1170 while (iter.hasNext()) { 1171 String contentType = (String ) iter.next(); 1172 1173 insert.clear(); 1174 1175 insert.addColumnValue( 1176 getContentRestrictionsColumnRef( 1177 Domain.CLMN_DETAILS_DOMAIN_ID, 1178 m_bIsHistorical), 1179 m_nId); 1180 1181 insert.addColumnValue( 1182 getContentRestrictionsColumnRef( 1183 Domain.CLMN_CONTENT_TYPE, 1184 m_bIsHistorical), 1185 contentType); 1186 1187 m_dsi.execute(insert); 1188 } 1189 } 1190 } catch (DataAccessException e) { 1191 throw new EditException("Error saving domain", e); 1192 } catch (DataStoreException e) { 1193 throw new EditException("Error saving domain", e); 1194 } catch (SQLException e) { 1195 throw new EditException("Error saving domain", e); 1196 } 1197 } 1198 1199 1205 public void delete() throws EditException { 1206 try { 1207 DeleteStatement delete = new DeleteStatement(); 1208 1209 delete.addWhereCondition( 1210 getDetailsColumnRef( 1211 Domain.CLMN_DETAILS_DOMAIN_ID, 1212 m_bIsHistorical), 1213 "=", 1214 m_nId); 1215 1216 1217 m_dsi.execute(delete); 1218 1219 delete.clear(); 1220 1221 delete.addWhereCondition( 1222 this.getContentRestrictionsColumnRef( 1223 CLMN_DETAILS_DOMAIN_ID, 1224 this.m_bIsHistorical), 1225 "=", 1226 m_nId); 1227 1228 m_dsi.execute(delete); 1229 1230 delete.clear(); 1231 1232 delete.addWhereCondition( 1233 getColumnRef(CLMN_DOMAIN_ID, this.m_bIsHistorical), 1234 "=", 1235 m_nId); 1236 1237 m_dsi.execute(delete); 1238 1239 } catch (DataStoreException e) { 1240 throw new EditException("Error deleting domain", e); 1241 } 1242 } 1243 1244 1249 private synchronized void populateDetails() throws DataStoreException { 1250 if (m_bIsDetailsPopulated == false) { 1251 1252 if (m_details == null) { 1253 m_details = new Vector(); 1254 } 1255 1256 SelectStatement select = new SelectStatement(); 1257 1258 select.addSelectColumn( 1259 getDetailsColumnRef(CLMN_DOMAIN_DETAILS, m_bIsHistorical)); 1260 1261 select.addWhereCondition( 1262 getDetailsColumnRef(CLMN_DETAILS_DOMAIN_ID, m_bIsHistorical), 1263 "=", 1264 this.m_nId); 1265 1266 ResultSet rs = m_dsi.execute(select); 1267 1268 try { 1269 while (rs.next()) { 1270 String sDetail = rs.getString(1); 1271 1272 m_details.add(sDetail); 1273 } 1274 } catch (SQLException e) { 1275 throw new DataStoreException( 1276 "Error populating domain details", 1277 e); 1278 } finally { 1279 if(rs!=null) { 1280 try { 1281 rs.close(); 1282 } catch (SQLException e1) { 1283 throw new DataStoreException( 1284 "Error occured closing result set:" 1285 + e1.getLocalizedMessage()); 1286 } 1287 } 1288 } 1289 1290 m_bIsDetailsPopulated = true; 1291 } 1292 } 1293 1294 1304 protected static ColumnRef getDetailsColumnRef(String sCol, boolean bIsHist) 1305 throws DataStoreException { 1306 String sTable = Domain.CLMN_DOMAIN_DETAILS; 1307 ColumnRef colref = null; 1308 1309 if (bIsHist == true) { 1310 sTable = sTable + AbstractObject.EXT_HIST; 1311 } 1312 1313 if (sCol.equals(Domain.CLMN_DOMAIN_DETAILS) == true) { 1314 colref = new ColumnRef(sTable, sCol, ColumnRef.TEXT); 1315 } else if (sCol.equals(Domain.CLMN_DETAILS_DOMAIN_ID) == true) { 1316 colref = new ColumnRef(sTable, sCol, ColumnRef.NUMBER); 1317 } else { 1318 throw new InvalidColumnReferenceException(); 1319 } 1320 1321 return colref; 1322 } 1323 1324 1333 private ColumnRef getContentRestrictionsColumnRef( 1334 String sCol, 1335 boolean bIsHist) 1336 throws DataStoreException { 1337 String sTable = Domain.TBL_DOMAIN_CONTENT_RESTRICTIONS; 1338 ColumnRef colref = null; 1339 1340 if (bIsHist == true) { 1341 sTable = sTable + AbstractObject.EXT_HIST; 1342 } 1343 1344 if (sCol.equals(Domain.CLMN_CONTENT_TYPE) == true) { 1345 colref = new ColumnRef(sTable, sCol, ColumnRef.TEXT); 1346 } else if (sCol.equals(Domain.CLMN_DETAILS_DOMAIN_ID) == true) { 1347 colref = new ColumnRef(sTable, sCol, ColumnRef.NUMBER); 1348 } else { 1349 throw new InvalidColumnReferenceException(); 1350 } 1351 1352 return colref; 1353 } 1354 1355 1364 protected static ColumnRef getColumnRef(String sCol, boolean bIsHist) 1365 throws DataStoreException { 1366 String sTable = Domain.TBL_NAME; 1367 ColumnRef colref = null; 1368 1369 if (bIsHist == true) { 1370 sTable = sTable + AbstractObject.EXT_HIST; 1371 } 1372 1373 if (sCol.equals(Domain.CLMN_DOMAIN_DETAILS) == true 1374 || sCol.equals(Domain.CLMN_DOMAIN_OBJECT) == true) { 1375 colref = new ColumnRef(sTable, sCol, ColumnRef.TEXT); 1376 } else if (sCol.equals(Domain.CLMN_PROPERTY_KEY) == true) { 1377 colref = new ColumnRef(sTable, sCol, ColumnRef.NUMBER); 1378 } else if (sCol.equals(Domain.CLMN_MIN_OCCURS) == true) { 1379 colref = new ColumnRef(sTable, sCol, ColumnRef.NUMBER); 1380 } else if (sCol.equals(Domain.CLMN_MAX_OCCURS) == true) { 1381 colref = new ColumnRef(sTable, sCol, ColumnRef.NUMBER); 1382 } else if (sCol.equals(Domain.CLMN_DEPTH) == true) { 1383 colref = new ColumnRef(sTable, sCol, ColumnRef.NUMBER); 1384 } else if (sCol.equals(Domain.CLMN_DOMAIN_ID) == true) { 1385 colref = new ColumnRef(sTable, sCol, ColumnRef.NUMBER); 1386 } else { 1387 throw new InvalidColumnReferenceException(); 1388 } 1389 1390 return colref; 1391 } 1392 1393 1401 public boolean isValid(AbstractProfiledObject obj) 1402 throws DataAccessException { 1403 boolean bIsValid = true; 1404 1405 if (obj.getClass().getName().equals(getDomainClass()) == true) { 1406 if (obj instanceof AbstractChildObject) { 1407 AbstractChildObject child = (AbstractChildObject) obj; 1408 List details = getDetails(); 1409 String sChildPath = child.getPath(); 1410 1411 if (details.size() > 0 1414 && sChildPath != null 1415 && sChildPath.length() > 0) { 1416 1417 bIsValid = false; 1418 1419 Iterator iter = details.iterator(); 1420 1421 while (iter.hasNext()) { 1422 String sPath = (String ) iter.next(); 1423 1424 if (sChildPath.startsWith(sPath)) { 1425 bIsValid = true; 1426 } 1427 } 1428 } 1429 1430 } 1431 } else { 1432 bIsValid = false; 1433 } 1434 1435 return bIsValid; 1436 } 1437 1438 1441 public Object clone() throws CloneNotSupportedException { 1442 try { 1443 populateContentRestrictions(); 1444 populateDetails(); 1445 1446 Domain domain = (Domain)super.clone(); 1447 domain.m_details = (List)((Vector)m_details).clone(); 1448 domain.m_contentRestrictions = (List)((Vector) m_contentRestrictions).clone(); 1449 1450 return domain; 1451 } catch (CloneNotSupportedException e) { 1452 throw new IllegalStateException ( 1453 "Clone failed:" + e.getLocalizedMessage()); 1454 } catch (DataStoreException e) { 1455 throw new IllegalStateException ("Clone failed:" + e.getLocalizedMessage()); 1456 } 1457 } 1458 1459} 1460 | Popular Tags |