Spring Integration

org.springframework.integration.twitter.oauth
Class AbstractOAuthAccessTokenBasedFactoryBean<T>

java.lang.Object
  extended by org.springframework.integration.twitter.oauth.AbstractOAuthAccessTokenBasedFactoryBean<T>
Type Parameters:
T -
All Implemented Interfaces:
FactoryBean<T>, InitializingBean
Direct Known Subclasses:
OAuthAccessTokenBasedTwitterFactoryBean

public abstract class AbstractOAuthAccessTokenBasedFactoryBean<T>
extends Object
implements InitializingBean, FactoryBean<T>

base-class for OAuthAccessTokenBasedTwitterFactoryBean.

Provides hooks so that subclasses able to reference a concrete implementation of the generic type parameter can call methods for us. Most hooks are to handle the case of the first time subscription, where no accessToken is present.

Since:
2.0
Author:
Josh Long
See Also:
OAuthAccessTokenBasedTwitterFactoryBean

Field Summary
protected  OAuthConfiguration configuration
           
protected  boolean initialized
           
protected  Object monitor
           
protected  T twitter
           
 
Constructor Summary
protected AbstractOAuthAccessTokenBasedFactoryBean(OAuthConfiguration configuration)
          Nasty little bit of circular indirection here: the OAuthConfiguration hosts the String values for authentication, which we need to build up this instance, but the OAuthConfiguration in turn needs references to the instances provided by this FactoryBean.
 
Method Summary
 void afterPropertiesSet()
          provides lifecycle for initiation of the reference.
abstract  void establishTwitterObject(twitter4j.http.AccessToken accessToken)
           
protected static Properties fromResource(Resource resource)
          This probably doesn't belong here.
abstract  twitter4j.http.AccessToken getOAuthAccessToken()
          Only used if the impementation is trying to get an AccessToken for the first time.
abstract  twitter4j.http.AccessToken getOAuthAccessToken(twitter4j.http.RequestToken token, String pin)
          Only used if the impementation is trying to get an AccessToken for the first time.
abstract  twitter4j.http.RequestToken getOAuthRequestToken()
          because we are not able to dereference the Twitter or AsyncTwitter instances, we need to ask subclasses to call us how to call AsyncTwitter.getOAuthRequestToken() or Twitter.getOAuthRequestToken() for us.This method will never be evaluated as long as the OAuthConfiguration.accessToken and OAuthConfiguration.accessTokenSecret beans are not null.
 T getObject()
          Rubber meets the road: builds up a reference to the twitter4j.
abstract  Class<?> getObjectType()
          this method is delegated to implementations because we can't correctly dereference the generic type's class
 boolean isSingleton()
          Standard FactoryBean method.
abstract  void verifyCredentials()
          Responsibility of subclasses to call this because we cant dereference the generic type appropriately.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

configuration

protected OAuthConfiguration configuration

monitor

protected final Object monitor

twitter

protected volatile T twitter

initialized

protected volatile boolean initialized
Constructor Detail

AbstractOAuthAccessTokenBasedFactoryBean

protected AbstractOAuthAccessTokenBasedFactoryBean(OAuthConfiguration configuration)
Nasty little bit of circular indirection here: the OAuthConfiguration hosts the String values for authentication, which we need to build up this instance, but the OAuthConfiguration in turn needs references to the instances provided by this FactoryBean. So, they collaborate and guard each others state. Ultimately, clients should use OAuthConfiguration to correctly any implementations of this factory bean as well as the OAuthConfiguration reference itself.

Parameters:
configuration - the configuration object
Method Detail

fromResource

protected static Properties fromResource(Resource resource)
                                  throws Exception
This probably doesn't belong here. It's more for support for running the OAuthAccessTokenBasedTwitterFactoryBean#main(String[]) or OAuthAccessTokenBasedTwitterFactoryBean#main(String[]) methods that run the user through a command line tool to approve a user for the first time if the user hasn't obtained her accessToken yet

Parameters:
resource - the resource where properties file lives
Returns:
returns a fully configured Properties instance
Throws:
Exception - thrown if anythign goes wrong

afterPropertiesSet

public void afterPropertiesSet()
                        throws Exception
provides lifecycle for initiation of the reference. By the time this method is left we should have a fully configured twitter connection that can connect and make calls

Specified by:
afterPropertiesSet in interface InitializingBean
Throws:
Exception

establishTwitterObject

public abstract void establishTwitterObject(twitter4j.http.AccessToken accessToken)
                                     throws Exception
Throws:
Exception

getOAuthRequestToken

public abstract twitter4j.http.RequestToken getOAuthRequestToken()
                                                          throws Exception
because we are not able to dereference the Twitter or AsyncTwitter instances, we need to ask subclasses to call us how to call AsyncTwitter.getOAuthRequestToken() or Twitter.getOAuthRequestToken() for us.This method will never be evaluated as long as the OAuthConfiguration.accessToken and OAuthConfiguration.accessTokenSecret beans are not null.

Returns:
the RequestToken as vended by the service. Ths will contain a verification URl required to obtain an access key and secret.
Throws:
Exception - thrown if anything should go wrong

getOAuthAccessToken

public abstract twitter4j.http.AccessToken getOAuthAccessToken(twitter4j.http.RequestToken token,
                                                               String pin)
                                                        throws Exception
Only used if the impementation is trying to get an AccessToken for the first time. This method will never be evaluated as long as the OAuthConfiguration.accessToken and OAuthConfiguration.accessTokenSecret beans are not null.

Parameters:
token - the initiating RequestToken
pin - the string returned from the verification URL
Returns:
returns the AccessToken fetched from the twitter service.
Throws:
Exception - thrown if anything should go wrong

getOAuthAccessToken

public abstract twitter4j.http.AccessToken getOAuthAccessToken()
                                                        throws Exception
Only used if the impementation is trying to get an AccessToken for the first time. This method will never be evaluated as long as the OAuthConfiguration.accessToken and OAuthConfiguration.accessTokenSecret beans are not null.

Returns:
returns the AccessToken fetched from the twitter service.
Throws:
Exception - thrown if anything should go wrong

verifyCredentials

public abstract void verifyCredentials()
                                throws Exception
Responsibility of subclasses to call this because we cant dereference the generic type appropriately. The responsibility is to call Twitter.verifyCredentials() or AsyncTwitter.verifyCredentials() as appropriate

Throws:
Exception - if there's an inability to authenticate

getObject

public T getObject()
            throws Exception
Rubber meets the road: builds up a reference to the twitter4j.(Async)Twitter instance

Specified by:
getObject in interface FactoryBean<T>
Returns:
the instance
Throws:
Exception - thrown in case some condition isn't met correctly in construction

getObjectType

public abstract Class<?> getObjectType()
this method is delegated to implementations because we can't correctly dereference the generic type's class

Specified by:
getObjectType in interface FactoryBean<T>
Returns:
a class

isSingleton

public boolean isSingleton()
Standard FactoryBean method. Implementations may override if there's a specific method

Specified by:
isSingleton in interface FactoryBean<T>
Returns:
whether or not this is a singleton

Spring Integration

Copyright © 2010. All Rights Reserved.