001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one
003: * or more contributor license agreements. See the NOTICE file
004: * distributed with this work for additional information
005: * regarding copyright ownership. The ASF licenses this file
006: * to you under the Apache License, Version 2.0 (the
007: * "License"); you may not use this file except in compliance
008: * with the License. You may obtain a copy of the License at
009: *
010: * http://www.apache.org/licenses/LICENSE-2.0
011: *
012: * Unless required by applicable law or agreed to in writing,
013: * software distributed under the License is distributed on an
014: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015: * KIND, either express or implied. See the License for the
016: * specific language governing permissions and limitations
017: * under the License.
018: */
019: package org.apache.axis2.jaxws.description.validator;
020:
021: import org.apache.axis2.jaxws.description.EndpointInterfaceDescription;
022: import org.apache.axis2.jaxws.description.EndpointInterfaceDescriptionJava;
023: import org.apache.axis2.jaxws.description.EndpointInterfaceDescriptionWSDL;
024: import org.apache.axis2.jaxws.description.OperationDescription;
025:
026: import javax.wsdl.Operation;
027: import javax.wsdl.PortType;
028: import java.util.ArrayList;
029: import java.util.Iterator;
030: import java.util.List;
031:
032: /**
033: *
034: */
035: public class EndpointInterfaceDescriptionValidator extends Validator {
036: EndpointInterfaceDescription epInterfaceDesc;
037: EndpointInterfaceDescriptionJava epInterfaceDescJava;
038: EndpointInterfaceDescriptionWSDL epInterfaceDescWSDL;
039:
040: public EndpointInterfaceDescriptionValidator(
041: EndpointInterfaceDescription toValidate) {
042: epInterfaceDesc = toValidate;
043: epInterfaceDescJava = (EndpointInterfaceDescriptionJava) epInterfaceDesc;
044: epInterfaceDescWSDL = (EndpointInterfaceDescriptionWSDL) epInterfaceDesc;
045:
046: }
047:
048: /* (non-Javadoc)
049: * @see org.apache.axis2.jaxws.description.validator.Validator#validate()
050: */
051: @Override
052: public boolean validate() {
053: if (getValidationLevel() == ValidationLevel.OFF) {
054: return VALID;
055: }
056: if (!validateSEIvsWSDLPortType()) {
057: return INVALID;
058: }
059: if (!validateSEIvsImplementation()) {
060: return INVALID;
061: }
062: return VALID;
063: }
064:
065: private boolean validateSEIvsWSDLPortType() {
066: PortType portType = epInterfaceDescWSDL.getWSDLPortType();
067: if (portType != null) {
068: // TODO: Need more validation here, including: operation name, parameters, faults
069: List wsdlOperationList = portType.getOperations();
070:
071: OperationDescription[] dispatchableOpDescArray = epInterfaceDesc
072: .getDispatchableOperations();
073:
074: if (wsdlOperationList.size() != dispatchableOpDescArray.length) {
075: addValidationFailure(
076: this ,
077: "The number of operations in the WSDL "
078: + "portType does not match the number of methods in the SEI or "
079: + "Web service implementation class.");
080: return INVALID;
081: }
082:
083: // If they are the same size, let's check to see if the operation names match
084: if (!checkOperationsMatchMethods(wsdlOperationList,
085: dispatchableOpDescArray)) {
086: addValidationFailure(
087: this ,
088: "The operation names in the WSDL portType "
089: + "do not match the method names in the SEI or Web service i"
090: + "mplementation class.");
091: return INVALID;
092: }
093: }
094: return VALID;
095: }
096:
097: private boolean checkOperationsMatchMethods(List wsdlOperationList,
098: OperationDescription[] opDescArray) {
099: List<String> opNameList = createWSDLOperationNameList(wsdlOperationList);
100: for (int i = 0; i < opDescArray.length; i++) {
101: OperationDescription opDesc = opDescArray[i];
102: if (opNameList.contains(opDesc.getOperationName())) {
103: opNameList.remove(opDesc.getOperationName());
104: } else {
105: return false;
106: }
107: }
108: return true;
109: }
110:
111: private List<String> createWSDLOperationNameList(
112: List wsdlOperationList) {
113: List<String> opNameList = new ArrayList<String>();
114: Iterator wsdlOpIter = wsdlOperationList.iterator();
115: while (wsdlOpIter.hasNext()) {
116: Object obj = wsdlOpIter.next();
117: if (obj instanceof Operation) {
118: Operation operation = (Operation) obj;
119: opNameList.add(operation.getName());
120: }
121: }
122: return opNameList;
123: }
124:
125: private boolean validateSEIvsImplementation() {
126: // REVIEW: This level of validation is currently being done by the DBC Composite validation
127: return VALID;
128: }
129: }
|