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.io.Serializable;
25  import java.net.MalformedURLException;
26  
27  /**
28   * Provides a burlap service object.
29   * <p/>
30   * <p>
31   * <b>Dependencies</b>:
32   * <ul>
33   * <li>Burlap version 2.1.7 or greater</li>
34   * </ul>
35   * </p>
36   *
37   * @author James Carman
38   * @since 1.0
39   */
40  public class BurlapProvider implements ObjectProvider, Serializable
41  {
42  //**********************************************************************************************************************
43  // Fields
44  //**********************************************************************************************************************
45  
46      private Class serviceInterface;
47      private String url;
48  
49  //**********************************************************************************************************************
50  // Constructors
51  //**********************************************************************************************************************
52  
53      public BurlapProvider()
54      {
55      }
56  
57      public BurlapProvider( Class serviceInterface, String url )
58      {
59          this.serviceInterface = serviceInterface;
60          this.url = url;
61      }
62  
63  //**********************************************************************************************************************
64  // ObjectProvider Implementation
65  //**********************************************************************************************************************
66  
67      public Object getObject()
68      {
69          try
70          {
71              return new BurlapProxyFactory().create(serviceInterface, url);
72          }
73          catch( MalformedURLException e )
74          {
75              throw new ObjectProviderException("Invalid url given.", e);
76          }
77      }
78  
79  //**********************************************************************************************************************
80  // Getter/Setter Methods
81  //**********************************************************************************************************************
82  
83      public void setServiceInterface( Class serviceInterface )
84      {
85          this.serviceInterface = serviceInterface;
86      }
87  
88      public void setUrl( String url )
89      {
90          this.url = url;
91      }
92  }
93