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.xml.ws.server;
038:
039: import com.sun.istack.NotNull;
040: import com.sun.xml.ws.api.server.SDDocument;
041: import com.sun.xml.ws.api.server.SDDocumentFilter;
042: import com.sun.xml.ws.api.server.ServiceDefinition;
043:
044: import java.net.URL;
045: import java.util.ArrayList;
046: import java.util.HashMap;
047: import java.util.Iterator;
048: import java.util.List;
049: import java.util.Map;
050:
051: /**
052: * {@link ServiceDefinition} implementation.
053: *
054: * <p>
055: * You construct a {@link ServiceDefinitionImpl} by first constructing
056: * a list of {@link SDDocumentImpl}s.
057: *
058: * @author Kohsuke Kawaguchi
059: */
060: public final class ServiceDefinitionImpl implements ServiceDefinition {
061: private final List<SDDocumentImpl> docs;
062:
063: private final Map<String, SDDocumentImpl> bySystemId;
064: private final @NotNull
065: SDDocumentImpl primaryWsdl;
066:
067: /**
068: * Set when {@link WSEndpointImpl} is created.
069: */
070: /*package*/WSEndpointImpl<?> owner;
071:
072: /*package*/final List<SDDocumentFilter> filters = new ArrayList<SDDocumentFilter>();
073:
074: /**
075: * @param docs
076: * List of {@link SDDocumentImpl}s to form the description.
077: * There must be at least one entry.
078: * The first document is considered {@link #getPrimary() primary}.
079: */
080: public ServiceDefinitionImpl(List<SDDocumentImpl> docs, @NotNull
081: SDDocumentImpl primaryWsdl) {
082: assert docs.contains(primaryWsdl);
083: this .docs = docs;
084: this .primaryWsdl = primaryWsdl;
085:
086: this .bySystemId = new HashMap<String, SDDocumentImpl>(docs
087: .size());
088: for (SDDocumentImpl doc : docs) {
089: bySystemId.put(doc.getURL().toExternalForm(), doc);
090:
091: assert doc.owner == null;
092: doc.owner = this ;
093: }
094: }
095:
096: /**
097: * The owner is set when {@link WSEndpointImpl} is created.
098: */
099: /*package*/void setOwner(WSEndpointImpl<?> owner) {
100: assert owner != null && this .owner == null;
101: this .owner = owner;
102: }
103:
104: public @NotNull
105: SDDocument getPrimary() {
106: return primaryWsdl;
107: }
108:
109: public void addFilter(SDDocumentFilter filter) {
110: filters.add(filter);
111: }
112:
113: public Iterator<SDDocument> iterator() {
114: return (Iterator) docs.iterator();
115: }
116:
117: /**
118: * @see #getBySystemId(String)
119: */
120: public SDDocument getBySystemId(URL systemId) {
121: return getBySystemId(systemId.toString());
122: }
123:
124: /**
125: * Gets the {@link SDDocumentImpl} whose {@link SDDocumentImpl#getURL()}
126: * returns the specified value.
127: *
128: * @return
129: * null if none is found.
130: */
131: public SDDocumentImpl getBySystemId(String systemId) {
132: return bySystemId.get(systemId);
133: }
134: }
|