[Buix-commits] r776 - in trunk/lutinjaxx: jaxx-swing-action/src/main/java/org/codelutin/jaxx/action jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/provider maven/src/main/java/org/codelutin/jaxx
Author: tchemit Date: 2008-07-24 14:10:12 +0000 (Thu, 24 Jul 2008) New Revision: 776 Added: trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/provider/AbstractActionProvider.java trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/provider/ActionProvider.java trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/provider/ActionProviderFromProperties.java Removed: trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/AbstractActionProvider.java trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/ActionProvider.java trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/ActionProviderFromProperties.java Modified: trunk/lutinjaxx/maven/src/main/java/org/codelutin/jaxx/ActionProviderGeneratorMojo.java Log: introduce provider package Deleted: trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/AbstractActionProvider.java =================================================================== --- trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/AbstractActionProvider.java 2008-07-24 14:08:09 UTC (rev 775) +++ trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/AbstractActionProvider.java 2008-07-24 14:10:12 UTC (rev 776) @@ -1,72 +0,0 @@ -/** - * # #% Copyright (C) 2008 Code Lutin, Tony Chemit - * 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. - * # #% - */ -package org.codelutin.jaxx.action; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; - -import java.util.Map; - -/** @author chemit */ -public abstract class AbstractActionProvider<A extends MyAbstractAction> implements ActionProvider<A> { - - protected static Log log = LogFactory.getLog(AbstractActionProvider.class); - - protected String name; - - protected Class<A> baseClass; - - protected Map<String, Class<? extends A>> actions; - - protected abstract Map<String, Class<? extends A>> initCache(); - - protected AbstractActionProvider(String name, Class<A> baseClass, boolean doInitCache) { - this.name = name; - this.baseClass = baseClass; - if (doInitCache) { - this.actions = initCache(); - } - } - - public String getName() { - return name; - } - - public Class<A> getBaseClass() { - return baseClass; - } - - public Map<String, Class<? extends A>> getClasses() { - return actions; - } - - @Override - public String toString() { - return super.toString() + "<name:" + name + ", baseClass:" + baseClass.getSimpleName() + ">"; - } - - protected void clearCache() { - if (actions != null) { - actions.clear(); - actions = null; - } - } - - @Override - protected void finalize() throws Throwable { - super.finalize(); - clearCache(); - } -} Deleted: trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/ActionProvider.java =================================================================== --- trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/ActionProvider.java 2008-07-24 14:08:09 UTC (rev 775) +++ trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/ActionProvider.java 2008-07-24 14:10:12 UTC (rev 776) @@ -1,33 +0,0 @@ -/** - * # #% Copyright (C) 2008 Code Lutin, Tony Chemit - * 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. - * # #% - */ -package org.codelutin.jaxx.action; - -/** - * Contract to be realized by a provider of Actions - * - * @author chemit - */ -public interface ActionProvider<A extends MyAbstractAction> { - - /** @return the name of the provider */ - String getName(); - - /** @return the base classe of provided actions */ - Class<A> getBaseClass(); - - /** @return the provided actions classes */ - java.util.Map<String, Class<? extends A>> getClasses(); - -} Deleted: trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/ActionProviderFromProperties.java =================================================================== --- trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/ActionProviderFromProperties.java 2008-07-24 14:08:09 UTC (rev 775) +++ trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/ActionProviderFromProperties.java 2008-07-24 14:10:12 UTC (rev 776) @@ -1,85 +0,0 @@ -/** - * # #% Copyright (C) 2008 Code Lutin, Tony Chemit - * 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. - * # #% - */ -package org.codelutin.jaxx.action; - -import static org.codelutin.i18n.I18n._; - -import java.io.IOException; -import java.io.InputStream; -import java.util.Map; -import java.util.Properties; -import java.util.TreeMap; - -/** @author chemit */ -public class ActionProviderFromProperties<A extends MyAbstractAction> extends AbstractActionProvider<A> { - - /** default prefix for an entryin mapping file. */ - protected static final String ACTION_KEY_PREFIX = "action."; - - protected String propertiesPath; - - protected ActionProviderFromProperties(String name, Class<A> baseClass, String propertiesPath) { - super(name, baseClass, false); - this.propertiesPath = propertiesPath; - this.actions = initCache(); - } - - @SuppressWarnings({"unchecked"}) - protected Map<String, Class<? extends A>> initCache() { - - InputStream inputStream = null; - - Properties properties = new Properties(); - - try { - inputStream = getClass().getResourceAsStream(propertiesPath); - if (inputStream == null) { - throw new NullPointerException("could not find action file " + propertiesPath); - } - log.info("load " + propertiesPath); - properties.load(inputStream); - } catch (IOException e) { - log.warn(_("jaxx.error.load.actions.file", e.getMessage())); - throw new RuntimeException(_("jaxx.error.load.actions.file", e.getMessage())); - } finally { - if (inputStream != null) { - try { - inputStream.close(); - } catch (IOException e) { - log.warn(_("jaxx.error.close.actions.file", e.getMessage())); - //throw new RuntimeException(_("jaxx.error.load.actions.file", e.getMessage())); - } - } - } - - Map<String, Class<? extends A>> cache = new TreeMap<String, Class<? extends A>>(); - int prefix = ACTION_KEY_PREFIX.length(); - for (Map.Entry<Object, Object> entry : properties.entrySet()) { - String key = entry.getKey() + ""; - String qfn = entry.getValue() + ""; - try { - Class<? extends A> implCass; - implCass = (Class<? extends A>) Class.forName(qfn); - String actionKey = key.substring(prefix); - log.debug("found action <" + actionKey + " : " + implCass + ">"); - cache.put(actionKey, implCass); - } catch (ClassNotFoundException e) { - throw new RuntimeException(_("jaxx.error.load.actions.class", key, qfn), e); - } - } - - return cache; - } -} Copied: trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/provider/AbstractActionProvider.java (from rev 771, trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/AbstractActionProvider.java) =================================================================== --- trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/provider/AbstractActionProvider.java (rev 0) +++ trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/provider/AbstractActionProvider.java 2008-07-24 14:10:12 UTC (rev 776) @@ -0,0 +1,73 @@ +/** + * # #% Copyright (C) 2008 Code Lutin, Tony Chemit + * 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. + * # #% + */ +package org.codelutin.jaxx.action.provider; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.codelutin.jaxx.action.MyAbstractAction; + +import java.util.Map; + +/** @author chemit */ +public abstract class AbstractActionProvider<A extends MyAbstractAction> implements ActionProvider<A> { + + protected static Log log = LogFactory.getLog(AbstractActionProvider.class); + + protected String name; + + protected Class<A> baseClass; + + protected Map<String, Class<? extends A>> actions; + + protected abstract Map<String, Class<? extends A>> initCache(); + + protected AbstractActionProvider(String name, Class<A> baseClass, boolean doInitCache) { + this.name = name; + this.baseClass = baseClass; + if (doInitCache) { + this.actions = initCache(); + } + } + + public String getName() { + return name; + } + + public Class<A> getBaseClass() { + return baseClass; + } + + public Map<String, Class<? extends A>> getClasses() { + return actions; + } + + @Override + public String toString() { + return super.toString() + "<name:" + name + ", baseClass:" + baseClass.getSimpleName() + ">"; + } + + protected void clearCache() { + if (actions != null) { + actions.clear(); + actions = null; + } + } + + @Override + protected void finalize() throws Throwable { + super.finalize(); + clearCache(); + } +} Copied: trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/provider/ActionProvider.java (from rev 775, trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/ActionProvider.java) =================================================================== --- trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/provider/ActionProvider.java (rev 0) +++ trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/provider/ActionProvider.java 2008-07-24 14:10:12 UTC (rev 776) @@ -0,0 +1,35 @@ +/** + * # #% Copyright (C) 2008 Code Lutin, Tony Chemit + * 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. + * # #% + */ +package org.codelutin.jaxx.action.provider; + +import org.codelutin.jaxx.action.MyAbstractAction; + +/** + * Contract to be realized by a provider of Actions + * + * @author chemit + */ +public interface ActionProvider<A extends MyAbstractAction> { + + /** @return the name of the provider */ + String getName(); + + /** @return the base classe of provided actions */ + Class<A> getBaseClass(); + + /** @return the provided actions classes */ + java.util.Map<String, Class<? extends A>> getClasses(); + +} Copied: trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/provider/ActionProviderFromProperties.java (from rev 775, trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/ActionProviderFromProperties.java) =================================================================== --- trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/provider/ActionProviderFromProperties.java (rev 0) +++ trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/provider/ActionProviderFromProperties.java 2008-07-24 14:10:12 UTC (rev 776) @@ -0,0 +1,86 @@ +/** + * # #% Copyright (C) 2008 Code Lutin, Tony Chemit + * 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. + * # #% + */ +package org.codelutin.jaxx.action.provider; + +import static org.codelutin.i18n.I18n._; +import org.codelutin.jaxx.action.MyAbstractAction; + +import java.io.IOException; +import java.io.InputStream; +import java.util.Map; +import java.util.Properties; +import java.util.TreeMap; + +/** @author chemit */ +public class ActionProviderFromProperties<A extends MyAbstractAction> extends AbstractActionProvider<A> { + + /** default prefix for an entryin mapping file. */ + protected static final String ACTION_KEY_PREFIX = "action."; + + protected String propertiesPath; + + protected ActionProviderFromProperties(String name, Class<A> baseClass, String propertiesPath) { + super(name, baseClass, false); + this.propertiesPath = propertiesPath; + this.actions = initCache(); + } + + @SuppressWarnings({"unchecked"}) + protected Map<String, Class<? extends A>> initCache() { + + InputStream inputStream = null; + + Properties properties = new Properties(); + + try { + inputStream = getClass().getResourceAsStream(propertiesPath); + if (inputStream == null) { + throw new NullPointerException("could not find action file " + propertiesPath); + } + log.info("load " + propertiesPath); + properties.load(inputStream); + } catch (IOException e) { + log.warn(_("jaxx.error.load.actions.file", e.getMessage())); + throw new RuntimeException(_("jaxx.error.load.actions.file", e.getMessage())); + } finally { + if (inputStream != null) { + try { + inputStream.close(); + } catch (IOException e) { + log.warn(_("jaxx.error.close.actions.file", e.getMessage())); + //throw new RuntimeException(_("jaxx.error.load.actions.file", e.getMessage())); + } + } + } + + Map<String, Class<? extends A>> cache = new TreeMap<String, Class<? extends A>>(); + int prefix = ACTION_KEY_PREFIX.length(); + for (Map.Entry<Object, Object> entry : properties.entrySet()) { + String key = entry.getKey() + ""; + String qfn = entry.getValue() + ""; + try { + Class<? extends A> implCass; + implCass = (Class<? extends A>) Class.forName(qfn); + String actionKey = key.substring(prefix); + log.debug("found action <" + actionKey + " : " + implCass + ">"); + cache.put(actionKey, implCass); + } catch (ClassNotFoundException e) { + throw new RuntimeException(_("jaxx.error.load.actions.class", key, qfn), e); + } + } + + return cache; + } +} Modified: trunk/lutinjaxx/maven/src/main/java/org/codelutin/jaxx/ActionProviderGeneratorMojo.java =================================================================== --- trunk/lutinjaxx/maven/src/main/java/org/codelutin/jaxx/ActionProviderGeneratorMojo.java 2008-07-24 14:08:09 UTC (rev 775) +++ trunk/lutinjaxx/maven/src/main/java/org/codelutin/jaxx/ActionProviderGeneratorMojo.java 2008-07-24 14:10:12 UTC (rev 776) @@ -19,14 +19,14 @@ package org.codelutin.jaxx; -import org.codelutin.jaxx.action.ActionProvider; +import org.codelutin.jaxx.action.provider.ActionProvider; import org.codelutin.util.FileUtil; import java.io.File; import java.io.IOException; /** - * Classe permettant de generer un {@link org.codelutin.jaxx.action.ActionProvider} et son fichier de d�claration. + * Classe permettant de generer un {@link org.codelutin.jaxx.action.provider.ActionProvider} et son fichier de d�claration. * * @author chemit * @goal generate-actions-provider @@ -66,7 +66,7 @@ protected static final String PROVIDER_TEMPLATE = "package %1$s;\n" + "\n" + - "public class %2$s extends org.codelutin.jaxx.action.ActionProviderFromProperties<%3$s> {\n" + + "public class %2$s extends org.codelutin.jaxx.action.provider.ActionProviderFromProperties<%3$s> {\n" + "\n" + " public %2$s() {\n" + " super(\"%5$s\", %3$s.class, \"%4$s\");\n" +
participants (1)
-
tchemit@users.labs.libre-entreprise.org