01: /* Copyright (c) 2001 - 2007 TOPP - www.openplans.org. All rights reserved.
02: * This code is licensed under the GPL 2.0 license, availible at the root
03: * application directory.
04: */
05: package org.geoserver.ows.util;
06:
07: import org.geoserver.ows.KvpParser;
08: import org.geotools.util.Converters;
09:
10: /**
11: * A kvp parser which parses a value into a numeric value.
12: * <p>
13: * The type of the number is determined by {@link #getBinding()}. It must be
14: * assignable from {@link Number}.
15: * </p>
16: * @author Justin Deoliveira, The Open Planning Project, jdeolive@openplans.org
17: *
18: */
19: public class NumericKvpParser extends KvpParser {
20: /**
21: * Constructs a numeric kvp parser with the specified key and binding.
22: *
23: * @param key The key to bind to.
24: * @param binding The resulting type of parsed object, must be a subclass
25: * of {@link Number}.
26: */
27: public NumericKvpParser(String key, Class binding) {
28: super (key, binding);
29:
30: if (!Number.class.isAssignableFrom(binding)) {
31: throw new IllegalArgumentException(
32: "Number is not assignable from: " + binding);
33: }
34: }
35:
36: /**
37: * Parses the string into a numberic value.
38: */
39: public Object parse(String value) throws Exception {
40: return Converters.convert(value, getBinding());
41: }
42: }
|