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.bpel.model.api.support;
021:
022: import javax.xml.namespace.QName;
023: import org.netbeans.modules.bpel.model.api.VariableDeclaration;
024: import org.netbeans.modules.xml.schema.model.GlobalElement;
025: import org.netbeans.modules.xml.schema.model.GlobalType;
026: import org.netbeans.modules.xml.schema.model.ReferenceableSchemaComponent;
027: import org.netbeans.modules.xml.wsdl.model.Part;
028: import org.netbeans.modules.xml.xam.dom.NamedComponentReference;
029: import org.netbeans.modules.xml.xpath.ext.spi.XPathVariable;
030:
031: /**
032: * The special BPEL variable container is intended to be used by XPath model.
033: *
034: * @author nk160297
035: */
036: public final class XPathBpelVariable implements XPathVariable {
037:
038: private VariableDeclaration myVarDecl;
039: private Part myPart;
040:
041: /**
042: * The part can be null.
043: */
044: public XPathBpelVariable(VariableDeclaration var, Part part) {
045: assert var != null;
046: myVarDecl = var;
047: myPart = part;
048: }
049:
050: public VariableDeclaration getVarDecl() {
051: return myVarDecl;
052: }
053:
054: public Part getPart() {
055: return myPart;
056: }
057:
058: public QName getName() {
059: return constructXPathName();
060: }
061:
062: public ReferenceableSchemaComponent getType() {
063: //
064: NamedComponentReference<GlobalElement> gElementRef = null;
065: NamedComponentReference<GlobalType> gTypeRef = null;
066: Part part = getPart();
067: if (part != null) {
068: gElementRef = part.getElement();
069: if (gElementRef == null) {
070: gTypeRef = part.getType();
071: }
072: } else {
073: VariableDeclaration varDecl = getVarDecl();
074: gElementRef = varDecl.getElement();
075: if (gElementRef == null) {
076: gTypeRef = varDecl.getType();
077: }
078: }
079: //
080: if (gElementRef != null) {
081: GlobalElement gElement = gElementRef.get();
082: return gElement;
083: }
084: //
085: if (gTypeRef != null) {
086: GlobalType gType = gTypeRef.get();
087: return gType;
088: }
089: //
090: return null;
091: }
092:
093: public QName constructXPathName() {
094: String partName = null;
095: if (myPart != null) {
096: partName = myPart.getName();
097: }
098: //
099: String totalVarName;
100: if (partName != null && partName.length() != 0) {
101: totalVarName = myVarDecl.getVariableName() + "." + partName;
102: } else {
103: totalVarName = myVarDecl.getVariableName();
104: }
105: //
106: // It looks like a prefix is not required for BPEL variables
107: return new QName(totalVarName);
108: }
109:
110: @Override
111: public boolean equals(Object obj) {
112: if (!(obj instanceof XPathBpelVariable)) {
113: return false;
114: }
115: //
116: XPathBpelVariable other = (XPathBpelVariable) obj;
117: //
118: if (!(myVarDecl.equals(other.myVarDecl))) {
119: return false;
120: }
121: //
122: if (myPart != null && other.myPart == null) {
123: return false;
124: }
125: if (myPart == null && other.myPart != null) {
126: return false;
127: }
128: if (myPart != null && other.myPart != null) {
129: if (!(myPart.equals(other.myPart))) {
130: return false;
131: }
132: }
133: //
134: return true;
135: }
136:
137: @Override
138: public String toString() {
139: String varName = myVarDecl.getVariableName();
140: if (myPart == null) {
141: return "$" + varName;
142: } else {
143: return "$" + varName + "." + myPart.getName();
144: }
145: }
146: }
|