001/* 002 * Text.java April 2007 003 * 004 * Copyright (C) 2007, 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.RetentionPolicy; 022import java.lang.annotation.Retention; 023 024/** 025 * The <code>Text</code> annotation is used to represent a field or 026 * method that appears as text within an XML element. Methods and 027 * fields annotated with this must represent primitive values, which 028 * means that the type is converted to and from an XML representation 029 * using a <code>Transform</code> object. For example, the primitive 030 * types typically annotated could be strings, integers, or dates. 031 * <p> 032 * One restriction on this annotation is that it can only appear once 033 * within a schema class, and it can not appear with the another XML 034 * element annotations, such as the <code>Element</code> annotation. 035 * It can however appear with any number of <code>Attribute</code> 036 * annotations. 037 * <pre> 038 * 039 * <example one="value" two="value"> 040 * Example text value 041 * </example> 042 * 043 * </pre> 044 * Text values are used when an element containing attributes is 045 * used to wrap a text value with no child elements. This can be 046 * used in place of an element annotation to represent a primitive 047 * which is wrapped in a surrounding XML element. 048 * 049 * @author Niall Gallagher 050 * 051 * @see org.simpleframework.xml.transform.Transformer 052 */ 053@Retention(RetentionPolicy.RUNTIME) 054public @interface Text { 055 056 /** 057 * This is used to provide a default value for the text data if 058 * the annotated field or method is null. This ensures the the 059 * serialization process writes the text data with a value even 060 * if the value is null, and allows deserialization to determine 061 * whether the value within the object was null or not. 062 * 063 * @return this returns the default attribute value to use 064 */ 065 String empty() default ""; 066 067 /** 068 * This is used to determine whether the text is written within 069 * CDATA block or not. If this is set to true then the text is 070 * written within a CDATA block, by default the text is output 071 * as escaped XML. Typically this is used for large text values. 072 * 073 * @return true if the data is to be wrapped in a CDATA block 074 */ 075 boolean data() default false; 076 077 /** 078 * Determines whether the text value is required within the XML 079 * document. Any field marked as not required may not have its 080 * value set when the object is deserialized. If an object is to 081 * be serialized only a null attribute will not appear in XML. 082 * 083 * @return true if the element is required, false otherwise 084 */ 085 boolean required() default true; 086}