001    /*
002     *    GeoAPI - Java interfaces for OGC/ISO standards
003     *    http://www.geoapi.org
004     *
005     *    Copyright (C) 2006-2012 Open Geospatial Consortium, Inc.
006     *    All Rights Reserved. http://www.opengeospatial.org/ogc/legal
007     *
008     *    Permission to use, copy, and modify this software and its documentation, with
009     *    or without modification, for any purpose and without fee or royalty is hereby
010     *    granted, provided that you include the following on ALL copies of the software
011     *    and documentation or portions thereof, including modifications, that you make:
012     *
013     *    1. The full text of this NOTICE in a location viewable to users of the
014     *       redistributed or derivative work.
015     *    2. Notice of any changes or modifications to the OGC files, including the
016     *       date changes were made.
017     *
018     *    THIS SOFTWARE AND DOCUMENTATION IS PROVIDED "AS IS," AND COPYRIGHT HOLDERS MAKE
019     *    NO REPRESENTATIONS OR WARRANTIES, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
020     *    TO, WARRANTIES OF MERCHANTABILITY OR FITNESS FOR ANY PARTICULAR PURPOSE OR THAT
021     *    THE USE OF THE SOFTWARE OR DOCUMENTATION WILL NOT INFRINGE ANY THIRD PARTY
022     *    PATENTS, COPYRIGHTS, TRADEMARKS OR OTHER RIGHTS.
023     *
024     *    COPYRIGHT HOLDERS WILL NOT BE LIABLE FOR ANY DIRECT, INDIRECT, SPECIAL OR
025     *    CONSEQUENTIAL DAMAGES ARISING OUT OF ANY USE OF THE SOFTWARE OR DOCUMENTATION.
026     *
027     *    The name and trademarks of copyright holders may NOT be used in advertising or
028     *    publicity pertaining to the software without specific, written prior permission.
029     *    Title to copyright in this software and any associated documentation will at all
030     *    times remain with copyright holders.
031     */
032    package org.opengis.filter.expression;
033    
034    import org.opengis.annotation.Extension;
035    import org.opengis.annotation.XmlElement;
036    import org.opengis.feature.Feature;
037    
038    
039    /**
040     * Interface for all the OGC Filter elements that compute values.
041     * <p>
042     * The most common use is with potentially using {@linkplain Feature feature} and
043     * metadata.  The ability to access "attributes" based on the provided content is
044     * defined based on XPath queries currently.
045     *
046     * @version <A HREF="http://www.opengis.org/docs/02-059.pdf">Implementation specification 1.0</A>
047     * @author Chris Dillard (SYS Technologies)
048     * @author Justin Deoliveira (The Open Planning Project)
049     * @since GeoAPI 2.0
050     */
051    @XmlElement("expression")
052    public interface Expression {
053        /**
054         * Constant expression that always evaulates to {@code null}.
055         * <p>
056         * This constant is a "NullObject" that can represent the absense of
057         * expression in a data structures. As example it can be used to represent
058         * the default stroke color in a LineSymbolizer Stroke structure.
059         */
060        Expression NIL = new NilExpression();
061    
062        /**
063         * Evaluates the given expression based on the content of the given object.
064         */
065        @Extension
066        Object evaluate(Object object);
067    
068        /**
069         * Evaluates the given expressoin based on the content of the given object
070         * and the context type.
071         * <p>
072         * The {@code context} parameter is used to control the type of the
073         * result of the expression. A particular expression may not be able to evaluate
074         * to an instance of {@code context}. Therefore to be safe calling code
075         * should do a null check on the return value of this method, and call {@link #evaluate(Object)}
076         * if neccessary. Example:
077         * <pre>
078         *  Object input = ...;
079         *  String result = expression.evaluate( input, String.class );
080         *  if ( result == null ) {
081         *     result = expression.evalute( input ).toString();
082         *  }
083         *  ...
084         * </pre>
085         * </p>
086         * <p>
087         * Implementations that can not return a result as an instance of {@code context}
088         * should return {@code null}.
089         * </p>
090         * @param <T> The type of the returned object.
091         * @param object The object to evaluate the expression against.
092         * @param context The type of the resulting value of the expression.
093         *
094         * @return Evaluates the given expression based on the content of the given object an
095         *         an instance of {@code context}.
096         */
097        @Extension
098        <T> T evaluate( Object object, Class<T> context );
099    
100        /**
101         * Accepts a visitor. Subclasses must implement with a method whose content is the following:
102         * <pre>return visitor.{@linkplain ExpressionVisitor#visit visit}(this, extraData);</pre>
103         */
104        @Extension
105        Object accept(ExpressionVisitor visitor, Object extraData);
106    }