001package org.andromda.andromdapp; 002 003import java.util.ArrayList; 004import java.util.List; 005import org.apache.commons.lang.StringUtils; 006 007/** 008 * Represents a mapping within an AndroMDApp descriptor. 009 * 010 * @author Chad Brandon 011 */ 012public class Mapping 013{ 014 /** 015 * Stores the mappings from which the output is mapped. 016 */ 017 private final List<String> froms = new ArrayList<String>(); 018 019 /** 020 * Adds a from to this mapping's list of from mappings. 021 * 022 * @param from the from mapping. 023 */ 024 public void addFrom(final String from) 025 { 026 this.froms.add(from); 027 } 028 029 /** 030 * Attempts to match the given <code>path</code> on one of the 031 * the from values, if a match can be made, the new path value is returned, 032 * otherwise null is returned. 033 * @param path 034 * 035 * @return true/false 036 */ 037 public String getMatch(final String path) 038 { 039 String match = null; 040 for (final String from : this.froms) 041 { 042 if (path.contains(from)) 043 { 044 match = StringUtils.replace(path, from, to); 045 } 046 } 047 return match; 048 } 049 050 051 private String to; 052 053 /** 054 * @return Returns the to. 055 */ 056 public String getTo() 057 { 058 return to; 059 } 060 061 /** 062 * @param to The to to set. 063 */ 064 public void setTo(final String to) 065 { 066 this.to = to; 067 } 068}