001/*
002 * ElementMapUnion.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>ElementMapUnion</code> annotation is used to describe a 
026 * field or method that can dynamically match a schema class. Each union
027 * can have a number of different XML class schemas matched based on
028 * an XML element name or the instance type. Here a map of element 
029 * map annotations can be declared. Each annotation expresses the types
030 * the map can accept. Taking the declaration below, if the annotation 
031 * is inline, the map can take a number of varying types all determined
032 * from the XML element name.
033 * <pre>
034 * 
035 *    &#64;ElementMapUnion({
036 *       &#64;ElementMap(entry="x", inline=true, valueType=X.class),
037 *       &#64;ElementMap(entry="y", inline=true, valueType=Y.class),
038 *       &#64;ElementMap(entry="z", inline=true, valueType=Z.class)               
039 *    })
040 *    private Map&lt;String, Code&gt; codes;
041 *    
042 * </pre>
043 * For the above definition the map 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 map. When the map
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.ElementMap
053 */
054@Retention(RetentionPolicy.RUNTIME)
055public @interface ElementMapUnion {
056   
057   /**
058    * This provides the <code>ElementMap</code> annotations that have 
059    * been defined for this union. Each element map 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 maps defined for the union declaration
066    */ 
067   ElementMap[] value();
068}