001: /*
002: * The contents of this file are subject to the terms of the Common Development
003: * and Distribution License (the License). You may not use this file except in
004: * compliance with the License.
005: *
006: * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
007: * or http://www.netbeans.org/cddl.txt.
008: *
009: * When distributing Covered Code, include this CDDL Header Notice in each file
010: * and include the License file at http://www.netbeans.org/cddl.txt.
011: * If applicable, add the following below the CDDL Header, with the fields
012: * enclosed by brackets [] replaced by your own identifying information:
013: * "Portions Copyrighted [year] [name of copyright owner]"
014: *
015: * The Original Software is NetBeans. The Initial Developer of the Original
016: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
017: * Microsystems, Inc. All Rights Reserved.
018: */
019:
020: package org.netbeans.modules.xslt.mapper.model;
021:
022: import org.netbeans.modules.xml.axi.AXIComponent;
023: import org.netbeans.modules.xml.xpath.XPathPredicateExpression;
024: import org.netbeans.modules.xslt.mapper.view.PredicateManager;
025:
026: /**
027: * This class is a container of AXIOM component combined with
028: * an array of predicates. It is intended to be used as a paramether
029: * for construction of a PredicatedSchemaNode with the help of NodeFactory.
030: *
031: * @author nk160297
032: */
033: public class PredicatedAxiComponent {
034:
035: private AXIComponent myAxiComponent;
036: private XPathPredicateExpression[] myPredicateArr;
037:
038: public PredicatedAxiComponent(AXIComponent axiComponent,
039: XPathPredicateExpression[] predicateArr) {
040: myAxiComponent = axiComponent;
041: myPredicateArr = predicateArr;
042: }
043:
044: public AXIComponent getType() {
045: return myAxiComponent;
046: }
047:
048: public XPathPredicateExpression[] getPredicates() {
049: return myPredicateArr;
050: }
051:
052: public void setPredicates(XPathPredicateExpression[] newPArr) {
053: myPredicateArr = newPArr;
054: }
055:
056: public String getPredicatesText() {
057: return PredicateManager.toString(myPredicateArr);
058: }
059:
060: public boolean hasSamePredicates(XPathPredicateExpression[] predArr) {
061: // Compare predicates count
062: int myCount = myPredicateArr == null ? 0
063: : myPredicateArr.length;
064: int otherCount = predArr == null ? 0 : predArr.length;
065: if (myCount != otherCount) {
066: return false;
067: }
068: // Compare predicates one by one
069: for (int index = 0; index < myCount; index++) {
070: XPathPredicateExpression myPredicate = myPredicateArr[index];
071: XPathPredicateExpression otherPredicate = predArr[index];
072: String myPredText = myPredicate.getExpressionString();
073: String otherPredText = otherPredicate.getExpressionString();
074: if (!(myPredText.equals(otherPredText))) {
075: return false;
076: }
077: }
078: return true;
079: }
080:
081: public boolean equals(Object obj) {
082: // Compare class
083: if (!(obj instanceof PredicatedAxiComponent)) {
084: return false;
085: }
086: PredicatedAxiComponent comp2 = (PredicatedAxiComponent) obj;
087: // Compare type
088: if (!(comp2.getType().equals(myAxiComponent))) {
089: return false;
090: }
091: // Compare predicates
092: XPathPredicateExpression[] otherPredicateArr = comp2
093: .getPredicates();
094: return hasSamePredicates(otherPredicateArr);
095: }
096:
097: public String toString() {
098: String predicatesText = PredicateManager
099: .toString(myPredicateArr);
100: if (predicatesText.length() == 0) {
101: return myAxiComponent.toString();
102: } else {
103: return myAxiComponent.toString() + " " + predicatesText;
104: }
105: }
106: }
|