org.apache.juneau.swap.BeanInterceptor Maven / Gradle / Ivy
// ***************************************************************************************************************************
// * 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.juneau.swap;
/**
* Bean interceptor.
*
*
* Bean interceptors intercept calls to bean getters and setters to allow them to override values in transit.
*
*
Example:
*
* // Interceptor that strips out sensitive information on Address beans.
* public class AddressInterceptor extends BeanInterceptor<Address> {
*
* @Override
* public Object readProperty(Address bean , String name , Object value ) {
* if ("taxInfo" .equals(name ))
* return "redacted" ;
* return value ;
* }
*
* @Override
* public Object writeProperty(Address bean , String name , Object value ) {
* if ("taxInfo" .equals(name ) && "redacted" .equals(value ))
* return TaxInfoUtils.lookup (bean .getStreet(), bean .getCity(), bean .getState());
* return value ;
* }
* }
*
*
*
* Bean interceptors are registered in the following way:
*
* - {@link org.apache.juneau.annotation.Bean#interceptor() @Bean(interceptor)}
*
- {@link org.apache.juneau.BeanContext.Builder#beanInterceptor(Class,Class)}
*
*
* Example:
*
* // Register interceptor on bean class.
* @Bean (interceptor=AddressInterceptor.class )
* public class Address {
* public String getTaxInfo() {...}
* public void setTaxInfo(String value ) {...}
* }
*
*
* See Also:
* - Swaps
*
*
* @param The bean type.
*/
public class BeanInterceptor {
/** Non-existent bean interceptor. */
public static final class Void extends BeanInterceptor