001// Copyright 2012 The Apache Software Foundation 002// 003// Licensed under the Apache License, Version 2.0 (the "License"); 004// you may not use this file except in compliance with the License. 005// You may obtain a copy of the License at 006// 007// http://www.apache.org/licenses/LICENSE-2.0 008// 009// Unless required by applicable law or agreed to in writing, software 010// distributed under the License is distributed on an "AS IS" BASIS, 011// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 012// See the License for the specific language governing permissions and 013// limitations under the License. 014 015package org.apache.tapestry5.internal.services.compatibility; 016 017import org.apache.tapestry5.services.compatibility.Compatibility; 018import org.apache.tapestry5.services.compatibility.Trait; 019 020import java.util.EnumSet; 021import java.util.Map; 022 023public class CompatibilityImpl implements Compatibility 024{ 025 private final EnumSet<Trait> traits; 026 027 public CompatibilityImpl(Map<Trait, Boolean> configuration) 028 { 029 // Since the default in 5.4 is true, we can just remove those for which the value is false. 030 031 traits = EnumSet.allOf(Trait.class); 032 033 for (Map.Entry<Trait, Boolean> entry : configuration.entrySet()) 034 { 035 if (entry.getValue().equals(Boolean.FALSE)) 036 { 037 traits.remove(entry.getKey()); 038 } 039 } 040 } 041 042 public boolean enabled(Trait trait) 043 { 044 assert trait != null; 045 046 return traits.contains(trait); 047 } 048}