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='bcode w800'>
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 p = JsonParser
043 *       .<jsm>create</jsm>()
044 *       .beanDictionary(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 */
051public class BeanDictionaryList extends ArrayList<Class<?>> {
052   private static final long serialVersionUID = 1L;
053
054   /**
055    * Constructor.
056    *
057    * @param c
058    *    The list of bean classes to add to this dictionary.
059    *    Classes must either specify a {@link Bean#typeName() @Bean(typeName)} value or be another subclass of
060    *    <code>BeanDictionaryList</code>.
061    */
062   protected BeanDictionaryList(Class<?>...c) {
063      append(c);
064   }
065
066   /**
067    * Append one or more bean classes to this bean dictionary.
068    *
069    * @param c
070    *    The list of bean classes to add to this dictionary.
071    *    Classes must either specify a {@link Bean#typeName() @Bean(typeName)} value or be another subclass of
072    *    <code>BeanDictionaryList</code>.
073    * @return This object (for method chaining).
074    */
075   protected BeanDictionaryList append(Class<?>...c) {
076      for (Class<?> cc : c)
077         add(cc);
078      return this;
079   }
080}