This project has retired. For details please refer to its
Attic page.
RepositoryContentFactory xref
1 package org.apache.archiva.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.admin.model.RepositoryAdminException;
23 import org.apache.archiva.admin.model.beans.ManagedRepository;
24 import org.apache.archiva.admin.model.beans.RemoteRepository;
25 import org.apache.archiva.admin.model.managed.ManagedRepositoryAdmin;
26 import org.apache.archiva.admin.model.remote.RemoteRepositoryAdmin;
27 import org.apache.archiva.configuration.ArchivaConfiguration;
28 import org.apache.archiva.configuration.ConfigurationNames;
29 import org.apache.archiva.redback.components.registry.Registry;
30 import org.apache.archiva.redback.components.registry.RegistryListener;
31 import org.springframework.context.ApplicationContext;
32 import org.springframework.stereotype.Service;
33
34 import javax.annotation.PostConstruct;
35 import javax.inject.Inject;
36 import java.util.Map;
37 import java.util.concurrent.ConcurrentHashMap;
38
39
40
41
42
43
44 @Service( "repositoryContentFactory#default" )
45 public class RepositoryContentFactory
46 implements RegistryListener
47 {
48
49
50
51 @Inject
52 private ArchivaConfiguration archivaConfiguration;
53
54 @Inject
55 private ManagedRepositoryAdmin managedRepositoryAdmin;
56
57 @Inject
58 private RemoteRepositoryAdmin remoteRepositoryAdmin;
59
60 @Inject
61 private ApplicationContext applicationContext;
62
63 private final Map<String, ManagedRepositoryContent> managedContentMap;
64
65 private final Map<String, RemoteRepositoryContent> remoteContentMap;
66
67
68 public RepositoryContentFactory()
69 {
70 managedContentMap = new ConcurrentHashMap<String, ManagedRepositoryContent>();
71 remoteContentMap = new ConcurrentHashMap<String, RemoteRepositoryContent>();
72 }
73
74
75
76
77
78
79
80
81
82 public ManagedRepositoryContent getManagedRepositoryContent( String repoId )
83 throws RepositoryNotFoundException, RepositoryException
84 {
85 try
86 {
87 ManagedRepositoryContent repo = managedContentMap.get( repoId );
88
89 if ( repo != null )
90 {
91 return repo;
92 }
93
94 ManagedRepository repoConfig = managedRepositoryAdmin.getManagedRepository( repoId );
95 if ( repoConfig == null )
96 {
97 throw new RepositoryNotFoundException(
98 "Unable to find managed repository configuration for id:" + repoId );
99 }
100
101 repo = applicationContext.getBean( "managedRepositoryContent#" + repoConfig.getLayout(),
102 ManagedRepositoryContent.class );
103 repo.setRepository( repoConfig );
104 managedContentMap.put( repoId, repo );
105
106 return repo;
107 }
108 catch ( RepositoryAdminException e )
109 {
110 throw new RepositoryException( e.getMessage(), e );
111 }
112 }
113
114 public RemoteRepositoryContent getRemoteRepositoryContent( String repoId )
115 throws RepositoryNotFoundException, RepositoryException
116 {
117 try
118 {
119 RemoteRepositoryContent repo = remoteContentMap.get( repoId );
120
121 if ( repo != null )
122 {
123 return repo;
124 }
125
126 RemoteRepository repoConfig = remoteRepositoryAdmin.getRemoteRepository( repoId );
127 if ( repoConfig == null )
128 {
129 throw new RepositoryNotFoundException(
130 "Unable to find remote repository configuration for id:" + repoId );
131 }
132
133 repo = applicationContext.getBean( "remoteRepositoryContent#" + repoConfig.getLayout(),
134 RemoteRepositoryContent.class );
135 repo.setRepository( repoConfig );
136 remoteContentMap.put( repoId, repo );
137
138 return repo;
139 }
140 catch ( RepositoryAdminException e )
141 {
142 throw new RepositoryException( e.getMessage(), e );
143 }
144 }
145
146
147 @Override
148 public void afterConfigurationChange( Registry registry, String propertyName, Object propertyValue )
149 {
150 if ( ConfigurationNames.isManagedRepositories( propertyName ) || ConfigurationNames.isRemoteRepositories(
151 propertyName ) )
152 {
153 initMaps();
154 }
155 }
156
157 @Override
158 public void beforeConfigurationChange( Registry registry, String propertyName, Object propertyValue )
159 {
160
161 }
162
163 @PostConstruct
164 public void initialize()
165 {
166 archivaConfiguration.addChangeListener( this );
167 }
168
169 private void initMaps()
170 {
171
172
173
174 managedContentMap.clear();
175
176
177
178
179 remoteContentMap.clear();
180
181 }
182
183 public ArchivaConfiguration getArchivaConfiguration()
184 {
185 return archivaConfiguration;
186 }
187
188 public void setArchivaConfiguration( ArchivaConfiguration archivaConfiguration )
189 {
190 this.archivaConfiguration = archivaConfiguration;
191 }
192 }