Spring Social

org.springframework.social.connect.support
Class AbstractConnection<A>

java.lang.Object
  extended by org.springframework.social.connect.support.AbstractConnection<A>
Type Parameters:
A - the service provider's API type
All Implemented Interfaces:
Connection<A>
Direct Known Subclasses:
OAuth1Connection, OAuth2Connection

public abstract class AbstractConnection<A>
extends java.lang.Object
implements Connection<A>

Base support class for Connection implementations. Defines the state and behavior that is common across connection implementations and independent of any specific authorization protocol.

Author:
Keith Donald

Constructor Summary
AbstractConnection(ApiAdapter<A> apiAdapter)
          Creates a new connection.
AbstractConnection(ConnectionData data, ApiAdapter<A> apiAdapter)
          Creates a connection from the data provider.
 
Method Summary
abstract  ConnectionData createData()
          Creates a data transfer object that can be used to persist the state of this connection.
 boolean equals(java.lang.Object o)
           
 UserProfile fetchUserProfile()
          Fetch a normalized model of the user's profile on the provider system.
abstract  A getApi()
          A Java binding to the service provider's native API.
 java.lang.String getDisplayName()
          A display name or label for this connection.
 java.lang.String getImageUrl()
          A link to a image that visualizes this connection.
 ConnectionKey getKey()
          The key identifying this connection.
protected  java.lang.Object getMonitor()
          Provides subclasses with access to a monitor that can be used to synchronize access to this connection.
 java.lang.String getProfileUrl()
          The public URL of the connected user's profile at the provider's site.
 boolean hasExpired()
          Returns true if this connection has expired.
 int hashCode()
           
protected  void initKey(java.lang.String providerId, java.lang.String providerUserId)
          Hook that should be called by subclasses to initialize the key property when establishing a new connection.
 void refresh()
          Refresh this connection.
 void sync()
          Sync's this connection object with the current state of the external user's profile.
 boolean test()
          Test this connection.
 void updateStatus(java.lang.String message)
          Update the user's status on the provider's system.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AbstractConnection

public AbstractConnection(ApiAdapter<A> apiAdapter)
Creates a new connection.

Parameters:
apiAdapter - the Service API adapter

AbstractConnection

public AbstractConnection(ConnectionData data,
                          ApiAdapter<A> apiAdapter)
Creates a connection from the data provider.

Parameters:
data - the connection data
apiAdapter - the Service API adapter
Method Detail

getKey

public ConnectionKey getKey()
Description copied from interface: Connection
The key identifying this connection. A composite key that consists of the "providerId" plus "providerUserId"; for example, "facebook" and "125660".

Specified by:
getKey in interface Connection<A>

getDisplayName

public java.lang.String getDisplayName()
Description copied from interface: Connection
A display name or label for this connection. Should be suitable for display on a UI and distinguish this connection from others with the same provider. Generally the full name or screen name of the connected provider user e.g. "Keith Donald" or "@kdonald". May be null if this information is not public or not provided. The value of this property may change if the user updates his or her profile.

Specified by:
getDisplayName in interface Connection<A>
See Also:
Connection.sync()

getProfileUrl

public java.lang.String getProfileUrl()
Description copied from interface: Connection
The public URL of the connected user's profile at the provider's site. A client application may use this value along with the displayName to generate a link to the user's profile on the provider's system. May be null if this information is not public or not provided. The value of this property may change if the user updates his or her profile.

Specified by:
getProfileUrl in interface Connection<A>
See Also:
Connection.sync()

getImageUrl

public java.lang.String getImageUrl()
Description copied from interface: Connection
A link to a image that visualizes this connection. Should visually distinguish this connection from others with the same provider. Generally the small/thumbnail version of the connected provider user's profile picture. May be null if this information is not public or not provided. The value of this property may change if the user updates his or her profile.

Specified by:
getImageUrl in interface Connection<A>
See Also:
Connection.sync()

test

public boolean test()
Description copied from interface: Connection
Test this connection. If false, indicates calls to the api will fail. Used to proactively test authorization credentials such as an API access token before invoking the service API.

Specified by:
test in interface Connection<A>

hasExpired

public boolean hasExpired()
Description copied from interface: Connection
Returns true if this connection has expired. An expired connection cannot be used; calls to Connection.test() return false, and any service API invocations fail. If expired, you may call Connection.refresh() to renew the connection. Not supported by all Connection implementations; always returns false if not supported.

Specified by:
hasExpired in interface Connection<A>

refresh

public void refresh()
Description copied from interface: Connection
Refresh this connection. Used to renew an expired connection. If the refresh operation is successful, Connection.hasExpired() returns false. Not supported by all connection implementations; if not supported, this method is a no-op.

Specified by:
refresh in interface Connection<A>

fetchUserProfile

public UserProfile fetchUserProfile()
Description copied from interface: Connection
Fetch a normalized model of the user's profile on the provider system. Capable of exposing the user's name, email, and username. What is actually exposed depends on the provider and scope of this connection.

Specified by:
fetchUserProfile in interface Connection<A>

updateStatus

public void updateStatus(java.lang.String message)
Description copied from interface: Connection
Update the user's status on the provider's system. This method is a no-op if a status concept is not supported by the service provider.

Specified by:
updateStatus in interface Connection<A>
Parameters:
message - the status message

sync

public void sync()
Description copied from interface: Connection
Sync's this connection object with the current state of the external user's profile. Triggers locally cached profile fields to update if they have changed on the provider's system.

Specified by:
sync in interface Connection<A>

getApi

public abstract A getApi()
Description copied from interface: Connection
A Java binding to the service provider's native API.

Specified by:
getApi in interface Connection<A>

createData

public abstract ConnectionData createData()
Description copied from interface: Connection
Creates a data transfer object that can be used to persist the state of this connection. Used to support the transfer of connection state between layers of the application, such as to the database layer.

Specified by:
createData in interface Connection<A>

initKey

protected void initKey(java.lang.String providerId,
                       java.lang.String providerUserId)
Hook that should be called by subclasses to initialize the key property when establishing a new connection.

Parameters:
providerId - the providerId
providerUserId - the providerUserId

getMonitor

protected java.lang.Object getMonitor()
Provides subclasses with access to a monitor that can be used to synchronize access to this connection.


equals

public boolean equals(java.lang.Object o)
Overrides:
equals in class java.lang.Object

hashCode

public int hashCode()
Overrides:
hashCode in class java.lang.Object

Spring Social