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:
037: package com.sun.tools.ws.processor.model.java;
038:
039: import com.sun.tools.ws.processor.model.ModelException;
040:
041: import java.util.*;
042:
043: /**
044: *
045: * @author WS Development Team
046: */
047: public class JavaStructureType extends JavaType {
048:
049: public JavaStructureType() {
050: }
051:
052: public JavaStructureType(String name, boolean present, Object owner) {
053: super (name, present, "null");
054: this .owner = owner;
055: }
056:
057: public void add(JavaStructureMember m) {
058: if (membersByName.containsKey(m.getName())) {
059: throw new ModelException(
060: "model.uniqueness.javastructuretype", new Object[] {
061: m.getName(), getRealName() });
062: }
063: members.add(m);
064: membersByName.put(m.getName(), m);
065: }
066:
067: public JavaStructureMember getMemberByName(String name) {
068: if (membersByName.size() != members.size()) {
069: initializeMembersByName();
070: }
071: return membersByName.get(name);
072: }
073:
074: public Iterator getMembers() {
075: return members.iterator();
076: }
077:
078: public int getMembersCount() {
079: return members.size();
080: }
081:
082: /* serialization */
083: public List<JavaStructureMember> getMembersList() {
084: return members;
085: }
086:
087: /* serialization */
088: public void setMembersList(List<JavaStructureMember> l) {
089: members = l;
090: }
091:
092: private void initializeMembersByName() {
093: membersByName = new HashMap<String, JavaStructureMember>();
094: if (members != null) {
095: for (JavaStructureMember m : members) {
096: if (m.getName() != null
097: && membersByName.containsKey(m.getName())) {
098:
099: throw new ModelException("model.uniqueness");
100: }
101: membersByName.put(m.getName(), m);
102: }
103: }
104: }
105:
106: public boolean isAbstract() {
107: return isAbstract;
108: }
109:
110: public void setAbstract(boolean isAbstract) {
111: this .isAbstract = isAbstract;
112: }
113:
114: public JavaStructureType getSuperclass() {
115: return super class;
116: }
117:
118: public void setSuperclass(JavaStructureType super classType) {
119: super class = super classType;
120: }
121:
122: public void addSubclass(JavaStructureType subclassType) {
123: subclasses.add(subclassType);
124: subclassType.setSuperclass(this );
125: }
126:
127: public Iterator getSubclasses() {
128: if (subclasses == null || subclasses.size() == 0) {
129: return null;
130: }
131: return subclasses.iterator();
132: }
133:
134: public Set getSubclassesSet() {
135: return subclasses;
136: }
137:
138: /* serialization */
139: public void setSubclassesSet(Set s) {
140: subclasses = s;
141: for (Iterator iter = s.iterator(); iter.hasNext();) {
142: ((JavaStructureType) iter.next()).setSuperclass(this );
143: }
144: }
145:
146: public Iterator getAllSubclasses() {
147: Set subs = getAllSubclassesSet();
148: if (subs.size() == 0) {
149: return null;
150: }
151: return subs.iterator();
152: }
153:
154: public Set getAllSubclassesSet() {
155: Set transitiveSet = new HashSet();
156: Iterator subs = subclasses.iterator();
157: while (subs.hasNext()) {
158: transitiveSet.addAll(((JavaStructureType) subs.next())
159: .getAllSubclassesSet());
160: }
161: transitiveSet.addAll(subclasses);
162: return transitiveSet;
163: }
164:
165: public Object getOwner() {
166:
167: // usually a SOAPStructureType
168: return owner;
169: }
170:
171: public void setOwner(Object owner) {
172:
173: // usually a SOAPStructureType
174: this .owner = owner;
175: }
176:
177: private List<JavaStructureMember> members = new ArrayList();
178: private Map<String, JavaStructureMember> membersByName = new HashMap();
179:
180: // known subclasses of this type
181: private Set subclasses = new HashSet();
182: private JavaStructureType super class;
183:
184: // usually a SOAPStructureType
185: private Object owner;
186: private boolean isAbstract = false;
187: }
|