KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > genimen > djeneric > web > renderers > ImportRenderer


1 package com.genimen.djeneric.web.renderers;
2
3 import java.util.Iterator JavaDoc;
4 import java.util.TreeMap JavaDoc;
5
6 import javax.xml.parsers.FactoryConfigurationError JavaDoc;
7 import javax.xml.parsers.ParserConfigurationException JavaDoc;
8
9 import org.w3c.dom.Document JavaDoc;
10 import org.w3c.dom.Element JavaDoc;
11
12 import com.genimen.djeneric.language.Messages;
13 import com.genimen.djeneric.repository.DjUid;
14
15 public class ImportRenderer extends AbstractRenderer
16 {
17   public static int _uidcounter = 1;
18
19   public ImportRenderer()
20   {
21   }
22
23   public Document JavaDoc asXml() throws FactoryConfigurationError JavaDoc, ParserConfigurationException JavaDoc
24   {
25     Document JavaDoc doc = createDocument();
26     Element JavaDoc importelem = doc.createElement("import");
27     importelem.setAttribute("id", "imp."+ String.valueOf(_uidcounter++));
28     doc.appendChild(importelem);
29
30     return doc;
31   }
32
33   public Document JavaDoc asXml(TreeMap JavaDoc result) throws FactoryConfigurationError JavaDoc, ParserConfigurationException JavaDoc
34   {
35     Document JavaDoc doc = createDocument();
36     Element JavaDoc importelem = doc.createElement("import");
37     importelem.setAttribute("id", "imp."+ String.valueOf(_uidcounter++));
38     doc.appendChild(importelem);
39
40     Iterator JavaDoc it = result.keySet().iterator();
41     while (it.hasNext())
42     {
43       Element JavaDoc file = doc.createElement("file");
44       importelem.appendChild(file);
45       String JavaDoc fileName = (String JavaDoc) it.next();
46       file.setAttribute("name", fileName);
47       DjUid[] unresolved = (DjUid[]) result.get(fileName);
48
49       for (int i = 0; i < unresolved.length; i++)
50       {
51         file.appendChild(createUnresolvedElement(doc, unresolved[i]));
52       }
53
54       if (unresolved.length == 0)
55       {
56         file.setAttribute("message", Messages.getString("ObjectImporter.completed"));
57         file.setAttribute("successful", "true");
58       }
59       else
60       {
61         file.setAttribute("message", Messages.getString("ObjectImporter.completed"));
62         file.setAttribute("successful", "false");
63       }
64     }
65
66     return doc;
67   }
68
69   protected Element JavaDoc createUnresolvedElement(Document JavaDoc doc, DjUid uid)
70   {
71     Element JavaDoc unresolved = doc.createElement("unresolved");
72
73     unresolved.setAttribute("id", String.valueOf(uid.getAssociatedObjectid()));
74     unresolved.setAttribute("extent", uid.getExtent().getName());
75     unresolved.setAttribute("typename", uid.getExtent().getNameSingular());
76     unresolved.setAttribute("descriptor", uid.getDescriptor());
77
78     return unresolved;
79   }
80 }
81
Popular Tags