-
Notifications
You must be signed in to change notification settings - Fork 5
/
PersistentApplication.java
43 lines (34 loc) · 1.39 KB
/
PersistentApplication.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
package org.genericsystem.reactor.appserver;
import java.lang.reflect.InvocationTargetException;
import org.genericsystem.common.AbstractRoot;
import org.genericsystem.reactor.Model;
import org.genericsystem.reactor.Tag;
import org.genericsystem.reactor.html.HtmlApp;
import io.vertx.core.http.ServerWebSocket;
public class PersistentApplication {
private final Class<? extends HtmlApp<?>> htmlAppClass;
private final AbstractRoot engine;
private final Class<? extends Model> modelClass;
public PersistentApplication(Class<? extends HtmlApp<?>> htmlAppClass, Class<? extends Model> modelClass, AbstractRoot engine) {
this.htmlAppClass = htmlAppClass;
this.modelClass = modelClass;
this.engine = engine;
}
public AbstractRoot getEngine() {
return engine;
}
public Class<? extends HtmlApp<?>> getApplicationClass() {
return htmlAppClass;
}
public void close() {
engine.close();
}
@SuppressWarnings("unchecked")
public Tag<?> newHtmlApp(ServerWebSocket socket) {
try {
return ((HtmlApp<Model>) getApplicationClass().getConstructor(AbstractRoot.class, ServerWebSocket.class).newInstance(getEngine(), socket)).init(modelClass.getConstructor(AbstractRoot.class).newInstance(engine));
} catch (InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException | NoSuchMethodException | SecurityException e) {
throw new IllegalStateException(e);
}
}
}