Skip to content

Commit

Permalink
gs-reactor: Start saving tags in Generic System on app loading
Browse files Browse the repository at this point in the history
Works only if the tags have not been stored already. Crashes if the application
tries to read already stored tags at startup.
The styles are stored as well, but are not read from GS.
  • Loading branch information
fducroquet committed Nov 10, 2016
1 parent 719dbf9 commit 90fe863
Show file tree
Hide file tree
Showing 16 changed files with 188 additions and 89 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

import java.io.Serializable;

import org.genericsystem.api.core.IGeneric.SystemProperty;

/**
* Represents the <code>Class</code> for an axed property.
*
Expand All @@ -13,7 +11,7 @@
public class AxedPropertyClass implements Serializable {
private static final long serialVersionUID = -2631066712866842794L;

private final Class<? extends SystemProperty> clazz;
private final Class<?> clazz;
private final int axe;

/**
Expand All @@ -24,7 +22,7 @@ public class AxedPropertyClass implements Serializable {
* @param axe
* the position of the <code>SystemProperty</code>.
*/
public AxedPropertyClass(Class<? extends SystemProperty> clazz, int axe) {
public AxedPropertyClass(Class<?> clazz, int axe) {
this.clazz = clazz;
this.axe = axe;
}
Expand All @@ -34,7 +32,7 @@ public AxedPropertyClass(Class<? extends SystemProperty> clazz, int axe) {
*
* @return the <code>Class</code> of the <code>SystemProperty</code>.
*/
public Class<? extends SystemProperty> getClazz() {
public Class<?> getClazz() {
return clazz;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
* The System Property to constrain the type of a value.
*
* @author Nicolas Feybesse
* @author Michael Ory
*/
@Retention(RetentionPolicy.RUNTIME)
@Target({ ElementType.TYPE })
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package org.genericsystem.api.core.annotations.constraints;

import java.lang.annotation.ElementType;
import java.lang.annotation.Inherited;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

/**
* The System Property to constrain the type of a value.
*
* @author Nicolas Feybesse
*/
@Retention(RetentionPolicy.RUNTIME)
@Target({ ElementType.TYPE })
@Inherited
public @interface NoInheritance {
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import org.genericsystem.api.core.annotations.Meta;
import org.genericsystem.api.core.annotations.constraints.InstanceValueClassConstraint;
import org.genericsystem.api.core.annotations.constraints.InstanceValueGenerator;
import org.genericsystem.api.core.annotations.constraints.NoInheritance;
import org.genericsystem.api.core.annotations.constraints.NoReferentialIntegrityProperty;
import org.genericsystem.api.core.annotations.constraints.PropertyConstraint;
import org.genericsystem.api.core.annotations.constraints.RequiredConstraint;
Expand Down Expand Up @@ -119,6 +120,9 @@ void mountConstraints(Class<?> clazz, Generic result) {
if (clazz.getAnnotation(InstanceValueClassConstraint.class) != null)
result.setInstanceValueClassConstraint(clazz.getAnnotation(InstanceValueClassConstraint.class).value());

if (clazz.getAnnotation(NoInheritance.class) != null)
result.disableInheritance();

if (clazz.getAnnotation(InstanceValueGenerator.class) != null)
result.setInstanceValueGenerator(clazz.getAnnotation(InstanceValueGenerator.class).value());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@ default RootTag getRootTag() {

AnnotationsManager getAnnotationsManager();

TagNode buildTagNode(Tag parent);
TagNode buildTagNode(Tag child);
}
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,6 @@ default HtmlDomNode createNode(HtmlDomNode parent, Context modelContext) {
default void init() {
}

@Override
public <COMPONENT extends Tag> COMPONENT getParent();

default RootTag getRootTag() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@

public interface TagNode {

public <COMPONENT extends Tag> COMPONENT getParent();

public ObservableList<Tag> getObservableChildren();

}
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,13 @@
import java.lang.annotation.Target;
import java.util.function.BiConsumer;

import org.genericsystem.api.core.AxedPropertyClass;
import org.genericsystem.reactor.Tag;
import org.genericsystem.reactor.annotations.Children.ChildrenMult;
import org.genericsystem.reactor.annotations.Children.ChildrenProcessor;
import org.genericsystem.reactor.gscomponents.ExtendedRootTag;
import org.genericsystem.reactor.gscomponents.ExtendedRootTag.GTag;
import org.genericsystem.reactor.gscomponents.ExtendedRootTag.GenericTagNode;
import org.genericsystem.reactor.gscomponents.TagImpl;

/**
Expand Down Expand Up @@ -38,16 +42,27 @@ public static class ChildrenProcessor implements BiConsumer<Annotation, Tag> {

@Override
public void accept(Annotation annotation, Tag tag) {
for (Class<? extends TagImpl> clazz : ((Children) annotation).value()) {
TagImpl result = null;
try {
result = clazz.newInstance();
} catch (IllegalAccessException | InstantiationException e) {
throw new IllegalStateException(e);
if (ExtendedRootTag.class.isAssignableFrom(tag.getRootTag().getClass())) {
GTag delegate = ((GenericTagNode) ((TagImpl) tag).getTagNode()).getDelegateGeneric();
Class<? extends TagImpl>[] classes = ((Children) annotation).value();
for (int i = 0; i < classes.length; i++) {
// System.out.println("Parent: " + delegate + ", adding child to GS: " + classes[i]);
delegate.getMeta().setInstance(delegate, new AxedPropertyClass(classes[i], i));// Aie! , marchera pas, comment distinguer les signatures des generics ???
}
} else {
for (Class<? extends TagImpl> clazz : ((Children) annotation).value()) {
TagImpl result = null;
try {
result = clazz.newInstance();
} catch (IllegalAccessException | InstantiationException e) {
throw new IllegalStateException(e);
}
result.setParent(tag);
result.setTagNode(tag.getRootTag().buildTagNode(result));
tag.getObservableChildren().add(result);
tag.getRootTag().getAnnotationsManager().processAnnotations(result);
result.init();
}
result.setParent(tag);
tag.getRootTag().getAnnotationsManager().processAnnotations(result);
result.init();
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
import org.genericsystem.reactor.annotations.Style.Styles;
import org.genericsystem.reactor.gscomponents.ExtendedRootTag;
import org.genericsystem.reactor.gscomponents.ExtendedRootTag.GTag;
import org.genericsystem.reactor.gscomponents.ExtendedRootTag.GTagType.GTagStyleType;
import org.genericsystem.reactor.gscomponents.ExtendedRootTag.GTagType.StyleName;
import org.genericsystem.reactor.gscomponents.ExtendedRootTag.GTagType.StyleValue;
import org.genericsystem.reactor.gscomponents.ExtendedRootTag.GenericTagNode;
import org.genericsystem.reactor.gscomponents.FlexDirection;
Expand Down Expand Up @@ -55,14 +55,21 @@

public static class StyleProcessor implements BiConsumer<Annotation, Tag> {

static long styleTime;
static int stylesNumber = 0;

@Override
public void accept(Annotation annotation, Tag tag) {
tag.addStyle(((Style) annotation).name(), ((Style) annotation).value());
if (ExtendedRootTag.class.isAssignableFrom(tag.getRootTag().getClass())) {
GTag delegate = ((GenericTagNode) ((TagImpl) tag).getTagNode()).getDelegateGeneric();
Generic style = delegate.setHolder(delegate.getRoot().find(GTagStyleType.class), ((Style) annotation).name());
// long startTime = System.currentTimeMillis();
Generic style = delegate.setHolder(delegate.getRoot().find(StyleName.class), ((Style) annotation).name());
style.setHolder(delegate.getRoot().find(StyleValue.class), ((Style) annotation).value());
// long endTime = System.currentTimeMillis();
// styleTime += endTime - startTime;
// System.out.println("Style, temps passé : " + (endTime - startTime) + ", temps total : " + styleTime + ", nombre de styles : " + (++stylesNumber) + ", temps par style : " + (styleTime / stylesNumber));
}
tag.addStyle(((Style) annotation).name(), ((Style) annotation).value());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

public class PersistentApplication {
private final Class<? extends RootTag> htmlAppClass;
private final RootTag tagTree;
private RootTag tagTree;
private final Root engine;
private final Class<Context> modelClass;
private final String rootId;
Expand All @@ -42,7 +42,13 @@ public PersistentApplication(Class<? extends RootTag> htmlAppClass, Class<Contex
try {
tagTree = getApplicationClass().newInstance();
} catch (InstantiationException | IllegalAccessException | IllegalArgumentException | SecurityException e) {
throw new IllegalStateException(e);
try {
engine.newCache().start();
tagTree = getApplicationClass().getConstructor(Root.class).newInstance(engine);
engine.getCurrentCache().flush();
} catch (InstantiationException | IllegalAccessException | IllegalArgumentException | SecurityException | InvocationTargetException | NoSuchMethodException ex) {
throw new IllegalStateException(ex);
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,28 @@
public abstract class AbstractTag implements Tag {

protected TagNode tagNode;
private Tag parent;

public TagNode getTagNode() {
return tagNode;
}

public void setTagNode(TagNode tagNode) {
this.tagNode = tagNode;
}

public void setParent(Tag parent) {
tagNode = parent.getRootTag().buildTagNode(parent);
this.parent = parent;
}

@Override
public ObservableList<Tag> getObservableChildren() {
// System.out.println("getObservableChildren on " + this);
return getTagNode().getObservableChildren();
}

@Override
public <COMPONENT extends Tag> COMPONENT getParent() {
return getTagNode().getParent();
return (COMPONENT) parent;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,8 @@
import org.genericsystem.reactor.gscomponents.HtmlTag.HtmlLabel.GSLabelDisplayer;

@Style(name = "flex", value = "1 1 0%")

@Style(path = FlexDiv.class, name = "flex", value = "1 1 0%")

@Style(path = FlexDiv.class, name = "overflow", value = "auto")
@Children({ Composite.Content.class })
@Children(path = Content.class, value = GSLabelDisplayer.class)
@Children(path = Header.class, value = GSLabelDisplayer.class)
Expand Down
Loading

0 comments on commit 90fe863

Please sign in to comment.