alvinalexander.com | career | drupal | java | mac | mysql | perl | scala | uml | unix  

Apache CXF example source code file (CXFInvocationHandlerBase.java)

This example Apache CXF source code file (CXFInvocationHandlerBase.java) is included in the DevDaily.com "Java Source Code Warehouse" project. The intent of this project is to help you "Learn Java by Example" TM.

Java - Apache CXF tags/keywords

bus, bus, cxfinvocationhandler, cxfinvocationhandler, cxfinvocationhandlerbase, cxfinvocationhandlerdata, cxfmanagedconnection, log, logging, method, object, object, reflection, runtimeexception, subject, throwable, throwable

The Apache CXF CXFInvocationHandlerBase.java source code

/**
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements. See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership. The ASF licenses this file
 * to you 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.
 */
package org.apache.cxf.jca.cxf.handlers;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.logging.Logger;

import javax.security.auth.Subject;

import org.apache.cxf.Bus;
import org.apache.cxf.common.logging.LogUtils;
import org.apache.cxf.jca.cxf.CXFInvocationHandler;
import org.apache.cxf.jca.cxf.CXFInvocationHandlerData;
import org.apache.cxf.jca.cxf.CXFManagedConnection;

abstract class CXFInvocationHandlerBase<T> implements CXFInvocationHandler {

    private static final Logger LOG = LogUtils.getL7dLogger(CXFInvocationHandlerBase.class);

    private CXFInvocationHandler next;
    private CXFInvocationHandlerData data;

    public CXFInvocationHandlerBase(CXFInvocationHandlerData cihd) {
        this.data = cihd;
    }

    public void setNext(CXFInvocationHandler cih) {
        this.next = cih;
    }

    public CXFInvocationHandler getNext() {
        return next;
    }

    public CXFInvocationHandlerData getData() {
        return data;
    }

    protected Object invokeNext(Object proxy, Method method, Object[] args) throws Throwable {
        Object ret = null;
        if (getNext() != null) {
            ret = getNext().invoke(proxy, method, args);
        } else {
            // if the next handler is null , there could be end of the handler chains
            LOG.fine("no more invocation handler");
        }
        return ret;
    }

    protected Throwable getExceptionToThrow(InvocationTargetException ex, Method targetMethod)
        throws Throwable {
        Throwable targetException = ex.getTargetException();
        Throwable ret = null;

        if (isOkToThrow(targetMethod, targetException)) {
            ret = targetException;
        } else {
            //get the exception when call the method
            RuntimeException re = new RuntimeException("Unexpected exception from method " + targetMethod,
                                                      targetException);
            ret = re;
        }
        return ret;
    }

    private boolean isOkToThrow(Method method, Throwable t) {
        return t instanceof RuntimeException || isCheckedException(method, t);
    }

    private boolean isCheckedException(Method method, Throwable t) {
        boolean isCheckedException = false;

        Class<?> checkExceptionTypes[] = (Class[])method.getExceptionTypes();

        for (int i = 0; i < checkExceptionTypes.length; i++) {
            if (checkExceptionTypes[i].isAssignableFrom(t.getClass())) {
                isCheckedException = true;

                break;
            }
        }

        return isCheckedException;
    }

}

class CXFInvocationHandlerDataImpl implements CXFInvocationHandlerData {
    private Bus bus;
    private CXFManagedConnection managedConnection;
    private Subject subject;
    private Object target;
    
    public final void setSubject(Subject sub) {
        this.subject = sub;
    }

    public final Subject getSubject() {
        return subject;
    }

    public final void setBus(final Bus b) {
        this.bus = b;
    }

    public final Bus getBus() {
        return bus;
    }

    public final void setManagedConnection(final CXFManagedConnection cxfManagedConnection) {
        this.managedConnection = cxfManagedConnection;
    }

    public final CXFManagedConnection getManagedConnection() {
        return managedConnection;
    }

    public void setTarget(Object t) {
        this.target = t; 
        
    }

    public Object getTarget() {        
        return target;
    }

}

Other Apache CXF examples (source code examples)

Here is a short list of links related to this Apache CXF CXFInvocationHandlerBase.java source code file:

... this post is sponsored by my books ...

#1 New Release!

FP Best Seller

 

new blog posts

 

Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.

A percentage of advertising revenue from
pages under the /java/jwarehouse URI on this website is
paid back to open source projects.