001: /*
002: * Copyright (c) 1998-2008 Caucho Technology -- all rights reserved
003: *
004: * This file is part of Resin(R) Open Source
005: *
006: * Each copy or derived work must preserve the copyright notice and this
007: * notice unmodified.
008: *
009: * Resin Open Source is free software; you can redistribute it and/or modify
010: * it under the terms of the GNU General Public License as published by
011: * the Free Software Foundation; either version 2 of the License, or
012: * (at your option) any later version.
013: *
014: * Resin Open Source is distributed in the hope that it will be useful,
015: * but WITHOUT ANY WARRANTY; without even the implied warranty of
016: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, or any warranty
017: * of NON-INFRINGEMENT. See the GNU General Public License for more
018: * details.
019: *
020: * You should have received a copy of the GNU General Public License
021: * along with Resin Open Source; if not, write to the
022: *
023: * Free Software Foundation, Inc.
024: * 59 Temple Place, Suite 330
025: * Boston, MA 02111-1307 USA
026: *
027: * @author Scott Ferguson
028: */
029:
030: package javax.xml.ws.spi;
031:
032: import javax.xml.namespace.QName;
033: import javax.xml.ws.Endpoint;
034: import java.io.IOException;
035: import java.io.InputStream;
036: import java.net.URL;
037: import java.util.WeakHashMap;
038: import java.util.logging.Level;
039: import java.util.logging.Logger;
040:
041: public abstract class Provider {
042: private static final Logger log = Logger.getLogger(Provider.class
043: .getName());
044:
045: public static final String JAXWSPROVIDER_PROPERTY = "javax.xml.ws.spi.Provider";
046:
047: private static final WeakHashMap<ClassLoader, String> _providerMap = new WeakHashMap<ClassLoader, String>();
048:
049: protected Provider() {
050: }
051:
052: public abstract Endpoint createAndPublishEndpoint(String address,
053: Object implementor);
054:
055: public abstract Endpoint createEndpoint(String bindingId,
056: Object implementor);
057:
058: public abstract ServiceDelegate createServiceDelegate(
059: URL wsdlDocumentLocation, QName serviceName,
060: Class serviceClass);
061:
062: /** XXX */
063: public static Provider provider() {
064: Thread thread = Thread.currentThread();
065: ClassLoader loader = thread.getContextClassLoader();
066:
067: try {
068: synchronized (_providerMap) {
069: String className = _providerMap.get(loader);
070:
071: if (className == null) {
072: className = findServiceName(loader);
073:
074: if (log.isLoggable(Level.FINER)
075: && className != null)
076: log.finer("jaxws.Provider implementation "
077: + className);
078:
079: _providerMap.put(loader, className);
080: }
081:
082: Class cl = Class.forName(className, false, loader);
083:
084: return (Provider) cl.newInstance();
085: }
086: } catch (Exception e) {
087: throw new RuntimeException(e);
088: }
089: }
090:
091: private static String findServiceName(ClassLoader loader) {
092: InputStream is = null;
093: try {
094: is = loader
095: .getResourceAsStream("META-INF/services/javax.xml.ws.spi.Provider");
096:
097: if (is != null) {
098: StringBuilder sb = new StringBuilder();
099: int ch;
100:
101: while (Character.isWhitespace((ch = is.read()))) {
102: }
103:
104: for (; ch >= 0 && !Character.isWhitespace(ch); ch = is
105: .read()) {
106: sb.append((char) ch);
107: }
108:
109: return sb.toString();
110: }
111: } catch (IOException e) {
112: log.log(Level.FINER, e.toString(), e);
113: } finally {
114: if (is != null)
115: try {
116: is.close();
117: } catch (IOException e) {
118: }
119: }
120:
121: String name = System.getProperty("javax.xml.ws.spi.Provider");
122:
123: if (name != null)
124: return name;
125: else
126: return "com.caucho.soap.jaxws.ProviderImpl";
127: }
128: }
|