Michael Bedward ha scritto:
Hi Andrea
I didn't get your attachment
Silly me... here is it.
Cheers
Andrea
--
Andrea Aime
OpenGeo - http://opengeo.org
Expert service straight from the developers.
Proprietà modificate su: .
___________________________________________________________________
Modified: svn:mergeinfo
Fuso /branches/2.5.x/modules/unsupported/process:r33682,33788
Index: src/test/java/org/geotools/process/literal/ProcessTest.java
===================================================================
--- src/test/java/org/geotools/process/literal/ProcessTest.java (revisione 33810)
+++ src/test/java/org/geotools/process/literal/ProcessTest.java (copia locale)
@@ -23,8 +23,6 @@
import junit.framework.TestCase;
-import org.geotools.factory.FactoryFinder;
-
import com.vividsolutions.jts.geom.Geometry;
import com.vividsolutions.jts.geom.GeometryFactory;
import com.vividsolutions.jts.geom.Polygon;
Index: src/main/java/org/geotools/process/raster/RasterToVectorFactory.java
===================================================================
--- src/main/java/org/geotools/process/raster/RasterToVectorFactory.java (revisione 33810)
+++ src/main/java/org/geotools/process/raster/RasterToVectorFactory.java (copia locale)
@@ -16,22 +16,23 @@
*/
package org.geotools.process.raster;
+import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
+import java.util.TreeMap;
+import org.geotools.coverage.grid.GridCoverage2D;
import org.geotools.data.Parameter;
import org.geotools.feature.FeatureCollection;
+import org.geotools.feature.NameImpl;
import org.geotools.feature.simple.SimpleFeatureTypeBuilder;
-import org.geotools.process.ProcessFactory;
+import org.geotools.process.impl.SingleProcessFactory;
import org.geotools.text.Text;
import org.opengis.feature.simple.SimpleFeatureType;
import org.opengis.referencing.crs.CoordinateReferenceSystem;
import org.opengis.util.InternationalString;
import com.vividsolutions.jts.geom.Polygon;
-import java.util.Collections;
-import java.util.TreeMap;
-import org.geotools.coverage.grid.GridCoverage2D;
/**
@@ -45,7 +46,7 @@
* @author Michael Bedward, Jody Garnett
* @since 2.6
*/
-public class RasterToVectorFactory implements ProcessFactory {
+public class RasterToVectorFactory extends SingleProcessFactory {
private static final String VERSION_STRING = "0.0.3";
@@ -97,6 +98,10 @@
resultInfo.put(RESULT_FEATURES.key, RESULT_FEATURES);
}
+
+ public RasterToVectorFactory() {
+ super(new NameImpl(GT_NAMESPACE, "RasterToVectorProcess"));
+ }
/**
* Return a new instance of a RasterToVectorProcess
@@ -114,14 +119,6 @@
}
/**
- * Get the name of this process
- * @return the string: RasterToVectorProcess
- */
- public String getName() {
- return "RasterToVectorProcess";
- }
-
- /**
* Get a map of input parameters required by the
* {...@linkplain RasterToVectorProcess#execute(java.util.Map, org.opengis.util.ProgressListener) }
* method
Index: src/main/java/org/geotools/process/impl/AbstractProcess.java
===================================================================
--- src/main/java/org/geotools/process/impl/AbstractProcess.java (revisione 33810)
+++ src/main/java/org/geotools/process/impl/AbstractProcess.java (copia locale)
@@ -29,6 +29,7 @@
*/
public abstract class AbstractProcess implements Process {
protected ProcessFactory factory;
+
protected AbstractProcess( ProcessFactory factory ){
this.factory = factory;
}
Index: src/main/java/org/geotools/process/impl/SimpleProcess.java
===================================================================
--- src/main/java/org/geotools/process/impl/SimpleProcess.java (revisione 33810)
+++ src/main/java/org/geotools/process/impl/SimpleProcess.java (copia locale)
@@ -18,7 +18,6 @@
import java.util.HashMap;
import java.util.Map;
-import java.util.concurrent.Callable;
import org.geotools.process.ProcessFactory;
import org.geotools.util.NullProgressListener;
Index: src/main/java/org/geotools/process/impl/SingleProcessFactory.java
===================================================================
--- src/main/java/org/geotools/process/impl/SingleProcessFactory.java (revisione 0)
+++ src/main/java/org/geotools/process/impl/SingleProcessFactory.java (revisione 0)
@@ -0,0 +1,134 @@
+/*
+ * GeoTools - The Open Source Java GIS Toolkit
+ * http://geotools.org
+ *
+ * (C) 2008, Open Source Geospatial Foundation (OSGeo)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation;
+ * version 2.1 of the License.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ */
+package org.geotools.process.impl;
+
+import java.util.Collections;
+import java.util.Map;
+import java.util.Set;
+
+import org.geotools.data.Parameter;
+import org.geotools.feature.NameImpl;
+import org.geotools.process.Process;
+import org.geotools.process.ProcessFactory;
+import org.opengis.feature.type.Name;
+import org.opengis.util.InternationalString;
+
+/**
+ * Helper class for a process factory that will return just a single process
+ *
+ * @author Andrea Aime - OpenGeo
+ */
+public abstract class SingleProcessFactory implements ProcessFactory {
+
+ Name processName;
+
+ /**
+ * Utility method for factories that will use the process factory name in order to define the
+ * process name by stripping the "Factory" at the end of the name.
+ */
+ protected SingleProcessFactory() {
+ String factoryName = this.getClass().getSimpleName();
+ String localName;
+ if (factoryName.endsWith("Factory") && !factoryName.equals("Factory")) {
+ localName = factoryName.substring(0, factoryName.length() - 7);
+ } else {
+ localName = factoryName;
+ }
+ processName = new NameImpl(GT_NAMESPACE, localName);
+ }
+
+ /**
+ *
+ * @param processName
+ */
+ protected SingleProcessFactory(Name processName) {
+ if (processName == null)
+ throw new NullPointerException("Process name cannot be null");
+ this.processName = processName;
+ }
+
+ /**
+ * Checks the process name and makes sure it's consistent with the only process name this
+ * factory knows about
+ *
+ * @param name
+ */
+ void checkName(Name name) {
+ if(name == null)
+ throw new NullPointerException("Process name cannot be null");
+ if(!processName.equals(processName))
+ throw new IllegalArgumentException("Unknown process '" + name
+ + "', this factory knows only about '" + processName + "'");
+ }
+
+ public Process create(Name name) {
+ checkName(name);
+ return create();
+ }
+
+ public Set<Name> getNames() {
+ return Collections.singleton(processName);
+ }
+
+ public InternationalString getDescription(Name name) {
+ checkName(name);
+ return getDescription();
+ }
+
+
+ public Map<String, Parameter<?>> getParameterInfo(Name name) {
+ checkName(name);
+ return getParameterInfo();
+ }
+
+ public Map<String, Parameter<?>> getResultInfo(Name name, Map<String, Object> parameters)
+ throws IllegalArgumentException {
+ checkName(name);
+ return getResultInfo(parameters);
+ }
+
+ public InternationalString getTitle(Name name) {
+ checkName(name);
+ return getTitle();
+ }
+
+ public String getVersion(Name name) {
+ checkName(name);
+ return getVersion();
+ }
+
+ public boolean supportsProgress(Name name) {
+ checkName(name);
+ return supportsProgress();
+ }
+
+ protected abstract Process create();
+
+ protected abstract InternationalString getDescription();
+
+ protected abstract Map<String, Parameter<?>> getParameterInfo();
+
+ protected abstract Map<String, Parameter<?>> getResultInfo(Map<String, Object> parameters)
+ throws IllegalArgumentException;
+
+ protected abstract InternationalString getTitle();
+
+ protected abstract String getVersion();
+
+ protected abstract boolean supportsProgress();
+
+}
Index: src/main/java/org/geotools/process/impl/AbstractProcessFactory.java
===================================================================
--- src/main/java/org/geotools/process/impl/AbstractProcessFactory.java (revisione 33810)
+++ src/main/java/org/geotools/process/impl/AbstractProcessFactory.java (copia locale)
@@ -1,37 +0,0 @@
-/*
- * GeoTools - The Open Source Java GIS Toolkit
- * http://geotools.org
- *
- * (C) 2008, Open Source Geospatial Foundation (OSGeo)
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation;
- * version 2.1 of the License.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- */
-package org.geotools.process.impl;
-
-import org.geotools.process.ProcessFactory;
-
-/**
- * Super class that provides additional helper methods
- * useful when implementing your own ProcessFactory.
- *
- * @author gdavis
- */
-public abstract class AbstractProcessFactory implements ProcessFactory {
-
- public String getName() {
- String factoryName = this.getClass().getSimpleName();
- if( factoryName.endsWith("Factory")){
- return factoryName.substring(0, factoryName.length()-7);
- }
- return factoryName;
- }
-
-}
Index: src/main/java/org/geotools/process/impl/BeanProcessFactory.java
===================================================================
--- src/main/java/org/geotools/process/impl/BeanProcessFactory.java (revisione 33810)
+++ src/main/java/org/geotools/process/impl/BeanProcessFactory.java (copia locale)
@@ -20,7 +20,6 @@
import java.beans.IntrospectionException;
import java.beans.Introspector;
import java.beans.PropertyDescriptor;
-import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.HashMap;
import java.util.Map;
@@ -30,8 +29,12 @@
import org.geotools.process.ProcessFactory;
import org.geotools.text.Text;
import org.opengis.util.InternationalString;
-import org.opengis.util.ProgressListener;
+/**
+ * Reflective implementation of a {...@link SingleProcessFactory} that will embed in the
+ * same entity both the process and the factory.
+ * The process is supposed to take a bean as a parameter and return a bean as a result.
+ */
public abstract class BeanProcessFactory implements ProcessFactory {
public Process create() {
@@ -152,7 +155,5 @@
*/
protected abstract Class<?> getInputBean();
protected abstract Class<?> getResultBean();
- protected Object process( Object input ) {
- return null; // please implement your process here
- }
+ protected abstract Object process( Object input );
}
Index: src/main/java/org/geotools/process/Processors.java
===================================================================
--- src/main/java/org/geotools/process/Processors.java (revisione 33810)
+++ src/main/java/org/geotools/process/Processors.java (copia locale)
@@ -28,6 +28,7 @@
import org.geotools.factory.FactoryRegistry;
import org.geotools.resources.LazySet;
import org.geotools.util.NullProgressListener;
+import org.opengis.feature.type.Name;
/**
@@ -79,9 +80,9 @@
* @param name Name of Factory
* @return ProcessFactory with matching name
*/
- public static synchronized ProcessFactory createProcessFactory( String name){
- for( ProcessFactory factory : getProcessFactories() ){
- if( name.equals( factory.getName() )){
+ public static synchronized ProcessFactory createProcessFactory(Name name){
+ for( ProcessFactory factory : getProcessFactories() ) {
+ if(factory.getNames().contains(name)) {
return factory;
}
}
@@ -91,11 +92,11 @@
/**
* Look up an implementation of the named process on the classpath.
*/
- public static synchronized Process createProcess(String name){
+ public static synchronized Process createProcess(Name name){
ProcessFactory factory = createProcessFactory( name );
if( factory == null ) return null;
- return factory.create();
+ return factory.create(name);
}
/**
Index: src/main/java/org/geotools/process/ProcessFactory.java
===================================================================
--- src/main/java/org/geotools/process/ProcessFactory.java (revisione 33810)
+++ src/main/java/org/geotools/process/ProcessFactory.java (copia locale)
@@ -17,68 +17,86 @@
package org.geotools.process;
import java.util.Map;
+import java.util.Set;
import org.geotools.data.Parameter;
+import org.opengis.feature.type.Name;
import org.opengis.util.InternationalString;
/**
- * Used to describe the parameters needed for a Process, and for creating a Process to use.
+ * Used to describe the parameters needed for a group of Process, and for creating a Process to use.
*
* @author gdavis
+ * @author Andrea Aime - OpenGeo
*/
public interface ProcessFactory {
+ public static final String GT_NAMESPACE = "gt";
/**
- * Unique name (non human readable) that can be used to
- * refer to this implementation.
+ * The names (non human readable) that can be used to
+ * refer to the processes generated by this factory.
* <p>
* This name is used to advertise the availability of a Process
* in a WPS; while the Title and Description will change depending
* on the users locale; this name will be consistent.
* </p>
* It is up to the implementor to ensure this name is unique
- * @return name of this process factory
+ * @return a set of names handled by this process factory
*/
- public String getName();
+ public Set<Name> getNames();
- /** Human readable title suitable for display.
+ /** Human readable title suitable for display for the specified process
* <p>
* Please note that this title is *not* stable across locale; if you want
* to remember a ProcessFactory between runs please use getName (which is
* dependent on the implementor to guarantee uniqueness) or use the classname
+ * @param name the process identifier
*/
- public InternationalString getTitle();
+ public InternationalString getTitle(Name name);
/**
- * Human readable description of this process.
+ * Human readable description of the specified process
+ * @param name the process whose description is to be returned
* @return
*/
- public InternationalString getDescription();
+ public InternationalString getDescription(Name name);
/**
* Description of the Map parameter to use when executing.
+ * @param name the process identifier
* @return Description of required parameters
+ *
*/
- public Map<String,Parameter<?>> getParameterInfo();
+ public Map<String,Parameter<?>> getParameterInfo(Name name);
/**
* Create a process for execution.
* @return Process implementation
+ * @param name the process identifier
*/
- public Process create();
+ public Process create(Name name);
- public Map<String,Parameter<?>> getResultInfo(Map<String, Object> parameters) throws IllegalArgumentException;
+ /**
+ * Description of the results returned
+ * @param name the process identifier
+ * @param parameters the parameters to be used
+ * @return
+ * @throws IllegalArgumentException
+ */
+ public Map<String,Parameter<?>> getResultInfo(Name name, Map<String, Object> parameters) throws IllegalArgumentException;
/**
* It is up to the process implementors to implement progress on the task,
* this method is used to see if the process has progress monitoring implemented
+ * @param name the process identifier
* @return true if it supports progress monitoring
*/
- public boolean supportsProgress();
+ public boolean supportsProgress(Name name);
/**
* Return the version of the process
+ * @param name the process identifier
* @return String version
*/
- public String getVersion();
+ public String getVersion(Name name);
}
Index: src/main/java/org/geotools/process/feature/AbstractFeatureCollectionProcessFactory.java
===================================================================
--- src/main/java/org/geotools/process/feature/AbstractFeatureCollectionProcessFactory.java (revisione 33810)
+++ src/main/java/org/geotools/process/feature/AbstractFeatureCollectionProcessFactory.java (copia locale)
@@ -22,7 +22,7 @@
import org.geotools.data.Parameter;
import org.geotools.feature.FeatureCollection;
import org.geotools.process.ProcessFactory;
-import org.geotools.process.impl.AbstractProcessFactory;
+import org.geotools.process.impl.SingleProcessFactory;
import org.geotools.text.Text;
/**
@@ -41,7 +41,7 @@
* @author Justin Deoliveira, OpenGEO
* @since 2.6
*/
-public abstract class AbstractFeatureCollectionProcessFactory extends AbstractProcessFactory {
+public abstract class AbstractFeatureCollectionProcessFactory extends SingleProcessFactory {
/** Features for operation */
public static final Parameter<FeatureCollection> FEATURES = new Parameter<FeatureCollection>(
"features", FeatureCollection.class, Text.text("Features"), Text.text("Features to process"));
Index: src/main/java/org/geotools/process/literal/UnionFactory.java
===================================================================
--- src/main/java/org/geotools/process/literal/UnionFactory.java (revisione 33810)
+++ src/main/java/org/geotools/process/literal/UnionFactory.java (copia locale)
@@ -21,8 +21,9 @@
import java.util.TreeMap;
import org.geotools.data.Parameter;
+import org.geotools.feature.NameImpl;
import org.geotools.process.Process;
-import org.geotools.process.impl.AbstractProcessFactory;
+import org.geotools.process.impl.SingleProcessFactory;
import org.geotools.text.Text;
import org.geotools.util.SimpleInternationalString;
import org.opengis.util.InternationalString;
@@ -41,7 +42,7 @@
*
* @author gdavis
*/
-public class UnionFactory extends AbstractProcessFactory {
+public class UnionFactory extends SingleProcessFactory {
// making parameters available as static constants to help java programmers
/** First geometry for union */
static final Parameter<Geometry> GEOM1 =
@@ -70,6 +71,10 @@
resultInfo.put( RESULT.key, RESULT );
}
+ public UnionFactory() {
+ super(new NameImpl(GT_NAMESPACE, "Union"));
+ }
+
public Process create(){
return new UnionProcess();
}
@@ -94,11 +99,6 @@
return Text.text("Union");
}
- @Override
- public String getName() {
- return "Union";
- }
-
public boolean supportsProgress() {
return true;
}
Index: src/main/java/org/geotools/process/literal/BufferFactory.java
===================================================================
--- src/main/java/org/geotools/process/literal/BufferFactory.java (revisione 33810)
+++ src/main/java/org/geotools/process/literal/BufferFactory.java (copia locale)
@@ -21,8 +21,9 @@
import java.util.TreeMap;
import org.geotools.data.Parameter;
+import org.geotools.feature.NameImpl;
import org.geotools.process.Process;
-import org.geotools.process.impl.AbstractProcessFactory;
+import org.geotools.process.impl.SingleProcessFactory;
import org.geotools.text.Text;
import org.opengis.util.InternationalString;
@@ -35,7 +36,7 @@
*
* @author gdavis
*/
-public class BufferFactory extends AbstractProcessFactory {
+public class BufferFactory extends SingleProcessFactory {
// making parameters available as static constants to help java programmers
/** Geometry for operation */
static final Parameter<Geometry> GEOM1 =
@@ -66,6 +67,10 @@
resultInfo.put( RESULT.key, RESULT );
}
+ public BufferFactory() {
+ super(new NameImpl(GT_NAMESPACE, "buffer"));
+ }
+
public Process create(Map<String, Object> parameters)
throws IllegalArgumentException {
return new BufferProcess( this );
@@ -94,11 +99,6 @@
return new BufferProcess( this );
}
- @Override
- public String getName() {
- return "buffer";
- }
-
public boolean supportsProgress() {
return true;
}
Index: src/main/java/org/geotools/process/literal/FeatureBufferFactory.java
===================================================================
--- src/main/java/org/geotools/process/literal/FeatureBufferFactory.java (revisione 33810)
+++ src/main/java/org/geotools/process/literal/FeatureBufferFactory.java (copia locale)
@@ -22,8 +22,9 @@
import java.util.TreeMap;
import org.geotools.data.Parameter;
+import org.geotools.feature.NameImpl;
import org.geotools.process.Process;
-import org.geotools.process.impl.AbstractProcessFactory;
+import org.geotools.process.impl.SingleProcessFactory;
import org.geotools.text.Text;
import org.opengis.feature.Feature;
import org.opengis.util.InternationalString;
@@ -33,8 +34,7 @@
*
* @author Lucas Reed, Refractions Research Inc
*/
-public class FeatureBufferFactory extends AbstractProcessFactory
-{
+public class FeatureBufferFactory extends SingleProcessFactory {
static final Parameter<Feature> INPUT_A = new Parameter<Feature>("input_a",
Feature.class, Text.text("Input Feature"), Text.text("Feature to buffer"));
static final Parameter<Double> INPUT_B = new Parameter<Double>("input_b", Double.class,
@@ -55,6 +55,10 @@
{
resultInfo.put(RESULT.key, RESULT);
}
+
+ public FeatureBufferFactory() {
+ super(new NameImpl(GT_NAMESPACE, "FeatureBuffer"));
+ }
public Process create(Map<String, Object> parameters) throws IllegalArgumentException
{
@@ -81,12 +85,6 @@
return Text.text("FeatureBuffer");
}
- @Override
- public String getName()
- {
- return "FeatureBuffer";
- }
-
public boolean supportsProgress()
{
return true;
Index: src/main/java/org/geotools/process/literal/DoubleAdditionFactory.java
===================================================================
--- src/main/java/org/geotools/process/literal/DoubleAdditionFactory.java (revisione 33810)
+++ src/main/java/org/geotools/process/literal/DoubleAdditionFactory.java (copia locale)
@@ -29,11 +29,12 @@
import org.geotools.text.Text;
import org.geotools.data.Parameter;
+import org.geotools.feature.NameImpl;
import org.geotools.process.Process;
import org.opengis.util.InternationalString;
-import org.geotools.process.impl.AbstractProcessFactory;
+import org.geotools.process.impl.SingleProcessFactory;
-public class DoubleAdditionFactory extends AbstractProcessFactory
+public class DoubleAdditionFactory extends SingleProcessFactory
{
static final Parameter<Double> INPUT_A = new Parameter<Double>("input_a", Double.class, Text.text("First value"), Text.text("First value to add"));
static final Parameter<Double> INPUT_B = new Parameter<Double>("input_b", Double.class, Text.text("Second value"), Text.text("Second value to add"));
@@ -51,6 +52,10 @@
{
resultInfo.put(RESULT.key, RESULT);
}
+
+ public DoubleAdditionFactory() {
+ super(new NameImpl(GT_NAMESPACE, "DoubleAddition"));
+ }
public Process create(Map<String, Object> parameters) throws IllegalArgumentException
{
@@ -82,12 +87,6 @@
return new DoubleAdditionProcess(this);
}
- @Override
- public String getName()
- {
- return "DoubleAddition";
- }
-
public boolean supportsProgress()
{
return true;
Index: src/main/java/org/geotools/process/literal/IntersectionFactory.java
===================================================================
--- src/main/java/org/geotools/process/literal/IntersectionFactory.java (revisione 33810)
+++ src/main/java/org/geotools/process/literal/IntersectionFactory.java (copia locale)
@@ -21,8 +21,9 @@
import java.util.TreeMap;
import org.geotools.data.Parameter;
+import org.geotools.feature.NameImpl;
import org.geotools.process.Process;
-import org.geotools.process.impl.AbstractProcessFactory;
+import org.geotools.process.impl.SingleProcessFactory;
import org.geotools.text.Text;
import org.opengis.util.InternationalString;
@@ -40,7 +41,7 @@
*
* @author gdavis
*/
-public class IntersectionFactory extends AbstractProcessFactory {
+public class IntersectionFactory extends SingleProcessFactory {
// making parameters available as static constants to help java programmers
/** First geometry for intersection */
static final Parameter<Geometry> GEOM1 =
@@ -71,6 +72,10 @@
resultInfo.put( RESULT.key, RESULT );
}
+ public IntersectionFactory() {
+ super(new NameImpl(GT_NAMESPACE, "Intersect"));
+ }
+
public Process create()
throws IllegalArgumentException {
return new IntersectionProcess( this );
@@ -96,11 +101,6 @@
return Text.text("Intersection");
}
- @Override
- public String getName() {
- return "Intersect";
- }
-
public boolean supportsProgress() {
return false;
}
------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
trial. Simplify your report design, integration and deployment - and focus on
what you do best, core application coding. Discover what's new with
Crystal Reports now. http://p.sf.net/sfu/bobj-july
_______________________________________________
Geotools-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/geotools-devel