001/*
002 * (C) Copyright 2006-2007 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 *     Nuxeo - initial API and implementation
016 *
017 * $Id$
018 */
019
020package org.nuxeo.ecm.webapp.delegate;
021
022import static org.jboss.seam.ScopeType.CONVERSATION;
023
024import java.io.Serializable;
025
026import javax.annotation.security.PermitAll;
027
028import org.apache.commons.logging.Log;
029import org.apache.commons.logging.LogFactory;
030import org.jboss.seam.annotations.Destroy;
031import org.jboss.seam.annotations.Name;
032import org.jboss.seam.annotations.Scope;
033import org.jboss.seam.annotations.Unwrap;
034import org.nuxeo.ecm.platform.types.TypeManager;
035import org.nuxeo.runtime.api.Framework;
036
037/**
038 * @author <a href="mailto:rcaraghin@nuxeo.com">Razvan Caraghin</a>
039 */
040@Name("typeManager")
041@Scope(CONVERSATION)
042public class TypeManagerBusinessDelegate implements Serializable {
043
044    private static final long serialVersionUID = -5326113474071108997L;
045
046    private static final Log log = LogFactory.getLog(TypeManagerBusinessDelegate.class);
047
048    protected TypeManager typeManager;
049
050    // @Create
051    public void initialize() {
052        log.info("Seam component initialized...");
053    }
054
055    /**
056     * Acquires a new {@link TypeManager} reference. The related EJB may be deployed on a local or remote AppServer.
057     *
058     * @return
059     */
060    @Unwrap
061    public TypeManager getTypeManager() {
062        if (typeManager == null) {
063            typeManager = Framework.getService(TypeManager.class);
064        }
065        return typeManager;
066    }
067
068    @Destroy
069    @PermitAll
070    public void destroy() {
071        if (null != typeManager) {
072            // typeManager.remove();
073            typeManager = null;
074        }
075    }
076}