1 /* 2 * The contents of this file are subject to the terms of the Common Development and 3 * Distribution License (the License). You may not use this file except in compliance with the 4 * License. 5 * 6 * You can obtain a copy of the License at legal/CDDLv1.0.txt. See the License for the 7 * specific language governing permission and limitations under the License. 8 * 9 * When distributing Covered Software, include this CDDL Header Notice in each file and include 10 * the License file at legal/CDDLv1.0.txt. If applicable, add the following below the CDDL 11 * Header, with the fields enclosed by brackets [] replaced by your own identifying 12 * information: "Portions copyright [year] [name of copyright owner]". 13 * 14 * Copyright 2016 ForgeRock AS. 15 */ 16 17 package org.forgerock.json.resource; 18 19 import static org.forgerock.util.Reject.checkNotNull; 20 21 /** 22 * {@link QueryResourceHandler} that searches for a specific identifier value. 23 */ 24 public class IdentifierQueryResourceHandler implements QueryResourceHandler { 25 private final String id; 26 private ResourceResponse resourceResponse; 27 28 /** 29 * Creates a new {@link QueryResourceHandler} for the given identifier. 30 * 31 * @param id Identifier to query for 32 */ 33 public IdentifierQueryResourceHandler(final String id) { 34 this.id = checkNotNull(id); 35 } 36 37 @Override 38 public boolean handleResource(final ResourceResponse resource) { 39 if (id.equals(resource.getId())) { 40 resourceResponse = resource; 41 return false; 42 } 43 return true; 44 } 45 46 /** 47 * Gets the identifier being queried for. 48 * 49 * @return Identifier 50 */ 51 public String getId() { 52 return id; 53 } 54 55 /** 56 * Gets the {@link ResourceResponse} query result. 57 * 58 * @return {@link ResourceResponse} or {@code null} if not yet found 59 */ 60 public ResourceResponse getResourceResponse() { 61 return resourceResponse; 62 } 63 }