01: package org.drools.brms.client.rpc;
02:
03: /*
04: * Copyright 2005 JBoss Inc
05: *
06: * Licensed under the Apache License, Version 2.0 (the "License");
07: * you may not use this file except in compliance with the License.
08: * You may obtain a copy of the License at
09: *
10: * http://www.apache.org/licenses/LICENSE-2.0
11: *
12: * Unless required by applicable law or agreed to in writing, software
13: * distributed under the License is distributed on an "AS IS" BASIS,
14: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15: * See the License for the specific language governing permissions and
16: * limitations under the License.
17: */
18:
19: import com.google.gwt.core.client.GWT;
20: import com.google.gwt.user.client.rpc.AsyncCallback;
21: import com.google.gwt.user.client.rpc.ServiceDefTarget;
22:
23: /**
24: * Creates instances of the repository service for the client code to use.
25: * @author Michael Neale
26: */
27: public class RepositoryServiceFactory {
28:
29: /**
30: * Change this to switch between debug/mock mode (ie web front end only)
31: * versus full RPC (which requires the back end be running in some form).
32: * Can set it to DEBUG if you want to run it client side only.
33: */
34: public static boolean DEBUG = false;
35: public static RepositoryServiceAsync SERVICE;
36:
37: public static RepositoryServiceAsync getService() {
38: if (SERVICE == null) {
39: loadService();
40: }
41: return SERVICE;
42:
43: }
44:
45: private static void loadService() {
46: if (DEBUG)
47: SERVICE = getMockService();
48: else
49: SERVICE = getRealService();
50:
51: }
52:
53: private static RepositoryServiceAsync getMockService() {
54: //return new MockRepositoryServiceAsync();
55: return null;
56: }
57:
58: private static RepositoryServiceAsync getRealService() {
59: // define the service you want to call
60: RepositoryServiceAsync svc = (RepositoryServiceAsync) GWT
61: .create(RepositoryService.class);
62: ServiceDefTarget endpoint = (ServiceDefTarget) svc;
63:
64: String endpointURL = GWT.getModuleBaseURL() + "jbrmsService";
65:
66: endpoint.setServiceEntryPoint(endpointURL);
67: return svc;
68: }
69:
70: /**
71: * Perform the login.
72: */
73: public static void login(String userName, String password,
74: AsyncCallback cb) {
75: SecurityServiceAsync svc = getSecurityService();
76: svc.login(userName, password, cb);
77: }
78:
79: public static SecurityServiceAsync getSecurityService() {
80: SecurityServiceAsync svc = (SecurityServiceAsync) GWT
81: .create(SecurityService.class);
82: ServiceDefTarget endpoint = (ServiceDefTarget) svc;
83: String endpointURL = GWT.getModuleBaseURL() + "jbrmsService";
84: endpoint.setServiceEntryPoint(endpointURL);
85: return svc;
86: }
87:
88: }
|