1 8 package org.apache.avalon.excalibur.extension; 9 10 import java.io.File ; 11 import java.io.IOException ; 12 import java.util.ArrayList ; 13 import java.util.List ; 14 15 25 public class PackageManager 26 { 27 private PackageRepository m_repository; 29 30 35 public PackageManager( final PackageRepository repository ) 36 { 37 if( null == repository ) 38 { 39 throw new NullPointerException ( "repository property is null" ); 40 } 41 42 m_repository = repository; 43 } 44 45 61 public OptionalPackage getOptionalPackage( final Extension extension ) 62 { 63 final OptionalPackage[] packages = m_repository.getOptionalPackages( extension ); 64 65 if( null == packages || 0 == packages.length ) return null; 66 67 69 return packages[ 0 ]; 70 } 71 72 73 90 public OptionalPackage[] scanDependencies( final Extension required, 91 final Extension[] available ) 92 throws UnsatisfiedExtensionException 93 { 94 final Extension[] extensions = new Extension[] { required }; 95 return scanDependencies( required, available ); 96 } 97 98 115 public OptionalPackage[] scanDependencies( final Extension[] required, 116 final Extension[] available ) 117 throws UnsatisfiedExtensionException 118 { 119 final ArrayList dependencies = new ArrayList (); 120 final ArrayList unsatisfied = new ArrayList (); 121 122 scanDependencies( required, available, dependencies, unsatisfied ); 123 124 if( 0 != unsatisfied.size() ) 125 { 126 final Extension extension = (Extension)unsatisfied.get( 0 ); 127 throw new UnsatisfiedExtensionException( extension ); 128 } 129 130 return (OptionalPackage[])dependencies.toArray( new OptionalPackage[ 0 ] ); 131 } 132 133 150 public void scanDependencies( final Extension[] required, 151 final Extension[] available, 152 final List dependencies, 153 final List unsatisfied ) 154 { 155 for( int i = 0; i < required.length; i++ ) 156 { 157 scanDependencies( required[ i ], available, dependencies, unsatisfied ); 158 } 159 } 160 161 178 public void scanDependencies( final Extension required, 179 final Extension[] available, 180 final List dependencies, 181 final List unsatisfied ) 182 { 183 for( int i = 0; i < available.length; i++ ) 186 { 187 final Extension other = available[ i ]; 188 if( other.isCompatibleWith( required ) ) 189 { 190 return; 191 } 192 } 193 194 final int size = dependencies.size(); 197 for( int i = 0; i < size; i++ ) 198 { 199 final OptionalPackage optionalPackage = (OptionalPackage)dependencies.get( i ); 200 if( optionalPackage.isCompatible( required ) ) 201 { 202 return; 203 } 204 } 205 206 final OptionalPackage optionalPackage = getOptionalPackage( required ); 207 if( null == optionalPackage ) 208 { 209 if( !unsatisfied.contains( required ) ) 210 { 211 unsatisfied.add( required ); 212 } 213 } 214 else 215 { 216 if( !dependencies.contains( optionalPackage ) ) 217 { 218 dependencies.add( optionalPackage ); 219 } 220 221 scanDependencies( optionalPackage.getRequiredExtensions(), 222 available, 223 dependencies, 224 unsatisfied ); 225 } 226 } 227 } 228 | Popular Tags |