001/*
002 * (C) Copyright 2014 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 *     Maxime Hilaire
018 *
019 */
020package org.nuxeo.ecm.core.cache;
021
022import java.io.Serializable;
023import java.util.Set;
024
025/**
026 * Class to implement mandatory check attributes before calling implementation of cache This enable to have the same
027 * behavior for any use of cache for all implementation of cache
028 *
029 * @since 6.0
030 */
031public class CacheAttributesChecker extends CacheWrapper {
032
033    public CacheAttributesChecker(CacheManagement cache) {
034        super(cache);
035    }
036
037    @Override
038    public Serializable get(String key) {
039        if (key == null) {
040            return null;
041        }
042        return super.get(key);
043    }
044
045    @Override
046    public Set<String> keySet() {
047        return super.keySet();
048    }
049
050    @Override
051    public void invalidate(String key) {
052        if (key == null) {
053            throw new IllegalArgumentException(String.format("Can't invalidate a null key for the cache '%s'!", cache.getName()));
054        }
055        super.invalidate(key);
056    }
057
058    @Override
059    public void invalidateAll() {
060        super.invalidateAll();
061    }
062
063    @Override
064    public void put(String key, Serializable value) {
065        if (key == null) {
066            throw new IllegalArgumentException(String.format("Can't put a null key for the cache '%s'!", cache.getName()));
067        }
068        super.put(key, value);
069    }
070
071    @Override
072    public boolean hasEntry(String key) {
073        if (key == null) {
074            return false;
075        }
076        return super.hasEntry(key);
077    }
078
079    @Override
080    public long getSize() {
081        return super.getSize();
082    }
083}