Author: glandais Date: 2008-03-07 17:57:20 +0000 (Fri, 07 Mar 2008) New Revision: 1303 Added: trunk/simexplorer-is/simexplorer-is-entities/src/java/fr/cemagref/simexplorer/is/entities/Composite.java trunk/simexplorer-is/simexplorer-is-entities/src/java/fr/cemagref/simexplorer/is/entities/Entity.java trunk/simexplorer-is/simexplorer-is-entities/src/java/fr/cemagref/simexplorer/is/entities/EntityHelper.java trunk/simexplorer-is/simexplorer-is-entities/src/java/fr/cemagref/simexplorer/is/entities/EntityTypeEnum.java trunk/simexplorer-is/simexplorer-is-entities/src/java/fr/cemagref/simexplorer/is/entities/Leaf.java trunk/simexplorer-is/simexplorer-is-entities/src/java/fr/cemagref/simexplorer/is/entities/SimpleComposite.java trunk/simexplorer-is/simexplorer-is-storage/src/java/fr/cemagref/simexplorer/is/factories/EntityFactory.java Removed: trunk/simexplorer-is/simexplorer-is-entities/src/java/fr/cemagref/simexplorer/is/entities/BaseEntity.java trunk/simexplorer-is/simexplorer-is-entities/src/java/fr/cemagref/simexplorer/is/entities/EntityHelper.java trunk/simexplorer-is/simexplorer-is-entities/src/java/fr/cemagref/simexplorer/is/entities/EntityTypeEnum.java trunk/simexplorer-is/simexplorer-is-entities/src/java/fr/cemagref/simexplorer/is/entities/SimpleEntityVisitor.java trunk/simexplorer-is/simexplorer-is-entities/src/java/fr/cemagref/simexplorer/is/entities/data/DataEntity.java trunk/simexplorer-is/simexplorer-is-storage/src/java/fr/cemagref/simexplorer/is/factories/BaseEntityFactory.java trunk/simexplorer-is/simexplorer-is-storage/src/java/fr/cemagref/simexplorer/is/factories/MetaDataFactory.java Modified: trunk/simexplorer-is/simexplorer-is-entities/src/java/fr/cemagref/simexplorer/is/entities/EntityVisitable.java trunk/simexplorer-is/simexplorer-is-entities/src/java/fr/cemagref/simexplorer/is/entities/EntityVisitor.java trunk/simexplorer-is/simexplorer-is-entities/src/java/fr/cemagref/simexplorer/is/entities/attachment/Attachment.java trunk/simexplorer-is/simexplorer-is-entities/src/java/fr/cemagref/simexplorer/is/entities/data/Code.java trunk/simexplorer-is/simexplorer-is-entities/src/java/fr/cemagref/simexplorer/is/entities/data/Component.java trunk/simexplorer-is/simexplorer-is-entities/src/java/fr/cemagref/simexplorer/is/entities/data/Constant.java trunk/simexplorer-is/simexplorer-is-entities/src/java/fr/cemagref/simexplorer/is/entities/data/ConstantValue.java trunk/simexplorer-is/simexplorer-is-entities/src/java/fr/cemagref/simexplorer/is/entities/data/Descriptor.java trunk/simexplorer-is/simexplorer-is-entities/src/java/fr/cemagref/simexplorer/is/entities/data/ExplorationApplication.java trunk/simexplorer-is/simexplorer-is-entities/src/java/fr/cemagref/simexplorer/is/entities/data/ExplorationData.java trunk/simexplorer-is/simexplorer-is-entities/src/java/fr/cemagref/simexplorer/is/entities/data/Library.java trunk/simexplorer-is/simexplorer-is-entities/src/java/fr/cemagref/simexplorer/is/entities/data/LoggableElement.java trunk/simexplorer-is/simexplorer-is-entities/src/java/fr/cemagref/simexplorer/is/entities/data/Repository.java trunk/simexplorer-is/simexplorer-is-entities/src/java/fr/cemagref/simexplorer/is/entities/data/Result.java trunk/simexplorer-is/simexplorer-is-entities/src/java/fr/cemagref/simexplorer/is/entities/data/Structure.java trunk/simexplorer-is/simexplorer-is-entities/src/java/fr/cemagref/simexplorer/is/entities/metadata/MetaData.java trunk/simexplorer-is/simexplorer-is-service/src/java/fr/cemagref/simexplorer/is/service/MockDatabase.java trunk/simexplorer-is/simexplorer-is-service/src/java/fr/cemagref/simexplorer/is/service/StorageServiceCommon.java trunk/simexplorer-is/simexplorer-is-service/src/java/fr/cemagref/simexplorer/is/service/StorageServiceGenerator.java trunk/simexplorer-is/simexplorer-is-storage/src/java/fr/cemagref/simexplorer/is/factories/LoggableElementFactory.java trunk/simexplorer-is/simexplorer-is-storage/src/java/fr/cemagref/simexplorer/is/storage/ElementGenerator.java trunk/simexplorer-is/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/actions/ExportElementAction.java trunk/simexplorer-is/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/model/DataEntityModel.java trunk/simexplorer-is/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/ui/EntityTreeNodeHelper.java trunk/simexplorer-is/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/ui/ListTabUpdater.java trunk/simexplorer-is/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/ui/SimExplorerMainUI.java trunk/simexplorer-is/simexplorer-is-web/src/java/fr/cemagref/simexplorer/is/ui/web/pages/ElementDetail.java trunk/simexplorer-is/simexplorer-is-web/src/java/fr/cemagref/simexplorer/is/ui/web/pages/ElementDownload.java Log: Hierarchical Visitor Pattern for entities Swing UI adapted Deleted: trunk/simexplorer-is/simexplorer-is-entities/src/java/fr/cemagref/simexplorer/is/entities/BaseEntity.java =================================================================== --- trunk/simexplorer-is/simexplorer-is-entities/src/java/fr/cemagref/simexplorer/is/entities/BaseEntity.java 2008-03-06 21:49:51 UTC (rev 1302) +++ trunk/simexplorer-is/simexplorer-is-entities/src/java/fr/cemagref/simexplorer/is/entities/BaseEntity.java 2008-03-07 17:57:20 UTC (rev 1303) @@ -1,35 +0,0 @@ -/* -* ##% Copyright (C) 2008 Code Lutin, Gabriel Landais -* -* 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 fr.cemagref.simexplorer.is.entities; - -import java.io.Serializable; - -/** - * The minimal Entity contract. - * <p/> - * This is a <code>marker</code> interface, nothing special to describe for this - * contract. - * <p/> - * An Entity is serializable and visitable. - * - * @author glandais - * @see Serializable - * @see EntityVisitable - */ -public interface BaseEntity extends Serializable, EntityVisitable { -} Added: trunk/simexplorer-is/simexplorer-is-entities/src/java/fr/cemagref/simexplorer/is/entities/Composite.java =================================================================== --- trunk/simexplorer-is/simexplorer-is-entities/src/java/fr/cemagref/simexplorer/is/entities/Composite.java (rev 0) +++ trunk/simexplorer-is/simexplorer-is-entities/src/java/fr/cemagref/simexplorer/is/entities/Composite.java 2008-03-07 17:57:20 UTC (rev 1303) @@ -0,0 +1,64 @@ +/* +* ##% Copyright (C) 2008 Code Lutin, Gabriel Landais +* +* 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 fr.cemagref.simexplorer.is.entities; + +import java.util.List; + +/** + * The Class Composite. This class aims to be a node with children + */ +public abstract class Composite implements Entity { + + /** + * Visit enter. + * + * @param visitor the visitor + * + * @return true, if successful + */ + protected boolean visitEnter(EntityVisitor visitor) { + visitor.enterComposite(this); + return true; + } + + /** + * Visit leave. + * + * @param visitor the visitor + * + */ + protected void visitLeave(EntityVisitor visitor) { + visitor.exitComposite(this); + // do nothing + } + + /* (non-Javadoc) + * @see fr.cemagref.simexplorer.is.entities.EntityVisitable#accept(fr.cemagref.simexplorer.is.entities.EntityVisitor) + */ + @Override + public void accept(EntityVisitor visitor) { + if (visitEnter(visitor)) { + List<Entity> children = getChildren(); + for (Entity entity : children) { + entity.accept(visitor); + } + visitLeave(visitor); + } + } + +} Added: trunk/simexplorer-is/simexplorer-is-entities/src/java/fr/cemagref/simexplorer/is/entities/Entity.java =================================================================== --- trunk/simexplorer-is/simexplorer-is-entities/src/java/fr/cemagref/simexplorer/is/entities/Entity.java (rev 0) +++ trunk/simexplorer-is/simexplorer-is-entities/src/java/fr/cemagref/simexplorer/is/entities/Entity.java 2008-03-07 17:57:20 UTC (rev 1303) @@ -0,0 +1,40 @@ +/* +* ##% Copyright (C) 2008 Code Lutin, Gabriel Landais +* +* 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 fr.cemagref.simexplorer.is.entities; + +import java.io.Serializable; +import java.util.List; + +/** + * The minimal Entity contract. + * <p/> + * This is a <code>marker</code> interface, nothing special to describe for this + * contract. + * <p/> + * An Entity is serializable and visitable. + */ +public interface Entity extends Serializable, EntityVisitable { + + /** + * Gets the children. + * + * @return the children + */ + public List<Entity> getChildren(); + +} Deleted: trunk/simexplorer-is/simexplorer-is-entities/src/java/fr/cemagref/simexplorer/is/entities/EntityHelper.java =================================================================== --- trunk/simexplorer-is/simexplorer-is-entities/src/java/fr/cemagref/simexplorer/is/entities/EntityHelper.java 2008-03-06 21:49:51 UTC (rev 1302) +++ trunk/simexplorer-is/simexplorer-is-entities/src/java/fr/cemagref/simexplorer/is/entities/EntityHelper.java 2008-03-07 17:57:20 UTC (rev 1303) @@ -1,89 +0,0 @@ -/* -* ##% Copyright (C) 2007, 2008 Code Lutin, Tony Chemit, Gabriel Landais -* -* 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 fr.cemagref.simexplorer.is.entities; - - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; - -import javax.swing.tree.DefaultMutableTreeNode; - -import fr.cemagref.simexplorer.is.entities.data.ExplorationApplication; -import fr.cemagref.simexplorer.is.entities.data.ExplorationData; -import fr.cemagref.simexplorer.is.entities.data.Library; -import fr.cemagref.simexplorer.is.entities.data.LoggableElement; -import fr.cemagref.simexplorer.is.entities.data.Result; -import fr.cemagref.simexplorer.is.entities.metadata.MetaData; - -/** - * Une classe utilitaires pour les Entities du projet. - * - * @author chemit - */ -public class EntityHelper { - /** - * Une énumération pour définir les types des entités du - * projet. - * - * @author chemit - */ - public static enum Action { - - DOWNLOAD(ExplorationApplication.class, Result.class, Library.class), - EXPORT(ExplorationApplication.class, Result.class, Library.class), - IMPORT(ExplorationApplication.class, Library.class), - DELETE(ExplorationApplication.class, ExplorationData.class); - - private List<Class<?>> classes; - private List<String> types; - - public boolean accept(DefaultMutableTreeNode node) { - return node != null && node.getUserObject() != null && - accept(node.getUserObject().getClass()); - } - - public boolean accept(LoggableElement sNode) { - return sNode != null && accept(sNode.getClass()); - } - - public boolean accept(MetaData metaData) { - return metaData != null && accept(metaData.getElementClass()); - } - - private Action(Class<?>... classes) { - this.classes = Arrays.asList(classes); - this.types = new ArrayList<String>(classes.length); - for (Class<?> aClass : classes) { - this.types.add(aClass.getSimpleName()); - } - } - - private boolean accept(Class<?> klass) { - return classes.contains(klass); - } - - private boolean accept(String type) { - return types.contains(type); - } - } - - protected EntityHelper() { - // no instance - } -} Added: trunk/simexplorer-is/simexplorer-is-entities/src/java/fr/cemagref/simexplorer/is/entities/EntityHelper.java =================================================================== --- trunk/simexplorer-is/simexplorer-is-entities/src/java/fr/cemagref/simexplorer/is/entities/EntityHelper.java (rev 0) +++ trunk/simexplorer-is/simexplorer-is-entities/src/java/fr/cemagref/simexplorer/is/entities/EntityHelper.java 2008-03-07 17:57:20 UTC (rev 1303) @@ -0,0 +1,89 @@ +/* +* ##% Copyright (C) 2007, 2008 Code Lutin, Tony Chemit, Gabriel Landais +* +* 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 fr.cemagref.simexplorer.is.entities; + + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +import javax.swing.tree.DefaultMutableTreeNode; + +import fr.cemagref.simexplorer.is.entities.data.ExplorationApplication; +import fr.cemagref.simexplorer.is.entities.data.ExplorationData; +import fr.cemagref.simexplorer.is.entities.data.Library; +import fr.cemagref.simexplorer.is.entities.data.LoggableElement; +import fr.cemagref.simexplorer.is.entities.data.Result; +import fr.cemagref.simexplorer.is.entities.metadata.MetaData; + +/** + * Une classe utilitaires pour les Entities du projet. + * + * @author chemit + */ +public class EntityHelper { + /** + * Une énumération pour définir les types des entités du + * projet. + * + * @author chemit + */ + public static enum Action { + + DOWNLOAD(ExplorationApplication.class, Result.class, Library.class), + EXPORT(ExplorationApplication.class, Result.class, Library.class), + IMPORT(ExplorationApplication.class, Library.class), + DELETE(ExplorationApplication.class, ExplorationData.class); + + private List<Class<?>> classes; + private List<String> types; + + public boolean accept(DefaultMutableTreeNode node) { + return node != null && node.getUserObject() != null && + accept(node.getUserObject().getClass()); + } + + public boolean accept(LoggableElement sNode) { + return sNode != null && accept(sNode.getClass()); + } + + public boolean accept(MetaData metaData) { + return metaData != null && accept(metaData.getElementClass()); + } + + private Action(Class<?>... classes) { + this.classes = Arrays.asList(classes); + this.types = new ArrayList<String>(classes.length); + for (Class<?> aClass : classes) { + this.types.add(aClass.getSimpleName()); + } + } + + private boolean accept(Class<?> klass) { + return classes.contains(klass); + } + + private boolean accept(String type) { + return types.contains(type); + } + } + + protected EntityHelper() { + // no instance + } +} Deleted: trunk/simexplorer-is/simexplorer-is-entities/src/java/fr/cemagref/simexplorer/is/entities/EntityTypeEnum.java =================================================================== --- trunk/simexplorer-is/simexplorer-is-entities/src/java/fr/cemagref/simexplorer/is/entities/EntityTypeEnum.java 2008-03-06 21:49:51 UTC (rev 1302) +++ trunk/simexplorer-is/simexplorer-is-entities/src/java/fr/cemagref/simexplorer/is/entities/EntityTypeEnum.java 2008-03-07 17:57:20 UTC (rev 1303) @@ -1,170 +0,0 @@ -package fr.cemagref.simexplorer.is.entities; - -import static org.codelutin.i18n.I18n.n_; -import static org.codelutin.i18n.I18n._; -import fr.cemagref.simexplorer.is.entities.attachment.Attachment; -import fr.cemagref.simexplorer.is.entities.data.Code; -import fr.cemagref.simexplorer.is.entities.data.Component; -import fr.cemagref.simexplorer.is.entities.data.Constant; -import fr.cemagref.simexplorer.is.entities.data.ConstantValue; -import fr.cemagref.simexplorer.is.entities.data.ExplorationApplication; -import fr.cemagref.simexplorer.is.entities.data.ExplorationData; -import fr.cemagref.simexplorer.is.entities.data.Library; -import fr.cemagref.simexplorer.is.entities.data.Repository; -import fr.cemagref.simexplorer.is.entities.data.Result; -import fr.cemagref.simexplorer.is.entities.data.Structure; - -/** - * Une enum pour definir les differents types d'entities rencontres dans le projet. <p/> On ajoute ici une clef i18n - * pour pouvoir traduire plus tard ces types. <p/> Note: on n'utilise pas directement les traductions pour permettre le - * mécanisme de changement de langue (voir module swing et web). - * - * @author chemit - */ -public enum EntityTypeEnum { - - /** The Attachment. */ - Attachment(false, n_("simexplorer.common.attachment"), n_("simexplorer.common.attachments"), Attachment.class), - - /** The Code. */ - Code(false, n_("simexplorer.common.code"), n_("simexplorer.common.codes"), Code.class), - - /** The Component. */ - Component(true, n_("simexplorer.common.component"), n_("simexplorer.common.components"), Component.class), - - /** The Constant. */ - Constant(false, n_("simexplorer.common.constant"), n_("simexplorer.common.constants"), Constant.class), - - /** The Constant value. */ - ConstantValue(false, n_("simexplorer.common.constantvalue"), n_("simexplorer.common.constantvalues"), ConstantValue.class), - - /** The Exploration application. */ - ExplorationApplication(true, n_("simexplorer.common.explorationapplication"), n_("simexplorer.common.explorationapplications"), ExplorationApplication.class), - - /** The Exploration data. */ - ExplorationData(true, n_("simexplorer.common.explorationdata"), n_("simexplorer.common.explorationdatas"), ExplorationData.class), - - /** The Library. */ - Library(true, n_("simexplorer.common.library"), n_("simexplorer.common.libraries"), Library.class), - - /** The Repository. */ - Repository(false, n_("simexplorer.common.repository"), n_("simexplorer.common.repositories"), Repository.class), - - /** The Result. */ - Result(false, n_("simexplorer.common.result"), n_("simexplorer.common.results"), Result.class), - - /** The Structure. */ - Structure(false, n_("simexplorer.common.structure"), n_("simexplorer.common.structures"), Structure.class); - - /** The le. */ - private boolean le; - - /** The i18n key. */ - private String i18nKey; - - /** The i18n keys. */ - private String i18nKeys; - - /** The implementation. */ - private Class<?> implementation; - - /** - * Gets the entity type. - * - * @param klass the klass - * - * @return the entity type - */ - public static EntityTypeEnum getEntityType(Class<?> klass) { - EntityTypeEnum[] values = values(); - for (EntityTypeEnum value : values) { - if (klass.equals(value.getImplementation())) { - return value; - } - } - return null; - } - - /** - * Gets the libelle. - * - * @param entity the entity - * - * @return the libelle - */ - public static String getLibelle(Object entity) { - if (entity == null) { - return ""; - } - return getLibelle(entity instanceof Class ? (Class<?>) entity : entity.getClass()); - } - - /** - * Gets the libelle. - * - * @param entity the entity - * - * @return the libelle - */ - private static String getLibelle(Class<?> entity) { - if (entity == null) { - return ""; - } - EntityTypeEnum entityType = getEntityType(entity); - if (entityType == null) { - return ""; - } - return entityType.getLibelle(); - } - - /** - * Gets the libelle. - * - * @return the libelle - */ - public String getLibelle() { - return _(i18nKey); - } - - /** - * Gets the libelles. - * - * @return the libelles - */ - public String getLibelles() { - return _(i18nKeys); - } - - /** - * Checks if is le. - * - * @return true, if is le - */ - public boolean isLe() { - return le; - } - - /** - * Gets the implementation. - * - * @return the implementation - */ - public Class<?> getImplementation() { - return implementation; - } - - /** - * Instantiates a new entity type enum. - * - * @param isLE the is le - * @param i18nKey the i18n key - * @param i18nKeys the i18n keys - * @param implementation the implementation - */ - private EntityTypeEnum(boolean isLE, String i18nKey, String i18nKeys, Class<?> implementation) { - this.le = isLE; - this.i18nKey = i18nKey; - this.i18nKeys = i18nKeys; - this.implementation = implementation; - } -} \ No newline at end of file Added: trunk/simexplorer-is/simexplorer-is-entities/src/java/fr/cemagref/simexplorer/is/entities/EntityTypeEnum.java =================================================================== --- trunk/simexplorer-is/simexplorer-is-entities/src/java/fr/cemagref/simexplorer/is/entities/EntityTypeEnum.java (rev 0) +++ trunk/simexplorer-is/simexplorer-is-entities/src/java/fr/cemagref/simexplorer/is/entities/EntityTypeEnum.java 2008-03-07 17:57:20 UTC (rev 1303) @@ -0,0 +1,170 @@ +package fr.cemagref.simexplorer.is.entities; + +import static org.codelutin.i18n.I18n.n_; +import static org.codelutin.i18n.I18n._; +import fr.cemagref.simexplorer.is.entities.attachment.Attachment; +import fr.cemagref.simexplorer.is.entities.data.Code; +import fr.cemagref.simexplorer.is.entities.data.Component; +import fr.cemagref.simexplorer.is.entities.data.Constant; +import fr.cemagref.simexplorer.is.entities.data.ConstantValue; +import fr.cemagref.simexplorer.is.entities.data.ExplorationApplication; +import fr.cemagref.simexplorer.is.entities.data.ExplorationData; +import fr.cemagref.simexplorer.is.entities.data.Library; +import fr.cemagref.simexplorer.is.entities.data.Repository; +import fr.cemagref.simexplorer.is.entities.data.Result; +import fr.cemagref.simexplorer.is.entities.data.Structure; + +/** + * Une enum pour definir les differents types d'entities rencontres dans le projet. <p/> On ajoute ici une clef i18n + * pour pouvoir traduire plus tard ces types. <p/> Note: on n'utilise pas directement les traductions pour permettre le + * mécanisme de changement de langue (voir module swing et web). + * + * @author chemit + */ +public enum EntityTypeEnum { + + /** The Attachment. */ + Attachment(false, n_("simexplorer.common.attachment"), n_("simexplorer.common.attachments"), Attachment.class), + + /** The Code. */ + Code(false, n_("simexplorer.common.code"), n_("simexplorer.common.codes"), Code.class), + + /** The Component. */ + Component(true, n_("simexplorer.common.component"), n_("simexplorer.common.components"), Component.class), + + /** The Constant. */ + Constant(false, n_("simexplorer.common.constant"), n_("simexplorer.common.constants"), Constant.class), + + /** The Constant value. */ + ConstantValue(false, n_("simexplorer.common.constantvalue"), n_("simexplorer.common.constantvalues"), ConstantValue.class), + + /** The Exploration application. */ + ExplorationApplication(true, n_("simexplorer.common.explorationapplication"), n_("simexplorer.common.explorationapplications"), ExplorationApplication.class), + + /** The Exploration data. */ + ExplorationData(true, n_("simexplorer.common.explorationdata"), n_("simexplorer.common.explorationdatas"), ExplorationData.class), + + /** The Library. */ + Library(true, n_("simexplorer.common.library"), n_("simexplorer.common.libraries"), Library.class), + + /** The Repository. */ + Repository(false, n_("simexplorer.common.repository"), n_("simexplorer.common.repositories"), Repository.class), + + /** The Result. */ + Result(false, n_("simexplorer.common.result"), n_("simexplorer.common.results"), Result.class), + + /** The Structure. */ + Structure(false, n_("simexplorer.common.structure"), n_("simexplorer.common.structures"), Structure.class); + + /** The le. */ + private boolean le; + + /** The i18n key. */ + private String i18nKey; + + /** The i18n keys. */ + private String i18nKeys; + + /** The implementation. */ + private Class<?> implementation; + + /** + * Gets the entity type. + * + * @param klass the klass + * + * @return the entity type + */ + public static EntityTypeEnum getEntityType(Class<?> klass) { + EntityTypeEnum[] values = values(); + for (EntityTypeEnum value : values) { + if (klass.equals(value.getImplementation())) { + return value; + } + } + return null; + } + + /** + * Gets the libelle. + * + * @param entity the entity + * + * @return the libelle + */ + public static String getLibelle(Object entity) { + if (entity == null) { + return ""; + } + return getLibelle(entity instanceof Class ? (Class<?>) entity : entity.getClass()); + } + + /** + * Gets the libelle. + * + * @param entity the entity + * + * @return the libelle + */ + private static String getLibelle(Class<?> entity) { + if (entity == null) { + return ""; + } + EntityTypeEnum entityType = getEntityType(entity); + if (entityType == null) { + return ""; + } + return entityType.getLibelle(); + } + + /** + * Gets the libelle. + * + * @return the libelle + */ + public String getLibelle() { + return _(i18nKey); + } + + /** + * Gets the libelles. + * + * @return the libelles + */ + public String getLibelles() { + return _(i18nKeys); + } + + /** + * Checks if is le. + * + * @return true, if is le + */ + public boolean isLe() { + return le; + } + + /** + * Gets the implementation. + * + * @return the implementation + */ + public Class<?> getImplementation() { + return implementation; + } + + /** + * Instantiates a new entity type enum. + * + * @param isLE the is le + * @param i18nKey the i18n key + * @param i18nKeys the i18n keys + * @param implementation the implementation + */ + private EntityTypeEnum(boolean isLE, String i18nKey, String i18nKeys, Class<?> implementation) { + this.le = isLE; + this.i18nKey = i18nKey; + this.i18nKeys = i18nKeys; + this.implementation = implementation; + } +} \ No newline at end of file Modified: trunk/simexplorer-is/simexplorer-is-entities/src/java/fr/cemagref/simexplorer/is/entities/EntityVisitable.java =================================================================== --- trunk/simexplorer-is/simexplorer-is-entities/src/java/fr/cemagref/simexplorer/is/entities/EntityVisitable.java 2008-03-06 21:49:51 UTC (rev 1302) +++ trunk/simexplorer-is/simexplorer-is-entities/src/java/fr/cemagref/simexplorer/is/entities/EntityVisitable.java 2008-03-07 17:57:20 UTC (rev 1303) @@ -25,11 +25,13 @@ * @see EntityVisitor */ public interface EntityVisitable { + /** - * Méthode à implanter dans chaque visitable pour indiquer ce que - * le visiteur doit visiter. - * + * Méthode à implanter dans chaque visitable pour indiquer ce que le visiteur doit visiter. + * * @param visitor le visiteur + * + * @return true, if accept */ void accept(EntityVisitor visitor); Modified: trunk/simexplorer-is/simexplorer-is-entities/src/java/fr/cemagref/simexplorer/is/entities/EntityVisitor.java =================================================================== --- trunk/simexplorer-is/simexplorer-is-entities/src/java/fr/cemagref/simexplorer/is/entities/EntityVisitor.java 2008-03-06 21:49:51 UTC (rev 1302) +++ trunk/simexplorer-is/simexplorer-is-entities/src/java/fr/cemagref/simexplorer/is/entities/EntityVisitor.java 2008-03-07 17:57:20 UTC (rev 1303) @@ -17,24 +17,10 @@ * ##% */ package fr.cemagref.simexplorer.is.entities; -import fr.cemagref.simexplorer.is.entities.attachment.Attachment; -import fr.cemagref.simexplorer.is.entities.data.Code; -import fr.cemagref.simexplorer.is.entities.data.Component; -import fr.cemagref.simexplorer.is.entities.data.Constant; -import fr.cemagref.simexplorer.is.entities.data.ConstantValue; -import fr.cemagref.simexplorer.is.entities.data.ExplorationApplication; -import fr.cemagref.simexplorer.is.entities.data.ExplorationData; -import fr.cemagref.simexplorer.is.entities.data.Library; -import fr.cemagref.simexplorer.is.entities.data.Repository; -import fr.cemagref.simexplorer.is.entities.data.Result; -import fr.cemagref.simexplorer.is.entities.data.Structure; -import fr.cemagref.simexplorer.is.entities.metadata.MetaData; -import java.util.Collection; - /** * Le contrat à respecter pour un visiteur à visiter des {@link EntityVisitable}.. - * + * * @author chemit * @see EntityVisitable * @see SimpleEntityVisitor @@ -42,169 +28,41 @@ public interface EntityVisitor { /** - * La méthode de base pour visiter n'importe quel {@link EntityVisitable}. - * - * @param v le visité + * Visit. + * + * @param v the v + * */ void visit(EntityVisitable v); - + /** - * Pour visiter une exploration d'application - * - * @param v le visité - * @see ExplorationApplication + * Visit. + * + * @param v the v + * */ - void visitExplorationApplication(ExplorationApplication v); + void visitLeaf(Leaf v); /** - * Pour visiter un Component - * - * @param v le visité - * @see Component + * Visit. + * + * @param v the v + * */ - void visitComponent(Component v); + void visitComposite(Composite v); /** - * Pour visiter une ExplorationApplication - * - * @param v le visité - * @see ExplorationApplication + * Enter composite. + * + * @param v the v */ - void visitExplorationData(ExplorationData v); + void enterComposite(Composite v); /** - * Pour visiter un Library - * - * @param v le visité - * @see Library + * Exit composite. + * + * @param v the v */ - void visitLibrary(Library v); - - /** - * Pour visiter un Metadata - * - * @param v le visité - * @see MetaData - */ - void visitMetaData(MetaData v); - - /** - * Pour visiter un Result - * - * @param v le visité - * @see Result - */ - void visitResult(Result v); - - /** - * Pour visiter un Constant - * - * @param vs le visité - * @see Constant - */ - void visitConstant(Constant vs); - - /** - * Pour visiter un Code - * - * @param v le visité - * @see Code - */ - void visitCode(Code v); - - /** - * Pour visiter un Structure - * - * @param v le visité - * @see Structure - */ - void visitStructure(Structure v); - - /** - * Pour visiter un ConstantValue - * - * @param v le visité - * @see ConstantValue - */ - void visitConstantValue(ConstantValue v); - - /** - * Pour visiter un Attachment - * - * @param v le visité - * @see Attachment - */ - void visitAttachment(Attachment v); - - /** - * Pour visiter un Repository - * - * @param v le visité - * @see Repository - */ - void visitRepository(Repository v); - - /** - * Pour visiter une collection de Component - * - * @param vs les visités - * @see Component - */ - void visitComponents(Collection<Component> vs); - - /** - * Pour visiter une collection de ExplorationData - * - * @param vs les visités - * @see ExplorationData - */ - void visitExplorationDatas(Collection<ExplorationData> vs); - - /** - * Pour visiter une collection de Library - * - * @param vs les visités - * @see Library - */ - void visitLibraries(Collection<Library> vs); - - /** - * Pour visiter une collection de Constant - * - * @param vs les visités - * @see Constant - */ - void visitConstants(Collection<Constant> vs); - - /** - * Pour visiter une collection de Code - * - * @param vs les visités - * @see Code - */ - void visitCodes(Collection<Code> vs); - - /** - * Pour visiter une collection de Structure - * - * @param vs les visités - * @see Structure - */ - void visitStructures(Collection<Structure> vs); - - /** - * Pour visiter une collection de ConstantValue - * - * @param vs les visités - * @see ConstantValue - */ - void visitConstantValues(Collection<ConstantValue> vs); - - /** - * Pour visiter une collection de Attachment - * - * @param vs les visités - * @see Attachment - */ - void visitAttachments(Collection<Attachment> vs); + void exitComposite(Composite v); + } Added: trunk/simexplorer-is/simexplorer-is-entities/src/java/fr/cemagref/simexplorer/is/entities/Leaf.java =================================================================== --- trunk/simexplorer-is/simexplorer-is-entities/src/java/fr/cemagref/simexplorer/is/entities/Leaf.java (rev 0) +++ trunk/simexplorer-is/simexplorer-is-entities/src/java/fr/cemagref/simexplorer/is/entities/Leaf.java 2008-03-07 17:57:20 UTC (rev 1303) @@ -0,0 +1,37 @@ +/* +* ##% Copyright (C) 2008 Code Lutin, Gabriel Landais +* +* 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 fr.cemagref.simexplorer.is.entities; + +import java.util.ArrayList; +import java.util.List; + +/** + * The Class Leaf. + * This class represents a leaf of the tree + */ +public abstract class Leaf implements Entity { + + /* (non-Javadoc) + * @see fr.cemagref.simexplorer.is.entities.pattern.Entity#getChildren() + */ + @Override + public final List<Entity> getChildren() { + return new ArrayList<Entity>(); + } + +} Added: trunk/simexplorer-is/simexplorer-is-entities/src/java/fr/cemagref/simexplorer/is/entities/SimpleComposite.java =================================================================== --- trunk/simexplorer-is/simexplorer-is-entities/src/java/fr/cemagref/simexplorer/is/entities/SimpleComposite.java (rev 0) +++ trunk/simexplorer-is/simexplorer-is-entities/src/java/fr/cemagref/simexplorer/is/entities/SimpleComposite.java 2008-03-07 17:57:20 UTC (rev 1303) @@ -0,0 +1,119 @@ +/* +* ##% Copyright (C) 2008 Code Lutin, Gabriel Landais +* +* 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 fr.cemagref.simexplorer.is.entities; + +import java.util.ArrayList; +import java.util.List; + +/** + * The Class SimpleComposite. + */ +public class SimpleComposite<E extends Entity> extends Composite { + + /** The Constant serialVersionUID. */ + private static final long serialVersionUID = -2085840703844194573L; + + /** The children. */ + private List<E> elements; + + /** + * Cast list. + * + * @param list the list + * + * @return the simple composite< t> + */ + public static <T extends Entity> SimpleComposite<T> castList(List<T> list) { + SimpleComposite<T> result = new SimpleComposite<T>(); + result.setElements(list); + return result; + } + + /* (non-Javadoc) + * @see fr.cemagref.simexplorer.is.entities.Composite#visitEnter(fr.cemagref.simexplorer.is.entities.EntityVisitor) + */ + @Override + protected boolean visitEnter(EntityVisitor v) { + v.enterComposite(this); + return true; + } + + /* (non-Javadoc) + * @see fr.cemagref.simexplorer.is.entities.Composite#visitLeave(fr.cemagref.simexplorer.is.entities.EntityVisitor) + */ + @Override + protected void visitLeave(EntityVisitor v) { + v.exitComposite(this); + } + + /* (non-Javadoc) + * @see fr.cemagref.simexplorer.is.entities.Entity#getChildren() + */ + @Override + public List<Entity> getChildren() { + List<Entity> entities = new ArrayList<Entity>(); + entities.addAll(elements); + return entities; + } + + /** + * Gets the elements. + * + * @return the elements + */ + public List<E> getElements() { + return elements; + } + + /** + * Sets the elements. + * + * @param elements the new elements + */ + public void setElements(List<E> elements) { + this.elements = elements; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((elements == null) ? 0 : elements.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + final SimpleComposite other = (SimpleComposite) obj; + if (elements == null) { + if (other.elements != null) + return false; + } else if (!elements.equals(other.elements)) + return false; + return true; + } + + + +} Deleted: trunk/simexplorer-is/simexplorer-is-entities/src/java/fr/cemagref/simexplorer/is/entities/SimpleEntityVisitor.java =================================================================== --- trunk/simexplorer-is/simexplorer-is-entities/src/java/fr/cemagref/simexplorer/is/entities/SimpleEntityVisitor.java 2008-03-06 21:49:51 UTC (rev 1302) +++ trunk/simexplorer-is/simexplorer-is-entities/src/java/fr/cemagref/simexplorer/is/entities/SimpleEntityVisitor.java 2008-03-07 17:57:20 UTC (rev 1303) @@ -1,168 +0,0 @@ -/* -* ##% Copyright (C) 2007, 2008 Code Lutin, -* Tony Chemit, Gabriel Landais -* -* 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 fr.cemagref.simexplorer.is.entities; - -import fr.cemagref.simexplorer.is.entities.attachment.Attachment; -import fr.cemagref.simexplorer.is.entities.data.Code; -import fr.cemagref.simexplorer.is.entities.data.Component; -import fr.cemagref.simexplorer.is.entities.data.Constant; -import fr.cemagref.simexplorer.is.entities.data.ConstantValue; -import fr.cemagref.simexplorer.is.entities.data.ExplorationApplication; -import fr.cemagref.simexplorer.is.entities.data.ExplorationData; -import fr.cemagref.simexplorer.is.entities.data.Library; -import fr.cemagref.simexplorer.is.entities.data.Repository; -import fr.cemagref.simexplorer.is.entities.data.Result; -import fr.cemagref.simexplorer.is.entities.data.Structure; -import fr.cemagref.simexplorer.is.entities.metadata.MetaData; - -import java.util.Collection; - -/** - * Un simple visiteur de BaseEntity. - * - * @author chemit - * @see EntityVisitor - * @see EntityVisitable - * @see BaseEntity - */ -public class SimpleEntityVisitor implements EntityVisitor { - - /** - * La méthode générique pour visiter un {@link EntityVisitable}. - * - * @param v le visité - */ - public void visit(EntityVisitable v) { - if (v != null) { - // on lance la visite - v.accept(this); - } - } - - public void visitExplorationApplication(ExplorationApplication v) { - if (v != null) { - visitComponents(v.getComponents()); - visitExplorationDatas(v.getExplorations()); - visitMetaData(v.getMetaData()); - } - } - - public void visitComponent(Component v) { - if (v != null) { - visitConstants(v.getConstants()); - visitCodes(v.getCodes()); - visitLibraries(v.getLibraries()); - visitMetaData(v.getMetaData()); - } - } - - public void visitExplorationData(ExplorationData v) { - if (v != null) { - visitConstantValues(v.getConstantValues()); - visitResult(v.getResult()); - visitMetaData(v.getMetaData()); - } - } - - public void visitLibrary(Library v) { - if (v != null) { - visitMetaData(v.getMetaData()); - } - } - - public void visitMetaData(MetaData v) { - if (v != null) { - // FIXME !!! - //visitAttachments(v.getAttachments()); - } - } - - public void visitExplorationDatas(Collection<ExplorationData> vs) { - visitSet(vs); - } - - public void visitComponents(Collection<Component> v) { - visitSet(v); - } - - public void visitCodes(Collection<Code> v) { - visitSet(v); - } - - public void visitConstants(Collection<Constant> vs) { - visitSet(vs); - } - - public void visitConstantValues(Collection<ConstantValue> vs) { - visitSet(vs); - } - - public void visitLibraries(Collection<Library> vs) { - visitSet(vs); - } - - public void visitStructures(Collection<Structure> vs) { - visitSet(vs); - } - - public void visitAttachments(Collection<Attachment> vs) { - visitSet(vs); - } - - public void visitCode(Code v) { - // by default, do nothing - } - - public void visitConstant(Constant v) { - // by default, do nothing - } - - public void visitConstantValue(ConstantValue v) { - // by default, do nothing - } - - public void visitResult(Result v) { - // by default, do nothing - } - - public void visitRepository(Repository v) { - // by default, do nothing - } - - public void visitStructure(Structure v) { - // by default, do nothing - } - - public void visitAttachment(Attachment v) { - // by default, do nothing - } - - /** - * Visite une collection de visitables du même type. - * - * @param vs l'ensemble de visitables visités - */ - protected void visitSet(Collection<? extends EntityVisitable> vs) { - if (vs != null) { - for (EntityVisitable visitable : vs) { - visitable.accept(this); - } - } - } -} Modified: trunk/simexplorer-is/simexplorer-is-entities/src/java/fr/cemagref/simexplorer/is/entities/attachment/Attachment.java =================================================================== --- trunk/simexplorer-is/simexplorer-is-entities/src/java/fr/cemagref/simexplorer/is/entities/attachment/Attachment.java 2008-03-06 21:49:51 UTC (rev 1302) +++ trunk/simexplorer-is/simexplorer-is-entities/src/java/fr/cemagref/simexplorer/is/entities/attachment/Attachment.java 2008-03-07 17:57:20 UTC (rev 1303) @@ -19,15 +19,15 @@ import org.apache.commons.lang.StringUtils; -import fr.cemagref.simexplorer.is.entities.BaseEntity; import fr.cemagref.simexplorer.is.entities.EntityVisitor; +import fr.cemagref.simexplorer.is.entities.Leaf; /** * Represents data attached to metadata. * * @author glandais */ -public class Attachment implements BaseEntity { +public class Attachment extends Leaf { /** Serial version ID. */ private static final long serialVersionUID = 5467615366054227592L; @@ -178,7 +178,7 @@ } public void accept(EntityVisitor visitor) { - visitor.visitAttachment(this); + visitor.visitLeaf(this); } } Modified: trunk/simexplorer-is/simexplorer-is-entities/src/java/fr/cemagref/simexplorer/is/entities/data/Code.java =================================================================== --- trunk/simexplorer-is/simexplorer-is-entities/src/java/fr/cemagref/simexplorer/is/entities/data/Code.java 2008-03-06 21:49:51 UTC (rev 1302) +++ trunk/simexplorer-is/simexplorer-is-entities/src/java/fr/cemagref/simexplorer/is/entities/data/Code.java 2008-03-07 17:57:20 UTC (rev 1303) @@ -20,11 +20,12 @@ import java.io.Serializable; import fr.cemagref.simexplorer.is.entities.EntityVisitor; +import fr.cemagref.simexplorer.is.entities.Leaf; /** * The Class Code. */ -public class Code extends DataEntity implements Serializable { +public class Code extends Leaf implements Serializable { /** The Constant serialVersionUID. */ private static final long serialVersionUID = 1232989963544650014L; @@ -80,7 +81,7 @@ } public void accept(EntityVisitor visitor) { - visitor.visitCode(this); + visitor.visitLeaf(this); } @Override Modified: trunk/simexplorer-is/simexplorer-is-entities/src/java/fr/cemagref/simexplorer/is/entities/data/Component.java =================================================================== --- trunk/simexplorer-is/simexplorer-is-entities/src/java/fr/cemagref/simexplorer/is/entities/data/Component.java 2008-03-06 21:49:51 UTC (rev 1302) +++ trunk/simexplorer-is/simexplorer-is-entities/src/java/fr/cemagref/simexplorer/is/entities/data/Component.java 2008-03-07 17:57:20 UTC (rev 1303) @@ -21,12 +21,13 @@ import java.util.ArrayList; import java.util.List; +import fr.cemagref.simexplorer.is.entities.Entity; import fr.cemagref.simexplorer.is.entities.EntityVisitor; /** * The Class Component. */ -public class Component extends LoggableElement implements Serializable { +public class Component extends LoggableElement { /** The Constant serialVersionUID. */ private static final long serialVersionUID = -1759921918565071510L; @@ -119,16 +120,12 @@ * @see fr.cemagref.simexplorer.is.entities.data.LoggableElement#getDirectChildren() */ @Override - public List<LoggableElement> getDirectChildren() { - List<LoggableElement> directChildren = new ArrayList<LoggableElement>(); + public List<Entity> getChildren() { + List<Entity> directChildren = new ArrayList<Entity>(); directChildren.addAll(libraries); return directChildren; } - public void accept(EntityVisitor visitor) { - visitor.visitComponent(this); - } - @Override public int hashCode() { final int prime = 31; Modified: trunk/simexplorer-is/simexplorer-is-entities/src/java/fr/cemagref/simexplorer/is/entities/data/Constant.java =================================================================== --- trunk/simexplorer-is/simexplorer-is-entities/src/java/fr/cemagref/simexplorer/is/entities/data/Constant.java 2008-03-06 21:49:51 UTC (rev 1302) +++ trunk/simexplorer-is/simexplorer-is-entities/src/java/fr/cemagref/simexplorer/is/entities/data/Constant.java 2008-03-07 17:57:20 UTC (rev 1303) @@ -20,9 +20,10 @@ import java.io.Serializable; import fr.cemagref.simexplorer.is.entities.EntityVisitor; +import fr.cemagref.simexplorer.is.entities.Leaf; /** The Class Constant. */ -public class Constant extends DataEntity implements Serializable { +public class Constant extends Leaf implements Serializable { /** The Constant serialVersionUID. */ private static final long serialVersionUID = 5473300963328292128L; @@ -78,7 +79,7 @@ } public void accept(EntityVisitor visitor) { - visitor.visitConstant(this); + visitor.visitLeaf(this); } @Override Modified: trunk/simexplorer-is/simexplorer-is-entities/src/java/fr/cemagref/simexplorer/is/entities/data/ConstantValue.java =================================================================== --- trunk/simexplorer-is/simexplorer-is-entities/src/java/fr/cemagref/simexplorer/is/entities/data/ConstantValue.java 2008-03-06 21:49:51 UTC (rev 1302) +++ trunk/simexplorer-is/simexplorer-is-entities/src/java/fr/cemagref/simexplorer/is/entities/data/ConstantValue.java 2008-03-07 17:57:20 UTC (rev 1303) @@ -20,11 +20,12 @@ import java.io.Serializable; import fr.cemagref.simexplorer.is.entities.EntityVisitor; +import fr.cemagref.simexplorer.is.entities.Leaf; /** * The Class ConstantValue. */ -public class ConstantValue extends DataEntity implements Serializable { +public class ConstantValue extends Leaf implements Serializable { /** The Constant serialVersionUID. */ private static final long serialVersionUID = -5434140706898012637L; @@ -72,7 +73,7 @@ } public void accept(EntityVisitor visitor) { - visitor.visitConstantValue(this); + visitor.visitLeaf(this); } @Override Deleted: trunk/simexplorer-is/simexplorer-is-entities/src/java/fr/cemagref/simexplorer/is/entities/data/DataEntity.java =================================================================== --- trunk/simexplorer-is/simexplorer-is-entities/src/java/fr/cemagref/simexplorer/is/entities/data/DataEntity.java 2008-03-06 21:49:51 UTC (rev 1302) +++ trunk/simexplorer-is/simexplorer-is-entities/src/java/fr/cemagref/simexplorer/is/entities/data/DataEntity.java 2008-03-07 17:57:20 UTC (rev 1303) @@ -1,48 +0,0 @@ -/* -* ##% Copyright (C) 2008 Code Lutin, Gabriel Landais -* -* 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 fr.cemagref.simexplorer.is.entities.data; - -import fr.cemagref.simexplorer.is.entities.BaseEntity; - -/** - * The Class DataEntity. - */ -public abstract class DataEntity implements BaseEntity { - - /** The Constant serialVersionUID. */ - private static final long serialVersionUID = -2570073990226703994L; - - @Override - public int hashCode() { - final int prime = 31; - int result = 1; - return result; - } - - @Override - public boolean equals(Object obj) { - if (this == obj) - return true; - if (obj == null) - return false; - if (getClass() != obj.getClass()) - return false; - return true; - } - -} Modified: trunk/simexplorer-is/simexplorer-is-entities/src/java/fr/cemagref/simexplorer/is/entities/data/Descriptor.java =================================================================== --- trunk/simexplorer-is/simexplorer-is-entities/src/java/fr/cemagref/simexplorer/is/entities/data/Descriptor.java 2008-03-06 21:49:51 UTC (rev 1302) +++ trunk/simexplorer-is/simexplorer-is-entities/src/java/fr/cemagref/simexplorer/is/entities/data/Descriptor.java 2008-03-07 17:57:20 UTC (rev 1303) @@ -17,13 +17,13 @@ * ##% */ package fr.cemagref.simexplorer.is.entities.data; -import fr.cemagref.simexplorer.is.entities.BaseEntity; import fr.cemagref.simexplorer.is.entities.EntityVisitor; +import fr.cemagref.simexplorer.is.entities.Leaf; /** * The Class Descriptor. */ -public class Descriptor implements BaseEntity, Comparable<Descriptor> { +public class Descriptor extends Leaf implements Comparable<Descriptor> { /** The Constant serialVersionUID. */ private static final long serialVersionUID = -7429465085491453048L; Modified: trunk/simexplorer-is/simexplorer-is-entities/src/java/fr/cemagref/simexplorer/is/entities/data/ExplorationApplication.java =================================================================== --- trunk/simexplorer-is/simexplorer-is-entities/src/java/fr/cemagref/simexplorer/is/entities/data/ExplorationApplication.java 2008-03-06 21:49:51 UTC (rev 1302) +++ trunk/simexplorer-is/simexplorer-is-entities/src/java/fr/cemagref/simexplorer/is/entities/data/ExplorationApplication.java 2008-03-07 17:57:20 UTC (rev 1303) @@ -21,7 +21,8 @@ import java.util.ArrayList; import java.util.List; -import fr.cemagref.simexplorer.is.entities.EntityVisitor; +import fr.cemagref.simexplorer.is.entities.Entity; +import fr.cemagref.simexplorer.is.entities.SimpleComposite; /** * The Class ExplorationApplication. @@ -32,17 +33,17 @@ private static final long serialVersionUID = 122049347724394193L; /** The explorations. */ - private List<ExplorationData> explorations; + private SimpleComposite<ExplorationData> explorations; /** The components. */ - private List<Component> components; + private SimpleComposite<Component> components; /** * Gets the explorations. * * @return the explorations */ - public List<ExplorationData> getExplorations() { + public SimpleComposite<ExplorationData> getExplorations() { return explorations; } @@ -51,7 +52,7 @@ * * @param explorations the new explorations */ - public void setExplorations(List<ExplorationData> explorations) { + public void setExplorations(SimpleComposite<ExplorationData> explorations) { this.explorations = explorations; } @@ -60,7 +61,7 @@ * * @return the components */ - public List<Component> getComponents() { + public SimpleComposite<Component> getComponents() { return components; } @@ -69,7 +70,7 @@ * * @param components the new components */ - public void setComponents(List<Component> components) { + public void setComponents(SimpleComposite<Component> components) { this.components = components; } @@ -77,17 +78,13 @@ * @see fr.cemagref.simexplorer.is.entities.data.LoggableElement#getDirectChildren() */ @Override - public List<LoggableElement> getDirectChildren() { - List<LoggableElement> directChildren = new ArrayList<LoggableElement>(); - directChildren.addAll(explorations); - directChildren.addAll(components); + public List<Entity> getChildren() { + List<Entity> directChildren = new ArrayList<Entity>(); + directChildren.add(explorations); + directChildren.add(components); return directChildren; } - public void accept(EntityVisitor visitor) { - visitor.visitExplorationApplication(this); - } - @Override public int hashCode() { final int prime = 31; Modified: trunk/simexplorer-is/simexplorer-is-entities/src/java/fr/cemagref/simexplorer/is/entities/data/ExplorationData.java =================================================================== --- trunk/simexplorer-is/simexplorer-is-entities/src/java/fr/cemagref/simexplorer/is/entities/data/ExplorationData.java 2008-03-06 21:49:51 UTC (rev 1302) +++ trunk/simexplorer-is/simexplorer-is-entities/src/java/fr/cemagref/simexplorer/is/entities/data/ExplorationData.java 2008-03-07 17:57:20 UTC (rev 1303) @@ -18,9 +18,11 @@ package fr.cemagref.simexplorer.is.entities.data; import java.io.Serializable; +import java.util.ArrayList; import java.util.List; -import fr.cemagref.simexplorer.is.entities.EntityVisitor; +import fr.cemagref.simexplorer.is.entities.Entity; +import fr.cemagref.simexplorer.is.entities.SimpleComposite; /** * The Class ExplorationData. @@ -31,7 +33,7 @@ private static final long serialVersionUID = -6439801837608358754L; /** The values map. */ - private List<ConstantValue> constantValues; + private SimpleComposite<ConstantValue> constantValues; /** The result. */ private Result result; @@ -44,7 +46,7 @@ * @return the constant value */ private ConstantValue findConstantValue(Constant c) { - for (ConstantValue constantValue : constantValues) { + for (ConstantValue constantValue : constantValues.getElements()) { if (c.equals(constantValue.getConstant())) { return constantValue; } @@ -63,7 +65,7 @@ if (constantValue == null) { constantValue = new ConstantValue(); constantValue.setConstant(c); - constantValues.add(constantValue); + constantValues.getElements().add(constantValue); } constantValue.setValue(value); } @@ -106,7 +108,7 @@ * * @return the values map */ - public List<ConstantValue> getConstantValues() { + public SimpleComposite<ConstantValue> getConstantValues() { return constantValues; } @@ -115,7 +117,7 @@ * * @param constantValues the new values map */ - public void setConstantValues(List<ConstantValue> constantValues) { + public void setConstantValues(SimpleComposite<ConstantValue> constantValues) { this.constantValues = constantValues; } @@ -123,14 +125,13 @@ * @see fr.cemagref.simexplorer.is.entities.data.LoggableElement#getDirectChildren() */ @Override - public List<LoggableElement> getDirectChildren() { - return null; + public List<Entity> getChildren() { + List<Entity> children = new ArrayList<Entity>(); + children.add(result); + children.add(constantValues); + return children; } - public void accept(EntityVisitor visitor) { - visitor.visitExplorationData(this); - } - @Override public int hashCode() { final int prime = 31; Modified: trunk/simexplorer-is/simexplorer-is-entities/src/java/fr/cemagref/simexplorer/is/entities/data/Library.java =================================================================== --- trunk/simexplorer-is/simexplorer-is-entities/src/java/fr/cemagref/simexplorer/is/entities/data/Library.java 2008-03-06 21:49:51 UTC (rev 1302) +++ trunk/simexplorer-is/simexplorer-is-entities/src/java/fr/cemagref/simexplorer/is/entities/data/Library.java 2008-03-07 17:57:20 UTC (rev 1303) @@ -17,8 +17,10 @@ * ##% */ package fr.cemagref.simexplorer.is.entities.data; +import java.util.ArrayList; import java.util.List; +import fr.cemagref.simexplorer.is.entities.Entity; import fr.cemagref.simexplorer.is.entities.EntityVisitor; /** The Class Library. */ @@ -27,19 +29,7 @@ /** The Constant serialVersionUID. */ private static final long serialVersionUID = -5635619075345573945L; - /* (non-Javadoc) - * @see fr.cemagref.simexplorer.is.entities.data.LoggableElement#getDirectChildren() - */ @Override - public List<LoggableElement> getDirectChildren() { - return null; - } - - public void accept(EntityVisitor visitor) { - visitor.visitLibrary(this); - } - - @Override public int hashCode() { final int prime = 31; int result = super.hashCode(); @@ -65,6 +55,12 @@ // return false; return true; } - - + + @Override + public List<Entity> getChildren() { + List<Entity> children = new ArrayList<Entity>(); + children.addAll(getAttachments()); + return children; + } + } Modified: trunk/simexplorer-is/simexplorer-is-entities/src/java/fr/cemagref/simexplorer/is/entities/data/LoggableElement.java =================================================================== --- trunk/simexplorer-is/simexplorer-is-entities/src/java/fr/cemagref/simexplorer/is/entities/data/LoggableElement.java 2008-03-06 21:49:51 UTC (rev 1302) +++ trunk/simexplorer-is/simexplorer-is-entities/src/java/fr/cemagref/simexplorer/is/entities/data/LoggableElement.java 2008-03-07 17:57:20 UTC (rev 1303) @@ -20,13 +20,16 @@ import java.util.ArrayList; import java.util.List; +import fr.cemagref.simexplorer.is.entities.Composite; +import fr.cemagref.simexplorer.is.entities.Entity; +import fr.cemagref.simexplorer.is.entities.EntityVisitor; import fr.cemagref.simexplorer.is.entities.attachment.Attachment; import fr.cemagref.simexplorer.is.entities.metadata.MetaData; /** * The Class LoggableElement. */ -public abstract class LoggableElement extends DataEntity { +public abstract class LoggableElement extends Composite { /** The name. */ private String name; @@ -54,30 +57,33 @@ return getName(); } + /** - * Gets the direct children. + * Gets all children of LoggableElement type. * - * @return the direct children + * @param entity the entity + * @param list the list + * */ - public abstract List<LoggableElement> getDirectChildren(); - + private void getLEChildren(Entity entity, List<LoggableElement> list) { + if (entity instanceof LoggableElement) { + list.add((LoggableElement) entity); + } + List<Entity> children = entity.getChildren(); + for (Entity child : children) { + getLEChildren(child, list); + } + } + /** - * Gets the children. + * Gets all children of LoggableElement type. * - * @return the children + * @return the lE children */ - public List<LoggableElement> getChildren() { - List<LoggableElement> directChildren = getDirectChildren(); - - List<LoggableElement> children = new ArrayList<LoggableElement>(); - if (directChildren != null) { - for (LoggableElement element : directChildren) { - children.add(element); - children.addAll(element.getChildren()); - } - } - - return children; + public List<LoggableElement> getLEChildren() { + ArrayList<LoggableElement> leChildren = new ArrayList<LoggableElement>(); + getLEChildren(this, leChildren); + return leChildren; } /** Modified: trunk/simexplorer-is/simexplorer-is-entities/src/java/fr/cemagref/simexplorer/is/entities/data/Repository.java =================================================================== --- trunk/simexplorer-is/simexplorer-is-entities/src/java/fr/cemagref/simexplorer/is/entities/data/Repository.java 2008-03-06 21:49:51 UTC (rev 1302) +++ trunk/simexplorer-is/simexplorer-is-entities/src/java/fr/cemagref/simexplorer/is/entities/data/Repository.java 2008-03-07 17:57:20 UTC (rev 1303) @@ -18,19 +18,16 @@ package fr.cemagref.simexplorer.is.entities.data; import fr.cemagref.simexplorer.is.entities.EntityVisitor; +import fr.cemagref.simexplorer.is.entities.Leaf; /** * The Class Repository. */ -public class Repository extends DataEntity { +public class Repository extends Leaf { /** The Constant serialVersionUID. */ private static final long serialVersionUID = 1232065724338066924L; - public void accept(EntityVisitor visitor) { - visitor.visitRepository(this); - } - @Override public int hashCode() { final int prime = 31; @@ -58,4 +55,9 @@ return true; } + @Override + public void accept(EntityVisitor visitor) { + // nothing yet + } + } Modified: trunk/simexplorer-is/simexplorer-is-entities/src/java/fr/cemagref/simexplorer/is/entities/data/Result.java =================================================================== --- trunk/simexplorer-is/simexplorer-is-entities/src/java/fr/cemagref/simexplorer/is/entities/data/Result.java 2008-03-06 21:49:51 UTC (rev 1302) +++ trunk/simexplorer-is/simexplorer-is-entities/src/java/fr/cemagref/simexplorer/is/entities/data/Result.java 2008-03-07 17:57:20 UTC (rev 1303) @@ -18,9 +18,10 @@ package fr.cemagref.simexplorer.is.entities.data; import fr.cemagref.simexplorer.is.entities.EntityVisitor; +import fr.cemagref.simexplorer.is.entities.Leaf; /** The Class Result. */ -public class Result extends DataEntity { +public class Result extends Leaf { /** The Constant serialVersionUID. */ private static final long serialVersionUID = 2111484866027162494L; @@ -31,7 +32,7 @@ } public void accept(EntityVisitor visitor) { - visitor.visitResult(this); + visitor.visitLeaf(this); } @Override Modified: trunk/simexplorer-is/simexplorer-is-entities/src/java/fr/cemagref/simexplorer/is/entities/data/Structure.java =================================================================== --- trunk/simexplorer-is/simexplorer-is-entities/src/java/fr/cemagref/simexplorer/is/entities/data/Structure.java 2008-03-06 21:49:51 UTC (rev 1302) +++ trunk/simexplorer-is/simexplorer-is-entities/src/java/fr/cemagref/simexplorer/is/entities/data/Structure.java 2008-03-07 17:57:20 UTC (rev 1303) @@ -18,17 +18,18 @@ package fr.cemagref.simexplorer.is.entities.data; import fr.cemagref.simexplorer.is.entities.EntityVisitor; +import fr.cemagref.simexplorer.is.entities.Leaf; /** * The Class Structure. */ -public abstract class Structure extends DataEntity { +public abstract class Structure extends Leaf { /** The Constant serialVersionUID. */ private static final long serialVersionUID = 2594331198459134006L; public void accept(EntityVisitor visitor) { - visitor.visitStructure(this); + visitor.visitLeaf(this); } @Override Modified: trunk/simexplorer-is/simexplorer-is-entities/src/java/fr/cemagref/simexplorer/is/entities/metadata/MetaData.java =================================================================== --- trunk/simexplorer-is/simexplorer-is-entities/src/java/fr/cemagref/simexplorer/is/entities/metadata/MetaData.java 2008-03-06 21:49:51 UTC (rev 1302) +++ trunk/simexplorer-is/simexplorer-is-entities/src/java/fr/cemagref/simexplorer/is/entities/metadata/MetaData.java 2008-03-07 17:57:20 UTC (rev 1303) @@ -19,15 +19,15 @@ import java.util.Date; -import fr.cemagref.simexplorer.is.entities.BaseEntity; import fr.cemagref.simexplorer.is.entities.EntityTypeEnum; import fr.cemagref.simexplorer.is.entities.EntityVisitor; +import fr.cemagref.simexplorer.is.entities.Leaf; /** * The Class MetaData. Used by IS to store relative data of a LoggableElement. SimExplorer should not set properties of * this class. */ -public class MetaData implements BaseEntity { +public class MetaData extends Leaf { /** The Constant serialVersionUID. */ private static final long serialVersionUID = -7916932464982315229L; Modified: trunk/simexplorer-is/simexplorer-is-service/src/java/fr/cemagref/simexplorer/is/service/MockDatabase.java =================================================================== --- trunk/simexplorer-is/simexplorer-is-service/src/java/fr/cemagref/simexplorer/is/service/MockDatabase.java 2008-03-06 21:49:51 UTC (rev 1302) +++ trunk/simexplorer-is/simexplorer-is-service/src/java/fr/cemagref/simexplorer/is/service/MockDatabase.java 2008-03-07 17:57:20 UTC (rev 1303) @@ -130,13 +130,13 @@ this.eas.put(uuid, eas); registerLoggableElement(uuid, eas); for (ExplorationApplication ea : eas) { - for (Component component : ea.getComponents()) { + for (Component component : ea.getComponents().getElements()) { registerLoggableElement(component.getMetaData().getUuid(), component); for (Library library : component.getLibraries()) { registerLoggableElement(library.getMetaData().getUuid(), library); } } - for (ExplorationData explorationData : ea.getExplorations()) { + for (ExplorationData explorationData : ea.getExplorations().getElements()) { registerLoggableElement(explorationData.getMetaData().getUuid(), explorationData); } } Modified: trunk/simexplorer-is/simexplorer-is-service/src/java/fr/cemagref/simexplorer/is/service/StorageServiceCommon.java =================================================================== --- trunk/simexplorer-is/simexplorer-is-service/src/java/fr/cemagref/simexplorer/is/service/StorageServiceCommon.java 2008-03-06 21:49:51 UTC (rev 1302) +++ trunk/simexplorer-is/simexplorer-is-service/src/java/fr/cemagref/simexplorer/is/service/StorageServiceCommon.java 2008-03-07 17:57:20 UTC (rev 1303) @@ -43,9 +43,9 @@ import com.healthmarketscience.rmiio.SerializableInputStream; +import fr.cemagref.simexplorer.is.entities.Entity; import fr.cemagref.simexplorer.is.entities.EntityTypeEnum; import fr.cemagref.simexplorer.is.entities.attachment.Attachment; -import fr.cemagref.simexplorer.is.entities.data.ExplorationApplication; import fr.cemagref.simexplorer.is.entities.data.LoggableElement; import fr.cemagref.simexplorer.is.entities.metadata.MetaData; import fr.cemagref.simexplorer.is.entities.metadata.Version; @@ -402,7 +402,7 @@ files.put(FILE_XML, getStorageEngine().retrieveData(token, loggableElement.getMetaData(), getXMLAttachment())); - List<LoggableElement> children = loggableElement.getChildren(); + List<LoggableElement> children = loggableElement.getLEChildren(); for (Attachment attachment : loggableElement.getAttachments()) { files.put(FILE_DATA_PREFIX + FOLDER_SEPARATOR + attachment.getUniqueId(), getStorageEngine().retrieveData( token, loggableElement.getMetaData(), attachment)); @@ -760,6 +760,31 @@ // Compute element hash metaData.setHash(Long.toString(loggableElement.hashCode())); } + + /** + * Save all LE under element + * Only first level LE are saved + * + * @param token the token + * @param element the element + * @param idsattachment the idsattachment + * + * @throws SimExplorerException the sim explorer exception + */ + private void recursiveSaveElement(String token, Entity element, Map<Attachment, String> idsattachment) + throws SimExplorerException { + List<Entity> children = element.getChildren(); + for (Entity child : children) { + if (child instanceof LoggableElement) { + LoggableElement leChild = (LoggableElement) child; + LoggableElement childElement = saveElement(token, leChild, idsattachment); + // TODO check + getStorageEngine().saveElementHierarchy(token, leChild.getMetaData(), childElement.getMetaData()); + } else { + recursiveSaveElement(token, child, idsattachment); + } + } + } /** * Real implementation of saveElement. @@ -791,12 +816,7 @@ // Process version rules processVersionRules(token, metaData, element); - List<LoggableElement> children = element.getChildren(); - LoggableElement childElement; - for (LoggableElement child : children) { - childElement = saveElement(token, child, idsattachment); - getStorageEngine().saveElementHierarchy(token, metaData, childElement.getMetaData()); - } + recursiveSaveElement(token, element, idsattachment); // Prepare saving Map<Attachment, InputStream> attachments = new HashMap<Attachment, InputStream>(); Modified: trunk/simexplorer-is/simexplorer-is-service/src/java/fr/cemagref/simexplorer/is/service/StorageServiceGenerator.java =================================================================== --- trunk/simexplorer-is/simexplorer-is-service/src/java/fr/cemagref/simexplorer/is/service/StorageServiceGenerator.java 2008-03-06 21:49:51 UTC (rev 1302) +++ trunk/simexplorer-is/simexplorer-is-service/src/java/fr/cemagref/simexplorer/is/service/StorageServiceGenerator.java 2008-03-07 17:57:20 UTC (rev 1303) @@ -53,7 +53,7 @@ List<Attachment> attachmentsKeys = new ArrayList<Attachment>(); attachmentsKeys.addAll(ea.getAttachments()); - List<LoggableElement> children = ea.getChildren(); + List<LoggableElement> children = ea.getLEChildren(); for (LoggableElement child : children) { attachmentsKeys.addAll(child.getAttachments()); } @@ -123,7 +123,7 @@ ea.getMetaData().setVersion(secondVersion); if (different) { - Component component = ea.getComponents().iterator().next(); + Component component = ea.getComponents().getElements().iterator().next(); Code code = new Code(); code.setCode("regreg"); code.setLanguage("regreg"); Deleted: trunk/simexplorer-is/simexplorer-is-storage/src/java/fr/cemagref/simexplorer/is/factories/BaseEntityFactory.java =================================================================== --- trunk/simexplorer-is/simexplorer-is-storage/src/java/fr/cemagref/simexplorer/is/factories/BaseEntityFactory.java 2008-03-06 21:49:51 UTC (rev 1302) +++ trunk/simexplorer-is/simexplorer-is-storage/src/java/fr/cemagref/simexplorer/is/factories/BaseEntityFactory.java 2008-03-07 17:57:20 UTC (rev 1303) @@ -1,37 +0,0 @@ -/* -* ##% Copyright (C) 2008 Code Lutin, Gabriel Landais -* -* 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 fr.cemagref.simexplorer.is.factories; - -import com.thoughtworks.xstream.XStream; - -import fr.cemagref.simexplorer.is.entities.BaseEntity; - -/** - * A factory for creating BaseEntity objects. - * - * @param <E> Entity type - */ -public abstract class BaseEntityFactory<E extends BaseEntity> { - - private static XStream xstream = new XStream(); - - public static XStream getXstream() { - return xstream; - } - -} Copied: trunk/simexplorer-is/simexplorer-is-storage/src/java/fr/cemagref/simexplorer/is/factories/EntityFactory.java (from rev 1302, trunk/simexplorer-is/simexplorer-is-storage/src/java/fr/cemagref/simexplorer/is/factories/BaseEntityFactory.java) =================================================================== --- trunk/simexplorer-is/simexplorer-is-storage/src/java/fr/cemagref/simexplorer/is/factories/EntityFactory.java (rev 0) +++ trunk/simexplorer-is/simexplorer-is-storage/src/java/fr/cemagref/simexplorer/is/factories/EntityFactory.java 2008-03-07 17:57:20 UTC (rev 1303) @@ -0,0 +1,37 @@ +/* +* ##% Copyright (C) 2008 Code Lutin, Gabriel Landais +* +* 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 fr.cemagref.simexplorer.is.factories; + +import com.thoughtworks.xstream.XStream; + +import fr.cemagref.simexplorer.is.entities.Entity; + +/** + * A factory for creating BaseEntity objects. + * + * @param <E> Entity type + */ +public abstract class EntityFactory<E extends Entity> { + + private static XStream xstream = new XStream(); + + public static XStream getXstream() { + return xstream; + } + +} Modified: trunk/simexplorer-is/simexplorer-is-storage/src/java/fr/cemagref/simexplorer/is/factories/LoggableElementFactory.java =================================================================== --- trunk/simexplorer-is/simexplorer-is-storage/src/java/fr/cemagref/simexplorer/is/factories/LoggableElementFactory.java 2008-03-06 21:49:51 UTC (rev 1302) +++ trunk/simexplorer-is/simexplorer-is-storage/src/java/fr/cemagref/simexplorer/is/factories/LoggableElementFactory.java 2008-03-07 17:57:20 UTC (rev 1303) @@ -32,7 +32,7 @@ * LoggableElement subtype */ public abstract class LoggableElementFactory<E extends LoggableElement> extends - BaseEntityFactory<E> { + EntityFactory<E> { /** * Parses the stream. Deleted: trunk/simexplorer-is/simexplorer-is-storage/src/java/fr/cemagref/simexplorer/is/factories/MetaDataFactory.java =================================================================== --- trunk/simexplorer-is/simexplorer-is-storage/src/java/fr/cemagref/simexplorer/is/factories/MetaDataFactory.java 2008-03-06 21:49:51 UTC (rev 1302) +++ trunk/simexplorer-is/simexplorer-is-storage/src/java/fr/cemagref/simexplorer/is/factories/MetaDataFactory.java 2008-03-07 17:57:20 UTC (rev 1303) @@ -1,362 +0,0 @@ -/* -* ##% Copyright (C) 2008 Code Lutin, Gabriel Landais -* -* 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 fr.cemagref.simexplorer.is.factories; - -import java.io.InputStream; -import java.io.PipedInputStream; -import java.io.PipedOutputStream; -import java.text.ParseException; -import java.text.SimpleDateFormat; -import java.util.ArrayList; -import java.util.Date; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import javax.xml.transform.dom.DOMSource; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.codelutin.util.DigestGenerator; -import org.codelutin.util.MD5; -import org.w3c.dom.Document; -import org.w3c.dom.Element; -import org.w3c.dom.Node; -import org.w3c.dom.NodeList; - -import fr.cemagref.simexplorer.is.entities.attachment.Attachment; -import fr.cemagref.simexplorer.is.entities.attachment.ContentType; -import fr.cemagref.simexplorer.is.entities.metadata.MetaData; -import fr.cemagref.simexplorer.is.exceptions.SimExplorerException; -import fr.cemagref.simexplorer.is.exceptions.SimExplorerTechnicalException; - -/** - * A factory for creating MetaData objects. - * - * @param <E> MetaData - */ -public class MetaDataFactory<E extends MetaData> extends BaseEntityFactory<MetaData> { - - private static final Log log = LogFactory.getLog(MetaDataFactory.class); - - /** The Constant sdf. */ - private static final SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss"); - -// /* (non-Javadoc) -// * @see fr.cemagref.simexplorer.is.factories.BaseEntityFactory#createInstance() -// */ -// @Override -// public MetaData createInstance() { -// return new MetaData(); -// } -// -// /** -// * Gets the factory. -// * -// * @param <E> Metadata -// * -// * @param entityClass the entity class -// * -// * @return the factory -// * -// * @throws SimExplorerException the exception -// */ -// @SuppressWarnings( { "unchecked" }) -// public static <E extends MetaData> MetaDataFactory<E> getFactory(Class<E> entityClass) throws SimExplorerException { -// return (MetaDataFactory) BaseEntityFactory.getFactory(entityClass); -// } -// -// /* -// * (non-Javadoc) -// * -// * @see fr.cemagref.simexplorer.is.storage.factories.BaseEntityFactory#loadXMLElement(org.w3c.dom.Element) -// */ -// -// @Override -// public MetaData loadElement(Element xmlElement) throws SimExplorerException { -// MetaData entity = super.loadElement(xmlElement); -// entity.setUuid(getXMLProperty(xmlElement, KEY_METADATA_UUID)); -// entity.setName(getXMLProperty(xmlElement, KEY_METADATA_NAME)); -// entity.setType(getXMLProperty(xmlElement, KEY_METADATA_TYPE)); -// entity.setDescription(getXMLProperty(xmlElement, KEY_METADATA_DESCRIPTION)); -// entity.setVersion(getXMLProperty(xmlElement, KEY_METADATA_VERSION)); -// -// String latestVersion = getXMLProperty(xmlElement, KEY_METADATA_LATESTVERSION); -// if (latestVersion != null && "1".equals(latestVersion)) { -// entity.setLatest(true); -// } else { -// entity.setLatest(false); -// } -// -// String creationDate = getXMLProperty(xmlElement, KEY_METADATA_CREATIONDATE); -// if (creationDate != null) { -// Date date; -// try { -// date = sdf.parse(creationDate); -// } catch (ParseException e) { -// throw new SimExplorerTechnicalException(e); -// } -// entity.setCreationDate(date); -// } -// -// entity.setHash(getXMLProperty(xmlElement, KEY_METADATA_HASH)); -// entity.setParentVersionUuid(getXMLProperty(xmlElement, KEY_METADATA_PARENTVERSION_UUID)); -// entity.setParentVersionVersion(getXMLProperty(xmlElement, KEY_METADATA_PARENTVERSION_VERSION)); -// -// Map<String, String> descriptors = new HashMap<String, String>(); -// -// Element descriptorsElement = getXMLElementByTagName(xmlElement, KEY_METADATA_DESCRIPTORS); -// if (descriptorsElement != null) { -// List<Element> descriptorElements = getXMLElementsByTagName(descriptorsElement, KEY_METADATA_DESCRIPTOR); -// for (Element descriptorElement : descriptorElements) { -// String name = getXMLProperty(descriptorElement, KEY_METADATA_DESCRIPTOR_NAME); -// String value = getXMLProperty(descriptorElement, KEY_METADATA_DESCRIPTOR_VALUE); -// descriptors.put(name, value); -// } -// } -// entity.setDescriptors(descriptors); -// -// List<Attachment> attachments = new ArrayList<Attachment>(); -// -// Element attachmentsElement = getXMLElementByTagName(xmlElement, KEY_METADATA_ATTACHMENTS); -// if (attachmentsElement != null) { -// List<Element> attachmentElements = getXMLElementsByTagName(attachmentsElement, KEY_METADATA_ATTACHMENT); -// for (Element attachmentElement : attachmentElements) { -// Attachment attachment = new Attachment(); -// -// String name = getXMLProperty(attachmentElement, KEY_METADATA_ATTACHMENT_NAME); -// attachment.setFileName(name); -// -// String type = getXMLProperty(attachmentElement, KEY_METADATA_ATTACHMENT_TYPE); -// ContentType contentType = ContentTypeFactory.getContentTypeInstance(type); -// attachment.setContentType(contentType); -// -// String dataHash = getXMLProperty(attachmentElement, KEY_METADATA_ATTACHMENT_HASH); -// attachment.setDataHash(dataHash); -// -// attachments.add(attachment); -// } -// } -// -// entity.setAttachments(attachments); -// -// return entity; -// } -// -// /* (non-Javadoc) -// * @see fr.cemagref.simexplorer.is.factories.BaseEntityFactory#saveElement(org.w3c.dom.Document, org.w3c.dom.Element, fr.cemagref.simexplorer.is.entities.BaseEntity) -// */ -// @Override -// public void saveElement(Document document, Element xmlElement, MetaData element) throws SimExplorerException { -// -// setXMLProperty(document, xmlElement, KEY_METADATA_UUID, element.getUuid()); -// setXMLProperty(document, xmlElement, KEY_METADATA_NAME, element.getName()); -// setXMLProperty(document, xmlElement, KEY_METADATA_TYPE, element.getType()); -// setXMLProperty(document, xmlElement, KEY_METADATA_DESCRIPTION, element.getDescription()); -// setXMLProperty(document, xmlElement, KEY_METADATA_VERSION, element.getVersion().toString()); -// -// if (element.isLatest()) { -// setXMLProperty(document, xmlElement, KEY_METADATA_LATESTVERSION, "1"); -// } else { -// setXMLProperty(document, xmlElement, KEY_METADATA_LATESTVERSION, "0"); -// } -// -// if (element.getCreationDate() != null) { -// setXMLProperty(document, xmlElement, KEY_METADATA_CREATIONDATE, sdf.format(element.getCreationDate())); -// } -// -// setXMLProperty(document, xmlElement, KEY_METADATA_HASH, element.getHash()); -// setXMLProperty(document, xmlElement, KEY_METADATA_PARENTVERSION_UUID, element.getParentVersionUuid()); -// setXMLProperty(document, xmlElement, KEY_METADATA_PARENTVERSION_VERSION, element.getParentVersionVersion()); -// -// Map<String, String> descriptors = element.getDescriptors(); -// -// Element descriptorsElement = document.createElement(KEY_METADATA_DESCRIPTORS); -// -// for (Map.Entry<String, String> kv : descriptors.entrySet()) { -// Element descriptorElement = document.createElement(KEY_METADATA_DESCRIPTOR); -// setXMLProperty(document, descriptorElement, KEY_METADATA_DESCRIPTOR_NAME, kv.getKey()); -// setXMLProperty(document, descriptorElement, KEY_METADATA_DESCRIPTOR_VALUE, kv.getValue()); -// descriptorsElement.appendChild(descriptorElement); -// } -// -// xmlElement.appendChild(descriptorsElement); -// -// List<Attachment> attachments = element.getAttachments(); -// -// if (attachments != null) { -// -// Element attachmentsElement = document.createElement(KEY_METADATA_ATTACHMENTS); -// -// for (Attachment attachment : attachments) { -// Element attachmentElement = document.createElement(KEY_METADATA_ATTACHMENT); -// -// setXMLProperty(document, attachmentElement, KEY_METADATA_ATTACHMENT_NAME, attachment.getFileName()); -// setXMLProperty(document, attachmentElement, KEY_METADATA_ATTACHMENT_TYPE, attachment.getContentType() -// .getClass().getSimpleName()); -// setXMLProperty(document, attachmentElement, KEY_METADATA_ATTACHMENT_HASH, attachment.getDataHash()); -// -// attachmentsElement.appendChild(attachmentElement); -// } -// xmlElement.appendChild(attachmentsElement); -// -// } -// -// } -// -// /** -// * As metadata is stored inside an entity, this method loads metadata with parsing stream and retrieve metadata -// * node. -// * -// * @param node the node -// * -// * @return the meta data -// * -// * @throws SimExplorerException the exception -// */ -// public MetaData loadElementFromParentXML(Element node) throws SimExplorerException { -// Element mdeElement = getXMLElementByTagName(node, KEY_METADATA); -// MetaData mde; -// try { -// mde = loadElement(mdeElement); -// } catch (SimExplorerException e) { -// throw new SimExplorerTechnicalException(e); -// } -// return mde; -// } -// -// /** -// * Replace element in parent xml. -// * -// * @param xmlStream the xml stream -// * @param newMetadata the new metadata -// * -// * @return the input stream -// * -// * @throws SimExplorerException the exception -// */ -// public InputStream modifyMedataElementStream(InputStream xmlStream, MetaData newMetadata) -// throws SimExplorerException { -// Document document; -// Element rootElement; -// Element newElement; -// try { -// document = getXMLBuilder().parse(xmlStream); -// rootElement = (Element) document.getFirstChild(); -// newElement = document.createElement(KEY_METADATA); -// } catch (Exception e) { -// throw new SimExplorerTechnicalException(e); -// } -// this.saveElement(document, newElement, newMetadata); -// Element oldElement = getXMLElementByTagName(rootElement, KEY_METADATA); -// rootElement.replaceChild(newElement, oldElement); -// -// DOMSource domSource = new DOMSource(document); -// -// try { -// PipedOutputStream os = new PipedOutputStream(); -// PipedInputStream is = new PipedInputStream(os); -// -// XMLStreamEncoder xse = new XMLStreamEncoder(domSource, os); -// xse.start(); -// -// return is; -// } catch (Exception e) { -// throw new SimExplorerTechnicalException(e); -// } -// } -// -// /** -// * Replace element in parent xml. -// * -// * @param newMetadata the new metadata -// * @param document the document -// * @param xmlNode the xml node -// * -// * @throws SimExplorerException the exception -// */ -// public void replaceMetadataInXML(Document document, Element xmlNode, MetaData newMetadata) -// throws SimExplorerException { -// Element newElement = document.createElement(KEY_METADATA); -// this.saveElement(document, newElement, newMetadata); -// -// Element oldElement = getXMLElementByTagName(xmlNode, KEY_METADATA); -// xmlNode.replaceChild(newElement, oldElement); -// } -// -// /** -// * Compute hash. -// * -// * @param node the xml stream -// * -// * @return the string -// * -// * @throws SimExplorerException the exception -// */ -// public String computeHash(Element node) throws SimExplorerException { -// try { -// Document document = getXMLBuilder().newDocument(); -// document.appendChild(document.importNode(node, true)); -// -// removeMetadatas(document); -// -// DigestGenerator digestGenerator = new DigestGenerator(); -// byte[] digest = digestGenerator.getDigest(document, DigestGenerator.sha1DigestAlgorithm); -// -// return MD5.asHex(digest); -// } catch (Exception e) { -// throw new SimExplorerTechnicalException(e); -// } -// } -// -// /** -// * Removes the metadatas. -// * -// * @param node the node -// * -// * @return the int -// */ -// private int removeMetadatas(Node node) { -// int tot = 0; -// NodeList childNodes = node.getChildNodes(); -// List<Node> toRemove = new ArrayList<Node>(); -// -// for (int i = 0; i < childNodes.getLength(); i++) { -// Node child = childNodes.item(i); -// if (child instanceof Element && KEY_METADATA.equals(((Element) child).getTagName())) { -// toRemove.add(child); -// } -// } -// -// for (Node metadata : toRemove) { -// node.removeChild(metadata); -// tot++; -// } -// -// if (tot == 0) { -// childNodes = node.getChildNodes(); -// for (int i = 0; i < childNodes.getLength(); i++) { -// Node child = childNodes.item(i); -// tot = tot + removeMetadatas(child); -// } -// } -// -// return tot; -// } - -} Modified: trunk/simexplorer-is/simexplorer-is-storage/src/java/fr/cemagref/simexplorer/is/storage/ElementGenerator.java =================================================================== --- trunk/simexplorer-is/simexplorer-is-storage/src/java/fr/cemagref/simexplorer/is/storage/ElementGenerator.java 2008-03-06 21:49:51 UTC (rev 1302) +++ trunk/simexplorer-is/simexplorer-is-storage/src/java/fr/cemagref/simexplorer/is/storage/ElementGenerator.java 2008-03-07 17:57:20 UTC (rev 1303) @@ -28,12 +28,13 @@ import org.apache.commons.lang.RandomStringUtils; import org.codelutin.util.MD5; +import fr.cemagref.simexplorer.is.entities.Entity; +import fr.cemagref.simexplorer.is.entities.SimpleComposite; import fr.cemagref.simexplorer.is.entities.attachment.Attachment; import fr.cemagref.simexplorer.is.entities.data.Code; import fr.cemagref.simexplorer.is.entities.data.Component; import fr.cemagref.simexplorer.is.entities.data.Constant; import fr.cemagref.simexplorer.is.entities.data.ConstantValue; -import fr.cemagref.simexplorer.is.entities.data.DataEntity; import fr.cemagref.simexplorer.is.entities.data.Descriptor; import fr.cemagref.simexplorer.is.entities.data.ExplorationApplication; import fr.cemagref.simexplorer.is.entities.data.ExplorationData; @@ -43,7 +44,6 @@ import fr.cemagref.simexplorer.is.entities.data.Structure; import fr.cemagref.simexplorer.is.entities.metadata.MetaData; import fr.cemagref.simexplorer.is.entities.metadata.Version; -import fr.cemagref.simexplorer.is.factories.BaseEntityFactory; import fr.cemagref.simexplorer.is.factories.ContentTypeFactory; /** @@ -213,7 +213,7 @@ * * @throws Exception the exception */ - public <T extends DataEntity> List<T> generateArray(Class<T> clazz) throws Exception { + public <T extends Entity> List<T> generateArray(Class<T> clazz) throws Exception { List<T> elements = new ArrayList<T>(); int i = 3 + r.nextInt(2); for (int j = 0; j < i; j++) { @@ -240,12 +240,12 @@ for (ExplorationData object : datas) { processExplorationData(object); } - ea.setExplorations(datas); + ea.setExplorations(SimpleComposite.castList(datas)); List<Component> components = generateArray(Component.class); for (Component object : components) { processComponent(object); } - ea.setComponents(components); + ea.setComponents(SimpleComposite.castList(components)); return ea; } @@ -341,7 +341,7 @@ for (ConstantValue constantValue : constantValues) { processConstantValue(constantValue); } - explorationData.setConstantValues(constantValues); + explorationData.setConstantValues(SimpleComposite.castList(constantValues)); } Modified: trunk/simexplorer-is/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/actions/ExportElementAction.java =================================================================== --- trunk/simexplorer-is/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/actions/ExportElementAction.java 2008-03-06 21:49:51 UTC (rev 1302) +++ trunk/simexplorer-is/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/actions/ExportElementAction.java 2008-03-07 17:57:20 UTC (rev 1303) @@ -18,6 +18,14 @@ * ##% */ package fr.cemagref.simexplorer.is.ui.swing.actions; +import static org.codelutin.i18n.I18n.n_; + +import java.awt.event.ActionEvent; + +import javax.swing.Action; + +import jaxx.runtime.UIHelper; +import jaxx.runtime.builder.TabModel; import fr.cemagref.simexplorer.is.entities.EntityHelper; import fr.cemagref.simexplorer.is.entities.data.LoggableElement; import fr.cemagref.simexplorer.is.service.StorageService; @@ -29,13 +37,7 @@ import fr.cemagref.simexplorer.is.ui.swing.model.tab.SimExplorerAbstractTabModel; import fr.cemagref.simexplorer.is.ui.swing.model.tab.SynchronizeTabModel; import fr.cemagref.simexplorer.is.ui.swing.ui.SimExplorerTab; -import jaxx.runtime.UIHelper; -import jaxx.runtime.builder.TabModel; -import static org.codelutin.i18n.I18n.n_; -import javax.swing.Action; -import java.awt.event.ActionEvent; - /** * Action pour exporter un élément * Modified: trunk/simexplorer-is/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/model/DataEntityModel.java =================================================================== --- trunk/simexplorer-is/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/model/DataEntityModel.java 2008-03-06 21:49:51 UTC (rev 1302) +++ trunk/simexplorer-is/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/model/DataEntityModel.java 2008-03-07 17:57:20 UTC (rev 1303) @@ -17,8 +17,8 @@ * ##% */ package fr.cemagref.simexplorer.is.ui.swing.model; +import fr.cemagref.simexplorer.is.entities.Entity; import fr.cemagref.simexplorer.is.entities.EntityTypeEnum; -import fr.cemagref.simexplorer.is.entities.data.DataEntity; import fr.cemagref.simexplorer.is.entities.data.ExplorationData; import fr.cemagref.simexplorer.is.entities.data.LoggableElement; import fr.cemagref.simexplorer.is.entities.metadata.MetaData; @@ -53,7 +53,7 @@ protected transient LoggableElement le; /** l'objet selectionne */ - protected transient DataEntity data; + protected transient Entity data; /** les meta du le selectionne */ protected transient MetaData meta; @@ -109,7 +109,7 @@ * @param context the application context * @return the object selected */ - public DataEntity get(SimExplorerContext context) { + public Entity get(SimExplorerContext context) { // acquire loggableElement le = getLe(context); @@ -143,7 +143,7 @@ LoggableElement selectedElement = parent.getLoggableElement(); synch(node.isRemote(), selectedElement); setType(EntityTypeEnum.Result); - setData((DataEntity) node.get()); + setData((Entity) node.get()); } else { synch(node.isRemote(), node.getLoggableElement()); } @@ -182,7 +182,7 @@ this.le = le; } - public void setData(DataEntity data) { + public void setData(Entity data) { this.data = data; } Modified: trunk/simexplorer-is/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/ui/EntityTreeNodeHelper.java =================================================================== --- trunk/simexplorer-is/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/ui/EntityTreeNodeHelper.java 2008-03-06 21:49:51 UTC (rev 1302) +++ trunk/simexplorer-is/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/ui/EntityTreeNodeHelper.java 2008-03-07 17:57:20 UTC (rev 1303) @@ -18,66 +18,49 @@ * ##% */ package fr.cemagref.simexplorer.is.ui.swing.ui; -import static fr.cemagref.simexplorer.is.entities.EntityTypeEnum.Code; -import static fr.cemagref.simexplorer.is.entities.EntityTypeEnum.Component; -import static fr.cemagref.simexplorer.is.entities.EntityTypeEnum.Constant; -import static fr.cemagref.simexplorer.is.entities.EntityTypeEnum.ConstantValue; -import static fr.cemagref.simexplorer.is.entities.EntityTypeEnum.ExplorationData; -import static fr.cemagref.simexplorer.is.entities.EntityTypeEnum.Library; -import static fr.cemagref.simexplorer.is.entities.EntityTypeEnum.Structure; -import fr.cemagref.simexplorer.is.entities.EntityVisitable; -import fr.cemagref.simexplorer.is.entities.SimpleEntityVisitor; -import fr.cemagref.simexplorer.is.entities.data.Code; -import fr.cemagref.simexplorer.is.entities.data.Component; -import fr.cemagref.simexplorer.is.entities.data.Constant; -import fr.cemagref.simexplorer.is.entities.data.ConstantValue; -import fr.cemagref.simexplorer.is.entities.data.ExplorationApplication; -import fr.cemagref.simexplorer.is.entities.data.ExplorationData; -import fr.cemagref.simexplorer.is.entities.data.Library; -import fr.cemagref.simexplorer.is.entities.data.LoggableElement; -import fr.cemagref.simexplorer.is.entities.data.Result; -import fr.cemagref.simexplorer.is.entities.data.Structure; -import fr.cemagref.simexplorer.is.entities.metadata.MetaData; -import fr.cemagref.simexplorer.is.ui.swing.model.EntityTreeNode; +import java.util.ArrayDeque; +import java.util.Deque; import javax.swing.AbstractButton; import javax.swing.JTree; import javax.swing.event.TreeSelectionEvent; import javax.swing.tree.TreePath; -import java.util.Collection; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import fr.cemagref.simexplorer.is.entities.Composite; +import fr.cemagref.simexplorer.is.entities.Entity; +import fr.cemagref.simexplorer.is.entities.EntityVisitable; +import fr.cemagref.simexplorer.is.entities.EntityVisitor; +import fr.cemagref.simexplorer.is.entities.Leaf; +import fr.cemagref.simexplorer.is.entities.data.LoggableElement; +import fr.cemagref.simexplorer.is.ui.swing.model.EntityTreeNode; + /** - * La classe responsable de la création des arbres de {@link fr.cemagref.simexplorer.is.ui.swing.model.EntityTreeNode} - * à partir de {@link LoggableElement} . - * <p/> - * La classe possède une instance cachée par thread qui délègue la construction - * del'arbre de navigation à un visiteur de {@link LoggableElement}. - * <p/> - * + * La classe responsable de la création des arbres de {@link fr.cemagref.simexplorer.is.ui.swing.model.EntityTreeNode} à + * partir de {@link LoggableElement} . <p/> La classe possède une instance cachée par thread qui délègue la construction + * del'arbre de navigation à un visiteur de {@link LoggableElement}. <p/> + * * @author chemit */ public class EntityTreeNodeHelper { protected static Log log = LogFactory.getLog(EntityTreeNodeHelper.class); - + /** L'instance cachée de builder par Thread. */ - protected static final ThreadLocal<EntityVisitorBuilder> builder = - new ThreadLocal<EntityVisitorBuilder>() { - @Override - protected EntityVisitorBuilder initialValue() { - return new EntityVisitorBuilder(); - } - }; + protected static final ThreadLocal<EntityVisitorBuilder> builder = new ThreadLocal<EntityVisitorBuilder>() { + @Override + protected EntityVisitorBuilder initialValue() { + return new EntityVisitorBuilder(); + } + }; /** * Construit un arbre de navigation à partir d'un {@link LoggableElement}. - * - * @param v la donnée à visiter - * @param remote flag pour indiquer si on travaille sur des données locales - * ou en remote. + * + * @param v la donnée à visiter + * @param remote flag pour indiquer si on travaille sur des données locales ou en remote. * @return le noeud parent de l'arbre de nivation construit. */ public static EntityTreeNode build(LoggableElement v, boolean remote) { @@ -86,7 +69,7 @@ EntityTreeNode result; // walk result = instance.visit(v, remote); - log.info(v+" ("+remote+") "); + log.info(v + " (" + remote + ") "); return result; } } @@ -100,9 +83,9 @@ node = (EntityTreeNode) o; } } - return node==null?null:node.getLoggableElement(); + return node == null ? null : node.getLoggableElement(); } - + public static EntityTreeNode getSelectedNode(TreeSelectionEvent e) { TreePath path = e.getNewLeadSelectionPath(); EntityTreeNode node = null; @@ -147,7 +130,8 @@ return node; } - public static void refreshTreeActions(AbstractButton collapseButton, AbstractButton expandButton, EntityTreeNode node) { + public static void refreshTreeActions(AbstractButton collapseButton, AbstractButton expandButton, + EntityTreeNode node) { boolean enabled = node != null && !node.isLeaf() && node.getChildCount() > 0; Object o = enabled ? node.getUserObject() : null; SimExplorerMainUI.UpdateButton(collapseButton, enabled, o); @@ -159,48 +143,40 @@ } /** - * Implantation de {@link SimpleEntityVisitor} pour construire l'arbre - * de navigation d'un {@link LoggableElement}. - * <p/> - * Cette classe est stateless, tous ces états internes doivent être nettoyé - * après une visite, en utilisant la méthode {@link #reset()}. - * <p/> + * Implantation de {@link SimpleEntityVisitor} pour construire l'arbre de navigation d'un {@link LoggableElement}. + * <p/> Cette classe est stateless, tous ces états internes doivent être nettoyé après une visite, en utilisant la + * méthode {@link #reset()}. <p/> */ - public static class EntityVisitorBuilder extends SimpleEntityVisitor { + public static class EntityVisitorBuilder implements EntityVisitor { /** - * le noeud parent de tous les autres. - * <p/> - * Ce noeud est positionné par la méthode + * le noeud parent de tous les autres. <p/> Ce noeud est positionné par la méthode * {@link #markRootNode(EntityTreeNode)}. */ protected EntityTreeNode rootNode; + + /** The node stack. */ + protected Deque<EntityTreeNode> nodeStack; /** - * flag qui indique si on travaille sur des objet locaux ou distants. - * <p/> - * Cette information est conservé dans les nodes pour permettre de gérer - * de manière transparent des objet locaux ou distants. + * flag qui indique si on travaille sur des objet locaux ou distants. <p/> Cette information est conservé dans + * les nodes pour permettre de gérer de manière transparent des objet locaux ou distants. */ protected Boolean remote; - /** les nodes internes utilisés pendant la visite. */ - protected EntityTreeNode explorationApplication, - component, - explorationData, - components, - explorationDatas, - libraries, - constants, - strutures, - codes, - constantValues; - + /** + * Visite un element visitable. + * + * @param v the v + * @param remote the remote + * + * @return the entity tree node + */ public EntityTreeNode visit(EntityVisitable v, boolean remote) { reset(); try { this.remote = remote; - super.visit(v); + visit(v); EntityTreeNode result; result = this.rootNode; return result; @@ -210,111 +186,53 @@ } @Override - public void visitMetaData(MetaData v) { - // do not visit meta data (for the moment we dont need thoses - // informations in navigation tree), but it could be interresting - // for example to display attchments here ? + public void enterComposite(Composite v) { + EntityTreeNode newNode; + newNode = createNode(v, true); + nodeStack.addFirst(newNode); + markRootNode(newNode); } - @Override - public void visitExplorationApplication(ExplorationApplication v) { - markRootNode(explorationApplication = new EntityTreeNode(null, v, remote, true)); - super.visitExplorationApplication(v); + /** + * Creates the node. + * + * @param e the e + * @param allowedChildren the allowed children + * + * @return the entity tree node + */ + private EntityTreeNode createNode(Entity e, boolean allowedChildren) { + EntityTreeNode newNode = new EntityTreeNode(nodeStack.peekFirst(), e, remote, allowedChildren); + return newNode; } @Override - public void visitComponent(Component v) { - markRootNode(component = new EntityTreeNode(components, v, remote, true)); - super.visitComponent(v); + public void exitComposite(Composite v) { + nodeStack.removeFirst(); } @Override - public void visitExplorationData(ExplorationData v) { - markRootNode(explorationData = new EntityTreeNode(explorationDatas, v, remote, true)); - super.visitExplorationData(v); - } - - @Override - public void visitCodes(Collection<Code> vs) { - codes = new EntityTreeNode(component, Code.getLibelles(), remote, true); - super.visitCodes(vs); - } - - @Override - public void visitComponents(Collection<Component> vs) { - components = new EntityTreeNode(explorationApplication, Component.getLibelles(), remote, true); - super.visitComponents(vs); - } - - @Override - public void visitConstants(Collection<Constant> vs) { - constants = new EntityTreeNode(component, Constant.getLibelles(), remote, true); - super.visitConstants(vs); - } - - @Override - public void visitConstantValues(Collection<ConstantValue> vs) { - constantValues = new EntityTreeNode(explorationData, ConstantValue.getLibelles(), remote, true); - super.visitConstantValues(vs); - } - - @Override - public void visitExplorationDatas(Collection<ExplorationData> vs) { - explorationDatas = new EntityTreeNode(explorationApplication, ExplorationData.getLibelles(), remote, true); - super.visitExplorationDatas(vs); - } - - @Override - public void visitLibraries(Collection<Library> vs) { - libraries = new EntityTreeNode(component, Library.getLibelles(), remote, true); - super.visitLibraries(vs); - } - - @Override - public void visitStructures(Collection<Structure> vs) { - strutures = new EntityTreeNode(component, Structure.getLibelles(), remote, true); - super.visitStructures(vs); - } - - @Override - public void visitConstant(Constant v) { - markRootNode(new EntityTreeNode(constants, v, remote, false)); - } - - @Override - public void visitLibrary(Library v) { - markRootNode(new EntityTreeNode(libraries, v, remote, false)); - } - - @Override - public void visitResult(Result v) { + public void visit(EntityVisitable v) { if (v != null) { - markRootNode(new EntityTreeNode(explorationData, v, remote, false)); + // on lance la visite + v.accept(this); } } @Override - public void visitCode(Code v) { - new EntityTreeNode(codes, v, remote, false); + public void visitComposite(Composite v) { + createNode(v, false); } @Override - public void visitConstantValue(ConstantValue v) { - new EntityTreeNode( - new EntityTreeNode(constantValues, v.getConstant().getName(), remote, true), - v.getValue(), remote, false); + public void visitLeaf(Leaf v) { + createNode(v, false); } - @Override - public void visitStructure(Structure v) { - new EntityTreeNode(strutures, v, remote, false); - } - /** - * Tente de marquerle node donné comme noeud ancêtre de tous les autres. - * <p/> - * Le positionnement n'a lieu que si on a pas encore de rootNode. - * + * Tente de marquerle node donné comme noeud ancêtre de tous les autres. <p/> Le positionnement n'a lieu que si + * on a pas encore de rootNode. + * * @param node le node a positionner comme rootNode (si nessecaire) */ protected void markRootNode(EntityTreeNode node) { @@ -324,16 +242,13 @@ } /** - * La méthode pour réinitialiser les états interne de la classe. - * <p/> - * Cette méthode doit être appeler après chaque visite, afin d'assurer - * la propriété stateless de la classe. + * La méthode pour réinitialiser les états interne de la classe. <p/> Cette méthode doit être appeler après + * chaque visite, afin d'assurer la propriété stateless de la classe. */ protected void reset() { + nodeStack = new ArrayDeque<EntityTreeNode>(); remote = null; - rootNode = explorationApplication = explorationDatas = explorationData - = components = component = constants = codes = libraries - = constantValues = null; } + } } Modified: trunk/simexplorer-is/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/ui/ListTabUpdater.java =================================================================== --- trunk/simexplorer-is/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/ui/ListTabUpdater.java 2008-03-06 21:49:51 UTC (rev 1302) +++ trunk/simexplorer-is/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/ui/ListTabUpdater.java 2008-03-07 17:57:20 UTC (rev 1303) @@ -17,17 +17,18 @@ * ##% */ package fr.cemagref.simexplorer.is.ui.swing.ui; +import java.beans.PropertyChangeEvent; +import java.text.SimpleDateFormat; + +import javax.swing.JComboBox; + import fr.cemagref.simexplorer.is.entities.EntityHelper; import fr.cemagref.simexplorer.is.entities.metadata.MetaData; import fr.cemagref.simexplorer.is.ui.swing.SimExplorerContext; import fr.cemagref.simexplorer.is.ui.swing.model.DataEntityModel; +import fr.cemagref.simexplorer.is.ui.swing.model.ListTableModel; import fr.cemagref.simexplorer.is.ui.swing.model.tab.ListTabModel; -import fr.cemagref.simexplorer.is.ui.swing.model.ListTableModel; -import javax.swing.JComboBox; -import java.beans.PropertyChangeEvent; -import java.text.SimpleDateFormat; - /** * La classe responsable du rafrachissement des ui de l'onglet de liste. * Modified: trunk/simexplorer-is/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/ui/SimExplorerMainUI.java =================================================================== --- trunk/simexplorer-is/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/ui/SimExplorerMainUI.java 2008-03-06 21:49:51 UTC (rev 1302) +++ trunk/simexplorer-is/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/ui/SimExplorerMainUI.java 2008-03-07 17:57:20 UTC (rev 1303) @@ -18,6 +18,20 @@ * ##% */ package fr.cemagref.simexplorer.is.ui.swing.ui; +import static org.codelutin.i18n.I18n._; + +import java.awt.event.InputEvent; +import java.awt.event.KeyEvent; +import java.util.regex.Matcher; + +import javax.swing.AbstractButton; +import javax.swing.JComboBox; +import javax.swing.JComponent; +import javax.swing.KeyStroke; +import javax.swing.SwingUtilities; + +import org.codelutin.i18n.LocaleEnum; + import fr.cemagref.simexplorer.is.entities.EntityHelper; import fr.cemagref.simexplorer.is.entities.data.LoggableElement; import fr.cemagref.simexplorer.is.entities.metadata.MetaData; @@ -27,18 +41,7 @@ import fr.cemagref.simexplorer.is.ui.swing.actions.ExportElementAction; import fr.cemagref.simexplorer.is.ui.swing.actions.util.ChangeLocaleAction; import fr.cemagref.simexplorer.is.ui.swing.actions.util.SimExplorerAbstractAction; -import static org.codelutin.i18n.I18n._; -import org.codelutin.i18n.LocaleEnum; -import javax.swing.AbstractButton; -import javax.swing.JComboBox; -import javax.swing.JComponent; -import javax.swing.KeyStroke; -import javax.swing.SwingUtilities; -import java.awt.event.InputEvent; -import java.awt.event.KeyEvent; -import java.util.regex.Matcher; - /** * L'ui principale de l'application * Modified: trunk/simexplorer-is/simexplorer-is-web/src/java/fr/cemagref/simexplorer/is/ui/web/pages/ElementDetail.java =================================================================== --- trunk/simexplorer-is/simexplorer-is-web/src/java/fr/cemagref/simexplorer/is/ui/web/pages/ElementDetail.java 2008-03-06 21:49:51 UTC (rev 1302) +++ trunk/simexplorer-is/simexplorer-is-web/src/java/fr/cemagref/simexplorer/is/ui/web/pages/ElementDetail.java 2008-03-07 17:57:20 UTC (rev 1303) @@ -65,6 +65,7 @@ */ public List<TreeNode> getNodes() { List<TreeNode> nodes = new ArrayList<TreeNode>(); + // FIXME use visitors nodes.add(generateElement()); return nodes; } @@ -148,7 +149,7 @@ */ private List<TreeNode> generateExplorations(ExplorationApplication explorationApplication) { List<TreeNode> res = new ArrayList<TreeNode>(); - for (ExplorationData data : explorationApplication.getExplorations()) { + for (ExplorationData data : explorationApplication.getExplorations().getElements()) { res.add(generateExplorationData(data)); } return res; @@ -193,7 +194,7 @@ * @return the list< tree node> */ private List<TreeNode> generateValues(ExplorationData explorationData) { - List<ConstantValue> values = explorationData.getConstantValues(); + List<ConstantValue> values = explorationData.getConstantValues().getElements(); List<TreeNode> res = new ArrayList<TreeNode>(); for (ConstantValue value : values) { TreeNode node = new TreeNode(); @@ -230,7 +231,7 @@ * @return the list< tree node> */ private List<TreeNode> generateComponents(ExplorationApplication explorationApplication) { - List<Component> components = explorationApplication.getComponents(); + List<Component> components = explorationApplication.getComponents().getElements(); List<TreeNode> res = new ArrayList<TreeNode>(); for (Component component : components) { Modified: trunk/simexplorer-is/simexplorer-is-web/src/java/fr/cemagref/simexplorer/is/ui/web/pages/ElementDownload.java =================================================================== --- trunk/simexplorer-is/simexplorer-is-web/src/java/fr/cemagref/simexplorer/is/ui/web/pages/ElementDownload.java 2008-03-06 21:49:51 UTC (rev 1302) +++ trunk/simexplorer-is/simexplorer-is-web/src/java/fr/cemagref/simexplorer/is/ui/web/pages/ElementDownload.java 2008-03-07 17:57:20 UTC (rev 1303) @@ -104,7 +104,8 @@ String version = st.nextToken(); String attachmentUniqueId = st.nextToken(); - LoggableElement loggableElement = RemoteStorageService.getStorageService().getLoggableElement(getToken(), uuid, version); + LoggableElement loggableElement = RemoteStorageService.getStorageService().getLoggableElement(getToken(), uuid, + version); List<Attachment> attachments = loggableElement.getAttachments(); for (Attachment attachment : attachments) { if (attachment.getUniqueId().equals(attachmentUniqueId)) { @@ -140,6 +141,7 @@ */ public List<TreeNode> getNodes() { List<TreeNode> nodes = new ArrayList<TreeNode>(); + // FIXME use visitors nodes.add(generateNodes()); return nodes; } @@ -205,7 +207,7 @@ */ private List<TreeNode> generateExplorations(ExplorationApplication explorationApplication) { List<TreeNode> res = new ArrayList<TreeNode>(); - for (ExplorationData explorationData : explorationApplication.getExplorations()) { + for (ExplorationData explorationData : explorationApplication.getExplorations().getElements()) { res.add(generateExplorationData(explorationData)); } return res; @@ -245,7 +247,7 @@ * @return the list< tree node> */ private List<TreeNode> generateComponents(ExplorationApplication explorationApplication) { - List<Component> components = explorationApplication.getComponents(); + List<Component> components = explorationApplication.getComponents().getElements(); List<TreeNode> res = new ArrayList<TreeNode>(); for (Component component : components) {