001/*
002 * (C) Copyright 2006-2007 Nuxeo SAS <http://nuxeo.com> and others
003 *
004 * All rights reserved. This program and the accompanying materials
005 * are made available under the terms of the Eclipse Public License v1.0
006 * which accompanies this distribution, and is available at
007 * http://www.eclipse.org/legal/epl-v10.html
008 *
009 * Contributors:
010 *     Jean-Marc Orliaguet, Chalmers
011 *
012 * $Id$
013 */
014
015package org.nuxeo.theme.models;
016
017import java.util.HashMap;
018import java.util.Map;
019
020import org.nuxeo.theme.rendering.RenderingInfo;
021
022public final class InfoPool {
023
024    private static final String INFOID_PREFIX = "i";
025
026    protected static final ThreadLocal<HashMap<String, Info>> threadInstance = new ThreadLocal<HashMap<String, Info>>() {
027        @Override
028        protected HashMap<String, Info> initialValue() {
029            return new HashMap<String, Info>();
030        }
031    };
032
033    public static Map<String, Info> getInfoMap() {
034        return threadInstance.get();
035    }
036
037    public static void register(RenderingInfo info) {
038        getInfoMap().put(computeInfoId(info), info);
039    }
040
041    public static Info get(String key) {
042        return getInfoMap().get(key);
043    }
044
045    public static String computeInfoId(RenderingInfo info) {
046        return INFOID_PREFIX + info.getUid().toString();
047    }
048
049}