1 package net.sf.mmapps.modules.config;
2
3 import java.util.Iterator;
4
5 import simplexml.XMLElement;
6
7 /***
8 * Utility class to read configuration
9 * @author Kees Jongenburger
10 * @version $Id: ConfigurationXMLReader.java,v 1.3 2004/05/18 13:53:55 keesj Exp $
11 */
12 public abstract class ConfigurationXMLReader {
13
14 public static ApplicationConfiguration createApplicationConfiguration(Configuration config, String data) {
15 ApplicationConfiguration conf = config.createApplicationConfiguration();
16 XMLElement xmle = new XMLElement();
17 xmle.parseString(data);
18 conf.setName(xmle.getProperty("name", conf.getName()));
19 conf.setMaintainer(xmle.getProperty("maintainer", conf.getMaintainer()));
20 conf.setVersion(xmle.getProperty("version", conf.getVersion()));
21 Iterator iter = xmle.getChildren().iterator();
22 while (iter.hasNext()) {
23 XMLElement child = (XMLElement) iter.next();
24
25 if (child.getTagName().equals("neededbuilderlist")) {
26 Iterator neededBuilderListIterator = child.getChildren().iterator();
27 while (neededBuilderListIterator.hasNext()) {
28 XMLElement neededBuilder = (XMLElement) neededBuilderListIterator.next();
29 if (neededBuilder.getTagName().equals("builder")) {
30
31
32 conf.addRequiredNodeManager(neededBuilder.getContents());
33 } else {
34 System.err.println("unknown sub tag(" + neededBuilder.getTagName() + ") of the names tag.. skipping");
35 }
36 }
37 } else if (child.getTagName().equals("requirements")) {
38 Iterator deps = child.getChildren().iterator();
39 while (deps.hasNext()) {
40 XMLElement requires = (XMLElement) deps.next();
41 conf.addDepends(requires.getProperty("name"));
42 }
43 } else if (child.getTagName().equals("neededreldeflist")) {
44 Iterator neededReldefListIterator = child.getChildren().iterator();
45 while (neededReldefListIterator.hasNext()) {
46 XMLElement reldef = (XMLElement) neededReldefListIterator.next();
47 if (reldef.getTagName().equals("reldef")) {
48
49
50 conf.addRelationType(
51 new RelationType(
52 reldef.getProperty("source"),
53 reldef.getProperty("guisourcename"),
54 reldef.getProperty("guidestinationname"),
55 reldef.getProperty("builder"),
56 reldef.getProperty("directions")));
57 } else {
58 System.err.println("unknown sub tag(" + reldef.getTagName() + ") of the names tag.. skipping");
59 }
60 }
61 } else if (child.getTagName().equals("allowedrelationlist")) {
62 Iterator allowedrelationIterator = child.getChildren().iterator();
63 while (allowedrelationIterator.hasNext()) {
64 XMLElement relation = (XMLElement) allowedrelationIterator.next();
65 if (relation.getTagName().equals("relation")) {
66
67
68 RelationManagerConfiguration relationManagerConfiguration = config.createRelationManagerConfiguration();
69 relationManagerConfiguration.setSourceNodeManagerName(relation.getProperty("from"));
70 relationManagerConfiguration.setDestinationNodeManagerName(relation.getProperty("to"));
71 relationManagerConfiguration.setRelationTypeName(relation.getProperty("type"));
72 conf.addRelationManagerConfiguration(relationManagerConfiguration);
73 } else {
74 System.err.println("unknown sub tag(" + relation.getTagName() + ") of the names tag.. skipping");
75 }
76 }
77 }
78
79 }
80
81 return conf;
82
83 }
84
85 public static NodeManagerConfiguration createNodeManagerConfiguration(Configuration configuration,String data) {
86 NodeManagerConfiguration conf = configuration.createNodeManagerConfiguration();
87 XMLElement xmle = new XMLElement();
88 xmle.parseString(data);
89
90 conf.setName(xmle.getProperty("name", conf.getName()));
91 conf.setMaintainer(xmle.getProperty("maintainer", conf.getMaintainer()));
92 conf.setVersion(xmle.getProperty("version", conf.getVersion()));
93
94
95 conf.setExtends(xmle.getProperty("extends", conf.getExtends()));
96
97 Iterator iter = xmle.getChildren().iterator();
98 while (iter.hasNext()) {
99 XMLElement child = (XMLElement) iter.next();
100
101
102 if (child.getTagName().equals("classfile")) {
103 conf.setClassFile(child.getContents());
104 } else if (child.getTagName().equals("status")) {
105 conf.setStatus(child.getContents());
106 } else if (child.getTagName().equals("searchage")) {
107 conf.setSearchAge(child.getContents());
108 } else if (child.getTagName().equals("names")) {
109 Iterator nameIter = child.getChildren().iterator();
110 while (nameIter.hasNext()) {
111 XMLElement nameElement = (XMLElement) nameIter.next();
112 if (nameElement.getTagName().equals("singular")) {
113 conf.setSingularGUIName(nameElement.getProperty("xml:lang"), nameElement.getContents());
114 } else if (nameElement.getTagName().equals("plural")) {
115 conf.setPluralGUIName(nameElement.getProperty("xml:lang"), nameElement.getContents());
116 } else {
117 System.err.println("unknown sub tag(" + nameElement.getTagName() + ") of the names tag.. skipping");
118 }
119 }
120 } else if (child.getTagName().equals("descriptions")) {
121 Iterator descIter = child.getChildren().iterator();
122 while (descIter.hasNext()) {
123 XMLElement descElement = (XMLElement) descIter.next();
124 conf.setDescription(descElement.getProperty("xml:lang"), descElement.getContents());
125 }
126 } else if (child.getTagName().equals("properties")) {
127 Iterator propIter = child.getChildren().iterator();
128 while (propIter.hasNext()) {
129 XMLElement propElement = (XMLElement) propIter.next();
130
131 if (propElement.getContents() == null) {
132 conf.setProperty(propElement.getProperty("name"), "");
133 } else {
134 conf.setProperty(propElement.getProperty("name"), propElement.getContents());
135 }
136 }
137 } else if (child.getTagName().equals("fieldlist")) {
138 Iterator fieldIter = child.getChildren().iterator();
139 while (fieldIter.hasNext()) {
140 XMLElement fieldElement = (XMLElement) fieldIter.next();
141 conf.addFieldConfiguration(createFieldConfiguration(configuration,fieldElement));
142
143 }
144 } else {
145 System.err.println("unknown tag(" + child.getTagName() + ") for nodemanager configuration(" + conf.getName() + ")");
146 }
147 }
148
149 return conf;
150 }
151
152 public static FieldConfiguration createFieldConfiguration(Configuration config,XMLElement xmlField) {
153 FieldConfiguration conf = config.createFieldConfiguration();
154 Iterator iter = xmlField.getChildren().iterator();
155 while (iter.hasNext()) {
156 XMLElement child = (XMLElement) iter.next();
157 if (child.getTagName().equals("gui")) {
158 Iterator guiNameIter = child.getChildren().iterator();
159 while (guiNameIter.hasNext()) {
160 XMLElement guiNameElement = (XMLElement) guiNameIter.next();
161 if (guiNameElement.getTagName().equals("guiname")) {
162 conf.setGUIName(guiNameElement.getProperty("xml:lang"), guiNameElement.getContents());
163 } else if (guiNameElement.getTagName().equals("guitype")) {
164 conf.setGUIType(guiNameElement.getContents());
165 } else {
166 System.err.println("error in unknown gui subtag(" + guiNameElement.getTagName() + ")");
167 }
168 }
169 } else if (child.getTagName().equals("descriptions")) {
170 Iterator descIter = child.getChildren().iterator();
171 while (descIter.hasNext()) {
172 XMLElement descElement = (XMLElement) descIter.next();
173 conf.setDescription(descElement.getProperty("xml:lang"), descElement.getContents());
174 }
175 } else if (child.getTagName().equals("editor")) {
176 Iterator editorIter = child.getChildren().iterator();
177 while (editorIter.hasNext()) {
178 XMLElement tag = (XMLElement) editorIter.next();
179 if (tag.getTagName().equals("positions")) {
180 Iterator positionIter = tag.getChildren().iterator();
181 while (positionIter.hasNext()) {
182 XMLElement pos = (XMLElement) positionIter.next();
183 if (pos.getTagName().equals("input")) {
184 conf.setEditorPosition(pos.getContents());
185 } else if (pos.getTagName().equals("list")) {
186 conf.setListPosition(pos.getContents());
187 } else if (pos.getTagName().equals("search")) {
188 conf.setSearchPosition(pos.getContents());
189 } else {
190 System.err.println("unknown subtag of gui/positions with name (" + pos.getTagName() + ")");
191 }
192 }
193 } else {
194 System.err.println("error in unknown editor subtag(" + tag.getTagName() + ")");
195 }
196
197 }
198 } else if (child.getTagName().equals("db")) {
199 Iterator dbTagIter = child.getChildren().iterator();
200 while (dbTagIter.hasNext()) {
201 XMLElement dbTag = (XMLElement) dbTagIter.next();
202 if (dbTag.getTagName().equals("name")) {
203 conf.setName(dbTag.getContents());
204 } else if (dbTag.getTagName().equals("type")) {
205 conf.setType(dbTag.getContents());
206
207 if (dbTag.getProperty("state") != null) {
208 conf.setState(dbTag.getProperty("state"));
209 }
210 if (dbTag.getProperty("size") != null) {
211 conf.setSize(dbTag.getProperty("size"));
212 }
213 if (dbTag.getProperty("key") != null) {
214 conf.setIsKey(Boolean.getBoolean(dbTag.getProperty("key")));
215 }
216 if (dbTag.getProperty("doctype") != null) {
217 conf.setDocType(dbTag.getProperty("doctype"));
218 }
219 if (dbTag.getProperty("notnull") != null) {
220 conf.setIsNotNull(Boolean.getBoolean(dbTag.getProperty("notnull")));
221 }
222 } else {
223 System.err.println("error in unknown db subtag(" + dbTag.getTagName() + ")");
224 }
225 }
226 }
227 }
228 return conf;
229 }
230 }