-
Notifications
You must be signed in to change notification settings - Fork 5
/
RootTagImpl.java
150 lines (138 loc) · 5.4 KB
/
RootTagImpl.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
package org.genericsystem.reactor;
import java.util.Arrays;
import java.util.HashMap;
import java.util.LinkedHashMap;
import org.genericsystem.reactor.annotations.DirectSelect;
import org.genericsystem.reactor.annotations.ForEach;
import org.genericsystem.reactor.annotations.Parent;
import org.genericsystem.reactor.annotations.ReactorDependencies;
import org.genericsystem.reactor.annotations.Select;
import org.genericsystem.reactor.annotations.Style;
import org.genericsystem.reactor.annotations.Style.AlignItems;
import org.genericsystem.reactor.annotations.Style.BackgroundColor;
import org.genericsystem.reactor.annotations.Style.Color;
import org.genericsystem.reactor.annotations.Style.Flex;
import org.genericsystem.reactor.annotations.Style.FlexDirection;
import org.genericsystem.reactor.annotations.Style.FlexWrap;
import org.genericsystem.reactor.annotations.Style.JustifyContent;
import org.genericsystem.reactor.annotations.Style.Overflow;
import org.genericsystem.reactor.gs.GSDiv;
public class RootTagImpl extends GSDiv implements Tag {
private final HashMap<Class<? extends TagImpl>, TagImpl> nodes = new LinkedHashMap<Class<? extends TagImpl>, TagImpl>() {
private static final long serialVersionUID = -6835018021862236920L;
@Override
public TagImpl get(Object key) {
Class<? extends TagImpl> searchClass = (Class<? extends TagImpl>) key;
TagImpl tag = super.get(searchClass);
if (tag == null)
for (Class<? extends TagImpl> clazz : keySet()) {
if (searchClass.isAssignableFrom(clazz)) {
tag = super.get(clazz);
break;
}
}
return tag;
};
};
public RootTagImpl() {
super();
nodes.put(getClass(), this);
ReactorDependencies deps = getClass().getAnnotation(ReactorDependencies.class);
if (deps != null) {
System.out.println("Declaring classes : " + Arrays.toString(getClass().getDeclaredClasses()));
System.out.println("ReactorDependencies : " + Arrays.toString(deps.value()));
for (Class<? extends TagImpl> clazz : deps.value())
find(clazz);
}
for (Tag tag : nodes.values())
tag.postfix();
}
public RootTagImpl(Tag parent) {
super(parent);
init();
style();
nodes.put(getClass(), this);
ReactorDependencies deps = getClass().getAnnotation(ReactorDependencies.class);
if (deps != null)
for (Class<? extends TagImpl> clazz : deps.value())
find(clazz);
for (Tag tag : nodes.values())
tag.postfix();
}
public Class<? extends TagImpl> getParentTagClass(Class<? extends TagImpl> tagClass) {
Parent parent = tagClass.getAnnotation(Parent.class);
if (parent != null)
return parent.value();
Class<? extends TagImpl> enclosing = (Class<? extends TagImpl>) tagClass.getEnclosingClass();
if (enclosing != null && !enclosing.isAssignableFrom(tagClass))
return enclosing;
return null;
}
@Override
public TagImpl find(Class<? extends TagImpl> tagClass) {
TagImpl result = nodes.get(tagClass);
if (result == null) {
try {
result = tagClass.newInstance();
} catch (IllegalAccessException | InstantiationException e) {
throw new IllegalStateException();
}
Class<? extends TagImpl> parentClass = getParentTagClass(tagClass);
System.out.println(tagClass + " " + parentClass + " on " + getClass());
if (parentClass == null || parentClass.isAssignableFrom(getClass()))
result.setParent(this);
else
result.setParent(find(parentClass));
ForEach forEach = tagClass.getAnnotation(ForEach.class);
if (forEach != null) {
try {
result.forEach(forEach.value().newInstance().get());
} catch (InstantiationException | IllegalAccessException e) {
throw new IllegalStateException(e);
}
}
Select select = tagClass.getAnnotation(Select.class);
if (select != null) {
try {
result.select(select.value().newInstance().get());
} catch (InstantiationException | IllegalAccessException e) {
throw new IllegalStateException(e);
}
}
DirectSelect directSelect = tagClass.getAnnotation(DirectSelect.class);
if (directSelect != null)
result.select(directSelect.value());
BackgroundColor backgroundColor = tagClass.getAnnotation(BackgroundColor.class);
if (backgroundColor != null)
result.addStyle("background-color", backgroundColor.value());
FlexDirection flexDirection = tagClass.getAnnotation(FlexDirection.class);
if (flexDirection != null)
result.addStyle("flex-direction", flexDirection.value());
FlexWrap flexWrap = tagClass.getAnnotation(FlexWrap.class);
if (flexWrap != null)
result.addStyle("flex-wrap", flexWrap.value());
Flex flex = tagClass.getAnnotation(Flex.class);
if (flex != null)
result.addStyle("flex", flex.value());
AlignItems alignItems = tagClass.getAnnotation(AlignItems.class);
if (alignItems != null)
result.addStyle("align-items", alignItems.value());
JustifyContent justifyContent = tagClass.getAnnotation(JustifyContent.class);
if (justifyContent != null)
result.addStyle("justify-content", justifyContent.value());
Overflow overlflow = tagClass.getAnnotation(Overflow.class);
if (overlflow != null)
result.addStyle("overflow", overlflow.value());
Color color = tagClass.getAnnotation(Color.class);
if (color != null)
result.addStyle("color", color.value());
Style style = tagClass.getAnnotation(Style.class);
if (style != null)
result.addStyle(style.propertyName(), style.propertyValue());
result.init();
result.style();
nodes.put(tagClass, result);
}
return result;
}
}