KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > caucho > soa > client > ProxyManager


1 /*
2  * Copyright (c) 1998-2006 Caucho Technology -- all rights reserved
3  *
4  * This file is part of Resin(R) Open Source
5  *
6  * Each copy or derived work must preserve the copyright notice and this
7  * notice unmodified.
8  *
9  * Resin Open Source is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * Resin Open Source is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, or any warranty
17  * of NON-INFRINGEMENT. See the GNU General Public License for more
18  * details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with Resin Open Source; if not, write to the
22  *
23  * Free Software Foundation, Inc.
24  * 59 Temple Place, Suite 330
25  * Boston, MA 02111-1307 USA
26  *
27  * @author Emil Ong
28  */

29
30 package com.caucho.soa.client;
31
32 import com.caucho.soa.encoding.UnknownServiceEncodingException;
33
34 import javax.xml.bind.JAXBException;
35 import java.net.MalformedURLException JavaDoc;
36 import java.util.HashMap JavaDoc;
37 import java.util.logging.Logger JavaDoc;
38
39 public class ProxyManager {
40   private static final Logger JavaDoc log
41     = Logger.getLogger(WebServiceClient.class.getName());
42
43   private static final HashMap JavaDoc<String JavaDoc,EncodingProxyFactory> _factories =
44     new HashMap JavaDoc<String JavaDoc,EncodingProxyFactory>();
45
46   public static void addEncodingProxyFactory(String JavaDoc name,
47                                              EncodingProxyFactory factory)
48   {
49     _factories.put(name, factory);
50   }
51
52   public static Object JavaDoc getWebServiceProxy(Class JavaDoc serviceInterface, String JavaDoc url)
53     throws MalformedURLException JavaDoc, UnknownServiceEncodingException, JAXBException
54   {
55     String JavaDoc[] components = url.split(":", 2);
56
57     if (components.length < 2)
58       throw new MalformedURLException JavaDoc(url);
59
60     String JavaDoc factoryName = components[0];
61     EncodingProxyFactory factory = _factories.get(factoryName);
62
63     if (factory == null)
64       throw new UnknownServiceEncodingException(factoryName);
65
66     return factory.getProxy(serviceInterface, components[1]);
67   }
68
69   public static Object JavaDoc getWebServiceProxy(Class JavaDoc serviceInterface, String JavaDoc url,
70                                           String JavaDoc jaxbPackages)
71     throws MalformedURLException JavaDoc, UnknownServiceEncodingException, JAXBException
72   {
73     String JavaDoc[] components = url.split(":", 2);
74
75     if (components.length < 2)
76       throw new MalformedURLException JavaDoc(url);
77
78     String JavaDoc factoryName = components[0];
79     EncodingProxyFactory factory = _factories.get(factoryName);
80
81     if (factory == null)
82       throw new UnknownServiceEncodingException(factoryName);
83
84     return factory.getProxy(serviceInterface, components[1], jaxbPackages);
85   }
86
87   public static Object JavaDoc getWebServiceProxy(Class JavaDoc serviceInterface, String JavaDoc url,
88                                           Class JavaDoc[] jaxbClasses)
89     throws MalformedURLException JavaDoc, UnknownServiceEncodingException, JAXBException
90   {
91     String JavaDoc[] components = url.split(":", 2);
92
93     if (components.length < 2)
94       throw new MalformedURLException JavaDoc(url);
95
96     String JavaDoc factoryName = components[0];
97     EncodingProxyFactory factory = _factories.get(factoryName);
98
99     if (factory == null)
100       throw new UnknownServiceEncodingException(factoryName);
101
102     return factory.getProxy(serviceInterface, components[1], jaxbClasses);
103   }
104
105   static {
106     addEncodingProxyFactory("hessian", new HessianEncodingProxyFactory());
107     addEncodingProxyFactory("rest", new RestEncodingProxyFactory());
108     addEncodingProxyFactory("soap", new SoapEncodingProxyFactory());
109     addEncodingProxyFactory("vm", new VMEncodingProxyFactory());
110   }
111 }
112
Popular Tags