Hi Andrea:

You asked what some of the "defaults" were doing in the API; and I had
a look at them today while cleaning up 2.6.x. In particular we have a
few places where constants are defined in order to document what
options are available.

Michael I am determined to make the library easier to use; mostly
using our tutorials as a stick to beat useful methods in (or useless
methods out) where we can. This is our first example ...

interface Font {
    /**
     * @param style The "font-style" SVG parameter (one of "normal",
"italic", or "oblique"
     */
    void setStyle( Expression style );
    ...
    /** An enumeration of font style values
     */
    interface Style {
        static final String NORMAL = "normal";
        static final String ITALIC = "italic";
        static final String OBLIQUE = "oblique";
    }
}

These are a pain to use out of the box without:
- making them an actual enumeration which implements Literal; or
- adding a setStyle( String style ) method; or
- font.setStyle( filterFactory.literal( Font.Style.NORMAL ) )

For reference here is what making this a real enum would look like
(allowing font.setStyle( Font.Style.NORMAL ) to be used directly)
/**
     * Enumeration of allow font-style values.
     * <p>
     * This is a way to document the constants allowable for the setStyle method
     */
    enum Style2 implements Literal {
        NORMAL("normal"),
        ITALIC("italic"),
        OBLIQUE("oblique");

        final String literal;
        final static int count=0;
        private Style2(String constant) {
            literal = constant;
        }
        public Object accept(ExpressionVisitor visitor, Object extraData) {
            return visitor.visit( this, extraData );
        }
        public Object evaluate(Object object) {
            return literal;
        }
        public <T> T evaluate(Object object, Class<T> context) {
            // return Converters.convert(literal, context);
            if( context.isInstance( literal) ){
                return context.cast(literal);
            }
            return null;
        }
        public Object getValue() {
            return literal;
        }
    }

There are two problems
- the location of the converter API (it is part of main); perhaps we
can move it to api for more general usefulness
- you cannot provide an implementation of equals or hascode for an
enumeration (so I need to use a CodeList)

It may be easier to provide these as static final ConstantExpressions
rather than group them into enumerations as has been done here.

Jody

------------------------------------------------------------------------------
Register Now & Save for Velocity, the Web Performance & Operations 
Conference from O'Reilly Media. Velocity features a full day of 
expert-led, hands-on workshops and two days of sessions from industry 
leaders in dedicated Performance & Operations tracks. Use code vel09scf 
and Save an extra 15% before 5/3. http://p.sf.net/sfu/velocityconf
_______________________________________________
Geotools-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/geotools-devel

Reply via email to