View Javadoc
1   package org.andromda.core.namespace;
2   
3   import java.util.Arrays;
4   import java.util.Collection;
5   import java.util.LinkedHashSet;
6   import org.andromda.core.common.ClassUtils;
7   
8   /**
9    * Stores information about a namespace component.
10   *
11   * @author Chad Brandon
12   */
13  public class Component
14  {
15      /**
16       * The name of the component
17       */
18      private String name;
19  
20      /**
21       * Gets the name of the component.
22       *
23       * @return the component name.
24       */
25      public String getName()
26      {
27          return name;
28      }
29  
30      /**
31       * Sets the name of the component.
32       *
33       * @param name the component's name.
34       */
35      public void setName(final String name)
36      {
37          this.name = name;
38      }
39  
40      /**
41       * The path to the compoment's descriptor.
42       */
43      private final Collection<String> paths = new LinkedHashSet<String>();
44  
45      /**
46       * Gets the component's descriptor paths (these are the paths
47       * where the component's descriptor may be found).
48       *
49       * @return the path to the component's descriptor.
50       */
51      public String[] getPaths()
52      {
53          return paths.toArray(new String[paths.size()]);
54      }
55  
56      /**
57       * Adds a path to the component's descriptor.
58       *
59       * @param path that path to the component's descriptor.
60       */
61      public void addPath(final String path)
62      {
63          this.paths.add(path);
64      }
65  
66      /**
67       * Adds the given <code>paths</code> to the existing paths
68       * contained within this component.
69       *
70       * @param paths the paths to add.
71       */
72      final void addPaths(final String[] paths)
73      {
74          if (paths != null && paths.length > 0)
75          {
76              this.paths.addAll(Arrays.asList(paths));
77          }
78      }
79  
80      /**
81       * Stores the interface name that defines this component.
82       */
83      private Class type;
84  
85      /**
86       * Sets the type class  that defines this component.
87       *
88       * @param typeClass the name of the type.
89       */
90      public void setTypeClass(final String typeClass)
91      {
92          final Class type = ClassUtils.loadClass(typeClass);
93          if (!NamespaceComponent.class.isAssignableFrom(type))
94          {
95              throw new NamespaceComponentsException(
96                  "namespace component '" + type + "' must implement --> '" + NamespaceComponent.class.getName() + '\'');
97          }
98          this.type = type;
99      }
100 
101     /**
102      * Gets the class that defines this component.
103      *
104      * @return the  class that defines this component.
105      */
106     public Class getType()
107     {
108         return this.type;
109     }
110 }