001/* 002 * The contents of this file are subject to the terms of the Common Development and 003 * Distribution License (the License). You may not use this file except in compliance with the 004 * License. 005 * 006 * You can obtain a copy of the License at legal/CDDLv1.0.txt. See the License for the 007 * specific language governing permission and limitations under the License. 008 * 009 * When distributing Covered Software, include this CDDL Header Notice in each file and include 010 * the License file at legal/CDDLv1.0.txt. If applicable, add the following below the CDDL 011 * Header, with the fields enclosed by brackets [] replaced by your own identifying 012 * information: "Portions copyright [year] [name of copyright owner]". 013 * 014 * Copyright 2015 ForgeRock AS. 015 */ 016 017package org.forgerock.services.routing; 018 019import org.forgerock.services.context.Context; 020 021/** 022 * A matcher for evaluating whether a route matches the incoming request. 023 * Implementing class can either return a {@link RouteMatch}, if the route 024 * matches, or {@code null}, if the route does not match, from the 025 * {@link #evaluate(Context, Object)} method. 026 * 027 * <p>Implementing classes must implement both {@link #equals(Object)} and 028 * {@link #hashCode()} methods as each instance of a {@code RouteMatcher} 029 * will be used as the key for a route.</p> 030 * 031 * @param <R> The type of the request. 032 */ 033public abstract class RouteMatcher<R> { 034 035 /** 036 * Evaluates the request and determines whether it matches the route. 037 * 038 * @param context The request context. 039 * @param request The request. 040 * @return A {@link RouteMatch}, if the request matches the route, or 041 * {@code null}, if not. 042 */ 043 public abstract RouteMatch evaluate(Context context, R request); 044 045 /** 046 * Returns a {@code String} representation of the route matcher. 047 * 048 * @return A string representation of the route matcher. 049 */ 050 @Override 051 public abstract String toString(); 052 053 @Override 054 public abstract int hashCode(); 055 056 @Override 057 public abstract boolean equals(Object o); 058}