1 package org.ejen; 22 23 import org.ejen.ext.Version; 24 import org.ejen.util.DOMUtil; 25 import org.ejen.util.XSLUtil; 26 import java.util.Vector ; 27 import java.util.Enumeration ; 28 import javax.xml.transform.dom.DOMSource ; 29 import javax.xml.transform.TransformerFactory ; 30 import org.w3c.dom.Document ; 31 import org.apache.xalan.processor.TransformerFactoryImpl; 32 33 45 public class EjenRootNode extends EjenChildNode { 46 private Vector _childNodes = new Vector (); 47 48 52 public String nodeName() { 53 return "ejen"; 54 } 55 56 60 public Vector getChildren() { 61 Vector children = super.getChildren(); 62 63 children.addAll(_childNodes); 64 return children; 65 } 66 67 73 public void appendChildNode(EjenChildNode ecn) { 74 if (ecn instanceof EjenParamNode || ecn instanceof EjenIncludeNode 75 || ecn instanceof EjenImportNode) { 76 throw new EjenException(this, "initialisation error"); 77 } 78 _childNodes.addElement(ecn); 79 } 80 81 85 public void check() { 86 super.check(); 87 for (Enumeration e = _childNodes.elements(); e.hasMoreElements();) { 88 ((EjenChildNode) e.nextElement()).check(); 89 } 90 } 91 92 98 public void beforeProcess() { 99 super.beforeProcess(); 100 101 try { 102 Document doc = DOMUtil.parseXMLString(null); 103 104 doc.getDocumentElement().setAttribute("ejen-version", 105 Version.toString(null)); 106 putInGlobalContext(CTX_DOM_SOURCE, new DOMSource (doc)); 107 TransformerFactoryImpl tfi = (TransformerFactoryImpl) TransformerFactory.newInstance(); 108 109 putInGlobalContext(CTX_TRANSFORMER_FACTORY_IMPL, tfi); 110 putInGlobalContext(CTX_TRANSFORMER_IMPL, 111 XSLUtil.getDefaultTransformer(tfi)); 112 putInGlobalContext(CTX_STYLESHEET_HANDLER, tfi.newTemplatesHandler()); 113 } catch (EjenException e) { 114 throw e; 115 } catch (Exception e) { 116 throw new EjenException(this, "initialisation error", e); 117 } 118 119 } 120 121 125 public void process() { 126 super.process(); 127 try { 128 for (Enumeration e = _childNodes.elements(); e.hasMoreElements();) { 129 EjenChildNode ecn = (EjenChildNode) (e.nextElement()); 130 131 _messageIndent = LOG_INDENT_STR2; 133 ecn.beforeProcess(); 134 ecn.process(); 135 ecn.afterProcess(); 136 ecn.idle(); 137 _messageIndent = ""; 138 } 139 } catch (EjenException e) { 140 throw e; 141 } catch (Exception e) { 142 throw new EjenException(this, null, e); 143 } 144 } 145 } 146 | Popular Tags |