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:
026: package com.sun.tools.internal.ws.processor.model;
027:
028: import java.util.ArrayList;
029: import java.util.HashMap;
030: import java.util.HashSet;
031: import java.util.Iterator;
032: import java.util.List;
033: import java.util.Map;
034: import java.util.Set;
035: import java.util.EnumSet;
036: import javax.xml.namespace.QName;
037:
038: import com.sun.tools.internal.ws.processor.model.jaxb.JAXBModel;
039: import com.sun.tools.internal.ws.processor.ProcessorActionVersion;
040:
041: /**
042: * The model is used to represent the entire Web Service. The JAX-WS ProcessorActions can process
043: * this Model to generate Java artifacts such as the service interface.
044: *
045: * @author WS Development Team
046: */
047: public class Model extends ModelObject {
048:
049: public Model() {
050: }
051:
052: public Model(QName name) {
053: this .name = name;
054: }
055:
056: public QName getName() {
057: return name;
058: }
059:
060: public void setName(QName n) {
061: name = n;
062: }
063:
064: public String getTargetNamespaceURI() {
065: return targetNamespace;
066: }
067:
068: public void setTargetNamespaceURI(String s) {
069: targetNamespace = s;
070: }
071:
072: public void addService(Service service) {
073: if (servicesByName.containsKey(service.getName())) {
074: throw new ModelException("model.uniqueness");
075: }
076: services.add(service);
077: servicesByName.put(service.getName(), service);
078: }
079:
080: public Service getServiceByName(QName name) {
081: if (servicesByName.size() != services.size()) {
082: initializeServicesByName();
083: }
084: return (Service) servicesByName.get(name);
085: }
086:
087: /* serialization */
088: public List<Service> getServices() {
089: return services;
090: }
091:
092: /* serialization */
093: public void setServices(List<Service> l) {
094: services = l;
095: }
096:
097: private void initializeServicesByName() {
098: servicesByName = new HashMap();
099: if (services != null) {
100: for (Service service : services) {
101: if (service.getName() != null
102: && servicesByName
103: .containsKey(service.getName())) {
104:
105: throw new ModelException("model.uniqueness");
106: }
107: servicesByName.put(service.getName(), service);
108: }
109: }
110: }
111:
112: public void addExtraType(AbstractType type) {
113: extraTypes.add(type);
114: }
115:
116: public Iterator getExtraTypes() {
117: return extraTypes.iterator();
118: }
119:
120: /* serialization */
121: public Set<AbstractType> getExtraTypesSet() {
122: return extraTypes;
123: }
124:
125: /* serialization */
126: public void setExtraTypesSet(Set<AbstractType> s) {
127: extraTypes = s;
128: }
129:
130: public void accept(ModelVisitor visitor) throws Exception {
131: visitor.visit(this );
132: }
133:
134: /**
135: * @return the source version
136: */
137: public String getSource() {
138: return source;
139: }
140:
141: /**
142: * @param string
143: */
144: public void setSource(String string) {
145: source = string;
146: }
147:
148: public ProcessorActionVersion getProcessorActionVersion() {
149: return processorActionVersion;
150: }
151:
152: public void setProcessorActionVersion(ProcessorActionVersion version) {
153: this .processorActionVersion = version;
154: }
155:
156: public void setProcessorActionVersion(String version) {
157: for (ProcessorActionVersion paVersion : EnumSet
158: .allOf(ProcessorActionVersion.class)) {
159: switch (paVersion) {
160: case PRE_20:
161: if (version.equals(ProcessorActionVersion.PRE_20
162: .toString()))
163: processorActionVersion = ProcessorActionVersion.PRE_20;
164: break;
165: case VERSION_20:
166: if (version.equals(ProcessorActionVersion.VERSION_20
167: .toString()))
168: processorActionVersion = ProcessorActionVersion.VERSION_20;
169: break;
170: default:
171: throw new ModelException(
172: "model.invalid.processorActionVersion",
173: new Object[] { version });
174: }
175: }
176: }
177:
178: public void setJAXBModel(JAXBModel jaxBModel) {
179: this .jaxBModel = jaxBModel;
180: }
181:
182: public JAXBModel getJAXBModel() {
183: return jaxBModel;
184: }
185:
186: private QName name;
187: private String targetNamespace;
188: private List<Service> services = new ArrayList<Service>();
189: private Map<QName, Service> servicesByName = new HashMap<QName, Service>();
190: private Set<AbstractType> extraTypes = new HashSet<AbstractType>();
191: private String source;
192: private JAXBModel jaxBModel = null;
193: private ProcessorActionVersion processorActionVersion = ProcessorActionVersion.VERSION_20;
194: }
|