Dashboard > GeoTools 2.5 Users Guide > ... > 07 Referencing > 02 Parameters
GeoTools 2.5 Users Guide
02 Parameters
Added by jgarnett , last edited by jgarnett on Dec 22, 2006  (view change)
Labels: 
(None)

The Parameters used by the referencing module are a stange beast, they are actually a dynamic type system (you need to inspect the values at runtime in order to learn what values are acceptable).

All of this is very similar to ISO19119, in terms of having a dynamic system to specify allowable parameters. In general we will try and favour the use of Java Beans were possible.

ParameterDescriptors

A ParameterDescriptor is used to advertise what values are acceptable, the quickest way to show this is to create one.

final DefaultParameterDescriptor RANGE =
    new DefaultParameterDescriptor("Range", 15.0, -30.0, +40.0, null)

And then ask it questions:

System.out.println( RANGE.getMinimumValue().compareTo( new Double(2) ) );
System.out.println( RANGE.getMaximumValue().compareTo( new Double(20) ) );

Please not that metadata classes such as Identifier are used here:

Identifier name = RANGE.getName();
System.out.println( name );

ParameterValue

A Parameter value is used to hold a single value, within the limits of the ParameterDescriptor.

ParameterValue value = (ParameterValue) RANGE.createValue();
value.setValue( 2.0 );

You are kind of on the honour system here:

value.setValue( 20.0 ); // out of RANGE  
value.setValue( 2 ); // wrong type

You can actually get very specific with the use of units:

final DefaultParameterDescriptor LIMIT =
    new DefaultParameterDescriptor(
         Citations.GEOTOOLS, "Limit", Double.class,
         null, null, null. null, SI.METER.divide(SI.SECOND), true);

Enumerations

You can indicate a set of valid values with a "CodeList" (like a Java 1.4 enum, but allows more values at runtime):

final DefaultParameterDescriptor STATUS = new DefaultParameterDescriptor("Status",Status.GOOD );

ParameterValue status = (ParameterValue) STATUS.createValue();

Here is that code list:

class Status extends CodeList {
        private static final long serialVersionUID = 0L;        
        static ArrayList values = new ArrayList();
        static Status GOOD = new Status("GOOD");
        static Status BAD = new Status("BAD");
        static Status UGLY = new Status("UGLY");        
        private Status( String name){
            super( name, values );
        }
        public CodeList[] family() {
            return (Status[]) values.toArray( new Status[ values.size()]);
        }
}

Groups

You can also have groups of parameters (that may repeat if needed as indicated by minOccurs and maxOccurs). Here is a simple example with associating prefix with URI.

final DefaultParameterDescriptor PREFIX =
    new DefaultParameterDescriptor(
        Citations.GEOTOOLS, "Perfix", String.class,
        null, null, null. null, null, true);
final DefaultParameterDescriptor NAMESPACE =
    new DefaultParameterDescriptor(
        Citations.GEOTOOLS, "Namespace", URI.class,
        null, null, null. null, null, true);        

final DefaultParameterDescriptorGroup REFERENCES = new DefaultParameterDescriptorGroup(
    Citations.GEOTOOLS,
    "Referneces",
    new DefaultParameterDescriptor[]{PREFIX,NAMESPACE}
);

You can have groups within groups, and so on.

Quick Metadata

You can use a Map to quickly create a citation, incase a constant does not suite you:

Map metadata = new HashMap();
metadata.put( "authority", System.getProperties().get("user.name"));
metadata.put( "name", "References2");
metadata.put( "alias", "References II");

final DefaultParameterDescriptorGroup REFERENCES2 = new DefaultParameterDescriptorGroup(
    metadata, 0, Integer.MAX_VALUE,
    new DefaultParameterDescriptor[]{PREFIX,NAMESPACE}
);

The above example also has the References2 group being optional (minOccurs == 0), and any number of references are allowed (maxOccurs == Integer.MAX_VALUE ).

Site running on a free Atlassian Confluence Open Source Project License granted to The Codehaus. Evaluate Confluence today.
Powered by Atlassian Confluence, the Enterprise Wiki. (Version: 2.6.2 Build:#919 Nov 26, 2007) - Bug/feature request - Contact Administrators