1 19 20 package org.netbeans.modules.xml.wsdl.model.extensions.bpel.validation.staticanalysis; 21 22 import java.util.ArrayList ; 23 import java.util.Collection ; 24 import java.util.Iterator ; 25 import java.util.List ; 26 import org.netbeans.modules.xml.schema.model.GlobalElement; 27 import org.netbeans.modules.xml.schema.model.GlobalType; 28 import org.netbeans.modules.xml.wsdl.model.Message; 29 import org.netbeans.modules.xml.wsdl.model.Part; 30 import org.netbeans.modules.xml.wsdl.model.extensions.bpel.CorrelationProperty; 31 import org.netbeans.modules.xml.wsdl.model.extensions.bpel.PartnerLinkType; 32 import org.netbeans.modules.xml.wsdl.model.extensions.bpel.PropertyAlias; 33 import org.netbeans.modules.xml.wsdl.model.extensions.bpel.Role; 34 import org.netbeans.modules.xml.wsdl.model.extensions.bpel.validation.StringAttribute; 35 import org.netbeans.modules.xml.wsdl.model.extensions.bpel.validation.ValidationVisitor; 36 import org.netbeans.modules.xml.xam.Component; 37 import org.netbeans.modules.xml.xam.dom.NamedComponentReference; 38 import org.netbeans.modules.xml.xam.spi.Validator; 39 import org.netbeans.modules.xml.xam.spi.Validator.ResultItem; 40 import org.openide.util.NbBundle; 41 42 46 public class BPELExtensionStaticAnalysisVisitor extends ValidationVisitor { 47 48 public static final String VAL_INVALID_PROPERTY_ALIAS = "VAL_INVALID_PROPERTY_ALIAS"; public static final String FIX_INVALID_PROPERTY_ALIAS = "VAL_INVALID_PROPERTY_ALIAS"; 51 public static final String VAL_INVALID_PROPERTY_ALIAS_MUST_SPECIFY_ONE_OF_MESSAGETYPE_OR_ELEMENT_OR_TYPE = 52 "VAL_INVALID_PROPERTY_ALIAS_MUST_SPECIFY_ONE_OF_MESSAGETYPE_OR_ELEMENT_OR_TYPE"; 53 54 public static final String VAL_INVALID_PROPERTY_ALIAS_MUST_SPECIFY_MESSAGE = 55 "VAL_INVALID_PROPERTY_ALIAS_MUST_SPECIFY_MESSAGE"; 56 57 public static final String VAL_INVALID_PROPERTY_ALIAS_MUST_SPECIFY_MESSAGE_PART = 58 "VAL_INVALID_PROPERTY_ALIAS_MUST_SPECIFY_MESSAGE_PART"; 59 60 61 public static final String VAL_INVALID_PROPERTY_ALIAS_MESSAGE_PART_IS_NOT_FROM_MESSAGE = 62 "VAL_INVALID_PROPERTY_ALIAS_MESSAGE_PART_IS_NOT_FROM_MESSAGE"; 63 public static final String FIX_INVALID_PROPERTY_ALIAS_MESSAGE_PART_IS_NOT_FROM_MESSAGE = 64 "FIX_INVALID_PROPERTY_ALIAS_MESSAGE_PART_IS_NOT_FROM_MESSAGE"; 65 66 public static final String VAL_INVALID_PROPERTY = "VAL_INVALID_PROPERTY"; public static final String FIX_INVALID_PROPERTY = "VAL_INVALID_PROPERTY"; 69 public static final String VAL_INVALID_PROPERTY_MUST_SPECIFY_ONE_OF_ELEMENT_OR_TYPE = 70 "VAL_INVALID_PROPERTY_MUST_SPECIFY_ONE_OF_ELEMENT_OR_TYPE"; 71 72 73 74 private Validator mValidator; 75 76 public BPELExtensionStaticAnalysisVisitor(Validator validator) { 77 this.mValidator = validator; 78 init(); 79 } 80 81 public void visit(PartnerLinkType c) { 82 83 } 84 85 public void visit(Role c) { 86 } 87 88 public void visit(CorrelationProperty c) { 89 NamedComponentReference<GlobalElement> geRef = c.getElement(); 90 String element = c.getAttribute(new StringAttribute(CorrelationProperty.ELEMENT_PROPERTY)); 91 92 NamedComponentReference<GlobalType> gtRef = c.getType(); 93 String type = c.getAttribute(new StringAttribute(CorrelationProperty.TYPE_PROPERTY)); 94 95 if (element != null && type != null) 97 { 98 addNewResultItem(Validator.ResultType.ERROR, 99 c, 100 NbBundle.getMessage(getClass(), VAL_INVALID_PROPERTY), 101 NbBundle.getMessage(getClass(), FIX_INVALID_PROPERTY)); 102 103 } 104 105 if(element == null && type == null) { 106 addNewResultItem(Validator.ResultType.ERROR, 107 c, 108 NbBundle.getMessage(getClass(), VAL_INVALID_PROPERTY_MUST_SPECIFY_ONE_OF_ELEMENT_OR_TYPE), 109 ""); 110 } 111 } 112 113 114 115 public void visit(PropertyAlias c) { 116 NamedComponentReference<Message> msgRef = c.getMessageType(); 117 String messageType = c.getAttribute(new StringAttribute(PropertyAlias.MESSAGE_TYPE_PROPERTY)); 118 119 String part = c.getPart(); 120 121 NamedComponentReference<GlobalElement> geRef = c.getElement(); 122 String element = c.getAttribute(new StringAttribute(PropertyAlias.ELEMENT_PROPERTY)); 123 124 NamedComponentReference<GlobalType> gtRef = c.getType(); 125 String type = c.getAttribute(new StringAttribute(PropertyAlias.TYPE_PROPERTY)); 126 127 if ((messageType != null && element != null) 129 || (messageType != null && type != null) 130 || (element != null && type != null)) 131 { 132 addNewResultItem(Validator.ResultType.ERROR, 133 c, 134 NbBundle.getMessage(getClass(), VAL_INVALID_PROPERTY_ALIAS), 135 NbBundle.getMessage(getClass(), FIX_INVALID_PROPERTY_ALIAS)); 136 137 } 138 139 if(messageType == null && part == null && element == null && type == null) { 141 addNewResultItem(Validator.ResultType.ERROR, 142 c, 143 NbBundle.getMessage(getClass(), VAL_INVALID_PROPERTY_ALIAS_MUST_SPECIFY_ONE_OF_MESSAGETYPE_OR_ELEMENT_OR_TYPE), 144 ""); 145 146 } 147 148 149 if(messageType == null && part != null) { 150 addNewResultItem(Validator.ResultType.ERROR, 151 c, 152 NbBundle.getMessage(getClass(), VAL_INVALID_PROPERTY_ALIAS_MUST_SPECIFY_MESSAGE), 153 ""); 154 155 } else if (messageType != null && part == null) { 156 addNewResultItem(Validator.ResultType.ERROR, 157 c, 158 NbBundle.getMessage(getClass(), VAL_INVALID_PROPERTY_ALIAS_MUST_SPECIFY_MESSAGE_PART), 159 ""); 160 161 } 162 163 if(messageType != null && part != null) { 164 Message msg = msgRef.get(); 165 if(msg != null) { 166 boolean foundPart = false; 167 168 Collection <Part> parts = msg.getParts(); 169 Iterator <Part> it = parts.iterator(); 170 while(it.hasNext()) { 171 Part p = it.next(); 172 if(p.getName() != null && p.getName().equals(part)) { 173 foundPart = true; 174 break; 175 } 176 } 177 178 if(!foundPart) { 179 addNewResultItem(Validator.ResultType.ERROR, 180 c, 181 NbBundle.getMessage(getClass(), VAL_INVALID_PROPERTY_ALIAS_MESSAGE_PART_IS_NOT_FROM_MESSAGE, part, messageType), 182 NbBundle.getMessage(getClass(), FIX_INVALID_PROPERTY_ALIAS_MESSAGE_PART_IS_NOT_FROM_MESSAGE, messageType)); 183 } 184 } 185 } 186 } 187 188 189 197 void addNewResultItem( Validator.ResultType type, 198 Component component, 199 String desc, 200 String correction ) 201 { 202 ResultItem item = new Validator.ResultItem(mValidator, 203 type, 204 component, 205 desc + correction); 206 getResultItems().add(item); 207 } 208 209 210 211 } 212 | Popular Tags |