Example usage for com.liferay.portal.kernel.util ProxyUtil getInvocationHandler

List of usage examples for com.liferay.portal.kernel.util ProxyUtil getInvocationHandler

Introduction

In this page you can find the example usage for com.liferay.portal.kernel.util ProxyUtil getInvocationHandler.

Prototype

public static InvocationHandler getInvocationHandler(Object proxy) 

Source Link

Usage

From source file:com.bvakili.portlet.integration.box.service.impl.BoxRepositoryLocalServiceImpl.java

License:Open Source License

protected BoxRepository getBoxRepository(long repositoryId) throws PortalException, SystemException {

    Repository repositoryImpl = repositoryLocalService.getRepositoryImpl(repositoryId);

    BoxRepositoryHandler repo = null;/*from w ww .j  av a 2 s .c  o m*/
    BoxRepository retVal = null;
    //      CMISRepositoryHandler cmisRepositoryHandler = null;
    //
    //      if (repositoryImpl instanceof CMISRepositoryHandler) {
    //         cmisRepositoryHandler = (CMISRepositoryHandler)repositoryImpl;
    //      }
    //      else if (repositoryImpl instanceof BaseRepositoryProxyBean) {
    //         BaseRepositoryProxyBean baseRepositoryProxyBean =
    //            (BaseRepositoryProxyBean)repositoryImpl;
    //
    //         ClassLoaderBeanHandler classLoaderBeanHandler =
    //            (ClassLoaderBeanHandler)ProxyUtil.getInvocationHandler(
    //               baseRepositoryProxyBean.getProxyBean());
    //
    //         Object bean = classLoaderBeanHandler.getBean();
    //
    //         if (bean instanceof CMISRepositoryHandler) {
    //            cmisRepositoryHandler = (CMISRepositoryHandler)bean;
    //         }
    //      }
    //
    //      BoxRepository cmisRepository =
    //         (BoxRepository)cmisRepositoryHandler.getCmisRepository();
    //
    //      return cmisRepository;

    if (repositoryImpl instanceof BoxRepository) {
        repo = (BoxRepositoryHandler) repositoryImpl;
    } else if (repositoryImpl instanceof BaseRepositoryProxyBean) {
        BaseRepositoryProxyBean baseRepositoryProxyBean = (BaseRepositoryProxyBean) repositoryImpl;

        ClassLoaderBeanHandler classLoaderBeanHandler = (ClassLoaderBeanHandler) ProxyUtil
                .getInvocationHandler(baseRepositoryProxyBean.getProxyBean());

        Object bean = classLoaderBeanHandler.getBean();

        if (bean instanceof BoxRepositoryHandler) {
            repo = (BoxRepositoryHandler) bean;
        }
    }

    retVal = (BoxRepository) repo.getBoxRepository();
    return retVal;
}

From source file:com.liferay.compat.servlet.CompatServletContextListener.java

License:Open Source License

protected void updateRepository(ClassLoader classLoader, Map<String, Object> repositoryFactories,
        String repositoryClassName, Object repositoryFactory) throws Exception {

    if (!repositoryClassName.startsWith("com.liferay.portal.repository.cmis.CMIS")) {

        return;/*from  w ww .j ava  2s. c  o  m*/
    }

    Class<?> repositoryFactoryImplClass = classLoader
            .loadClass("com.liferay.portal.repository.util.RepositoryFactoryImpl");

    if (ClassUtil.isSubclass(repositoryFactory.getClass(), repositoryFactoryImplClass)) {

        Class<?> repositoryFactoryClass = classLoader
                .loadClass("com.liferay.portal.repository.util.RepositoryFactory");

        Object newRepositoryFactory = ProxyUtil.newProxyInstance(classLoader,
                new Class<?>[] { repositoryFactoryClass },
                new CompatCMISRepositoryFactoryInvocationHandler(repositoryFactory));

        if (_log.isInfoEnabled()) {
            _log.info(
                    "Overriding " + repositoryFactory.getClass() + " with " + newRepositoryFactory.getClass());
        }

        repositoryFactories.put(repositoryClassName, newRepositoryFactory);
    } else {
        InvocationHandler invocationHandler = ProxyUtil.getInvocationHandler(repositoryFactory);

        if (invocationHandler instanceof CompatCMISRepositoryFactoryInvocationHandler) {

            CompatCMISRepositoryFactoryInvocationHandler compatCMISRepositoryFactoryInvocationHandler = (CompatCMISRepositoryFactoryInvocationHandler) invocationHandler;

            Object oldRepositoryFactory = compatCMISRepositoryFactoryInvocationHandler.getRepositoryFactory();

            if (_log.isInfoEnabled()) {
                _log.info("Restoring " + repositoryFactory.getClass() + " with "
                        + oldRepositoryFactory.getClass());
            }

            repositoryFactories.put(repositoryClassName, oldRepositoryFactory);
        }
    }
}

From source file:com.liferay.compat.servlet.CompatServletContextListener.java

License:Open Source License

protected void updateSharepointMethod(ClassLoader classLoader, Map<String, Object> sharepointMethods,
        String sharepointMethodName, Object sharepointMethod) throws Exception {

    Class<?> sharepointBaseMethodImplClass = classLoader
            .loadClass("com.liferay.portal.sharepoint.methods.BaseMethodImpl");

    if (ClassUtil.isSubclass(sharepointMethod.getClass(), sharepointBaseMethodImplClass)) {

        Class<?> sharepointMethodClass = classLoader.loadClass("com.liferay.portal.sharepoint.methods.Method");

        Object newSharepointMethod = ProxyUtil.newProxyInstance(classLoader,
                new Class<?>[] { sharepointMethodClass },
                new CompatSharepointInvocationHandler(sharepointMethod));

        if (_log.isInfoEnabled()) {
            _log.info("Overriding " + sharepointMethod.getClass() + " with " + newSharepointMethod.getClass());
        }/* ww w. j av a2s. co  m*/

        sharepointMethods.put(sharepointMethodName, newSharepointMethod);
    } else {
        InvocationHandler invocationHandler = ProxyUtil.getInvocationHandler(sharepointMethod);

        if (invocationHandler instanceof CompatSharepointInvocationHandler) {

            CompatSharepointInvocationHandler compatSharepointInvocationHandler = (CompatSharepointInvocationHandler) invocationHandler;

            Object oldSharepointMethod = compatSharepointInvocationHandler.getSharepointMethod();

            if (_log.isInfoEnabled()) {
                _log.info(
                        "Restoring " + sharepointMethod.getClass() + " with " + oldSharepointMethod.getClass());
            }

            sharepointMethods.put(sharepointMethodName, oldSharepointMethod);
        }
    }
}

From source file:com.liferay.docs.guestbook.service.persistence.impl.EntryPersistenceImpl.java

License:Open Source License

@Override
public Entry updateImpl(Entry entry) {
    boolean isNew = entry.isNew();

    if (!(entry instanceof EntryModelImpl)) {
        InvocationHandler invocationHandler = null;

        if (ProxyUtil.isProxyClass(entry.getClass())) {
            invocationHandler = ProxyUtil.getInvocationHandler(entry);

            throw new IllegalArgumentException(
                    "Implement ModelWrapper in entry proxy " + invocationHandler.getClass());
        }/*from   w  w  w .  j a va 2s. c  o  m*/

        throw new IllegalArgumentException(
                "Implement ModelWrapper in custom Entry implementation " + entry.getClass());
    }

    EntryModelImpl entryModelImpl = (EntryModelImpl) entry;

    if (Validator.isNull(entry.getUuid())) {
        String uuid = PortalUUIDUtil.generate();

        entry.setUuid(uuid);
    }

    ServiceContext serviceContext = ServiceContextThreadLocal.getServiceContext();

    Date now = new Date();

    if (isNew && (entry.getCreateDate() == null)) {
        if (serviceContext == null) {
            entry.setCreateDate(now);
        } else {
            entry.setCreateDate(serviceContext.getCreateDate(now));
        }
    }

    if (!entryModelImpl.hasSetModifiedDate()) {
        if (serviceContext == null) {
            entry.setModifiedDate(now);
        } else {
            entry.setModifiedDate(serviceContext.getModifiedDate(now));
        }
    }

    Session session = null;

    try {
        session = openSession();

        if (entry.isNew()) {
            session.save(entry);

            entry.setNew(false);
        } else {
            entry = (Entry) session.merge(entry);
        }
    } catch (Exception e) {
        throw processException(e);
    } finally {
        closeSession(session);
    }

    finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);

    if (!EntryModelImpl.COLUMN_BITMASK_ENABLED) {
        finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
    } else if (isNew) {
        Object[] args = new Object[] { entryModelImpl.getUuid() };

        finderCache.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
        finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID, args);

        args = new Object[] { entryModelImpl.getUuid(), entryModelImpl.getCompanyId() };

        finderCache.removeResult(FINDER_PATH_COUNT_BY_UUID_C, args);
        finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C, args);

        args = new Object[] { entryModelImpl.getGroupId(), entryModelImpl.getGuestbookId() };

        finderCache.removeResult(FINDER_PATH_COUNT_BY_G_G, args);
        finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_G, args);

        finderCache.removeResult(FINDER_PATH_COUNT_ALL, FINDER_ARGS_EMPTY);
        finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL, FINDER_ARGS_EMPTY);
    }

    else {
        if ((entryModelImpl.getColumnBitmask()
                & FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID.getColumnBitmask()) != 0) {
            Object[] args = new Object[] { entryModelImpl.getOriginalUuid() };

            finderCache.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
            finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID, args);

            args = new Object[] { entryModelImpl.getUuid() };

            finderCache.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
            finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID, args);
        }

        if ((entryModelImpl.getColumnBitmask()
                & FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C.getColumnBitmask()) != 0) {
            Object[] args = new Object[] { entryModelImpl.getOriginalUuid(),
                    entryModelImpl.getOriginalCompanyId() };

            finderCache.removeResult(FINDER_PATH_COUNT_BY_UUID_C, args);
            finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C, args);

            args = new Object[] { entryModelImpl.getUuid(), entryModelImpl.getCompanyId() };

            finderCache.removeResult(FINDER_PATH_COUNT_BY_UUID_C, args);
            finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C, args);
        }

        if ((entryModelImpl.getColumnBitmask()
                & FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_G.getColumnBitmask()) != 0) {
            Object[] args = new Object[] { entryModelImpl.getOriginalGroupId(),
                    entryModelImpl.getOriginalGuestbookId() };

            finderCache.removeResult(FINDER_PATH_COUNT_BY_G_G, args);
            finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_G, args);

            args = new Object[] { entryModelImpl.getGroupId(), entryModelImpl.getGuestbookId() };

            finderCache.removeResult(FINDER_PATH_COUNT_BY_G_G, args);
            finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_G, args);
        }
    }

    entityCache.putResult(EntryModelImpl.ENTITY_CACHE_ENABLED, EntryImpl.class, entry.getPrimaryKey(), entry,
            false);

    clearUniqueFindersCache(entryModelImpl, false);
    cacheUniqueFindersCache(entryModelImpl);

    entry.resetOriginalValues();

    return entry;
}

From source file:com.liferay.docs.guestbook.service.persistence.impl.GuestbookEntryPersistenceImpl.java

License:Open Source License

@Override
public GuestbookEntry updateImpl(GuestbookEntry guestbookEntry) {
    boolean isNew = guestbookEntry.isNew();

    if (!(guestbookEntry instanceof GuestbookEntryModelImpl)) {
        InvocationHandler invocationHandler = null;

        if (ProxyUtil.isProxyClass(guestbookEntry.getClass())) {
            invocationHandler = ProxyUtil.getInvocationHandler(guestbookEntry);

            throw new IllegalArgumentException(
                    "Implement ModelWrapper in guestbookEntry proxy " + invocationHandler.getClass());
        }/* www  .  j  a  va 2  s.co m*/

        throw new IllegalArgumentException(
                "Implement ModelWrapper in custom GuestbookEntry implementation " + guestbookEntry.getClass());
    }

    GuestbookEntryModelImpl guestbookEntryModelImpl = (GuestbookEntryModelImpl) guestbookEntry;

    if (Validator.isNull(guestbookEntry.getUuid())) {
        String uuid = PortalUUIDUtil.generate();

        guestbookEntry.setUuid(uuid);
    }

    ServiceContext serviceContext = ServiceContextThreadLocal.getServiceContext();

    Date now = new Date();

    if (isNew && (guestbookEntry.getCreateDate() == null)) {
        if (serviceContext == null) {
            guestbookEntry.setCreateDate(now);
        } else {
            guestbookEntry.setCreateDate(serviceContext.getCreateDate(now));
        }
    }

    if (!guestbookEntryModelImpl.hasSetModifiedDate()) {
        if (serviceContext == null) {
            guestbookEntry.setModifiedDate(now);
        } else {
            guestbookEntry.setModifiedDate(serviceContext.getModifiedDate(now));
        }
    }

    Session session = null;

    try {
        session = openSession();

        if (guestbookEntry.isNew()) {
            session.save(guestbookEntry);

            guestbookEntry.setNew(false);
        } else {
            guestbookEntry = (GuestbookEntry) session.merge(guestbookEntry);
        }
    } catch (Exception e) {
        throw processException(e);
    } finally {
        closeSession(session);
    }

    finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);

    if (!_columnBitmaskEnabled) {
        finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
    } else if (isNew) {
        Object[] args = new Object[] { guestbookEntryModelImpl.getUuid() };

        finderCache.removeResult(_finderPathCountByUuid, args);
        finderCache.removeResult(_finderPathWithoutPaginationFindByUuid, args);

        args = new Object[] { guestbookEntryModelImpl.getUuid(), guestbookEntryModelImpl.getCompanyId() };

        finderCache.removeResult(_finderPathCountByUuid_C, args);
        finderCache.removeResult(_finderPathWithoutPaginationFindByUuid_C, args);

        args = new Object[] { guestbookEntryModelImpl.getGroupId(), guestbookEntryModelImpl.getGuestbookId() };

        finderCache.removeResult(_finderPathCountByG_G, args);
        finderCache.removeResult(_finderPathWithoutPaginationFindByG_G, args);

        finderCache.removeResult(_finderPathCountAll, FINDER_ARGS_EMPTY);
        finderCache.removeResult(_finderPathWithoutPaginationFindAll, FINDER_ARGS_EMPTY);
    } else {
        if ((guestbookEntryModelImpl.getColumnBitmask()
                & _finderPathWithoutPaginationFindByUuid.getColumnBitmask()) != 0) {

            Object[] args = new Object[] { guestbookEntryModelImpl.getOriginalUuid() };

            finderCache.removeResult(_finderPathCountByUuid, args);
            finderCache.removeResult(_finderPathWithoutPaginationFindByUuid, args);

            args = new Object[] { guestbookEntryModelImpl.getUuid() };

            finderCache.removeResult(_finderPathCountByUuid, args);
            finderCache.removeResult(_finderPathWithoutPaginationFindByUuid, args);
        }

        if ((guestbookEntryModelImpl.getColumnBitmask()
                & _finderPathWithoutPaginationFindByUuid_C.getColumnBitmask()) != 0) {

            Object[] args = new Object[] { guestbookEntryModelImpl.getOriginalUuid(),
                    guestbookEntryModelImpl.getOriginalCompanyId() };

            finderCache.removeResult(_finderPathCountByUuid_C, args);
            finderCache.removeResult(_finderPathWithoutPaginationFindByUuid_C, args);

            args = new Object[] { guestbookEntryModelImpl.getUuid(), guestbookEntryModelImpl.getCompanyId() };

            finderCache.removeResult(_finderPathCountByUuid_C, args);
            finderCache.removeResult(_finderPathWithoutPaginationFindByUuid_C, args);
        }

        if ((guestbookEntryModelImpl.getColumnBitmask()
                & _finderPathWithoutPaginationFindByG_G.getColumnBitmask()) != 0) {

            Object[] args = new Object[] { guestbookEntryModelImpl.getOriginalGroupId(),
                    guestbookEntryModelImpl.getOriginalGuestbookId() };

            finderCache.removeResult(_finderPathCountByG_G, args);
            finderCache.removeResult(_finderPathWithoutPaginationFindByG_G, args);

            args = new Object[] { guestbookEntryModelImpl.getGroupId(),
                    guestbookEntryModelImpl.getGuestbookId() };

            finderCache.removeResult(_finderPathCountByG_G, args);
            finderCache.removeResult(_finderPathWithoutPaginationFindByG_G, args);
        }
    }

    entityCache.putResult(entityCacheEnabled, GuestbookEntryImpl.class, guestbookEntry.getPrimaryKey(),
            guestbookEntry, false);

    clearUniqueFindersCache(guestbookEntryModelImpl, false);
    cacheUniqueFindersCache(guestbookEntryModelImpl);

    guestbookEntry.resetOriginalValues();

    return guestbookEntry;
}

From source file:com.liferay.docs.guestbook.service.persistence.impl.GuestbookPersistenceImpl.java

License:Open Source License

@Override
public Guestbook updateImpl(Guestbook guestbook) {
    boolean isNew = guestbook.isNew();

    if (!(guestbook instanceof GuestbookModelImpl)) {
        InvocationHandler invocationHandler = null;

        if (ProxyUtil.isProxyClass(guestbook.getClass())) {
            invocationHandler = ProxyUtil.getInvocationHandler(guestbook);

            throw new IllegalArgumentException(
                    "Implement ModelWrapper in guestbook proxy " + invocationHandler.getClass());
        }//from   w  w  w. ja  v  a2  s  . c  om

        throw new IllegalArgumentException(
                "Implement ModelWrapper in custom Guestbook implementation " + guestbook.getClass());
    }

    GuestbookModelImpl guestbookModelImpl = (GuestbookModelImpl) guestbook;

    if (Validator.isNull(guestbook.getUuid())) {
        String uuid = PortalUUIDUtil.generate();

        guestbook.setUuid(uuid);
    }

    ServiceContext serviceContext = ServiceContextThreadLocal.getServiceContext();

    Date now = new Date();

    if (isNew && (guestbook.getCreateDate() == null)) {
        if (serviceContext == null) {
            guestbook.setCreateDate(now);
        } else {
            guestbook.setCreateDate(serviceContext.getCreateDate(now));
        }
    }

    if (!guestbookModelImpl.hasSetModifiedDate()) {
        if (serviceContext == null) {
            guestbook.setModifiedDate(now);
        } else {
            guestbook.setModifiedDate(serviceContext.getModifiedDate(now));
        }
    }

    Session session = null;

    try {
        session = openSession();

        if (guestbook.isNew()) {
            session.save(guestbook);

            guestbook.setNew(false);
        } else {
            guestbook = (Guestbook) session.merge(guestbook);
        }
    } catch (Exception e) {
        throw processException(e);
    } finally {
        closeSession(session);
    }

    finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);

    if (!_columnBitmaskEnabled) {
        finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
    } else if (isNew) {
        Object[] args = new Object[] { guestbookModelImpl.getUuid() };

        finderCache.removeResult(_finderPathCountByUuid, args);
        finderCache.removeResult(_finderPathWithoutPaginationFindByUuid, args);

        args = new Object[] { guestbookModelImpl.getUuid(), guestbookModelImpl.getCompanyId() };

        finderCache.removeResult(_finderPathCountByUuid_C, args);
        finderCache.removeResult(_finderPathWithoutPaginationFindByUuid_C, args);

        args = new Object[] { guestbookModelImpl.getGroupId() };

        finderCache.removeResult(_finderPathCountByGroupId, args);
        finderCache.removeResult(_finderPathWithoutPaginationFindByGroupId, args);

        finderCache.removeResult(_finderPathCountAll, FINDER_ARGS_EMPTY);
        finderCache.removeResult(_finderPathWithoutPaginationFindAll, FINDER_ARGS_EMPTY);
    } else {
        if ((guestbookModelImpl.getColumnBitmask()
                & _finderPathWithoutPaginationFindByUuid.getColumnBitmask()) != 0) {

            Object[] args = new Object[] { guestbookModelImpl.getOriginalUuid() };

            finderCache.removeResult(_finderPathCountByUuid, args);
            finderCache.removeResult(_finderPathWithoutPaginationFindByUuid, args);

            args = new Object[] { guestbookModelImpl.getUuid() };

            finderCache.removeResult(_finderPathCountByUuid, args);
            finderCache.removeResult(_finderPathWithoutPaginationFindByUuid, args);
        }

        if ((guestbookModelImpl.getColumnBitmask()
                & _finderPathWithoutPaginationFindByUuid_C.getColumnBitmask()) != 0) {

            Object[] args = new Object[] { guestbookModelImpl.getOriginalUuid(),
                    guestbookModelImpl.getOriginalCompanyId() };

            finderCache.removeResult(_finderPathCountByUuid_C, args);
            finderCache.removeResult(_finderPathWithoutPaginationFindByUuid_C, args);

            args = new Object[] { guestbookModelImpl.getUuid(), guestbookModelImpl.getCompanyId() };

            finderCache.removeResult(_finderPathCountByUuid_C, args);
            finderCache.removeResult(_finderPathWithoutPaginationFindByUuid_C, args);
        }

        if ((guestbookModelImpl.getColumnBitmask()
                & _finderPathWithoutPaginationFindByGroupId.getColumnBitmask()) != 0) {

            Object[] args = new Object[] { guestbookModelImpl.getOriginalGroupId() };

            finderCache.removeResult(_finderPathCountByGroupId, args);
            finderCache.removeResult(_finderPathWithoutPaginationFindByGroupId, args);

            args = new Object[] { guestbookModelImpl.getGroupId() };

            finderCache.removeResult(_finderPathCountByGroupId, args);
            finderCache.removeResult(_finderPathWithoutPaginationFindByGroupId, args);
        }
    }

    entityCache.putResult(entityCacheEnabled, GuestbookImpl.class, guestbook.getPrimaryKey(), guestbook, false);

    clearUniqueFindersCache(guestbookModelImpl, false);
    cacheUniqueFindersCache(guestbookModelImpl);

    guestbook.resetOriginalValues();

    return guestbook;
}

From source file:com.liferay.exportimport.staging.LayoutStagingImpl.java

License:Open Source License

@Override
public LayoutSetStagingHandler getLayoutSetStagingHandler(LayoutSet layoutSet) {

    if (!ProxyUtil.isProxyClass(layoutSet.getClass())) {
        return null;
    }/*from  w  w w .j  a v  a  2s .c  o m*/

    InvocationHandler invocationHandler = ProxyUtil.getInvocationHandler(layoutSet);

    if (!(invocationHandler instanceof LayoutSetStagingHandler)) {
        return null;
    }

    return (LayoutSetStagingHandler) invocationHandler;
}

From source file:com.liferay.exportimport.staging.LayoutStagingImpl.java

License:Open Source License

@Override
public LayoutStagingHandler getLayoutStagingHandler(Layout layout) {
    if (layout == null) {
        return null;
    }//  www  .  j av  a2 s. co m

    if (!ProxyUtil.isProxyClass(layout.getClass())) {
        return null;
    }

    InvocationHandler invocationHandler = ProxyUtil.getInvocationHandler(layout);

    if (!(invocationHandler instanceof LayoutStagingHandler)) {
        return null;
    }

    return (LayoutStagingHandler) invocationHandler;
}

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/*from  www . ja v  a  2 s .c o  m*/
                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);
                }

            });
}

From source file:com.liferay.portlet.display.template.internal.PortletDisplayTemplateImpl.java

License:Open Source License

@Override
public List<TemplateHandler> getPortletDisplayTemplateHandlers() {
    List<TemplateHandler> templateHandlers = TemplateHandlerRegistryUtil.getTemplateHandlers();

    List<TemplateHandler> portletDisplayTemplateHandlers = new ArrayList<>();

    for (TemplateHandler templateHandler : templateHandlers) {
        if (templateHandler instanceof BasePortletDisplayTemplateHandler) {
            portletDisplayTemplateHandlers.add(templateHandler);
        } else if (ProxyUtil.isProxyClass(templateHandler.getClass())) {
            InvocationHandler invocationHandler = ProxyUtil.getInvocationHandler(templateHandler);

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

                Object bean = classLoaderBeanHandler.getBean();

                if (bean instanceof BasePortletDisplayTemplateHandler) {
                    portletDisplayTemplateHandlers.add(templateHandler);
                }/*from  w ww .  j a v  a2  s  . c o m*/
            }
        }
    }

    return portletDisplayTemplateHandlers;
}