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