KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > celtix > tools > processors > wsdl2 > validators > UniqueBodyPartsValidator


1 package org.objectweb.celtix.tools.processors.wsdl2.validators;
2
3 import java.util.HashMap JavaDoc;
4 import java.util.Iterator JavaDoc;
5 import java.util.Map JavaDoc;
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 JavaDoc;
13
14 public class UniqueBodyPartsValidator extends AbstractValidator {
15     private Map JavaDoc<QName JavaDoc, String JavaDoc> uniqueBodyPartsMap = new HashMap JavaDoc<QName JavaDoc, String JavaDoc>();
16
17     public UniqueBodyPartsValidator(Definition def) {
18         super(def);
19
20     }
21
22     public boolean isValid() {
23         Iterator JavaDoc ite = def.getPortTypes().values().iterator();
24         while (ite.hasNext()) {
25             PortType portType = (PortType)ite.next();
26             Iterator JavaDoc 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 JavaDoc operationName, Message msg) {
42         Map JavaDoc partsMap = msg.getParts();
43         Iterator JavaDoc 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 JavaDoc 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 JavaDoc getOperationNameWithSamePart(String JavaDoc operationName, Part part) {
61         QName JavaDoc partQN = part.getElementName();
62         String JavaDoc 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