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.transform;
014
015import static org.apache.juneau.internal.StringUtils.*;
016
017import java.util.*;
018
019import org.apache.juneau.*;
020import org.apache.juneau.annotation.*;
021
022/**
023 * Bean filter builder initialized from the contents of a {@link Bean @Bean} annotation found on a class.
024 *
025 * <p>
026 * <b>*** Internal class - Not intended for external use ***</b>
027 *
028 * @param <T> Annotated bean class.
029 */
030public final class AnnotationBeanFilterBuilder<T> extends BeanFilterBuilder<T> {
031
032   /**
033    * Constructor.
034    *
035    * @param annotatedClass The class found to have a {@link Bean @Bean} annotation.
036    * @param annotations
037    *    The {@link Bean @Bean} annotations found on the class and all parent classes in child-to-parent order.
038    * @throws Exception Thrown from property namer constructor.
039    */
040   public AnnotationBeanFilterBuilder(Class<T> annotatedClass, List<Bean> annotations) throws Exception {
041      super(annotatedClass);
042
043      ListIterator<Bean> li = annotations.listIterator(annotations.size());
044      while (li.hasPrevious()) {
045         Bean b = li.previous();
046
047         if (! b.properties().isEmpty())
048            properties(split(b.properties()));
049
050         if (! b.typeName().isEmpty())
051            typeName(b.typeName());
052
053         if (b.sort())
054            sortProperties(true);
055
056         if (b.fluentSetters())
057            fluentSetters(true);
058
059         if (! b.excludeProperties().isEmpty())
060            excludeProperties(split(b.excludeProperties()));
061
062         if (b.propertyNamer() != PropertyNamerDefault.class)
063            propertyNamer(b.propertyNamer());
064
065         if (b.interfaceClass() != Object.class)
066            interfaceClass(b.interfaceClass());
067
068         if (b.stopClass() != Object.class)
069            stopClass(b.stopClass());
070
071         if (b.beanDictionary().length > 0)
072            beanDictionary(b.beanDictionary());
073
074         if (b.propertyFilter() != PropertyFilter.class)
075            propertyFilter(b.propertyFilter());
076      }
077   }
078}