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.io.Serializable;
025    import java.net.MalformedURLException;
026    
027    /**
028     * Provides a burlap service object.
029     * <p/>
030     * <p>
031     * <b>Dependencies</b>:
032     * <ul>
033     * <li>Burlap version 2.1.7 or greater</li>
034     * </ul>
035     * </p>
036     *
037     * @author James Carman
038     * @since 1.0
039     */
040    public class BurlapProvider implements ObjectProvider, Serializable
041    {
042    //**********************************************************************************************************************
043    // Fields
044    //**********************************************************************************************************************
045    
046        private Class serviceInterface;
047        private String url;
048    
049    //**********************************************************************************************************************
050    // Constructors
051    //**********************************************************************************************************************
052    
053        public BurlapProvider()
054        {
055        }
056    
057        public BurlapProvider( Class serviceInterface, String url )
058        {
059            this.serviceInterface = serviceInterface;
060            this.url = url;
061        }
062    
063    //**********************************************************************************************************************
064    // ObjectProvider Implementation
065    //**********************************************************************************************************************
066    
067        public Object getObject()
068        {
069            try
070            {
071                return new BurlapProxyFactory().create(serviceInterface, url);
072            }
073            catch( MalformedURLException e )
074            {
075                throw new ObjectProviderException("Invalid url given.", e);
076            }
077        }
078    
079    //**********************************************************************************************************************
080    // Getter/Setter Methods
081    //**********************************************************************************************************************
082    
083        public void setServiceInterface( Class serviceInterface )
084        {
085            this.serviceInterface = serviceInterface;
086        }
087    
088        public void setUrl( String url )
089        {
090            this.url = url;
091        }
092    }
093