1 package org.objectweb.celtix.tools.processors.wsdl2.validators; 2 3 import java.util.HashMap ; 4 import java.util.Iterator ; 5 import java.util.Map ; 6 7 import javax.wsdl.Definition; 8 import javax.wsdl.Message; 9 import javax.wsdl.Operation; 10 import javax.wsdl.Part; 11 import javax.wsdl.PortType; 12 import javax.xml.namespace.QName ; 13 14 public class UniqueBodyPartsValidator extends AbstractValidator { 15 private Map <QName , String > uniqueBodyPartsMap = new HashMap <QName , String >(); 16 17 public UniqueBodyPartsValidator(Definition def) { 18 super(def); 19 20 } 21 22 public boolean isValid() { 23 Iterator ite = def.getPortTypes().values().iterator(); 24 while (ite.hasNext()) { 25 PortType portType = (PortType)ite.next(); 26 Iterator ite2 = portType.getOperations().iterator(); 27 while (ite2.hasNext()) { 28 Operation operation = (Operation)ite2.next(); 29 if (operation.getInput() != null) { 30 Message inMessage = operation.getInput().getMessage(); 31 if (inMessage != null && !isUniqueBodyPart(operation.getName(), inMessage)) { 32 return false; 33 } 34 } 35 } 36 } 37 return true; 38 39 } 40 41 private boolean isUniqueBodyPart(String operationName, Message msg) { 42 Map partsMap = msg.getParts(); 43 Iterator ite = partsMap.values().iterator(); 44 if (ite.hasNext()) { 45 Part part = (Part)ite.next(); 46 if (part.getElementName() == null) { 47 return true; 48 } 49 String opName = getOperationNameWithSamePart(operationName, part); 50 if (opName != null) { 51 addErrorMessage("Non unique body parts, operation " + "[ " + opName + " ] " 52 + "and operation [ " + operationName + "] have the same body block " 53 + part.getElementName()); 54 return false; 55 } 56 } 57 return true; 58 } 59 60 private String getOperationNameWithSamePart(String operationName, Part part) { 61 QName partQN = part.getElementName(); 62 String opName = uniqueBodyPartsMap.get(partQN); 63 if (opName == null) { 64 uniqueBodyPartsMap.put(partQN, operationName); 65 return null; 66 } else { 67 return opName; 68 } 69 } 70 71 } 72 | Popular Tags |