001/* 002 * (C) Copyright 2017 Nuxeo (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 * Funsho David 018 * Kevin Leturc 019 */ 020package org.nuxeo.ecm.core.versioning; 021 022import java.io.Serializable; 023import java.util.HashSet; 024import java.util.Set; 025 026import org.apache.commons.logging.Log; 027import org.apache.commons.logging.LogFactory; 028import org.nuxeo.common.xmap.annotation.XNode; 029import org.nuxeo.common.xmap.annotation.XNodeList; 030import org.nuxeo.common.xmap.annotation.XObject; 031 032/** 033 * @since 9.1 034 */ 035@XObject("filter") 036public class VersioningFilterDescriptor implements Serializable { 037 038 private static final long serialVersionUID = 1L; 039 040 private static final Log log = LogFactory.getLog(VersioningFilterDescriptor.class); 041 042 @XNode("@id") 043 protected String id; 044 045 @XNode("@class") 046 protected Class<VersioningPolicyFilter> className; 047 048 @XNodeList(value = "type", componentType = String.class, type = HashSet.class) 049 protected Set<String> types = new HashSet<>(); 050 051 @XNodeList(value = "facet", componentType = String.class, type = HashSet.class) 052 protected Set<String> facets = new HashSet<>(); 053 054 @XNodeList(value = "schema", componentType = String.class, type = HashSet.class) 055 protected Set<String> schemas = new HashSet<>(); 056 057 @XNode("condition") 058 protected String condition; 059 060 public String getId() { 061 return id; 062 } 063 064 public VersioningPolicyFilter newInstance() { 065 VersioningPolicyFilter filter = null; 066 if (className != null) { 067 try { 068 filter = className.newInstance(); 069 } catch (InstantiationException | IllegalAccessException e) { 070 log.error("Class " + className + " could not be instantiated", e); 071 } 072 } else { 073 return new StandardVersioningPolicyFilter(types, facets, schemas, condition); 074 } 075 return filter; 076 } 077 078 @Override 079 public String toString() { 080 return getClass().getSimpleName() + '(' + id + ')'; 081 } 082 083}