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 javax.xml.namespace.QName;
023: import org.netbeans.modules.xml.xpath.ext.XPathSchemaContext;
024: import org.netbeans.modules.xml.xpath.ext.XPathUtils;
025: import org.netbeans.modules.xml.xpath.ext.XPathModel;
026: import org.netbeans.modules.xml.xpath.ext.XPathVariableReference;
027: import org.netbeans.modules.xml.xpath.ext.spi.VariableResolver;
028: import org.netbeans.modules.xml.xpath.ext.visitor.XPathVisitor;
029: import org.netbeans.modules.xml.schema.model.ReferenceableSchemaComponent;
030: import org.netbeans.modules.xml.xpath.ext.spi.VariableSchemaContext;
031: import org.netbeans.modules.xml.xpath.ext.spi.XPathVariable;
032:
033: /**
034: *
035: * @author radval
036: * @author nk160297
037: *
038: */
039: public class XPathVariableReferenceImpl extends XPathExpressionImpl
040: implements XPathVariableReference {
041:
042: // private Reference mVaribleReference;
043: private QName mVariableQName;
044: private VariableSchemaContext mSchemaContext;
045:
046: public XPathVariableReferenceImpl(XPathModel model,
047: QName variableQName) {
048: super (model);
049: mVariableQName = variableQName;
050: }
051:
052: public void setVariableName(QName qName) {
053: mVariableQName = qName;
054: }
055:
056: public QName getVariableName() {
057: return mVariableQName;
058: }
059:
060: public XPathVariable getVariable() {
061: VariableResolver varResolver = myModel.getVariableResolver();
062: if (varResolver != null) {
063: XPathVariable var = varResolver
064: .resolveVariable(mVariableQName);
065: return var;
066: }
067: return null;
068: }
069:
070: public ReferenceableSchemaComponent getType() {
071: VariableResolver varResolver = myModel.getVariableResolver();
072: if (varResolver != null) {
073: ReferenceableSchemaComponent varType = varResolver
074: .resolveVariableType(mVariableQName);
075: return varType;
076: }
077: return null;
078: }
079:
080: public <VAR_TYPE extends XPathVariable> VAR_TYPE getVariable(
081: Class<VAR_TYPE> varClass) {
082: XPathVariable var = getVariable();
083: if (var != null) {
084: assert varClass.isInstance(var) : "Wrong class"; // NOI18N
085: return varClass.cast(var);
086: }
087: return null;
088: }
089:
090: /**
091: * Calls the visitor.
092: * @param visitor the visitor
093: */
094: @Override
095: public void accept(XPathVisitor visitor) {
096: visitor.visit(this );
097: }
098:
099: @Override
100: public String toString() {
101: return XPathUtils.qNameObjectToString(mVariableQName);
102: }
103:
104: public VariableSchemaContext getSchemaContext() {
105: return mSchemaContext;
106: }
107:
108: public void setSchemaContext(XPathSchemaContext newContext) {
109: assert newContext instanceof VariableSchemaContext;
110: mSchemaContext = (VariableSchemaContext) newContext;
111: }
112:
113: }
|