Index: topia/src/java/org/codelutin/topia/AbstractTopiaElement.java diff -u /dev/null topia/src/java/org/codelutin/topia/AbstractTopiaElement.java:1.1 --- /dev/null Thu Jul 15 13:19:35 2004 +++ topia/src/java/org/codelutin/topia/AbstractTopiaElement.java Thu Jul 15 13:19:30 2004 @@ -0,0 +1,47 @@ +/* *##% + * Copyright (C) 2002, 2003 Code Lutin + * + * 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. + *##%*/ + +/* * + * AbstractTopiaElement.java + * + * Created: 3 juil. 2004 + * + * @author Benjamin Poussin + * Copyright Code Lutin + * @version $Revision: 1.1 $ + * + * Mise a jour: $Date: 2004/07/15 13:19:30 $ + * par : $Author: bpoussin $ + */ + +package org.codelutin.topia; + +public abstract class AbstractTopiaElement implements TopiaElement { // AbstractTopiaElement + + protected TopiaContext topiaContext; + + public void setContext(TopiaContext topiaContext) throws TopiaException { + this.topiaContext = topiaContext; + } + + public TopiaContext getContext() { + return topiaContext; + } + +} // AbstractTopiaElement + Index: topia/src/java/org/codelutin/topia/Const.java diff -u /dev/null topia/src/java/org/codelutin/topia/Const.java:1.1 --- /dev/null Thu Jul 15 13:19:35 2004 +++ topia/src/java/org/codelutin/topia/Const.java Thu Jul 15 13:19:30 2004 @@ -0,0 +1,55 @@ +/* *##% + * Copyright (C) 2002, 2003 Code Lutin + * + * 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. + *##%*/ + +/* * + * Const.java + * + * Created: 3 juil. 2004 + * + * @author Benjamin Poussin + * Copyright Code Lutin + * @version $Revision: 1.1 $ + * + * Mise a jour: $Date: 2004/07/15 13:19:30 $ + * par : $Author: bpoussin $ + */ + +package org.codelutin.topia; + +public interface Const { // Const + public final static String DEFAULT_CONTEXT_PROPERTIES_FILENAME = + "topiaContext.properties"; + + public final static String CONTEXT_CLASS = + "context.class"; + public final static String HELPER_DISTRIBUTION = + "context.helper.distribution"; + public final static String HELPER_PERSISTENCE = + "context.helper.persistence"; + public final static String HELPER_HOOK = + "context.helper.hook"; + + public final static String MAPPING_IMPLEMENTATION = + "mapping.implementation"; + public final static String MAPPING_DISTRIBUTION = + "mapping.distribution"; + public final static String MAPPING_JDO = + "mapping.jdo"; + +} // Const + Index: topia/src/java/org/codelutin/topia/ContextHelper.java diff -u /dev/null topia/src/java/org/codelutin/topia/ContextHelper.java:1.1 --- /dev/null Thu Jul 15 13:19:35 2004 +++ topia/src/java/org/codelutin/topia/ContextHelper.java Thu Jul 15 13:19:30 2004 @@ -0,0 +1,152 @@ +/* *##% + * Copyright (C) 2002, 2003 Code Lutin + * + * 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. + *##%*/ + +/* * + * ContextHelper.java + * + * Created: 3 juil. 2004 + * + * @author Benjamin Poussin + * Copyright Code Lutin + * @version $Revision: 1.1 $ + * + * Mise a jour: $Date: 2004/07/15 13:19:30 $ + * par : $Author: bpoussin $ + */ + +package org.codelutin.topia; + +import java.util.Properties; +import java.util.HashMap; +import java.net.URL; +import java.util.logging.Level; +import java.util.logging.Logger; +import java.lang.reflect.Constructor; +import org.codelutin.util.Resource; + +/** +* Ensemble de methode util pour le framework et reutilisable dans plusieurs +* classe. Les methodes ne sont pas static car chaque context doit avoir +* son propre objet Util. +*/ +public class ContextHelper { // ContextHelper + + protected TopiaContext context = null; + protected Properties properties = null; + + public ContextHelper(TopiaContext context, Properties properties){ + this.context = context; + this.properties = properties; + } + + /** + * Un helper doit avoir un constructeur prenant en paramètre un + * {@link TopiaContext} et un objet {@link java.util.Properties} + * Un objet {@link java.util.Properties} est créé et est chargé avec + * le fichier de propriété définie dans la configuration du context. + * L'ancètre de cet objet de propriété est l'objet de propriété du context + * @param propertyId l'id dans le fichier de propriété du helper + * permettant de retrouver la classe a utiliser. + */ + public Object getHelper(String propertyId) throws TopiaNotFoundException { + String className = properties.getProperty(propertyId); + if (className == null) { + throw new TopiaNotFoundException( + "Helper not found: " + className); + } + + // load properties for helper + String propertiesFilename = properties.getProperty(propertyId+".properties.file"); + Properties properties = new Properties(this.properties); + if (propertiesFilename != null && !propertiesFilename.equals("")) { + try { + URL propURL = Resource.getURL(propertiesFilename); + Logger.getLogger(ContextHelper.class +".getHelper").log( + Level.INFO, + "Properties file used for helper is: " + propURL); + properties.load(propURL.openStream()); + } catch (Exception eee) { + throw new TopiaNotFoundException( + "Properties file can't be found: " + propertiesFilename, + eee); + } + } + + Class mappedClass = null; + try { + // Warning : don't replace that for a Class.forName(...) has it does NOT behave the same way ! + mappedClass = getClass().forName(className); + Constructor constructor = mappedClass.getDeclaredConstructor(new Class[] {TopiaContext.class, Properties.class}); + constructor.setAccessible(true); + return constructor.newInstance(new Object[] {context, properties}); + } catch (Exception eee) { + throw new TopiaNotFoundException( + "Persistence Helper can't be instanciated: " + + className + + " concret : " + + mappedClass, + eee); + } + } + + protected HashMap singleton = new HashMap(); + /** + * Retourne un objet deja instancier de la classe passé en paremetre. Si + * aucun objet de cette classe n'existe, alors un nouveau est instancier. + */ + public Object getSingletonObject(Class clazz) throws TopiaException { + Object result = singleton.get(clazz); + if(result == null){ + result = getInstance(clazz); + singleton.put(clazz, result); + } + return result; + } + + /** + * Instancie un objet de la classe passé en paramètre. Si l'objet instancier + * implante {@link TopiaElement} alors un {@link TopiaElement#setContext} est + * appele. + */ + public Object getInstance(Class clazz) throws TopiaException{ + Object result = Util.getInstance(clazz); + if (result instanceof TopiaElement) { + ((TopiaElement) result).setContext(context); + } + return result; + } + + /** + * Retourne la classe qui implante réellement l'interface passé en paremètre + */ + public Class getImplementationClass(Class interfacez) throws TopiaNotFoundException { + String clazz = properties.getProperty(Const.MAPPING_IMPLEMENTATION + "." + interfacez.getName()); + return Util.getClazz(clazz); + } + + /** + * Retourne la classe qui permet de générer la distribution des méthode de + * l'interface passé en paremètre + */ + public Class getDistributionClass(Class interfacez) throws TopiaNotFoundException { + String clazz = properties.getProperty(Const.MAPPING_DISTRIBUTION + "." + interfacez.getName()); + return Util.getClazz(clazz); + } + +} // ContextHelper + Index: topia/src/java/org/codelutin/topia/TopiaArgument.java diff -u /dev/null topia/src/java/org/codelutin/topia/TopiaArgument.java:1.1 --- /dev/null Thu Jul 15 13:19:35 2004 +++ topia/src/java/org/codelutin/topia/TopiaArgument.java Thu Jul 15 13:19:30 2004 @@ -0,0 +1,77 @@ +/* *##% + * Copyright (C) 2002, 2003 Code Lutin + * + * 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. + *##%*/ + +/* * + * TopiaArgument.java + * + * Created: 3 juil. 2004 + * + * @author Benjamin Poussin + * Copyright Code Lutin + * @version $Revision: 1.1 $ + * + * Mise a jour: $Date: 2004/07/15 13:19:30 $ + * par : $Author: bpoussin $ + */ + +package org.codelutin.topia; + +import java.io.Serializable; +import java.util.List; +import java.util.LinkedList; + +public class TopiaArgument implements Serializable { // TopiaArgument + protected List args = new LinkedList(); + + public List getArgs(){ + return args; + } + public TopiaArgument addArg(Object arg){ + if(!(arg instanceof Serializable)){ + throw new IllegalArgumentException("Argument must be Serializable"); + } + args.add(arg); + return this; + } + public TopiaArgument addArg(int arg){ + return addArg(new Integer(arg)); + } + public TopiaArgument addArg(byte arg){ + return addArg(new Byte(arg)); + } + public TopiaArgument addArg(char arg){ + return addArg(new Character(arg)); + } + public TopiaArgument addArg(float arg){ + return addArg(new Float(arg)); + } + public TopiaArgument Float(double arg){ + return addArg(new Double(arg)); + } + public TopiaArgument addArg(long arg){ + return addArg(new Long(arg)); + } + public TopiaArgument addArg(boolean arg){ + return addArg(new Boolean(arg)); + } + public TopiaArgument addArg(short arg){ + return addArg(new Short(arg)); + } + +} // TopiaArgument + Index: topia/src/java/org/codelutin/topia/TopiaContextFactory.java diff -u /dev/null topia/src/java/org/codelutin/topia/TopiaContextFactory.java:1.1 --- /dev/null Thu Jul 15 13:19:35 2004 +++ topia/src/java/org/codelutin/topia/TopiaContextFactory.java Thu Jul 15 13:19:30 2004 @@ -0,0 +1,134 @@ +/* *##% + * Copyright (C) 2002, 2003 Code Lutin + * + * 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. + *##%*/ + +/* * + * TopiaContextFactory.java + * + * Created: 3 juil. 2004 + * + * @author Benjamin Poussin + * Copyright Code Lutin + * @version $Revision: 1.1 $ + * + * Mise a jour: $Date: 2004/07/15 13:19:30 $ + * par : $Author: bpoussin $ + */ + +package org.codelutin.topia; + +import java.util.Properties; +import java.util.HashMap; +import java.lang.reflect.Constructor; +import java.net.URL; +import java.util.logging.Logger; +import java.util.logging.Level; +import org.codelutin.util.Resource; + +/** +* Class permettant de récupérer le context de l'application. Pour un fichier +* de propriété donné, le context retourné est toujours le même. +*/ +public class TopiaContextFactory { // TopiaContextFactory + + /** Static context */ + protected static HashMap contexts = new HashMap(); + + /** + * Donne le context par defaut, c'est a dire que le fichier de propriété + * recherché est topiaContext.properties. + */ + public static TopiaContext getContext() throws TopiaException { + return getContext(((Properties)null)); + } + + /** + * Donne le context associé au fichier de propriétés passés en argument + * Si le context n'existe pas encore, il est créé. + */ + public static TopiaContext getContext(String propertiesFileName) throws TopiaException { + if (propertiesFileName == null) { + return getContext(((Properties)null)); + } + return getContext(getProperties(propertiesFileName)); + } + + /** + * Donne le context associé à l'objet propriété passé en argument + * Si le context n'existe pas encore, il est créé. + */ + public static TopiaContext getContext(Properties properties) + throws TopiaException { + TopiaContext context = (TopiaContext) contexts.get(properties); + if (context == null) { + if (properties == null) { + context = createContext(getProperties(Const.DEFAULT_CONTEXT_PROPERTIES_FILENAME)); + } else { + context = createContext(properties); + } + contexts.put(properties, context); + } + return context; + } + + /** + * Créé le context en utilisant les propriétés. Pour savoir qu'elle + * context instancier, on utilise la valeur de application.class.context + * qui doit se trouver dans les propriétés. + */ + protected static TopiaContext createContext(Properties properties) throws TopiaNotFoundException { + TopiaContext context = null; + Class contextClass = null; + String contextClassName = + properties.getProperty( + Const.CONTEXT_CLASS, + "org.codelutin.topia.TopiaContext"); + Logger.getLogger(TopiaContextFactory.class + ".createContext").log(Level.INFO, "Class used for context is " + contextClassName); + try { + contextClass = Class.forName(contextClassName); + Constructor constructor = contextClass.getDeclaredConstructor(new Class[] {Properties.class}); + constructor.setAccessible(true); + context = (TopiaContext) constructor.newInstance(new Object[] {properties}); + } catch (Exception eee) { + throw new TopiaNotFoundException( + "TopiaContext can't be instanciated: " + + contextClassName + + " concret : " + + contextClass, + eee); + } + return context; + } + + protected static Properties getProperties(String propertiesFilename) throws TopiaException { + Properties properties = new Properties(); + try { + URL propURL = Resource.getURL(propertiesFilename); + Logger.getLogger(TopiaContext.class +".getDefaultProperties").log( + Level.INFO, + "Properties file used for context is: " + propURL); + properties.load(propURL.openStream()); + } catch (Exception eee) { + throw new TopiaNotFoundException( + "Properties file can't be found: " + propertiesFilename, + eee); + } + return properties; + } + +} // TopiaContextFactory + Index: topia/src/java/org/codelutin/topia/TopiaEntityOperation.java diff -u /dev/null topia/src/java/org/codelutin/topia/TopiaEntityOperation.java:1.1 --- /dev/null Thu Jul 15 13:19:35 2004 +++ topia/src/java/org/codelutin/topia/TopiaEntityOperation.java Thu Jul 15 13:19:30 2004 @@ -0,0 +1,37 @@ +/* *##% + * Copyright (C) 2002, 2003 Code Lutin + * + * 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. + *##%*/ + +/* * + * TopiaEntityOperation.java + * + * Created: 4 juil. 2004 + * + * @author Benjamin Poussin + * Copyright Code Lutin + * @version $Revision: 1.1 $ + * + * Mise a jour: $Date: 2004/07/15 13:19:30 $ + * par : $Author: bpoussin $ + */ + +package org.codelutin.topia; + +public interface TopiaEntityOperation extends TopiaService { // TopiaEntityOperation + +} // TopiaEntityOperation + Index: topia/src/java/org/codelutin/topia/TopiaId.java diff -u /dev/null topia/src/java/org/codelutin/topia/TopiaId.java:1.1 --- /dev/null Thu Jul 15 13:19:35 2004 +++ topia/src/java/org/codelutin/topia/TopiaId.java Thu Jul 15 13:19:30 2004 @@ -0,0 +1,49 @@ +/* *##% + * Copyright (C) 2002, 2003 Code Lutin + * + * 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. + *##%*/ + +/* * + * TopiaId.java + * + * Created: 6 juil. 2004 + * + * @author Benjamin Poussin + * Copyright Code Lutin + * @version $Revision: 1.1 $ + * + * Mise a jour: $Date: 2004/07/15 13:19:30 $ + * par : $Author: bpoussin $ + */ + +package org.codelutin.topia; + +/** +* Ensemble de methode static utile pour la manipulation des topiaId +*/ +public class TopiaId { // TopiaId + + public static String create(Class clazz){ + return clazz.getName() + "#" + System.currentTimeMillis() + "#" + Math.random(); + } + + public static Class getClassName(String topiaId) throws TopiaNotFoundException { + String classname = topiaId.substring(0, topiaId.indexOf("#")); + return Util.getClazz(classname); + } + +} // TopiaId +