subclass MyAccessProtectedResource
authorEugene Crosser <Eugene.Crosser@ru.ibm.com>
Mon, 6 Feb 2012 18:31:52 +0000 (22:31 +0400)
committerEugene Crosser <Eugene.Crosser@ru.ibm.com>
Mon, 6 Feb 2012 18:31:52 +0000 (22:31 +0400)
src/org/average/whereami/Oracle.java

index 7ba16a5ec2dfde72e118e4b339783a6979895760..1de3879b7db2b24b53d768f13a5bf74b09441312 100644 (file)
@@ -2,6 +2,8 @@ package org.average.whereami;
 
 import org.average.whereami.PersistentStore;
 
 
 import org.average.whereami.PersistentStore;
 
+import java.io.IOException;
+
 import com.google.api.client.extensions.android2.AndroidHttp;
 import com.google.api.client.auth.oauth2.draft10.AccessTokenResponse;
 import com.google.api.client.googleapis.auth.oauth2.draft10.GoogleAccessProtectedResource;
 import com.google.api.client.extensions.android2.AndroidHttp;
 import com.google.api.client.auth.oauth2.draft10.AccessTokenResponse;
 import com.google.api.client.googleapis.auth.oauth2.draft10.GoogleAccessProtectedResource;
@@ -21,8 +23,6 @@ abstract public class Oracle {
        public HttpTransport httpTransport;
        public JsonFactory jsonFactory;
        public PersistentStore store;
        public HttpTransport httpTransport;
        public JsonFactory jsonFactory;
        public PersistentStore store;
-
-
        public String authErrorMessage;
 
        public Oracle(final Resources res, final PersistentStore store) {
        public String authErrorMessage;
 
        public Oracle(final Resources res, final PersistentStore store) {
@@ -31,9 +31,38 @@ abstract public class Oracle {
 
                httpTransport = AndroidHttp.newCompatibleTransport();
                jsonFactory = new JacksonFactory();
 
                httpTransport = AndroidHttp.newCompatibleTransport();
                jsonFactory = new JacksonFactory();
-}
+       }
+
+       private class MyAccessProtectedResource
+               extends GoogleAccessProtectedResource {
+
+       // Why on earth contructors are not inherited?!?!
+               public MyAccessProtectedResource(
+                               String accessToken,
+                               HttpTransport transport,
+                               JsonFactory jsonFactory,
+                               String clientId,
+                               String clientSecret,
+                               String refreshToken) {
+                       super(accessToken, transport, jsonFactory,
+                               clientId, clientSecret, refreshToken);
+               }
+
+               @Override
+               public void onAccessToken(String accessToken) {
+                       Log.v(TAG, "Update access token to \""
+                               + accessToken + "\"");
+                       store.updateAccessToken( accessToken);
+               }
+
+               @Override
+               protected boolean executeRefreshToken() throws IOException {
+                       Log.v(TAG, "executeRefreshToken was called");
+                       return super.executeRefreshToken();
+               }
+       }
 
 
-       public GoogleAccessProtectedResource accessProtectedResource() {
+       public MyAccessProtectedResource accessProtectedResource() {
                AccessTokenResponse token = store.readTokens();
                Log.v(TAG, "tokens - access: \"" + token.accessToken +
                        "\", refresh: \"" + token.refreshToken +
                AccessTokenResponse token = store.readTokens();
                Log.v(TAG, "tokens - access: \"" + token.accessToken +
                        "\", refresh: \"" + token.refreshToken +
@@ -41,21 +70,11 @@ abstract public class Oracle {
                        "\", client_secret: \"" +
                                        ClientCredentials.CLIENT_SECRET +
                        "\"");
                        "\", client_secret: \"" +
                                        ClientCredentials.CLIENT_SECRET +
                        "\"");
-               return new GoogleAccessProtectedResource(
+               return new MyAccessProtectedResource(
                        token.accessToken, httpTransport, jsonFactory,
                        ClientCredentials.CLIENT_ID,
                        ClientCredentials.CLIENT_SECRET,
                        token.accessToken, httpTransport, jsonFactory,
                        ClientCredentials.CLIENT_ID,
                        ClientCredentials.CLIENT_SECRET,
-                       token.refreshToken)
-                       {
-                               @Override
-                               public void onAccessToken(
-                                               String accessToken) {
-                                       Log.v(TAG, "Update access token to \""
-                                               + accessToken + "\"");
-                                       store.updateAccessToken(
-                                               accessToken);
-                               }
-                       };
+                       token.refreshToken);
        }
 
        abstract public String getResult();
        }
 
        abstract public String getResult();