1 17 18 package org.apache.avalon.extension.manager; 19 20 import java.util.ArrayList ; 21 import java.util.List ; 22 23 import org.apache.avalon.extension.Extension; 24 25 40 public class PackageManager 41 { 42 private ExtensionManager m_repository; 44 45 50 public PackageManager( final ExtensionManager repository ) 51 { 52 if( null == repository ) 53 { 54 throw new NullPointerException ( "repository" ); 55 } 56 57 m_repository = repository; 58 } 59 60 78 public OptionalPackage getOptionalPackage( final Extension extension ) 79 { 80 final OptionalPackage[] packages = m_repository.getOptionalPackages( extension ); 81 if( null == packages || 0 == packages.length ) 82 { 83 return null; 84 } 85 86 return packages[ 0 ]; 89 } 90 91 108 public OptionalPackage[] scanDependencies( final Extension required, 109 final Extension[] available ) 110 throws UnsatisfiedExtensionException 111 { 112 return scanDependencies( new Extension[]{required}, available ); 113 } 114 115 132 public OptionalPackage[] scanDependencies( final Extension[] required, 133 final Extension[] available ) 134 throws UnsatisfiedExtensionException 135 { 136 final ArrayList dependencies = new ArrayList (); 137 final ArrayList unsatisfied = new ArrayList (); 138 139 scanDependencies( required, available, dependencies, unsatisfied ); 140 141 if( 0 != unsatisfied.size() ) 142 { 143 final Extension extension = (Extension)unsatisfied.get( 0 ); 144 throw new UnsatisfiedExtensionException( extension ); 145 } 146 147 return (OptionalPackage[])dependencies.toArray( new OptionalPackage[ 0 ] ); 148 } 149 150 167 public void scanDependencies( final Extension[] required, 168 final Extension[] available, 169 final List dependencies, 170 final List unsatisfied ) 171 { 172 for( int i = 0; i < required.length; i++ ) 173 { 174 scanDependencies( required[ i ], available, dependencies, unsatisfied ); 175 } 176 } 177 178 195 public void scanDependencies( final Extension required, 196 final Extension[] available, 197 final List dependencies, 198 final List unsatisfied ) 199 { 200 for( int i = 0; i < available.length; i++ ) 203 { 204 final Extension other = available[ i ]; 205 if( other.isCompatibleWith( required ) ) 206 { 207 return; 208 } 209 } 210 211 final int size = dependencies.size(); 214 for( int i = 0; i < size; i++ ) 215 { 216 final OptionalPackage optionalPackage = (OptionalPackage)dependencies.get( i ); 217 if( optionalPackage.isCompatible( required ) ) 218 { 219 return; 220 } 221 } 222 223 final OptionalPackage optionalPackage = getOptionalPackage( required ); 224 if( null == optionalPackage ) 225 { 226 if( !unsatisfied.contains( required ) ) 227 { 228 unsatisfied.add( required ); 229 } 230 } 231 else 232 { 233 if( !dependencies.contains( optionalPackage ) ) 234 { 235 dependencies.add( optionalPackage ); 236 } 237 238 scanDependencies( optionalPackage.getRequiredExtensions(), 239 available, 240 dependencies, 241 unsatisfied ); 242 } 243 } 244 } 245 | Popular Tags |