001: package org.andromda.core.cartridge.template;
002:
003: import java.util.Collection;
004: import java.util.LinkedHashMap;
005: import java.util.Map;
006:
007: import org.apache.commons.lang.StringUtils;
008:
009: /**
010: * Represents the <type/> element nested within the <modelElement/> element.
011: *
012: * @author Chad Brandon
013: * @see ModelElement
014: */
015: public class Type {
016: /**
017: * The name of this type.
018: */
019: private String name;
020:
021: /**
022: * Gets the name of this type (typically the fully qualified class name
023: * of the type).
024: *
025: * @return Returns the name.
026: */
027: public String getName() {
028: return StringUtils.trimToEmpty(name);
029: }
030:
031: /**
032: * Sets the name of this type (this is the fully qualified class name
033: * of the type).
034: *
035: * @param name The name to set.
036: */
037: public void setName(final String name) {
038: this .name = name;
039: }
040:
041: /**
042: * The properties that must be valid for this type.
043: */
044: private final Map properties = new LinkedHashMap();
045:
046: /**
047: * Gets the properties defined for this type.
048: *
049: * @return Returns the properties.
050: */
051: public Collection getProperties() {
052: return properties.values();
053: }
054:
055: /**
056: * Adds a property having the given <code>name</code> and <code>value</code>. The <code>value</code> is what the
057: * property must be in order to be collected.
058: *
059: * @param name the name of the property.
060: * @param variable the optional variable name in which the contents of this
061: * property's value should be stored within a template.
062: * @param value the option value the property must be in order to be considered <code>valid</code>.
063: */
064: public void addProperty(final String name, final String variable,
065: final String value) {
066: if (value != null && !this .properties.containsKey(name)) {
067: this .properties.put(name, new Property(name, variable,
068: value));
069: }
070: }
071:
072: /**
073: * Stores and provides access to the type's <property/> elements.
074: */
075: public static final class Property {
076: private String name;
077: private String variable;
078: private String value;
079:
080: Property(final String name, final String variable,
081: final String value) {
082: this .name = StringUtils.trimToEmpty(name);
083: this .variable = StringUtils.trimToEmpty(variable);
084: this .value = StringUtils.trimToEmpty(value);
085: }
086:
087: /**
088: * Gets the value of the <code>name</code> attribute on the <code>property</code> element.
089: *
090: * @return the name
091: */
092: public String getName() {
093: return this .name;
094: }
095:
096: /**
097: * Gets the variable name under which this property's value (or element if the property
098: * is a collection) should be stored within the template.
099: *
100: * @return the variable name.
101: */
102: public String getVariable() {
103: return this .variable;
104: }
105:
106: /**
107: * Gets the value of the <code>value</code> attribute defined on the <code>property</code> element.
108: *
109: * @return the value
110: */
111: public String getValue() {
112: return this.value;
113: }
114: }
115: }
|