1 8 package org.apache.avalon.excalibur.extension; 9 10 import java.io.File ; 11 12 19 public final class OptionalPackage 20 { 21 private final File m_file; 22 private final Extension[] m_available; 23 private final Extension[] m_required; 24 25 31 public static final File [] toFiles( final OptionalPackage[] packages ) 32 { 33 final File [] results = new File [ packages.length ]; 34 35 for( int i = 0; i < packages.length; i++ ) 36 { 37 results[ i ] = packages[ i ].getFile(); 38 } 39 40 return results; 41 } 42 43 51 public OptionalPackage( final File file, 52 final Extension[] available, 53 final Extension[] required ) 54 { 55 if( null == file ) 56 { 57 throw new NullPointerException ( "file property is null" ); 58 } 59 60 if( null == available ) 61 { 62 throw new NullPointerException ( "available property is null" ); 63 } 64 65 if( null == required ) 66 { 67 throw new NullPointerException ( "required property is null" ); 68 } 69 70 m_file = file; 71 m_available = available; 72 m_required = required; 73 } 74 75 81 public File getFile() 82 { 83 return m_file; 84 } 85 86 92 public Extension[] getRequiredExtensions() 93 { 94 return m_required; 95 } 96 97 103 public Extension[] getAvailableExtensions() 104 { 105 return m_available; 106 } 107 108 115 public boolean isCompatible( final Extension extension ) 116 { 117 for( int i = 0; i < m_available.length; i++ ) 118 { 119 if( m_available[ i ].isCompatibleWith( extension ) ) 120 { 121 return true; 122 } 123 } 124 125 return false; 126 } 127 128 131 public String toString() 132 { 133 final StringBuffer sb = new StringBuffer ( "OptionalPackage[" ); 134 sb.append( m_file ); 135 136 sb.append( ", Available[" ); 137 for( int i = 0; i < m_available.length; i++ ) 138 { 139 sb.append( m_available ); 140 sb.append( " " ); 141 } 142 143 sb.append( "], Required[" ); 144 for( int i = 0; i < m_required.length; i++ ) 145 { 146 sb.append( m_required ); 147 sb.append( " " ); 148 } 149 150 sb.append( "] ]" ); 151 152 return sb.toString(); 153 } 154 } 155 | Popular Tags |