KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > enhydra > xml > xmlc > dom > xerces > XercesNodeCreateGenerator


1 /*
2  * Enhydra Java Application Server Project
3  *
4  * The contents of this file are subject to the Enhydra Public License
5  * Version 1.1 (the "License"); you may not use this file except in
6  * compliance with the License. You may obtain a copy of the License on
7  * the Enhydra web site ( http://www.enhydra.org/ ).
8  *
9  * Software distributed under the License is distributed on an "AS IS"
10  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
11  * the License for the specific terms governing rights and limitations
12  * under the License.
13  *
14  * The Initial Developer of the Enhydra Application Server is Lutris
15  * Technologies, Inc. The Enhydra Application Server and portions created
16  * by Lutris Technologies, Inc. are Copyright Lutris Technologies, Inc.
17  * All Rights Reserved.
18  *
19  * Contributor(s):
20  *
21  * $Id: XercesNodeCreateGenerator.java,v 1.2 2005/01/26 08:29:24 jkjome Exp $
22  */

23
24 package org.enhydra.xml.xmlc.dom.xerces;
25
26 import org.enhydra.xml.dom.DOMOps;
27 import org.enhydra.xml.xmlc.codegen.JavaCode;
28 import org.enhydra.xml.xmlc.codegen.JavaLang;
29 import org.enhydra.xml.xmlc.dom.XMLCDocument;
30 import org.enhydra.xml.xmlc.dom.generic.NodeCreateGenerator;
31 import org.w3c.dom.Entity JavaDoc;
32 import org.w3c.dom.Notation JavaDoc;
33
34 /**
35  * Class used create DOM nodes for the Xerces DOM.
36  */

37 public class XercesNodeCreateGenerator extends NodeCreateGenerator {
38     /**
39      * Constructor.
40      */

41     public XercesNodeCreateGenerator(XMLCDocument xmlcDoc) {
42         super(xmlcDoc);
43     }
44
45     /**
46      * Generate Entity creation.
47      */

48     protected void genEntityCreate(Entity JavaDoc entity,
49                                    String JavaDoc docVar,
50                                    String JavaDoc varName,
51                                    JavaCode body) {
52         body.addln(varName + " = " + docVar + ".createEntity("
53                    + JavaLang.createStringConst(entity.getNodeName()));
54         body.addln(varName + ".setPublicId("
55                    + JavaLang.createStringConst(entity.getPublicId()) + ");");
56         body.addln(varName + ".setSystemId("
57                    + JavaLang.createStringConst(entity.getSystemId()) + ");");
58     try {
59         String JavaDoc encoding = DOMOps.getEncoding(entity);
60         body.addln(
61            "try { " +
62                "DOMOps.setEncoding(" + varName + ", " + encoding +"); " +
63            "} catch (UnsupportedOperationException e) { /* ignore */ }"
64        );
65     } catch (UnsupportedOperationException JavaDoc e) {
66         // Ignore this - if we can't read the encoding here, no point
67
// in trying to set it in the compiled document...
68
}
69         
70         body.addln(varName + ".setNotationName("
71                    + JavaLang.createStringConst(entity.getNotationName())
72            + ");");
73     }
74
75     /**
76      * Generate Notation creation.
77      */

78     protected void genNotationCreate(Notation JavaDoc notation,
79                                      String JavaDoc docVar,
80                                      String JavaDoc varName,
81                                      JavaCode body) {
82         body.addln(varName + " = " + docVar + ".createNotation("
83                    + JavaLang.createStringConst(notation.getNodeName()));
84         body.addln(varName + ".setPublicId("
85                    + JavaLang.createStringConst(notation.getPublicId()) + ");");
86         body.addln(varName + ".setSystemId("
87                    + JavaLang.createStringConst(notation.getSystemId()) + ");");
88     }
89
90     /**
91      * Add an entity to a DocumentType
92      */

93     public void genAddEntity(String JavaDoc docTypeVar,
94                              String JavaDoc entityVar,
95                              Entity JavaDoc entity,
96                              JavaCode body) {
97         //FIXME: should be in xerces version of this file
98
if (entity.getNamespaceURI() != null) {
99             body.addln(docTypeVar + ".getEntities().setNamedItemNS("
100                        + entityVar + ");");
101         } else {
102             body.addln(docTypeVar + ".getEntities().setNamedItem("
103                        + entityVar + ");");
104         }
105     }
106
107     /**
108      * Add an notation to a DocumentType
109      */

110     public void genAddNotation(String JavaDoc docTypeVar,
111                                String JavaDoc notationVar,
112                                Notation JavaDoc notation,
113                                JavaCode body) {
114         //FIXME: should be in xerces version of this file
115
if (notation.getNamespaceURI() != null) {
116             body.addln(docTypeVar + ".getNotations().setNamedItemNS("
117                        + notationVar + ");");
118         } else {
119             body.addln(docTypeVar + ".getNotations().setNamedItem("
120                        + notationVar + ");");
121         }
122     }
123 }
124
Popular Tags