Index: topia2/src/java/org/codelutin/topia/framework/TopiaContextImpl.java diff -u topia2/src/java/org/codelutin/topia/framework/TopiaContextImpl.java:1.48 topia2/src/java/org/codelutin/topia/framework/TopiaContextImpl.java:1.49 --- topia2/src/java/org/codelutin/topia/framework/TopiaContextImpl.java:1.48 Thu Jan 18 21:58:47 2007 +++ topia2/src/java/org/codelutin/topia/framework/TopiaContextImpl.java Mon Apr 2 10:49:52 2007 @@ -23,9 +23,9 @@ * * @author poussin * - * @version $Revision: 1.48 $ + * @version $Revision: 1.49 $ * - * Last update: $Date: 2007/01/18 21:58:47 $ by : $Author: bpoussin $ + * Last update: $Date: 2007/04/02 10:49:52 $ by : $Author: bpoussin $ */ package org.codelutin.topia.framework; @@ -44,6 +44,7 @@ import java.io.PrintStream; import java.io.Reader; import java.io.Writer; +import java.lang.reflect.Field; import java.sql.Connection; import java.sql.Statement; import java.text.DateFormat; @@ -221,7 +222,7 @@ } } catch (Throwable eee) { if(log.isErrorEnabled()) { - log.error("Service class inconnu for " + key + ": " + classService); + log.error("Service class unknow for " + key + ": " + classService); } if(log.isDebugEnabled()) { log.debug(eee); @@ -253,16 +254,50 @@ } - public boolean serviceEnabled(String name) { + protected boolean serviceEnabled(String name) { boolean result = getServices().containsKey(name); return result; } - public TopiaService getService(String name) { + protected TopiaService getService(String name) { TopiaService result = getServices().get(name); return result; } + public boolean serviceEnabled(Class interfaceService) { + boolean result = false; + try { + Field f = interfaceService.getField("SERVICE_NAME"); + String name = (String)f.get(null); + result = serviceEnabled(name); + } catch (Exception eee) { + if (log.isWarnEnabled()) { + log.warn("Can't get service name for: " + interfaceService, eee); + } + } + return result; + } + + /** + * Take one service, this service must be valid service interface with + * public static final SERVICE_NAME declaration. + * @param + * @throws TopiaNotFoundException + */ + public E getService(Class interfaceService) throws TopiaNotFoundException { + try { + Field f = interfaceService.getField("SERVICE_NAME"); + String name = (String)f.get(null); + E result = (E)getService(name); + if (result == null) { + throw new TopiaNotFoundException("Service not available: " + interfaceService); + } + return result; + } catch (Exception eee) { + throw new TopiaNotFoundException("Can't get service: " + interfaceService, eee); + } + } + /* (non-Javadoc) * @see org.codelutin.topia.framework.TopiaContextImplementor#getAllServices() */ @@ -470,9 +505,12 @@ TOPIA_PERSISTENCE_CLASSES, ""); for (TopiaService service : getAllServices()) { - String persistenceClasses = service.getPersistenceClasses(); - if (persistenceClasses != null && !"".equals(persistenceClasses)) { - listPersistenceClasses += "," + persistenceClasses; + Class [] persistenceClasses = service.getPersistenceClasses(); + for (Class pc : persistenceClasses) { + String name = pc.getName(); + if (persistenceClasses != null && !"".equals(name)) { + listPersistenceClasses += "," + name; + } } } @@ -708,6 +746,12 @@ this.closed = true; hibernate.close(); getParentContext().removeChildContext(this); + } else { + if (hibernateFactory != null) { + hibernateFactory.close(); + this.closed = true; + log.debug("TopiaContext finalized"); + } } } Index: topia2/src/java/org/codelutin/topia/framework/TopiaContextImplementor.java diff -u topia2/src/java/org/codelutin/topia/framework/TopiaContextImplementor.java:1.15 topia2/src/java/org/codelutin/topia/framework/TopiaContextImplementor.java:1.16 --- topia2/src/java/org/codelutin/topia/framework/TopiaContextImplementor.java:1.15 Mon Oct 23 15:01:58 2006 +++ topia2/src/java/org/codelutin/topia/framework/TopiaContextImplementor.java Mon Apr 2 10:49:52 2007 @@ -23,10 +23,10 @@ * Created: 3 janv. 2006 21:27:24 * * @author poussin - * @version $Revision: 1.15 $ + * @version $Revision: 1.16 $ * - * Last update: $Date: 2006/10/23 15:01:58 $ - * by : $Author: ruchaud $ + * Last update: $Date: 2007/04/02 10:49:52 $ + * by : $Author: bpoussin $ */ package org.codelutin.topia.framework; @@ -106,12 +106,8 @@ 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.2 topia2/src/java/org/codelutin/topia/framework/TopiaService.java:1.3 --- topia2/src/java/org/codelutin/topia/framework/TopiaService.java:1.2 Tue Oct 17 13:02:52 2006 +++ topia2/src/java/org/codelutin/topia/framework/TopiaService.java Mon Apr 2 10:49:52 2007 @@ -23,9 +23,9 @@ * Created: 8 oct. 06 17:15:52 * * @author poussin - * @version $Revision: 1.2 $ + * @version $Revision: 1.3 $ * - * Last update: $Date: 2006/10/17 13:02:52 $ + * Last update: $Date: 2007/04/02 10:49:52 $ * by : $Author: bpoussin $ */ @@ -33,8 +33,15 @@ /** + * Permet d'implanter un service Topia. Il faut absolument créer une interface + * pour votre service qui contienne un attribut SERVICE_NAME + * + *
  • public static final String SERVICE_NAME = "monservice"; + * + * la valeur de cette attribut doit être retourné par les implantation de votre + * service par la méthode {@link #getServiceName()} + * * @author poussin - * */ public interface TopiaService { @@ -49,10 +56,10 @@ public String getServiceName(); /** - * Permet de récupérer les entités à persister pour la gestion de la sécurité. + * Permet de récupérer les entités à persister pour ce service * @return Liste des entités à persister, séparées par des virgules */ - public String getPersistenceClasses(); + public Class [] getPersistenceClasses(); /** * Initialise le service