View Javadoc
1   package org.codehaus.plexus.component.repository;
2   
3   /*
4    * Copyright 2001-2006 Codehaus Foundation.
5    *
6    * Licensed under the Apache License, Version 2.0 (the "License");
7    * you may not use this file except in compliance with the License.
8    * You may obtain a copy of the License at
9    *
10   *      http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing, software
13   * distributed under the License is distributed on an "AS IS" BASIS,
14   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15   * See the License for the specific language governing permissions and
16   * limitations under the License.
17   */
18  
19  import java.util.ArrayList;
20  import java.util.List;
21  
22  /**
23   * Contains a set of ComponentDescriptors and the set's dependencies.
24   *
25   * @author Jason van Zyl
26   * @author <a href="mailto:trygvis@inamo.no">Trygve Laugst&oslash;l</a>
27   * @version $Id$
28   */
29  public class ComponentSetDescriptor
30  {
31      // This field is not currently used in Maven, or Plexus
32      private String id;
33  
34      /** The source location of this component source descriptor */
35      private String source;
36  
37      /** Flag to indicate whether this component should be loaded in a realm/classloader of its own. */
38      private boolean isolatedRealm;
39      
40      /** The component descriptors that can be found within this component set descriptor. */
41      private final List<ComponentDescriptor<?>> components = new ArrayList<ComponentDescriptor<?>>();
42  
43      /** The dependencies that are required by the set of components found in this component set descriptor. */
44      private final List<ComponentDependency> dependencies = new ArrayList<ComponentDependency>();
45      
46      /**
47       * Returns a list of components in this set.
48       * @return a list of components
49       */
50      public List<ComponentDescriptor<?>> getComponents()
51      {
52          return components;
53      }
54  
55      /**
56       * Add a new ComponentDescriptor to this set.
57       * @param cd the ComponentDescriptor to add
58       */
59      public void addComponentDescriptor( ComponentDescriptor<?> cd )
60      {
61          components.add( cd );
62      }
63  
64      /**
65       * Sets a List of components as this set's contents.
66       * @param components the List of components to set
67       */
68      public void setComponents( List<ComponentDescriptor<?>> components )
69      {
70          this.components.clear();
71          this.components.addAll(components);
72      }
73  
74      /**
75       * Returns a List of dependencies of this set of components.
76       * @return a List of dependencies of this set of components
77       */
78      public List<ComponentDependency> getDependencies()
79      {
80          return dependencies;
81      }
82  
83      /**
84       * Add a depenency to this set's contents.
85       * @param cd the ComponentDependency to add
86       */
87      public void addDependency( ComponentDependency cd )
88      {
89          dependencies.add( cd );
90      }
91  
92      /**
93       * Sets a List of dependencies as this set's component dependencies.
94       * @param dependencies the List of components to set
95       */
96      public void setDependencies( List<ComponentDependency> dependencies )
97      {
98          this.dependencies.clear();
99          this.dependencies.addAll(dependencies);
100     }
101 
102     /**
103      * Sets that this set of components may be in an isolated classrealm.
104      * @param isolatedRealm true if this set of components may be in an
105      *  isolated classrealm
106      */
107     public void setIsolatedRealm( boolean isolatedRealm )
108     {
109         this.isolatedRealm = isolatedRealm;
110     }
111 
112     /**
113      * Returns true if this set may be in an isolated classrealm.
114      * @return true if this set may be in an isolated classrealm
115      */
116     public boolean isIsolatedRealm()
117     {
118         return isolatedRealm;
119     }
120 
121     /**
122      * Returns the identifier of this set.
123      * @return the identifier of this set
124      */
125     public String getId()
126     {
127         return id;
128     }
129 
130     /**
131      * Sets the identifier of this set.
132      * @param id the identifier to set
133      */
134     public void setId( String id )
135     {
136         this.id = id;
137     }
138 
139     public String toString()
140     {
141         StringBuilder sb = new StringBuilder();
142 
143         sb.append( "Component Descriptor: " );
144 
145         for ( ComponentDescriptor<?> cd : components )
146         {
147             sb.append( cd.getHumanReadableKey() ).append( "\n" );
148         }
149 
150         sb.append( "---" );
151 
152         return sb.toString();
153     }
154 
155     public String getSource()
156     {
157         return source;
158     }
159 
160     public void setSource( String source )
161     {
162         this.source = source;
163     }
164 }