1 42 43 package org.jfree.base; 44 45 import java.util.ArrayList ; 46 import java.util.List ; 47 import java.lang.reflect.Method ; 48 49 import org.jfree.util.ObjectUtilities; 50 import org.jfree.util.Log; 51 52 57 public class BasicProjectInfo extends Library { 58 62 private static class OptionalLibraryHolder { 63 private String libraryClass; 64 private transient Library library; 65 66 public OptionalLibraryHolder(final String libraryClass) { 67 if (libraryClass == null) { 68 throw new NullPointerException ("LibraryClass must not be null."); 69 } 70 this.libraryClass = libraryClass; 71 } 72 73 public OptionalLibraryHolder(final Library library) { 74 if (library == null) { 75 throw new NullPointerException ("Library must not be null."); 76 } 77 this.library = library; 78 this.libraryClass = library.getClass().getName(); 79 } 80 81 public String getLibraryClass() { 82 return libraryClass; 83 } 84 85 public Library getLibrary() { 86 if (library == null) { 87 library = loadLibrary(libraryClass); 88 } 89 return library; 90 } 91 92 protected Library loadLibrary(final String classname) { 93 if (classname == null) { 94 return null; 95 } 96 try { 97 final Class c = ObjectUtilities.getClassLoader( 98 getClass()).loadClass(classname); 99 try { 100 final Method m = c.getMethod("getInstance", (Class []) null); 101 return (Library) m.invoke(null, (Object []) null); 102 } 103 catch(Exception e) { 104 } 106 return (Library) c.newInstance(); 107 } 108 catch (Exception e) { 109 return null; 112 } 113 } 114 115 } 116 117 118 private String copyright; 119 120 121 private List libraries; 122 123 private List optionalLibraries; 124 125 128 public BasicProjectInfo() { 129 this.libraries = new ArrayList (); 130 this.optionalLibraries = new ArrayList (); 131 } 132 133 141 public BasicProjectInfo(final String name, final String version, 142 final String licence, final String info) { 143 this(); 144 setName(name); 145 setVersion(version); 146 setLicenceName(licence); 147 setInfo(info); 148 } 149 150 159 public BasicProjectInfo(final String name, final String version, 160 final String info, final String copyright, 161 final String licenceName) { 162 this(name, version, licenceName, info); 163 setCopyright(copyright); 164 } 165 166 171 public String getCopyright() { 172 return this.copyright; 173 } 174 175 180 public void setCopyright(final String copyright) { 181 this.copyright = copyright; 182 } 183 184 189 public void setInfo(final String info) { 190 super.setInfo(info); 191 } 192 193 198 public void setLicenceName(final String licence) { 199 super.setLicenceName(licence); 200 } 201 202 207 public void setName(final String name) { 208 super.setName(name); 209 } 210 211 216 public void setVersion(final String version) { 217 super.setVersion(version); 218 } 219 220 225 public Library[] getLibraries() { 226 return (Library[]) this.libraries.toArray 227 (new Library[this.libraries.size()]); 228 } 229 230 235 public void addLibrary (final Library library) { 236 if (library == null) { 237 throw new NullPointerException (); 238 } 239 this.libraries.add(library); 240 } 241 242 247 public Library[] getOptionalLibraries() { 248 final ArrayList libraries = new ArrayList (); 249 for (int i = 0; i < optionalLibraries.size(); i++) { 250 OptionalLibraryHolder holder = 251 (OptionalLibraryHolder) optionalLibraries.get(i); 252 Library l = holder.getLibrary(); 253 if (l != null) { 254 libraries.add(l); 255 } 256 } 257 return (Library[]) libraries.toArray(new Library[libraries.size()]); 258 } 259 260 267 public void addOptionalLibrary (final String libraryClass) { 268 if (libraryClass == null) { 269 throw new NullPointerException ("Library classname must be given."); 270 } 271 this.optionalLibraries.add 272 (new OptionalLibraryHolder(libraryClass)); 273 } 274 275 276 283 public void addOptionalLibrary (final Library library) { 284 if (library == null) { 285 throw new NullPointerException ("Library must be given."); 286 } 287 this.optionalLibraries.add(new OptionalLibraryHolder(library)); 288 } 289 } 290 | Popular Tags |