01: package org.andromda.andromdapp;
02:
03: import java.util.ArrayList;
04: import java.util.Iterator;
05: import java.util.List;
06:
07: import org.apache.commons.lang.StringUtils;
08:
09: /**
10: * Represents a mapping within an AndroMDApp descriptor.
11: *
12: * @author Chad Brandon
13: */
14: public class Mapping {
15: /**
16: * Stores the mappings from which the output is mapped.
17: */
18: private final List froms = new ArrayList();
19:
20: /**
21: * Adds a from to this mapping's list of from mappings.
22: *
23: * @param from the from mapping.
24: */
25: public void addFrom(final String from) {
26: this .froms.add(from);
27: }
28:
29: /**
30: * Attempts to match the given <code>path</code> on one of the
31: * the from values, if a match can be made, the new path value is returned,
32: * otherwise null is returned.
33: *
34: * @return true/false
35: */
36: public String getMatch(final String path) {
37: String match = null;
38: for (final Iterator iterator = this .froms.iterator(); iterator
39: .hasNext();) {
40: final String from = (String) iterator.next();
41: if (path.indexOf(from) != -1) {
42: match = StringUtils.replace(path, from, to);
43: }
44: }
45: return match;
46: }
47:
48: private String to;
49:
50: /**
51: * @return Returns the to.
52: */
53: public String getTo() {
54: return to;
55: }
56:
57: /**
58: * @param to The to to set.
59: */
60: public void setTo(String to) {
61: this.to = to;
62: }
63: }
|