View Javadoc
1   package org.andromda.core.configuration;
2   
3   import java.io.Serializable;
4   import java.util.ArrayList;
5   import java.util.Collection;
6   import java.util.LinkedHashMap;
7   import java.util.Map;
8   
9   /**
10   * A configurable namespace object. These are passed to Plugin instances (Cartridges, etc.).
11   *
12   * @author Chad Brandon
13   */
14  public class Namespace
15      implements Serializable
16  {
17      private static final long serialVersionUID = 34L;
18  
19      /**
20       * The namespace name.
21       */
22      private String name;
23  
24      /**
25       * Returns name of this Namespace. Will correspond to a Plugin name (or it can be be 'default' if we want it's
26       * settings to be used everywhere).
27       *
28       * @return String
29       */
30      public String getName()
31      {
32          return this.name;
33      }
34  
35      /**
36       * Sets the name of this Namespace.
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       * Stores the collected properties
47       */
48      private final Map<String, Collection<Property>> properties = new LinkedHashMap<String, Collection<Property>>();
49  
50      /**
51       * Adds a property to this Namespace object. A property must correspond to a java bean property name on a Plugin in
52       * order for it to be set during processing. Otherwise the property will just be ignored.
53       *
54       * @param property the property to add to this namespace.
55       */
56      public void addProperty(final Property property)
57      {
58          if (property != null)
59          {
60              Collection<Property> properties = this.properties.get(property.getName());
61              if (properties == null)
62              {
63                  properties = new ArrayList<Property>();
64                  this.properties.put(
65                      property.getName(),
66                      properties);
67              }
68              properties.add(property);
69          }
70      }
71  
72      /**
73       * Retrieves the properties with the specified name.
74       *
75       * @param name the name of the property.
76       *
77       * @return the property
78       */
79      public Collection<Property> getProperties(final String name)
80      {
81          return this.properties.get(name);
82      }
83  
84      /**
85       * Retrieves the property (the first one found) with the specified name.
86       *
87       * @param name the name of the property.
88       *
89       * @return the property
90       */
91      public Property getProperty(final String name)
92      {
93          final Collection<Property> properties = this.getProperties(name);
94          return properties == null || properties.isEmpty() ?
95              null : properties.iterator().next();
96      }
97  
98      /**
99       * Gets all namespaces belonging to this namespaces instance.
100      *
101      * @return all namespaces.
102      */
103     public Collection<Collection<Property>> getProperties()
104     {
105         return this.properties.values();
106     }
107 
108     /**
109      * @see Object#toString()
110      */
111     public String toString()
112     {
113         return super.toString() + '[' + this.name + ']';
114     }
115 }