001: /*
002: * Portions 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: package com.sun.tools.internal.ws.processor.model.jaxb;
026:
027: import java.util.ArrayList;
028: import java.util.HashMap;
029: import java.util.HashSet;
030: import java.util.Iterator;
031: import java.util.List;
032: import java.util.Map;
033: import java.util.Set;
034:
035: import javax.xml.namespace.QName;
036:
037: import com.sun.tools.internal.ws.processor.model.ModelException;
038: import com.sun.tools.internal.ws.processor.model.java.JavaStructureType;
039:
040: /**
041: * Top-level binding between JAXB generated Java type
042: * and XML Schema element declaration.
043: *
044: * @author
045: * Kohsuke Kawaguchi (kohsuke.kawaguchi@sun.com)
046: */
047: public class JAXBStructuredType extends JAXBType {
048:
049: public JAXBStructuredType(JAXBType jaxbType) {
050: super (jaxbType);
051: }
052:
053: public JAXBStructuredType() {
054: }
055:
056: public JAXBStructuredType(QName name) {
057: this (name, null);
058: }
059:
060: public JAXBStructuredType(QName name, JavaStructureType javaType) {
061: super (name, javaType);
062: }
063:
064: public void add(JAXBElementMember m) {
065: if (_elementMembersByName.containsKey(m.getName())) {
066: throw new ModelException("model.uniqueness");
067: }
068: _elementMembers.add(m);
069: if (m.getName() != null) {
070: _elementMembersByName.put(m.getName().getLocalPart(), m);
071: }
072: }
073:
074: public Iterator getElementMembers() {
075: return _elementMembers.iterator();
076: }
077:
078: public int getElementMembersCount() {
079: return _elementMembers.size();
080: }
081:
082: /* serialization */
083: public List getElementMembersList() {
084: return _elementMembers;
085: }
086:
087: /* serialization */
088: public void setElementMembersList(List l) {
089: _elementMembers = l;
090: }
091:
092: public void addSubtype(JAXBStructuredType type) {
093: if (_subtypes == null) {
094: _subtypes = new HashSet();
095: }
096: _subtypes.add(type);
097: type.setParentType(this );
098: }
099:
100: public Iterator getSubtypes() {
101: if (_subtypes != null) {
102: return _subtypes.iterator();
103: }
104: return null;
105: }
106:
107: /* (non-Javadoc)
108: * @see JAXBType#isUnwrapped()
109: */
110: public boolean isUnwrapped() {
111: return true;
112: }
113:
114: /* serialization */
115: public Set getSubtypesSet() {
116: return _subtypes;
117: }
118:
119: /* serialization */
120: public void setSubtypesSet(Set s) {
121: _subtypes = s;
122: }
123:
124: public void setParentType(JAXBStructuredType parent) {
125: if (_parentType != null && parent != null
126: && !_parentType.equals(parent)) {
127:
128: throw new ModelException("model.parent.type.already.set",
129: new Object[] { getName().toString(),
130: _parentType.getName().toString(),
131: parent.getName().toString() });
132: }
133: this ._parentType = parent;
134: }
135:
136: public JAXBStructuredType getParentType() {
137: return _parentType;
138: }
139:
140: private List _elementMembers = new ArrayList();
141: private Map _elementMembersByName = new HashMap();
142: private Set _subtypes = null;
143: private JAXBStructuredType _parentType = null;
144: }
|