PageRenderTime 20ms CodeModel.GetById 7ms app.highlight 10ms RepoModel.GetById 1ms app.codeStats 0ms

/facebook-java-api/src/main/java/com/google/code/facebookapi/FBWebSession.java

http://facebook-java-api.googlecode.com/
Java | 107 lines | 85 code | 22 blank | 0 comment | 19 complexity | f66022bee41bb8091c64d3e52bdc02b1 MD5 | raw file
  1package com.google.code.facebookapi;
  2
  3import java.io.Serializable;
  4import java.util.Date;
  5import java.util.SortedMap;
  6import java.util.TreeMap;
  7
  8import org.apache.commons.lang.ObjectUtils;
  9
 10public class FBWebSession implements Serializable {
 11
 12	private FBAppConf appConf;
 13	private String sessionKey;
 14	private Date sessionExpires;
 15	private Long userId;
 16	private String sessionSecret;
 17	private SortedMap<String,String> params;
 18
 19	private boolean appUser;
 20
 21	public FBWebSession( FBAppConf appConf ) {
 22		this.appConf = appConf;
 23		this.params = new TreeMap<String,String>();
 24	}
 25
 26	public FBAppConf getAppConf() {
 27		return appConf;
 28	}
 29
 30	public String getSessionKey() {
 31		return sessionKey;
 32	}
 33
 34	public void setSessionKey( String sessionKey ) {
 35		this.sessionKey = sessionKey;
 36	}
 37
 38	public boolean isExpired() {
 39		return sessionKey == null || sessionExpires == null || sessionExpires.getTime() <= System.currentTimeMillis();
 40	}
 41
 42	public Date getSessionExpires() {
 43		return sessionExpires;
 44	}
 45
 46	public void setSessionExpires( Date sessionExpires ) {
 47		this.sessionExpires = sessionExpires;
 48	}
 49
 50	public Long getUserId() {
 51		return userId;
 52	}
 53
 54	public void setUserId( Long userId ) {
 55		this.userId = userId;
 56	}
 57
 58	public String getSessionSecret() {
 59		return sessionSecret;
 60	}
 61
 62	public void setSessionSecret( String sessionSecret ) {
 63		this.sessionSecret = sessionSecret;
 64	}
 65
 66	public SortedMap<String,String> getParams() {
 67		return params;
 68	}
 69
 70	public void setParams( SortedMap<String,String> params ) {
 71		this.params = params;
 72	}
 73
 74	public boolean isAppUser() {
 75		return appUser;
 76	}
 77
 78	public void setAppUser( boolean appUser ) {
 79		this.appUser = appUser;
 80	}
 81
 82	public boolean update( String sessionKey, Date sessionExpires, Long userId, String sessionSecret, Boolean appUser ) {
 83		boolean same = true;
 84		if ( sessionKey != null && !ObjectUtils.equals( this.sessionKey, sessionKey ) ) {
 85			this.sessionKey = sessionKey;
 86			same = false;
 87		}
 88		if ( sessionExpires != null && !ObjectUtils.equals( this.sessionExpires, sessionExpires ) ) {
 89			this.sessionExpires = sessionExpires;
 90			same = false;
 91		}
 92		if ( userId != null && !ObjectUtils.equals( this.userId, userId ) ) {
 93			this.userId = userId;
 94			same = false;
 95		}
 96		if ( sessionSecret != null && !ObjectUtils.equals( this.sessionSecret, sessionSecret ) ) {
 97			this.sessionSecret = sessionSecret;
 98			same = false;
 99		}
100		if ( appUser != null && !ObjectUtils.equals( this.appUser, appUser ) ) {
101			this.appUser = appUser;
102			same = false;
103		}
104		return !same;
105	}
106
107}