001/* 002 * (C) Copyright 2006-2009 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.connect.client; 023 024import org.nuxeo.connect.NuxeoConnectClient; 025import org.nuxeo.connect.connector.ConnectConnector; 026import org.nuxeo.connect.downloads.ConnectDownloadManager; 027import org.nuxeo.connect.packages.PackageManager; 028import org.nuxeo.connect.registration.ConnectRegistrationService; 029import org.nuxeo.connect.update.PackageUpdateService; 030import org.nuxeo.runtime.model.ComponentContext; 031import org.nuxeo.runtime.model.DefaultComponent; 032 033/** 034 * Nuxeo Runtime Component used to wrap nuxeo-connect-client services as Nuxeo Services. 035 * <p> 036 * This is required because nuxeo-connect-client can not depend on Nuxeo Runtime, so this wrapper manages the 037 * integration and the callbacks needed. 038 * 039 * @author tiry 040 */ 041public class ConnectClientComponent extends DefaultComponent { 042 043 @Override 044 public void activate(ComponentContext context) { 045 NuxeoConnectClient.setCallBackHolder(new NuxeoCallbackHolder()); 046 } 047 048 // Wrap connect client services as Nuxeo Services 049 public <T> T getAdapter(Class<T> adapter) { 050 051 if (adapter.getCanonicalName().equals(ConnectConnector.class.getCanonicalName())) { 052 return adapter.cast(NuxeoConnectClient.getConnectConnector()); 053 } 054 055 if (adapter.getCanonicalName().equals(ConnectRegistrationService.class.getCanonicalName())) { 056 return adapter.cast(NuxeoConnectClient.getConnectRegistrationService()); 057 } 058 059 if (adapter.getCanonicalName().equals(ConnectDownloadManager.class.getCanonicalName())) { 060 return adapter.cast(NuxeoConnectClient.getDownloadManager()); 061 } 062 063 if (adapter.getCanonicalName().equals(PackageManager.class.getCanonicalName())) { 064 return adapter.cast(NuxeoConnectClient.getPackageManager()); 065 } 066 067 if (adapter.getCanonicalName().equals(PackageUpdateService.class.getCanonicalName())) { 068 return adapter.cast(NuxeoConnectClient.getPackageUpdateService()); 069 } 070 071 return adapter.cast(this); 072 } 073 074}