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.platform.ui.web.util;
023
024import static org.jboss.seam.ScopeType.APPLICATION;
025
026import java.io.Serializable;
027
028import javax.naming.NamingException;
029
030import org.apache.commons.logging.Log;
031import org.apache.commons.logging.LogFactory;
032import org.jboss.seam.annotations.Create;
033import org.jboss.seam.annotations.In;
034import org.jboss.seam.annotations.Name;
035import org.jboss.seam.annotations.Scope;
036import org.jboss.seam.annotations.Startup;
037import org.jboss.seam.core.Init;
038import org.nuxeo.launcher.config.ConfigurationGenerator;
039import org.nuxeo.runtime.api.Framework;
040import org.nuxeo.runtime.transaction.TransactionHelper;
041
042/**
043 * Component that updates the Seam configuration as needed when app starts
044 *
045 * @author Thierry Delprat
046 */
047@Name("NuxeoSeamConfigurator")
048@Scope(APPLICATION)
049@Startup
050public class SeamConfigurator implements Serializable {
051
052    private static final long serialVersionUID = 178687658975L;
053
054    private static final Log log = LogFactory.getLog(SeamConfigurator.class);
055
056    @In(value = "org.jboss.seam.core.init")
057    transient Init init;
058
059    public boolean isDebugEnabled() {
060        return Framework.isBooleanPropertyTrue(ConfigurationGenerator.SEAM_DEBUG_SYSTEM_PROP);
061    }
062
063    @Create
064    public void init() {
065        // FIXME: this init is done too late: debug components have already
066        // been scanned and not installed => debug page will not work if
067        // available (needs jar jboss-seam-debug to be available)
068        init.setDebug(isDebugEnabled());
069        init.setJbpmInstalled(false);
070        try {
071            TransactionHelper.lookupUserTransaction();
072            log.info("Activate Seam transaction support");
073            init.setTransactionManagementEnabled(true);
074        } catch (NamingException e) {
075            log.info("Deactivate Seam transaction support (no tx manager)");
076            init.setTransactionManagementEnabled(false);
077        }
078    }
079}