// ----------- CommuniGate Pro: XIMSS Client Library ---------- // // androidCallback.java // Android-environment callback management // // Created by Vadim Belov on 10-Dec-2010 // ---------- (c) Stalker Software, Inc. 2010-2011 ------------ package com.communigate.ximss.android; import android.os.Handler; //import com.unrealmojo.pronto.helpers.debug.DebugLog; import com.communigate.ximss.Callback; import com.communigate.ximss.CallbackFactory; import com.communigate.ximss.CallList; import com.communigate.ximss.Session; import org.w3c.dom.Element; import java.util.logging.Level; import java.util.logging.Logger; public class androidCallbackFactory extends CallbackFactory { //private static final String TAG = "XIMMSAndroidCallbackFactory"; class androidCallback extends Callback { class delayedData implements Runnable { Element xmlResponse, xmlRequest; String errorCode; Session newSession; CallList asyncList; public void run() { try { androidCallback.this.invokeSuper(errorCode,xmlResponse, xmlRequest, asyncList, newSession); } catch (Exception ex) { Logger.getLogger(androidCallback.class.getName()).log(Level.SEVERE, null, ex); // DebugLog.d(TAG, "Error"); ex.printStackTrace(); } } } public androidCallback(Object xObject, String methodName,callType xType) throws NoSuchMethodException, Exception { super(xObject, methodName, xType); } void invokeSuper(String errorCode, Element xmlResponse,Element xmlRequest, CallList asyncList, Session newSession) throws Exception { super.invoke(errorCode, xmlResponse, xmlRequest, asyncList,newSession); } @Override public void invoke(String errorCode, Element xmlResponse, Element xmlRequest, CallList asyncList, Session newSession) { delayedData x = new delayedData(); x.xmlResponse = xmlResponse; x.xmlRequest = xmlRequest; x.errorCode = errorCode; x.newSession = newSession; x.asyncList = asyncList; // !!! commented by Vadim Belov // SwingUtilities.invokeLater(x); androidCallbackFactory.this.mUIHandler.post(x); } } private Handler mUIHandler; public androidCallbackFactory(Handler handler) { super(); mUIHandler = handler; } @Override public Callback createLogin(Object xObject, String methodName) throws NoSuchMethodException, Exception { return(new androidCallback(xObject, methodName,Callback.callType.tLogin)); } @Override public Callback createFinal(Object xObject, String methodName) throws NoSuchMethodException, Exception { return(new androidCallback(xObject, methodName,Callback.callType.tFinal)); } @Override public Callback createSyncData(Object xObject, String methodName) throws NoSuchMethodException, Exception { return(new androidCallback(xObject, methodName,Callback.callType.tSyncData)); } @Override public Callback createAsyncData(Object xObject, String methodName) throws NoSuchMethodException, Exception { return (new androidCallback(xObject, methodName,Callback.callType.tAsyncData)); } }