| Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
| VarExploder |
|
| 1.0;1 |
| 1 | /* | |
| 2 | * Copyright 2012, Ryan J. McDonough | |
| 3 | * | |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); | |
| 5 | * you may not use this file except in compliance with the License. | |
| 6 | * You may obtain a copy of the License at | |
| 7 | * | |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 | |
| 9 | * | |
| 10 | * Unless required by applicable law or agreed to in writing, software | |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, | |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
| 13 | * See the License for the specific language governing permissions and | |
| 14 | * limitations under the License. | |
| 15 | */ | |
| 16 | package com.damnhandy.uri.template; | |
| 17 | ||
| 18 | import java.util.Collection; | |
| 19 | import java.util.Map; | |
| 20 | ||
| 21 | ||
| 22 | ||
| 23 | /** | |
| 24 | * | |
| 25 | * <p> | |
| 26 | * A {@link VarExploder} is invoked when an explode modifier "*" is encountered within | |
| 27 | * a variable name within a URI expression expression and the replacement value is a complex | |
| 28 | * type, such a some type of POJO or other data type. For most use cases, the {@link DefaultVarExploder} will be | |
| 29 | * sufficient. Please refer to the {@link DefaultVarExploder} JavaDoc | |
| 30 | * for more details on how it works. | |
| 31 | * </p> | |
| 32 | * | |
| 33 | * <p> | |
| 34 | * Should the {@link DefaultVarExploder} not be suitable for your needs, custom {@link VarExploder} | |
| 35 | * implementations can be added by rolling your own implementation. A custom {@link VarExploder} | |
| 36 | * implementation can be registered in one of two ways. By wrapping your object in your {@link VarExploder}: | |
| 37 | * </p> | |
| 38 | * <pre> | |
| 39 | * UriTemplate.fromTemplate("/mapper{?address*}").set("address", new MyCustomVarExploder(address)).expand(); | |
| 40 | * </pre> | |
| 41 | * <p> | |
| 42 | * <strong>Note:</strong> {@link VarExploder} implementations are <strong>ONLY</strong> invoked when the | |
| 43 | * explode modifier "*" is declared in the URI Template expression. If the variable declaration does not | |
| 44 | * specify the explode modifier, a {@link VariableExpansionException} will be raised. | |
| 45 | * </p> | |
| 46 | * | |
| 47 | * <p> | |
| 48 | * Please see the unit test on example usage of a custom {@link VarExploder}. | |
| 49 | * </p> | |
| 50 | * | |
| 51 | * | |
| 52 | * @author <a href="ryan@damnhandy.com">Ryan J. McDonough</a> | |
| 53 | * @version $Revision: 1.1 $ | |
| 54 | * @since 1.0 | |
| 55 | */ | |
| 56 | public interface VarExploder | |
| 57 | { | |
| 58 | ||
| 59 | ||
| 60 | /** | |
| 61 | * Returns the properties of the source object a {@link Map} of | |
| 62 | * name/value pairs. | |
| 63 | * | |
| 64 | * @return the object properties as name/value pairs. | |
| 65 | */ | |
| 66 | Map<String, Object> getNameValuePairs() throws VariableExpansionException; | |
| 67 | ||
| 68 | /** | |
| 69 | * Returns the properties of the source object a {@link Collection} of | |
| 70 | * object values. | |
| 71 | * | |
| 72 | * @return | |
| 73 | */ | |
| 74 | Collection<Object> getValues() throws VariableExpansionException; | |
| 75 | ||
| 76 | } |