001 /**
002 *
003 * Copyright 2004 Protique Ltd
004 *
005 * Licensed under the Apache License, Version 2.0 (the "License");
006 * you may not use this file except in compliance with the License.
007 * You may obtain a copy of the License at
008 *
009 * http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 *
017 **/
018 package org.codehaus.activesoap.handler.xstream;
019
020 import org.codehaus.activesoap.RestClient;
021 import org.codehaus.activesoap.RestService;
022 import org.codehaus.activesoap.SoapClient;
023 import org.codehaus.activesoap.SoapService;
024 import org.codehaus.activesoap.transport.LocalTransportClient;
025 import org.codehaus.activesoap.transport.TransportClient;
026
027 /**
028 * A helper class for creating XStreams centric REST and SOAP clients
029 *
030 * @version $Revision: 1.2 $
031 */
032 public class XStreamHelper {
033
034 public static RestClient createRestClient(TransportClient transportClient) {
035 RestService service = new RestService();
036 RestClient client = new RestClient(transportClient, service);
037 useXStream(client);
038 return client;
039 }
040
041 public static SoapClient createSoapClient(TransportClient transportClient) {
042 SoapService service = new SoapService();
043 SoapClient client = new SoapClient(transportClient, service);
044 useXStream(client);
045 return client;
046 }
047
048 public static RestClient newLocalRestClient(RestService service) {
049 RestClient client = new RestClient(new LocalTransportClient(service), service);
050 useXStream(client);
051 return client;
052 }
053
054 public static SoapClient newLocalSoapClient(SoapService service) {
055 SoapClient client = new SoapClient(new LocalTransportClient(service), service);
056 useXStream(client);
057 return client;
058 }
059
060 /**
061 * Configures the given {@link RestClient} to use XStream as the default
062 * client side marshalling layer
063 */
064 public static void useXStream(RestClient client) {
065 client.setClientHandler(new XStreamClientHandler());
066 }
067
068 }