01: package org.gomba.domains;
02:
03: import java.util.List;
04:
05: import org.gomba.ParameterDefinition;
06: import org.gomba.ParameterDomain;
07: import org.gomba.ParameterResolver;
08:
09: /**
10: * This domain contains properties extracted from the servlet request extra
11: * path. Each path element is named with an integer starting from 0.
12: *
13: * @author Flavio Tordini
14: * @version $Id: PathDomain.java,v 1.1.1.1 2004/06/16 13:15:12 flaviotordini Exp $
15: */
16: public class PathDomain implements ParameterDomain {
17:
18: /**
19: * @see org.gomba.ParameterDomain#getParameterValue(org.gomba.ParameterResolver,
20: * org.gomba.ParameterDefinition)
21: */
22: public Object getParameterValue(ParameterResolver context,
23: ParameterDefinition parameter) {
24: List pathElements = context.getPathElements();
25: if (pathElements.isEmpty()) {
26: return null;
27: }
28: int elementIndex = Integer.parseInt(parameter.getName());
29: // elementIndex is zerobased!
30: if (elementIndex >= pathElements.size()) {
31: return null;
32: }
33: return pathElements.get(elementIndex);
34: }
35:
36: /**
37: * @see org.gomba.ParameterDomain#getName()
38: */
39: public String getName() {
40: return "path";
41: }
42: }
|