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 * Kevin Leturc <kleturc@nuxeo.com> 018 */ 019package org.nuxeo.ecm.core.schema; 020 021import java.util.Collections; 022import java.util.Map; 023import java.util.Set; 024 025/** 026 * Handler used to test if a specific property is marked as deprecated/removed and to get its fallback. 027 * 028 * @since 9.2 029 * @deprecated since 11.1, use {@link PropertyCharacteristicHandler} service instead 030 */ 031@Deprecated(since = "11.1") 032public class PropertyDeprecationHandler { 033 034 /** 035 * Deprecated/removed properties map, its mapping is: 036 * <p> 037 * schemaName -> propertyXPath -> fallbackXPath 038 * </p> 039 */ 040 protected final Map<String, Map<String, String>> properties; 041 042 public PropertyDeprecationHandler(Map<String, Map<String, String>> properties) { 043 this.properties = properties; 044 } 045 046 /** 047 * @return true if the input property has deprecated/removed property 048 */ 049 public boolean hasMarkedProperties(String schema) { 050 return properties.containsKey(schema); 051 } 052 053 /** 054 * Returned properties are a path to marked property. 055 * 056 * @return the deprecated/removed properties for input schema or an empty set if schema doesn't have marked 057 * properties 058 */ 059 public Set<String> getProperties(String schema) { 060 Map<String, String> schemaProperties = properties.get(schema); 061 if (schemaProperties == null) { 062 return Collections.emptySet(); 063 } 064 return Collections.unmodifiableSet(schemaProperties.keySet()); 065 } 066 067 /** 068 * @return true if the input property is marked as deprecated/removed 069 */ 070 public boolean isMarked(String schema, String name) { 071 Map<String, String> schemaProperties = properties.get(schema); 072 return schemaProperties != null && schemaProperties.containsKey(name); 073 } 074 075 /** 076 * @return the fallback of input property, if it is marked as deprecated/removed and has a fallback 077 */ 078 public String getFallback(String schema, String name) { 079 Map<String, String> schemaProperties = properties.get(schema); 080 if (schemaProperties != null) { 081 return schemaProperties.get(name); 082 } 083 return null; 084 } 085 086}