1 package org.objectweb.celtix.tools.processors.wsdl2.validators; 2 3 import java.util.Collection ; 4 import java.util.Iterator ; 5 import java.util.List ; 6 import javax.wsdl.Binding; 7 import javax.wsdl.BindingOperation; 8 import javax.wsdl.Definition; 9 import javax.wsdl.Operation; 10 import javax.xml.namespace.QName ; 11 12 import org.objectweb.celtix.tools.extensions.xmlformat.XMLFormat; 13 import org.objectweb.celtix.tools.extensions.xmlformat.XMLFormatBinding; 14 15 public class XMLFormatValidator 16 extends AbstractValidator { 17 18 public XMLFormatValidator(Definition def) { 19 super(def); 20 } 21 22 @Override  23 public boolean isValid() { 24 return checkXMLBindingFormat(); 26 } 27 28 @SuppressWarnings ("unchecked") 29 private boolean checkXMLBindingFormat() { 30 Collection <Binding> bindings = def.getBindings().values(); 31 if (bindings != null) { 32 for (Binding binding : bindings) { 33 Iterator it = binding.getExtensibilityElements().iterator(); 34 while (it.hasNext()) { 35 if (it.next() instanceof XMLFormatBinding) { 36 if (!checkXMLFormat(binding)) { 37 return false; 38 } 39 } else { 40 break; 41 } 42 } 43 } 44 } 45 return true; 46 } 47 48 @SuppressWarnings ("unchecked") 49 private boolean checkXMLFormat(Binding binding) { 50 List <BindingOperation> bos = binding.getBindingOperations(); 51 boolean result = true; 52 boolean needRootNode = false; 53 for (BindingOperation bo : bos) { 54 Operation op = binding.getPortType().getOperation(bo.getName(), null, null); 55 needRootNode = false; 56 if (op.getInput().getMessage().getParts().size() == 0 57 || op.getInput().getMessage().getParts().size() > 1) { 58 needRootNode = true; 59 } 60 if (needRootNode) { 61 String path = "Binding(" + binding.getQName().getLocalPart() 62 + "):BindingOperation(" + bo.getName() + ")"; 63 Iterator itIn = bo.getBindingInput().getExtensibilityElements().iterator(); 64 if (findXMLFormatRootNode(itIn, bo, path + "-input")) { 65 needRootNode = false; 67 if (op.getOutput().getMessage().getParts().size() == 0 68 || op.getOutput().getMessage().getParts().size() > 1) { 69 needRootNode = true; 70 } 71 if (needRootNode) { 72 Iterator itOut = bo.getBindingInput().getExtensibilityElements().iterator(); 73 result = result 74 && findXMLFormatRootNode(itOut, bo, path + "-Output"); 75 if (!result) { 76 return false; 77 } 78 } 79 } else { 80 return false; 81 } 82 } 83 } 84 return true; 85 } 86 87 private boolean findXMLFormatRootNode(Iterator it, BindingOperation bo, String errorPath) { 88 while (it.hasNext()) { 89 Object ext = it.next(); 90 if (ext instanceof XMLFormat) { 91 XMLFormat xmlFormat = (XMLFormat)ext; 92 QName rootNodeName = new QName (def.getTargetNamespace(), bo.getName()); 94 if (xmlFormat.getRootNode() != null) { 95 if (xmlFormat.getRootNode().equals(rootNodeName)) { 96 return true; 97 } else { 98 addErrorMessage(errorPath 99 + ": wrong value of rootNode attribute, the value should be " 100 + rootNodeName); 101 return false; 102 } 103 } else { 104 addErrorMessage(errorPath 105 + ": empty value of rootNode attribute, the value should be " 106 + rootNodeName); 107 return false; 108 } 109 } 110 } 111 addErrorMessage(errorPath + ": missing xml format body element"); 112 return false; 113 } 114 } 115 | Popular Tags |