1 17 18 package org.apache.avalon.repository.impl; 19 20 21 import java.io.File ; 22 23 import java.util.Map ; 24 25 import org.apache.avalon.repository.Artifact; 26 import org.apache.avalon.repository.RepositoryRuntimeException; 27 import org.apache.avalon.repository.provider.RepositoryCriteria; 28 import org.apache.avalon.repository.provider.InitialContext; 29 import org.apache.avalon.repository.provider.Factory; 30 31 import org.apache.avalon.util.i18n.ResourceManager; 32 import org.apache.avalon.util.i18n.Resources; 33 34 40 public class DefaultFactory implements Factory 41 { 42 46 private static Resources REZ = 47 ResourceManager.getPackageResources( DefaultFactory.class ); 48 49 private String [] m_hosts; 50 51 55 private final InitialContext m_context; 56 57 61 66 public DefaultFactory( InitialContext context ) 67 { 68 if( null == context ) 69 throw new NullPointerException ( "context" ); 70 m_context = context; 71 } 72 73 77 81 public Map createDefaultCriteria() 82 { 83 try 84 { 85 return new DefaultRepositoryCriteria( m_context ); 86 } 87 catch( Throwable e ) 88 { 89 final String error = 90 "Could not create default factory criteria."; 91 throw new RepositoryRuntimeException( error, e ); 92 } 93 } 94 95 101 public Object create() throws Exception 102 { 103 return create( createDefaultCriteria() ); 104 } 105 106 113 public Object create( Map map ) throws Exception 114 { 115 if( null == map ) 116 { 117 throw new NullPointerException ( "map" ); 118 } 119 120 File root = getCache( map ); 121 String [] hosts = getHosts( map ); 122 boolean online = getOnlineMode( map ); 123 Artifact[] candidates = getFactoryArtifacts( map ); 124 return new DefaultRepository( root, hosts, online, candidates ); 125 } 126 127 private boolean getOnlineMode( Map map ) 128 { 129 Boolean value = (Boolean ) map.get( 130 RepositoryCriteria.REPOSITORY_ONLINE_MODE ); 131 if( null != value ) return value.booleanValue(); 132 return true; 133 } 134 135 private File getCache( Map map ) 136 { 137 return (File ) map.get( 138 RepositoryCriteria.REPOSITORY_CACHE_DIR ); 139 } 140 141 private String [] getHosts( Map map ) 142 { 143 return (String []) map.get( 144 RepositoryCriteria.REPOSITORY_REMOTE_HOSTS ); 145 } 146 147 private Artifact[] getFactoryArtifacts( Map map ) 148 { 149 return (Artifact[]) map.get( 150 RepositoryCriteria.REPOSITORY_FACTORY_ARTIFACTS ); 151 } 152 } 153 | Popular Tags |