Example usage for com.liferay.portal.kernel.model ModelListenerRegistrationUtil register

List of usage examples for com.liferay.portal.kernel.model ModelListenerRegistrationUtil register

Introduction

In this page you can find the example usage for com.liferay.portal.kernel.model ModelListenerRegistrationUtil register.

Prototype

public static void register(ModelListener<?> modelListener) 

Source Link

Usage

From source file:com.liferay.osb.scv.connector.internal.jsonws.SCVUserJSONWS.java

License:Open Source License

protected void initServiceTracker() throws Exception {
    _serviceTracker = ServiceTrackerFactory.open(_bundleContext, SCVModel.class,
            new ServiceTrackerCustomizer<SCVModel, SCVModel>() {

                @Override// w w  w .jav a  2  s . com
                public SCVModel addingService(ServiceReference<SCVModel> serviceReference) {

                    SCVModel scvModel = _bundleContext.getService(serviceReference);

                    Class<?> clazz = getModelClass(scvModel);

                    _scvModelMap.put(clazz.getSimpleName(), scvModel);
                    _modelClasses.put(clazz.getSimpleName(), getModelClass(scvModel));

                    ModelListenerRegistrationUtil.register(scvModel);

                    return scvModel;
                }

                @Override
                public void modifiedService(ServiceReference<SCVModel> serviceReference, SCVModel scvModel) {

                    removedService(serviceReference, scvModel);

                    addingService(serviceReference);
                }

                @Override
                public void removedService(ServiceReference<SCVModel> serviceReference, SCVModel scvModel) {

                    Class<?> clazz = getModelClass(scvModel);

                    _scvModelMap.remove(clazz.getSimpleName(), scvModel);
                    _modelClasses.remove(clazz.getSimpleName(), getModelClass(scvModel));

                    ModelListenerRegistrationUtil.unregister(scvModel);

                    _bundleContext.ungetService(serviceReference);
                }

                protected Class<?> getModelClass(SCVModel scvModel) {
                    Class<?> clazz = scvModel.getClass();

                    if (ProxyUtil.isProxyClass(clazz)) {
                        InvocationHandler invocationHandler = ProxyUtil.getInvocationHandler(scvModel);

                        if (invocationHandler instanceof ClassLoaderBeanHandler) {
                            ClassLoaderBeanHandler classLoaderBeanHandler = (ClassLoaderBeanHandler) invocationHandler;

                            Object bean = classLoaderBeanHandler.getBean();

                            clazz = bean.getClass();
                        }
                    }

                    return ReflectionUtil.getGenericSuperType(clazz);
                }

            });
}