Permalink
Browse files

Refactoring to be Jdk 1.4 compliant

  • Loading branch information...
1 parent 105a2d9 commit 349a417eb3516d30dedddc2316abc1046e7157ac Jon Schang committed Apr 8, 2012
Showing with 221 additions and 98 deletions.
  1. +10 −12 clients/java/openmeap-slic-android/src/com/openmeap/android/MainActivity.java
  2. +7 −0 clients/java/openmeap-slic-android/src/com/openmeap/android/OmSlicCredentialsProvider.java
  3. +2 −1 clients/java/openmeap-slic-android/src/com/openmeap/android/javascript/JsApiCoreImpl.java
  4. +26 −2 clients/java/openmeap-slic-core/src/com/openmeap/thinclient/AppMgmtClientFactory.java
  5. +2 −2 clients/java/openmeap-slic-core/src/com/openmeap/thinclient/FirstRunCheck.java
  6. +3 −2 clients/java/openmeap-slic-core/src/com/openmeap/thinclient/LoginFormCallback.java
  7. +2 −4 clients/java/openmeap-slic-core/src/com/openmeap/thinclient/LoginFormLauncher.java
  8. +1 −2 clients/java/openmeap-slic-core/src/com/openmeap/thinclient/RESTAppMgmtClient.java
  9. +9 −9 clients/java/openmeap-slic-core/src/com/openmeap/thinclient/SLICConfig.java
  10. +0 −1 clients/java/openmeap-slic-core/src/com/openmeap/thinclient/javascript/JsApiCore.java
  11. +51 −0 clients/java/openmeap-slic-core/src/com/openmeap/thinclient/javascript/Orientation.java
  12. +2 −0 clients/java/openmeap-slic-core/src/com/openmeap/thinclient/update/UpdateException.java
  13. +22 −21 clients/java/openmeap-slic-core/src/com/openmeap/thinclient/update/UpdateHandler.java
  14. +51 −10 clients/java/openmeap-slic-core/src/com/openmeap/thinclient/update/UpdateResult.java
  15. +10 −10 clients/java/openmeap-slic-core/src/com/openmeap/thinclient/update/UpdateStatus.java
  16. +13 −13 clients/java/openmeap-slic-core/test/com/openmeap/thinclient/AppMgmtClientTest.java
  17. +6 −6 clients/java/openmeap-slic-core/test/com/openmeap/thinclient/PreferencesTestImpl.java
  18. +4 −3 clients/java/openmeap-slic-core/test/com/openmeap/thinclient/SLICConfigTest.java
@@ -59,6 +59,7 @@
import com.openmeap.protocol.dto.UpdateHeader;
import com.openmeap.protocol.dto.UpdateType;
import com.openmeap.thinclient.FirstRunCheck;
+import com.openmeap.thinclient.LoginFormCallback;
import com.openmeap.thinclient.LoginFormLauncher;
import com.openmeap.thinclient.Preferences;
import com.openmeap.thinclient.SLICConfig;
@@ -69,7 +70,7 @@
import com.openmeap.util.HttpRequestExecuterImpl;
import com.openmeap.util.Utils;
-public class MainActivity extends Activity implements LoginFormLauncher<OmSlicCredentialsProvider> {
+public class MainActivity extends Activity implements LoginFormLauncher {
private static String SOURCE_ENCODING = "utf-8";
private static String DIRECTORY_INDEX = "index.html";
@@ -80,7 +81,7 @@
private UpdateHandler updateHandler = null;
private WebView webView = null;
private LocalStorageImpl storage = null;
- private OmSlicCredentialsProvider credentialsProvider = null;
+ private LoginFormCallback loginFormCallback = null;
/**
* Called when the activity is first created.
@@ -126,8 +127,8 @@ public void onCreate(Bundle savedInstanceState) {
setupWindowTitle();
}
- public void launchLoginForm(OmSlicCredentialsProvider credProv) {
- this.credentialsProvider = credProv;
+ public void launchLoginForm(LoginFormCallback credProv) {
+ this.loginFormCallback = credProv;
this.runOnUiThread(new Runnable() {
public void run() {
showDialog(LOGIN_DIALOG);
@@ -337,10 +338,7 @@ private Dialog createLoginFormDialog() {
dialog.setContentView(layout);
dialog.setTitle("Authentication Prompt");
- AuthScope authScope = credentialsProvider.getAuthScope();
- String infoText = authScope.getHost() + ":" +
- authScope.getPort() + "\n" +
- authScope.getRealm();
+ String infoText = loginFormCallback.getInfoText();
TextView infoTextView = (TextView)layout.findViewById(R.id.info);
infoTextView.setText(infoText);
@@ -350,11 +348,11 @@ public void onClick(View view) {
EditText passwordText = (EditText)layout.findViewById(R.id.password);
EditText usernameText = (EditText)layout.findViewById(R.id.username);
CheckBox rememberBox = (CheckBox)layout.findViewById(R.id.remember);
- credentialsProvider.onProceed(
+ loginFormCallback.onProceed(
usernameText.getEditableText().toString(),
passwordText.getEditableText().toString(),
rememberBox.isChecked());
- credentialsProvider=null;
+ loginFormCallback=null;
if( ! rememberBox.isChecked() ) {
usernameText.setText("");
passwordText.setText("");
@@ -369,8 +367,8 @@ public void onClick(View view) {
EditText passwordText = (EditText)layout.findViewById(R.id.password);
EditText usernameText = (EditText)layout.findViewById(R.id.username);
CheckBox rememberBox = (CheckBox)layout.findViewById(R.id.remember);
- credentialsProvider.onCancel();
- credentialsProvider=null;
+ loginFormCallback.onCancel();
+ loginFormCallback=null;
if( ! rememberBox.isChecked() ) {
usernameText.setText("");
passwordText.setText("");
@@ -38,6 +38,13 @@ public CredentialsProvider newCredentialsProvider() {
this.launcher = launcher;
}
+ public String getInfoText() {
+ if( authScope==null ) {
+ return null;
+ }
+ return authScope.getHost() + ":" + authScope.getPort() + "\n" + authScope.getRealm();
+ }
+
@Override
public void clear() {
super.clear();
@@ -40,7 +40,8 @@
import com.openmeap.protocol.json.JsError;
import com.openmeap.protocol.json.JsUpdateHeader;
import com.openmeap.thinclient.Preferences;
-import com.openmeap.thinclient.javascript.*;
+import com.openmeap.thinclient.javascript.JsApiCore;
+import com.openmeap.thinclient.javascript.Orientation;
import com.openmeap.thinclient.update.UpdateException;
import com.openmeap.thinclient.update.UpdateStatus;
import com.openmeap.thinclient.update.UpdateHandler;
@@ -1,3 +1,27 @@
+/*
+ ###############################################################################
+ # #
+ # Copyright (C) 2011-2012 OpenMEAP, Inc. #
+ # Credits to Jonathan Schang & Robert Thacher #
+ # #
+ # Released under the LGPLv3 #
+ # #
+ # OpenMEAP is free software: you can redistribute it and/or modify #
+ # it under the terms of the GNU Lesser General Public License as published #
+ # by the Free Software Foundation, either version 3 of the License, or #
+ # (at your option) any later version. #
+ # #
+ # OpenMEAP is distributed in the hope that it will be useful, #
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of #
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
+ # GNU Lesser General Public License for more details. #
+ # #
+ # You should have received a copy of the GNU Lesser General Public License #
+ # along with OpenMEAP. If not, see <http://www.gnu.org/licenses/>. #
+ # #
+ ###############################################################################
+ */
+
package com.openmeap.thinclient;
import java.lang.reflect.Constructor;
@@ -22,8 +46,8 @@ static public Class getDefaultType() {
static public ApplicationManagementService newDefault(String serviceUrl) {
try {
- Constructor constructor = defaultClient.getConstructor(String.class, HttpRequestExecuter.class);
- return (ApplicationManagementService)constructor.newInstance(serviceUrl, HttpRequestExecuterFactory.newDefault());
+ Constructor constructor = defaultClient.getConstructor(new Class[]{String.class, HttpRequestExecuter.class});
+ return (ApplicationManagementService)constructor.newInstance(new Object[]{serviceUrl, HttpRequestExecuterFactory.newDefault()});
} catch( Exception e ) {
throw new RuntimeException(e);
}
@@ -28,11 +28,11 @@ public FirstRunCheck(SLICConfig config, String macAddress) {
this.macAddress = macAddress;
}
public void run() {
- if( config.isDevelopmentMode() ) {
+ if( config.isDevelopmentMode().equals(Boolean.TRUE) ) {
return;
}
if( config.getNotFirstRun()==null ) {
- config.setNotFirstRun(true);
+ config.setNotFirstRun(Boolean.TRUE);
try {
String macWithSalt = macAddress+".OPENMEAP#$!@3__234";
String hashValue = Utils.hashInputStream("sha1", new ByteArrayInputStream(macWithSalt.getBytes("UTF-8")));
@@ -1,6 +1,7 @@
package com.openmeap.thinclient;
public interface LoginFormCallback {
- public void onCancel();
- public void onProceed(String username, String password, Boolean remember);
+ void onCancel();
+ void onProceed(String username, String password, Boolean remember);
+ String getInfoText();
}
@@ -1,7 +1,5 @@
package com.openmeap.thinclient;
-import org.apache.http.client.CredentialsProvider;
-
-public interface LoginFormLauncher<T extends CredentialsProvider> {
- public void launchLoginForm(T credentialsProvider);
+public interface LoginFormLauncher {
+ public void launchLoginForm(LoginFormCallback loginFormCallback);
}
@@ -32,12 +32,11 @@ public RESTAppMgmtClient(String serviceUrl, HttpRequestExecuter requestMaker) {
this.requester = requestMaker;
}
- @SuppressWarnings("unused")
public ConnectionOpenResponse connectionOpen(ConnectionOpenRequest request) throws WebServiceException {
ConnectionOpenResponse response = null;
- Map<String,Object> postData = new HashMap<String,Object>();
+ Map postData = new HashMap();
postData.put(UrlParamConstants.ACTION, "connection-open-request");
postData.put(UrlParamConstants.DEVICE_UUID, request.getApplication().getInstallation().getUuid());
postData.put(UrlParamConstants.APP_NAME, request.getApplication().getName());
@@ -66,7 +66,7 @@ public void setArchiveHash(String hash) {
public Boolean getNotFirstRun() {
String notFirstRun = getProperty("com.openmeap.slic.notFirstRun");
if( notFirstRun!=null ) {
- return Boolean.parseBoolean(notFirstRun);
+ return Boolean.valueOf(notFirstRun);
}
return null;
}
@@ -80,29 +80,29 @@ public String getDeviceType() {
return getProperty("com.openmeap.slic.deviceType");
}
public Boolean shouldPerformUpdateCheck() {
- return isTimeForUpdateCheck() && getProperty("com.openmeap.slic.pullUpdates").equals("true");
+ return Boolean.valueOf(isTimeForUpdateCheck().booleanValue() && getProperty("com.openmeap.slic.pullUpdates").equals("true"));
}
public Boolean isDevelopmentMode() {
String devMode = getProperty("com.openmeap.slic.developmentMode");
if( devMode!=null ) {
- return Boolean.parseBoolean(devMode);
+ return Boolean.valueOf(devMode);
}
- return false;
+ return Boolean.FALSE;
}
public Boolean isTimeForUpdateCheck() {
// proceed with an update, if one is requested
Long lastUpdate = getLastUpdateAttempt();
- Boolean shouldUpdate = true;
+ boolean shouldUpdate = true;
if( lastUpdate!=null ) {
Date now = new Date();
- shouldUpdate = getUpdateFrequency()!=null? ((now.getTime()-lastUpdate)/1000 > getUpdateFrequency()) : false;
+ shouldUpdate = getUpdateFrequency()!=null? ((now.getTime()-lastUpdate.longValue())/1000 > getUpdateFrequency().intValue()) : false;
}
- return shouldUpdate;
+ return Boolean.valueOf(shouldUpdate);
}
public Boolean isVersionOriginal(String version) {
if( version.equals( properties.getProperty("com.openmeap.slic.appVersion") ) )
- return true;
- return false;
+ return Boolean.TRUE;
+ return Boolean.FALSE;
}
public Long getLastUpdateAttempt() {
@@ -10,7 +10,6 @@
* @author schang
*/
public interface JsApiCore {
- public enum Orientation { PORTRAIT, LANDSCAPE, SQUARE, UNDEFINED };
public String getOrientation();
@@ -0,0 +1,51 @@
+package com.openmeap.thinclient.javascript;
+
+import java.lang.reflect.Field;
+import java.util.ArrayList;
+import java.util.List;
+
+import com.openmeap.json.Enum;
+
+public class Orientation implements Enum {
+ static final public Orientation PORTRAIT = new Orientation("PORTRAIT");
+ static final public Orientation LANDSCAPE = new Orientation("LANDSCAPE");
+ static final public Orientation SQUARE = new Orientation("SQUARE");
+ static final public Orientation UNDEFINED = new Orientation("UNDEFINED");
+ private String value;
+ private Orientation(String value) {
+ this.value=value;
+ }
+ public String value() {
+ return value;
+ }
+ public String toString() {
+ return value();
+ }
+ static public Orientation[] values() {
+ List list = new ArrayList();
+ Field[] fields = Orientation.class.getDeclaredFields();
+ for( int fieldIdx=0; fieldIdx<fields.length; fieldIdx++ ) {
+ try {
+ list.add(fields[fieldIdx].get(null));
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ }
+ }
+ return (Orientation[])list.toArray();
+ }
+ public static Orientation fromValue(String v) {
+ Field[] fields = Orientation.class.getDeclaredFields();
+ for( int fieldIdx=0; fieldIdx<fields.length; fieldIdx++ ) {
+ Field field = fields[fieldIdx];
+ try {
+ if( ((Orientation)field.get(null)).value().equals(v) ) {
+ return (Orientation)field.get(null);
+
+ }
+ } catch(Exception e) {
+ throw new IllegalArgumentException(v);
+ }
+ }
+ throw new IllegalArgumentException(v);
+ }
+};
@@ -1,6 +1,8 @@
package com.openmeap.thinclient.update;
public class UpdateException extends Exception {
+
+ private static final long serialVersionUID = 1940779386542633906L;
private UpdateResult updateResult;
Oops, something went wrong.

0 comments on commit 349a417

Please sign in to comment.