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:
042: package org.netbeans.modules.xml.wsdl.model.extensions.bpel.validation.staticanalysis;
043:
044: import java.util.ArrayList;
045: import java.util.Collection;
046: import java.util.Iterator;
047: import java.util.List;
048: import org.netbeans.modules.xml.schema.model.GlobalElement;
049: import org.netbeans.modules.xml.schema.model.GlobalType;
050: import org.netbeans.modules.xml.wsdl.model.Message;
051: import org.netbeans.modules.xml.wsdl.model.Part;
052: import org.netbeans.modules.xml.wsdl.model.extensions.bpel.CorrelationProperty;
053: import org.netbeans.modules.xml.wsdl.model.extensions.bpel.PartnerLinkType;
054: import org.netbeans.modules.xml.wsdl.model.extensions.bpel.PropertyAlias;
055: import org.netbeans.modules.xml.wsdl.model.extensions.bpel.Role;
056: import org.netbeans.modules.xml.wsdl.model.extensions.bpel.validation.StringAttribute;
057: import org.netbeans.modules.xml.wsdl.model.extensions.bpel.validation.ValidationVisitor;
058: import org.netbeans.modules.xml.xam.Component;
059: import org.netbeans.modules.xml.xam.dom.NamedComponentReference;
060: import org.netbeans.modules.xml.xam.spi.Validator;
061: import org.netbeans.modules.xml.xam.spi.Validator.ResultItem;
062: import org.openide.util.NbBundle;
063:
064: /**
065: *
066: * @author radval
067: */
068: public class BPELExtensionStaticAnalysisVisitor extends
069: ValidationVisitor {
070:
071: public static final String VAL_INVALID_PROPERTY_ALIAS = "VAL_INVALID_PROPERTY_ALIAS"; //NOT I18N
072: public static final String FIX_INVALID_PROPERTY_ALIAS = "VAL_INVALID_PROPERTY_ALIAS"; //NOT 118N
073:
074: public static final String VAL_INVALID_PROPERTY_ALIAS_MUST_SPECIFY_ONE_OF_MESSAGETYPE_OR_ELEMENT_OR_TYPE = "VAL_INVALID_PROPERTY_ALIAS_MUST_SPECIFY_ONE_OF_MESSAGETYPE_OR_ELEMENT_OR_TYPE";
075:
076: public static final String VAL_INVALID_PROPERTY_ALIAS_MUST_SPECIFY_MESSAGE = "VAL_INVALID_PROPERTY_ALIAS_MUST_SPECIFY_MESSAGE";
077:
078: public static final String VAL_INVALID_PROPERTY_ALIAS_MUST_SPECIFY_MESSAGE_PART = "VAL_INVALID_PROPERTY_ALIAS_MUST_SPECIFY_MESSAGE_PART";
079:
080: public static final String VAL_INVALID_PROPERTY_ALIAS_MESSAGE_PART_IS_NOT_FROM_MESSAGE = "VAL_INVALID_PROPERTY_ALIAS_MESSAGE_PART_IS_NOT_FROM_MESSAGE";
081: public static final String FIX_INVALID_PROPERTY_ALIAS_MESSAGE_PART_IS_NOT_FROM_MESSAGE = "FIX_INVALID_PROPERTY_ALIAS_MESSAGE_PART_IS_NOT_FROM_MESSAGE";
082:
083: public static final String VAL_INVALID_PROPERTY = "VAL_INVALID_PROPERTY"; //NOT I18N
084: public static final String FIX_INVALID_PROPERTY = "VAL_INVALID_PROPERTY"; //NOT 118N
085:
086: public static final String VAL_INVALID_PROPERTY_MUST_SPECIFY_ONE_OF_ELEMENT_OR_TYPE = "VAL_INVALID_PROPERTY_MUST_SPECIFY_ONE_OF_ELEMENT_OR_TYPE";
087:
088: private Validator mValidator;
089:
090: public BPELExtensionStaticAnalysisVisitor(Validator validator) {
091: this .mValidator = validator;
092: init();
093: }
094:
095: public void visit(PartnerLinkType c) {
096:
097: }
098:
099: public void visit(Role c) {
100: }
101:
102: public void visit(CorrelationProperty c) {
103: NamedComponentReference<GlobalElement> geRef = c.getElement();
104: String element = c.getAttribute(new StringAttribute(
105: CorrelationProperty.ELEMENT_PROPERTY));
106:
107: NamedComponentReference<GlobalType> gtRef = c.getType();
108: String type = c.getAttribute(new StringAttribute(
109: CorrelationProperty.TYPE_PROPERTY));
110:
111: // only one of element/type attribute should be specified
112: if (element != null && type != null) {
113: addNewResultItem(Validator.ResultType.ERROR, c, NbBundle
114: .getMessage(getClass(), VAL_INVALID_PROPERTY),
115: NbBundle.getMessage(getClass(),
116: FIX_INVALID_PROPERTY));
117:
118: }
119:
120: if (element == null && type == null) {
121: addNewResultItem(
122: Validator.ResultType.ERROR,
123: c,
124: NbBundle
125: .getMessage(getClass(),
126: VAL_INVALID_PROPERTY_MUST_SPECIFY_ONE_OF_ELEMENT_OR_TYPE),
127: "");
128: }
129: }
130:
131: public void visit(PropertyAlias c) {
132: NamedComponentReference<Message> msgRef = c.getMessageType();
133: String messageType = c.getAttribute(new StringAttribute(
134: PropertyAlias.MESSAGE_TYPE_PROPERTY));
135:
136: String part = c.getPart();
137:
138: NamedComponentReference<GlobalElement> geRef = c.getElement();
139: String element = c.getAttribute(new StringAttribute(
140: PropertyAlias.ELEMENT_PROPERTY));
141:
142: NamedComponentReference<GlobalType> gtRef = c.getType();
143: String type = c.getAttribute(new StringAttribute(
144: PropertyAlias.TYPE_PROPERTY));
145:
146: // only one of messageType & part/element/type attribute should be specified
147: if ((messageType != null && element != null)
148: || (messageType != null && type != null)
149: || (element != null && type != null)) {
150: addNewResultItem(Validator.ResultType.ERROR, c,
151: NbBundle.getMessage(getClass(),
152: VAL_INVALID_PROPERTY_ALIAS), NbBundle
153: .getMessage(getClass(),
154: FIX_INVALID_PROPERTY_ALIAS));
155:
156: }
157:
158: //at least one of messageType & part/element/type attribute should be specified
159: if (messageType == null && part == null && element == null
160: && type == null) {
161: addNewResultItem(
162: Validator.ResultType.ERROR,
163: c,
164: NbBundle
165: .getMessage(getClass(),
166: VAL_INVALID_PROPERTY_ALIAS_MUST_SPECIFY_ONE_OF_MESSAGETYPE_OR_ELEMENT_OR_TYPE),
167: "");
168:
169: }
170:
171: if (messageType == null && part != null) {
172: addNewResultItem(
173: Validator.ResultType.ERROR,
174: c,
175: NbBundle
176: .getMessage(getClass(),
177: VAL_INVALID_PROPERTY_ALIAS_MUST_SPECIFY_MESSAGE),
178: "");
179:
180: } else if (messageType != null && part == null) {
181: addNewResultItem(
182: Validator.ResultType.ERROR,
183: c,
184: NbBundle
185: .getMessage(getClass(),
186: VAL_INVALID_PROPERTY_ALIAS_MUST_SPECIFY_MESSAGE_PART),
187: "");
188:
189: }
190:
191: if (messageType != null && part != null) {
192: Message msg = msgRef.get();
193: if (msg != null) {
194: boolean foundPart = false;
195:
196: Collection<Part> parts = msg.getParts();
197: Iterator<Part> it = parts.iterator();
198: while (it.hasNext()) {
199: Part p = it.next();
200: if (p.getName() != null && p.getName().equals(part)) {
201: foundPart = true;
202: break;
203: }
204: }
205:
206: if (!foundPart) {
207: addNewResultItem(
208: Validator.ResultType.ERROR,
209: c,
210: NbBundle
211: .getMessage(
212: getClass(),
213: VAL_INVALID_PROPERTY_ALIAS_MESSAGE_PART_IS_NOT_FROM_MESSAGE,
214: part, messageType),
215: NbBundle
216: .getMessage(
217: getClass(),
218: FIX_INVALID_PROPERTY_ALIAS_MESSAGE_PART_IS_NOT_FROM_MESSAGE,
219: messageType));
220: }
221: }
222: }
223: }
224:
225: /**
226: * Fires to-do events to listeners.
227: *
228: * @param toDoEvent
229: * To-do event to fire.
230: * @return <code>true</code> if more events can be accepted by the
231: * listener; <code>false</code> otherwise.
232: */
233: void addNewResultItem(Validator.ResultType type,
234: Component component, String desc, String correction) {
235: ResultItem item = new Validator.ResultItem(mValidator, type,
236: component, desc + correction);
237: getResultItems().add(item);
238: }
239:
240: }
|