001/* 
002 * Copyright (c) 2006-2011 Nuxeo SA (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 *     bstefanescu
011 *
012 * $Id$
013 */
014
015package org.nuxeo.ecm.platform.rendering.fm.extensions;
016
017import java.util.HashMap;
018import java.util.Map;
019
020/**
021 * @author <a href="mailto:bs@nuxeo.com">Bogdan Stefanescu</a>
022 */
023public class BlockWriterRegistry {
024
025    protected final Map<String, BlockWriter> blockMap = new HashMap<String, BlockWriter>();
026
027    public void addBlock(String name, BlockWriter bw) {
028        BlockWriter existingBw = blockMap.get(name);
029        if (existingBw != null) {
030            // get the base block and set its superBlock
031            if (existingBw.baseBlock != null) {
032                existingBw.baseBlock.superBlock = bw;
033                existingBw.baseBlock = bw;
034            } else {
035                existingBw.superBlock = bw;
036                existingBw.baseBlock = bw;
037            }
038        } else {
039            blockMap.put(name, bw);
040        }
041    }
042
043    public BlockWriter getBlock(String name) {
044        return blockMap.get(name);
045    }
046
047}