Index: topia/src/java/org/codelutin/topia/DefaultEntitiesHelper.java diff -u topia/src/java/org/codelutin/topia/DefaultEntitiesHelper.java:1.3 topia/src/java/org/codelutin/topia/DefaultEntitiesHelper.java:1.4 --- topia/src/java/org/codelutin/topia/DefaultEntitiesHelper.java:1.3 Wed Jul 20 12:49:52 2005 +++ topia/src/java/org/codelutin/topia/DefaultEntitiesHelper.java Fri Nov 25 18:51:22 2005 @@ -23,10 +23,10 @@ * Created: 6 juillet 2005 16:34:59 CEST * * @author Benjamin POUSSIN - * @version $Revision: 1.3 $ + * @version $Revision: 1.4 $ * - * Last update: $Date: 2005/07/20 12:49:52 $ - * by : $Author: bpoussin $ + * Last update: $Date: 2005/11/25 18:51:22 $ + * by : $Author: thimel $ */ package org.codelutin.topia; @@ -50,8 +50,13 @@ } public String toString(Object o){ - return ObjectUtils.identityToString(o); + StringBuffer buffer = new StringBuffer(); + if (o instanceof TopiaEntity) { + buffer.append("[").append(((TopiaEntity)o).getEntityClass().getSimpleName()).append("]"); + } + return ObjectUtils.appendIdentityToString(buffer, o).toString(); } + public String toXML(Object o){ return "<" + ((o!=null)?o.getClass().getName():"null") + "/>"; } Index: topia/src/java/org/codelutin/topia/TopiaContext.java diff -u topia/src/java/org/codelutin/topia/TopiaContext.java:1.53 topia/src/java/org/codelutin/topia/TopiaContext.java:1.54 --- topia/src/java/org/codelutin/topia/TopiaContext.java:1.53 Thu Nov 10 10:04:07 2005 +++ topia/src/java/org/codelutin/topia/TopiaContext.java Fri Nov 25 18:51:22 2005 @@ -23,38 +23,43 @@ * * @author Benjamin Poussin * Copyright Code Lutin -* @version $Revision: 1.53 $ +* @version $Revision: 1.54 $ * -* Mise a jour: $Date: 2005/11/10 10:04:07 $ +* Mise a jour: $Date: 2005/11/25 18:51:22 $ * par : $Author: thimel $ */ package org.codelutin.topia; +import java.lang.reflect.Method; import java.util.HashMap; import java.util.HashSet; import java.util.Map; import java.util.Properties; import java.util.Set; -import java.util.logging.Level; -import java.util.logging.Logger; import javax.security.auth.callback.CallbackHandler; import javax.security.auth.login.LoginContext; import javax.security.auth.login.LoginException; +import org.apache.commons.beanutils.MethodUtils; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.codelutin.topia.annotation.MethodInfoHelper; +import org.codelutin.topia.annotation.MethodType; import org.codelutin.topia.distribution.DistributionHelper; import org.codelutin.topia.hook.HookHelper; import org.codelutin.topia.persistence.PersistenceHelper; import org.codelutin.topia.persistence.TopiaTransaction; import org.codelutin.topia.persistence.TransactionHelper; import org.codelutin.topia.security.TopiaSecurityHelper; +import org.codelutin.util.ArrayUtil; import org.codelutin.util.CategorisedListenerSet; public abstract class TopiaContext implements TopiaEntityListener { // TopiaContext /** to use log facility, just put in your code: log.info(\"...\"); */ - static private Logger log = Logger.getLogger("org.codelutin.topia.TopiaContext"); + static private Log log = LogFactory.getLog(TopiaContext.class); protected TopiaContextChild rootContext = null; @@ -103,8 +108,10 @@ try { getSecurityHelper(); } catch (Exception eee) { - log.log(Level.SEVERE, "Aucun SecurityHelper trouvé, sécurité" + - " non opérationnelle"); + if (log.isErrorEnabled()) { + log.error("Aucun SecurityHelper trouvé, sécurité non " + + "opérationnelle"); + } } } @@ -254,7 +261,9 @@ try{ parent.getListeners().fire(clazz, "entityAdded", new TopiaEntityEvent(this, entities)); }catch(Exception eee){ - log.log(Level.WARNING, "Probleme lors de la propagation d'un event", eee); + if (log.isWarnEnabled()) { + log.warn("Probleme lors de la propagation d'un event", eee); + } } } } @@ -268,7 +277,9 @@ try{ parent.getListeners().fire(clazz, "entityModified", new TopiaEntityEvent(this, entities)); }catch(Exception eee){ - log.log(Level.WARNING, "Probleme lors de la propagation d'un event", eee); + if (log.isWarnEnabled()) { + log.warn("Probleme lors de la propagation d'un event", eee); + } } } } @@ -282,7 +293,9 @@ try{ parent.getListeners().fire(clazz, "entityRemoved", new TopiaEntityEvent(this, entities)); }catch(Exception eee){ - log.log(Level.WARNING, "Probleme lors de la propagation d'un event", eee); + if (log.isWarnEnabled()) { + log.warn("Probleme lors de la propagation d'un event", eee); + } } } } @@ -397,7 +410,7 @@ public TopiaEntityOperation getEntityOperation(Class entityClass) throws TopiaException { String className = entityClass.getName() + "Operation"; Class interfacez = Util.getClazz(className); - return (TopiaEntityOperation) getService(interfacez, false); + return (TopiaEntityOperation)getService(interfacez, false); } /** @@ -426,17 +439,21 @@ result = (A)getDistributionHelper().createProxy(serviceInterfacez); } - result = (A)getHookHelper().addHookSupport(result, - new Class[] { serviceInterfacez }); - - if (result instanceof TopiaPersistenceService) { - TopiaPersistenceService ps = (TopiaPersistenceService)result; - listeners.addCategory(this.getClass(), ps.getEntityClass()); - - // on s'enregistre comme listener sur tout les persistences services - // pour que lors du commit on puisse rejouer les modifications sur le - // context pere - ps.addTopiaEntityListener(this); + // Dans le cas d'un TopiaEntityOperation, on ne souhaite pas mettre de proxy + // Dans tous les autres cas, oui + if (!(result instanceof TopiaEntityOperation)) { + result = (A)getHookHelper().addHookSupport(result, + new Class[] { serviceInterfacez }); + + if (result instanceof TopiaPersistenceService) { + TopiaPersistenceService ps = (TopiaPersistenceService)result; + listeners.addCategory(this.getClass(), ps.getEntityClass()); + + // on s'enregistre comme listener sur tout les persistences services + // pour que lors du commit on puisse rejouer les modifications sur le + // context pere + ps.addTopiaEntityListener(this); + } } cacheService.put(serviceInterfacez, result); } @@ -551,6 +568,90 @@ public LoginContext login(CallbackHandler callbackHandler) throws LoginException, TopiaNotFoundException { return getSecurityHelper().login(callbackHandler); + } + + /** + * Vérifie l'existence des implantations de toutes les operations pour les + * entites specifiees + * @return true si chaque implantation a ete trouvee + */ + public boolean checkOperationExistence(Class ... classes) { + boolean allCorrect = true; + for (Class clazz : classes) { + allCorrect &= checkOperationExistenceClass(clazz); + } + return allCorrect; + } + + /** + * Vérifie l'existence des implantations de toutes les operations pour les + * entites specifiees + * @return true si chaque implantation a ete trouvee + */ + public boolean checkOperationExistence(String ... classNames ) { + boolean allCorrect = true; + for (String className : classNames) { + Class clazz = null; + try { + clazz = (Class)Class.forName(className); + } catch (ClassNotFoundException cnfe) { + log.info("La classe \"" + className + "\" n'a pas ete trouvee"); + allCorrect = false; + continue; + } catch (ClassCastException cce) { + log.info("La classe \"" + className + "\" n'est pas une TopiaEntity"); + allCorrect = false; + continue; + } + allCorrect &= checkOperationExistenceClass(clazz); + } + return allCorrect; + } + + /** + * Vérifie l'existence des implantations de toutes les operations pour + * l'entite specifiee + * @return true si chaque implantation a ete trouvee + */ + public boolean checkOperationExistenceClass(Class clazz) { + //On teste en premier lieu l'existence de la classe d'implantation + Class operationsClass; + try { + String operationClassName = clazz.getName() + "Operation"; + Class interfacez = Util.getClazz(operationClassName); + try { + operationsClass = (Class)contextHelper.getImplementationClass(interfacez); + } catch (TopiaNotFoundException eee) { + // on a pas trouve la classe dans les fichiers de proprietes, on essaye directement + operationsClass = (Class)Util.getClazz(interfacez.getName() + "Impl"); + } + } catch (TopiaException te) { + if (log.isTraceEnabled()) { + log.info("Pas d'implantation d'operation trouvee pour l'entite \"" + clazz.getName() + "\""); + } + return false; + } + boolean allCorrect = true; + for (Method method : clazz.getMethods()) { + if (MethodInfoHelper.type(method) == MethodType.OPERATION) { + Class[] args = (Class[])ArrayUtil.concat(new Class[] {clazz}, method.getParameterTypes()); + Method operationMethod = MethodUtils.getAccessibleMethod( + operationsClass, + method.getName(), + args); + if (operationMethod == null) { + if (log.isTraceEnabled()) { + String methodArgs = ""; + for (Class argType : args) { + methodArgs += argType.getName() + ", "; + } + log.info("La methode \"" + method.getName() + "(" + methodArgs.substring(0, methodArgs.length() - 2) + ")\" n'a pas ete trouve sur la classe \"" + operationsClass.getName() + "\""); + } + } + allCorrect &= (operationMethod != null); + } + } + return allCorrect; } } // TopiaContext