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.xml.xpath.ext.impl;
021:
022: import java.util.HashSet;
023: import java.util.Set;
024: import org.netbeans.modules.xml.xpath.ext.XPathSchemaContext;
025: import org.netbeans.modules.xml.schema.model.SchemaComponent;
026: import org.netbeans.modules.xml.xpath.ext.LocationStep;
027:
028: /**
029: * This schema context references to multiple schema components.
030: *
031: * @author nk160297
032: */
033: public class MultiCompSchemaContext implements XPathSchemaContext {
034:
035: private XPathSchemaContext mParentContext;
036: private Set<SchemaCompPair> mSchemaCompPairSet;
037: private Set<SchemaComponent> mUsedSchemaCompSet;
038:
039: public MultiCompSchemaContext(XPathSchemaContext parentContext,
040: Set<SchemaCompPair> compPairSet) {
041: mParentContext = parentContext;
042: mSchemaCompPairSet = compPairSet;
043: }
044:
045: public XPathSchemaContext getParentContext() {
046: return mParentContext;
047: }
048:
049: public Set<SchemaCompPair> getSchemaCompPairs() {
050: return mSchemaCompPairSet;
051: }
052:
053: public Set<SchemaCompPair> getUsedSchemaCompPairs() {
054: HashSet<SchemaCompPair> resultSet = new HashSet<SchemaCompPair>();
055: //
056: if (mUsedSchemaCompSet != null) {
057: for (SchemaCompPair myCompPair : mSchemaCompPairSet) {
058: SchemaComponent myComponent = myCompPair.getComp();
059: for (SchemaComponent usdComp : mUsedSchemaCompSet) {
060: if (myComponent.equals(usdComp)) {
061: resultSet.add(myCompPair);
062: }
063: }
064: }
065: }
066: //
067: return resultSet;
068: }
069:
070: public void setUsedSchemaComp(Set<SchemaComponent> compSet) {
071: mUsedSchemaCompSet = compSet;
072: }
073:
074: @Override
075: public String toString() {
076: StringBuffer sb = new StringBuffer();
077: //
078: if (mParentContext != null) {
079: sb.append(mParentContext.toString());
080: }
081: sb.append(LocationStep.STEP_SEPARATOR);
082: //
083: if (mSchemaCompPairSet != null) {
084: boolean isFirst = true;
085: for (SchemaCompPair schemaCompPair : mSchemaCompPairSet) {
086: if (isFirst) {
087: isFirst = false;
088: } else {
089: sb.append(" | ");
090: }
091: //
092: SchemaComponent parentComp = schemaCompPair
093: .getParetnComp();
094: if (parentComp != null) {
095: SchemaCompPair.appendCompName(sb, parentComp);
096: sb.append(">");
097: }
098: SchemaComponent schemaComp = schemaCompPair.getComp();
099: SchemaCompPair.appendCompName(sb, schemaComp);
100: }
101: }
102: //
103: return sb.toString();
104: }
105:
106: @Override
107: public boolean equals(Object obj) {
108: if (obj instanceof XPathSchemaContext) {
109: return XPathSchemaContext.Utilities.equals(this ,
110: (XPathSchemaContext) obj);
111: }
112: //
113: return false;
114: }
115:
116: public boolean equalsChain(XPathSchemaContext obj) {
117: if (obj instanceof XPathSchemaContext) {
118: return XPathSchemaContext.Utilities.equalsChain(this ,
119: (XPathSchemaContext) obj);
120: }
121: //
122: return false;
123: }
124:
125: }
|