001/* 002 * (C) Copyright 2006-2012 Nuxeo SAS (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 * Nuxeo - initial API and implementation 016 * 017 * $Id$ 018 */ 019package org.nuxeo.ecm.platform.scanimporter.service; 020 021import java.io.Serializable; 022import java.util.ArrayList; 023import java.util.List; 024 025import org.apache.commons.logging.Log; 026import org.apache.commons.logging.LogFactory; 027import org.nuxeo.common.xmap.annotation.XNode; 028import org.nuxeo.common.xmap.annotation.XNodeList; 029import org.nuxeo.common.xmap.annotation.XObject; 030import org.nuxeo.ecm.platform.scanimporter.processor.DocumentTypeMapper; 031 032/** 033 * Top level descriptor for mapping 034 * 035 * @author Thierry Delprat 036 */ 037@XObject("mapping") 038public class ScanFileMappingDescriptor implements Serializable { 039 040 private static final long serialVersionUID = 1L; 041 042 public static final String DEFAULT_CONTAINER_TYPE = "Folder"; 043 044 public static final String DEFAULT_LEAF_TYPE = "File"; 045 046 private static final Log log = LogFactory.getLog(ScanFileMappingDescriptor.class); 047 048 @XNode("targetContainerType") 049 protected String targetContainerType = DEFAULT_CONTAINER_TYPE; 050 051 @XNode("targetLeafType") 052 protected String targetLeafType = DEFAULT_LEAF_TYPE; 053 054 @XNode("targetLeafTypeMapper") 055 protected Class<DocumentTypeMapper> mapperClass; 056 057 protected DocumentTypeMapper leafTypeMapper = null; 058 059 @XNodeList(value = "fieldMappings/fieldMapping", type = ArrayList.class, componentType = ScanFileFieldMapping.class) 060 private List<ScanFileFieldMapping> fieldMappings; 061 062 @XNodeList(value = "blobMappings/blobMapping", type = ArrayList.class, componentType = ScanFileBlobMapping.class) 063 private List<ScanFileBlobMapping> blobMappings; 064 065 public List<ScanFileFieldMapping> getFieldMappings() { 066 return fieldMappings; 067 } 068 069 public List<ScanFileBlobMapping> getBlobMappings() { 070 return blobMappings; 071 } 072 073 public String getTargetContainerType() { 074 return targetContainerType; 075 } 076 077 public String getTargetLeafType() { 078 return targetLeafType; 079 } 080 081 public DocumentTypeMapper getTargetLeafTypeMapper() { 082 if (mapperClass == null) { 083 return null; 084 } 085 if (leafTypeMapper == null) { 086 try { 087 leafTypeMapper = mapperClass.newInstance(); 088 } catch (ReflectiveOperationException e) { 089 log.error("Unable to instanciate mapper class", e); 090 } 091 } 092 return leafTypeMapper; 093 } 094 095}