KickJava   Java API By Example, From Geeks To Geeks.

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


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 /**
11  * In each Assembly there may be groups of components that are activated
12  * together and treated as a group. These components are all "visible" to each
13  * other as peers. The group will have a name and may use resources from other
14  * partitions. Partitions can also be nested one inside each other.
15  *
16  * @author Peter Donald
17  * @version $Revision: 1.2 $ $Date: 2004/05/01 12:48:35 $
18  */

19 public class PartitionTemplate
20 {
21     /** Constant for an empty set of partitions. */
22     public static final PartitionTemplate[] EMPTY_SET = new PartitionTemplate[ 0 ];
23
24     /**
25      * The name of the partition. This is an abstract name used during
26      * assembly.
27      */

28     private final String JavaDoc m_name;
29
30     /**
31      * An array listing the set of other partitions required by this partition.
32      * The required partitions must be initialized and in ready state prior to
33      * this partition starting and this partition must be shutdown prior
34      */

35     private final String JavaDoc[] m_depends;
36
37     /** AN array of partitions that are contained by this object. */
38     private final PartitionTemplate[] m_partitions;
39
40     /** AN array of components that are contained by this object. */
41     private final ComponentTemplate[] m_components;
42
43     /**
44      * Create a PartitionTemplate.
45      *
46      * @param name the abstract name of component meta data instance
47      * @param depends the partitions depended upon by this parition
48      * @param partitions the partitions contained by this partition
49      * @param components the components contained by this partition
50      */

51     public PartitionTemplate( final String JavaDoc name,
52                               final String JavaDoc[] depends,
53                               final PartitionTemplate[] partitions,
54                               final ComponentTemplate[] components )
55     {
56         if( null == name )
57         {
58             throw new NullPointerException JavaDoc( "name" );
59         }
60         if( null == depends )
61         {
62             throw new NullPointerException JavaDoc( "depends" );
63         }
64         if( null == partitions )
65         {
66             throw new NullPointerException JavaDoc( "partitions" );
67         }
68         if( null == components )
69         {
70             throw new NullPointerException JavaDoc( "components" );
71         }
72
73         m_name = name;
74         m_depends = depends;
75         m_partitions = partitions;
76         m_components = components;
77     }
78
79     /**
80      * Return the name of component profile.
81      *
82      * @return the name of the component profile.
83      */

84     public String JavaDoc getName()
85     {
86         return m_name;
87     }
88
89     /**
90      * Return the set of prereqs for this partition.
91      *
92      * @return the set of prereqs for this partition.
93      */

94     public String JavaDoc[] getDepends()
95     {
96         return m_depends;
97     }
98
99     /**
100      * Return the set of partitions contained in this partition.
101      *
102      * @return the set of partitions contained in this partition.
103      */

104     public PartitionTemplate[] getPartitions()
105     {
106         return m_partitions;
107     }
108
109     /**
110      * Return the set of components contained in this partition.
111      *
112      * @return the set of components contained in this partition.
113      */

114     public ComponentTemplate[] getComponents()
115     {
116         return m_components;
117     }
118
119     /**
120      * Return the partition with specified name.
121      *
122      * @return the partition with specified name.
123      */

124     public PartitionTemplate getPartition( final String JavaDoc name )
125     {
126         for( int i = 0; i < m_partitions.length; i++ )
127         {
128             final PartitionTemplate partition = m_partitions[ i ];
129             if( partition.getName().equals( name ) )
130             {
131                 return partition;
132             }
133         }
134
135         throw new IllegalArgumentException JavaDoc( "Missing partition named " + name );
136     }
137
138     /**
139      * Return the component with specified name.
140      *
141      * @return the component with specified name.
142      */

143     public ComponentTemplate getComponent( final String JavaDoc name )
144     {
145         for( int i = 0; i < m_components.length; i++ )
146         {
147             final ComponentTemplate component = m_components[ i ];
148             if( component.getName().equals( name ) )
149             {
150                 return component;
151             }
152         }
153         return null;
154     }
155 }
156
Popular Tags