This project has retired. For details please refer to its
Attic page.
MetadataService xref
1 package org.apache.archiva.metadata.repository;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import org.apache.archiva.metadata.model.MetadataFacet;
23 import org.apache.archiva.metadata.model.MetadataFacetFactory;
24 import org.springframework.context.ApplicationContext;
25 import org.springframework.stereotype.Service;
26
27 import javax.inject.Inject;
28 import java.util.HashMap;
29 import java.util.List;
30 import java.util.Map;
31 import java.util.Set;
32
33
34
35
36
37 @SuppressWarnings( "SpringJavaInjectionPointsAutowiringInspection" )
38 @Service("metadataService")
39 public class MetadataService
40 {
41
42 private Map<String, MetadataFacetFactory<? extends MetadataFacet>> facetFactories = new HashMap<>( );
43 private Map<Class<? extends MetadataFacet>, MetadataFacetFactory<? extends MetadataFacet>> facetFactoriesByClass = new HashMap<>( );
44 private Map<String, Class<? extends MetadataFacet>> reverseFactoryMap = new HashMap<>( );
45
46 private MetadataResolver metadataResolver = null;
47
48 @Inject
49 ApplicationContext applicationContext;
50
51
52 @Inject
53 public void setMetadataFacetFactories( List<MetadataFacetFactory> factoryList ) {
54 Map<String, MetadataFacetFactory<? extends MetadataFacet>> facetFactories = new HashMap<>( );
55 Map<Class<? extends MetadataFacet>, MetadataFacetFactory<? extends MetadataFacet>> facetFactoriesByClass = new HashMap<>( );
56 Map<String, Class<? extends MetadataFacet>> reverseFactoryMap = new HashMap<>( );
57 for (MetadataFacetFactory factory : factoryList) {
58 facetFactories.put( factory.getFacetId( ), factory );
59 facetFactoriesByClass.put( factory.getFacetClass( ), factory );
60 reverseFactoryMap.put( factory.getFacetId( ), factory.getFacetClass( ) );
61 }
62 this.facetFactories = facetFactories;
63 this.facetFactoriesByClass = facetFactoriesByClass;
64 this.reverseFactoryMap = reverseFactoryMap;
65 }
66
67 public <T extends MetadataFacet> MetadataFacetFactory<T> getFactory(Class<T> facetClazz) {
68 return (MetadataFacetFactory<T>) facetFactoriesByClass.get( facetClazz );
69 }
70
71 public MetadataFacetFactory<?> getFactory(String facetId) {
72 return facetFactories.get( facetId );
73 }
74
75 public Set<String> getSupportedFacets() {
76 return facetFactories.keySet( );
77 }
78
79 public boolean supportsFacet(Class<? extends MetadataFacet> facetClazz) {
80 return facetFactoriesByClass.containsKey( facetClazz );
81 }
82
83 public boolean supportsFacet(String facetId) {
84 return facetFactories.containsKey( facetId );
85 }
86
87 public Class<? extends MetadataFacet> getFactoryClassForId( String facetId ) {
88 return reverseFactoryMap.get( facetId );
89 }
90
91
92 public MetadataResolver getMetadataResolver()
93 {
94 if ( this.metadataResolver == null && applicationContext!=null)
95 {
96 this.metadataResolver = applicationContext.getBean( MetadataResolver.class );
97 }
98 return this.metadataResolver;
99 }
100 }