Mercurial > dive4elements > framework
comparison artifact-database/src/main/java/org/dive4elements/artifactdatabase/DefaultArtifactFactory.java @ 517:863f1fa66981
Simplified code to be more readable.
author | Sascha L. Teichmann <teichmann@intevation.de> |
---|---|
date | Wed, 30 Apr 2014 17:03:10 +0200 |
parents | 69f99bdf3d65 |
children | 3d9d6d61d0c6 |
comparison
equal
deleted
inserted
replaced
516:7bdc45945e5d | 517:863f1fa66981 |
---|---|
25 import org.dive4elements.artifacts.GlobalContext; | 25 import org.dive4elements.artifacts.GlobalContext; |
26 | 26 |
27 import org.apache.log4j.Logger; | 27 import org.apache.log4j.Logger; |
28 | 28 |
29 import org.w3c.dom.Document; | 29 import org.w3c.dom.Document; |
30 import org.w3c.dom.Element; | |
30 import org.w3c.dom.Node; | 31 import org.w3c.dom.Node; |
31 import org.w3c.dom.NodeList; | 32 import org.w3c.dom.NodeList; |
32 | 33 |
33 /** | 34 /** |
34 * Trivial implementation of the ArtifactFactory interface. | 35 * Trivial implementation of the ArtifactFactory interface. |
139 Document data | 140 Document data |
140 ) { | 141 ) { |
141 try { | 142 try { |
142 Artifact artifact = | 143 Artifact artifact = |
143 (Artifact)artifactClass.newInstance(); | 144 (Artifact)artifactClass.newInstance(); |
144 | 145 String oldName = artifact.getName(); |
145 if (artifact.getName() == null || | 146 |
146 artifact.getName().length() == 0) { | 147 if (oldName == null || oldName.length() == 0) { |
147 artifact.setName(artifactName); | 148 artifact.setName(artifactName); |
148 } | 149 } |
149 artifact.setup( | 150 artifact.setup( |
150 identifier, | 151 identifier, |
151 this, | 152 this, |
168 | 169 |
169 return null; | 170 return null; |
170 } | 171 } |
171 | 172 |
172 public void setup(Document document, Node factoryNode) { | 173 public void setup(Document document, Node factoryNode) { |
174 boolean debug = logger.isDebugEnabled(); | |
175 | |
173 String ttlString = Config.getStringXPath(factoryNode, XPATH_TTL); | 176 String ttlString = Config.getStringXPath(factoryNode, XPATH_TTL); |
174 if (ttlString != null) { | 177 if (ttlString != null) { |
175 try { | 178 try { |
176 ttl = Long.valueOf(ttlString); | 179 ttl = Long.valueOf(ttlString); |
177 } | 180 } |
183 description = Config.getStringXPath( | 186 description = Config.getStringXPath( |
184 factoryNode, XPATH_DESCRIPTION, DEFAULT_DESCRIPTION); | 187 factoryNode, XPATH_DESCRIPTION, DEFAULT_DESCRIPTION); |
185 | 188 |
186 name = Config.getStringXPath( | 189 name = Config.getStringXPath( |
187 factoryNode, XPATH_NAME, toString()); | 190 factoryNode, XPATH_NAME, toString()); |
188 logger.debug("setting up " + name); | 191 |
192 if (debug) { | |
193 logger.debug("setting up " + name); | |
194 } | |
189 | 195 |
190 String artifact = Config.getStringXPath( | 196 String artifact = Config.getStringXPath( |
191 factoryNode, XPATH_ARTIFACT, DEFAULT_ARTIFACT); | 197 factoryNode, XPATH_ARTIFACT, DEFAULT_ARTIFACT); |
192 | 198 |
193 artifactName = Config.getStringXPath( | 199 artifactName = Config.getStringXPath( |
194 document, XPATH_ARTIFACT_NAME, "default"); | 200 document, XPATH_ARTIFACT_NAME, "default"); |
195 logger.debug(artifactName); | 201 |
202 if (debug) { | |
203 logger.debug("artifact name: " + artifactName); | |
204 } | |
196 Map<String, String> variables = new HashMap<String, String>(); | 205 Map<String, String> variables = new HashMap<String, String>(); |
197 variables.put("name", name); | 206 variables.put("name", name); |
198 NodeList facets = (NodeList) XMLUtils.xpath( | 207 NodeList facets = (NodeList) XMLUtils.xpath( |
199 document, | 208 document, |
200 XPATH_ARTIFACT_CONFIG, | 209 XPATH_ARTIFACT_CONFIG, |
201 XPathConstants.NODESET, | 210 XPathConstants.NODESET, |
202 null, | 211 null, |
203 variables); | 212 variables); |
204 | 213 |
205 for (int i = 0; i < facets.getLength(); i++) { | 214 for (int i = 0, F = facets.getLength(); i < F; i++) { |
206 logger.debug(facets.item(i).getAttributes().getNamedItem("class").getNodeValue()); | 215 Element element = (Element)facets.item(i); |
207 String className = | 216 String className = element.getAttribute("class"); |
208 facets.item(i).getAttributes().getNamedItem("class").getNodeValue(); | 217 |
218 if (debug) { | |
219 logger.debug("load facet class: " + className); | |
220 } | |
221 | |
209 try { | 222 try { |
210 facetClasses.add(Class.forName(className)); | 223 facetClasses.add(Class.forName(className)); |
211 } | 224 } |
212 catch (ClassNotFoundException cnfe) { | 225 catch (ClassNotFoundException cnfe) { |
213 logger.error(cnfe.getLocalizedMessage(), cnfe); | 226 logger.error(cnfe.getLocalizedMessage(), cnfe); |
214 } | 227 } |
215 } | 228 } |
229 | |
216 try { | 230 try { |
217 artifactClass = Class.forName(artifact); | 231 artifactClass = Class.forName(artifact); |
218 } | 232 } |
219 catch (ClassNotFoundException cnfe) { | 233 catch (ClassNotFoundException cnfe) { |
220 logger.error(cnfe.getLocalizedMessage(), cnfe); | 234 logger.error(cnfe.getLocalizedMessage(), cnfe); |