1 /**
2 * Copyright (C) 2005-2009 Alfresco Software Limited.
3 *
4 * This file is part of the Spring Surf Extension project.
5 *
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 */
18
19 package org.springframework.extensions.webscripts.connector;
20
21 import org.apache.commons.logging.Log;
22 import org.apache.commons.logging.LogFactory;
23 import org.springframework.extensions.surf.exception.ConnectorProviderException;
24 import org.springframework.extensions.surf.exception.ConnectorServiceException;
25
26 /**
27 * A very simple implementation of a connector provider that provisions
28 * web script connectors. These are inherently stateless connectors - no
29 * reuse of credentials or connector session data is applied to the
30 * provisioned connectors.
31 *
32 * The connector provider pattern is utilized by the remote store as well
33 * as the script remote object. Both delegate to connector providers so as
34 * to acquire connectors.
35 *
36 * @author muzquiano
37 */
38 public class ConnectorProviderImpl implements ConnectorProvider
39 {
40 private static final Log logger = LogFactory.getLog(ConnectorProviderImpl.class);
41
42 private ConnectorService connectorService;
43
44 /**
45 * Sets the connector service.
46 *
47 * @param connectorService
48 */
49 public void setConnectorService(ConnectorService connectorService)
50 {
51 this.connectorService = connectorService;
52 }
53
54 /**
55 * Implementation of the contract to provide a Connector for our
56 * the web script framework.
57 *
58 * Allows lazy providing of the Connector object only if the remote store actually needs
59 * it. Otherwise acquiring the Connector when rarely used is an expensive overhead as most
60 * objects are cached by the persister in which case the remote store isn't actually called.
61 */
62 public Connector provide(String endpoint)
63 throws ConnectorProviderException
64 {
65 Connector conn = null;
66
67 try
68 {
69 conn = connectorService.getConnector(endpoint);
70 }
71 catch(ConnectorServiceException cse)
72 {
73 throw new ConnectorProviderException("Unable to provision connector for endpoint: " + endpoint, cse);
74 }
75
76 return conn;
77 }
78 }