Index: topia/src/java/org/codelutin/topia/TopiaContext.java diff -u topia/src/java/org/codelutin/topia/TopiaContext.java:1.41 topia/src/java/org/codelutin/topia/TopiaContext.java:1.42 --- topia/src/java/org/codelutin/topia/TopiaContext.java:1.41 Fri Jul 22 16:57:57 2005 +++ topia/src/java/org/codelutin/topia/TopiaContext.java Fri Jul 22 22:01:33 2005 @@ -23,9 +23,9 @@ * * @author Benjamin Poussin * Copyright Code Lutin -* @version $Revision: 1.41 $ +* @version $Revision: 1.42 $ * -* Mise a jour: $Date: 2005/07/22 16:57:57 $ +* Mise a jour: $Date: 2005/07/22 22:01:33 $ * par : $Author: thimel $ */ @@ -76,6 +76,8 @@ protected TransactionHelper transactionHelper = null; protected TopiaTransaction transaction = null; + + protected TopiaAssociationManager associationManager = null; protected CategorisedListenerSet listeners = new CategorisedListenerSet( TopiaEntityListener.class); @@ -250,6 +252,15 @@ cacheService.put(serviceInterfacez, result); } return result; + } + + /** + * Retourne l'objet gérant les associations entre les entités + */ + protected TopiaAssociationManager getAssociationManager() { + if (associationManager == null) + associationManager = new TopiaAssociationManager(); + return associationManager; } /** Index: topia/src/java/org/codelutin/topia/TopiaAssociationManager.java diff -u /dev/null topia/src/java/org/codelutin/topia/TopiaAssociationManager.java:1.1 --- /dev/null Fri Jul 22 22:01:38 2005 +++ topia/src/java/org/codelutin/topia/TopiaAssociationManager.java Fri Jul 22 22:01:33 2005 @@ -0,0 +1,107 @@ +/* *##% +* 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. +*##%*/ + +/* * +* TopiaAssociationsManager.java +* +* Created: 9 juin 2005 +* +* @author Arnaud Thimel +* @version $Revision$ +*/ + + +package org.codelutin.topia; + +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; + +import org.codelutin.util.HashMapMultiKey; +import org.codelutin.util.HashMapMultiKey.Key; + +/** + * Classe gérant les associations entre les entités. + * Chaque association différente est une HashMapMultiKey identifiée dans la + * table associations par un identifiant de l'association. + * Les instances d'associations sont représentées par la présence d'une + * instance de Key dont les clés sont les deux instances des + * entités concernées. + */ +public class TopiaAssociationManager { + + protected HashMap associations; + //La table associations est constituée de clés String identifiant les + //différentes associations et les valeurs sont des HashMapMultiKey dont + //chaque entrée identifie une instance d'association. + + public TopiaAssociationManager() { + associations = new HashMap(); + } + + public void createAssociation(String associationName) { + if (associations.get(associationName) == null) + associations.put(associationName, new HashMapMultiKey()); + } + + public HashMapMultiKey getAssociation(String associationName) { + return associations.get(associationName); + } + + public List getKeys(String associationName, Object partOfKey) { + HashMapMultiKey assocMap = associations.get(associationName); + if (assocMap == null) + return null; + return (List)assocMap.getKeys(partOfKey); + } + + public Object getAssociationClass(String associationName, Key key) { + HashMapMultiKey assocMap = associations.get(associationName); + if (assocMap == null) + return null; + return assocMap.get(key); + } + + public List getKeysForPosition(String associationName, Object partOfKey, int pos) { + List keys = getKeys(associationName, partOfKey); + for (Key key : keys) { + if ((pos >= key.size()) || (!key.get(pos).equals(partOfKey))) + keys.remove(key);//FIXME Acces concurrentiel !!! + } + return keys; + } + + public Object getFirstOppositeObjectForPosition(String associationName, Object partOfKey, int pos) { + Iterator it = getKeys(associationName, partOfKey).iterator(); + if (it.hasNext()) + return ((Key)it.next()).get(1-pos); + else + return null; + } + + public int numberInPosition(String associationName, Object partOfKey, int pos) { + int number = 0; + for (Key key : getKeys(associationName, partOfKey)) { + if ((pos < key.size()) || (key.get(pos).equals(partOfKey))) + number++; + } + return number; + } +}