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;
014
015import java.util.*;
016
017import org.apache.juneau.annotation.*;
018
019/**
020 * Represents a collection of bean classes that make up a bean dictionary.
021 *
022 * <p>
023 * The classes in the list must be one of the following:
024 * <ul>
025 *    <li>Beans that provide a dictionary name using the {@link Bean#typeName() @Bean(typeName)} annotation.
026 *    <li>Other subclasses of {@link BeanDictionaryList}.
027 *    <li>Other subclasses of {@link BeanDictionaryMap}.
028 * </ul>
029 *
030 * <h5 class='section'>Example:</h5>
031 * <p class='bjava'>
032 *    <jc>// A bean dictionary list consisting of classes with @Bean(typeName) annotations.</jc>
033 *    <jk>public class</jk> MyBeanDictionaryList <jk>extends</jk> BeanDictionaryList {
034 *
035 *       <jc>// Must provide a no-arg constructor!</jc>
036 *       <jk>public</jk> MyBeanDictionaryList() {
037 *          <jk>super</jk>(ABean.<jk>class</jk>, BBean.<jk>class</jk>, CBean.<jk>class</jk>);
038 *       }
039 *    }
040 *
041 *    <jc>// Use it in a parser.</jc>
042 *    ReaderParser <jv>parser</jv> = JsonParser
043 *       .<jsm>create</jsm>()
044 *       .dictionary(MyBeanDictionaryList.<jk>class</jk>)
045 *       .build();
046 * </p>
047 *
048 * <p>
049 * Subclasses must implement a public no-arg constructor so that it can be instantiated by the bean context code.
050 *
051 * <h5 class='section'>See Also:</h5><ul>
052 * </ul>
053 *
054 * @serial exclude
055 */
056public class BeanDictionaryList extends ArrayList<Class<?>> {
057   private static final long serialVersionUID = 1L;
058
059   /**
060    * Constructor.
061    *
062    * @param c
063    *    The list of bean classes to add to this dictionary.
064    *    Classes must either specify a {@link Bean#typeName() @Bean(typeName)} value or be another subclass of
065    *    <c>BeanDictionaryList</c>.
066    */
067   protected BeanDictionaryList(Class<?>...c) {
068      append(c);
069   }
070
071   /**
072    * Append one or more bean classes to this bean dictionary.
073    *
074    * @param c
075    *    The list of bean classes to add to this dictionary.
076    *    Classes must either specify a {@link Bean#typeName() @Bean(typeName)} value or be another subclass of
077    *    <c>BeanDictionaryList</c>.
078    * @return This object.
079    */
080   protected BeanDictionaryList append(Class<?>...c) {
081      for (Class<?> cc : c)
082         add(cc);
083      return this;
084   }
085}