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.spi;
021:
022: import java.util.Collections;
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.XPathVariableReference;
027:
028: /**
029: *
030: * @author nk160297
031: */
032: public class VariableSchemaContext implements XPathSchemaContext {
033:
034: private Set<SchemaCompPair> mCompPairSet;
035: private XPathVariable mXPathVar;
036:
037: public VariableSchemaContext(XPathVariable var) {
038: assert var != null;
039: mXPathVar = var;
040: }
041:
042: public VariableSchemaContext(XPathVariableReference varRef) {
043: assert varRef != null;
044: XPathVariable var = varRef.getVariable();
045: assert var != null;
046: mXPathVar = var;
047: }
048:
049: public XPathSchemaContext getParentContext() {
050: return null;
051: }
052:
053: public synchronized Set<SchemaCompPair> getSchemaCompPairs() {
054: if (mCompPairSet == null) {
055: SchemaComponent varType = mXPathVar.getType();
056: SchemaCompPair sCompPair = new SchemaCompPair(varType, null);
057: mCompPairSet = Collections.singleton(sCompPair);
058: }
059: //
060: return mCompPairSet;
061: }
062:
063: public Set<SchemaCompPair> getUsedSchemaCompPairs() {
064: return getSchemaCompPairs();
065: }
066:
067: public void setUsedSchemaComp(Set<SchemaComponent> compSet) {
068: // Ignore the set because there is only one schema component
069: // in this context and it always is implied as used!
070: }
071:
072: public XPathVariable getVariable() {
073: return mXPathVar;
074: }
075:
076: @Override
077: public String toString() {
078: return mXPathVar.toString();
079: }
080:
081: @Override
082: public boolean equals(Object obj) {
083: if (obj instanceof VariableSchemaContext) {
084: if (this == obj) {
085: return true;
086: }
087: //
088: // Compare variables
089: VariableSchemaContext other = (VariableSchemaContext) obj;
090: XPathVariable var1 = this .getVariable();
091: XPathVariable var2 = other.getVariable();
092: //
093: if (var1.equals(var2)) {
094: return true;
095: }
096: }
097: //
098: return false;
099: }
100:
101: public boolean equalsChain(XPathSchemaContext obj) {
102: return equals(obj);
103: }
104:
105: }
|