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;
06:
07: import java.util.logging.Logger;
08:
09: /**
10: * Parses a key-value pair into a key-object pair.
11: * <p>
12: * This class is intended to be subclassed. Subclasses need declare the key in
13: * which they parse, and the type of object they parse into.
14: * </p>
15: * <p>
16: * Instances need to be declared in a spring context like the following:
17: * <pre>
18: * <code>
19: * <bean id="myKvpParser" class="org.xzy.MyKvpParser"/>
20: * </code>
21: * </pre>
22: * Where <code>com.xzy.MyKvpParser</code> could be something like:
23: * <pre>
24: * <code>
25: * public class MyKvpParser extends KvpParser {
26: *
27: * public MyKvpParser() {
28: * super( "MyKvp", MyObject.class )l
29: * }
30: *
31: * public Object parse( String value ) {
32: * return new MyObject( value );
33: * }
34: * }
35: * </code>
36: * </pre>
37: * </p>
38: * @author Justin Deoliveira, The Open Planning Project, jdeolive@openplans.org
39: *
40: */
41: public abstract class KvpParser {
42: /**
43: * logger
44: */
45: protected static Logger LOGGER = org.geotools.util.logging.Logging
46: .getLogger("org.geoserver.ows");
47:
48: /**
49: * The key.
50: */
51: String key;
52:
53: /**
54: * The class of parsed objects.
55: */
56: Class binding;
57:
58: public KvpParser(String key, Class binding) {
59: this .key = key;
60: this .binding = binding;
61: }
62:
63: /**
64: * @return The name of the key the parser binds to.
65: */
66: public String getKey() {
67: return key;
68: }
69:
70: /**
71: * @return The type of parsed objects.
72: */
73: protected Class getBinding() {
74: return binding;
75: }
76:
77: /**
78: * Parses the string representation into the object representation.
79: *
80: * @param value The string value.
81: *
82: * @return The parsed object, or null if it could not be parsed.
83: *
84: * @throws Exception In the event of an unsuccesful parse.
85: */
86: public abstract Object parse(String value) throws Exception;
87: }
|