001    // Copyright 2008 The Apache Software Foundation
002    //
003    // Licensed under the Apache License, Version 2.0 (the "License");
004    // you may not use this file except in compliance with the License.
005    // You may obtain a copy of the License at
006    //
007    //     http://www.apache.org/licenses/LICENSE-2.0
008    //
009    // Unless required by applicable law or agreed to in writing, software
010    // distributed under the License is distributed on an "AS IS" BASIS,
011    // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
012    // See the License for the specific language governing permissions and
013    // limitations under the License.
014    
015    package org.apache.tapestry;
016    
017    /**
018     * A collection of parameters that may eventually be passed to an event handler method.  Includes the ability to coerce
019     * or encode parameters as needed.
020     *
021     * @see org.apache.tapestry.ioc.services.TypeCoercer
022     * @see org.apache.tapestry.ValueEncoder
023     */
024    public interface EventContext
025    {
026        /**
027         * Returns the number of parameter values that can be extracted.
028         */
029        int getCount();
030    
031        /**
032         * Extracts a parameter value and coerces or decodes it to the desired type.
033         *
034         * @param desiredType the type of value required
035         * @param index       identifies which parameter value to extract
036         * @return the value extracted and converted or coerced
037         * @throws RuntimeException if the value can't be converted or the index is out of range
038         */
039        <T> T get(Class<T> desiredType, int index);
040    }