-
Notifications
You must be signed in to change notification settings - Fork 35
Expand file tree
/
Copy pathLocalUser.java
More file actions
89 lines (76 loc) · 2.64 KB
/
Copy pathLocalUser.java
File metadata and controls
89 lines (76 loc) · 2.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
// -*- mode: java; c-basic-offset: 2; -*-
// Copyright 2009-2011 Google, All Rights reserved
// Copyright 2011-2012 MIT, All rights reserved
// Released under the MIT License https://raw.github.com/mit-cml/app-inventor/master/mitlicense.txt
package com.google.appinventor.server;
import com.google.appinventor.shared.rpc.user.User;
import com.google.appinventor.shared.rpc.user.UserInfoProvider;
/**
* A singleton providing the UserInfoProvider interface information.
*
* @author kerr@google.com (Debby Wallach)
*/
public class LocalUser implements UserInfoProvider {
private ThreadLocal<User> user = new ThreadLocal<User>();
/**
* Returns the singleton LocalUser instance.
*
* @return localUser instance
*/
public static LocalUser getInstance() {
return LocalUserInstanceHolder.INSTANCE;
}
private static class LocalUserInstanceHolder {
private LocalUserInstanceHolder() {} // not to be instantiated
private static final LocalUser INSTANCE = new LocalUser();
}
public void set(User newUser) {
user.set(newUser);
}
@Override
public User getUser() throws UnsupportedOperationException {
try {
return user.get().copy();
} catch (NullPointerException e) {
// This should never happen, but just in case...
throw new UnsupportedOperationException("User field should have been initialized.");
}
}
// UserInfoProvider implementation
@Override
public String getUserId() throws UnsupportedOperationException {
try {
return user.get().getUserId();
} catch (NullPointerException e) {
// This should never happen, but just in case...
throw new UnsupportedOperationException("User field should have been initialized.");
}
}
@Override
public String getUserEmail() throws UnsupportedOperationException {
try {
return user.get().getUserEmail();
} catch (NullPointerException e) {
// This should never happen, but just in case...
throw new UnsupportedOperationException("User field should have been initialized.");
}
}
@Override
public boolean getUserTosAccepted() throws UnsupportedOperationException {
try {
return user.get().getUserTosAccepted();
} catch (NullPointerException e) {
// This should never happen, but just in case...
throw new UnsupportedOperationException("User field should have been initialized.");
}
}
@Override
public boolean getIsAdmin() {
try {
return user.get().getIsAdmin();
} catch (NullPointerException e) {
// This should never happen, but just in case...
throw new UnsupportedOperationException("User field should have been initialized.");
}
}
}