# Example

The following is a sample interceptor and configuration file, where one interceptor class implements all four interfaces.

Configuration file CMServiceConfig.xml:

    			<ServiceInterceptors
    			    <Service name="CMLTBTCP">
    			        <Interceptor action="add">
    			            com.splwg.cis.interceptortest.InterceptorTest
    			        </Interceptor>
    			        <Interceptor action="change">
    			            com.splwg.cis.interceptortest.InterceptorTest
    			        </Interceptor>
    			        <Interceptor action="delete">
    			            com.splwg.cis.interceptortest.InterceptorTest
    			        </Interceptor>
    			        <Interceptor action="read">
    			            com.splwg.cis.interceptortest.InterceptorTest
    			        </Interceptor>
    			    </Service>
    			</ServiceInterceptors>

Class com.splwg.cm.interceptortest.InterceptorTest:

    			package com.splwg.cm.interceptortest;

    			import com.splwg.base.api.serviceinterception.IAddInterceptor;
    			import com.splwg.base.api.serviceinterception.IChangeInterceptor;
    			import com.splwg.base.api.serviceinterception.IDeleteInterceptor;
    			import com.splwg.base.api.serviceinterception.IReadInterceptor;
    			import com.splwg.base.api.service.PageBody;
    			import com.splwg.base.api.service.PageHeader;
    			import com.splwg.base.api.service.RequestContext;

    			public class InterceptorTest implements IAddInterceptor, IChangeInterceptor,
    			        IDeleteInterceptor, IReadInterceptor {

    			    public PageBody aboutToAdd(RequestContext context, PageBody in) {
    			        System.out.println("aboutToAdd: " + in);
    			        return null;
    			    }

    			    public void afterAdd(RequestContext context, PageBody added) {
    			        System.out.println("afterAdd: " + added);
    			    };

    			    public PageBody aboutToChange(RequestContext context, PageBody in) {
    			        System.out.println("aboutToChange: " + in);
    			        return null;
    			    };

    			    public void afterChange(RequestContext context, PageBody changed) {
    			        System.out.println("afterChange: " + changed);
    			    };

    			    public boolean aboutToDelete(RequestContext context, PageBody in) {
    			        System.out.println("aboutToDelete: " + in);
    			        return true;
    			    }

    			    public void afterDelete(RequestContext context, PageBody in) {
    			        System.out.println("afterDelete: " + in);
    			    }

    			    public PageBody aboutToRead(RequestContext context, PageHeader in) {
    			        System.out.println("aboutToRead: " + in);
    			        return null;
    			    }

    			    public void afterRead(RequestContext context, PageBody result) {
    			        System.out.println("afterRead: " + result);
    			    }
    			}

Parent topic: Hooking into Java User Exits (interceptors)