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.tools.internal.xjc.reader.xmlschema.bindinfo;
027:
028: import java.util.HashMap;
029: import java.util.Map;
030:
031: import javax.xml.bind.annotation.XmlAttribute;
032: import javax.xml.bind.annotation.XmlElement;
033: import javax.xml.bind.annotation.XmlRootElement;
034: import javax.xml.bind.annotation.XmlTransient;
035: import javax.xml.namespace.QName;
036:
037: import com.sun.tools.internal.xjc.reader.Const;
038: import com.sun.tools.internal.xjc.reader.xmlschema.SimpleTypeBuilder;
039:
040: /**
041: * Enumeration customization.
042: * <p>
043: * This customization binds a simple type to a type-safe enum class.
044: * The actual binding process takes place in {@link SimpleTypeBuilder}.
045: *
046: * <p>
047: * This customization is acknowledged by {@link SimpleTypeBuilder}.
048: *
049: * @author
050: * Kohsuke Kawaguchi (kohsuke.kawaguchi@sun.com)
051: */
052: @XmlRootElement(name="typesafeEnumClass")
053: public final class BIEnum extends AbstractDeclarationImpl {
054:
055: /**
056: * If false, it means not to bind to a type-safe enum.
057: *
058: * this takes precedence over all the other properties of this class.
059: */
060: @XmlAttribute(name="map")
061: private boolean map = true;
062:
063: /** Gets the specified class name, or null if not specified. */
064: @XmlAttribute(name="name")
065: public final String className = null;
066:
067: /**
068: * Gets the javadoc comment specified in the customization.
069: * Can be null if none is specified.
070: */
071: @XmlElement
072: public final String javadoc = null;
073:
074: public boolean isMapped() {
075: return map;
076: }
077:
078: /**
079: * Gets the map that contains XML value->BIEnumMember pairs.
080: * This table is built from <enumMember> customizations.
081: *
082: * Always return non-null.
083: */
084: @XmlTransient
085: public final Map<String, BIEnumMember> members = new HashMap<String, BIEnumMember>();
086:
087: public QName getName() {
088: return NAME;
089: }
090:
091: public void setParent(BindInfo p) {
092: super .setParent(p);
093: for (BIEnumMember mem : members.values())
094: mem.setParent(p);
095: }
096:
097: /** Name of this declaration. */
098: public static final QName NAME = new QName(Const.JAXB_NSURI, "enum");
099:
100: // setter method for JAXB runtime
101: @XmlElement(name="typesafeEnumMember")
102: private void setMembers(BIEnumMember2[] mems) {
103: for (BIEnumMember2 e : mems)
104: members.put(e.value, e);
105: }
106:
107: /**
108: * {@link BIEnumMember} used inside {@link BIEnum} has additional 'value' attribute.
109: */
110: static class BIEnumMember2 extends BIEnumMember {
111: /**
112: * The lexical representaion of the constant to which we are attaching.
113: */
114: @XmlAttribute(required=true)
115: String value;
116: }
117: }
|