001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common Development
008: * and Distribution License("CDDL") (collectively, the "License"). You
009: * may not use this file except in compliance with the License. You can obtain
010: * a copy of the License at https://glassfish.dev.java.net/public/CDDL+GPL.html
011: * or glassfish/bootstrap/legal/LICENSE.txt. See the License for the specific
012: * language governing permissions and limitations under the License.
013: *
014: * When distributing the software, include this License Header Notice in each
015: * file and include the License file at glassfish/bootstrap/legal/LICENSE.txt.
016: * Sun designates this particular file as subject to the "Classpath" exception
017: * as provided by Sun in the GPL Version 2 section of the License file that
018: * accompanied this code. If applicable, add the following below the License
019: * Header, with the fields enclosed by brackets [] replaced by your own
020: * identifying information: "Portions Copyrighted [year]
021: * [name of copyright owner]"
022: *
023: * Contributor(s):
024: *
025: * If you wish your version of this file to be governed by only the CDDL or
026: * only the GPL Version 2, indicate your decision by adding "[Contributor]
027: * elects to include this software in this distribution under the [CDDL or GPL
028: * Version 2] license." If you don't indicate a single choice of license, a
029: * recipient has the option to distribute your version of this file under
030: * either the CDDL, the GPL Version 2 or to extend the choice of license to
031: * its licensees as provided above. However, if you add GPL Version 2 code
032: * and therefore, elected the GPL Version 2 license, then the option applies
033: * only if the new code is made subject to such option by the copyright
034: * holder.
035: */
036: package com.sun.tools.ws.processor.model.jaxb;
037:
038: import com.sun.tools.ws.processor.model.ModelException;
039: import com.sun.tools.ws.processor.model.java.JavaStructureType;
040:
041: import javax.xml.namespace.QName;
042: import java.util.*;
043:
044: /**
045: * Top-level binding between JAXB generated Java type
046: * and XML Schema element declaration.
047: *
048: * @author
049: * Kohsuke Kawaguchi (kohsuke.kawaguchi@sun.com)
050: */
051: public class JAXBStructuredType extends JAXBType {
052:
053: public JAXBStructuredType(JAXBType jaxbType) {
054: super (jaxbType);
055: }
056:
057: public JAXBStructuredType() {
058: }
059:
060: public JAXBStructuredType(QName name) {
061: this (name, null);
062: }
063:
064: public JAXBStructuredType(QName name, JavaStructureType javaType) {
065: super (name, javaType);
066: }
067:
068: public void add(JAXBElementMember m) {
069: if (_elementMembersByName.containsKey(m.getName())) {
070: throw new ModelException("model.uniqueness");
071: }
072: _elementMembers.add(m);
073: if (m.getName() != null) {
074: _elementMembersByName.put(m.getName().getLocalPart(), m);
075: }
076: }
077:
078: public Iterator getElementMembers() {
079: return _elementMembers.iterator();
080: }
081:
082: public int getElementMembersCount() {
083: return _elementMembers.size();
084: }
085:
086: /* serialization */
087: public List getElementMembersList() {
088: return _elementMembers;
089: }
090:
091: /* serialization */
092: public void setElementMembersList(List l) {
093: _elementMembers = l;
094: }
095:
096: public void addSubtype(JAXBStructuredType type) {
097: if (_subtypes == null) {
098: _subtypes = new HashSet();
099: }
100: _subtypes.add(type);
101: type.setParentType(this );
102: }
103:
104: public Iterator getSubtypes() {
105: if (_subtypes != null) {
106: return _subtypes.iterator();
107: }
108: return null;
109: }
110:
111: /* (non-Javadoc)
112: * @see JAXBType#isUnwrapped()
113: */
114: public boolean isUnwrapped() {
115: return true;
116: }
117:
118: /* serialization */
119: public Set getSubtypesSet() {
120: return _subtypes;
121: }
122:
123: /* serialization */
124: public void setSubtypesSet(Set s) {
125: _subtypes = s;
126: }
127:
128: public void setParentType(JAXBStructuredType parent) {
129: if (_parentType != null && parent != null
130: && !_parentType.equals(parent)) {
131:
132: throw new ModelException("model.parent.type.already.set",
133: new Object[] { getName().toString(),
134: _parentType.getName().toString(),
135: parent.getName().toString() });
136: }
137: this ._parentType = parent;
138: }
139:
140: public JAXBStructuredType getParentType() {
141: return _parentType;
142: }
143:
144: private List _elementMembers = new ArrayList();
145: private Map _elementMembersByName = new HashMap();
146: private Set _subtypes = null;
147: private JAXBStructuredType _parentType = null;
148: }
|