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.semantic;
043:
044: import java.util.ArrayList;
045: import java.util.List;
046: import org.netbeans.modules.xml.schema.model.GlobalElement;
047: import org.netbeans.modules.xml.schema.model.GlobalType;
048: import org.netbeans.modules.xml.wsdl.model.Message;
049: import org.netbeans.modules.xml.wsdl.model.PortType;
050: import org.netbeans.modules.xml.wsdl.model.extensions.bpel.CorrelationProperty;
051: import org.netbeans.modules.xml.wsdl.model.extensions.bpel.PartnerLinkType;
052: import org.netbeans.modules.xml.wsdl.model.extensions.bpel.PropertyAlias;
053: import org.netbeans.modules.xml.wsdl.model.extensions.bpel.Role;
054: import org.netbeans.modules.xml.wsdl.model.extensions.bpel.validation.StringAttribute;
055: import org.netbeans.modules.xml.wsdl.model.extensions.bpel.validation.ValidationVisitor;
056: import org.netbeans.modules.xml.xam.Component;
057: import org.netbeans.modules.xml.xam.dom.NamedComponentReference;
058: import org.netbeans.modules.xml.xam.spi.Validator;
059: import org.netbeans.modules.xml.xam.spi.Validator.ResultItem;
060: import org.openide.util.NbBundle;
061:
062: /**
063: *
064: * @author radval
065: */
066: public class BPELExtensionSemanticVisitor extends ValidationVisitor {
067:
068: public static final String VAL_INVALID_PROPERTY_ALIAS_MESSAGE_TYPE = "VAL_INVALID_PROPERTY_ALIAS_MESSAGE_TYPE"; //NOT I18N
069: public static final String FIX_INVALID_PROPERTY_ALIAS_MESSAGE_TYPE = "FIX_INVALID_PROPERTY_ALIAS_MESSAGE_TYPE"; //NOT I18N
070:
071: public static final String VAL_INVALID_PROPERTY_ALIAS_ELEMENT = "VAL_INVALID_PROPERTY_ALIAS_ELEMENT"; //NOT I18N
072: public static final String FIX_INVALID_PROPERTY_ALIAS_ELEMENT = "FIX_INVALID_PROPERTY_ALIAS_ELEMENT"; //NOT I18N
073:
074: public static final String VAL_INVALID_PROPERTY_ALIAS_TYPE = "VAL_INVALID_PROPERTY_ALIAS_TYPE"; //NOT I18N
075: public static final String FIX_INVALID_PROPERTY_ALIAS_TYPE = "FIX_INVALID_PROPERTY_ALIAS_TYPE"; //NOT I18N
076:
077: public static final String VAL_INVALID_PORT_TYPE = "VAL_INVALID_PORT_TYPE"; //NOT I18N
078: public static final String FIX_INVALID_PORT_TYPE = "FIX_INVALID_PORT_TYPE"; //NOT I18N
079:
080: public static final String VAL_INVALID_PARTNERLINK_TYPE = "VAL_INVALID_PARTNERLINK_TYPE"; //NOT I18N
081: public static final String FIX_INVALID_PARTNERLINK_TYPE = "FIX_INVALID_PARTNERLINK_TYPE"; //NOT I18N
082:
083: public static final String VAL_INVALID_PROPERTY_NAME = "VAL_INVALID_PROPERTY_NAME";
084: public static final String FIX_INVALID_PROPERTY_NAME = "FIX_INVALID_PROPERTY_NAME";
085:
086: private Validator mValidator;
087:
088: public BPELExtensionSemanticVisitor(Validator validator) {
089: this .mValidator = validator;
090: init();
091: }
092:
093: public void visit(PartnerLinkType c) {
094: Role role1 = c.getRole1();
095: if (role1 != null) {
096: visit(role1);
097: }
098:
099: Role role2 = c.getRole2();
100: if (role2 != null) {
101: visit(role2);
102: }
103:
104: //make sure there only two roles specified
105: if (c.getChildren(Role.class).size() > 2) {
106: addNewResultItem(Validator.ResultType.ERROR, c, NbBundle
107: .getMessage(getClass(),
108: VAL_INVALID_PARTNERLINK_TYPE), NbBundle
109: .getMessage(getClass(),
110: FIX_INVALID_PARTNERLINK_TYPE));
111: }
112: }
113:
114: public void visit(Role c) {
115: //make sure role's portType if specified in accessible
116: NamedComponentReference<PortType> portTypeRef = c.getPortType();
117: String portType = c.getAttribute(new StringAttribute(
118: Role.PORT_TYPE_PROPERTY));
119: if ((portTypeRef == null || portTypeRef.get() == null)
120: && portType != null) {
121:
122: addNewResultItem(Validator.ResultType.ERROR, c, NbBundle
123: .getMessage(getClass(), VAL_INVALID_PORT_TYPE,
124: portType), NbBundle.getMessage(getClass(),
125: FIX_INVALID_PORT_TYPE, portType));
126: }
127: }
128:
129: public void visit(PropertyAlias c) {
130:
131: //make sure propery if specified exists
132: NamedComponentReference<CorrelationProperty> propertyRef = c
133: .getPropertyName();
134: String property = c.getAttribute(new StringAttribute(
135: PropertyAlias.PROPERTY_NAME_PROPERTY));
136: if ((propertyRef == null || propertyRef.get() == null)
137: && property != null) {
138: addNewResultItem(Validator.ResultType.ERROR, c, NbBundle
139: .getMessage(getClass(), VAL_INVALID_PROPERTY_NAME,
140: property), NbBundle.getMessage(getClass(),
141: FIX_INVALID_PROPERTY_NAME, property));
142:
143: }
144:
145: //make sure messageType if specified is accessible
146: NamedComponentReference<Message> msgRef = c.getMessageType();
147: String messageType = c.getAttribute(new StringAttribute(
148: PropertyAlias.MESSAGE_TYPE_PROPERTY));
149: if ((msgRef == null || msgRef.get() == null)
150: && messageType != null) {
151:
152: addNewResultItem(Validator.ResultType.ERROR, c, NbBundle
153: .getMessage(getClass(),
154: VAL_INVALID_PROPERTY_ALIAS_MESSAGE_TYPE,
155: messageType), NbBundle.getMessage(
156: getClass(),
157: FIX_INVALID_PROPERTY_ALIAS_MESSAGE_TYPE,
158: messageType));
159: }
160:
161: //make sure element if specified is accessible
162: NamedComponentReference<GlobalElement> geRef = c.getElement();
163: String element = c.getAttribute(new StringAttribute(
164: PropertyAlias.ELEMENT_PROPERTY));
165: if ((geRef == null || geRef.get() == null) && element != null) {
166:
167: addNewResultItem(Validator.ResultType.ERROR, c,
168: NbBundle
169: .getMessage(getClass(),
170: VAL_INVALID_PROPERTY_ALIAS_ELEMENT,
171: element), NbBundle
172: .getMessage(getClass(),
173: FIX_INVALID_PROPERTY_ALIAS_ELEMENT,
174: element));
175: }
176:
177: //make sure type if specified is accessible
178: NamedComponentReference<GlobalType> gtRef = c.getType();
179: String type = c.getAttribute(new StringAttribute(
180: PropertyAlias.TYPE_PROPERTY));
181: if ((gtRef == null || gtRef.get() == null) && type != null) {
182:
183: addNewResultItem(Validator.ResultType.ERROR, c, NbBundle
184: .getMessage(getClass(),
185: VAL_INVALID_PROPERTY_ALIAS_TYPE, type),
186: NbBundle.getMessage(getClass(),
187: FIX_INVALID_PROPERTY_ALIAS_TYPE, type));
188: }
189:
190: }
191:
192: /**
193: * Fires to-do events to listeners.
194: *
195: * @param toDoEvent
196: * To-do event to fire.
197: * @return <code>true</code> if more events can be accepted by the
198: * listener; <code>false</code> otherwise.
199: */
200: void addNewResultItem(Validator.ResultType type,
201: Component component, String desc, String correction) {
202: ResultItem item = new Validator.ResultItem(mValidator, type,
203: component, desc + correction);
204: getResultItems().add(item);
205: }
206:
207: }
|