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.marshall;
018
019import java.util.*;
020
021/**
022 * Represents a collection of bean classes that make up a bean dictionary.
023 *
024 * <p>
025 * The classes in the list must be one of the following:
026 * <ul>
027 *    <li>Beans that provide a dictionary name using the {@link Marshalled#typeName() @Marshalled(typeName)} annotation.
028 *    <li>Other subclasses of {@link BeanDictionaryList}.
029 *    <li>Other subclasses of {@link BeanDictionaryMap}.
030 * </ul>
031 *
032 * <h5 class='section'>Example:</h5>
033 * <p class='bjava'>
034 *    <jc>// A bean dictionary list consisting of classes with @Marshalled(typeName) annotations.</jc>
035 *    <jk>public class</jk> MyBeanDictionaryList <jk>extends</jk> BeanDictionaryList {
036 *
037 *       <jc>// Must provide a no-arg constructor!</jc>
038 *       <jk>public</jk> MyBeanDictionaryList() {
039 *          <jk>super</jk>(ABean.<jk>class</jk>, BBean.<jk>class</jk>, CBean.<jk>class</jk>);
040 *       }
041 *    }
042 *
043 *    <jc>// Use it in a parser.</jc>
044 *    ReaderParser <jv>parser</jv> = JsonParser
045 *       .<jsm>create</jsm>()
046 *       .dictionary(MyBeanDictionaryList.<jk>class</jk>)
047 *       .build();
048 * </p>
049 *
050 * <p>
051 * Subclasses must implement a public no-arg constructor so that it can be instantiated by the bean context code.
052 *
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 Marshalled#typeName() @Marshalled(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 Marshalled#typeName() @Marshalled(typeName)} value or be another subclass of
077    *    <c>BeanDictionaryList</c>.
078    * @return This object.
079    */
080   protected BeanDictionaryList append(Class<?>...c) {
081      for (var cc : c)
082         add(cc);
083      return this;
084   }
085}