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