325N/A/*
325N/A * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved.
325N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
325N/A *
325N/A * This code is free software; you can redistribute it and/or modify it
325N/A * under the terms of the GNU General Public License version 2 only, as
325N/A * published by the Free Software Foundation. Oracle designates this
325N/A * particular file as subject to the "Classpath" exception as provided
325N/A * by Oracle in the LICENSE file that accompanied this code.
325N/A *
325N/A * This code is distributed in the hope that it will be useful, but WITHOUT
325N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
325N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
325N/A * version 2 for more details (a copy is included in the LICENSE file that
325N/A * accompanied this code).
325N/A *
325N/A * You should have received a copy of the GNU General Public License version
325N/A * 2 along with this work; if not, write to the Free Software Foundation,
325N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
325N/A *
325N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
325N/A * or visit www.oracle.com if you need additional information or have any
325N/A * questions.
325N/A */
325N/A
325N/Apackage com.sun.xml.internal.ws.server;
325N/A
325N/Aimport com.sun.istack.internal.NotNull;
325N/Aimport com.sun.xml.internal.ws.api.server.SDDocument;
325N/Aimport com.sun.xml.internal.ws.api.server.SDDocumentFilter;
325N/Aimport com.sun.xml.internal.ws.api.server.ServiceDefinition;
325N/Aimport com.sun.xml.internal.ws.wsdl.SDDocumentResolver;
325N/A
325N/Aimport java.util.ArrayList;
325N/Aimport java.util.HashMap;
325N/Aimport java.util.Iterator;
325N/Aimport java.util.List;
325N/Aimport java.util.Map;
325N/A
325N/A/**
325N/A * {@link ServiceDefinition} implementation.
325N/A *
325N/A * <p>
325N/A * You construct a {@link ServiceDefinitionImpl} by first constructing
325N/A * a list of {@link SDDocumentImpl}s.
325N/A *
325N/A * @author Kohsuke Kawaguchi
325N/A */
325N/Apublic final class ServiceDefinitionImpl implements ServiceDefinition, SDDocumentResolver {
325N/A private final List<SDDocumentImpl> docs;
325N/A
325N/A private final Map<String,SDDocumentImpl> bySystemId;
325N/A private final @NotNull SDDocumentImpl primaryWsdl;
325N/A
325N/A /**
325N/A * Set when {@link WSEndpointImpl} is created.
325N/A */
325N/A /*package*/ WSEndpointImpl<?> owner;
325N/A
325N/A /*package*/ final List<SDDocumentFilter> filters = new ArrayList<SDDocumentFilter>();
325N/A
325N/A /**
325N/A * @param docs
325N/A * List of {@link SDDocumentImpl}s to form the description.
325N/A * There must be at least one entry.
325N/A * The first document is considered {@link #getPrimary() primary}.
325N/A */
325N/A public ServiceDefinitionImpl(List<SDDocumentImpl> docs, @NotNull SDDocumentImpl primaryWsdl) {
325N/A assert docs.contains(primaryWsdl);
325N/A this.docs = docs;
325N/A this.primaryWsdl = primaryWsdl;
325N/A
325N/A this.bySystemId = new HashMap<String, SDDocumentImpl>(docs.size());
325N/A for (SDDocumentImpl doc : docs) {
325N/A bySystemId.put(doc.getURL().toExternalForm(),doc);
325N/A doc.setFilters(filters);
325N/A doc.setResolver(this);
325N/A }
325N/A }
325N/A
325N/A /**
325N/A * The owner is set when {@link WSEndpointImpl} is created.
325N/A */
325N/A /*package*/ void setOwner(WSEndpointImpl<?> owner) {
325N/A assert owner!=null && this.owner==null;
325N/A this.owner = owner;
325N/A }
325N/A
325N/A public @NotNull SDDocument getPrimary() {
325N/A return primaryWsdl;
325N/A }
325N/A
325N/A public void addFilter(SDDocumentFilter filter) {
325N/A filters.add(filter);
325N/A }
325N/A
325N/A public Iterator<SDDocument> iterator() {
325N/A return (Iterator)docs.iterator();
325N/A }
325N/A
325N/A /**
325N/A * Gets the {@link SDDocumentImpl} whose {@link SDDocumentImpl#getURL()}
325N/A * returns the specified value.
325N/A *
325N/A * @return
325N/A * null if none is found.
325N/A */
325N/A public SDDocument resolve(String systemId) {
325N/A return bySystemId.get(systemId);
325N/A }
325N/A}