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