1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 package org.codehaus.plexus.metadata;
16
17 import java.util.HashMap;
18 import java.util.Map;
19
20 import org.codehaus.plexus.component.repository.ComponentDescriptor;
21
22
23
24
25
26 public abstract class ComponentDescriptorExtractorSupport implements ComponentDescriptorExtractor {
27 protected Map<String, ComponentDescriptor<?>> getDefaultsByRole(final ComponentDescriptor<?>[] roleDefaults) {
28 Map<String, ComponentDescriptor<?>> defaultsByRole = new HashMap<String, ComponentDescriptor<?>>();
29
30 if (roleDefaults != null) {
31 for (ComponentDescriptor<?> roleDefault : roleDefaults) {
32 String role = roleDefault.getRole();
33
34 if (role == null) {
35 throw new IllegalArgumentException("Invalid role defaults; found null role in: " + roleDefault);
36 }
37
38 defaultsByRole.put(role, roleDefault);
39 }
40 }
41
42 return defaultsByRole;
43 }
44
45 protected void applyDefaults(
46 ComponentDescriptor<?> descriptor, Map<String, ComponentDescriptor<?>> defaultsByRole) {
47 assert descriptor != null;
48 assert defaultsByRole != null;
49
50 if (defaultsByRole.containsKey(descriptor.getRole())) {
51 ComponentDescriptor<?> defaults = defaultsByRole.get(descriptor.getRole());
52
53 if (descriptor.getInstantiationStrategy() == null) {
54 descriptor.setInstantiationStrategy(defaults.getInstantiationStrategy());
55 }
56 }
57 }
58 }