KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > codehaus > loom > components > util > metadata > ComponentTemplate


1 /*
2  * Copyright (C) The Loom Group. All rights reserved.
3  *
4  * This software is published under the terms of the Loom
5  * Software License version 1.1, a copy of which has been included
6  * with this distribution in the LICENSE.txt file.
7  */

8 package org.codehaus.loom.components.util.metadata;
9
10 import java.util.ArrayList JavaDoc;
11 import java.util.List JavaDoc;
12 import org.apache.avalon.framework.parameters.Parameters;
13 import org.codehaus.dna.Configuration;
14
15 /**
16  * Each component declared in the application is represented by a
17  * ComponentTemplate. Note that this does not necessarily imply that there is
18  * only one instance of actual component. The ComponentTemplate could represent
19  * a pool of components, a single component or a component prototype that is
20  * reused to create new components as needed.
21  *
22  * @author Peter Donald
23  * @version $Revision: 1.2 $ $Date: 2004/05/01 12:48:35 $
24  */

25 public class ComponentTemplate
26 {
27     /** Empty set of component metadata. */
28     public static final ComponentTemplate[] EMPTY_SET = new ComponentTemplate[ 0 ];
29
30     /**
31      * The name of the component. This is an abstract name used during
32      * assembly.
33      */

34     private final String JavaDoc m_name;
35
36     /**
37      * The implementationKey for this component. Usually this represents a
38      * classname but alternative mechanisms could be used (ie URL of
39      * webservice).
40      */

41     private final String JavaDoc m_implementationKey;
42
43     /** The resolution of any dependencies required by the component type. */
44     private final DependencyDirective[] m_dependencies;
45
46     /** The parameters for component (if any). */
47     private final Parameters m_parameters;
48
49     /** The configuration for component (if any). */
50     private final Configuration m_configuration;
51
52     /** True if proxy should be disabled. */
53     private final boolean m_disableProxy;
54
55     /**
56      * Create a ComponentTemplate.
57      *
58      * @param name the abstract name of component meta data instance
59      * @param implementationKey the key used to create component (usually a
60      * classname)
61      * @param dependencies the meta data for any dependencies
62      * @param parameters the parameters that the component will be provided (may
63      * be null)
64      * @param configuration the configuration that the component will be
65      * provided (may be null)
66      * @param disableProxy true if proxy should be disabled
67      */

68     public ComponentTemplate( final String JavaDoc name,
69                               final String JavaDoc implementationKey,
70                               final DependencyDirective[] dependencies,
71                               final Parameters parameters,
72                               final Configuration configuration,
73                               final boolean disableProxy )
74     {
75         if( null == name )
76         {
77             throw new NullPointerException JavaDoc( "name" );
78         }
79         if( null == dependencies )
80         {
81             throw new NullPointerException JavaDoc( "dependencies" );
82         }
83         if( null == implementationKey )
84         {
85             throw new NullPointerException JavaDoc( "implementationKey" );
86         }
87
88         m_name = name;
89         m_dependencies = dependencies;
90         m_parameters = parameters;
91         m_configuration = configuration;
92         m_implementationKey = implementationKey;
93         m_disableProxy = disableProxy;
94     }
95
96     /**
97      * Return true if proxy should not be created for object.
98      *
99      * @return true if proxy should not be created for object.
100      */

101     public boolean isDisableProxy()
102     {
103         return m_disableProxy;
104     }
105
106     /**
107      * Return the name of component metadata.
108      *
109      * @return the name of the component metadata.
110      */

111     public String JavaDoc getName()
112     {
113         return m_name;
114     }
115
116     /**
117      * Return the implementationKey for component.
118      *
119      * @return the implementationKey for component.
120      */

121     public String JavaDoc getImplementationKey()
122     {
123         return m_implementationKey;
124     }
125
126     /**
127      * Return the dependency for component.
128      *
129      * @return the dependency for component.
130      */

131     public DependencyDirective[] getDependencies()
132     {
133         return m_dependencies;
134     }
135
136     /**
137      * Return the Parameters for Component (if any).
138      *
139      * @return the Parameters for Component (if any).
140      */

141     public Parameters getParameters()
142     {
143         return m_parameters;
144     }
145
146     /**
147      * Return the Configuration for Component (if any).
148      *
149      * @return the Configuration for Component (if any).
150      */

151     public Configuration getConfiguration()
152     {
153         return m_configuration;
154     }
155
156     /**
157      * Return the dependency for component with specified key.
158      *
159      * @return the dependency for component with specified key.
160      */

161     public DependencyDirective getDependency( final String JavaDoc key )
162     {
163         for( int i = 0; i < m_dependencies.length; i++ )
164         {
165             if( m_dependencies[ i ].getKey().equals( key ) )
166             {
167                 return m_dependencies[ i ];
168             }
169         }
170
171         return null;
172     }
173
174     /**
175      * Return all the dependencies for key. Used for Map and array
176      * dependencies.
177      *
178      * @return all the dependencies for key
179      */

180     public DependencyDirective[] getDependencies( final String JavaDoc key )
181     {
182         final List JavaDoc result = new ArrayList JavaDoc();
183
184         for( int i = 0; i < m_dependencies.length; i++ )
185         {
186             final DependencyDirective dependency = m_dependencies[ i ];
187             if( dependency.getKey().equals( key ) )
188             {
189                 result.add( dependency );
190             }
191         }
192
193         return (DependencyDirective[])result.
194             toArray( new DependencyDirective[ result.size() ] );
195     }
196 }
197
Popular Tags