dol: initial dol commit
[jump.git] / dol / src / dol / helper / flattener / MappingFlattener.java
1 /* $Id: MappingFlattener.java 1 2010-02-24 13:03:05Z haidw $ */
2 package dol.helper.flattener;
3
4 import java.util.List;
5
6 import org.jdom.Element;
7
8 /**
9  *
10  */
11 public class MappingFlattener extends FlattenerHelper {
12
13     /**
14      * Constructor.
15      *
16      * @param classname class name of the generated class
17      */
18     public MappingFlattener(String classname) {
19         super(classname);
20     }
21
22     public String processElement(Element element)
23         throws RuntimeException {
24
25         String string = "";
26
27         if (element.getName().equalsIgnoreCase("binding")) {
28             _generateElement = false;
29             string = generateBinding(element);
30         }
31         else if (element.getName().equalsIgnoreCase("path")) {
32             _generateElement = false;
33             string = generatePath(element);
34         }
35         else if (element.getName().equalsIgnoreCase("schedule")) {
36             _generateElement = false;
37             string = generateSchedule(element);
38         }
39
40         return string;
41     }
42
43     /**
44      * 
45      */
46     @SuppressWarnings("unchecked")
47     protected String generatePath(Element element) {
48         String attributes[] = {"name"};
49         String sourceCode = generateElement(element, attributes, false);
50
51         //add origin and target elements
52         for (Element childElement : (List<Element>)element.getChildren()) {
53             if (childElement.getName().equalsIgnoreCase("origin")
54                 || childElement.getName().equalsIgnoreCase("target")) {
55                 sourceCode += generateOriginOrTarget(childElement);
56             }
57             else if (childElement.getName().equalsIgnoreCase("resource")) {
58                 String rAttributes[] = {"name"};
59                 increaseXmlIndent();
60                 sourceCode += generateElement(childElement,rAttributes, false);
61                 sourceCode += _indent +
62                     "System.out.println(\"" + _xmlIndent + "</resource>\");\n";
63                 decreaseXmlIndent();
64             }
65             else if (childElement.getName().equalsIgnoreCase("buffer")) {
66                 String bAttributes[] = {"name"};
67                 increaseXmlIndent();
68                 sourceCode += generateElement(childElement,bAttributes, false);
69                 sourceCode += _indent +
70                     "System.out.println(\"" + _xmlIndent + "</buffer>\");\n";
71                 decreaseXmlIndent();
72             }
73         }
74         sourceCode += _indent + "System.out.println(\"</path>\");\n";
75         return sourceCode;
76     }
77
78     /**
79      * 
80      */
81     @SuppressWarnings("unchecked")
82     protected String generateSchedule(Element element) {
83         String attributes[] = {"name", "type"};
84         String sourceCode = generateElement(element, attributes, false);
85
86         //add origin and target elements
87         
88         for (Element childElement : (List<Element>)element.getChildren()) {
89             if (childElement.getName().equalsIgnoreCase("origin")) {
90                 sourceCode += generateOriginOrTarget(childElement);
91             }
92             else if (childElement.getName().equalsIgnoreCase("resource")) {
93                 String rAttributes[] = {"name"};
94                 increaseXmlIndent();
95                 sourceCode += generateElement(childElement,rAttributes, false);
96                 sourceCode += _indent +
97                     "System.out.println(\"" + _xmlIndent + "</resource>\");\n";
98                 decreaseXmlIndent();
99             }
100         }
101         sourceCode += _indent + "System.out.println(\"</schedule>\");\n";
102         return sourceCode;
103     }
104     
105     /**
106      * 
107      */
108     @SuppressWarnings("unchecked")
109     protected String generateBinding(Element element) {
110         String attributes[] = {"name", "type"};
111         String sourceCode = generateElement(element, attributes, false);
112
113         //add origin and target elements
114         for (Element childElement : (List<Element>)element.getChildren()) {
115             if (childElement.getName().equalsIgnoreCase("origin")
116                 || childElement.getName().equalsIgnoreCase("target")) {
117                 sourceCode += generateOriginOrTarget(childElement);
118             }
119         }
120         sourceCode += _indent + "System.out.println(\"</binding>\");\n";
121         return sourceCode;
122     }
123
124     /**
125      * 
126      */
127     @SuppressWarnings("unchecked")
128     protected String generateOriginOrTarget(Element element) {
129         String attributes[] = {"name"};
130         increaseXmlIndent();
131         String sourceCode = generateElement(element, attributes, false);
132
133         //add configuration elements
134         for (Element childElement : (List<Element>)element.getChildren()) {
135             if (childElement.getName().equalsIgnoreCase(_xt.getConfigurationTag())) {
136                 sourceCode += generateConfiguration(childElement);
137             }
138         }
139
140         sourceCode += _indent + "System.out.println(\"" + _xmlIndent + "</"
141             + element.getName() + ">\");\n";
142         decreaseXmlIndent();
143         
144         return sourceCode;
145     }
146
147     protected String generateConfiguration(Element element) {
148         String attributes[] = {"name", "value"};
149         increaseXmlIndent();
150         String sourceCode = generateElement(element, attributes, true);
151         decreaseXmlIndent();
152         return sourceCode;
153     }
154
155
156 }