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