001/* 002 * Copyright (c) 2006-2013 Nuxeo SA (http://nuxeo.com/) and others. 003 * 004 * All rights reserved. This program and the accompanying materials 005 * are made available under the terms of the Eclipse Public License v1.0 006 * which accompanies this distribution, and is available at 007 * http://www.eclipse.org/legal/epl-v10.html 008 * 009 * Contributors: 010 * Vladimir Pasquier <vpasquier@nuxeo.com> 011 * Stephane Lacoin <slacoin@nuxeo.com> 012 */ 013 014package org.nuxeo.ecm.automation.client.jaxrs.impl; 015 016import java.net.URISyntaxException; 017import java.net.URL; 018 019import org.nuxeo.ecm.automation.client.AutomationClient; 020import org.nuxeo.ecm.automation.client.AutomationClientFactory; 021import org.osgi.framework.BundleActivator; 022import org.osgi.framework.BundleContext; 023 024/** 025 * @since 5.7 Automation client osgi activator to use HttpAutomationClient service 026 */ 027public class AutomationClientActivator implements AutomationClientFactory, BundleActivator { 028 029 protected static volatile AutomationClientActivator instance; 030 031 protected BundleContext context; 032 033 @Override 034 public void start(BundleContext bundleContext) { 035 bundleContext.registerService(AutomationClientFactory.class.getName(), this, null); 036 this.instance = this; 037 this.context = bundleContext; 038 } 039 040 @Override 041 public void stop(BundleContext bundleContext) { 042 this.instance = null; 043 this.context = null; 044 } 045 046 @Override 047 public AutomationClient getClient(URL url) throws URISyntaxException { 048 return new HttpAutomationClient(url.toURI().toASCIIString()); 049 } 050 051 public BundleContext getContext() { 052 return context; 053 } 054 055 @Override 056 public AutomationClient getClient(URL url, int httpCxTimeout) throws URISyntaxException { 057 return new HttpAutomationClient(url.toURI().toASCIIString(), httpCxTimeout); 058 } 059 060 public static AutomationClientActivator getInstance() { 061 return instance; 062 } 063}