001/*
002 * Licensed to the Apache Software Foundation (ASF) under one or more
003 * contributor license agreements.  See the NOTICE file distributed with
004 * this work for additional information regarding copyright ownership.
005 * The ASF licenses this file to You under the Apache License, Version 2.0
006 * (the "License"); you may not use this file except in compliance with
007 * the License.  You may obtain a copy of the License at
008 *
009 *      http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017package org.apache.commons.dbutils;
018
019/**
020 * Interface to define how implementations can interact with property handling when constructing a bean from a
021 * {@link java.sql.ResultSet}.  PropertyHandlers do the work of coercing a value into the target type required.
022 */
023public interface PropertyHandler {
024
025    /**
026     * Test whether this {@code PropertyHandler} wants to handle setting {@code value} into something of type
027     * {@code parameter}.
028     *
029     * @param parameter The type of the target parameter.
030     * @param value The value to be set.
031     * @return true is this property handler can/wants to handle this value; false otherwise.
032     */
033    boolean match(Class<?> parameter, Object value);
034
035    /**
036     * Do the work required to store {@code value} into something of type {@code parameter}. This method is
037     * called only if this handler responded {@code true} after a call to {@link #match(Class, Object)}.
038     *
039     * @param parameter The type of the target parameter.
040     * @param value The value to be set.
041     * @return The converted value or the original value if something doesn't work out.
042     */
043    Object apply(Class<?> parameter, Object value);
044}