001 /*
002 * Licensed to the Apache Software Foundation (ASF) under one or more
003 * contributor license agreements. See the NOTICE file distributed with
004 * this work for additional information regarding copyright ownership.
005 * The ASF licenses this file to You under the Apache License, Version 2.0
006 * (the "License"); you may not use this file except in compliance with
007 * the License. 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.apache.commons.proxy.provider.remoting;
019
020 import com.caucho.burlap.client.BurlapProxyFactory;
021 import org.apache.commons.proxy.ObjectProvider;
022 import org.apache.commons.proxy.exception.ObjectProviderException;
023
024 import java.net.MalformedURLException;
025
026 /**
027 * Provides a burlap service object.
028 *
029 * <p>
030 * <b>Dependencies</b>:
031 * <ul>
032 * <li>Burlap version 2.1.7 or greater</li>
033 * </ul>
034 * </p>
035 * @author James Carman
036 * @since 1.0
037 */
038 public class BurlapProvider implements ObjectProvider
039 {
040 //----------------------------------------------------------------------------------------------------------------------
041 // Fields
042 //----------------------------------------------------------------------------------------------------------------------
043
044 private Class serviceInterface;
045 private String url;
046
047 //----------------------------------------------------------------------------------------------------------------------
048 // Constructors
049 //----------------------------------------------------------------------------------------------------------------------
050
051 public BurlapProvider()
052 {
053 }
054
055 public BurlapProvider( Class serviceInterface, String url )
056 {
057 this.serviceInterface = serviceInterface;
058 this.url = url;
059 }
060
061 //----------------------------------------------------------------------------------------------------------------------
062 // ObjectProvider Implementation
063 //----------------------------------------------------------------------------------------------------------------------
064
065 public Object getObject()
066 {
067 try
068 {
069 return new BurlapProxyFactory().create( serviceInterface, url );
070 }
071 catch( MalformedURLException e )
072 {
073 throw new ObjectProviderException( "Invalid url given.", e );
074 }
075 }
076
077 //----------------------------------------------------------------------------------------------------------------------
078 // Getter/Setter Methods
079 //----------------------------------------------------------------------------------------------------------------------
080
081 public void setServiceInterface( Class serviceInterface )
082 {
083 this.serviceInterface = serviceInterface;
084 }
085
086 public void setUrl( String url )
087 {
088 this.url = url;
089 }
090 }
091