1
2
3
4
5
6
7
8
9
10
11
12
13 package org.abstracthorizon.extend.support.spring.deployment;
14
15 import java.util.ArrayList;
16 import java.util.List;
17
18 import org.springframework.beans.factory.BeanDefinitionStoreException;
19 import org.springframework.beans.factory.support.BeanDefinitionReader;
20 import org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader;
21 import org.w3c.dom.Element;
22 import org.w3c.dom.Node;
23
24
25
26
27
28
29 public class ApplicationContextModuleXmlParser extends DefaultBeanDefinitionDocumentReader {
30
31 public static final String DEPENDS_ON_TAG = "depends-on";
32
33
34 protected AbstractApplicationContextModule context;
35
36
37
38
39 public ApplicationContextModuleXmlParser() {
40 }
41
42
43
44
45
46
47
48
49 protected void preProcessXml(Element root) throws BeanDefinitionStoreException {
50 List<Dependency> dependencies = new ArrayList<Dependency>();
51 List<Node> nodes = new ArrayList<Node>();
52 Node node = root.getFirstChild();
53 while (node != null) {
54 if (DEPENDS_ON_TAG.equals(node.getNodeName())) {
55 int type = node.getNodeType();
56 if (type == Node.ELEMENT_NODE) {
57 Node c = node.getFirstChild();
58 while ((c != null) && (c.getNodeType() != Node.TEXT_NODE)) {
59 c = c.getNextSibling();
60 }
61 if (c != null) {
62
63 String value = node.getFirstChild().getNodeValue();
64 Dependency dependency = new Dependency();
65 dependency.setValue(value);
66 dependencies.add(dependency);
67 }
68 }
69 nodes.add(node);
70 }
71 node = node.getNextSibling();
72 }
73 for (Node n : nodes) {
74 root.removeChild(n);
75 }
76 BeanDefinitionReader reader = getReaderContext().getReader();
77
78 AbstractApplicationContextModule context = (AbstractApplicationContextModule)reader.getResourceLoader();
79 if (!context.processDependencies(dependencies)) {
80
81
82 ArrayList<Node> ns = new ArrayList<Node>();
83 Node nn = root.getFirstChild();
84 while (nn != null) {
85 ns.add(nn);
86 nn = nn.getNextSibling();
87 }
88 for (Node n : ns) {
89 root.removeChild(n);
90 }
91 }
92 }
93
94
95
96
97
98
99 protected String getValue(Node node) {
100 Node c = node.getFirstChild();
101 while ((c != null) && (c.getNodeType() != Node.TEXT_NODE)) {
102 c = c.getNextSibling();
103 }
104 if (c != null) {
105 String value = node.getFirstChild().getNodeValue();
106 if (value.length() > 0) {
107 return value;
108 }
109 }
110 return null;
111 }
112
113 }