001: /*
002: * Copyright 2006 Sun Microsystems, Inc. All Rights Reserved.
003: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
004: *
005: * This code is free software; you can redistribute it and/or modify it
006: * under the terms of the GNU General Public License version 2 only, as
007: * published by the Free Software Foundation. Sun designates this
008: * particular file as subject to the "Classpath" exception as provided
009: * by Sun in the LICENSE file that accompanied this code.
010: *
011: * This code is distributed in the hope that it will be useful, but WITHOUT
012: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
013: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
014: * version 2 for more details (a copy is included in the LICENSE file that
015: * accompanied this code).
016: *
017: * You should have received a copy of the GNU General Public License version
018: * 2 along with this work; if not, write to the Free Software Foundation,
019: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
020: *
021: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
022: * CA 95054 USA or visit www.sun.com if you need additional information or
023: * have any questions.
024: */
025:
026: package com.sun.xml.internal.bind.annotation;
027:
028: import java.lang.annotation.Retention;
029: import java.lang.annotation.Target;
030:
031: import javax.xml.bind.annotation.XmlAttribute;
032: import javax.xml.bind.annotation.XmlElement;
033: import javax.xml.bind.annotation.XmlElementRef;
034: import javax.xml.bind.annotation.XmlValue;
035:
036: import static java.lang.annotation.ElementType.FIELD;
037: import static java.lang.annotation.ElementType.METHOD;
038: import static java.lang.annotation.RetentionPolicy.RUNTIME;
039:
040: /**
041: * Designates a boolean field/property as a flag to indicate
042: * whether another property is present or not.
043: *
044: * <p>
045: * Sometimes you'd want to map a Java primitive type to an
046: * optional element/attribute. Doing this makes it impossible
047: * to represent the absence of the property, thus you always
048: * end up producing the value when you marshal to XML.
049: *
050: * For example,
051: * <pre>
052: * {@link XmlElement}
053: * class Foo {
054: * {@link XmlElement}
055: * int x;
056: * }
057: *
058: * marshaller.marshal(new Foo());
059: * </pre>
060: * and you get:
061: * <pre><xmp>
062: * <foo><x>0</x></foo>
063: * </xmp></pre>
064: *
065: * <p>
066: * By creating a side boolean field/property that has this annotation,
067: * you can indicate the absence of the property by setting this boolean
068: * to false.
069: * <pre>
070: * {@link XmlElement}
071: * class Foo {
072: * {@link XmlElement}
073: * int x;
074: * {@link XmlIsSet}("x")
075: * boolean xIsPresent;
076: * }
077: *
078: * Foo f = new Foo();
079: * f.x = 5;
080: * f.xIsPresent = false;
081: *
082: * marshaller.marshal(f);
083: *
084: * <xmp>
085: * <foo/>
086: * </xmp>
087: *
088: * f.xIsPresent = true;
089: * <xmp>
090: * <foo><x>5</x></foo>
091: * </xmp>
092: * </pre>
093: *
094: * <p>
095: * A property/field annotated with {@link XmlIsSet} itself will not show up in XML.
096: * It is an error to use this annotation on the same property/field
097: * as {@link XmlElement}, {@link XmlAttribute}, {@link XmlValue}, or {@link XmlElementRef},
098: * ...<b>TBD</b>.
099: *
100: * @deprecated
101: * this hasn't been implemented in the RI, and this hasn't been speced yet.
102: * I believe Joe asked for this feature. I'd like to drop this.
103: *
104: * @author Kohsuke Kawaguchi
105: */
106: @Retention(RUNTIME)
107: @Target({FIELD,METHOD})
108: public @interface XmlIsSet {
109: /**
110: * Specifies the name of the property to attach to.
111: */
112: String value();
113: }
|