001/*
002 * (C) Copyright 2006-2007 Nuxeo SA (http://nuxeo.com/) and others.
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 *     http://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 *
016 * Contributors:
017 *     Nuxeo - initial API and implementation
018 *
019 * $Id$
020 */
021
022package org.nuxeo.ecm.webapp.delegate;
023
024import static org.jboss.seam.ScopeType.CONVERSATION;
025
026import java.io.Serializable;
027
028import javax.annotation.security.PermitAll;
029
030import org.apache.commons.logging.Log;
031import org.apache.commons.logging.LogFactory;
032import org.jboss.seam.annotations.Destroy;
033import org.jboss.seam.annotations.Name;
034import org.jboss.seam.annotations.Scope;
035import org.jboss.seam.annotations.Unwrap;
036import org.nuxeo.ecm.platform.types.TypeManager;
037import org.nuxeo.runtime.api.Framework;
038
039/**
040 * @author <a href="mailto:rcaraghin@nuxeo.com">Razvan Caraghin</a>
041 */
042@Name("typeManager")
043@Scope(CONVERSATION)
044public class TypeManagerBusinessDelegate implements Serializable {
045
046    private static final long serialVersionUID = -5326113474071108997L;
047
048    private static final Log log = LogFactory.getLog(TypeManagerBusinessDelegate.class);
049
050    protected TypeManager typeManager;
051
052    // @Create
053    public void initialize() {
054        log.info("Seam component initialized...");
055    }
056
057    /**
058     * Acquires a new {@link TypeManager} reference. The related EJB may be deployed on a local or remote AppServer.
059     *
060     * @return
061     */
062    @Unwrap
063    public TypeManager getTypeManager() {
064        if (typeManager == null) {
065            typeManager = Framework.getService(TypeManager.class);
066        }
067        return typeManager;
068    }
069
070    @Destroy
071    @PermitAll
072    public void destroy() {
073        if (null != typeManager) {
074            // typeManager.remove();
075            typeManager = null;
076        }
077    }
078}