KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > mmbase > util > xml > ModuleWriter


1 /*
2
3 This software is OSI Certified Open Source Software.
4 OSI Certified is a certification mark of the Open Source Initiative.
5
6 The license (Mozilla version 1.0) can be read at the MMBase site.
7 See http://www.MMBase.org/license
8
9 */

10 package org.mmbase.util.xml;
11
12 import java.util.*;
13 import org.mmbase.module.Module;
14 import org.mmbase.util.XMLEntityResolver;
15
16 import org.w3c.dom.*;
17
18 /**
19  * @author Daniel Ockeloen
20  * @version $Id: ModuleWriter.java,v 1.8 2005/09/12 14:07:39 pierre Exp $
21  */

22 public class ModuleWriter extends DocumentWriter {
23
24     /**
25      * Hold a reference to the module for which to create an XML document.
26      */

27     protected Module module;
28
29     /**
30      * Constructs the document writer.
31      * The constructor calls its super to create a basic document, based on the module document type.
32      * @param module the module for which to create an XML document.
33      */

34     public ModuleWriter(Module module) throws DOMException {
35         super("module", ModuleReader.PUBLIC_ID_MODULE,
36                         XMLEntityResolver.DOMAIN + XMLEntityResolver.DTD_SUBPATH + ModuleReader.DTD_MODULE);
37         this.module = module;
38         getMessageRetriever("org.mmbase.util.xml.resources.modulewriter");
39     }
40
41     /**
42      * Generates the document. Can only be called once.
43      * @throws DOMException when an error occurred during generation
44      */

45     protected void generate() throws DOMException {
46         Element root = document.getDocumentElement();
47         addComment("module.configuration",module.getName(),module.getModuleInfo(),root);
48         root.setAttribute("maintainer",module.getMaintainer());
49         root.setAttribute("version",""+module.getVersion());
50         // status
51
addComment("module.status",root);
52         addContentElement("status","active",root);
53         // classfile
54
addComment("module.classfile",root);
55         addContentElement("classfile",module.getClass().getName(),root);
56         // properties
57
Element properties=document.createElement("properties");
58         addComment("module.properties",root);
59         root.appendChild(properties);
60         // properties.property
61
Map datamap=module.getInitParameters();
62         for (Iterator i=datamap.entrySet().iterator(); i.hasNext();) {
63             Map.Entry entry = (Map.Entry) i.next();
64             String JavaDoc propname = (String JavaDoc) entry.getKey();
65             String JavaDoc propvalue = (String JavaDoc) entry.getValue();
66             Element elm=addContentElement("property",propvalue,properties);
67             elm.setAttribute("name",propname);
68         }
69     }
70 }
71
Popular Tags