use of org.whole.lang.models.model.Feature in project whole by wholeplatform.
the class ModelFragmentsBuilderTest method testModelFeaturesBuilderWithFeatureEvents.
@Test
public void testModelFeaturesBuilderWithFeatureEvents() {
ITemplateFactory<Model> modelsModel = new ModelsModelWithFeatureEvents();
Features features = ModelsEntityFactory.instance.createFeatures(0);
modelsModel.apply(new SpecificBuilderAdapterOperation(new ModelFeaturesBuilder(features)));
int count = 0;
Model model = modelsModel.create();
AbstractPatternFilterIterator<Feature> i = IteratorFactory.<Feature>descendantOrSelfMatcherIterator().withPattern(ModelsEntityDescriptorEnum.Feature);
i.reset(model);
for (Feature feature : i) if (EntityUtils.isNotResolver(feature))
count++;
assertEquals(features.wSize(), count);
}
use of org.whole.lang.models.model.Feature in project whole by wholeplatform.
the class ModelFragmentsBuilderTest method testModelFeaturesBuilder.
@Test
public void testModelFeaturesBuilder() {
ITemplateFactory<Model> modelsModel = new ModelsModel();
final Features features = ModelsEntityFactory.instance.createFeatures(0);
modelsModel.apply(new SpecificBuilderAdapterOperation(new ModelFeaturesBuilder(features)));
int count = 0;
Model model = modelsModel.create();
AbstractPatternFilterIterator<Feature> i = IteratorFactory.<Feature>descendantOrSelfMatcherIterator().withPattern(ModelsEntityDescriptorEnum.Feature);
i.reset(model);
for (Feature feature : i) if (EntityUtils.isNotResolver(feature))
count++;
assertEquals(features.wSize(), count);
}
use of org.whole.lang.models.model.Feature in project whole by wholeplatform.
the class ModelInfo method addInheritedFeatures.
protected void addInheritedFeatures(SimpleEntity entity, Types types, Set<String> entityTypes, Map<String, Set<String>> entityFeatures) {
ScannerIterator<IEntity> i = IteratorFactory.childReverseScannerIterator();
i.reset(types);
for (IEntity type : i) {
String typeName = type.wStringValue();
entityTypes.remove(typeName);
SimpleEntity declaration = (SimpleEntity) nameEntityMap.get(typeName);
if (declaration != null) {
ScannerIterator<Feature> i2 = IteratorFactory.<Feature>childReverseScannerIterator();
i2.reset(declaration.getFeatures());
for (Feature feature : i2) {
if (entityFeatures.get(entity.getName().wStringValue()).add(feature.getName().wStringValue()))
entity.getFeatures().wAdd(0, EntityUtils.clone(feature));
}
addInheritedFeatures(entity, declaration.getTypes(), entityTypes, entityFeatures);
}
}
}
use of org.whole.lang.models.model.Feature in project whole by wholeplatform.
the class ModelInfo method sortFeatures.
public void sortFeatures(Model model) {
for (String entityName : simpleEntityTypes) {
SimpleEntity e = (SimpleEntity) nameEntityMap.get(entityName);
Features features = e.getFeatures();
Collections.sort(features, new Comparator<Feature>() {
public int compare(Feature f1, Feature f2) {
boolean f1IsReference = f1.getModifiers().wContainsValue(FeatureModifierEnum.reference);
boolean f2IsReference = f2.getModifiers().wContainsValue(FeatureModifierEnum.reference);
if (f2IsReference)
return f1IsReference ? 0 : -1;
else
return !f1IsReference ? 0 : +1;
}
});
}
}
use of org.whole.lang.models.model.Feature in project whole by wholeplatform.
the class ControlQueriesTest method testChoose2.
@Test
public void testChoose2() {
Model model = new ModelsModel().create();
ModelDeclarations decls = model.getDeclarations();
ITemplateManager tm = ControlQueriesTemplateManager.instance();
PathExpression query = (PathExpression) tm.create("choose2");
int i = 0;
IEntityIterator<IEntity> iterator = BehaviorUtils.compileAndLazyEvaluate(query, model);
while (iterator.hasNext()) {
IEntity result;
IEntity decl = decls.wGet(i++);
switch(decl.wGetEntityOrd()) {
case ModelsEntityDescriptorEnum.SimpleEntity_ord:
IEntity features = ((SimpleEntity) decl).getFeatures();
for (int j = 0; j < features.wSize(); j++) {
result = iterator.next();
assertEquals(((Feature) features.wGet(j)).getName().wStringValue(), result.wStringValue());
}
break;
case ModelsEntityDescriptorEnum.CompositeEntity_ord:
result = iterator.next();
CompositeEntity compositeEntity = (CompositeEntity) decl;
assertEquals(compositeEntity.getComponentType().wStringValue(), result.wStringValue());
break;
case ModelsEntityDescriptorEnum.DataEntity_ord:
result = iterator.next();
DataEntity dataEntity = (DataEntity) decl;
assertEquals(dataEntity.getDataType().wStringValue(), result.wStringValue());
break;
case ModelsEntityDescriptorEnum.EnumEntity_ord:
EnumValues enumValues = ((EnumEntity) decl).getValues();
if (enumValues.wIsEmpty())
iterator.next();
else
for (int j = 0; j < enumValues.wSize(); j++) {
result = iterator.next();
assertEquals(enumValues.wGet(j).wStringValue(), result.wStringValue());
}
break;
}
}
}
Aggregations