Author: glandais Date: 2008-02-21 14:36:12 +0000 (Thu, 21 Feb 2008) New Revision: 1176 Added: trunk/simexplorer-is/simexplorer-is-entities/src/ trunk/simexplorer-is/simexplorer-is-entities/src/java/ trunk/simexplorer-is/simexplorer-is-entities/src/java/fr/ trunk/simexplorer-is/simexplorer-is-entities/src/java/fr/cemagref/ trunk/simexplorer-is/simexplorer-is-entities/src/java/fr/cemagref/simexplorer/ trunk/simexplorer-is/simexplorer-is-entities/src/java/fr/cemagref/simexplorer/is/ trunk/simexplorer-is/simexplorer-is-entities/src/java/fr/cemagref/simexplorer/is/entities/ 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/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/SimpleEntityVisitor.java trunk/simexplorer-is/simexplorer-is-entities/src/java/fr/cemagref/simexplorer/is/entities/attachment/ trunk/simexplorer-is/simexplorer-is-entities/src/java/fr/cemagref/simexplorer/is/entities/data/ trunk/simexplorer-is/simexplorer-is-entities/src/java/fr/cemagref/simexplorer/is/entities/metadata/ trunk/simexplorer-is/simexplorer-is-entities/src/site/ trunk/simexplorer-is/simexplorer-is-entities/src/xmi/ trunk/simexplorer-is/simexplorer-is-entities/src/xmi/simexplorer-si-entities.zargo Modified: trunk/simexplorer-is/simexplorer-is-entities/src/java/fr/cemagref/simexplorer/is/entities/attachment/ContentType.java Log: Resplit Copied: trunk/simexplorer-is/simexplorer-is-entities/src/java/fr/cemagref/simexplorer/is/entities/BaseEntity.java (from rev 1157, trunk/simexplorer-is/simexplorer-is-storage/src/java/fr/cemagref/simexplorer/is/entities/BaseEntity.java) =================================================================== --- trunk/simexplorer-is/simexplorer-is-entities/src/java/fr/cemagref/simexplorer/is/entities/BaseEntity.java (rev 0) +++ trunk/simexplorer-is/simexplorer-is-entities/src/java/fr/cemagref/simexplorer/is/entities/BaseEntity.java 2008-02-21 14:36:12 UTC (rev 1176) @@ -0,0 +1,35 @@ +/* +* ##% 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 { +} Copied: trunk/simexplorer-is/simexplorer-is-entities/src/java/fr/cemagref/simexplorer/is/entities/EntityHelper.java (from rev 1157, trunk/simexplorer-is/simexplorer-is-storage/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-02-21 14:36:12 UTC (rev 1176) @@ -0,0 +1,168 @@ +/* +* ##% 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 static org.codelutin.i18n.I18n._; +import static org.codelutin.i18n.I18n.n_; + +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 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 static enum Type { + Attachment(false,n_("simexplorer.common.attachment"), n_("simexplorer.common.attachments")), + Code(false,n_("simexplorer.common.code"), n_("simexplorer.common.codes")), + Component(true,n_("simexplorer.common.component"), n_("simexplorer.common.components")), + Constant(false,n_("simexplorer.common.constant"), n_("simexplorer.common.constants")), + ConstantValue(false,n_("simexplorer.common.constantvalue"), n_("simexplorer.common.constantvalues")), + ExplorationApplication(true,n_("simexplorer.common.explorationapplication"), n_("simexplorer.common.explorationapplications")), + ExplorationData(true,n_("simexplorer.common.explorationdata"), n_("simexplorer.common.explorationdatas")), + Library(true,n_("simexplorer.common.library"), n_("simexplorer.common.libraries")), + Repository(false,n_("simexplorer.common.repository"), n_("simexplorer.common.repositories")), + Result(false,n_("simexplorer.common.result"), n_("simexplorer.common.results")), + Structure(false,n_("simexplorer.common.structure"), n_("simexplorer.common.structures")); + + private String i18nKey; + private String i18nKeys; + private boolean le; + + public static String getLibelle(Object entity) { + if (entity == null) { + return ""; + } + if (entity instanceof LoggableElement) { + return getLibelle((LoggableElement) entity); + } + return getLibelle(entity.getClass().getSimpleName()); + } + + public static String getLibelle(LoggableElement element) { + return element == null ? "" : getLibelle(element.getMetaData()); + } + + public static String getLibelle(MetaData data) { + return data == null ? "" : getLibelle(data.getType()); + } + + public String getLibelle() { + return _(i18nKey); + } + + public String getLibelles() { + return _(i18nKeys); + } + + public boolean isLe() { + return le; + } + + protected static String getLibelle(String type) { + if (type != null) { + try { + Type type1 = Type.valueOf(type); + return type1.getLibelle(); + } catch (IllegalArgumentException e) { + //TODO log it + System.err.println(e.getMessage()); + } + } + return ""; + } + + private Type(boolean isLE,String i18nKey, String i18nKeys) { + this.le = isLE; + this.i18nKey = i18nKey; + this.i18nKeys = i18nKeys; + } + } + + /** + * Une énumération pour définir les actions possibles sur les 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.getType()); + } + + 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 + } +} Copied: trunk/simexplorer-is/simexplorer-is-entities/src/java/fr/cemagref/simexplorer/is/entities/EntityVisitable.java (from rev 1157, trunk/simexplorer-is/simexplorer-is-storage/src/java/fr/cemagref/simexplorer/is/entities/EntityVisitable.java) =================================================================== --- trunk/simexplorer-is/simexplorer-is-entities/src/java/fr/cemagref/simexplorer/is/entities/EntityVisitable.java (rev 0) +++ trunk/simexplorer-is/simexplorer-is-entities/src/java/fr/cemagref/simexplorer/is/entities/EntityVisitable.java 2008-02-21 14:36:12 UTC (rev 1176) @@ -0,0 +1,36 @@ +/* +* ##% 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; + +/** + * Le contrat a respecter par un entity pour être visiter par un + * {@link EntityVisitor} visiteur. + * + * @author chemit + * @see EntityVisitor + */ +public interface EntityVisitable { + /** + * Méthode à implanter dans chaque visitable pour indiquer ce que + * le visiteur doit visiter. + * + * @param visitor le visiteur + */ + void accept(EntityVisitor visitor); + +} Copied: trunk/simexplorer-is/simexplorer-is-entities/src/java/fr/cemagref/simexplorer/is/entities/EntityVisitor.java (from rev 1157, trunk/simexplorer-is/simexplorer-is-storage/src/java/fr/cemagref/simexplorer/is/entities/EntityVisitor.java) =================================================================== --- trunk/simexplorer-is/simexplorer-is-entities/src/java/fr/cemagref/simexplorer/is/entities/EntityVisitor.java (rev 0) +++ trunk/simexplorer-is/simexplorer-is-entities/src/java/fr/cemagref/simexplorer/is/entities/EntityVisitor.java 2008-02-21 14:36:12 UTC (rev 1176) @@ -0,0 +1,210 @@ +/* +* ##% 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; + +/** + * Le contrat à respecter pour un visiteur à visiter des {@link EntityVisitable}.. + * + * @author chemit + * @see EntityVisitable + * @see SimpleEntityVisitor + */ +public interface EntityVisitor { + + /** + * La méthode de base pour visiter n'importe quel {@link EntityVisitable}. + * + * @param v le visité + */ + void visit(EntityVisitable v); + + /** + * Pour visiter une exploration d'application + * + * @param v le visité + * @see ExplorationApplication + */ + void visitExplorationApplication(ExplorationApplication v); + + /** + * Pour visiter un Component + * + * @param v le visité + * @see Component + */ + void visitComponent(Component v); + + /** + * Pour visiter une ExplorationApplication + * + * @param v le visité + * @see ExplorationApplication + */ + void visitExplorationData(ExplorationData v); + + /** + * Pour visiter un Library + * + * @param v le visité + * @see Library + */ + 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); +} Copied: trunk/simexplorer-is/simexplorer-is-entities/src/java/fr/cemagref/simexplorer/is/entities/SimpleEntityVisitor.java (from rev 1157, trunk/simexplorer-is/simexplorer-is-storage/src/java/fr/cemagref/simexplorer/is/entities/SimpleEntityVisitor.java) =================================================================== --- trunk/simexplorer-is/simexplorer-is-entities/src/java/fr/cemagref/simexplorer/is/entities/SimpleEntityVisitor.java (rev 0) +++ trunk/simexplorer-is/simexplorer-is-entities/src/java/fr/cemagref/simexplorer/is/entities/SimpleEntityVisitor.java 2008-02-21 14:36:12 UTC (rev 1176) @@ -0,0 +1,167 @@ +/* +* ##% 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) { + 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); + } + } + } +} Copied: trunk/simexplorer-is/simexplorer-is-entities/src/java/fr/cemagref/simexplorer/is/entities/attachment (from rev 1157, trunk/simexplorer-is/simexplorer-is-storage/src/java/fr/cemagref/simexplorer/is/entities/attachment) Modified: trunk/simexplorer-is/simexplorer-is-entities/src/java/fr/cemagref/simexplorer/is/entities/attachment/ContentType.java =================================================================== --- trunk/simexplorer-is/simexplorer-is-storage/src/java/fr/cemagref/simexplorer/is/entities/attachment/ContentType.java 2008-02-20 23:12:38 UTC (rev 1157) +++ trunk/simexplorer-is/simexplorer-is-entities/src/java/fr/cemagref/simexplorer/is/entities/attachment/ContentType.java 2008-02-21 14:36:12 UTC (rev 1176) @@ -17,8 +17,6 @@ * ##% */ package fr.cemagref.simexplorer.is.entities.attachment; -import fr.cemagref.simexplorer.is.exceptions.SimExplorerException; - import java.io.InputStream; import java.io.Reader; import java.io.Serializable; @@ -35,9 +33,9 @@ * * @param is Input stream * @return Indexable text - * @throws SimExplorerException the exception + * @throws Exception the exception */ - Reader renderToText(InputStream is) throws SimExplorerException; + Reader renderToText(InputStream is) throws Exception; /** * Gets the mime type. Copied: trunk/simexplorer-is/simexplorer-is-entities/src/java/fr/cemagref/simexplorer/is/entities/data (from rev 1157, trunk/simexplorer-is/simexplorer-is-storage/src/java/fr/cemagref/simexplorer/is/entities/data) Copied: trunk/simexplorer-is/simexplorer-is-entities/src/java/fr/cemagref/simexplorer/is/entities/metadata (from rev 1157, trunk/simexplorer-is/simexplorer-is-storage/src/java/fr/cemagref/simexplorer/is/entities/metadata) Added: trunk/simexplorer-is/simexplorer-is-entities/src/xmi/simexplorer-si-entities.zargo =================================================================== (Binary files differ) Property changes on: trunk/simexplorer-is/simexplorer-is-entities/src/xmi/simexplorer-si-entities.zargo ___________________________________________________________________ Name: svn:mime-type + application/octet-stream