1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
package com.vci.client.common.providers;
 
import com.vci.common.ServiceNames;
import com.vci.common.log.ServerWithLog4j;
import com.vci.common.util.IceProxyUtility;
//import com.vci.corba.auth2.Auth2ServicePrx;
import com.vci.corba.bofactory.BOFactoryServicePrx;
import com.vci.corba.framework.FrameworkServicePrx;
import com.vci.corba.log.LogServicePrx;
//import com.vci.corba.framework.method.VolumeManagerPrx;
import com.vci.corba.omd.OMDServicePrx;
import com.vci.corba.portal.PortalServicePrx;
import com.vci.corba.query.ObjectQueryServicePrx;
import com.vci.corba.volume.VolumeServicePrx;
import com.vci.corba.workflow.WorkflowServicePrx;
import com.zeroc.Ice.ObjectPrx;
import com.vci.client.mw.ClientProxyUtility;
 
public class ServiceProvider {
    
    private static ServiceProvider _provider = null;
    
    private IceProxyUtility _proxyUtil = null;
 
    private static ServiceProvider getInstance(){
        if(_provider == null){
            _provider = new ServiceProvider();
        }
        
        return _provider;
    }
    
    /**
     * 获取系统该框架服务代理
     * @return
     */
    public static FrameworkServicePrx getFrameService()  {
        FrameworkServicePrx service = getInstance().getFrameServiceImpl();
        if (service == null) {
            String error = "获取 Frame Service 服务异常";
            System.out.println(error);
        }
        
        return service;
    }
    
    /**
     * 获取系统该框架服务代理
     * @return
     */
    public static LogServicePrx getLogService()  {
        LogServicePrx service = getInstance().getLogServiceImpl();
        if (service == null) {
            String error = "获取 Log Service 服务异常";
            System.out.println(error);
        }
        
        return service;
    }
    
    /**
     * 获取系统授权认证框架服务代理
     * @return
     */
//    public static Auth2ServicePrx getAuth2Service()  {
//        Auth2ServicePrx service = getInstance().getAuth2ServiceImpl();
//        if (service == null) {
//            String error = "获取 Auth2Service 服务异常";
//            System.out.println(error);
//        }
//        
//        return service;
//    }
    
    /**
     * 获取缓存服务代理
     * @return
     */
//    public static CacheServicePrx getCacheService()  {
//        CacheServicePrx service = getInstance().getCacheServiceImpl();
//        if (service == null) {
//            String error = "获取 CacheService 服务异常";
//            System.out.println(error);
//        }
//        
//        return service;
//    }
    
    /**
     * 获取都西昂模型定义服务代理
     * @return
     */
    public static OMDServicePrx getOMDService()  {
        OMDServicePrx service =  getInstance().getOMDServiceImpl();
        if (service == null) {
            String error = "获取 OMDService 服务异常";
            System.out.println(error);
        }
        
        return service;
    }
    
    /**
     * 获取业务对象工厂服务代理
     * @return
     */
    public static BOFactoryServicePrx getBOFService()  {
        BOFactoryServicePrx service = getInstance().getBOFServiceImpl();
        if (service == null) {
            String error = "获取 BOFactoryService 服务异常";
            System.out.println(error);
        }
        
        return service;
    }
 
    /**
     * 获取查询模板定义服务代理
     * @return
     */
//    public static QTDServicePrx getQTDService()  {
//        QTDServicePrx service = getInstance().getQTDServiceImpl();
//        if (service == null) {
//            String error = "获取 QTDService 服务异常";
//            System.out.println(error);
//        }
//        
//        return service;
//    }
 
    /**
     * 获取对象查询服务代理
     * @return
     */
    public static ObjectQueryServicePrx getOQService()  {
        ObjectQueryServicePrx service = getInstance().getBOQueryServiceImpl();
        if (service == null) {
            String error = "获取 QTService 服务异常";
            System.out.println(error);
        }
        
        return service;
    }
 
    /**
     * 获取参考对象查询服务代理
     * @return
     */
//    public static RefQueryServicePrx getRQService()  {
//        RefQueryServicePrx service = getInstance().getRQServiceImpl();
//        if (service == null) {
//            String error = "获取 RefQueryService 服务异常";
//            System.out.println(error);
//        }
//        
//        return service;
//    }
 
    /**
     * 获取UI服务服务代理
     * @return
     */
    public static PortalServicePrx getUIService()  {
        PortalServicePrx service = getInstance().getUIServiceImpl();
        if (service == null) {
            String error = "获取 PortalService 服务异常";
            System.out.println(error);
        }
        
        return service;
    }
    
    /**
     * 获取工作流服务代理
     * @return
     * @throws Exception 
     */
    public static WorkflowServicePrx getWFService()  {
        WorkflowServicePrx service = getInstance().getWFServiceImpl();
        if (service == null) {
            String error = "获取 WorkflowService 服务异常";
            System.out.println(error);
            //throw new Exception(error);
        }
        
        return service;
    }
    
    /**
     * 获取卷服务服务代理
     * @return
     */
//    public static VolumeManagerPrx getVolumeManager()  {
//        VolumeManagerPrx service = getInstance().getVolumeFactoryImpl();
//        if (service == null) {
//            String error = "获取 VolumeFactory 服务异常";
//            System.out.println(error);
//        }
//        
//        return service;
//    }
    
    /**
     * 获取系统该框架服务代理
     * @return
     */
    public static VolumeServicePrx getVolumeService(String vol)  {
        VolumeServicePrx service = getInstance().getVolumeServiceImpl(vol);
        if (service == null) {
            String error = "获取 VolumeService 服务异常";
            System.out.println(error);
        }
        
        return service;
    }
    
    private ServiceProvider() {
        InitIceUtil();
    }
    
    private void InitIceUtil() {
        if (_proxyUtil != null)
            return;
        
        _proxyUtil = new ClientProxyUtility();
        
        _proxyUtil.InitCommunicator(new String[0]);
 
    }
 
    
//    private Auth2ServicePrx _authService = null;
//    private Auth2ServicePrx getAuth2ServiceImpl() {
//        try {
//            if(_authService != null){
//                return _authService;
//            }
//            
//            if (_proxyUtil == null) {
//                InitIceUtil();
//            }
//            
//            // added by xf 增加客户端时区的注入
//            System.setProperty("user.timezone", "GMT+8");
//            _authService = Auth2ServicePrx.checkedCast(_proxyUtil.getObjectByName(ServiceNames.AUTH2SERVICE));
//        } catch (Exception e) {
//            //e.printStackTrace();
//            ServerWithLog4j.logger.error(e);
//        }
//        return _authService;
//    }
    
    
    private FrameworkServicePrx _frameService = null;
    private FrameworkServicePrx getFrameServiceImpl() {
        try {
            if(_frameService != null){
                return _frameService;
            }
            
            if (_proxyUtil == null) {
                InitIceUtil();
            }
            
            ObjectPrx prx = _proxyUtil.getObjectByName(ServiceNames.FRAMESERVICE, ServiceNames.FRAMESERVICEREP);
            
            _frameService = FrameworkServicePrx.checkedCast(prx);
        } catch (Exception e) {
            
            ServerWithLog4j.logger.error(e);
        }
        return _frameService;
    }
    
    private LogServicePrx _logService = null;
    private LogServicePrx getLogServiceImpl() {
        try {
            if(_logService != null){
                return _logService;
            }
            
            if (_proxyUtil == null) {
                InitIceUtil();
            }
            
            ObjectPrx prx = _proxyUtil.getObjectByName(ServiceNames.LOGSERVICE, ServiceNames.LOGSERVICEREP);
            
            _logService = LogServicePrx.checkedCast(prx);
        } catch (Exception e) {
            
            ServerWithLog4j.logger.error(e);
        }
        return _logService;
    }
 
 
//    private CacheServicePrx _cacheService = null;
//    private CacheServicePrx getCacheServiceImpl() {
//        try {
//            if(_cacheService != null){
//                return _cacheService;
//            }
//            
//            if (_proxyUtil == null) {
//                InitIceUtil();
//            }
//            
//            _cacheService = CacheServicePrx.checkedCast(_proxyUtil.getObjectByName(ServiceNames.CACHESERVICE));
//        } catch (Exception e) {
//            //e.printStackTrace();
//            ServerWithLog4j.logger.error(e);
//        }
//        return _cacheService;
//    }
 
    
    private BOFactoryServicePrx _bofService = null;
    private BOFactoryServicePrx getBOFServiceImpl() {
        try {
            if(_bofService != null){
                return _bofService;
            }
            
            if (_proxyUtil == null) {
                InitIceUtil();
            }
            
            _bofService = BOFactoryServicePrx.checkedCast(_proxyUtil.getObjectByName(ServiceNames.BOFSERVICE, ServiceNames.BOFSERVICEREP));
        } catch (Exception e) {
            //e.printStackTrace();
            ServerWithLog4j.logger.error(e);
        }
        return _bofService;
    }
 
//    private QTDServicePrx _qtdService = null;
//    private QTDServicePrx getQTDServiceImpl(){
//        try {
//            if(_qtdService != null){
//                return _qtdService;
//            }
//            
//            if (_proxyUtil == null) {
//                InitIceUtil();
//            }
//            
//            _qtdService = QTDServicePrx.checkedCast(_proxyUtil.getObjectByName(ServiceNames.QTDSERVICE));
//        } catch (Exception e) {
//            //e.printStackTrace();
//            ServerWithLog4j.logger.error(e);
//        }
//        return _qtdService;
//    }
 
    private ObjectQueryServicePrx _oqService = null;
    private ObjectQueryServicePrx getBOQueryServiceImpl(){
        try {
            if(_oqService != null){
                return _oqService;
            }
            
            if (_proxyUtil == null) {
                InitIceUtil();
            }
            
            _oqService = ObjectQueryServicePrx.checkedCast(_proxyUtil.getObjectByName(ServiceNames.OQSERVICE, ServiceNames.OQSERVICEREP));
        } catch (Exception e) {
            //e.printStackTrace();
            ServerWithLog4j.logger.error(e);
        }
        return _oqService;
    }
    
    
//    private RefQueryServicePrx _rqService = null;
//    private RefQueryServicePrx getRQServiceImpl() {
//        try {
//            if(_rqService != null){
//                return _rqService;
//            }
//            
//            if (_proxyUtil == null) {
//                InitIceUtil();
//            }
//            
//            _rqService = RefQueryServicePrx.checkedCast(_proxyUtil.getObjectByName(ServiceNames.RQSERVICE));
//        } catch (Exception e) {
//            //e.printStackTrace();
//            ServerWithLog4j.logger.error(e);
//        }
//        return _rqService;
//    }
 
 
    private PortalServicePrx _uiService = null;
    private PortalServicePrx getUIServiceImpl(){
        try {
            if(_uiService != null){
                return _uiService;
            }
            
            if (_proxyUtil == null) {
                InitIceUtil();
            }
            
            _uiService = PortalServicePrx.checkedCast(_proxyUtil.getObjectByName(ServiceNames.UISERVICE, ServiceNames.UISERVICEREP));
        } catch (Exception e) {
            //e.printStackTrace();
            ServerWithLog4j.logger.error(e);
        }
        return _uiService;
    }
 
 
    private OMDServicePrx _omdService = null;
    private OMDServicePrx getOMDServiceImpl(){
        try {
            if(_omdService != null){
                return _omdService;
            }
            
            if (_proxyUtil == null) {
                InitIceUtil();
            }
 
            _omdService = OMDServicePrx.checkedCast(_proxyUtil.getObjectByName(ServiceNames.OMDSERVICE, ServiceNames.OMDSERVICEREP));
        } catch (Exception e) {
            //e.printStackTrace();
            ServerWithLog4j.logger.error(e);
        }
        return _omdService;
    }
    
    private WorkflowServicePrx _wfService = null;
    private WorkflowServicePrx getWFServiceImpl(){
        try {
            if(_wfService != null){
                return _wfService;
            }
            
            if (_proxyUtil == null) {
                InitIceUtil();
            }
 
            _wfService = WorkflowServicePrx.checkedCast(_proxyUtil.getObjectByName(ServiceNames.WFSERVICE, ServiceNames.WFSERVICEREP));
        } catch (Exception e) {
            //e.printStackTrace();
            ServerWithLog4j.logger.error(e);
        }
        return _wfService;
    }
    
//    private VolumeManagerPrx getVolumeFactoryImpl(){
//        try {
//            if (_proxyUtil == null) {
//                InitIceUtil();
//            }
//            
//            return VolumeManagerPrx.checkedCast(_proxyUtil.getObjectByName(ServiceNames.VOLUMEMANAGER));
//        } catch (Exception e) {
//            //e.printStackTrace();
//            ServerWithLog4j.logger.error(e);
//        }
//        return null;
//    }
    
    private VolumeServicePrx _defaultVolService = null;
    private VolumeServicePrx getVolumeServiceImpl(String vol){
        try {
            if (_defaultVolService != null)
                return _defaultVolService;
            
            if (_proxyUtil == null) {
                InitIceUtil();
            }
            
            _defaultVolService = VolumeServicePrx.checkedCast(_proxyUtil.getObjectByName(ServiceNames.VOLUMESERVICE, ServiceNames.VOLUMESERVICEREP));
        } catch (Exception e) {
            //e.printStackTrace();
            ServerWithLog4j.logger.error(e);
        }
        return _defaultVolService;
    }
}