001/*
002 * (C) Copyright 2006-2008 Nuxeo SAS (http://nuxeo.com/) and contributors.
003 *
004 * All rights reserved. This program and the accompanying materials
005 * are made available under the terms of the GNU Lesser General Public License
006 * (LGPL) version 2.1 which accompanies this distribution, and is available at
007 * http://www.gnu.org/licenses/lgpl.html
008 *
009 * This library is distributed in the hope that it will be useful,
010 * but WITHOUT ANY WARRANTY; without even the implied warranty of
011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
012 * Lesser General Public License for more details.
013 *
014 * Contributors:
015 *     bstefanescu
016 *
017 * $Id$
018 */
019
020package org.nuxeo.ecm.webengine.session;
021
022/**
023 * @author <a href="mailto:bs@nuxeo.com">Bogdan Stefanescu</a>
024 */
025public abstract class AbstractComponent implements Component {
026
027    private static final long serialVersionUID = 3472450841328363350L;
028
029    protected String name;
030
031    private boolean isLive;
032
033    public String getName() {
034        return name;
035    }
036
037    public boolean isLive() {
038        return isLive;
039    }
040
041    public void initialize(UserSession session, String name) throws SessionException {
042        if (isLive) {
043            throw new InvalidStateException(this, "initialize");
044        }
045        this.name = name;
046        doInitialize(session, name);
047        isLive = true;
048    }
049
050    public void destroy(UserSession session) throws SessionException {
051        if (!isLive) {
052            throw new InvalidStateException(this, "destroy");
053        }
054        doDestroy(session);
055        name = null;
056        isLive = false;
057    }
058
059    public void doInitialize(UserSession session, String name) throws SessionException {
060        // do nothing by default
061    }
062
063    public void doDestroy(UserSession session) throws SessionException {
064        // do nothing by default
065    }
066
067}