001/* 002 * (C) Copyright 2012 Nuxeo SA (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 * Mathieu Guillaume 016 * 017 */ 018 019package org.nuxeo.launcher.connect; 020 021import java.io.IOException; 022 023import org.apache.commons.logging.Log; 024import org.apache.commons.logging.LogFactory; 025import org.nuxeo.common.Environment; 026import org.nuxeo.connect.CallbackHolder; 027import org.nuxeo.connect.update.PackageException; 028import org.nuxeo.connect.update.PackageUpdateService; 029import org.nuxeo.connect.update.standalone.StandaloneUpdateService; 030 031public class StandaloneCallbackHolder implements CallbackHolder { 032 033 static final Log log = LogFactory.getLog(StandaloneCallbackHolder.class); 034 035 protected PackageUpdateService pus = null; 036 037 protected Environment env = null; 038 039 protected boolean testMode = false; 040 041 public StandaloneCallbackHolder(Environment env) throws IOException, PackageException { 042 this.env = env; 043 pus = new ConnectBroker(env).getUpdateService(); 044 } 045 046 public StandaloneCallbackHolder(Environment env, StandaloneUpdateService pus) { 047 this.env = env; 048 this.pus = pus; 049 } 050 051 @Override 052 public PackageUpdateService getUpdateService() { 053 return pus; 054 } 055 056 @Override 057 public boolean isTestModeSet() { 058 return testMode; 059 } 060 061 public void setTestMode(boolean testMode) { 062 this.testMode = testMode; 063 } 064 065 @Override 066 public String getProperty(String key, String defaultValue) { 067 return env.getProperty(key, defaultValue); 068 } 069 070 @Override 071 public String getHomePath() { 072 try { 073 return env.getServerHome().getCanonicalPath(); 074 } catch (IOException e) { 075 log.error("Cannot get home path"); 076 return null; 077 } 078 } 079}