1 package org.apache.archiva.repository;
4 * Licensed to the Apache Software Foundation (ASF) under one
5 * or more contributor license agreements. See the NOTICE file
6 * distributed with this work for additional information
7 * regarding copyright ownership. The ASF licenses this file
8 * to you under the Apache License, Version 2.0 (the
9 * "License"); you may not use this file except in compliance
10 * with the License. You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing,
15 * software distributed under the License is distributed on an
16 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17 * KIND, either express or implied. See the License for the
18 * specific language governing permissions and limitations
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;
34 import javax.annotation.PostConstruct;
35 import javax.inject.Inject;
37 import java.util.concurrent.ConcurrentHashMap;
40 * RepositoryContentRequest
44 @Service( "repositoryContentFactory#default" )
45 public class RepositoryContentFactory
46 implements RegistryListener
52 private ArchivaConfiguration archivaConfiguration;
55 private ManagedRepositoryAdmin managedRepositoryAdmin;
58 private RemoteRepositoryAdmin remoteRepositoryAdmin;
61 private ApplicationContext applicationContext;
63 private final Map<String, ManagedRepositoryContent> managedContentMap;
65 private final Map<String, RemoteRepositoryContent> remoteContentMap;
68 public RepositoryContentFactory()
70 managedContentMap = new ConcurrentHashMap<String, ManagedRepositoryContent>();
71 remoteContentMap = new ConcurrentHashMap<String, RemoteRepositoryContent>();
75 * Get the ManagedRepositoryContent object for the repository Id specified.
77 * @param repoId the repository id to fetch.
78 * @return the ManagedRepositoryContent object associated with the repository id.
79 * @throws RepositoryNotFoundException if the repository id does not exist within the configuration.
80 * @throws RepositoryException the repository content object cannot be loaded due to configuration issue.
82 public ManagedRepositoryContent getManagedRepositoryContent( String repoId )
83 throws RepositoryNotFoundException, RepositoryException
87 ManagedRepositoryContent repo = managedContentMap.get( repoId );
94 ManagedRepository repoConfig = managedRepositoryAdmin.getManagedRepository( repoId );
95 if ( repoConfig == null )
97 throw new RepositoryNotFoundException(
98 "Unable to find managed repository configuration for id:" + repoId );
101 repo = applicationContext.getBean( "managedRepositoryContent#" + repoConfig.getLayout(),
102 ManagedRepositoryContent.class );
103 repo.setRepository( repoConfig );
104 managedContentMap.put( repoId, repo );
108 catch ( RepositoryAdminException e )
110 throw new RepositoryException( e.getMessage(), e );
114 public RemoteRepositoryContent getRemoteRepositoryContent( String repoId )
115 throws RepositoryNotFoundException, RepositoryException
119 RemoteRepositoryContent repo = remoteContentMap.get( repoId );
126 RemoteRepository repoConfig = remoteRepositoryAdmin.getRemoteRepository( repoId );
127 if ( repoConfig == null )
129 throw new RepositoryNotFoundException(
130 "Unable to find remote repository configuration for id:" + repoId );
133 repo = applicationContext.getBean( "remoteRepositoryContent#" + repoConfig.getLayout(),
134 RemoteRepositoryContent.class );
135 repo.setRepository( repoConfig );
136 remoteContentMap.put( repoId, repo );
140 catch ( RepositoryAdminException e )
142 throw new RepositoryException( e.getMessage(), e );
147 public void afterConfigurationChange( Registry registry, String propertyName, Object propertyValue )
149 if ( ConfigurationNames.isManagedRepositories( propertyName ) || ConfigurationNames.isRemoteRepositories(
156 public void beforeConfigurationChange( Registry registry, String propertyName, Object propertyValue )
162 public void initialize()
164 archivaConfiguration.addChangeListener( this );
167 private void initMaps()
169 // olamy we use concurent so no need of synchronize
170 //synchronized ( managedContentMap )
172 managedContentMap.clear();
175 //synchronized ( remoteContentMap )
177 remoteContentMap.clear();
181 public ArchivaConfiguration getArchivaConfiguration()
183 return archivaConfiguration;
186 public void setArchivaConfiguration( ArchivaConfiguration archivaConfiguration )
188 this.archivaConfiguration = archivaConfiguration;