View Javadoc

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 java.io.InputStream;
22  import java.io.OutputStream;
23  
24  import javax.servlet.http.HttpServletRequest;
25  import javax.servlet.http.HttpServletResponse;
26  
27  import org.springframework.extensions.config.RemoteConfigElement.ConnectorDescriptor;
28  
29  /**
30   * Abstract class for use by developers in building their own custom connectors.
31   * This provides basic implementations of most of the helper functions that
32   * simply call through to workhorse functions.
33   * 
34   * The primary workhorse functions are the two call methods - one of which
35   * buffers response data onto the response object and the other which streams
36   * data from source to destination.
37   * 
38   * Extending this class makes it easier for developers by removing most of the
39   * tedious stuff and letting them concentrate on the interesting functions.
40   * 
41   * @author muzquiano
42   */
43  public abstract class AbstractConnector implements Connector
44  {
45      private Credentials credentials;
46      protected String endpoint;
47      protected ConnectorDescriptor descriptor;
48      protected ConnectorSession connectorSession;
49      
50      /**
51       * Instantiates a new abstract connector.
52       * 
53       * @param descriptor the descriptor
54       * @param endpoint the endpoint
55       */
56      protected AbstractConnector(ConnectorDescriptor descriptor, String endpoint)
57      {
58          this.descriptor = descriptor;
59          this.endpoint = endpoint;
60      }
61      
62      /* (non-Javadoc)
63       * @see org.alfresco.connector.Connector#call(java.lang.String)
64       */
65      public Response call(String uri)
66      {
67          return call(uri, null);
68      }
69      
70      /* (non-Javadoc)
71       * @see org.alfresco.connector.Connector#setCredentials(org.alfresco.connector.Credentials)
72       */
73      public void setCredentials(Credentials credentials)
74      {
75          this.credentials = credentials;
76      }
77  
78      /* (non-Javadoc)
79       * @see org.alfresco.connector.Connector#getCredentials()
80       */
81      public Credentials getCredentials()
82      {
83          return credentials;
84      }
85  
86      /* (non-Javadoc)
87       * @see org.alfresco.connector.Connector#setEndpoint(java.lang.String)
88       */
89      public void setEndpoint(String endpoint)
90      {
91          this.endpoint = endpoint;
92      }
93      
94      /* (non-Javadoc)
95       * @see org.alfresco.connector.Connector#getEndpoint()
96       */
97      public String getEndpoint()
98      {
99          return this.endpoint;
100     }    
101 
102     /* (non-Javadoc)
103      * @see org.alfresco.connector.Connector#setConnectorSession(org.alfresco.connector.ConnectorSession)
104      */
105     public void setConnectorSession(ConnectorSession connectorSession)
106     {
107         this.connectorSession = connectorSession;
108     }
109     
110     /* (non-Javadoc)
111      * @see org.alfresco.connector.Connector#getConnectorSession()
112      */
113     public ConnectorSession getConnectorSession()
114     {
115         return this.connectorSession;
116     }
117 
118     /* (non-Javadoc)
119      * @see java.lang.Object#toString()
120      */
121     @Override
122     public String toString()
123     {
124         return this.endpoint + (credentials != null ? (" - " + credentials.toString()) : "");
125     }
126 }