1 /* 2 * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. Oracle designates this 8 * particular file as subject to the "Classpath" exception as provided 9 * by Oracle in the LICENSE file that accompanied this code. 10 * 11 * This code is distributed in the hope that it will be useful, but WITHOUT 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 * version 2 for more details (a copy is included in the LICENSE file that 15 * accompanied this code). 16 * 17 * You should have received a copy of the GNU General Public License version 18 * 2 along with this work; if not, write to the Free Software Foundation, 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 * 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 * or visit www.oracle.com if you need additional information or have any 23 * questions. 24 */ 25 26 package com.sun.tools.internal.ws.processor.model.jaxb; 27 28 import com.sun.tools.internal.ws.processor.model.ModelException; 29 import com.sun.tools.internal.ws.processor.model.java.JavaStructureType; 30 31 import javax.xml.namespace.QName; 32 import java.util.*; 33 34 /** 35 * Top-level binding between JAXB generated Java type 36 * and XML Schema element declaration. 37 * 38 * @author 39 * Kohsuke Kawaguchi (kohsuke.kawaguchi@sun.com) 40 */ 41 public class JAXBStructuredType extends JAXBType { 42 43 public JAXBStructuredType(JAXBType jaxbType){ 44 super(jaxbType); 45 } 46 47 public JAXBStructuredType() {} 48 49 public JAXBStructuredType(QName name) { 50 this(name, null); 51 } 52 53 public JAXBStructuredType(QName name, JavaStructureType javaType) { 54 super(name, javaType); 55 } 56 57 public void add(JAXBElementMember m) { 58 if (_elementMembersByName.containsKey(m.getName())) { 59 throw new ModelException("model.uniqueness"); 60 } 61 _elementMembers.add(m); 62 if (m.getName() != null) { 63 _elementMembersByName.put(m.getName().getLocalPart(), m); 64 } 65 } 66 67 public Iterator getElementMembers() { 68 return _elementMembers.iterator(); 69 } 70 71 public int getElementMembersCount() { 72 return _elementMembers.size(); 73 } 74 75 /* serialization */ 76 public List getElementMembersList() { 77 return _elementMembers; 78 } 79 80 /* serialization */ 81 public void setElementMembersList(List l) { 82 _elementMembers = l; 83 } 84 85 public void addSubtype(JAXBStructuredType type) { 86 if (_subtypes == null) { 87 _subtypes = new HashSet(); 88 } 89 _subtypes.add(type); 90 type.setParentType(this); 91 } 92 93 public Iterator getSubtypes() { 94 if (_subtypes != null) { 95 return _subtypes.iterator(); 96 } 97 return null; 98 } 99 100 /* (non-Javadoc) 101 * @see JAXBType#isUnwrapped() 102 */ 103 public boolean isUnwrapped() { 104 return true; 105 } 106 /* serialization */ 107 public Set getSubtypesSet() { 108 return _subtypes; 109 } 110 111 /* serialization */ 112 public void setSubtypesSet(Set s) { 113 _subtypes = s; 114 } 115 116 public void setParentType(JAXBStructuredType parent) { 117 if (_parentType != null && 118 parent != null && 119 !_parentType.equals(parent)) { 120 121 throw new ModelException("model.parent.type.already.set", 122 new Object[] { getName().toString(), 123 _parentType.getName().toString(), 124 parent.getName().toString()}); 125 } 126 this._parentType = parent; 127 } 128 129 public JAXBStructuredType getParentType() { 130 return _parentType; 131 } 132 133 134 private List _elementMembers = new ArrayList(); 135 private Map _elementMembersByName = new HashMap(); 136 private Set _subtypes = null; 137 private JAXBStructuredType _parentType = null; 138 }