Author: glandais Date: 2008-03-08 00:27:01 +0000 (Sat, 08 Mar 2008) New Revision: 1305 Added: trunk/simexplorer-is/simexplorer-is-entities/src/java/fr/cemagref/simexplorer/is/entities/composite/ trunk/simexplorer-is/simexplorer-is-entities/src/java/fr/cemagref/simexplorer/is/entities/composite/Attachments.java trunk/simexplorer-is/simexplorer-is-entities/src/java/fr/cemagref/simexplorer/is/entities/composite/Codes.java trunk/simexplorer-is/simexplorer-is-entities/src/java/fr/cemagref/simexplorer/is/entities/composite/Components.java trunk/simexplorer-is/simexplorer-is-entities/src/java/fr/cemagref/simexplorer/is/entities/composite/ConstantValues.java trunk/simexplorer-is/simexplorer-is-entities/src/java/fr/cemagref/simexplorer/is/entities/composite/Constants.java trunk/simexplorer-is/simexplorer-is-entities/src/java/fr/cemagref/simexplorer/is/entities/composite/Descriptors.java trunk/simexplorer-is/simexplorer-is-entities/src/java/fr/cemagref/simexplorer/is/entities/composite/ExplorationDatas.java trunk/simexplorer-is/simexplorer-is-entities/src/java/fr/cemagref/simexplorer/is/entities/composite/Libraries.java trunk/simexplorer-is/simexplorer-is-entities/src/java/fr/cemagref/simexplorer/is/entities/composite/SimpleComposite.java trunk/simexplorer-is/simexplorer-is-entities/src/java/fr/cemagref/simexplorer/is/entities/composite/Structures.java Removed: trunk/simexplorer-is/simexplorer-is-entities/src/java/fr/cemagref/simexplorer/is/entities/SimpleComposite.java Log: SimpleComposite is now abstract, allowing retrieving children class type SimpleComposite implements List interface Subclasses are final See http://serdom.szn.pl/ser/2007/03/25/java-generics-instantiating-objects-of-t... Deleted: 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 2008-03-08 00:25:39 UTC (rev 1304) +++ trunk/simexplorer-is/simexplorer-is-entities/src/java/fr/cemagref/simexplorer/is/entities/SimpleComposite.java 2008-03-08 00:27:01 UTC (rev 1305) @@ -1,119 +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.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; - } - - - -} Added: trunk/simexplorer-is/simexplorer-is-entities/src/java/fr/cemagref/simexplorer/is/entities/composite/Attachments.java =================================================================== --- trunk/simexplorer-is/simexplorer-is-entities/src/java/fr/cemagref/simexplorer/is/entities/composite/Attachments.java (rev 0) +++ trunk/simexplorer-is/simexplorer-is-entities/src/java/fr/cemagref/simexplorer/is/entities/composite/Attachments.java 2008-03-08 00:27:01 UTC (rev 1305) @@ -0,0 +1,24 @@ +/* +* ##% 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.composite; + +import fr.cemagref.simexplorer.is.entities.attachment.Attachment; + +public final class Attachments extends SimpleComposite<Attachment> { + +} Added: trunk/simexplorer-is/simexplorer-is-entities/src/java/fr/cemagref/simexplorer/is/entities/composite/Codes.java =================================================================== --- trunk/simexplorer-is/simexplorer-is-entities/src/java/fr/cemagref/simexplorer/is/entities/composite/Codes.java (rev 0) +++ trunk/simexplorer-is/simexplorer-is-entities/src/java/fr/cemagref/simexplorer/is/entities/composite/Codes.java 2008-03-08 00:27:01 UTC (rev 1305) @@ -0,0 +1,24 @@ +/* +* ##% 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.composite; + +import fr.cemagref.simexplorer.is.entities.data.Code; + +public final class Codes extends SimpleComposite<Code> { + +} Added: trunk/simexplorer-is/simexplorer-is-entities/src/java/fr/cemagref/simexplorer/is/entities/composite/Components.java =================================================================== --- trunk/simexplorer-is/simexplorer-is-entities/src/java/fr/cemagref/simexplorer/is/entities/composite/Components.java (rev 0) +++ trunk/simexplorer-is/simexplorer-is-entities/src/java/fr/cemagref/simexplorer/is/entities/composite/Components.java 2008-03-08 00:27:01 UTC (rev 1305) @@ -0,0 +1,24 @@ +/* +* ##% 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.composite; + +import fr.cemagref.simexplorer.is.entities.data.Component; + +public final class Components extends SimpleComposite<Component> { + +} Added: trunk/simexplorer-is/simexplorer-is-entities/src/java/fr/cemagref/simexplorer/is/entities/composite/ConstantValues.java =================================================================== --- trunk/simexplorer-is/simexplorer-is-entities/src/java/fr/cemagref/simexplorer/is/entities/composite/ConstantValues.java (rev 0) +++ trunk/simexplorer-is/simexplorer-is-entities/src/java/fr/cemagref/simexplorer/is/entities/composite/ConstantValues.java 2008-03-08 00:27:01 UTC (rev 1305) @@ -0,0 +1,24 @@ +/* +* ##% 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.composite; + +import fr.cemagref.simexplorer.is.entities.data.ConstantValue; + +public final class ConstantValues extends SimpleComposite<ConstantValue> { + +} Added: trunk/simexplorer-is/simexplorer-is-entities/src/java/fr/cemagref/simexplorer/is/entities/composite/Constants.java =================================================================== --- trunk/simexplorer-is/simexplorer-is-entities/src/java/fr/cemagref/simexplorer/is/entities/composite/Constants.java (rev 0) +++ trunk/simexplorer-is/simexplorer-is-entities/src/java/fr/cemagref/simexplorer/is/entities/composite/Constants.java 2008-03-08 00:27:01 UTC (rev 1305) @@ -0,0 +1,24 @@ +/* +* ##% 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.composite; + +import fr.cemagref.simexplorer.is.entities.data.Constant; + +public final class Constants extends SimpleComposite<Constant> { + +} Added: trunk/simexplorer-is/simexplorer-is-entities/src/java/fr/cemagref/simexplorer/is/entities/composite/Descriptors.java =================================================================== --- trunk/simexplorer-is/simexplorer-is-entities/src/java/fr/cemagref/simexplorer/is/entities/composite/Descriptors.java (rev 0) +++ trunk/simexplorer-is/simexplorer-is-entities/src/java/fr/cemagref/simexplorer/is/entities/composite/Descriptors.java 2008-03-08 00:27:01 UTC (rev 1305) @@ -0,0 +1,24 @@ +/* +* ##% 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.composite; + +import fr.cemagref.simexplorer.is.entities.data.Descriptor; + +public final class Descriptors extends SimpleComposite<Descriptor> { + +} Added: trunk/simexplorer-is/simexplorer-is-entities/src/java/fr/cemagref/simexplorer/is/entities/composite/ExplorationDatas.java =================================================================== --- trunk/simexplorer-is/simexplorer-is-entities/src/java/fr/cemagref/simexplorer/is/entities/composite/ExplorationDatas.java (rev 0) +++ trunk/simexplorer-is/simexplorer-is-entities/src/java/fr/cemagref/simexplorer/is/entities/composite/ExplorationDatas.java 2008-03-08 00:27:01 UTC (rev 1305) @@ -0,0 +1,24 @@ +/* +* ##% 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.composite; + +import fr.cemagref.simexplorer.is.entities.data.ExplorationData; + +public final class ExplorationDatas extends SimpleComposite<ExplorationData> { + +} Added: trunk/simexplorer-is/simexplorer-is-entities/src/java/fr/cemagref/simexplorer/is/entities/composite/Libraries.java =================================================================== --- trunk/simexplorer-is/simexplorer-is-entities/src/java/fr/cemagref/simexplorer/is/entities/composite/Libraries.java (rev 0) +++ trunk/simexplorer-is/simexplorer-is-entities/src/java/fr/cemagref/simexplorer/is/entities/composite/Libraries.java 2008-03-08 00:27:01 UTC (rev 1305) @@ -0,0 +1,24 @@ +/* +* ##% 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.composite; + +import fr.cemagref.simexplorer.is.entities.data.Library; + +public final class Libraries extends SimpleComposite<Library> { + +} Copied: trunk/simexplorer-is/simexplorer-is-entities/src/java/fr/cemagref/simexplorer/is/entities/composite/SimpleComposite.java (from rev 1303, 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/composite/SimpleComposite.java (rev 0) +++ trunk/simexplorer-is/simexplorer-is-entities/src/java/fr/cemagref/simexplorer/is/entities/composite/SimpleComposite.java 2008-03-08 00:27:01 UTC (rev 1305) @@ -0,0 +1,241 @@ +/* +* ##% 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.composite; + +import java.lang.reflect.ParameterizedType; +import java.lang.reflect.Type; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Iterator; +import java.util.List; +import java.util.ListIterator; + +import fr.cemagref.simexplorer.is.entities.Composite; +import fr.cemagref.simexplorer.is.entities.Entity; +import fr.cemagref.simexplorer.is.entities.EntityTypeEnum; + +/** + * The Class SimpleComposite. + */ +public abstract class SimpleComposite<E extends Entity> extends Composite implements List<E> { + + /** The Constant serialVersionUID. */ + private static final long serialVersionUID = -2085840703844194573L; + + /** The children. */ + private List<E> elements; + + /** + * Instantiates a new simple composite. + */ + public SimpleComposite() { + super(); + this.elements = new ArrayList<E>(); + } + + /** + * Instantiates a new simple composite. + * + * @param elements the elements + */ + public SimpleComposite(List<E> elements) { + super(); + this.elements = elements; + } + + /* (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; + } + + @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; + } + + public Class<E> getChildrenClass() { + Class<E> eClass = null; + + Type type = getClass().getGenericSuperclass(); + if (type instanceof ParameterizedType) { + ParameterizedType paramType = (ParameterizedType) type; + eClass = (Class<E>) paramType.getActualTypeArguments()[0]; + return eClass; + } + + return null; + } + + @Override + public String toString() { + Class<E> eClass = getChildrenClass(); + + if (eClass != null) { + EntityTypeEnum entityType = EntityTypeEnum.getEntityType(eClass); + if (entityType != null) { + return entityType.getLibelles(); + } + } + return super.toString(); + } + + /** + * Delegate List methods + */ + + @Override + public boolean add(E e) { + return elements.add(e); + } + + @Override + public void add(int index, E element) { + elements.add(index, element); + } + + @Override + public boolean addAll(Collection<? extends E> c) { + return elements.addAll(c); + } + + @Override + public boolean addAll(int index, Collection<? extends E> c) { + return elements.addAll(index, c); + } + + @Override + public void clear() { + elements.clear(); + } + + @Override + public boolean contains(Object o) { + return elements.contains(o); + } + + @Override + public boolean containsAll(Collection<?> c) { + return elements.containsAll(c); + } + + @Override + public E get(int index) { + return elements.get(index); + } + + @Override + public int indexOf(Object o) { + return elements.indexOf(o); + } + + @Override + public boolean isEmpty() { + return elements.isEmpty(); + } + + @Override + public Iterator<E> iterator() { + return elements.iterator(); + } + + @Override + public int lastIndexOf(Object o) { + return elements.lastIndexOf(o); + } + + @Override + public ListIterator<E> listIterator() { + return elements.listIterator(); + } + + @Override + public ListIterator<E> listIterator(int index) { + return elements.listIterator(index); + } + + @Override + public boolean remove(Object o) { + return elements.remove(o); + } + + @Override + public E remove(int index) { + return elements.remove(index); + } + + @Override + public boolean removeAll(Collection<?> c) { + return elements.removeAll(c); + } + + @Override + public boolean retainAll(Collection<?> c) { + return elements.retainAll(c); + } + + @Override + public E set(int index, E element) { + return elements.set(index, element); + } + + @Override + public int size() { + return elements.size(); + } + + @Override + public List<E> subList(int fromIndex, int toIndex) { + return elements.subList(fromIndex, toIndex); + } + + @Override + public Object[] toArray() { + return elements.toArray(); + } + + @Override + public <T> T[] toArray(T[] a) { + return elements.toArray(a); + } + +} Added: trunk/simexplorer-is/simexplorer-is-entities/src/java/fr/cemagref/simexplorer/is/entities/composite/Structures.java =================================================================== --- trunk/simexplorer-is/simexplorer-is-entities/src/java/fr/cemagref/simexplorer/is/entities/composite/Structures.java (rev 0) +++ trunk/simexplorer-is/simexplorer-is-entities/src/java/fr/cemagref/simexplorer/is/entities/composite/Structures.java 2008-03-08 00:27:01 UTC (rev 1305) @@ -0,0 +1,24 @@ +/* +* ##% 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.composite; + +import fr.cemagref.simexplorer.is.entities.data.Structure; + +public final class Structures extends SimpleComposite<Structure> { + +}