View Javadoc

1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one or more
3    * contributor license agreements.  See the NOTICE file distributed with
4    * this work for additional information regarding copyright ownership.
5    * The ASF licenses this file to You under the Apache License, Version 2.0
6    * (the "License"); you may not use this file except in compliance with
7    * the License.  You may obtain a copy of the License at
8    *
9    *      http://www.apache.org/licenses/LICENSE-2.0
10   *
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
16   */
17  
18  package org.apache.commons.proxy.provider.remoting;
19  
20  import com.caucho.burlap.client.BurlapProxyFactory;
21  import org.apache.commons.proxy.ObjectProvider;
22  import org.apache.commons.proxy.exception.ObjectProviderException;
23  
24  import java.net.MalformedURLException;
25  
26  /**
27   * Provides a burlap service object.
28   *
29   * <p>
30   * <b>Dependencies</b>:
31   * <ul>
32   *   <li>Burlap version 2.1.7 or greater</li>
33   * </ul>
34   * </p>
35   * @author James Carman
36   * @since 1.0
37   */
38  public class BurlapProvider implements ObjectProvider
39  {
40  //----------------------------------------------------------------------------------------------------------------------
41  // Fields
42  //----------------------------------------------------------------------------------------------------------------------
43  
44      private Class serviceInterface;
45      private String url;
46  
47  //----------------------------------------------------------------------------------------------------------------------
48  // Constructors
49  //----------------------------------------------------------------------------------------------------------------------
50  
51      public BurlapProvider()
52      {
53      }
54  
55      public BurlapProvider( Class serviceInterface, String url )
56      {
57          this.serviceInterface = serviceInterface;
58          this.url = url;
59      }
60  
61  //----------------------------------------------------------------------------------------------------------------------
62  // ObjectProvider Implementation
63  //----------------------------------------------------------------------------------------------------------------------
64  
65      public Object getObject()
66      {
67          try
68          {
69              return new BurlapProxyFactory().create( serviceInterface, url );
70          }
71          catch( MalformedURLException e )
72          {
73              throw new ObjectProviderException( "Invalid url given.", e );
74          }
75      }
76  
77  //----------------------------------------------------------------------------------------------------------------------
78  // Getter/Setter Methods
79  //----------------------------------------------------------------------------------------------------------------------
80  
81      public void setServiceInterface( Class serviceInterface )
82      {
83          this.serviceInterface = serviceInterface;
84      }
85  
86      public void setUrl( String url )
87      {
88          this.url = url;
89      }
90  }
91