View Javadoc
1   package org.andromda.andromdapp;
2   
3   import java.util.ArrayList;
4   import java.util.List;
5   import org.apache.commons.lang.StringUtils;
6   
7   /**
8    * Represents a mapping within an AndroMDApp descriptor.
9    *
10   * @author Chad Brandon
11   */
12  public class Mapping
13  {
14      /**
15       * Stores the mappings from which the output is mapped.
16       */
17      private final List<String> froms = new ArrayList<String>();
18  
19      /**
20       * Adds a from to this mapping's list of from mappings.
21       *
22       * @param from the from mapping.
23       */
24      public void addFrom(final String from)
25      {
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       * @param path
34       *
35       * @return true/false
36       */
37      public String getMatch(final String path)
38      {
39          String match = null;
40          for (final String from : this.froms)
41          {
42              if (path.contains(from))
43              {
44                  match = StringUtils.replace(path, from, to);
45              }
46          }
47          return match;
48      }
49  
50  
51      private String to;
52  
53      /**
54       * @return Returns the to.
55       */
56      public String getTo()
57      {
58          return to;
59      }
60  
61      /**
62       * @param to The to to set.
63       */
64      public void setTo(final String to)
65      {
66          this.to = to;
67      }
68  }