Untuk memudahkan aku access kepada service GWT yang telah aku buat, aku create satu Service Manager class untuk manage service-service yang ada. Jadi x perlua setiap kali nak guna service tu declare satu persatu. Call aje, senang.
Actually, yang bahagian if else tu patutnya x ada, tapi sebab benda ni x stable aku terpaksa juga buat.
package my.com.client.common;
import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.rpc.ServiceDefTarget;
import my.com.client.GeneralSettings.GeneralSettingsService;
import my.com.client.GeneralSettings.GeneralSettingsServiceAsync;
import my.com.client.lecturer.LecturerService;
import my.com.client.lecturer.LecturerServiceAsync;
import my.com.client.login.LoginService;
import my.com.client.login.LoginServiceAsync;
import my.com.client.semester.SemesterService;
import my.com.client.semester.SemesterServiceAsync;
import my.com.client.subject.SubjectService;
import my.com.client.subject.SubjectServiceAsync;
/**
*
* @author Peyo
*/
public class ServiceManager {
public static LoginServiceAsync getLoginService() {
return (LoginServiceAsync) getService(LoginService.class,"loginservice");
}
public static SubjectServiceAsync getSubjectService() {
return (SubjectServiceAsync) getService(SubjectService.class,"subjectservice");
}
public static GeneralSettingsServiceAsync getGeneralSettingService() {
return (GeneralSettingsServiceAsync) getService(GeneralSettingsService.class,"generalsettingsservice");
}
public static SemesterServiceAsync getSemesterService(){
return (SemesterServiceAsync) getService(SemesterService.class,"semesterservice");
}
public static LecturerServiceAsync getLecturerService(){
return (LecturerServiceAsync) getService(LecturerService.class,"lecturerservice");
}
private static Object getService(Class myclass,String relativeurl) {
Object service=null;
if (relativeurl.equals("subjectservice")) {
service = GWT.create(SubjectService.class);
}else if(relativeurl.equals("loginservice")){
service = GWT.create(LoginService.class);
}else if(relativeurl.equals("generalsettingsservice")){
service = GWT.create(GeneralSettingsService.class);
}else if(relativeurl.equals("semesterservice")){
service = GWT.create(SemesterService.class);
}else if(relativeurl.equals("lecturerservice")){
service = GWT.create(LecturerService.class);
}
//service = GWT.create(myclass);
ServiceDefTarget endpoint = (ServiceDefTarget) service;
String moduleRelativeURL = GWT.getModuleBaseURL() + relativeurl;
endpoint.setServiceEntryPoint(moduleRelativeURL);
return service;
}
}
Malaya Merdeka - from Ash's vinyl collection
9 months ago
0 comments:
Post a Comment