1 | |
package org.apache.maven.container; |
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
|
18 | |
|
19 | |
|
20 | |
|
21 | |
|
22 | |
import org.codehaus.plexus.PlexusContainer; |
23 | |
import org.codehaus.plexus.component.repository.ComponentDescriptor; |
24 | |
|
25 | |
import java.util.HashMap; |
26 | |
import java.util.LinkedHashMap; |
27 | |
import java.util.Map; |
28 | |
import java.util.Set; |
29 | |
|
30 | 0 | public class ContainerUtils |
31 | |
{ |
32 | |
|
33 | |
public static Set<String> findChildComponentHints( String role, PlexusContainer parent, PlexusContainer child ) |
34 | |
{ |
35 | 0 | return findChildComponents( role, parent, child ).keySet(); |
36 | |
} |
37 | |
|
38 | |
@SuppressWarnings( "unchecked" ) |
39 | |
public static Map<String, ComponentDescriptor> findChildComponents( String role, PlexusContainer parent, PlexusContainer child ) |
40 | |
{ |
41 | 0 | Map<String, ComponentDescriptor> parentComponents = parent.getComponentDescriptorMap( role ); |
42 | 0 | if ( parentComponents != null ) |
43 | |
{ |
44 | 0 | parentComponents = new LinkedHashMap<String, ComponentDescriptor>( parentComponents ); |
45 | |
} |
46 | |
|
47 | 0 | Map<String, ComponentDescriptor> childComponents = child.getComponentDescriptorMap( role ); |
48 | 0 | if ( childComponents == null ) |
49 | |
{ |
50 | 0 | return new HashMap<String, ComponentDescriptor>(); |
51 | |
} |
52 | |
else |
53 | |
{ |
54 | 0 | childComponents = new LinkedHashMap<String, ComponentDescriptor>( childComponents ); |
55 | 0 | if ( parentComponents != null && !parentComponents.isEmpty() ) |
56 | |
{ |
57 | 0 | for ( Map.Entry<String, ComponentDescriptor> entry : parentComponents.entrySet() ) |
58 | |
{ |
59 | 0 | String hint = entry.getKey(); |
60 | |
|
61 | 0 | if ( childComponents.containsKey( hint ) && entry.getValue() == childComponents.get( hint ) ) |
62 | |
{ |
63 | 0 | childComponents.remove( hint ); |
64 | |
} |
65 | 0 | } |
66 | |
} |
67 | |
} |
68 | |
|
69 | 0 | return childComponents; |
70 | |
} |
71 | |
|
72 | |
} |