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.transport.tcp.server;
038:
039: import com.sun.istack.NotNull;
040: import com.sun.xml.ws.transport.http.DeploymentDescriptorParser.AdapterFactory;
041: import com.sun.xml.ws.api.model.wsdl.WSDLPort;
042: import com.sun.xml.ws.api.server.PortAddressResolver;
043: import com.sun.xml.ws.api.server.WSEndpoint;
044: import java.util.AbstractList;
045: import java.util.ArrayList;
046: import java.util.HashMap;
047: import java.util.List;
048: import java.util.Map;
049: import javax.xml.namespace.QName;
050:
051: /**
052: * @author jax-ws team
053: */
054: public final class TCPAdapterList extends AbstractList<TCPAdapter>
055: implements AdapterFactory<TCPAdapter> {
056: private final List<TCPAdapter> adapters = new ArrayList<TCPAdapter>();
057: private final Map<String, String> addressMap = new HashMap<String, String>();
058:
059: // TODO: documented because it's used by AS
060: public TCPAdapter createAdapter(final String name,
061: final String urlPattern, final WSEndpoint<?> endpoint) {
062: final TCPAdapter tcpAdapter = new TCPAdapter(name, urlPattern,
063: endpoint);
064: adapters.add(tcpAdapter);
065: final WSDLPort port = endpoint.getPort();
066: if (port != null) {
067: addressMap.put(port.getName().getLocalPart(),
068: getValidPath(urlPattern));
069: }
070: return tcpAdapter;
071: }
072:
073: /**
074: * @return urlPattern without "/*"
075: */
076: private String getValidPath(@NotNull
077: final String urlPattern) {
078: if (urlPattern.endsWith("/*")) {
079: return urlPattern.substring(0, urlPattern.length() - 2);
080: } else {
081: return urlPattern;
082: }
083: }
084:
085: /**
086: * Creates a PortAddressResolver that maps portname to its address
087: */
088: protected PortAddressResolver createPortAddressResolver(
089: final String baseAddress) {
090: return new PortAddressResolver() {
091: public String getAddressFor(QName serviceName, @NotNull
092: String portName) {
093: final String urlPattern = addressMap.get(portName);
094: return (urlPattern == null) ? null : baseAddress
095: + urlPattern;
096: }
097: };
098: }
099:
100: public TCPAdapter get(final int index) {
101: return adapters.get(index);
102: }
103:
104: public int size() {
105: return adapters.size();
106: }
107: }
|