001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041: package org.netbeans.modules.bpel.validation.wsdl;
042:
043: import java.util.Collection;
044: import java.util.List;
045: import org.netbeans.modules.xml.xam.Component;
046: import org.netbeans.modules.xml.xam.dom.NamedComponentReference;
047: import org.netbeans.modules.xml.schema.model.GlobalElement;
048: import org.netbeans.modules.xml.schema.model.GlobalType;
049: import org.netbeans.modules.xml.wsdl.model.Message;
050: import org.netbeans.modules.xml.wsdl.model.Part;
051: import org.netbeans.modules.xml.wsdl.model.WSDLComponent;
052: import org.netbeans.modules.xml.wsdl.model.ExtensibilityElement;
053: import org.netbeans.modules.xml.wsdl.model.visitor.ChildVisitor;
054: import org.netbeans.modules.xml.wsdl.model.visitor.WSDLVisitor;
055: import org.netbeans.modules.xml.wsdl.model.extensions.bpel.CorrelationProperty;
056: import org.netbeans.modules.xml.xam.dom.DocumentComponent;
057: import org.netbeans.modules.xml.wsdl.model.extensions.bpel.PropertyAlias;
058: import org.netbeans.modules.bpel.validation.core.WsdlValidator;
059: import static org.netbeans.modules.soa.ui.util.UI.*;
060:
061: /**
062: * @author Vladimir Yaroslavskiy
063: * @version 2008.02.15
064: */
065: public final class Validator extends WsdlValidator {
066:
067: public WSDLVisitor getVisitor() {
068: return new ChildVisitor() {
069: @Override
070: public void visit(ExtensibilityElement element) {
071: //out("WSDL VISIT: " + element);
072: if (!(element instanceof PropertyAlias)) {
073: return;
074: }
075: // # 90324
076: PropertyAlias alias = (PropertyAlias) element;
077: //out();
078: //out("PROPERTY ALIAS: " + alias);
079: //out("Query: " + alias.getQuery());
080:
081: if (alias.getQuery() != null) {
082: return;
083: }
084: DocumentComponent query = getQuery(alias);
085:
086: if (query != null) {
087: addError("FIX_QUERY_PREFIX", alias); // NOI18N
088: return;
089: }
090: // property
091: NamedComponentReference<CorrelationProperty> ref1 = alias
092: .getPropertyName();
093:
094: if (ref1 == null) {
095: return;
096: }
097: CorrelationProperty property = ref1.get();
098: //out();
099: //out("property: " + getName(property));
100:
101: if (property == null) {
102: return;
103: }
104: Component propertyType = getType(property);
105: //out("!! propertyType: " + getName(propertyType));
106:
107: if (propertyType == null) {
108: return;
109: }
110: // message
111: NamedComponentReference<Message> ref2 = alias
112: .getMessageType();
113:
114: if (ref2 == null) {
115: return;
116: }
117: Message message = ref2.get();
118: //out("message: " + getName(message));
119:
120: if (message == null) {
121: return;
122: }
123: // part
124: String partName = alias.getPart();
125: //out("partName: " + partName);
126:
127: if (partName == null) {
128: return;
129: }
130: Collection<Part> parts = message.getParts();
131:
132: if (parts == null) {
133: return;
134: }
135: Part aliasPart = null;
136:
137: for (Part part : parts) {
138: if (partName.equals(part.getName())) {
139: aliasPart = part;
140: break;
141: }
142: }
143: //out("aliasPart: " + getName(aliasPart));
144: if (aliasPart == null) {
145: return;
146: }
147: // type
148: Component aliasType = getType(aliasPart);
149: //out("!! aliasType: " + getName(aliasType));
150:
151: if (aliasType == null) {
152: return;
153: }
154: // check
155: if (aliasType != propertyType) {
156: addError("FIX_TYPE_IN_PROPERTY_ALIAS", alias,
157: getTypeName(aliasType),
158: getTypeName(propertyType)); // NOI18N
159: //out("ERROR: " + getTypeName(aliasType) + " " + getTypeName(propertyType));
160: }
161: //out();
162: }
163: };
164: }
165:
166: private Component getType(CorrelationProperty property) {
167: NamedComponentReference<GlobalType> ref1 = property.getType();
168:
169: if (ref1 != null) {
170: GlobalType type = ref1.get();
171:
172: if (type != null) {
173: return getTypeOfElement(type);
174: }
175: }
176: NamedComponentReference<GlobalElement> ref2 = property
177: .getElement();
178:
179: if (ref2 != null) {
180: GlobalElement element = ref2.get();
181:
182: if (element != null) {
183: return getTypeOfElement(element);
184: }
185: }
186: return null;
187: }
188:
189: private Component getType(Part part) {
190: NamedComponentReference<GlobalType> ref1 = part.getType();
191:
192: if (ref1 != null) {
193: GlobalType type = ref1.get();
194:
195: if (type != null) {
196: return getTypeOfElement(type);
197: }
198: }
199: NamedComponentReference<GlobalElement> ref2 = part.getElement();
200:
201: if (ref2 != null) {
202: GlobalElement element = ref2.get();
203:
204: if (element != null) {
205: return getTypeOfElement(element);
206: }
207: }
208: return null;
209: }
210:
211: private DocumentComponent getQuery(PropertyAlias alias) {
212: List<WSDLComponent> children = alias.getChildren();
213:
214: for (WSDLComponent child : children) {
215: //out(" child: " + child);
216: if (!(child instanceof DocumentComponent)) {
217: continue;
218: }
219: DocumentComponent document = (DocumentComponent) child;
220: String tag = document.getPeer().getTagName();
221: //out(" tag: " + tag);
222: if (tag.endsWith("query")) { // NOI18N
223: return document;
224: }
225: }
226: return null;
227: }
228: }
|