1 package net.logAnalyzer.gui; 2 3 import java.lang.reflect.Constructor; 4 import java.util.Hashtable; 5 6 import net.logAnalyzer.patternParser.PatternParsingException; 7 8 /*** 9 * This class contains the definition of a view. 10 * @author Karim REFEYTON 11 * @version 0.1 12 */ 13 public class ViewDefinition { 14 15 /*** 16 * Name for IHM. 17 */ 18 private String name; 19 20 /*** 21 * LAView class. 22 */ 23 private Class viewClass; 24 25 /*** 26 * User friendly label. 27 */ 28 private String label; 29 30 /*** 31 * View attributes. 32 */ 33 private Hashtable attributes; 34 35 /*** 36 * Constructs a new view definition. 37 * @param name Name of the view. 38 * @param classname Class of the new view instances. 39 * @param label User friendly label. 40 * @param attributes View attributes. 41 * @throws ClassNotFoundException If the specified view class does not 42 * exists. 43 */ 44 public ViewDefinition(String name, String classname, String label, 45 Hashtable attributes) throws ClassNotFoundException { 46 this.name = name; 47 this.viewClass = ClassLoader.getSystemClassLoader() 48 .loadClass(classname); 49 this.label = label; 50 this.attributes = attributes; 51 } 52 53 public String getName() { 54 return this.name; 55 } 56 57 public Class getViewClass() { 58 return this.viewClass; 59 } 60 61 public String getLabel() { 62 return this.label; 63 } 64 65 public Hashtable getAttributes() { 66 return this.attributes; 67 } 68 69 public LAView createViewInstance() throws PatternParsingException { 70 try { 71 Class[] classes = new Class[] { ViewDefinition.class, 72 Hashtable.class }; 73 Object[] parameters = new Object[] { this, this.attributes }; 74 Constructor constructor = viewClass.getConstructor(classes); 75 return (LAView) constructor.newInstance(parameters); 76 } catch (Exception e) { 77 throw new PatternParsingException(e); 78 } 79 } 80 81 }