servicedescriptionimpl.java

来自「开源的axis2框架的源码。用于开发WEBSERVER」· Java 代码 · 共 1,278 行 · 第 1/5 页

JAVA
1,278
字号
                seiMethodHashMap.values().iterator();
        while (verifySEIIterator.hasNext()) {
            MethodDescriptionComposite mdc = verifySEIIterator.next();
            // TODO: This does not take into consideration overloaded java methods!
            MethodDescriptionComposite implMDC = compositeHashMap.get(mdc.getMethodName());
            
            if (implMDC == null) {
                // TODO: RAS/NLS
                throw ExceptionFactory.makeWebServiceException(
                        "Validation error: Implementation subclass does not implement method on specified interface.  Implementation class: "
                                + composite.getClassName() + "; missing method name: " +
                                mdc.getMethodName() + "; endpointInterface: " +
                                seic.getClassName());
            } else {
                //At least we found it, now make sure that signatures match up
                
                //Check for exception and signature matching
                validateMethodExceptions(mdc, implMDC, seic.getClassName());
                validateMethodReturnValue(mdc, implMDC, seic.getClassName());
                validateMethodParameters(mdc, implMDC, seic.getClassName());
            }
        }
    }

    private void validateMethodParameters(MethodDescriptionComposite seiMDC,
        MethodDescriptionComposite implMDC, String className) {
        List<ParameterDescriptionComposite> seiPDCList = seiMDC
            .getParameterDescriptionCompositeList();
        List<ParameterDescriptionComposite> implPDCList = implMDC
            .getParameterDescriptionCompositeList();
        if ((seiPDCList == null || seiPDCList.isEmpty())
            && (implPDCList == null || implPDCList.isEmpty())) {
            // There are no parameters on the SEI or the impl; all is well
        } else if ((seiPDCList == null || seiPDCList.isEmpty())
            && !(implPDCList == null || implPDCList.isEmpty())) {
            String message = "Validation error: SEI indicates no parameters but implementation method specifies parameters: "
                + implPDCList
                + "; Implementation class: "
                + composite.getClassName()
                + "; Method name: " + seiMDC.getMethodName() + "; Endpoint Interface: " + className;
            throw ExceptionFactory.makeWebServiceException(message);
        } else if ((seiPDCList != null && !seiPDCList.isEmpty())
            && !(implPDCList != null && !implPDCList.isEmpty())) {
            String message = "Validation error: SEI indicates parameters " + seiPDCList
                + " but implementation method specifies no parameters; Implementation class: "
                + composite.getClassName() + "; Method name: " + seiMDC.getMethodName()
                + "; Endpoint Interface: " + className;
            throw ExceptionFactory.makeWebServiceException(message);
        } else if (seiPDCList.size() != implPDCList.size()) {
            String message = "Validation error: The number of parameters on the SEI method ("
                + seiPDCList.size()
                + ") does not match the number of parameters on the implementation ( "
                + implPDCList.size() + "); Implementation class: " + composite.getClassName()
                + "; Method name: " + seiMDC.getMethodName() + "; Endpoint Interface: " + className;
            throw ExceptionFactory.makeWebServiceException(message);

        } else {
            // Make sure the order and type of parameters match
            // REVIEW: This checks for strict equality of the fully qualified
            // type. It does not
            // take into consideration object hierachy. For example foo(Animal)
            // will not equal bar(Zebra)
            boolean parametersMatch = true;
            String failingMessage = null;
            for (int paramNumber = 0; paramNumber < seiPDCList.size(); paramNumber++) {
                String seiParamType = seiPDCList.get(paramNumber).getParameterType();
                String implParamType = implPDCList.get(paramNumber).getParameterType();
                if (!seiParamType.equals(implParamType)) {
                    parametersMatch = false;
                    failingMessage = "Validation error: SEI and implementation parameters do not match.  Parameter number "
                        + paramNumber
                        + " on the SEI is "
                        + seiParamType
                        + "; on the implementation it is "
                        + implParamType
                        + "; Implementation class: "
                        + composite.getClassName()
                        + "; Method name: "
                        + seiMDC.getMethodName() + "; Endpoint Interface: " + className;
                    break;
                }
            }
            if (!parametersMatch) {
                throw ExceptionFactory.makeWebServiceException(failingMessage);
            }
        }
    }

    private void validateMethodReturnValue(MethodDescriptionComposite seiMDC,
        MethodDescriptionComposite implMDC, String className) {
        String seiReturnValue = seiMDC.getReturnType();
        String implReturnValue = implMDC.getReturnType();

        if (seiReturnValue == null && implReturnValue == null) {
            // Neither specify a return value; all is well
        } else if (seiReturnValue == null && implReturnValue != null) {
            String message = "Validation error: SEI indicates no return value but implementation method specifies return value: "
                + implReturnValue
                + "; Implementation class: "
                + composite.getClassName()
                + "; Method name: " + seiMDC.getMethodName() + "; Endpoint Interface: " + className;
            throw ExceptionFactory.makeWebServiceException(message);
        } else if (seiReturnValue != null && implReturnValue == null) {
            String message = "Validation error: SEI indicates return value " + seiReturnValue
                + " but implementation method specifies no return value; Implementation class: "
                + composite.getClassName() + "; Method name: " + seiMDC.getMethodName()
                + "; Endpoint Interface: " + className;
            throw ExceptionFactory.makeWebServiceException(message);
        } else if (!seiReturnValue.equals(implReturnValue)) {
            String message = "Validation error: SEI return value " + seiReturnValue
                + " does not match implementation method return value " + implReturnValue
                + "; Implementation class: " + composite.getClassName() + "; Method name: "
                + seiMDC.getMethodName() + "; Endpoint Interface: " + className;
            throw ExceptionFactory.makeWebServiceException(message);
        }

    }

    private void validateMethodExceptions ( MethodDescriptionComposite seiMDC, 
        MethodDescriptionComposite implMDC,
        String className) {

        String[] seiExceptions = seiMDC.getExceptions();
        String[] implExceptions = implMDC.getExceptions();

        // An impl can choose to throw fewer checked exceptions than declared on the SEI, but not more.
        // This is analagous to the Java rules for interfaces.
        if (seiExceptions == null) {
            if (implExceptions == null) {
                return;
            } else {
                // SEI delcares no checked exceptions, but the implementation has checked exceptions, which is an error
                throw ExceptionFactory.makeWebServiceException("Validation error: Implementation method signature has more checked exceptions than SEI method signature (0): Implementation class: "
                    + composite.getClassName() 
                    + "; method name: " + seiMDC.getMethodName() 
                    + "; endpointInterface: " + className);
            }
        } else if (implExceptions == null) {
            // Implementation throws fewer checked exceptions than SEI, which is OK.
            return;
        }
        
        // Check the list length; An implementation can not declare more exceptions than the SEI
        if (seiExceptions.length < implExceptions.length) {
            throw ExceptionFactory.makeWebServiceException("Validation error: Implementation method signature has more checked exceptions ("
                + implExceptions.length + ") than SEI method signature ("
                + seiExceptions.length + "): Implementation class: "
                + composite.getClassName() 
                + "; method name: " + seiMDC.getMethodName() 
                + "; endpointInterface: " + className);
        }
        
        // Make sure that each checked exception declared by the 
        // implementation is on the SEI also
        if (implExceptions.length > 0) {                
            for (String implException : implExceptions) {
                boolean foundIt = false;
                if (seiExceptions.length > 0) {         
                    for (String seiException : seiExceptions) {
                        if (seiException.equals(implException)) {
                            foundIt = true;
                            break;
                        }
                    }
                }
                
                if (!foundIt) {
                    throw ExceptionFactory.makeWebServiceException("Validation error: Implementation method signature throws exception " 
                        + implException + "which is not declared on the SEI method signature: Implementation class: "
                        + composite.getClassName() 
                        + "; method name: " + seiMDC.getMethodName() 
                        + "; endpointInterface: " + className);
                }
            }
        }

    }

    /**
     * Adds any methods declared in superclasses to the HashMap.  The hierachy starting with the DBC
     * will be walked up recursively, adding methods from each parent DBC encountered.
     * <p/>
     * Note that this can be used for either classes or interfaces.
     *
     * @param methodMap
     * @param dbc
     */
    private void addSuperClassMethods(HashMap methodMap, DescriptionBuilderComposite dbc) {
        DescriptionBuilderComposite superDBC = dbcMap.get(dbc.getSuperClassName());
        if (superDBC != null) {
            Iterator<MethodDescriptionComposite> mIter =
                    superDBC.getMethodDescriptionsList().iterator();
            while (mIter.hasNext()) {
                MethodDescriptionComposite mdc = mIter.next();
                methodMap.put(mdc.getMethodName(), mdc);
            }
            addSuperClassMethods(methodMap, superDBC);
        }
    }


    /*
      * This method verifies that, if there are any WebMethod with exclude == false, then
      * make sure that we find all of those methods represented in the wsdl. However, if
      * there are no exclusions == false, or there are no WebMethod annotations, then verify
      * that all the public methods are in the wsdl
      */
    private void checkMethodsAgainstWSDL() {
//Verify that, for ImplicitSEI, that all methods that should exist(if one false found, then
//only look for WebMethods w/ False, else take all public methods but ignore those with
//exclude == true
        if (webMethodAnnotationsExist()) {
            if (DescriptionUtils.falseExclusionsExist(composite))
                verifyFalseExclusionsWithWSDL();
            else
                verifyPublicMethodsWithWSDL();
        } else {
            verifyPublicMethodsWithWSDL();
        }
    }

    private void checkImplicitSEIAgainstWSDL() {

        //TODO: If there is a WSDL, then verify that all WebMethods on this class and in the
        //		superclasses chain are represented in the WSDL...Look at logic below to make
        //		sure this really happening


        if (webMethodAnnotationsExist()) {
            if (DescriptionUtils.falseExclusionsExist(composite))
                verifyFalseExclusionsWithWSDL();
            else
                verifyPublicMethodsWithWSDL();
        } else {
            verifyPublicMethodsWithWSDL();
        }

    }

    private void checkSEIAgainstWSDL() {
        //TODO: Place logic here to verify that each publicMethod with WebMethod annot
        //      is contained in the WSDL (If there is a WSDL) If we find
        //	    a WebMethod annotation, use its values for looking in the WSDL

    }

    private void validateSEI(DescriptionBuilderComposite seic) {

        //TODO: Validate SEI superclasses -- hmmm, may be doing this below
        //
        if (seic.getWebServiceAnnot() == null) {
            // TODO: RAS & NLS
            throw ExceptionFactory.makeWebServiceException(
                    "Validation error: SEI does not contain a WebService annotation.  

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?