View Javadoc
1   package org.andromda.core.cartridge.template;
2   
3   import java.util.Collection;
4   import java.util.LinkedHashMap;
5   import java.util.Map;
6   import org.apache.commons.lang.StringUtils;
7   
8   /**
9    * Represents the <type/> element nested within the <modelElement/> element.
10   *
11   * @author Chad Brandon
12   * @see ModelElement
13   */
14  public class Type
15  {
16      /**
17       * The name of this type.
18       */
19      private String name;
20  
21      /**
22       * Gets the name of this type (typically the fully qualified class name
23       * of the type).
24       *
25       * @return Returns the name.
26       */
27      public String getName()
28      {
29          return StringUtils.trimToEmpty(name);
30      }
31  
32      /**
33       * Sets the name of this type (this is the fully qualified class name
34       * of the type).
35       *
36       * @param name The name to set.
37       */
38      public void setName(final String name)
39      {
40          this.name = name;
41      }
42  
43      /**
44       * The properties that must be valid for this type.
45       */
46      private final Map<String, Property> properties = new LinkedHashMap<String, Property>();
47  
48      /**
49       * Gets the properties defined for this type.
50       *
51       * @return Returns the properties.
52       */
53      public Collection<Property> getProperties()
54      {
55          return properties.values();
56      }
57  
58      /**
59       * Adds a property having the given <code>name</code> and <code>value</code>. The <code>value</code> is what the
60       * property must be in order to be collected.
61       *
62       * @param name  the name of the property.
63       * @param variable the optional variable name in which the contents of this
64       *        property's value should be stored within a template.
65       * @param value the option value the property must be in order to be considered <code>valid</code>.
66       */
67      public void addProperty(
68          final String name,
69          final String variable,
70          final String value)
71      {
72          if (value != null && !this.properties.containsKey(name))
73          {
74              this.properties.put(
75                  name,
76                  new Property(name, variable, value));
77          }
78      }
79  
80      /**
81       * Stores and provides access to the type's &lt;property/&gt; elements.
82       */
83      public static final class Property
84      {
85          private String name;
86          private String variable;
87          private String value;
88  
89          /**
90           * @param name
91           * @param variable
92           * @param value
93           */
94          Property(
95              final String name,
96              final String variable,
97              final String value)
98          {
99              this.name = StringUtils.trimToEmpty(name);
100             this.variable = StringUtils.trimToEmpty(variable);
101             this.value = StringUtils.trimToEmpty(value);
102         }
103 
104         /**
105          * Gets the value of the <code>name</code> attribute on the <code>property</code> element.
106          *
107          * @return the name
108          */
109         public String getName()
110         {
111             return this.name;
112         }
113 
114         /**
115          * Gets the variable name under which this property's value (or element if the property
116          * is a collection) should be stored within the template.
117          *
118          * @return the variable name.
119          */
120         public String getVariable()
121         {
122             return this.variable;
123         }
124 
125         /**
126          * Gets the value of the <code>value</code> attribute defined on the <code>property</code> element.
127          *
128          * @return the value
129          */
130         public String getValue()
131         {
132             return this.value;
133         }
134     }
135 }