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 * <h5 class='section'>See Also:</h5><ul> 056 * </ul> 057 * 058 * @serial exclude 059 */ 060public class BeanDictionaryList extends ArrayList<Class<?>> { 061 private static final long serialVersionUID = 1L; 062 063 /** 064 * Constructor. 065 * 066 * @param c 067 * The list of bean classes to add to this dictionary. 068 * Classes must either specify a {@link Bean#typeName() @Bean(typeName)} value or be another subclass of 069 * <c>BeanDictionaryList</c>. 070 */ 071 protected BeanDictionaryList(Class<?>...c) { 072 append(c); 073 } 074 075 /** 076 * Append one or more bean classes to this bean dictionary. 077 * 078 * @param c 079 * The list of bean classes to add to this dictionary. 080 * Classes must either specify a {@link Bean#typeName() @Bean(typeName)} value or be another subclass of 081 * <c>BeanDictionaryList</c>. 082 * @return This object. 083 */ 084 protected BeanDictionaryList append(Class<?>...c) { 085 for (Class<?> cc : c) 086 add(cc); 087 return this; 088 } 089}