001/* 002 * Licensed to the Apache Software Foundation (ASF) under one or more 003 * contributor license agreements. See the NOTICE file distributed with 004 * this work for additional information regarding copyright ownership. 005 * The ASF licenses this file to You under the Apache License, Version 2.0 006 * (the "License"); you may not use this file except in compliance with 007 * the License. You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 */ 017package org.apache.juneau.annotation; 018 019import static org.apache.juneau.common.utils.Utils.*; 020 021import java.util.*; 022 023import org.apache.juneau.*; 024import org.apache.juneau.reflect.*; 025import org.apache.juneau.svl.*; 026 027/** 028 * Utility classes and methods for the {@link BeanConfig @BeanConfig} annotation. 029 * 030 * <h5 class='section'>See Also:</h5><ul> 031 * </ul> 032 */ 033public class BeanConfigAnnotation { 034 035 /** 036 * Applies {@link BeanConfig} annotations to a {@link org.apache.juneau.BeanContext.Builder}. 037 */ 038 public static class Applier extends AnnotationApplier<BeanConfig,BeanContext.Builder> { 039 040 /** 041 * Constructor. 042 * 043 * @param vr The resolver for resolving values in annotations. 044 */ 045 public Applier(VarResolverSession vr) { 046 super(BeanConfig.class, BeanContext.Builder.class, vr); 047 } 048 049 @Override 050 public void apply(AnnotationInfo<BeanConfig> ai, BeanContext.Builder b) { 051 BeanConfig a = ai.inner(); 052 053 string(a.beanClassVisibility()).map(Visibility::valueOf).ifPresent(x -> b.beanClassVisibility(x)); 054 string(a.beanConstructorVisibility()).map(Visibility::valueOf).ifPresent(x -> b.beanConstructorVisibility(x)); 055 string(a.beanFieldVisibility()).map(Visibility::valueOf).ifPresent(x -> b.beanFieldVisibility(x)); 056 string(a.beanMethodVisibility()).map(Visibility::valueOf).ifPresent(x -> b.beanMethodVisibility(x)); 057 bool(a.beanMapPutReturnsOldValue()).ifPresent(x -> b.beanMapPutReturnsOldValue(x)); 058 bool(a.beansRequireDefaultConstructor()).ifPresent(x -> b.beansRequireDefaultConstructor(x)); 059 bool(a.beansRequireSerializable()).ifPresent(x -> b.beansRequireSerializable(x)); 060 bool(a.beansRequireSettersForGetters()).ifPresent(x -> b.beansRequireSettersForGetters(x)); 061 bool(a.disableBeansRequireSomeProperties()).ifPresent(x -> b.disableBeansRequireSomeProperties(x)); 062 bool(a.debug()).ifPresent(x -> b.debug(x)); 063 bool(a.findFluentSetters()).ifPresent(x -> b.findFluentSetters(x)); 064 bool(a.ignoreInvocationExceptionsOnGetters()).ifPresent(x -> b.ignoreInvocationExceptionsOnGetters(x)); 065 bool(a.ignoreInvocationExceptionsOnSetters()).ifPresent(x -> b.ignoreInvocationExceptionsOnSetters(x)); 066 bool(a.disableIgnoreMissingSetters()).ifPresent(x -> b.disableIgnoreMissingSetters(x)); 067 bool(a.disableIgnoreTransientFields()).ifPresent(x -> b.disableIgnoreTransientFields(x)); 068 bool(a.ignoreUnknownBeanProperties()).ifPresent(x -> b.ignoreUnknownBeanProperties(x)); 069 bool(a.ignoreUnknownEnumValues()).ifPresent(x -> b.ignoreUnknownEnumValues(x)); 070 bool(a.disableIgnoreUnknownNullBeanProperties()).ifPresent(x -> b.disableIgnoreUnknownNullBeanProperties(x)); 071 bool(a.sortProperties()).ifPresent(x -> b.sortProperties(x)); 072 bool(a.useEnumNames()).ifPresent(x -> b.useEnumNames(x)); 073 bool(a.disableInterfaceProxies()).ifPresent(x -> b.disableInterfaceProxies(x)); 074 bool(a.useJavaBeanIntrospector()).ifPresent(x -> b.useJavaBeanIntrospector(x)); 075 string(a.typePropertyName()).ifPresent(x -> b.typePropertyName(x)); 076 string(a.locale()).map(Locale::forLanguageTag).ifPresent(x -> b.locale(x)); 077 string(a.mediaType()).map(MediaType::of).ifPresent(x -> b.mediaType(x)); 078 string(a.timeZone()).map(TimeZone::getTimeZone).ifPresent(x -> b.timeZone(x)); 079 classes(a.dictionary()).ifPresent(x -> b.beanDictionary(x)); 080 classes(a.dictionary_replace()).ifPresent(x -> { b.beanDictionary().clear(); b.beanDictionary(x);}); 081 classes(a.swaps()).ifPresent(x -> b.swaps(x)); 082 classes(a.swaps_replace()).ifPresent(x -> { b.swaps().clear(); b.swaps(x);}); 083 classes(a.notBeanClasses()).ifPresent(x -> b.notBeanClasses(x)); 084 classes(a.notBeanClasses_replace()).ifPresent(x -> { b.notBeanClasses().clear(); b.notBeanClasses(x);}); 085 type(a.propertyNamer()).ifPresent(x -> b.propertyNamer(x)); 086 alist(a.interfaces()).stream().map(x -> BeanAnnotation.create(x).interfaceClass(x).build()).forEach(x -> b.annotations(x)); 087 strings(a.notBeanPackages()).ifPresent(x -> b.notBeanPackages(x)); 088 strings(a.notBeanPackages_replace()).ifPresent(x -> {b.notBeanPackages().clear(); b.notBeanPackages(x);}); 089 } 090 } 091}