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øl</a>
27 */
28 public class ComponentSetDescriptor {
29 // This field is not currently used in Maven, or Plexus
30 private String id;
31
32 /** The source location of this component source descriptor */
33 private String source;
34
35 /** Flag to indicate whether this component should be loaded in a realm/classloader of its own. */
36 private boolean isolatedRealm;
37
38 /** The component descriptors that can be found within this component set descriptor. */
39 private final List<ComponentDescriptor<?>> components = new ArrayList<ComponentDescriptor<?>>();
40
41 /** The dependencies that are required by the set of components found in this component set descriptor. */
42 private final List<ComponentDependency> dependencies = new ArrayList<ComponentDependency>();
43
44 /**
45 * Returns a list of components in this set.
46 * @return a list of components
47 */
48 public List<ComponentDescriptor<?>> getComponents() {
49 return components;
50 }
51
52 /**
53 * Add a new ComponentDescriptor to this set.
54 * @param cd the ComponentDescriptor to add
55 */
56 public void addComponentDescriptor(ComponentDescriptor<?> cd) {
57 components.add(cd);
58 }
59
60 /**
61 * Sets a List of components as this set's contents.
62 * @param components the List of components to set
63 */
64 public void setComponents(List<ComponentDescriptor<?>> components) {
65 this.components.clear();
66 this.components.addAll(components);
67 }
68
69 /**
70 * Returns a List of dependencies of this set of components.
71 * @return a List of dependencies of this set of components
72 */
73 public List<ComponentDependency> getDependencies() {
74 return dependencies;
75 }
76
77 /**
78 * Add a depenency to this set's contents.
79 * @param cd the ComponentDependency to add
80 */
81 public void addDependency(ComponentDependency cd) {
82 dependencies.add(cd);
83 }
84
85 /**
86 * Sets a List of dependencies as this set's component dependencies.
87 * @param dependencies the List of components to set
88 */
89 public void setDependencies(List<ComponentDependency> dependencies) {
90 this.dependencies.clear();
91 this.dependencies.addAll(dependencies);
92 }
93
94 /**
95 * Sets that this set of components may be in an isolated classrealm.
96 * @param isolatedRealm true if this set of components may be in an
97 * isolated classrealm
98 */
99 public void setIsolatedRealm(boolean isolatedRealm) {
100 this.isolatedRealm = isolatedRealm;
101 }
102
103 /**
104 * Returns true if this set may be in an isolated classrealm.
105 * @return true if this set may be in an isolated classrealm
106 */
107 public boolean isIsolatedRealm() {
108 return isolatedRealm;
109 }
110
111 /**
112 * Returns the identifier of this set.
113 * @return the identifier of this set
114 */
115 public String getId() {
116 return id;
117 }
118
119 /**
120 * Sets the identifier of this set.
121 * @param id the identifier to set
122 */
123 public void setId(String id) {
124 this.id = id;
125 }
126
127 public String toString() {
128 StringBuilder sb = new StringBuilder();
129
130 sb.append("Component Descriptor: ");
131
132 for (ComponentDescriptor<?> cd : components) {
133 sb.append(cd.getHumanReadableKey()).append("\n");
134 }
135
136 sb.append("---");
137
138 return sb.toString();
139 }
140
141 public String getSource() {
142 return source;
143 }
144
145 public void setSource(String source) {
146 this.source = source;
147 }
148 }