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