001/* 002 * ElementListUnion.java March 2011 003 * 004 * Copyright (C) 2011, Niall Gallagher <niallg@users.sf.net> 005 * 006 * Licensed under the Apache License, Version 2.0 (the "License"); 007 * you may not use this file except in compliance with the License. 008 * You may obtain a copy of the License at 009 * 010 * http://www.apache.org/licenses/LICENSE-2.0 011 * 012 * Unless required by applicable law or agreed to in writing, software 013 * distributed under the License is distributed on an "AS IS" BASIS, 014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 015 * implied. See the License for the specific language governing 016 * permissions and limitations under the License. 017 */ 018 019package org.simpleframework.xml; 020 021import java.lang.annotation.Retention; 022import java.lang.annotation.RetentionPolicy; 023 024/** 025 * The <code>ElementListUnion</code> annotation is used to describe 026 * fields and methods that can dynamically match a schema class. Each 027 * union can have a number of different XML class schemas matched based 028 * on an XML element name or the instance type. Here a collection of 029 * element list annotations can be declared. Each annotation expresses 030 * the types the list can accept. Taking the declaration below, if the 031 * annotation is inline, the list can take a number of varying types 032 * all determined from the XML element name. 033 * <pre> 034 * 035 * @ElementListUnion({ 036 * @ElementList(entry="x", inline=true, type=X.class), 037 * @ElementList(entry="y", inline=true, type=Y.class), 038 * @ElementList(entry="z", inline=true, type=Z.class) 039 * }) 040 * private List<Code> codes; 041 * 042 * </pre> 043 * For the above definition the list field can take any of the declared 044 * types. On deserialization the name of the element will determine the 045 * type that is instantiated and inserted in to the list. When the list 046 * is serialized the list entry instance type will determine the name 047 * of the element the instance will serialized as. This provides a 048 * useful means of consume more complicated sources. 049 * 050 * @author Niall Gallagher 051 * 052 * @see org.simpleframework.xml.ElementList 053 */ 054@Retention(RetentionPolicy.RUNTIME) 055public @interface ElementListUnion { 056 057 /** 058 * This provides the <code>ElementList</code> annotations that have 059 * been defined for this union. Each element list describes the 060 * XML class schema to use and the name of the XML element. This 061 * allows the serialization process to determine which elements 062 * map to the defined types. Also, the types define how the XML 063 * is generated for a given instance. 064 * 065 * @return the element lists defined for the union declaration 066 */ 067 ElementList[] value(); 068} 069