1 package org.apache.maven.archiva.repository.layout;
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.commons.lang.StringUtils;
23 import org.apache.maven.archiva.configuration.AbstractRepositoryConfiguration;
24 import org.apache.maven.archiva.configuration.ArchivaConfiguration;
25 import org.apache.maven.archiva.configuration.ConfigurationNames;
26 import org.apache.maven.archiva.model.ArchivaArtifact;
27 import org.codehaus.plexus.logging.AbstractLogEnabled;
28 import org.codehaus.plexus.personality.plexus.lifecycle.phase.Initializable;
29 import org.codehaus.plexus.personality.plexus.lifecycle.phase.InitializationException;
30 import org.codehaus.plexus.registry.Registry;
31 import org.codehaus.plexus.registry.RegistryListener;
33 import java.util.HashMap;
34 import java.util.Iterator;
38 * BidirectionalRepositoryLayoutFactory
40 * @author <a href="mailto:joakime@apache.org">Joakim Erdfelt</a>
42 * @plexus.component role="org.apache.maven.archiva.repository.layout.BidirectionalRepositoryLayoutFactory"
44 public class BidirectionalRepositoryLayoutFactory
45 extends AbstractLogEnabled
46 implements RegistryListener, Initializable
49 * @plexus.requirement role="org.apache.maven.archiva.repository.layout.BidirectionalRepositoryLayout"
56 private ArchivaConfiguration configuration;
58 private Map repositoryMap = new HashMap();
60 public BidirectionalRepositoryLayout getLayout( String type )
61 throws LayoutException
63 if ( !layouts.containsKey( type ) )
65 throw new LayoutException(
66 "Layout type [" + type + "] does not exist. " + "Available types [" + layouts.keySet() + "]" );
69 return (BidirectionalRepositoryLayout) layouts.get( type );
72 public BidirectionalRepositoryLayout getLayoutForPath( String path )
73 throws LayoutException
75 for ( Iterator iter = layouts.values().iterator(); iter.hasNext(); )
77 BidirectionalRepositoryLayout layout = (BidirectionalRepositoryLayout) iter.next();
78 if ( layout.isValidPath( path ) )
83 throw new LayoutException( "No valid layout was found for path [" + path + "]" );
87 public BidirectionalRepositoryLayout getLayout( ArchivaArtifact artifact )
88 throws LayoutException
90 if ( artifact == null )
92 throw new LayoutException( "Cannot determine layout using a null artifact." );
95 String repoId = artifact.getModel().getRepositoryId();
96 if ( StringUtils.isBlank( repoId ) )
98 throw new LayoutException( "Cannot determine layout using artifact with no repository id: " + artifact );
101 AbstractRepositoryConfiguration repo = (AbstractRepositoryConfiguration) this.repositoryMap.get( repoId );
102 return getLayout( repo.getLayout() );
105 public void afterConfigurationChange( Registry registry, String propertyName, Object propertyValue )
107 if ( ConfigurationNames.isManagedRepositories( propertyName ) )
113 public void beforeConfigurationChange( Registry registry, String propertyName, Object propertyValue )
118 private void initRepositoryMap()
120 synchronized ( this.repositoryMap )
122 this.repositoryMap.clear();
123 this.repositoryMap.putAll( configuration.getConfiguration().getManagedRepositoriesAsMap() );
127 public void initialize()
128 throws InitializationException
131 configuration.addChangeListener( this );