001/* 002 * (C) Copyright 2015 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-2.1.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 * Florent Guillaume 016 */ 017package org.nuxeo.ecm.core.blob; 018 019import java.util.HashMap; 020import java.util.Map; 021 022import org.nuxeo.common.xmap.annotation.XNode; 023import org.nuxeo.common.xmap.annotation.XNodeMap; 024import org.nuxeo.common.xmap.annotation.XObject; 025import org.nuxeo.ecm.core.api.NuxeoException; 026 027/** 028 * Descriptor for a {@link BlobDispatcher} and its configuration. 029 * 030 * @since 7.3 031 */ 032@XObject(value = "blobdispatcher") 033public class BlobDispatcherDescriptor { 034 035 public BlobDispatcherDescriptor() { 036 } 037 038 @XNode("class") 039 public Class<? extends BlobDispatcher> klass; 040 041 @XNodeMap(value = "property", key = "@name", type = HashMap.class, componentType = String.class) 042 public Map<String, String> properties = new HashMap<String, String>(); 043 044 private BlobDispatcher instance; 045 046 public synchronized BlobDispatcher getBlobDispatcher() { 047 if (instance == null) { 048 if (klass == null) { 049 throw new NuxeoException("Missing class in blob dispatcher descriptor"); 050 } 051 BlobDispatcher blobDispatcher; 052 try { 053 blobDispatcher = klass.newInstance(); 054 } catch (ReflectiveOperationException e) { 055 throw new NuxeoException(e); 056 } 057 blobDispatcher.initialize(properties); 058 instance = blobDispatcher; 059 } 060 return instance; 061 } 062 063}