1 23 24 package org.enhydra.xml.xmlc.dom.generic; 25 26 import org.enhydra.xml.xmlc.XMLCException; 27 import org.enhydra.xml.xmlc.codegen.JavaClass; 28 import org.enhydra.xml.xmlc.codegen.JavaCode; 29 import org.enhydra.xml.xmlc.codegen.JavaLang; 30 import org.enhydra.xml.xmlc.codegen.JavaMethod; 31 import org.enhydra.xml.xmlc.compiler.ElementTable; 32 import org.enhydra.xml.xmlc.dom.AccessorGenerator; 33 import org.enhydra.xml.xmlc.dom.DocBuilderGenerator; 34 import org.enhydra.xml.xmlc.dom.XMLCDocument; 35 import org.w3c.dom.Document ; 36 37 42 abstract public class GenericDocBuilderGenerator implements DocBuilderGenerator { 43 47 private static final int MAX_CREATE_COST_PER_BUILD_METHOD = 512; 48 49 52 private static final String DOCUMENT_VAR_NAME = "document"; 53 54 57 private static final String SUBDOCUMENT_BUILD_METHOD = "buildSubDocument"; 58 59 63 public void createBuildDocumentMethod(XMLCDocument xmlcDoc, 64 AccessorGenerator accessorGenerator, 65 ElementTable elementTable, 66 JavaClass docClass, 67 JavaMethod buildDocumentMethod) throws XMLCException { 68 DOMBuilderGenerator domBuilderGenerator 70 = new DOMBuilderGenerator(SUBDOCUMENT_BUILD_METHOD, 71 xmlcDoc.getDocument(), 72 Document.class.getName(), 73 new NodeCreateGenerator(xmlcDoc), 74 accessorGenerator, 75 elementTable, 76 docClass, 77 MAX_CREATE_COST_PER_BUILD_METHOD, 78 false); 79 JavaCode body = buildDocumentMethod.getCode(); 81 body.add(xmlcDoc.getDocument().getClass().getName() + " " 82 + DOCUMENT_VAR_NAME + " = "); 83 domBuilderGenerator.createMethodCall(body); 84 85 body.addln("setDocument(" + DOCUMENT_VAR_NAME + "," 87 + JavaLang.createStringConst(xmlcDoc.getDomFactory().getMIMEType()) + ", " 88 + JavaLang.createStringConst(xmlcDoc.getEncoding()) + ");"); 89 body.addln(); 90 } 91 } 92 | Popular Tags |