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