1 16 package org.apache.cocoon.components.language.programming.javascript; 17 18 import org.apache.avalon.framework.component.ComponentManager; 19 import org.apache.avalon.framework.configuration.Configurable; 20 import org.apache.avalon.framework.configuration.DefaultConfiguration; 21 import org.apache.avalon.framework.context.Context; 22 23 import org.apache.avalon.excalibur.component.ComponentHandler; 24 import org.apache.avalon.excalibur.component.RoleManager; 25 import org.apache.avalon.excalibur.component.LogkitLoggerManager; 26 27 import org.apache.cocoon.components.language.generator.CompiledComponent; 28 import org.apache.cocoon.components.language.programming.Program; 29 30 import java.io.File ; 31 import java.util.Collection ; 32 import java.util.Iterator ; 33 34 40 public class JavascriptProgram implements Program { 41 42 protected File file; 43 protected Class clazz; 44 protected DefaultConfiguration config; 45 46 public JavascriptProgram(File file, Class clazz, Collection dependecies) { 47 DefaultConfiguration child; 48 49 this.file = file; 50 this.clazz = clazz; 51 52 config = new DefaultConfiguration("", "GeneratorSelector"); 53 child = new DefaultConfiguration("file", ""); 54 child.setValue(file.toString()); 55 config.addChild(child); 56 57 for (Iterator i = dependecies.iterator(); i.hasNext(); ) { 58 child = new DefaultConfiguration("dependency", ""); 59 child.setValue(i.next().toString()); 60 config.addChild(child); 61 } 62 } 63 64 public String getName() { 65 return file.toString(); 66 } 67 68 public ComponentHandler getHandler(ComponentManager manager, 69 Context context, 70 RoleManager roles, 71 LogkitLoggerManager logKitManager) 72 throws Exception { 73 74 return ComponentHandler.getComponentHandler( 75 clazz, config, manager, context, roles, logKitManager, null, "N/A"); 76 } 77 78 public CompiledComponent newInstance() throws Exception { 79 CompiledComponent instance = (CompiledComponent) clazz.newInstance(); 80 if (instance instanceof Configurable) 81 ((Configurable) instance).configure(config); 82 return instance; 83 } 84 } 85 | Popular Tags |