Project

General

Profile

« Previous | Next » 

Revision ae7e2680

Added by Cherian Mathew almost 9 years ago

ICdmDataChangeService, CdmUIDataChangeService, CdmDataChangeService : added new data change service with different services for the ui and non-ui states
CdmApplicationState, CdmStore : added data change service to app state
CdmChangeEvent, ICdmChangeListener : added change listener and even to fire in case of data changes
ICdmEntitySessionEnabled : extends new change service interface
ICdmEntitySession, CdmEntitySession : removed data change un/registration since this is now handled by the new data change service
BaseRemotingTest, MockCdmEntitySession, *Editor, *ViewPart, *Navigator : refactoring with new change listener
RemotingCdmHandler, RemotingCdmOperation, RemotingCdmUpdateOperation : added new handler / operation architecture base classes
AbstractUtility : added method for running async operation with callback to handler
RemotingChangeAcceptedTaxonToSynonymHandler,RemotingChangeAcceptedTaxonToSynonymOperation : first implementations of new handler / operation architecture
plugin.xml : added standalone and remoting handlers for ChangeAcceptedTaxonToSynonym
*Test : adapted for new handler / operation and change service

View differences:

eu.etaxonomy.taxeditor.cdmlib/src/main/java/eu/etaxonomy/cdm/api/application/CdmApplicationState.java
9 9
*/
10 10
package eu.etaxonomy.cdm.api.application;
11 11

  
12
import java.lang.reflect.InvocationTargetException;
13
import java.lang.reflect.Method;
14
import java.lang.reflect.Type;
15

  
16
import eu.etaxonomy.cdm.api.service.ICommonService;
17
import eu.etaxonomy.cdm.api.service.IService;
18

  
12 19
/**
13 20
 * @author cmathew
14 21
 * @date 17 Jun 2015
......
20 27

  
21 28
    private ICdmApplicationConfiguration appConfig;
22 29

  
30
    private ICdmDataChangeService dataChangeService;
31

  
23 32
    public static CdmApplicationState getInstance() {
24 33
        if(cdmApplicationState == null) {
25 34
            cdmApplicationState = new CdmApplicationState();
......
43 52
        return getInstance().getAppConfig();
44 53
    }
45 54

  
55
    /**
56
     * @return the dataChangeService
57
     */
58
    public ICdmDataChangeService getDataChangeService() {
59
        return dataChangeService;
60
    }
61

  
62
    /**
63
     * @param dataChangeService the dataChangeService to set
64
     */
65
    public void setDataChangeService(ICdmDataChangeService dataChangeService) {
66
        this.dataChangeService = dataChangeService;
67
    }
68

  
69
    public static ICdmDataChangeService getCurrentDataChangeService() {
70
        return getInstance().getDataChangeService();
71
    }
72

  
73
    public static void setCurrentDataChangeService(ICdmDataChangeService dataChangeService) {
74
        getInstance().setDataChangeService(dataChangeService);
75
    }
76

  
77
    public static void dispose() {
78
        getInstance().setCurrentDataChangeService(null);
79
        getInstance().setAppConfig(null);
80
    }
81

  
82
    /**
83
     * Generic method that will scan the getters of {@link ICdmApplicationConfiguration} for the given service
84
     * interface. If a matching getter is found the according service implementation is returned by
85
     * invoking the getter otherwise the method returns <code>null</code>.
86
     *
87
     * @param <T>
88
     * @param serviceClass
89
     * @return the configured implementation of <code>serviceClass</code> or <code>null</code>
90
     * @throws CdmApplicationException
91
     */
92
    public static <T extends IService> T getService(Class<T> serviceClass) throws CdmApplicationException {
93
        ICdmApplicationConfiguration configuration = getCurrentAppConfig();
94

  
95
        Method[] methods = ICdmApplicationConfiguration.class.getDeclaredMethods();
96

  
97
        T service = null;
98

  
99
        for (Method method : methods) {
100
            Type type = method.getGenericReturnType();
101

  
102
            if (type.equals(serviceClass)) {
103
                try {
104
                    service = (T) method.invoke(configuration, null);
105
                    break;
106
                } catch (IllegalArgumentException iae) {
107
                    throw new CdmApplicationException(iae);
108
                } catch (IllegalAccessException iae) {
109
                    throw new CdmApplicationException(iae);
110
                } catch (InvocationTargetException ite) {
111
                    throw new CdmApplicationException(ite);
112
                }
113
            }
114
        }
115

  
116
        return service;
117
    }
118

  
119
    /**
120
     * @see #getService(Class)
121
     * As ICommonService is not extending IService we need a specific request here
122
     */
123
    public static ICommonService getCommonService() {
124
        ICdmApplicationConfiguration configuration = getCurrentAppConfig();
125

  
126
        return configuration.getCommonService();
127

  
128
    }
129

  
46 130
}

Also available in: Unified diff