Index: topia-security/src/java/org/codelutin/topia/security/util/TopiaSecurityFilterList.java diff -u topia-security/src/java/org/codelutin/topia/security/util/TopiaSecurityFilterList.java:1.1 topia-security/src/java/org/codelutin/topia/security/util/TopiaSecurityFilterList.java:1.2 --- topia-security/src/java/org/codelutin/topia/security/util/TopiaSecurityFilterList.java:1.1 Mon Sep 25 13:24:40 2006 +++ topia-security/src/java/org/codelutin/topia/security/util/TopiaSecurityFilterList.java Fri Sep 29 15:50:07 2006 @@ -61,5 +61,5 @@ //TODO: Gestion des autorisations sur les champs (cf TopiaEntityAuthorization) throw new UnsupportedOperationException(); } - + } Index: topia-security/src/java/org/codelutin/topia/security/util/TopiaSecurityCaching.java diff -u /dev/null topia-security/src/java/org/codelutin/topia/security/util/TopiaSecurityCaching.java:1.1 --- /dev/null Fri Sep 29 15:50:12 2006 +++ topia-security/src/java/org/codelutin/topia/security/util/TopiaSecurityCaching.java Fri Sep 29 15:50:07 2006 @@ -0,0 +1,80 @@ +/* *##% +* Copyright (C) 2002, 2003, 2004, 2005 Code Lutin, +* Cédric Pineau, Benjamin Poussin, +* +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License +* as published by the Free Software Foundation; either version 2 +* of the License, or (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, write to the Free Software +* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +*##%*/ + +package org.codelutin.topia.security.util; + +import static org.apache.commons.collections.map.AbstractReferenceMap.SOFT; + +import org.apache.commons.collections.map.ReferenceMap; + +public class TopiaSecurityCaching { + + /** + * Le niveau correspond au nombre d'imbrication de ReferenceMap + */ + protected int niveau; + protected ReferenceMap map; + + public TopiaSecurityCaching(int niveau) { + this.niveau = niveau; + map = new ReferenceMap(SOFT, SOFT); + } + + public TopiaSecurityCaching() { + this(0); + } + + public void put(Object value, Object ... keys) { + if(keys.length != niveau + 2) { + throw new ArrayIndexOutOfBoundsException(); + } + + ReferenceMap current = map; + for (int i = 0; i < keys.length -1 ; i++) { + Object key = keys[i]; + ReferenceMap next = (ReferenceMap) current.get(key); + if (next == null) { + next = new ReferenceMap(SOFT, SOFT); + current.put(key, next); + current = next; + } + } + current.put(keys[keys.length - 1], value); + } + + public Object get(Object ... keys) { + if(keys.length != niveau + 2) { + throw new ArrayIndexOutOfBoundsException(); + } + + ReferenceMap current = map; + for (int i = 0; i < keys.length -1 ; i++) { + Object key = keys[i]; + ReferenceMap next = (ReferenceMap) current.get(key); + if (next == null) { + return null; + } else { + current = next; + } + } + + return current.get(keys[keys.length - 1]); + } +}