001: /*
002: * GeoTools - OpenSource mapping toolkit
003: * http://geotools.org
004: * (C) 2003-2006, GeoTools Project Managment Committee (PMC)
005: *
006: * This library is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU Lesser General Public
008: * License as published by the Free Software Foundation;
009: * version 2.1 of the License.
010: *
011: * This library is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * Lesser General Public License for more details.
015: */
016: package org.geotools.data;
017:
018: import java.util.Map;
019: import java.util.Collections;
020:
021: import org.geotools.factory.CommonFactoryFinder;
022: import org.geotools.factory.Factory;
023: import org.geotools.factory.FactoryConfigurationError;
024:
025: /**
026: * This specifies the interface to create FeatureLocks.
027: * <p>
028: * Sample use:
029: * <code><pre>
030: * FeatureLock lock = FeatureLockFactory.generate( "MyLock", 3600 );
031: * </pre></code>
032: * @source $URL: http://svn.geotools.org/geotools/tags/2.4.1/modules/library/main/src/main/java/org/geotools/data/FeatureLockFactory.java $
033: * @version $Id: FeatureLockFactory.java 24991 2007-04-03 05:41:12Z jgarnett $
034: * @task REVISIT: Combine this with a factory to also make Query objects?
035: * @author Chris Holmes, TOPP
036: */
037:
038: public abstract class FeatureLockFactory implements Factory {
039: /** A cached factory to create FeatureLocks. */
040: private static FeatureLockFactory factory = null;
041:
042: /**
043: * Gets an instance of the FeatureLockFactory.
044: *
045: * @return A FeatureLockFactory instance.
046: *
047: * @throws FactoryConfigurationError If there exists a configuration error.
048: */
049: public static FeatureLockFactory getInstance()
050: throws FactoryConfigurationError {
051: if (factory == null) {
052: factory = CommonFactoryFinder.getFeatureLockFactory(null);
053: }
054: return factory;
055: }
056:
057: /**
058: * Generates a new FeatureLock for use.
059: * <p>
060: * The lock will be of the form:
061: * </p>
062: * <table border=1 width="100%" background="gray"><code><pre>
063: * LockID{number}
064: * Where:
065: * {number} - is unique based on time and expiration requested
066: * </code></pre></table>
067: * <p>
068: * The resulting lock is unique.</p>
069: * <p>
070: * To aid in tracing your may wish to supply your own name,
071: * rather than <code>LockID<code>, for use in lock generation.</p>
072: *
073: * @param duration FeatureLock duration in seconds
074: */
075: public static FeatureLock generate(long duration) {
076: return generate("LockID", duration);
077: }
078:
079: /**
080: * Generates a new FeatureLock for use.
081: *
082: * The lock will be of the form:
083: * <table border=1 width="100%" background="gray"><code><pre>
084: * {name}{number}
085: * Where:
086: * {number} - is unique based on time and expiration requested
087: * </code></pre></table>
088: * The resulting lock is unique.
089: * <p>
090: * To aid in tracing your may wish to supply your own name,
091: * rather than <code>LockID<code>, for use in lock generation.
092: * @param name User supplied name used in lock generation.
093: * @param duration Date lock expires on.
094: */
095: public static FeatureLock generate(String name, long duration) {
096: return getInstance().createLock(name, duration);
097: }
098:
099: protected abstract FeatureLock createLock(String name, long duration);
100:
101: /**
102: * Returns the implementation hints. The default implementation returns en empty map.
103: */
104: public Map getImplementationHints() {
105: return Collections.EMPTY_MAP;
106: }
107: }
|