1 18 19 package de.gulden.framework.amoda.generic.core; 20 21 import de.gulden.framework.amoda.generic.metadata.*; 22 import de.gulden.framework.amoda.generic.option.*; 23 import de.gulden.framework.amoda.model.core.*; 24 import de.gulden.framework.amoda.model.core.ApplicationModule; 25 import de.gulden.framework.amoda.model.data.*; 26 import java.lang.*; 27 import java.net.*; 28 import java.util.*; 29 import org.w3c.dom.*; 30 31 37 public class GenericApplicationModule extends GenericFeatureGroup implements ApplicationModule { 38 39 43 protected Document configurationDocument; 44 45 protected boolean configurationDocumentSet = false; 46 47 48 52 public void init() { 53 } 55 56 public void start() { 57 for (Iterator it = getModules().iterator(); it.hasNext(); ) { 58 ApplicationModule m = (ApplicationModule)it.next(); 59 m.start(); 60 } 61 } 62 63 public void stop() { 64 for (Iterator it = getModules().iterator(); it.hasNext(); ) { 65 ApplicationModule m = (ApplicationModule)it.next(); 66 m.stop(); 67 } 68 } 69 70 public void destroy() { 71 for (Iterator it = getModules().iterator(); it.hasNext(); ) { 72 ApplicationModule m = (ApplicationModule)it.next(); 73 m.destroy(); 74 } 75 } 76 77 public Collection getModules() { 78 return getAll(ApplicationModule.class,false).values(); 79 } 80 81 public ApplicationModule getModule(String id) { 82 return (ApplicationModule)get(id); 83 } 84 85 public void loadModule(String id, String classname) { 86 Class cl; 88 try { 89 cl = Class.forName(classname); 90 } catch (ClassNotFoundException cnfe) { 91 getApplication().error("cannot load application module '"+classname+"'",cnfe); 92 return; 93 } 94 GenericApplicationModule module; 95 try { 96 module = (GenericApplicationModule)cl.newInstance(); 97 } catch (Exception e) { 98 getApplication().error("cannot create instance of module '"+classname+"' as GenericApplicationModule", e); 99 return; 100 } 101 module.setId(id); 102 this.add(module); ((GenericApplication)getApplication()).initModule(module); 104 } 105 106 public Document getConfigurationDocument() { 107 if (!configurationDocumentSet) { URL res = getDefaultConfigurationDocumentResource(); 110 if (res==null) { 111 getApplication().fatalError("cannot initialize application XML configuration for class "+this.getClass().getName(), null); 112 } 113 setConfigurationDocument(res); 114 configurationDocumentSet = true; } 116 return configurationDocument; 117 } 118 119 public void setConfigurationDocument(Document _configurationDocument) { 120 configurationDocumentSet = true; 121 configurationDocument = _configurationDocument; 122 } 123 124 public void setConfigurationDocument(URL url) { 125 try { 126 String u=url.toExternalForm(); 127 getApplication().log("loading configuration XML document '"+u+"'"); 128 Document d=((GenericApplication)getApplication()).getGenericApplicationEnvironment().getFactory().getDocumentBuilder().parse(u); 129 setConfigurationDocument(d); 130 } catch (Exception e) { 131 getApplication().fatalError("cannot initialize application XML configuration",e); 132 } 133 } 134 135 public void setConfigurationDocument(String resource) { 136 try { 137 setConfigurationDocument(de.gulden.util.Toolbox.getResourceURL(resource)); 138 } catch (java.net.MalformedURLException mue) { 139 getApplication().error(mue); 140 } 141 } 142 143 public CompositeMember get(String id) { 144 CompositeMember m = super.get(id); 145 if ((m.getParent()==null) && this.all.containsValue(m)) { 146 m.setParent(this); 148 } 149 return m; 150 } 151 152 protected URL getDefaultConfigurationDocumentResource() { 153 return GenericApplicationEnvironment.getXMLResourceForClass(this.getClass()); 154 } 155 156 } | Popular Tags |