ingo@3: package de.intevation.flys.client.shared.model;
ingo@3:
ingo@17: import java.util.ArrayList;
ingo@3: import java.util.Date;
ingo@67: import java.util.HashMap;
ingo@17: import java.util.List;
ingo@67: import java.util.Map;
ingo@3:
ingo@3:
ingo@3: /**
ingo@3: * The default implementation of a {@link Collection}.
ingo@3: *
ingo@3: * @author Ingo Weinzierl
ingo@3: */
ingo@3: public class DefaultCollection implements Collection {
ingo@3:
ingo@3: /** The uuid of the collection. */
ingo@3: protected String uuid;
ingo@3:
ingo@95: /** The name of the collection.*/
ingo@95: protected String name;
ingo@95:
ingo@95: /** The creation time of this collection.*/
ingo@95: protected Date creation;
ingo@95:
ingo@587: /** The time to live of the collection. If this value is 0, it will never
ingo@587: * die.*/
ingo@587: protected long ttl;
ingo@587:
ingo@17: /** The list of artifacts that are managed by this Collection.*/
ingo@67: protected List items;
ingo@67:
ingo@524: protected Map themeLists;
ingo@524:
ingo@67:
ingo@67: /**
ingo@67: * Constructor without arguments is necessary for GWT.
ingo@67: */
ingo@67: public DefaultCollection() {
ingo@67: }
ingo@17:
ingo@3:
ingo@3: /**
ingo@3: * Creates a new DefaultCollection with a UUID.
ingo@3: *
ingo@3: * @param uuid The UUID.
ingo@3: */
ingo@587: public DefaultCollection(String uuid, long ttl) {
ingo@524: this.uuid = uuid;
ingo@587: this.ttl = ttl;
ingo@524: this.items = new ArrayList();
ingo@524: this.themeLists = new HashMap();
ingo@524: }
ingo@524:
ingo@524:
ingo@587: public DefaultCollection(
ingo@587: String uuid,
ingo@587: long ttl,
ingo@587: Map themeLists)
ingo@587: {
ingo@587: this(uuid, ttl);
ingo@524: this.themeLists = themeLists;
ingo@3: }
ingo@3:
ingo@3:
ingo@95: /**
ingo@95: * Creates a new DefaultCollection with uuid and name.
ingo@95: *
ingo@95: * @param uuid The identifier of this collection.
ingo@95: * @param name The name of this collection.
ingo@95: */
ingo@587: public DefaultCollection(String uuid, long ttl, String name) {
ingo@587: this(uuid, ttl);
ingo@95:
ingo@95: this.name = name;
ingo@95: }
ingo@95:
ingo@95:
ingo@95: /**
ingo@95: * Creates a new DefaultCollection with uuid and name.
ingo@95: *
ingo@95: * @param uuid The identifier of this collection.
ingo@95: * @param name The name of this collection.
ingo@95: * @param creation The creation time.
ingo@95: */
ingo@587: public DefaultCollection(String uuid, long ttl, String name, Date creation){
ingo@587: this(uuid, ttl, name);
ingo@95:
ingo@95: this.creation = creation;
ingo@95: }
ingo@95:
ingo@95:
ingo@5: public String identifier() {
ingo@5: return uuid;
ingo@5: }
ingo@5:
ingo@5:
ingo@95: public Date getCreationTime() {
ingo@95: return creation;
ingo@95: }
ingo@95:
ingo@95:
ingo@3: public Date getLastAccess() {
ingo@3: return new Date();
ingo@3: }
ingo@3:
ingo@3:
ingo@587: public long getTTL() {
ingo@587: return ttl;
ingo@587: }
ingo@587:
ingo@587:
ingo@597: public void setTTL(long ttl) {
ingo@597: this.ttl = ttl;
ingo@597: }
ingo@597:
ingo@597:
ingo@3: public String getName() {
ingo@95: return name;
ingo@3: }
ingo@17:
ingo@17:
ingo@597: public void setName(String name) {
ingo@597: this.name = name;
ingo@597: }
ingo@597:
ingo@597:
ingo@67: public void addItem(CollectionItem item) {
ingo@67: if (item != null) {
ingo@67: items.add(item);
ingo@17: }
ingo@17: }
ingo@17:
ingo@17:
ingo@67: public int getItemLength() {
ingo@67: return items.size();
ingo@17: }
ingo@17:
ingo@17:
ingo@67: public CollectionItem getItem(int idx) {
ingo@67: if (idx >= getItemLength()) {
ingo@67: return null;
ingo@67: }
ingo@67:
ingo@67: return items.get(idx);
ingo@67: }
ingo@67:
ingo@67:
ingo@67: public Map getOutputModes() {
ingo@67: Map modes = new HashMap();
ingo@67:
ingo@67: for (CollectionItem item: items) {
ingo@67: List itemModes = item.getOutputModes();
ingo@67:
ingo@67: if (itemModes != null) {
ingo@67: for (OutputMode itemMode: itemModes) {
ingo@67: String name = itemMode.getName();
ingo@67: if (!modes.containsKey(name)) {
ingo@67: // we dont want duplicated OutputModes in our result.
ingo@67: modes.put(name, itemMode);
ingo@67: }
ingo@67: }
ingo@67: }
ingo@67: }
ingo@67:
ingo@67: return modes;
ingo@17: }
ingo@524:
ingo@524:
ingo@524: public ThemeList getThemeList(String outName) {
ingo@524: if (themeLists != null) {
ingo@524: return themeLists.get(outName);
ingo@524: }
ingo@524:
ingo@524: return null;
ingo@524: }
ingo@3: }
ingo@3: // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :