001/* 002 * Copyright (c) 2006-2011 Nuxeo SA (http://nuxeo.com/) and others. 003 * 004 * All rights reserved. This program and the accompanying materials 005 * are made available under the terms of the Eclipse Public License v1.0 006 * which accompanies this distribution, and is available at 007 * http://www.eclipse.org/legal/epl-v10.html 008 * 009 * Contributors: 010 * Laurent Doguin 011 */ 012package org.nuxeo.ecm.core.versioning; 013 014import java.io.Serializable; 015import java.util.HashMap; 016import java.util.Map; 017 018import org.nuxeo.common.xmap.annotation.XNode; 019import org.nuxeo.common.xmap.annotation.XNodeMap; 020import org.nuxeo.common.xmap.annotation.XObject; 021 022/** 023 * Descriptor to contribute new versioning rules. 024 * 025 * @author Laurent Doguin 026 * @since 5.4.2 027 */ 028@XObject("versioningRule") 029public class VersioningRuleDescriptor implements Serializable { 030 031 private static final long serialVersionUID = 1L; 032 033 @XNode("@enabled") 034 protected Boolean enabled; 035 036 @XNodeMap(value = "options", key = "@lifeCycleState", type = HashMap.class, componentType = SaveOptionsDescriptor.class) 037 public Map<String, SaveOptionsDescriptor> options = new HashMap<String, SaveOptionsDescriptor>(); 038 039 @XNode("initialState") 040 public InitialStateDescriptor initialState; 041 042 @XNode("@typeName") 043 protected String typeName; 044 045 /** True if the boolean is null or TRUE, false otherwise. */ 046 private static boolean defaultTrue(Boolean bool) { 047 return !Boolean.FALSE.equals(bool); 048 } 049 050 public boolean isEnabled() { 051 return defaultTrue(enabled); 052 } 053 054 public String getTypeName() { 055 return typeName; 056 } 057 058 public Map<String, SaveOptionsDescriptor> getOptions() { 059 return options; 060 } 061 062 public InitialStateDescriptor getInitialState() { 063 return initialState; 064 } 065 066 /** Empty constructor. */ 067 public VersioningRuleDescriptor() { 068 } 069 070 /** Copy constructor. */ 071 public VersioningRuleDescriptor(VersioningRuleDescriptor other) { 072 this.enabled = other.enabled; 073 this.typeName = other.typeName; 074 this.options = other.options; 075 this.initialState = other.initialState; 076 } 077 078 public void merge(VersioningRuleDescriptor other) { 079 if (other.enabled != null) { 080 enabled = other.enabled; 081 } 082 if (other.typeName != null) { 083 typeName = other.typeName; 084 } 085 options.putAll(other.options); // always merge options TODO override flag 086 if (other.initialState != null) { 087 initialState = other.initialState; 088 } 089 } 090 091}