Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: com/aendvari/cerberus/component/descriptor/AssemblyDescriptor.java


1   /*
2    * AssemblyDescriptor.java
3    *
4    * Copyright (c) 2001, 2002 Aendvari, Ltd. All Rights Reserved.
5    *
6    * See the file LICENSE for terms of use.
7    *
8    */
9   
10  package com.aendvari.cerberus.component.descriptor;
11  
12  import java.util.HashMap;
13  import java.util.Collection;
14  import java.util.Iterator;
15  
16  /**
17   * <p>Provides a container for {@link ComponentDefinition ComponentDefinitions} and
18   * {@link ComponentInstance ComponentInstances}.</p>
19   *
20   * <p>The assembly descriptor is used during the building of component objects.</p>
21   *
22   * @author  Trevor Milne
23   *
24   */
25  
26  public class AssemblyDescriptor
27  {
28    /** The definitions of this assembly descriptor. */
29    protected HashMap definitions;
30  
31    /** The components of this assembly descriptor. */
32    protected HashMap components;
33  
34  
35    /* Constructors. */
36  
37  
38    /**
39     * Constructs an <code>AssemblyDescriptor</code> instance.
40     *
41     */
42  
43    public AssemblyDescriptor()
44    {
45      definitions = new HashMap();
46      components = new HashMap();
47    }
48  
49    /**
50     * Constructs an <code>AssemblyDescriptor</code> instance as a copy of the one supplied.
51     *
52     * @param    assembly          The <code>AssemblyDescriptor</code> to copy.
53     *
54     */
55  
56    public AssemblyDescriptor(AssemblyDescriptor assembly)
57    {
58      definitions = new HashMap();
59      components = new HashMap();
60  
61      // copy definitions
62      Iterator definitionIterator = assembly.getDefinitions().iterator();
63  
64      while (definitionIterator.hasNext())
65      {
66        ComponentDefinition copyDefinition = (ComponentDefinition)definitionIterator.next();
67        ComponentDefinition newDefinition = new ComponentDefinition(copyDefinition);
68  
69        addDefinition(newDefinition);
70      }
71  
72      // copy components
73      Iterator componentIterator = assembly.getComponents().iterator();
74  
75      while (componentIterator.hasNext())
76      {
77        ComponentInstance copyComponent = (ComponentInstance)componentIterator.next();
78        ComponentInstance newComponent = new ComponentInstance(copyComponent);
79  
80        addComponent(newComponent);
81      }
82    }
83  
84  
85    /* Accessors. */
86  
87  
88    /* Definitions. */
89  
90    /**
91     * Adds a component definition to this assembly descriptor.
92     *
93     * @param    definition          A component definition for this assembly descriptor.
94     *
95     */
96  
97    public void addDefinition(ComponentDefinition definition)
98    {
99      definitions.put(definition.getName(), definition);
100   }
101 
102   /**
103    * Returns the specified component definition.
104    *
105    * @param    name            The name of the component definition.
106    *
107    * @return                  The component definition having the supplied name.
108    *
109    */
110 
111   public ComponentDefinition getDefinition(String name)
112   {
113     return (ComponentDefinition)definitions.get(name);
114   }
115 
116   /**
117    * Returns the component definitions in this assembly descriptor.
118    *
119    * @return                  A <code>Collection</code> of {@link ComponentDefinition ComponentDefinitions}.
120    *
121    */
122 
123   public Collection getDefinitions()
124   {
125     return definitions.values();
126   }
127 
128   /* Components. */
129 
130   /**
131    * Adds a component to this assembly descriptor.
132    *
133    * @param    component          A component for this assembly descriptor.
134    *
135    */
136 
137   public void addComponent(ComponentInstance component)
138   {
139     components.put(component.getName(), component);
140   }
141 
142   /**
143    * Returns the specified component.
144    *
145    * @param    name            The name of the component.
146    *
147    * @return                  The {@link ComponentInstance} having the supplied name.
148    *
149    */
150 
151   public ComponentInstance getComponent(String name)
152   {
153     return (ComponentInstance)components.get(name);
154   }
155 
156   /**
157    * Returns the components of this assembly descriptor.
158    *
159    * @return                  A <code>Collection</cide> of {@link ComponentInstance ComponentInstances}.
160    *
161    */
162 
163   public Collection getComponents()
164   {
165     return components.values();
166   }
167 }
168