All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.liferay.faces.patches.PatchedBridgeFactoryFinderImpl Maven / Gradle / Ivy

There is a newer version: 3.2.4-ga5
Show newest version
/**
 * Copyright (c) 2000-2014 Liferay, Inc. All rights reserved.
 *
 * This library is free software; you can redistribute it and/or modify it under
 * the terms of the GNU Lesser General Public License as published by the Free
 * Software Foundation; either version 2.1 of the License, or (at your option)
 * any later version.
 *
 * This library is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
 * details.
 */
package com.liferay.faces.patches;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

import javax.portlet.PortletConfig;
import javax.portlet.PortletContext;

import com.liferay.faces.bridge.BridgeFactoryFinder;
import com.liferay.faces.bridge.FactoryWrapper;
import com.liferay.faces.bridge.config.BridgeConfig;
import com.liferay.faces.bridge.config.BridgeConfigFactory;
import com.liferay.faces.bridge.config.BridgeConfigFactoryImpl;


/**
 * @author  Neil Griffin
 */
public class PatchedBridgeFactoryFinderImpl extends BridgeFactoryFinder {

	// Private Constants
	private static final String BRIDGE_FACTORY_CACHE = "com.liferay.faces.bridge.bridgeFactoryCache";

	// Private Data Members
	private BridgeConfig bridgeConfig;
	Map>, FactoryWrapper> bridgeFactoryCache;

	@SuppressWarnings("unchecked")
	@Override
	public void init(PortletConfig portletConfig) {

		System.err.println("*** FACES-2006 PATCH ACTIVATED for portletName=[" + portletConfig.getPortletName() + "] ***");
		PortletContext portletContext = portletConfig.getPortletContext();

		synchronized (portletContext) {
			bridgeFactoryCache = (Map>, FactoryWrapper>)
				portletContext.getAttribute(BRIDGE_FACTORY_CACHE);

			if (bridgeFactoryCache == null) {

				// FACES-2006: Use ConcurrentHashMap instead of HashMap for thread safety.
				bridgeFactoryCache = new ConcurrentHashMap>, FactoryWrapper>();
				portletContext.setAttribute(BRIDGE_FACTORY_CACHE, bridgeFactoryCache);
			}
		}

		BridgeConfigFactory bridgeConfigFactory = new BridgeConfigFactoryImpl(portletConfig);
		bridgeFactoryCache.put(BridgeConfigFactory.class, bridgeConfigFactory);
		bridgeConfig = bridgeConfigFactory.getBridgeConfig();
	}

	@Override
	public FactoryWrapper getFactoryInstance(Class> clazz) {

		FactoryWrapper factory = null;

		if (clazz != null) {

			factory = bridgeFactoryCache.get(clazz);

			if (factory == null) {
				factory = (FactoryWrapper) bridgeConfig.getAttributes().get(clazz.getName());

				if (factory != null) {
					bridgeFactoryCache.put(clazz, factory);
				}
			}
		}

		return factory;
	}

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy