Index: topia2/src/java/org/codelutin/topia/framework/TopiaContextImpl.java diff -u topia2/src/java/org/codelutin/topia/framework/TopiaContextImpl.java:1.39 topia2/src/java/org/codelutin/topia/framework/TopiaContextImpl.java:1.40 --- topia2/src/java/org/codelutin/topia/framework/TopiaContextImpl.java:1.39 Mon Oct 16 15:38:20 2006 +++ topia2/src/java/org/codelutin/topia/framework/TopiaContextImpl.java Tue Oct 17 13:02:52 2006 @@ -23,9 +23,9 @@ * * @author poussin * - * @version $Revision: 1.39 $ + * @version $Revision: 1.40 $ * - * Last update: $Date: 2006/10/16 15:38:20 $ by : $Author: bpoussin $ + * Last update: $Date: 2006/10/17 13:02:52 $ by : $Author: bpoussin $ */ package org.codelutin.topia.framework; @@ -47,7 +47,9 @@ import java.sql.Statement; import java.text.DateFormat; import java.text.SimpleDateFormat; +import java.util.Collection; import java.util.Date; +import java.util.Enumeration; import java.util.HashMap; import java.util.Iterator; import java.util.LinkedList; @@ -61,10 +63,8 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.codelutin.topia.TopiaIndexService; import org.codelutin.topia.TopiaContext; import org.codelutin.topia.TopiaException; -import org.codelutin.topia.TopiaHistoryService; import org.codelutin.topia.TopiaNotFoundException; import org.codelutin.topia.TopiaVetoException; import org.codelutin.topia.event.TopiaEntityEvent; @@ -78,8 +78,6 @@ import org.codelutin.topia.event.TopiaVetoableEntityListener; import org.codelutin.topia.event.TopiaVetoableEntityLoadEvent; import org.codelutin.topia.event.TopiaVetoableEntityLoadListener; -import org.codelutin.topia.index.IndexEnginImplementor; -import org.codelutin.topia.index.NotIndexable; import org.codelutin.topia.persistence.TopiaDAO; import org.codelutin.topia.persistence.TopiaDAODelegator; import org.codelutin.topia.persistence.TopiaEntity; @@ -216,26 +214,90 @@ protected List transactionEvents = new LinkedList(); - protected IndexEnginImplementor indexEngin = null; - - protected TopiaHistoryService historyService = null; - /** - * Manager pour la sécurité - */ - protected TopiaSecurityManager securityManager; + /** key: service name; value: service instance */ + protected Map services = null; /** * constructeur utilisé par la factory pour creer les contexts initiaux * * @param config + * @throws TopiaNotFoundException */ - public TopiaContextImpl(Properties config) { + public TopiaContextImpl(Properties config) throws TopiaNotFoundException { this.config = config; - initSecurity(); - initIndexEngin(); - initHistory(); + services = loadServices(config); + getHibernateConfiguration(); // force mapping loading + initServices(services); + } + + protected Map loadServices(Properties config) { + Map result = new HashMap(); + // recherche des services present dans la config + for (Enumeration e=(Enumeration)config.propertyNames(); e.hasMoreElements();) { + String key = e.nextElement(); + if (key.matches("^topia\\.service\\.\\w+$")) { + String classService = config.getProperty(key); + try { + Class forName = Class.forName(classService); + Object newInstance = forName.newInstance(); + TopiaService service = (TopiaService) newInstance; + if (key.equals("topia.service." + service.getServiceName())) { + result.put(service.getServiceName(), service); + } else { + log.warn("Service config key doesn't match service name, disable it: " + key + " != " + service.getServiceName()); + } + } catch (Throwable eee) { + if(log.isErrorEnabled()) { + log.error("Service class inconnu for " + key + ": " + classService); + } + if(log.isDebugEnabled()) { + log.debug(eee); + } + } + } + } + return result; + } + + protected void initServices(Map services) { + for (Iterator i=services.values().iterator(); i.hasNext();) { + TopiaService service = i.next(); + try { + service.init(this); + } catch (Exception eee) { + log.warn("Can't init service disable it: " + service.getServiceName(), eee); + } + } } + public Map getServices() { + TopiaContextImplementor parent = getParentContext(); + if(parent != null) { + return parent.getServices(); + } else { + return services; + } + + } + + public boolean serviceEnabled(String name) { + boolean result = getServices().containsKey(name); + return result; + } + + public TopiaService getService(String name) { + TopiaService result = getServices().get(name); + return result; + } + + /* (non-Javadoc) + * @see org.codelutin.topia.framework.TopiaContextImplementor#getAllServices() + */ + public Collection getAllServices() { + Collection result = getServices().values(); + return result; + } + /** * Constructeur utilisé par le beginTransaction pour créer le context fils. * @@ -420,9 +482,14 @@ // ajout des classes dites persistentes String listPersistenceClasses = getConfig().getProperty( TOPIA_PERSISTENCE_CLASSES, ""); - if(getSecurityManager() != null) { - listPersistenceClasses += "," + securityManager.getPersistenceClasses(); + + for (TopiaService service : getAllServices()) { + String persistenceClasses = service.getPersistenceClasses(); + if (persistenceClasses != null && !"".equals(persistenceClasses)) { + listPersistenceClasses += "," + persistenceClasses; + } } + String[] classes = listPersistenceClasses.split(","); for (String classname : classes) { classname = classname.trim(); @@ -1178,18 +1245,18 @@ if (getParentContext() != null) { getParentContext().fireOnCommited(); } - if (isIndexEnabled()) { - getIndexEnginImplementor().doIndexation(); - } +// FIXME indexation if (isIndexEnabled()) { +// getIndexEnginImplementor().doIndexation(); +// } } catch (Exception eee) { if (log.isWarnEnabled()) { log.warn("Can't fire event commit for entity", eee); } } finally { transactionEvents.clear(); - if (isIndexEnabled()) { - getIndexEnginImplementor().clearLastRecordedIndexation(); - } +// FIXME indexation if (isIndexEnabled()) { +// getIndexEnginImplementor().clearLastRecordedIndexation(); +// } } } @@ -1215,9 +1282,9 @@ } } finally { transactionEvents.clear(); - if (isIndexEnabled()) { - getIndexEnginImplementor().clearLastRecordedIndexation(); - } +// FIXME indexation if (isIndexEnabled()) { +// getIndexEnginImplementor().clearLastRecordedIndexation(); +// } } } @@ -1352,9 +1419,9 @@ Object entity = event.getEntity(); context.fireOnUpdated(event.getPersister().getMappedClass( EntityMode.POJO), id, entity); - if (!(entity instanceof NotIndexable) && context.isIndexEnabled()) { - context.getIndexEnginImplementor().recordForIndexation(id, event.getState()); - } +// FIXME indexation if (!(entity instanceof NotIndexable) && context.isIndexEnabled()) { +// context.getIndexEnginImplementor().recordForIndexation(id, event.getState()); +// } } } @@ -1371,142 +1438,13 @@ Object entity = event.getEntity(); context.fireOnDeleted(event.getPersister().getMappedClass( EntityMode.POJO), id, entity); - if (!(entity instanceof NotIndexable) && context.isIndexEnabled()) { - context.getIndexEnginImplementor().recordForIndexation(id, null); - } - } - } - } - - /** - * Initialise le TopiaSecurityManager en fonction des - * propriétés du context. Si le type n'est pas connu, la variable reste à - * null. - */ - protected void initHistory() { - Properties props = getConfig(); - historyService = null; - if (props != null) { - String classHistory = props.getProperty(TOPIA_HISTORY); - try { - Class forName = Class.forName(classHistory); - Object newInstance = forName.newInstance(); - historyService = (TopiaHistoryService) newInstance; - historyService.init(this); - } catch (Throwable eee) { - if(log.isErrorEnabled()) { - log.error("HistoryService inconnu : " + classHistory); - } - if(log.isDebugEnabled()) { - log.debug(eee); - } - } - } - } - - public boolean isHistoryEnabled() { - return getHistoryService() != null; - } - - public TopiaHistoryService getHistoryService() { - TopiaContextImplementor parent = getParentContext(); - if(parent != null) { - return parent.getHistoryService(); - } else { - return historyService; - } - } - - /** - * Initialise le TopiaSecurityManager en fonction des - * propriétés du context. Si le type n'est pas connu, la variable reste à - * null. - */ - protected void initIndexEngin() { - Properties props = getConfig(); - indexEngin = null; - if (props != null) { - String classIndexEngin = props.getProperty(TOPIA_INDEX_ENGIN); - try { - Class forName = Class.forName(classIndexEngin); - Object newInstance = forName.newInstance(); - indexEngin = (IndexEnginImplementor) newInstance; - indexEngin.init(this); - } catch (Throwable eee) { - if(log.isErrorEnabled()) { - log.error("IndexEngin inconnu : " + classIndexEngin); - } - if(log.isDebugEnabled()) { - log.debug(eee); - } - } - } - } - - public boolean isIndexEnabled() { - return getIndexService() != null; - } - - public TopiaIndexService getIndexService() { - TopiaIndexService result = getIndexEnginImplementor(); - return result; - } - - public IndexEnginImplementor getIndexEnginImplementor() { - TopiaContextImplementor parent = getParentContext(); - if(parent != null) { - return parent.getIndexEnginImplementor(); - } else { - return indexEngin; - } - } - - /** - * Initialise le TopiaSecurityManager en fonction des - * propriétés du context. Si le type n'est pas connu, la variable reste à - * null. - */ - protected void initSecurity() { - Properties props = getConfig(); - securityManager = null; - if (props != null) { - String classIndexEngin = props.getProperty(TOPIA_SECURITY_MANAGER); - try { - Class forName = Class.forName(classIndexEngin); - Object newInstance = forName.newInstance(); - securityManager = (TopiaSecurityManager) newInstance; - securityManager.init(this); - } catch (Throwable eee) { - if(log.isErrorEnabled()) { - log.error("IndexEngin inconnu : " + classIndexEngin); - } - if(log.isDebugEnabled()) { - log.debug(eee); - } +// FIXME indexation if (!(entity instanceof NotIndexable) && context.isIndexEnabled()) { +// context.getIndexEnginImplementor().recordForIndexation(id, null); +// } } } } - /* (non-Javadoc) - * @see org.codelutin.topia.framework.TopiaContextImplementor#isSecurityEnabled() - */ - public boolean isSecurityEnabled() { - return securityManager != null; - } - - /* - * (non-Javadoc) - * @see org.codelutin.topia.TopiaContext#getTopiaSecurityManager() - */ - public TopiaSecurityManager getSecurityManager() { - TopiaContextImplementor parent = getParentContext(); - if(parent != null) { - return parent.getSecurityManager(); - } else { - return securityManager; - } - } - /** * Backup database in gzip compressed file * Only work for h2 database Index: topia2/src/java/org/codelutin/topia/framework/TopiaContextImplementor.java diff -u topia2/src/java/org/codelutin/topia/framework/TopiaContextImplementor.java:1.13 topia2/src/java/org/codelutin/topia/framework/TopiaContextImplementor.java:1.14 --- topia2/src/java/org/codelutin/topia/framework/TopiaContextImplementor.java:1.13 Mon Oct 16 15:38:20 2006 +++ topia2/src/java/org/codelutin/topia/framework/TopiaContextImplementor.java Tue Oct 17 13:02:52 2006 @@ -23,22 +23,22 @@ * Created: 3 janv. 2006 21:27:24 * * @author poussin - * @version $Revision: 1.13 $ + * @version $Revision: 1.14 $ * - * Last update: $Date: 2006/10/16 15:38:20 $ + * Last update: $Date: 2006/10/17 13:02:52 $ * by : $Author: bpoussin $ */ package org.codelutin.topia.framework; +import java.util.Collection; +import java.util.Map; import java.util.Properties; import java.util.Set; -import org.codelutin.topia.TopiaIndexService; import org.codelutin.topia.TopiaContext; import org.codelutin.topia.TopiaException; import org.codelutin.topia.TopiaNotFoundException; -import org.codelutin.topia.index.IndexEnginImplementor; import org.codelutin.topia.persistence.TopiaDAO; import org.codelutin.topia.persistence.TopiaEntity; import org.codelutin.util.CategorisedListenerSet; @@ -201,16 +201,14 @@ */ public void fireOnRollbacked(); - /** - * Indique si la sécurité est activée ou non - */ - public boolean isSecurityEnabled(); - - /** - * Retourne la vision framework du moteur d'indexation - */ - public IndexEnginImplementor getIndexEnginImplementor(); - public void removeChildContext(TopiaContextImplementor child); + + public boolean serviceEnabled(String name); + + public Map getServices(); + public TopiaService getService(String name); + + public Collection getAllServices(); + } //TopiaContextImplementor Index: topia2/src/java/org/codelutin/topia/framework/TopiaService.java diff -u topia2/src/java/org/codelutin/topia/framework/TopiaService.java:1.1 topia2/src/java/org/codelutin/topia/framework/TopiaService.java:1.2 --- topia2/src/java/org/codelutin/topia/framework/TopiaService.java:1.1 Mon Oct 9 14:20:18 2006 +++ topia2/src/java/org/codelutin/topia/framework/TopiaService.java Tue Oct 17 13:02:52 2006 @@ -23,9 +23,9 @@ * Created: 8 oct. 06 17:15:52 * * @author poussin - * @version $Revision: 1.1 $ + * @version $Revision: 1.2 $ * - * Last update: $Date: 2006/10/09 14:20:18 $ + * Last update: $Date: 2006/10/17 13:02:52 $ * by : $Author: bpoussin $ */ @@ -38,6 +38,26 @@ */ public interface TopiaService { + /** + * Retourne le nom du service, ce nom doit correspondre a ce qui est + * trouvé dans le fichier de configuration, par exemple pour le service + * d'indexation on doit avoir: topia.service.index et cette methode doit + * retourner index + * + * @return + */ + public String getServiceName(); + + /** + * Permet de récupérer les entités à persister pour la gestion de la sécurité. + * @return Liste des entités à persister, séparées par des virgules + */ + public String getPersistenceClasses(); + + /** + * Initialise le service + * @param context + */ public void init(TopiaContextImplementor context); }