1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package net.sf.morph.lang.support;
17
18 import net.sf.composite.util.ObjectUtils;
19 import net.sf.morph.lang.InvalidExpressionException;
20
21 /**
22 * A base class for expression parsers.
23 *
24 * @author Matt Sgarlata
25 * @since Nov 28, 2004
26 */
27 public abstract class BaseExpressionParser implements ExpressionParser {
28
29 /**
30 * Implement <code>parse(expression)</code>.
31 * @param expression to parse
32 * @return String[] of path elements.
33 * @throws Exception
34 */
35 public abstract String[] parseImpl(String expression) throws Exception;
36
37 /**
38 * {@inheritDoc}
39 */
40 public String[] parse(String expression) throws InvalidExpressionException {
41 if (ObjectUtils.isEmpty(expression)) {
42 return new String[] { };
43 }
44
45 try {
46 return parseImpl(expression);
47 }
48 catch (InvalidExpressionException e) {
49 throw e;
50 }
51 catch (Exception e) {
52 throw new InvalidExpressionException("The expression '" + expression + "' is invalid", e);
53 }
54 }
55
56 }