1 17 18 package org.apache.avalon.extension.manager; 19 20 import java.io.File ; 21 22 import org.apache.avalon.extension.Extension; 23 24 31 public final class OptionalPackage 32 { 33 private final File m_file; 34 private final Extension[] m_available; 35 private final Extension[] m_required; 36 37 43 public static final File [] toFiles( final OptionalPackage[] packages ) 44 { 45 final File [] results = new File [ packages.length ]; 46 47 for( int i = 0; i < packages.length; i++ ) 48 { 49 results[ i ] = packages[ i ].getFile(); 50 } 51 52 return results; 53 } 54 55 63 public OptionalPackage( final File file, 64 final Extension[] available, 65 final Extension[] required ) 66 { 67 if( null == file ) 68 { 69 throw new NullPointerException ( "file" ); 70 } 71 72 if( null == available ) 73 { 74 throw new NullPointerException ( "available" ); 75 } 76 77 if( null == required ) 78 { 79 throw new NullPointerException ( "required" ); 80 } 81 82 m_file = file; 83 m_available = available; 84 m_required = required; 85 } 86 87 93 public File getFile() 94 { 95 return m_file; 96 } 97 98 104 public Extension[] getRequiredExtensions() 105 { 106 return m_required; 107 } 108 109 115 public Extension[] getAvailableExtensions() 116 { 117 return m_available; 118 } 119 120 127 public boolean isCompatible( final Extension extension ) 128 { 129 for( int i = 0; i < m_available.length; i++ ) 130 { 131 if( m_available[ i ].isCompatibleWith( extension ) ) 132 { 133 return true; 134 } 135 } 136 137 return false; 138 } 139 140 145 public String toString() 146 { 147 final StringBuffer sb = new StringBuffer ( "OptionalPackage[" ); 148 sb.append( m_file ); 149 150 sb.append( ", Available[" ); 151 for( int i = 0; i < m_available.length; i++ ) 152 { 153 if( 0 != i ) 154 { 155 sb.append( " " ); 156 } 157 sb.append( m_available[ i ].getExtensionName() ); 158 } 159 160 sb.append( "], Required[" ); 161 for( int i = 0; i < m_required.length; i++ ) 162 { 163 if( 0 != i ) 164 { 165 sb.append( " " ); 166 } 167 sb.append( m_required[ i ].getExtensionName() ); 168 } 169 170 sb.append( "] ]" ); 171 172 return sb.toString(); 173 } 174 } 175 | Popular Tags |