Java SOAP Message isExceptionObject(Class o)

Here you can find the source of isExceptionObject(Class o)

Description

is Exception Object

License

Apache License

Declaration

public static boolean isExceptionObject(Class o) throws AssertionError 

Method Source Code

//package com.java2s;
/*//www.j ava 2  s.c  om
 * Copyright 2013, The Sporting Exchange Limited
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

public class Main {
    public static boolean isExceptionObject(Class o) throws AssertionError {

        /*if (o.getName().equalsIgnoreCase("java.lang.Exception")||
        o.getName().equalsIgnoreCase("javax.xml.soap.SOAPException")||
        o.getName().equalsIgnoreCase("com.sun.xml.messaging.saaj.SOAPExceptionImpl")
        ||o.getName().equalsIgnoreCase("com.sun.xml.internal.messaging.saaj.SOAPExceptionImpl")) {
        return true;
        }
        return false;*/

        final String behaviourString = "java.lang.Exception";
        Class<?> behaviour;
        try {
            behaviour = Class.forName(behaviourString);
        } catch (ClassNotFoundException e) {
            throw new RuntimeException("Unable to determine interface behaviour from : " + behaviourString, e);
        }

        return checkBehaviour(o, behaviour);
    }

    /**
     * Check that the specified class implements a given interface or extends a given parent class as the behaviour
     * 
     * @param clazz
     * @param behaviour
     * @return
     */
    public static boolean checkBehaviour(Class<?> clazz, Class<?> behaviour) {

        boolean behaviourFlag = false;

        while (clazz != null) {

            if (clazz == behaviour) {
                behaviourFlag = true;
                break;
            } else {

                Class<?>[] interfaces = clazz.getInterfaces();

                for (Class<?> cls : interfaces) {
                    if (cls == behaviour) {
                        behaviourFlag = true;
                        break;
                    }
                }

                if (behaviourFlag) {
                    break;
                }

                clazz = clazz.getSuperclass();
            }
        }
        return behaviourFlag;
    }
}

Related

  1. getSoapMessageString(SOAPMessage message)
  2. getSOAPMsgFactory()
  3. getString(SOAPMessage msg)
  4. hasAttachments(SOAPMessage message)
  5. invokeOneWay(Dispatch dispatch, String request, String... args)
  6. isFaultMessage(final SOAPMessage msg)
  7. isFaultResponse(SOAPMessage message)
  8. isOutgoingMessage(SOAPMessageContext smc)
  9. isSOAP12(SOAPMessage soapMessage)