001: /*
002: * Copyright (c) 1998-2007 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 Emil Ong
028: */
029:
030: package com.caucho.soa.client;
031:
032: import com.caucho.soa.encoding.UnknownServiceEncodingException;
033:
034: import javax.xml.bind.JAXBException;
035: import java.net.MalformedURLException;
036: import java.util.HashMap;
037: import java.util.logging.Logger;
038:
039: public class ProxyManager {
040: private static final Logger log = Logger
041: .getLogger(ProxyManager.class.getName());
042:
043: private static final HashMap<String, EncodingProxyFactory> _factories = new HashMap<String, EncodingProxyFactory>();
044:
045: public static void addEncodingProxyFactory(String name,
046: EncodingProxyFactory factory) {
047: _factories.put(name, factory);
048: }
049:
050: public static Object getWebServiceProxy(Class serviceInterface,
051: String url) throws MalformedURLException,
052: UnknownServiceEncodingException, JAXBException {
053: String[] components = url.split(":", 2);
054:
055: if (components.length < 2)
056: throw new MalformedURLException(url);
057:
058: String factoryName = components[0];
059: EncodingProxyFactory factory = _factories.get(factoryName);
060:
061: if (factory == null)
062: throw new UnknownServiceEncodingException(factoryName);
063:
064: return factory.getProxy(serviceInterface, components[1]);
065: }
066:
067: public static Object getWebServiceProxy(Class serviceInterface,
068: String url, String jaxbPackages)
069: throws MalformedURLException,
070: UnknownServiceEncodingException, JAXBException {
071: String[] components = url.split(":", 2);
072:
073: if (components.length < 2)
074: throw new MalformedURLException(url);
075:
076: String factoryName = components[0];
077: EncodingProxyFactory factory = _factories.get(factoryName);
078:
079: if (factory == null)
080: throw new UnknownServiceEncodingException(factoryName);
081:
082: return factory.getProxy(serviceInterface, components[1],
083: jaxbPackages);
084: }
085:
086: public static Object getWebServiceProxy(Class serviceInterface,
087: String url, Class[] jaxbClasses)
088: throws MalformedURLException,
089: UnknownServiceEncodingException, JAXBException {
090: String[] components = url.split(":", 2);
091:
092: if (components.length < 2)
093: throw new MalformedURLException(url);
094:
095: String factoryName = components[0];
096: EncodingProxyFactory factory = _factories.get(factoryName);
097:
098: if (factory == null)
099: throw new UnknownServiceEncodingException(factoryName);
100:
101: return factory.getProxy(serviceInterface, components[1],
102: jaxbClasses);
103: }
104:
105: static {
106: addEncodingProxyFactory("hessian",
107: new HessianEncodingProxyFactory());
108: addEncodingProxyFactory("hessian-rest",
109: new HessianRestEncodingProxyFactory());
110: addEncodingProxyFactory("soap", new SoapEncodingProxyFactory());
111: addEncodingProxyFactory("vm", new VMEncodingProxyFactory());
112:
113: JAXBRestEncodingProxyFactory rest = new JAXBRestEncodingProxyFactory();
114: addEncodingProxyFactory("rest", rest);
115: addEncodingProxyFactory("jaxb-rest", rest);
116: }
117: }
|