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