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 * Antoine Taillefer <ataillefer@nuxeo.com> 016 */ 017package org.nuxeo.drive.adapter.impl; 018 019import org.nuxeo.drive.adapter.FileSystemItem; 020import org.nuxeo.drive.service.FileSystemItemAdapterService; 021import org.nuxeo.ecm.core.api.DocumentModel; 022import org.nuxeo.ecm.core.api.NuxeoException; 023import org.nuxeo.ecm.core.api.adapter.DocumentAdapterFactory; 024import org.nuxeo.runtime.api.Framework; 025 026/** 027 * Factory for {@link FileSystemItem} adapters. 028 * 029 * @author Antoine Taillefer 030 */ 031public class FileSystemItemAdapterFactory implements DocumentAdapterFactory { 032 033 @Override 034 public Object getAdapter(DocumentModel doc, Class<?> itf) { 035 try { 036 return getService().getFileSystemItem(doc); 037 } catch (NuxeoException e) { 038 e.addInfo(String.format("Error while trying to get adapter of class %s for doc %s.", itf.getName(), 039 doc.getId())); 040 throw e; 041 } 042 } 043 044 protected FileSystemItemAdapterService getService() { 045 return Framework.getLocalService(FileSystemItemAdapterService.class); 046 } 047 048}