/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

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