Mercurial > dive4elements > framework
changeset 119:3bb121d5b0b7
Added a default implementation of an ArtifactCollection and a User.
artifacts/trunk@1342 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Ingo Weinzierl <ingo.weinzierl@intevation.de> |
---|---|
date | Tue, 01 Mar 2011 15:58:09 +0000 |
parents | 0e0c27bc0b90 |
children | c030895edfcb |
files | ChangeLog artifact-database/src/main/java/de/intevation/artifactdatabase/DefaultArtifactCollection.java artifact-database/src/main/java/de/intevation/artifactdatabase/DefaultUser.java |
diffstat | 3 files changed, 388 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/ChangeLog Tue Mar 01 14:57:50 2011 +0000 +++ b/ChangeLog Tue Mar 01 15:58:09 2011 +0000 @@ -1,3 +1,11 @@ +2011-03-01 Ingo Weinzierl <ingo@intevation.de> + + * artifact-database/src/main/java/de/intevation/artifactdatabase/DefaultArtifactCollection.java: + A default implementation of a ArtifactCollection. + + * artifact-database/src/main/java/de/intevation/artifactdatabase/DefaultUser.java: + A default implementation of a User. + 2011-03-01 Sascha L. Teichmann <sascha.teichmann@intevation.de> * artifacts/src/main/java/de/intevation/artifacts/ArtifactCollection.java:
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/artifact-database/src/main/java/de/intevation/artifactdatabase/DefaultArtifactCollection.java Tue Mar 01 15:58:09 2011 +0000 @@ -0,0 +1,282 @@ +/* + * Copyright (c) 2011 by Intevation GmbH + * + * This program is free software under the LGPL (>=v2.1) + * Read the file LGPL.txt coming with the software for details + * or visit http://www.gnu.org/licenses/ if it does not exist. + */ +package de.intevation.artifactdatabase; + +import java.io.IOException; +import java.io.OutputStream; +import java.util.ArrayList; +import java.util.Date; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.apache.log4j.Logger; + +import org.w3c.dom.Document; + +import de.intevation.artifacts.Artifact; +import de.intevation.artifacts.ArtifactCollection; +import de.intevation.artifacts.ArtifactCollectionFactory; +import de.intevation.artifacts.CallContext; +import de.intevation.artifacts.User; + + +/** + * Trivial implementation of an artifact collection. Useful to be subclassed. + * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> + */ +public class DefaultArtifactCollection +implements ArtifactCollection +{ + /** The logger used in this class.*/ + private static Logger logger = + Logger.getLogger(DefaultArtifactCollection.class); + + /** + * The identifier of the collection. + */ + protected String identifier; + + /** + * The owner of this collection. + */ + protected User user; + + /** + * The artifacts stored in this collection. + */ + protected List<Artifact> artifacts; + + /** + * The attributes used for the artifacts stored in this collection. The key + * of this map represents the identifier of the artifact which the attribute + * belong to. + */ + protected Map<String, Document> attributes; + + /** The creation time of this collection.*/ + protected Date creationTime; + + + /** + * Default constructor. + */ + public DefaultArtifactCollection() { + } + + + /** + * When created by a factory this method is called to + * initialize the collection. + * @param identifier The identifier from collection database + * @param factory The factory which created this collection. + * @param context The global context of the runtime system. + * @param data The data which can be use to setup a collection with + * more details. + */ + public void setup( + String identifier, + ArtifactCollectionFactory factory, + Object context, + Document data) + { + logger.debug("DefaultArtifactCollection.setup: " + identifier); + + artifacts = new ArrayList<Artifact>(); + attributes = new HashMap<String, Document>(); + + setIdentifier(identifier); + } + + + /** + * Set a new identifier for this collection. + * @param identifier New identifier for this collection. + */ + public void setIdentifier(String identifier) { + this.identifier = identifier; + } + + + /** + * Identify this collection. + * @return Returns unique string to identify this collection globally. + */ + public String identifier() { + return identifier; + } + + + /** + * Set a new owner of this collection. + * @param user New owner for this collection. + */ + public void setUser(User user) { + this.user = user; + } + + + /** + * Identify the owner of the collection. + * @return Returns owner of the collection. + */ + public User getUser() { + return user; + } + + + /** + * Returns the creation time of the collection. + * + * @return the creation time of the collection. + */ + public Date getCreationTime() { + return creationTime; + } + + + /** + * Sets the creation time of the collection. + * + * @param creationTime The new creation time. + */ + public void setCreationTime(Date creationTime) { + this.creationTime = creationTime; + } + + + /** + * Called from artifact database when an artifact is + * going to be removed from system. + * @param context The global context of the runtime system. + */ + public void endOfLife(Object context) { + logger.debug("DefaultArtifactCollection.endOfLife"); + } + + + /** + * Internal hash of this collection. + * @return Returns hash that should stay the same if the internal + * value has not changed. Useful for caching + */ + public String hash() { + logger.debug("DefaultArtifactCollection.hash"); + + return String.valueOf(hashCode()); + } + + + /** + * Called from artifact database before an artifact is + * going to be exported as xml document. + * @param context The global context of the runtime system. + */ + public void cleanup(Object context) { + logger.debug("DefaultArtifactCollection.cleanup"); + } + + + /** + * Adds a new artifact to this collection. + * + * @param artifact The new artifact. + * @param attribute The attributes used for this artifact. + * @param context The CallContext. + */ + public void addArtifact( + Artifact artifact, + Document attribute, + CallContext context) + { + logger.debug("DefaultArtifactCollection.addArtifact"); + + artifacts.add(artifact); + attributes.put(artifact.identifier(), attribute); + } + + + /** + * Removes the given artifact from this collection. + * + * @param artifact The artifact that should be removed. + * @param context The CallContext. + */ + public void removeArtifact(Artifact artifact, CallContext context) { + logger.debug("DefaultArtifactCollection.removeArtifact"); + + if (artifact == null) { + return; + } + + artifacts.remove(artifact); + attributes.remove(artifact.identifier()); + } + + + /** + * Returns a list of artifacts that are stored in this collection. + * + * @param context The CallContext. + * + * @return the list of artifacts stored in this collection. + */ + public Artifact[] getArtifacts(CallContext context) { + logger.debug("DefaultArtifactCollection.getArtifacts"); + + return (Artifact[]) artifacts.toArray(); + } + + + /** + * Returns the attribute document for the given artifact. + * + * @param artifact The artifact. + * @param context The CallContext. + * + * @return a document that contains the attributes of the artifact. + */ + public Document getAttribute(Artifact artifact, CallContext context) { + logger.debug("DefaultArtifactCollection.getAttribute"); + + return attributes.get(artifact.identifier()); + } + + + /** + * Set the attribute for the given artifact. + * + * @param artifact The artifact of the attribute. + * @param document The new attribute of the artifact. + * @param context The CallContext. + */ + public void setAttribute( + Artifact artifact, + Document document, + CallContext context) + { + logger.debug("DefaultArtifactCollection.setAttribute"); + + attributes.put(artifact.identifier(), document); + } + + + /** + * Produce output for this collection. + * @param format Specifies the format of the output. + * @param out Stream to write the result data to. + * @param context The global context of the runtime system. + * @throws IOException Thrown if an I/O occurs. + */ + public void out(Document format, OutputStream out, CallContext context) + throws IOException + { + logger.debug("DefaultArtifactCollection.out"); + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/artifact-database/src/main/java/de/intevation/artifactdatabase/DefaultUser.java Tue Mar 01 15:58:09 2011 +0000 @@ -0,0 +1,98 @@ +/* + * Copyright (c) 2011 by Intevation GmbH + * + * This program is free software under the LGPL (>=v2.1) + * Read the file LGPL.txt coming with the software for details + * or visit http://www.gnu.org/licenses/ if it does not exist. + */ +package de.intevation.artifactdatabase; + +import org.w3c.dom.Document; + +import de.intevation.artifacts.User; + + +/** + * Trivial implementation of a user. Useful to be subclassed. + * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> + */ +public class DefaultUser +implements User +{ + /** The identifier of the user.*/ + protected String identifier; + + /** The name of the user.*/ + protected String name; + + /** The role of the user.*/ + protected Document role; + + + /** + * The default constructor. + */ + public DefaultUser() { + } + + + /** + * Returns the identifier of this user. + * + * @return the identifier of this user. + */ + public String identifier() { + return identifier; + } + + + /** + * Returns the name of the user. + * + * @return the name of the user. + */ + public String getName() { + return name; + } + + + /** + * Set the name of the user. + * + * @param name The name for this user. + */ + public void setName(String name) { + this.name = name; + } + + + /** + * Set the identifier of the user. + * + * @param identifier The new identifier. + */ + public void setIdentifier(String identifier) { + this.identifier = identifier; + } + + + /** + * Set the role of the user. + * + * @param role The new role of the user. + */ + public void setRole(Document role) { + this.role = role; + } + + + /** + * Returns the role of the user. + * + * @return the role of the user. + */ + public Document getRole() { + return role; + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :