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;
021:
022: import javax.xml.namespace.NamespaceContext;
023: import javax.xml.namespace.QName;
024: import org.netbeans.modules.xml.schema.model.Attribute;
025: import org.netbeans.modules.xml.schema.model.SchemaComponent;
026: import org.netbeans.modules.xml.xam.Named;
027:
028: /**
029: * Represents a node test on name.
030: *
031: * @author Enrico Lelina
032: * @version
033: */
034: public class StepNodeNameTest extends StepNodeTest {
035:
036: /** The node name. */
037: private QName mNodeName;
038:
039: /**
040: * Constructor.
041: * @param nodeName the node name
042: */
043: public StepNodeNameTest(QName nodeName) {
044: super ();
045: mNodeName = nodeName;
046: }
047:
048: public StepNodeNameTest(XPathModel xPathModel, SchemaComponent sComp) {
049: super ();
050: assert (sComp instanceof Named);
051: String componentName = ((Named) sComp).getName();
052: QName sCompQName = null;
053: //
054: if (XPathUtils.isPrefixRequired(sComp)) {
055: //
056: String nsPrefix = null;
057: String namespaceURI = sComp.getModel()
058: .getEffectiveNamespace(sComp);
059: NamespaceContext nsContext = xPathModel
060: .getNamespaceContext();
061: if (nsContext != null) {
062: nsPrefix = nsContext.getPrefix(namespaceURI);
063: }
064: //
065: if (nsPrefix == null || nsPrefix.length() == 0) {
066: sCompQName = new QName(componentName);
067: } else {
068: sCompQName = new QName(namespaceURI, componentName,
069: nsPrefix);
070: }
071: } else {
072: sCompQName = new QName(componentName);
073: }
074: mNodeName = sCompQName;
075: }
076:
077: /**
078: * Gets the node name.
079: * @return the node name
080: */
081: public QName getNodeName() {
082: return mNodeName;
083: }
084:
085: public boolean isWildcard() {
086: return mNodeName.getLocalPart().equals("*"); // NOI18N
087: }
088:
089: @Override
090: public boolean equals(Object obj) {
091: if (obj instanceof StepNodeNameTest) {
092: QName nodeName2 = ((StepNodeNameTest) obj).getNodeName();
093: return XPathUtils.equalsIgnorNsUri(nodeName2, mNodeName);
094: }
095: return false;
096: }
097:
098: @Override
099: public String toString() {
100: return XPathUtils.qNameObjectToString(mNodeName);
101: }
102: }
|