# HG changeset patch # User Sascha L. Teichmann # Date 1366879831 -7200 # Node ID 1a87cb24a446ec2dbb9cfbccc5988c901e1e0b23 # Parent 19cb9729bd17e0395affc2b8dff3ae59240ad65b Moved directories to org.dive4elements diff -r 19cb9729bd17 -r 1a87cb24a446 artifacts/src/main/java/de/intevation/artifacts/Artifact.java --- a/artifacts/src/main/java/de/intevation/artifacts/Artifact.java Wed Apr 24 17:35:46 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,153 +0,0 @@ -/* - * Copyright (c) 2010 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.artifacts; - -import java.io.IOException; -import java.io.OutputStream; -import java.io.Serializable; - -import org.w3c.dom.Document; - -/** - * Interface of the core component of the artifact system: The artifact. - *
- * - * An artifact is an abstract data type offering the following methods: - * - *
    - *
  1. {@link #identifier() identifier()}: Returns a gobally unique identfier - * of this artifact.
  2. - *
  3. {@link #hash() hash()}: Returns a hash value over the internal state - * of this artifact.
  4. - *
  5. {@link #describe(Document, CallContext)}: Returns a description of this artifact.
  6. - *
  7. {@link #advance(Document, CallContext) advance()}: Advances this artifact - * to the next internal state
  8. - *
  9. {@link #feed(Document, CallContext) feed()}: Feed new data into this artifact.
  10. - *
  11. {@link #out(Document, OutputStream, CallContext) out()}: Produces output for this artifact.
  12. - *
- * - * There are two more methods involved with the life cycle of the are: - *
    - *
  1. {@link #setup(String, ArtifactFactory, Object, CallMeta, Document) setup()}: - * Called after created by the factory.
  2. - *
  3. {@link #endOfLife(Object) endOfLife()}: Called when the artifact - * is going to be removed from - * system. Useful to clean up.
  4. - *
- * - * @author Sascha L. Teichmann - */ -public interface Artifact -extends Serializable -{ - - /** - * Set a new identifier for this artifact. - * @param identifier New identifier for this artifact. - */ - public void setIdentifier(String identifier); - - /** - * Identify this artifact. - * @return Returns unique string to identify this artifact globally. - */ - String identifier(); - - /** - * Internal hash of this artifact. - * @return Returns hash that should stay the same if the internal - * value has not changed. Useful for caching - */ - String hash(); - - /** - * A description used to build a interface to interact with this artifact. - * @param data General input data. Useful to produces specific descriptions. - * @param context The global context of the runtime system. - * @return An XML representation of the current state of the artifact. - */ - Document describe(Document data, CallContext context); - - /** - * Change the internal state of the artifact. - * @return An XML representation of the success of the advancing. - * @param target Target of internal state to move to. - * @param context The global context of the runtime system. - */ - Document advance(Document target, CallContext context); - - /** - * Feed data into this artifact. - * @param data Data to feed artifact with. - * @param context The global context of the runtime system. - * @return An XML representation of the success of the feeding. - */ - Document feed(Document data, CallContext context); - - /** - * Produce output for this artifact. - * @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. - */ - void out( - Document format, - OutputStream out, - CallContext context) - throws IOException; - - /** - * Produce output for this artifact. - * @param type Specifies the type of the output. - * @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. - */ - void out( - String type, - Document format, - OutputStream out, - CallContext context) - throws IOException; - - /** - * When created by a factory this method is called to - * initialize the artifact. - * - * @param identifier The identifier from artifact database - * @param factory The factory which created this artifact. - * @param context The global context of the runtime system. - * @param data The data which can be use to setup an artifact with - * more details. - */ - public void setup( - String identifier, - ArtifactFactory factory, - Object context, - CallMeta callMeta, - Document data); - - /** - * 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); - - - /** - * 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); -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : diff -r 19cb9729bd17 -r 1a87cb24a446 artifacts/src/main/java/de/intevation/artifacts/ArtifactCollection.java --- a/artifacts/src/main/java/de/intevation/artifacts/ArtifactCollection.java Wed Apr 24 17:35:46 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,131 +0,0 @@ -/* - * 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.artifacts; - -import org.w3c.dom.Document; - -import java.io.IOException; -import java.io.OutputStream; -import java.io.Serializable; - -import java.util.Date; - -public interface ArtifactCollection -extends Serializable -{ - /** - * Set a new identifier for this collection. - * @param identifier New identifier for this collection. - */ - void setIdentifier(String identifier); - - /** - * Identify this collection. - * @return Returns unique string to identify this collection globally. - */ - String identifier(); - - String getName(); - - void setName(String name); - - Date getCreationTime(); - - void setCreationTime(Date creationTime); - - long getTTL(); - - void setTTL(long ttl); - - Document getAttribute(); - - void setAttribute(Document attribute); - - /** - * Set a new owner of this collection. - * @param user New owner for this collection. - */ - void setUser(User user); - - /** - * Identify the owner of the collection. - * @return Returns owner of the collection. - */ - User getUser(); // FIXME: Is ArtifactCollectionFactory needed? - - /** - * 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. - */ - void setup( - String identifier, - String name, - Date creationTime, - long ttl, - ArtifactCollectionFactory factory, - Object context, - Document data); - - - Document describe(CallContext context); - - //TODO: create LifeCycle interface - /** - * Called from artifact database when an artifact is - * going to be removed from system. - * @param context The global context of the runtime system. - */ - void endOfLife(Object context); - - /** - * Internal hash of this collection. - * @return Returns hash that should stay the same if the internal - * value has not changed. Useful for caching - */ - String hash(); - - - /** - * Called from artifact database before an artifact is - * going to be exported as xml document. - * @param context The global context of the runtime system. - */ - void cleanup(Object context); - - void addArtifact(Artifact artifact, Document attributes, CallContext context); - - void removeArtifact(Artifact artifact, CallContext context); - - Artifact [] getArtifacts(CallContext context); - - Document getAttribute(Artifact artifactCall, CallContext context); - - void setAttribute(Artifact artifact, Document document, CallContext context); - - /** - * Produce output for this collection. - * @param type Specifies the output type of the action. - * @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. - */ - void out( - String type, - Document format, - OutputStream out, - CallContext context) - throws IOException; -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : diff -r 19cb9729bd17 -r 1a87cb24a446 artifacts/src/main/java/de/intevation/artifacts/ArtifactCollectionFactory.java --- a/artifacts/src/main/java/de/intevation/artifacts/ArtifactCollectionFactory.java Wed Apr 24 17:35:46 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,65 +0,0 @@ -/* - * 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.artifacts; - -import java.util.Date; - -import org.w3c.dom.Document; -import org.w3c.dom.Node; - - -public interface ArtifactCollectionFactory -{ - /** - * The short name of this factory. - * @return the name of this factory. - */ - String getName(); - - /** - * Description of this factory. - * @return description of the factory. - */ - String getDescription(); - - /** - * Create a new artifact of certain type, given a general purpose context and - * an identifier. - * @param context a context from the ArtifactDatabase. - * @param identifier unique identifer for the new artifact - * @param data the data containing more details for the setup of an Artifact. - * @return a new {@linkplain de.intevation.artifacts.ArtifactCollection ArtifactCollection} - */ - ArtifactCollection createCollection( - String identifier, - String name, - Date creationTime, - long ttl, - Document data, - Object context); - - /** - * Setup the factory with a given configuration - * @param config the configuration - * @param factoryNode the ConfigurationNode of this Factory - */ - void setup(Document config, Node factoryNode); - - /** - * Tells how long a collection should survive if it is - * not touched. This is put in the factory because - * life time is nothing a collection should handle it self. - * This method is only called once directly after the - * artifact is created. - * @param artifact The artifact to be rated. - * @param context The global context. - * @return time to live in ms. null means eternal. - */ - Long timeToLiveUntouched(ArtifactCollection collection, Object context); -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : diff -r 19cb9729bd17 -r 1a87cb24a446 artifacts/src/main/java/de/intevation/artifacts/ArtifactContextFactory.java --- a/artifacts/src/main/java/de/intevation/artifacts/ArtifactContextFactory.java Wed Apr 24 17:35:46 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,29 +0,0 @@ -/* - * Copyright (c) 2010 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.artifacts; - -import org.w3c.dom.Document; - -/** - * Interface of a factory that produces a global artifact context in the artifact data base. - * - * @author Sascha L. Teichmann - */ -public interface ArtifactContextFactory -{ - /** - * Creates a global context given a configuration in the artifact data base. - * @param config the configuration. - * @return The global context. - * {@link de.intevation.artifacts.ArtifactFactory#createArtifact(String, Object, Document) createArtifact()} - * {@link de.intevation.artifacts.Artifact Artifact} - */ - GlobalContext createArtifactContext(Document config); -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : diff -r 19cb9729bd17 -r 1a87cb24a446 artifacts/src/main/java/de/intevation/artifacts/ArtifactDatabase.java --- a/artifacts/src/main/java/de/intevation/artifacts/ArtifactDatabase.java Wed Apr 24 17:35:46 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,298 +0,0 @@ -/* - * Copyright (c) 2010 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.artifacts; - -import java.io.IOException; -import java.io.OutputStream; - -import org.w3c.dom.Document; - -import java.util.Date; - -/** - * Interface of an artifact managing database. - * - * @author Sascha L. Teichmann - */ -public interface ArtifactDatabase -{ - /** - * Implementations of this class defer the out call. - */ - public interface DeferredOutput { - - /** - * Inside this method the Artifact.out() method is called - * with the given Outputstream. - * @param output The stream to write the out() output into. - * @throws IOException Thrown if an exception occurs while writing to - * the output stream. - */ - void write(OutputStream output) throws IOException; - - } // interface DeferredOut - - /** - * List of artifact factories names accessible through the database. - * @return pairs of names and descriptions of the factories. - */ - String [][] artifactFactoryNamesAndDescriptions(); - - /** - * The methods returns a 'pure' factory which is not bound to - * the artifact database. This means when an artifact is created - * with the factory the created artifact is not stored in the - * artifact database. - * @param factoryName The name of the queried artifact factory. - * @return The queried artifact factory or null if corresponing - * factory is found. - */ - ArtifactFactory getInternalArtifactFactory(String factoryName); - - /** - * Used to create an artifact with the factory which given - * by the name 'factory'. The artifact is stored inside the - * artifact database. If the creation succeeds the describe - * document of the artifact is returned. - * @param factory The name of the factory to create the artifact. - * @param callMeta The meta information (languages et. al.) of the - * creation. - * @param data Optional input data to parameterize the creation. - * @return The describe document of new artifact. - * @throws ArtifactDatabaseException Thrown if something went wrong - * during artifact creation. - */ - Document createArtifactWithFactory( - String factory, - CallMeta callMeta, - Document data - ) throws ArtifactDatabaseException; - - /** - * Used to retrieve an artifact.NOTE: artifact modifications are not - * persisted to database! - */ - Artifact getRawArtifact(String identifier) - throws ArtifactDatabaseException; - - /** - * Returns the describe document of artifact identified - * with the string 'artifact'. - * @param artifact The identifier of the artifact. - * @param data Optional input data to parameterize the description. - * @param callMeta the meta information (language et. al.) of - * the description. - * @return The describe document of the artifact. - * @throws ArtifactDatabaseException Thrown id something went wrong - * during the creation of the describe document. - */ - Document describe(String artifact, Document data, CallMeta callMeta) - throws ArtifactDatabaseException; - - /** - * Advances the artifact identified by 'artifact' to the state - * 'target'. The result of the attempt is returned. - * @param artifact The identifier of the artifact. - * @param target The target state of the advance attempt. - * @param callMeta The meta information (language et. al.) of the - * advance attempt. - * @return The result document of the advance attempt. - * @throws ArtifactDatabaseException Thrown if something went wrong - * during the advance attempt. - */ - Document advance(String artifact, Document target, CallMeta callMeta) - throws ArtifactDatabaseException; - - /** - * Feeds the artifact identified by 'artifact' with some data 'data'. - * @param artifact The identifier of the artifact. - * @param data The data to be fed into the artifact. - * @param callMeta The meta information (language et. al.) of the feed - * attempt. - * @return The result of the feed attempt. - * @throws ArtifactDatabaseException Throw if something went wrong during - * the feed attempt. - */ - Document feed(String artifact, Document data, CallMeta callMeta) - throws ArtifactDatabaseException; - - /** - * Produces output for a given artifact identified by 'artifact' in - * a requested format 'format'. The writing of the data is done when - * the write() method of the returned DeferredOutput is called. This - * optimizes the out streaming of the data because the call can be - * deferred into to the calling context. - * @param artifact The identifier of the artifact. - * @param format The request format of the output. - * @param callMeta The meta information (language et. al.) of the output. - * @return The deferred output to be written later in the calling context. - * @throws ArtifactDatabaseException Thrown if something went wrong during - * producing the output. - */ - DeferredOutput out(String artifact, Document format, CallMeta callMeta) - throws ArtifactDatabaseException; - - - /** - * Produces output for a given artifact identified by 'artifact' in - * a requested format 'format'. The writing of the data is done when - * the write() method of the returned DeferredOutput is called. This - * optimizes the out streaming of the data because the call can be - * deferred into to the calling context. - * @param artifact The identifier of the artifact. - * @param format The request format of the output. - * @param callMeta The meta information (language et. al.) of the output. - * @return The deferred output to be written later in the calling context. - * @throws ArtifactDatabaseException Thrown if something went wrong during - * producing the output. - */ - DeferredOutput out( - String artifact, - String type, - Document format, - CallMeta callMeta) - throws ArtifactDatabaseException; - - /** - * Produces an extenal represention of the artifact identified by - * 'artifact' to be re-imported by #importArtifact(Document, CallMeta) - * later. - * @param artifact The identifier of the artifact. - * @param callMeta The meta informatio (language et. al.) of the export. - * @return A extenal representation of the artifact. - * @throws ArtifactDatabaseException Thrown if something went wrong - * during export. - */ - Document exportArtifact(String artifact, CallMeta callMeta) - throws ArtifactDatabaseException; - - /** - * The symmetrical counter part of #exportArtifact(String, CallMeta). - * It attempts to import the artifact which is coded inside the 'data' - * document. When the import succeeds the new artifact is given a new - * internal identifier and the describe document of the artifact is - * returned. - * @param data The encoded artifact. Has to be the output of - * #exportArtifact(String, CallMeta). - * @param callMeta The meta information (language et. al.) of the - * import. - * @return The describe document of the imported artifact. - * @throws ArtifactDatabaseException Thrown if something went wrong during - * the import attempt. - */ - Document importArtifact(Document data, CallMeta callMeta) - throws ArtifactDatabaseException; - - /** - * Returns a list of services offered by this artifact database. - * @return The array returned contains tuples of (name, description) - * strings. - */ - String [][] serviceNamesAndDescriptions(); - - /** - * Calls a service identified by 'service' with input document 'input' - * to produce some output document. - * @param service The name of the service. - * @param input The input document. - * @param callMeta The meta information (language et. al.) of the - * service call. - * @return The result document produced by the service. - * @throws ArtifactDatabaseException Thrown if someting went wrong during - * the service processing. - */ - Service.Output process(String service, Document input, CallMeta callMeta) - throws ArtifactDatabaseException; - - // User API - - Document listUsers(CallMeta callMeta) - throws ArtifactDatabaseException; - - Document findUser(Document data, CallMeta callMeta) - throws ArtifactDatabaseException; - - Document createUser(Document data, CallMeta callMeta) - throws ArtifactDatabaseException; - - Document deleteUser(String userId, CallMeta callMeta) - throws ArtifactDatabaseException; - - // Collection API - - Document getCollectionsMasterArtifact(String collectionId, CallMeta meta) - throws ArtifactDatabaseException; - - Document listCollections(String userId, CallMeta callMeta) - throws ArtifactDatabaseException; - - Document createCollection(String ownerId, Document data, - CallMeta callMeta) - throws ArtifactDatabaseException; - - Document deleteCollection(String collectionId, CallMeta callMeta) - throws ArtifactDatabaseException; - - Document describeCollection(String collectionId, CallMeta callMeta) - throws ArtifactDatabaseException; - - Document getCollectionAttribute(String collectionId, CallMeta callMeta) - throws ArtifactDatabaseException; - - Document setCollectionAttribute( - String collectionId, - CallMeta callMeta, - Document attribute) - throws ArtifactDatabaseException; - - Document getCollectionItemAttribute(String collectionId, String artifactId, - CallMeta callMeta) throws ArtifactDatabaseException; - - Document setCollectionItemAttribute(String collectionId, String artifactId, - Document attribute, CallMeta callMeta) - throws ArtifactDatabaseException; - - Document addCollectionArtifact(String collectionId, String artifactId, - Document input, CallMeta callMeta) throws ArtifactDatabaseException; - - Document removeCollectionArtifact(String collectionId, String artifactId, - CallMeta callMeta) throws ArtifactDatabaseException; - - Document listCollectionArtifacts(String collectionId, - CallMeta callMeta) throws ArtifactDatabaseException; - - DeferredOutput outCollection(String collectionId, - Document format, CallMeta callMeta) - throws ArtifactDatabaseException; - - DeferredOutput outCollection(String collectionId, String type, - Document format, CallMeta callMeta) - throws ArtifactDatabaseException; - - Document setCollectionTTL(String collectionId, Document doc, CallMeta meta) - throws ArtifactDatabaseException; - - Document setCollectionName(String collectionId, Document doc, CallMeta meta) - throws ArtifactDatabaseException; - - public interface ArtifactLoadedCallback { - void artifactLoaded( - String userId, - String collectionId, - String collectionName, - Date collectionCreated, - String artifactId, - Date artifactCreated, - Artifact artifact); - }; - - public void loadAllArtifacts(ArtifactLoadedCallback callback) - throws ArtifactDatabaseException; -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : diff -r 19cb9729bd17 -r 1a87cb24a446 artifacts/src/main/java/de/intevation/artifacts/ArtifactDatabaseException.java --- a/artifacts/src/main/java/de/intevation/artifacts/ArtifactDatabaseException.java Wed Apr 24 17:35:46 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,32 +0,0 @@ -/* - * Copyright (c) 2010 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.artifacts; - -/** - * The standard exception if something goes wrong inside the artifact database. - * @author Sascha L. Teichmann - */ -public class ArtifactDatabaseException -extends Exception -{ - /** - * The default constructor. - */ - public ArtifactDatabaseException() { - } - - /** - * Constructor with a string message. - * @param msg - */ - public ArtifactDatabaseException(String msg) { - super(msg); - } -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : diff -r 19cb9729bd17 -r 1a87cb24a446 artifacts/src/main/java/de/intevation/artifacts/ArtifactFactory.java --- a/artifacts/src/main/java/de/intevation/artifacts/ArtifactFactory.java Wed Apr 24 17:35:46 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,75 +0,0 @@ -/* - * Copyright (c) 2010 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.artifacts; - -import java.io.Serializable; - -import org.w3c.dom.Document; -import org.w3c.dom.Node; - - -/** - * Interface of an artifact producing factory. - * - * @author Sascha L. Teichmann - */ -public interface ArtifactFactory extends Serializable -{ - /** - * The short name of this factory. - * @return the name of this factory. - */ - String getName(); - - /** - * Description of this factory. - * @return description of the factory. - */ - String getDescription(); - - /** - * Create a new artifact of certain type, given a general purpose context and - * an identifier. - * @param context a context from the ArtifactDatabase. - * @param identifier unique identifer for the new artifact - * @param data the data containing more details for the setup of an Artifact. - * @return a new {@linkplain de.intevation.artifacts.Artifact Artifact} - */ - Artifact createArtifact( - String identifier, - GlobalContext context, - CallMeta callMeta, - Document data); - - /** - * Setup the factory with a given configuration - * @param config the configuration - * @param factoryNode the ConfigurationNode of this Factory - */ - void setup(Document config, Node factoryNode); - - /** - * Tells how long an artifact should survive if it is - * not touched. This is put in the factory because - * life time is nothing an artifact should handle it self. - * This method is only called once directly after the - * artifact is created. - * @param artifact The artifact to be rated. - * @param context The global context. - * @return time to live in ms. null means eternal. - */ - Long timeToLiveUntouched(Artifact artifact, Object context); - - /** - * Returns the serializer used to store the artifacts. - * @return The Serializer - */ - ArtifactSerializer getSerializer(); -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : diff -r 19cb9729bd17 -r 1a87cb24a446 artifacts/src/main/java/de/intevation/artifacts/ArtifactNamespaceContext.java --- a/artifacts/src/main/java/de/intevation/artifacts/ArtifactNamespaceContext.java Wed Apr 24 17:35:46 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,118 +0,0 @@ -/* - * Copyright (c) 2010 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.artifacts; - -import java.util.Iterator; -import java.util.Map; -import java.util.HashMap; -import java.util.ArrayList; - -import javax.xml.XMLConstants; - -import javax.xml.namespace.NamespaceContext; - -/** - * The namespace used in artifact documents. - * @author Sascha L. Teichmann - */ -public class ArtifactNamespaceContext -implements NamespaceContext -{ - /** - * The URI of the namespace of the artifacts. - */ - public final static String NAMESPACE_URI = - "http://www.intevation.de/2009/artifacts"; - - /** - * The XML prefix for the artifacts namespace. - */ - public final static String NAMESPACE_PREFIX = "art"; - - /** - * Final instance to be easily used to avoid creation - * of instances. - */ - public static final ArtifactNamespaceContext INSTANCE = - new ArtifactNamespaceContext(); - - protected Map map; - - /** - * The default constructor. - */ - public ArtifactNamespaceContext() { - map = new HashMap(); - map.put( - XMLConstants.XML_NS_PREFIX, XMLConstants.XML_NS_URI); - map.put( - XMLConstants.DEFAULT_NS_PREFIX, XMLConstants.DEFAULT_NS_PREFIX); - map.put( - XMLConstants.XMLNS_ATTRIBUTE, XMLConstants.XMLNS_ATTRIBUTE_NS_URI); - map.put( - NAMESPACE_PREFIX, NAMESPACE_URI); - } - - public void add(String prefix, String uri) { - map.put(prefix, uri); - } - - /** - * @see javax.xml.namespace.NamespaceContext#getNamespaceURI(String) - * @param prefix The prefix - * @return The corresponing URI - */ - @Override - public String getNamespaceURI(String prefix) { - - if (prefix == null) { - throw new IllegalArgumentException("Null prefix"); - } - - String namespace = map.get(prefix); - - return namespace != null ? namespace : XMLConstants.NULL_NS_URI; - } - - /** - * @see javax.xml.namespace.NamespaceContext#getPrefix(String) - * @param uri The URI - */ - @Override - public String getPrefix(String uri) { - - if (uri == null) { - throw new IllegalArgumentException("Null uri"); - } - - for (Map.Entry entry: map.entrySet()) { - if (entry.getValue().equals(uri)) { - return entry.getKey(); - } - } - - return XMLConstants.DEFAULT_NS_PREFIX; - } - - /** - * @see javax.xml.namespace.NamespaceContext#getPrefixes(java.lang.String) - * @param uri The URI - */ - @Override - public Iterator getPrefixes(String uri) { - ArrayList results = new ArrayList(); - for (Map.Entry entry: map.entrySet()) { - if (entry.getValue().equals(uri)) { - results.add(entry.getKey()); - } - } - return results.iterator(); - } -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : diff -r 19cb9729bd17 -r 1a87cb24a446 artifacts/src/main/java/de/intevation/artifacts/ArtifactSerializer.java --- a/artifacts/src/main/java/de/intevation/artifacts/ArtifactSerializer.java Wed Apr 24 17:35:46 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,32 +0,0 @@ -/* - * Copyright (c) 2010 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.artifacts; - -/** - * Interface to make artifact persistent. - * - * @author Sascha L. Teichmann - */ -public interface ArtifactSerializer -{ - /** - * Restores an artifact from an array of bytes. - * @param bytes the persistent representation of the artifact. - * @return The de-serialized artifact or null if there was an error. - */ - Artifact fromBytes(byte [] bytes); - /** - * Brings an artifact to a persistent form in form of a byte array. - * @param artifact The artifact to be serialized. - * @return the byte array representation of the artifact or null - * if there was an error. - */ - byte [] toBytes(Artifact artifact); -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : diff -r 19cb9729bd17 -r 1a87cb24a446 artifacts/src/main/java/de/intevation/artifacts/CallContext.java --- a/artifacts/src/main/java/de/intevation/artifacts/CallContext.java Wed Apr 24 17:35:46 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,145 +0,0 @@ -/* - * Copyright (c) 2010 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.artifacts; - -import java.util.LinkedList; -import java.util.List; - -import org.w3c.dom.Document; -import org.w3c.dom.Node; - -/** - * Instances of this interface are given to feed(), advance(), describe() - * and out() to enable the artifact to communicate with the runtime system. - * @author Sascha L. Teichmann - */ -public interface CallContext -{ - interface Listener { - void setup(Document config, Node listenerNode); - void init(CallContext callContext); - void close(CallContext callContext); - } - - /** - * Constant to signal that nothing should be done - * with the artifact after method return. - */ - int NOTHING = 0; - /** - * Constant to signal that the database timestamp - * should be updated after method return. - */ - int TOUCH = 1; - /** - * Constant to signal that the artifact should be stored - * after method return. - */ - int STORE = 2; - /** - * Constant to signal that the artifact fork a backgroud thread - * and should be hold in memory till it signals that it has - * finished its operation. - */ - int BACKGROUND = 3; - // int DELETE = 4; - // int FOREVER = 5; - - /** - * This method may be called from feed(), describe(), advance() - * and out to signal what should happend with artefact after - * the current method call returns. - * @param action Valid values are NOTHING, TOUCH, STORE, BACKGROUND. - */ - void afterCall(int action); - - /** - * When send to background with a afterCall(BACKGROUND) this - * method is to be called from the background thread to signal - * that the background operation has ended. - * @param action Same semantics as in afterCall. - */ - void afterBackground(int action); - - /** - * Returns true, if the object forked a background thread and has not - * finished it yet. - */ - boolean isInBackground(); - - /** - * Adds a background message for the current Artifact or Collection. - * - * @param msg The message. - */ - void addBackgroundMessage(Message msg); - - /** - * Returns the background messages of the current Artifact or Collection. - * - * @return the list of background messages. - */ - LinkedList getBackgroundMessages(); - - /** - * Access to the global context of the runtime system. - * @return The global context. - */ - Object globalContext(); - - /** - * Access to the artifact database itself. - * @return The database. - */ - ArtifactDatabase getDatabase(); - - /** - * The meta data of the current call. Used to transport - * language preferences of the callee e.g. - * @return The meta information of this call. - */ - CallMeta getMeta(); - - /** - * Each call context has a clipboard. - * getContextValue is used to fetch data from this board. - * @param key Key of the requested item. - * @return The value stored for the specified value, null if - * no item with this key exists. - */ - Object getContextValue(Object key); - - /** - * Each call context has a clipboard. - * putContextValue is used to store a key/value pair onto this board. - * @param key The key of the pair - * @param value The value of the pair. - * @return The formerly stored value under the given key. - */ - Object putContextValue(Object key, Object value); - - /** - * Returns the time to live of the current artifact. - * @return The time to live of the current artifact. - */ - Long getTimeToLive(); - - /** - * Get a list of DataProvider that get provide 'key' type of data to - * other facets. - */ - public List getDataProvider(Object key); - - /** - * Register a DataProvider that can provide 'key' type of data to - * other facets. - */ - public Object registerDataProvider(Object key, DataProvider provider); -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : diff -r 19cb9729bd17 -r 1a87cb24a446 artifacts/src/main/java/de/intevation/artifacts/CallMeta.java --- a/artifacts/src/main/java/de/intevation/artifacts/CallMeta.java Wed Apr 24 17:35:46 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,34 +0,0 @@ -/* - * Copyright (c) 2010 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.artifacts; - -import java.util.Locale; - -/** - * Interface to inject meta data like languages to CallContexts. - * - * @author Sascha L. Teichmann - */ -public interface CallMeta -{ - /** - * Returns a list of the languages the calling client is willing to accept. - * @return the list. - */ - PreferredLocale [] getLanguages(); - - /** - * Intersects the list of preferred client languages with a server - * given list and returns the one which is best fitting. - * @param locales The list of languages the server provides. - * @return The best fitting language. - */ - Locale getPreferredLocale(Locale [] locales); -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : diff -r 19cb9729bd17 -r 1a87cb24a446 artifacts/src/main/java/de/intevation/artifacts/CollectionItem.java --- a/artifacts/src/main/java/de/intevation/artifacts/CollectionItem.java Wed Apr 24 17:35:46 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,21 +0,0 @@ -/* - * 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.artifacts; - -import java.io.Serializable; - -import org.w3c.dom.Document; - - -public interface CollectionItem extends Serializable { - - String getArtifactIdentifier(); - - Document getAttribute(); -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : diff -r 19cb9729bd17 -r 1a87cb24a446 artifacts/src/main/java/de/intevation/artifacts/DataProvider.java --- a/artifacts/src/main/java/de/intevation/artifacts/DataProvider.java Wed Apr 24 17:35:46 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,21 +0,0 @@ -package de.intevation.artifacts; - -/** - * DataProviders register on a Blackboard with a key (basically shouting - * "I can or know X!"). - * - * Consumers look at the blackboard and then consume data from these - * DataProvider, passing them (optional) parameterization and the blackboard - * itself. - * - * Through the blackboard-passing-when-consuming, also recursive patterns can - * be modelled (but take care, there is no in-built cycle detection). - */ -public interface DataProvider { - /** Register this DataProvider on a blackboard under a key. */ - public void register(CallContext blackboard); - - /** Provide data, given parameterization and a "blackboard". */ - public Object provideData(Object key, Object param, CallContext context); -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : diff -r 19cb9729bd17 -r 1a87cb24a446 artifacts/src/main/java/de/intevation/artifacts/GlobalContext.java --- a/artifacts/src/main/java/de/intevation/artifacts/GlobalContext.java Wed Apr 24 17:35:46 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,23 +0,0 @@ -package de.intevation.artifacts; - -public interface GlobalContext { - - /** - * Fetch a custom value from the global key/value map using - * a given key. - * @param key The key. - * @return The stored value or null if no value was found under - * this key. - */ - Object get(Object key); - - /** - * Store a custom key/value pair in the global map. - * @param key The key to store - * @param value The value to store - * @return The old value registered under the key or null - * if none wa there before. - */ - Object put(Object key, Object value); -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : diff -r 19cb9729bd17 -r 1a87cb24a446 artifacts/src/main/java/de/intevation/artifacts/Hook.java --- a/artifacts/src/main/java/de/intevation/artifacts/Hook.java Wed Apr 24 17:35:46 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,13 +0,0 @@ -package de.intevation.artifacts; - -import org.w3c.dom.Document; -import org.w3c.dom.Node; - - -public interface Hook { - - void setup(Node config); - - void execute(Artifact artifact, CallContext context, Document document); -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : diff -r 19cb9729bd17 -r 1a87cb24a446 artifacts/src/main/java/de/intevation/artifacts/Message.java --- a/artifacts/src/main/java/de/intevation/artifacts/Message.java Wed Apr 24 17:35:46 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,20 +0,0 @@ -/* - * 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.artifacts; - -import java.io.Serializable; - - -/** - * @author Ingo Weinzierl - */ -public interface Message extends Serializable { - - String getText(); -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : diff -r 19cb9729bd17 -r 1a87cb24a446 artifacts/src/main/java/de/intevation/artifacts/PreferredLocale.java --- a/artifacts/src/main/java/de/intevation/artifacts/PreferredLocale.java Wed Apr 24 17:35:46 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,31 +0,0 @@ -/* - * Copyright (c) 2010 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.artifacts; - -import java.util.Locale; - -/** - * Interface to build pairs of preference and quality. - * - * @author Sascha L. Teichmann - */ -public interface PreferredLocale -{ - /** - * Returns the locale of the pair. - * @return The locale. - */ - Locale getLocale(); - /** - * Returns the quality of the pair. - * @return the quality - */ - float getQuality(); -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : diff -r 19cb9729bd17 -r 1a87cb24a446 artifacts/src/main/java/de/intevation/artifacts/Service.java --- a/artifacts/src/main/java/de/intevation/artifacts/Service.java Wed Apr 24 17:35:46 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,46 +0,0 @@ -/* - * Copyright (c) 2010 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.artifacts; - -import java.io.Serializable; - -import org.w3c.dom.Document; - -/** - * The idea is to process some input XML document to produce an output - * XML document. - * @author Sascha L. Teichmann - */ -public interface Service -extends Serializable -{ - interface Output { - Object getData(); - - String getMIMEType(); - } // interface Output - - /** - * Processes some input XML document - * @param data The input data - * @param globalContext The global context of the artifact database. - * @param callMeta The call meta contex, e.g. preferred languages. - * @return The result. - */ - Output process(Document data, GlobalContext globalContext, CallMeta callMeta); - - /** - * Setup the concrete processing service. This is done at startup time - * of the artifact database system. - * @param factory The service factory which created this service. - * @param globalContext The global context of the artifact database. - */ - void setup(ServiceFactory factory, GlobalContext globalContext); -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : diff -r 19cb9729bd17 -r 1a87cb24a446 artifacts/src/main/java/de/intevation/artifacts/ServiceFactory.java --- a/artifacts/src/main/java/de/intevation/artifacts/ServiceFactory.java Wed Apr 24 17:35:46 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,54 +0,0 @@ -/* - * Copyright (c) 2010 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.artifacts; - -import java.io.Serializable; - -import org.w3c.dom.Document; -import org.w3c.dom.Node; - -/** - * A factory which an XML in/XML out service which reachable through the - * artifact database. - * @author Sascha L. Teichmann - */ -public interface ServiceFactory -extends Serializable -{ - /** - * The name of the service which is created by this factory. - * @return The name of the created service. - */ - String getName(); - - /** - * The description of the service which is created by this factory. - * @return The description. - */ - String getDescription(); - - /** - * Creates the service. This is done at startup time of the - * artifact database system. - * @param globalContext The global context of the artifact database. - * @return The created service. - */ - Service createService(GlobalContext globalContext); - - /** - * Configures this factory. This is called before - * #createService(Object). - * @param config The global configuration document of the artifact - * database system. - * @param factoryNode The node inside the configuration document which - * corresponds to this factory. - */ - void setup(Document config, Node factoryNode); -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : diff -r 19cb9729bd17 -r 1a87cb24a446 artifacts/src/main/java/de/intevation/artifacts/User.java --- a/artifacts/src/main/java/de/intevation/artifacts/User.java Wed Apr 24 17:35:46 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,31 +0,0 @@ -/* - * 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.artifacts; - -import org.w3c.dom.Document; - -import java.io.Serializable; - -public interface User -extends Serializable -{ - String identifier(); - - String getName(); - - void setName(String name); - - void setIdentifier(String identifier); - - void setRole(Document role); - - Document getRole(); - - String getAccount(); -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : diff -r 19cb9729bd17 -r 1a87cb24a446 artifacts/src/main/java/de/intevation/artifacts/UserFactory.java --- a/artifacts/src/main/java/de/intevation/artifacts/UserFactory.java Wed Apr 24 17:35:46 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,20 +0,0 @@ -/* - * 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.artifacts; - -import org.w3c.dom.Document; -import org.w3c.dom.Node; - -public interface UserFactory -{ - void setup(Document config, Node factoryNode); - - User createUser(String identifier, String name, String account, - Document role, Object context); -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : diff -r 19cb9729bd17 -r 1a87cb24a446 artifacts/src/main/java/de/intevation/artifacts/package.html --- a/artifacts/src/main/java/de/intevation/artifacts/package.html Wed Apr 24 17:35:46 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,8 +0,0 @@ - - - - - -The abstract interfaces and base classes of the artifact system. - - diff -r 19cb9729bd17 -r 1a87cb24a446 artifacts/src/main/java/org/dive4elements/artifacts/Artifact.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/artifacts/src/main/java/org/dive4elements/artifacts/Artifact.java Thu Apr 25 10:50:31 2013 +0200 @@ -0,0 +1,153 @@ +/* + * Copyright (c) 2010 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.artifacts; + +import java.io.IOException; +import java.io.OutputStream; +import java.io.Serializable; + +import org.w3c.dom.Document; + +/** + * Interface of the core component of the artifact system: The artifact. + *
+ * + * An artifact is an abstract data type offering the following methods: + * + *
    + *
  1. {@link #identifier() identifier()}: Returns a gobally unique identfier + * of this artifact.
  2. + *
  3. {@link #hash() hash()}: Returns a hash value over the internal state + * of this artifact.
  4. + *
  5. {@link #describe(Document, CallContext)}: Returns a description of this artifact.
  6. + *
  7. {@link #advance(Document, CallContext) advance()}: Advances this artifact + * to the next internal state
  8. + *
  9. {@link #feed(Document, CallContext) feed()}: Feed new data into this artifact.
  10. + *
  11. {@link #out(Document, OutputStream, CallContext) out()}: Produces output for this artifact.
  12. + *
+ * + * There are two more methods involved with the life cycle of the are: + *
    + *
  1. {@link #setup(String, ArtifactFactory, Object, CallMeta, Document) setup()}: + * Called after created by the factory.
  2. + *
  3. {@link #endOfLife(Object) endOfLife()}: Called when the artifact + * is going to be removed from + * system. Useful to clean up.
  4. + *
+ * + * @author Sascha L. Teichmann + */ +public interface Artifact +extends Serializable +{ + + /** + * Set a new identifier for this artifact. + * @param identifier New identifier for this artifact. + */ + public void setIdentifier(String identifier); + + /** + * Identify this artifact. + * @return Returns unique string to identify this artifact globally. + */ + String identifier(); + + /** + * Internal hash of this artifact. + * @return Returns hash that should stay the same if the internal + * value has not changed. Useful for caching + */ + String hash(); + + /** + * A description used to build a interface to interact with this artifact. + * @param data General input data. Useful to produces specific descriptions. + * @param context The global context of the runtime system. + * @return An XML representation of the current state of the artifact. + */ + Document describe(Document data, CallContext context); + + /** + * Change the internal state of the artifact. + * @return An XML representation of the success of the advancing. + * @param target Target of internal state to move to. + * @param context The global context of the runtime system. + */ + Document advance(Document target, CallContext context); + + /** + * Feed data into this artifact. + * @param data Data to feed artifact with. + * @param context The global context of the runtime system. + * @return An XML representation of the success of the feeding. + */ + Document feed(Document data, CallContext context); + + /** + * Produce output for this artifact. + * @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. + */ + void out( + Document format, + OutputStream out, + CallContext context) + throws IOException; + + /** + * Produce output for this artifact. + * @param type Specifies the type of the output. + * @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. + */ + void out( + String type, + Document format, + OutputStream out, + CallContext context) + throws IOException; + + /** + * When created by a factory this method is called to + * initialize the artifact. + * + * @param identifier The identifier from artifact database + * @param factory The factory which created this artifact. + * @param context The global context of the runtime system. + * @param data The data which can be use to setup an artifact with + * more details. + */ + public void setup( + String identifier, + ArtifactFactory factory, + Object context, + CallMeta callMeta, + Document data); + + /** + * 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); + + + /** + * 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); +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : diff -r 19cb9729bd17 -r 1a87cb24a446 artifacts/src/main/java/org/dive4elements/artifacts/ArtifactCollection.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/artifacts/src/main/java/org/dive4elements/artifacts/ArtifactCollection.java Thu Apr 25 10:50:31 2013 +0200 @@ -0,0 +1,131 @@ +/* + * 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.artifacts; + +import org.w3c.dom.Document; + +import java.io.IOException; +import java.io.OutputStream; +import java.io.Serializable; + +import java.util.Date; + +public interface ArtifactCollection +extends Serializable +{ + /** + * Set a new identifier for this collection. + * @param identifier New identifier for this collection. + */ + void setIdentifier(String identifier); + + /** + * Identify this collection. + * @return Returns unique string to identify this collection globally. + */ + String identifier(); + + String getName(); + + void setName(String name); + + Date getCreationTime(); + + void setCreationTime(Date creationTime); + + long getTTL(); + + void setTTL(long ttl); + + Document getAttribute(); + + void setAttribute(Document attribute); + + /** + * Set a new owner of this collection. + * @param user New owner for this collection. + */ + void setUser(User user); + + /** + * Identify the owner of the collection. + * @return Returns owner of the collection. + */ + User getUser(); // FIXME: Is ArtifactCollectionFactory needed? + + /** + * 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. + */ + void setup( + String identifier, + String name, + Date creationTime, + long ttl, + ArtifactCollectionFactory factory, + Object context, + Document data); + + + Document describe(CallContext context); + + //TODO: create LifeCycle interface + /** + * Called from artifact database when an artifact is + * going to be removed from system. + * @param context The global context of the runtime system. + */ + void endOfLife(Object context); + + /** + * Internal hash of this collection. + * @return Returns hash that should stay the same if the internal + * value has not changed. Useful for caching + */ + String hash(); + + + /** + * Called from artifact database before an artifact is + * going to be exported as xml document. + * @param context The global context of the runtime system. + */ + void cleanup(Object context); + + void addArtifact(Artifact artifact, Document attributes, CallContext context); + + void removeArtifact(Artifact artifact, CallContext context); + + Artifact [] getArtifacts(CallContext context); + + Document getAttribute(Artifact artifactCall, CallContext context); + + void setAttribute(Artifact artifact, Document document, CallContext context); + + /** + * Produce output for this collection. + * @param type Specifies the output type of the action. + * @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. + */ + void out( + String type, + Document format, + OutputStream out, + CallContext context) + throws IOException; +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : diff -r 19cb9729bd17 -r 1a87cb24a446 artifacts/src/main/java/org/dive4elements/artifacts/ArtifactCollectionFactory.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/artifacts/src/main/java/org/dive4elements/artifacts/ArtifactCollectionFactory.java Thu Apr 25 10:50:31 2013 +0200 @@ -0,0 +1,65 @@ +/* + * 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.artifacts; + +import java.util.Date; + +import org.w3c.dom.Document; +import org.w3c.dom.Node; + + +public interface ArtifactCollectionFactory +{ + /** + * The short name of this factory. + * @return the name of this factory. + */ + String getName(); + + /** + * Description of this factory. + * @return description of the factory. + */ + String getDescription(); + + /** + * Create a new artifact of certain type, given a general purpose context and + * an identifier. + * @param context a context from the ArtifactDatabase. + * @param identifier unique identifer for the new artifact + * @param data the data containing more details for the setup of an Artifact. + * @return a new {@linkplain de.intevation.artifacts.ArtifactCollection ArtifactCollection} + */ + ArtifactCollection createCollection( + String identifier, + String name, + Date creationTime, + long ttl, + Document data, + Object context); + + /** + * Setup the factory with a given configuration + * @param config the configuration + * @param factoryNode the ConfigurationNode of this Factory + */ + void setup(Document config, Node factoryNode); + + /** + * Tells how long a collection should survive if it is + * not touched. This is put in the factory because + * life time is nothing a collection should handle it self. + * This method is only called once directly after the + * artifact is created. + * @param artifact The artifact to be rated. + * @param context The global context. + * @return time to live in ms. null means eternal. + */ + Long timeToLiveUntouched(ArtifactCollection collection, Object context); +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : diff -r 19cb9729bd17 -r 1a87cb24a446 artifacts/src/main/java/org/dive4elements/artifacts/ArtifactContextFactory.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/artifacts/src/main/java/org/dive4elements/artifacts/ArtifactContextFactory.java Thu Apr 25 10:50:31 2013 +0200 @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2010 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.artifacts; + +import org.w3c.dom.Document; + +/** + * Interface of a factory that produces a global artifact context in the artifact data base. + * + * @author Sascha L. Teichmann + */ +public interface ArtifactContextFactory +{ + /** + * Creates a global context given a configuration in the artifact data base. + * @param config the configuration. + * @return The global context. + * {@link de.intevation.artifacts.ArtifactFactory#createArtifact(String, Object, Document) createArtifact()} + * {@link de.intevation.artifacts.Artifact Artifact} + */ + GlobalContext createArtifactContext(Document config); +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : diff -r 19cb9729bd17 -r 1a87cb24a446 artifacts/src/main/java/org/dive4elements/artifacts/ArtifactDatabase.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/artifacts/src/main/java/org/dive4elements/artifacts/ArtifactDatabase.java Thu Apr 25 10:50:31 2013 +0200 @@ -0,0 +1,298 @@ +/* + * Copyright (c) 2010 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.artifacts; + +import java.io.IOException; +import java.io.OutputStream; + +import org.w3c.dom.Document; + +import java.util.Date; + +/** + * Interface of an artifact managing database. + * + * @author Sascha L. Teichmann + */ +public interface ArtifactDatabase +{ + /** + * Implementations of this class defer the out call. + */ + public interface DeferredOutput { + + /** + * Inside this method the Artifact.out() method is called + * with the given Outputstream. + * @param output The stream to write the out() output into. + * @throws IOException Thrown if an exception occurs while writing to + * the output stream. + */ + void write(OutputStream output) throws IOException; + + } // interface DeferredOut + + /** + * List of artifact factories names accessible through the database. + * @return pairs of names and descriptions of the factories. + */ + String [][] artifactFactoryNamesAndDescriptions(); + + /** + * The methods returns a 'pure' factory which is not bound to + * the artifact database. This means when an artifact is created + * with the factory the created artifact is not stored in the + * artifact database. + * @param factoryName The name of the queried artifact factory. + * @return The queried artifact factory or null if corresponing + * factory is found. + */ + ArtifactFactory getInternalArtifactFactory(String factoryName); + + /** + * Used to create an artifact with the factory which given + * by the name 'factory'. The artifact is stored inside the + * artifact database. If the creation succeeds the describe + * document of the artifact is returned. + * @param factory The name of the factory to create the artifact. + * @param callMeta The meta information (languages et. al.) of the + * creation. + * @param data Optional input data to parameterize the creation. + * @return The describe document of new artifact. + * @throws ArtifactDatabaseException Thrown if something went wrong + * during artifact creation. + */ + Document createArtifactWithFactory( + String factory, + CallMeta callMeta, + Document data + ) throws ArtifactDatabaseException; + + /** + * Used to retrieve an artifact.NOTE: artifact modifications are not + * persisted to database! + */ + Artifact getRawArtifact(String identifier) + throws ArtifactDatabaseException; + + /** + * Returns the describe document of artifact identified + * with the string 'artifact'. + * @param artifact The identifier of the artifact. + * @param data Optional input data to parameterize the description. + * @param callMeta the meta information (language et. al.) of + * the description. + * @return The describe document of the artifact. + * @throws ArtifactDatabaseException Thrown id something went wrong + * during the creation of the describe document. + */ + Document describe(String artifact, Document data, CallMeta callMeta) + throws ArtifactDatabaseException; + + /** + * Advances the artifact identified by 'artifact' to the state + * 'target'. The result of the attempt is returned. + * @param artifact The identifier of the artifact. + * @param target The target state of the advance attempt. + * @param callMeta The meta information (language et. al.) of the + * advance attempt. + * @return The result document of the advance attempt. + * @throws ArtifactDatabaseException Thrown if something went wrong + * during the advance attempt. + */ + Document advance(String artifact, Document target, CallMeta callMeta) + throws ArtifactDatabaseException; + + /** + * Feeds the artifact identified by 'artifact' with some data 'data'. + * @param artifact The identifier of the artifact. + * @param data The data to be fed into the artifact. + * @param callMeta The meta information (language et. al.) of the feed + * attempt. + * @return The result of the feed attempt. + * @throws ArtifactDatabaseException Throw if something went wrong during + * the feed attempt. + */ + Document feed(String artifact, Document data, CallMeta callMeta) + throws ArtifactDatabaseException; + + /** + * Produces output for a given artifact identified by 'artifact' in + * a requested format 'format'. The writing of the data is done when + * the write() method of the returned DeferredOutput is called. This + * optimizes the out streaming of the data because the call can be + * deferred into to the calling context. + * @param artifact The identifier of the artifact. + * @param format The request format of the output. + * @param callMeta The meta information (language et. al.) of the output. + * @return The deferred output to be written later in the calling context. + * @throws ArtifactDatabaseException Thrown if something went wrong during + * producing the output. + */ + DeferredOutput out(String artifact, Document format, CallMeta callMeta) + throws ArtifactDatabaseException; + + + /** + * Produces output for a given artifact identified by 'artifact' in + * a requested format 'format'. The writing of the data is done when + * the write() method of the returned DeferredOutput is called. This + * optimizes the out streaming of the data because the call can be + * deferred into to the calling context. + * @param artifact The identifier of the artifact. + * @param format The request format of the output. + * @param callMeta The meta information (language et. al.) of the output. + * @return The deferred output to be written later in the calling context. + * @throws ArtifactDatabaseException Thrown if something went wrong during + * producing the output. + */ + DeferredOutput out( + String artifact, + String type, + Document format, + CallMeta callMeta) + throws ArtifactDatabaseException; + + /** + * Produces an extenal represention of the artifact identified by + * 'artifact' to be re-imported by #importArtifact(Document, CallMeta) + * later. + * @param artifact The identifier of the artifact. + * @param callMeta The meta informatio (language et. al.) of the export. + * @return A extenal representation of the artifact. + * @throws ArtifactDatabaseException Thrown if something went wrong + * during export. + */ + Document exportArtifact(String artifact, CallMeta callMeta) + throws ArtifactDatabaseException; + + /** + * The symmetrical counter part of #exportArtifact(String, CallMeta). + * It attempts to import the artifact which is coded inside the 'data' + * document. When the import succeeds the new artifact is given a new + * internal identifier and the describe document of the artifact is + * returned. + * @param data The encoded artifact. Has to be the output of + * #exportArtifact(String, CallMeta). + * @param callMeta The meta information (language et. al.) of the + * import. + * @return The describe document of the imported artifact. + * @throws ArtifactDatabaseException Thrown if something went wrong during + * the import attempt. + */ + Document importArtifact(Document data, CallMeta callMeta) + throws ArtifactDatabaseException; + + /** + * Returns a list of services offered by this artifact database. + * @return The array returned contains tuples of (name, description) + * strings. + */ + String [][] serviceNamesAndDescriptions(); + + /** + * Calls a service identified by 'service' with input document 'input' + * to produce some output document. + * @param service The name of the service. + * @param input The input document. + * @param callMeta The meta information (language et. al.) of the + * service call. + * @return The result document produced by the service. + * @throws ArtifactDatabaseException Thrown if someting went wrong during + * the service processing. + */ + Service.Output process(String service, Document input, CallMeta callMeta) + throws ArtifactDatabaseException; + + // User API + + Document listUsers(CallMeta callMeta) + throws ArtifactDatabaseException; + + Document findUser(Document data, CallMeta callMeta) + throws ArtifactDatabaseException; + + Document createUser(Document data, CallMeta callMeta) + throws ArtifactDatabaseException; + + Document deleteUser(String userId, CallMeta callMeta) + throws ArtifactDatabaseException; + + // Collection API + + Document getCollectionsMasterArtifact(String collectionId, CallMeta meta) + throws ArtifactDatabaseException; + + Document listCollections(String userId, CallMeta callMeta) + throws ArtifactDatabaseException; + + Document createCollection(String ownerId, Document data, + CallMeta callMeta) + throws ArtifactDatabaseException; + + Document deleteCollection(String collectionId, CallMeta callMeta) + throws ArtifactDatabaseException; + + Document describeCollection(String collectionId, CallMeta callMeta) + throws ArtifactDatabaseException; + + Document getCollectionAttribute(String collectionId, CallMeta callMeta) + throws ArtifactDatabaseException; + + Document setCollectionAttribute( + String collectionId, + CallMeta callMeta, + Document attribute) + throws ArtifactDatabaseException; + + Document getCollectionItemAttribute(String collectionId, String artifactId, + CallMeta callMeta) throws ArtifactDatabaseException; + + Document setCollectionItemAttribute(String collectionId, String artifactId, + Document attribute, CallMeta callMeta) + throws ArtifactDatabaseException; + + Document addCollectionArtifact(String collectionId, String artifactId, + Document input, CallMeta callMeta) throws ArtifactDatabaseException; + + Document removeCollectionArtifact(String collectionId, String artifactId, + CallMeta callMeta) throws ArtifactDatabaseException; + + Document listCollectionArtifacts(String collectionId, + CallMeta callMeta) throws ArtifactDatabaseException; + + DeferredOutput outCollection(String collectionId, + Document format, CallMeta callMeta) + throws ArtifactDatabaseException; + + DeferredOutput outCollection(String collectionId, String type, + Document format, CallMeta callMeta) + throws ArtifactDatabaseException; + + Document setCollectionTTL(String collectionId, Document doc, CallMeta meta) + throws ArtifactDatabaseException; + + Document setCollectionName(String collectionId, Document doc, CallMeta meta) + throws ArtifactDatabaseException; + + public interface ArtifactLoadedCallback { + void artifactLoaded( + String userId, + String collectionId, + String collectionName, + Date collectionCreated, + String artifactId, + Date artifactCreated, + Artifact artifact); + }; + + public void loadAllArtifacts(ArtifactLoadedCallback callback) + throws ArtifactDatabaseException; +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : diff -r 19cb9729bd17 -r 1a87cb24a446 artifacts/src/main/java/org/dive4elements/artifacts/ArtifactDatabaseException.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/artifacts/src/main/java/org/dive4elements/artifacts/ArtifactDatabaseException.java Thu Apr 25 10:50:31 2013 +0200 @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2010 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.artifacts; + +/** + * The standard exception if something goes wrong inside the artifact database. + * @author Sascha L. Teichmann + */ +public class ArtifactDatabaseException +extends Exception +{ + /** + * The default constructor. + */ + public ArtifactDatabaseException() { + } + + /** + * Constructor with a string message. + * @param msg + */ + public ArtifactDatabaseException(String msg) { + super(msg); + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : diff -r 19cb9729bd17 -r 1a87cb24a446 artifacts/src/main/java/org/dive4elements/artifacts/ArtifactFactory.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/artifacts/src/main/java/org/dive4elements/artifacts/ArtifactFactory.java Thu Apr 25 10:50:31 2013 +0200 @@ -0,0 +1,75 @@ +/* + * Copyright (c) 2010 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.artifacts; + +import java.io.Serializable; + +import org.w3c.dom.Document; +import org.w3c.dom.Node; + + +/** + * Interface of an artifact producing factory. + * + * @author Sascha L. Teichmann + */ +public interface ArtifactFactory extends Serializable +{ + /** + * The short name of this factory. + * @return the name of this factory. + */ + String getName(); + + /** + * Description of this factory. + * @return description of the factory. + */ + String getDescription(); + + /** + * Create a new artifact of certain type, given a general purpose context and + * an identifier. + * @param context a context from the ArtifactDatabase. + * @param identifier unique identifer for the new artifact + * @param data the data containing more details for the setup of an Artifact. + * @return a new {@linkplain de.intevation.artifacts.Artifact Artifact} + */ + Artifact createArtifact( + String identifier, + GlobalContext context, + CallMeta callMeta, + Document data); + + /** + * Setup the factory with a given configuration + * @param config the configuration + * @param factoryNode the ConfigurationNode of this Factory + */ + void setup(Document config, Node factoryNode); + + /** + * Tells how long an artifact should survive if it is + * not touched. This is put in the factory because + * life time is nothing an artifact should handle it self. + * This method is only called once directly after the + * artifact is created. + * @param artifact The artifact to be rated. + * @param context The global context. + * @return time to live in ms. null means eternal. + */ + Long timeToLiveUntouched(Artifact artifact, Object context); + + /** + * Returns the serializer used to store the artifacts. + * @return The Serializer + */ + ArtifactSerializer getSerializer(); +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : diff -r 19cb9729bd17 -r 1a87cb24a446 artifacts/src/main/java/org/dive4elements/artifacts/ArtifactNamespaceContext.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/artifacts/src/main/java/org/dive4elements/artifacts/ArtifactNamespaceContext.java Thu Apr 25 10:50:31 2013 +0200 @@ -0,0 +1,118 @@ +/* + * Copyright (c) 2010 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.artifacts; + +import java.util.Iterator; +import java.util.Map; +import java.util.HashMap; +import java.util.ArrayList; + +import javax.xml.XMLConstants; + +import javax.xml.namespace.NamespaceContext; + +/** + * The namespace used in artifact documents. + * @author Sascha L. Teichmann + */ +public class ArtifactNamespaceContext +implements NamespaceContext +{ + /** + * The URI of the namespace of the artifacts. + */ + public final static String NAMESPACE_URI = + "http://www.intevation.de/2009/artifacts"; + + /** + * The XML prefix for the artifacts namespace. + */ + public final static String NAMESPACE_PREFIX = "art"; + + /** + * Final instance to be easily used to avoid creation + * of instances. + */ + public static final ArtifactNamespaceContext INSTANCE = + new ArtifactNamespaceContext(); + + protected Map map; + + /** + * The default constructor. + */ + public ArtifactNamespaceContext() { + map = new HashMap(); + map.put( + XMLConstants.XML_NS_PREFIX, XMLConstants.XML_NS_URI); + map.put( + XMLConstants.DEFAULT_NS_PREFIX, XMLConstants.DEFAULT_NS_PREFIX); + map.put( + XMLConstants.XMLNS_ATTRIBUTE, XMLConstants.XMLNS_ATTRIBUTE_NS_URI); + map.put( + NAMESPACE_PREFIX, NAMESPACE_URI); + } + + public void add(String prefix, String uri) { + map.put(prefix, uri); + } + + /** + * @see javax.xml.namespace.NamespaceContext#getNamespaceURI(String) + * @param prefix The prefix + * @return The corresponing URI + */ + @Override + public String getNamespaceURI(String prefix) { + + if (prefix == null) { + throw new IllegalArgumentException("Null prefix"); + } + + String namespace = map.get(prefix); + + return namespace != null ? namespace : XMLConstants.NULL_NS_URI; + } + + /** + * @see javax.xml.namespace.NamespaceContext#getPrefix(String) + * @param uri The URI + */ + @Override + public String getPrefix(String uri) { + + if (uri == null) { + throw new IllegalArgumentException("Null uri"); + } + + for (Map.Entry entry: map.entrySet()) { + if (entry.getValue().equals(uri)) { + return entry.getKey(); + } + } + + return XMLConstants.DEFAULT_NS_PREFIX; + } + + /** + * @see javax.xml.namespace.NamespaceContext#getPrefixes(java.lang.String) + * @param uri The URI + */ + @Override + public Iterator getPrefixes(String uri) { + ArrayList results = new ArrayList(); + for (Map.Entry entry: map.entrySet()) { + if (entry.getValue().equals(uri)) { + results.add(entry.getKey()); + } + } + return results.iterator(); + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : diff -r 19cb9729bd17 -r 1a87cb24a446 artifacts/src/main/java/org/dive4elements/artifacts/ArtifactSerializer.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/artifacts/src/main/java/org/dive4elements/artifacts/ArtifactSerializer.java Thu Apr 25 10:50:31 2013 +0200 @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2010 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.artifacts; + +/** + * Interface to make artifact persistent. + * + * @author Sascha L. Teichmann + */ +public interface ArtifactSerializer +{ + /** + * Restores an artifact from an array of bytes. + * @param bytes the persistent representation of the artifact. + * @return The de-serialized artifact or null if there was an error. + */ + Artifact fromBytes(byte [] bytes); + /** + * Brings an artifact to a persistent form in form of a byte array. + * @param artifact The artifact to be serialized. + * @return the byte array representation of the artifact or null + * if there was an error. + */ + byte [] toBytes(Artifact artifact); +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : diff -r 19cb9729bd17 -r 1a87cb24a446 artifacts/src/main/java/org/dive4elements/artifacts/CallContext.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/artifacts/src/main/java/org/dive4elements/artifacts/CallContext.java Thu Apr 25 10:50:31 2013 +0200 @@ -0,0 +1,145 @@ +/* + * Copyright (c) 2010 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.artifacts; + +import java.util.LinkedList; +import java.util.List; + +import org.w3c.dom.Document; +import org.w3c.dom.Node; + +/** + * Instances of this interface are given to feed(), advance(), describe() + * and out() to enable the artifact to communicate with the runtime system. + * @author Sascha L. Teichmann + */ +public interface CallContext +{ + interface Listener { + void setup(Document config, Node listenerNode); + void init(CallContext callContext); + void close(CallContext callContext); + } + + /** + * Constant to signal that nothing should be done + * with the artifact after method return. + */ + int NOTHING = 0; + /** + * Constant to signal that the database timestamp + * should be updated after method return. + */ + int TOUCH = 1; + /** + * Constant to signal that the artifact should be stored + * after method return. + */ + int STORE = 2; + /** + * Constant to signal that the artifact fork a backgroud thread + * and should be hold in memory till it signals that it has + * finished its operation. + */ + int BACKGROUND = 3; + // int DELETE = 4; + // int FOREVER = 5; + + /** + * This method may be called from feed(), describe(), advance() + * and out to signal what should happend with artefact after + * the current method call returns. + * @param action Valid values are NOTHING, TOUCH, STORE, BACKGROUND. + */ + void afterCall(int action); + + /** + * When send to background with a afterCall(BACKGROUND) this + * method is to be called from the background thread to signal + * that the background operation has ended. + * @param action Same semantics as in afterCall. + */ + void afterBackground(int action); + + /** + * Returns true, if the object forked a background thread and has not + * finished it yet. + */ + boolean isInBackground(); + + /** + * Adds a background message for the current Artifact or Collection. + * + * @param msg The message. + */ + void addBackgroundMessage(Message msg); + + /** + * Returns the background messages of the current Artifact or Collection. + * + * @return the list of background messages. + */ + LinkedList getBackgroundMessages(); + + /** + * Access to the global context of the runtime system. + * @return The global context. + */ + Object globalContext(); + + /** + * Access to the artifact database itself. + * @return The database. + */ + ArtifactDatabase getDatabase(); + + /** + * The meta data of the current call. Used to transport + * language preferences of the callee e.g. + * @return The meta information of this call. + */ + CallMeta getMeta(); + + /** + * Each call context has a clipboard. + * getContextValue is used to fetch data from this board. + * @param key Key of the requested item. + * @return The value stored for the specified value, null if + * no item with this key exists. + */ + Object getContextValue(Object key); + + /** + * Each call context has a clipboard. + * putContextValue is used to store a key/value pair onto this board. + * @param key The key of the pair + * @param value The value of the pair. + * @return The formerly stored value under the given key. + */ + Object putContextValue(Object key, Object value); + + /** + * Returns the time to live of the current artifact. + * @return The time to live of the current artifact. + */ + Long getTimeToLive(); + + /** + * Get a list of DataProvider that get provide 'key' type of data to + * other facets. + */ + public List getDataProvider(Object key); + + /** + * Register a DataProvider that can provide 'key' type of data to + * other facets. + */ + public Object registerDataProvider(Object key, DataProvider provider); +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : diff -r 19cb9729bd17 -r 1a87cb24a446 artifacts/src/main/java/org/dive4elements/artifacts/CallMeta.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/artifacts/src/main/java/org/dive4elements/artifacts/CallMeta.java Thu Apr 25 10:50:31 2013 +0200 @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2010 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.artifacts; + +import java.util.Locale; + +/** + * Interface to inject meta data like languages to CallContexts. + * + * @author Sascha L. Teichmann + */ +public interface CallMeta +{ + /** + * Returns a list of the languages the calling client is willing to accept. + * @return the list. + */ + PreferredLocale [] getLanguages(); + + /** + * Intersects the list of preferred client languages with a server + * given list and returns the one which is best fitting. + * @param locales The list of languages the server provides. + * @return The best fitting language. + */ + Locale getPreferredLocale(Locale [] locales); +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : diff -r 19cb9729bd17 -r 1a87cb24a446 artifacts/src/main/java/org/dive4elements/artifacts/CollectionItem.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/artifacts/src/main/java/org/dive4elements/artifacts/CollectionItem.java Thu Apr 25 10:50:31 2013 +0200 @@ -0,0 +1,21 @@ +/* + * 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.artifacts; + +import java.io.Serializable; + +import org.w3c.dom.Document; + + +public interface CollectionItem extends Serializable { + + String getArtifactIdentifier(); + + Document getAttribute(); +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : diff -r 19cb9729bd17 -r 1a87cb24a446 artifacts/src/main/java/org/dive4elements/artifacts/DataProvider.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/artifacts/src/main/java/org/dive4elements/artifacts/DataProvider.java Thu Apr 25 10:50:31 2013 +0200 @@ -0,0 +1,21 @@ +package de.intevation.artifacts; + +/** + * DataProviders register on a Blackboard with a key (basically shouting + * "I can or know X!"). + * + * Consumers look at the blackboard and then consume data from these + * DataProvider, passing them (optional) parameterization and the blackboard + * itself. + * + * Through the blackboard-passing-when-consuming, also recursive patterns can + * be modelled (but take care, there is no in-built cycle detection). + */ +public interface DataProvider { + /** Register this DataProvider on a blackboard under a key. */ + public void register(CallContext blackboard); + + /** Provide data, given parameterization and a "blackboard". */ + public Object provideData(Object key, Object param, CallContext context); +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : diff -r 19cb9729bd17 -r 1a87cb24a446 artifacts/src/main/java/org/dive4elements/artifacts/GlobalContext.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/artifacts/src/main/java/org/dive4elements/artifacts/GlobalContext.java Thu Apr 25 10:50:31 2013 +0200 @@ -0,0 +1,23 @@ +package de.intevation.artifacts; + +public interface GlobalContext { + + /** + * Fetch a custom value from the global key/value map using + * a given key. + * @param key The key. + * @return The stored value or null if no value was found under + * this key. + */ + Object get(Object key); + + /** + * Store a custom key/value pair in the global map. + * @param key The key to store + * @param value The value to store + * @return The old value registered under the key or null + * if none wa there before. + */ + Object put(Object key, Object value); +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : diff -r 19cb9729bd17 -r 1a87cb24a446 artifacts/src/main/java/org/dive4elements/artifacts/Hook.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/artifacts/src/main/java/org/dive4elements/artifacts/Hook.java Thu Apr 25 10:50:31 2013 +0200 @@ -0,0 +1,13 @@ +package de.intevation.artifacts; + +import org.w3c.dom.Document; +import org.w3c.dom.Node; + + +public interface Hook { + + void setup(Node config); + + void execute(Artifact artifact, CallContext context, Document document); +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : diff -r 19cb9729bd17 -r 1a87cb24a446 artifacts/src/main/java/org/dive4elements/artifacts/Message.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/artifacts/src/main/java/org/dive4elements/artifacts/Message.java Thu Apr 25 10:50:31 2013 +0200 @@ -0,0 +1,20 @@ +/* + * 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.artifacts; + +import java.io.Serializable; + + +/** + * @author Ingo Weinzierl + */ +public interface Message extends Serializable { + + String getText(); +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : diff -r 19cb9729bd17 -r 1a87cb24a446 artifacts/src/main/java/org/dive4elements/artifacts/PreferredLocale.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/artifacts/src/main/java/org/dive4elements/artifacts/PreferredLocale.java Thu Apr 25 10:50:31 2013 +0200 @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2010 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.artifacts; + +import java.util.Locale; + +/** + * Interface to build pairs of preference and quality. + * + * @author Sascha L. Teichmann + */ +public interface PreferredLocale +{ + /** + * Returns the locale of the pair. + * @return The locale. + */ + Locale getLocale(); + /** + * Returns the quality of the pair. + * @return the quality + */ + float getQuality(); +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : diff -r 19cb9729bd17 -r 1a87cb24a446 artifacts/src/main/java/org/dive4elements/artifacts/Service.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/artifacts/src/main/java/org/dive4elements/artifacts/Service.java Thu Apr 25 10:50:31 2013 +0200 @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2010 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.artifacts; + +import java.io.Serializable; + +import org.w3c.dom.Document; + +/** + * The idea is to process some input XML document to produce an output + * XML document. + * @author Sascha L. Teichmann + */ +public interface Service +extends Serializable +{ + interface Output { + Object getData(); + + String getMIMEType(); + } // interface Output + + /** + * Processes some input XML document + * @param data The input data + * @param globalContext The global context of the artifact database. + * @param callMeta The call meta contex, e.g. preferred languages. + * @return The result. + */ + Output process(Document data, GlobalContext globalContext, CallMeta callMeta); + + /** + * Setup the concrete processing service. This is done at startup time + * of the artifact database system. + * @param factory The service factory which created this service. + * @param globalContext The global context of the artifact database. + */ + void setup(ServiceFactory factory, GlobalContext globalContext); +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : diff -r 19cb9729bd17 -r 1a87cb24a446 artifacts/src/main/java/org/dive4elements/artifacts/ServiceFactory.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/artifacts/src/main/java/org/dive4elements/artifacts/ServiceFactory.java Thu Apr 25 10:50:31 2013 +0200 @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2010 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.artifacts; + +import java.io.Serializable; + +import org.w3c.dom.Document; +import org.w3c.dom.Node; + +/** + * A factory which an XML in/XML out service which reachable through the + * artifact database. + * @author Sascha L. Teichmann + */ +public interface ServiceFactory +extends Serializable +{ + /** + * The name of the service which is created by this factory. + * @return The name of the created service. + */ + String getName(); + + /** + * The description of the service which is created by this factory. + * @return The description. + */ + String getDescription(); + + /** + * Creates the service. This is done at startup time of the + * artifact database system. + * @param globalContext The global context of the artifact database. + * @return The created service. + */ + Service createService(GlobalContext globalContext); + + /** + * Configures this factory. This is called before + * #createService(Object). + * @param config The global configuration document of the artifact + * database system. + * @param factoryNode The node inside the configuration document which + * corresponds to this factory. + */ + void setup(Document config, Node factoryNode); +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : diff -r 19cb9729bd17 -r 1a87cb24a446 artifacts/src/main/java/org/dive4elements/artifacts/User.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/artifacts/src/main/java/org/dive4elements/artifacts/User.java Thu Apr 25 10:50:31 2013 +0200 @@ -0,0 +1,31 @@ +/* + * 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.artifacts; + +import org.w3c.dom.Document; + +import java.io.Serializable; + +public interface User +extends Serializable +{ + String identifier(); + + String getName(); + + void setName(String name); + + void setIdentifier(String identifier); + + void setRole(Document role); + + Document getRole(); + + String getAccount(); +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : diff -r 19cb9729bd17 -r 1a87cb24a446 artifacts/src/main/java/org/dive4elements/artifacts/UserFactory.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/artifacts/src/main/java/org/dive4elements/artifacts/UserFactory.java Thu Apr 25 10:50:31 2013 +0200 @@ -0,0 +1,20 @@ +/* + * 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.artifacts; + +import org.w3c.dom.Document; +import org.w3c.dom.Node; + +public interface UserFactory +{ + void setup(Document config, Node factoryNode); + + User createUser(String identifier, String name, String account, + Document role, Object context); +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : diff -r 19cb9729bd17 -r 1a87cb24a446 artifacts/src/main/java/org/dive4elements/artifacts/package.html --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/artifacts/src/main/java/org/dive4elements/artifacts/package.html Thu Apr 25 10:50:31 2013 +0200 @@ -0,0 +1,8 @@ + + + + + +The abstract interfaces and base classes of the artifact system. + +