Search in sources :

Example 1 with IEntityFactory

use of org.whole.lang.factories.IEntityFactory in project whole by wholeplatform.

the class ArtifactsUtils method cloneArtifact.

public static IEntity cloneArtifact(IEntity artifact, IEntity appendChild) {
    IEntityFactory ef = GenericEntityFactory.instance(RegistryConfigurations.RESOLVER);
    EntityDescriptor<?> ed = artifact.wGetEntityDescriptor();
    IEntity newArtifact = ef.create(ed);
    for (FeatureDescriptor fd : ed.getEntityFeatureDescriptors()) {
        if (artifacts.equals(fd) || projects.equals(fd)) {
            IEntity composite = newArtifact.wGet(fd);
            if (appendChild != null)
                composite.wAdd(appendChild);
            else
                composite.wResolveWith(fd.getEntityDescriptor());
        } else
            newArtifact.wSet(fd, EntityUtils.clone(artifact.wGet(fd)));
    }
    return newArtifact;
}
Also used : IEntity(org.whole.lang.model.IEntity) FeatureDescriptor(org.whole.lang.reflect.FeatureDescriptor) IEntityFactory(org.whole.lang.factories.IEntityFactory)

Example 2 with IEntityFactory

use of org.whole.lang.factories.IEntityFactory in project whole by wholeplatform.

the class BindingManagerFactory method createFlatBindingsModel.

public IEntity createFlatBindingsModel(IBindingManager bm) {
    IEntityFactory ef = GenericEntityFactory.instance;
    IEntity bindings = ef.create(getEdEnum().valueOf("Bindings"));
    Set<String> names = bm.wNames();
    for (String name : new TreeSet<String>(names)) bindings.wAdd(createBinding(name, bm.wGet(name)));
    return bindings;
}
Also used : IEntity(org.whole.lang.model.IEntity) IEntityFactory(org.whole.lang.factories.IEntityFactory) TreeSet(java.util.TreeSet)

Example 3 with IEntityFactory

use of org.whole.lang.factories.IEntityFactory in project whole by wholeplatform.

the class BindingManagerFactory method createFlatScopedBindingsModel.

public IEntity createFlatScopedBindingsModel(IBindingManager bm) {
    IEntityFactory ef = GenericEntityFactory.instance;
    IEntity scopedBindings = ef.create(getEdEnum().valueOf("ScopedBindings"));
    IBindingScope scope = bm;
    Map<String, IEntity> bindingsMap = new TreeMap<String, IEntity>();
    do {
        for (String name : scope.wLocalNames()) {
            IEntity value = scope.wGet(name);
            if (value == null)
                continue;
            if (!bindingsMap.containsKey(name))
                bindingsMap.put(name, value);
        }
        IEntity sourceEntity = scope.getSourceEntity();
        if (sourceEntity != null || scope.wEnclosingScope() == NullScope.instance) {
            int i = 0;
            for (Map.Entry<String, IEntity> entry : bindingsMap.entrySet()) scopedBindings.wAdd(i++, createBinding(entry.getKey(), entry.getValue()));
            bindingsMap.clear();
            scopedBindings.wAdd(0, ef.create(getEdEnum().valueOf("Scope"), ef.create(getEdEnum().valueOf("BindingScope"), (Object) scope), ef.create(getEdEnum().valueOf("Value"), (Object) scope.getSourceEntity())));
        }
    } while ((scope = scope.wEnclosingScope()) != NullScope.instance);
    return scopedBindings;
}
Also used : IEntity(org.whole.lang.model.IEntity) IEntityFactory(org.whole.lang.factories.IEntityFactory) TreeMap(java.util.TreeMap) Map(java.util.Map) TreeMap(java.util.TreeMap)

Example 4 with IEntityFactory

use of org.whole.lang.factories.IEntityFactory in project whole by wholeplatform.

the class DynamicModelDefinitionTest method testLanguageKitDefinition.

@Test
public void testLanguageKitDefinition() {
    DynamicLanguageKit lk = new DynamicLanguageKit();
    lk.setURI("http://lang.whole.org/DynamicImpl");
    lk.setNamespace("org.whole.lang.reflect");
    lk.setName("DynamicImp");
    FeatureDescriptorEnum fds = lk.getFeatureDescriptorEnum();
    fds.addFeatureDescriptors("value", "type", "name", "parameters", "body", "initializer", "exp", "exp1", "exp2", "condition", "trueBody", "falseBody", "arguments", "updater");
    EntityDescriptorEnum eds = lk.getEntityDescriptorEnum();
    final EntityDescriptor<?> ExpressionDesc = eds.addSimpleEntity("Expression", "Expression", true);
    final EntityDescriptor<?> StatementDesc = eds.addSimpleEntity("Statement", "Statement", true);
    EntityDescriptor<?> bs = eds.addCompositeEntity("BlockStatement", "BlockStatement", false, true, false);
    bs.withFeature(CommonsFeatureDescriptorEnum.composite_element, StatementDesc.getOrdinal());
    EntityDescriptor<?> ifs = eds.addSimpleEntity("IfStatement", "IfStatement", false).withFeature(fds.valueOf("condition"), ExpressionDesc.getOrdinal()).withFeature(fds.valueOf("trueBody"), StatementDesc.getOrdinal());
    EntityDescriptor<?> ifes = eds.addSimpleEntity("IfElseStatement", "IfElseStatement", false).withFeature(fds.valueOf("condition"), ExpressionDesc.getOrdinal()).withFeature(fds.valueOf("trueBody"), StatementDesc.getOrdinal()).withFeature(fds.valueOf("falseBody"), StatementDesc.getOrdinal());
    EntityDescriptor<?> ws = eds.addSimpleEntity("WhileStatement", "WhileStatement", false).withFeature(fds.valueOf("condition"), ExpressionDesc.getOrdinal()).withFeature(fds.valueOf("body"), StatementDesc.getOrdinal());
    EntityDescriptor<?> es = eds.addSimpleEntity("ExpressionStatement", "ExpressionStatement", false).withFeature(fds.valueOf("exp"), ExpressionDesc.getOrdinal());
    StatementDesc.setLanguageSubtypes(true, bs.getOrdinal(), ifs.getOrdinal(), ifes.getOrdinal(), ws.getOrdinal(), es.getOrdinal());
    final EntityDescriptor<?> LiteralDesc = eds.addSimpleEntity("Literal", "Literal", true);
    LiteralDesc.setLanguageSubtypes(true, eds.addDataEntity("BooleanLiteral", "BooleanLiteral", false, Boolean.TYPE).getOrdinal(), eds.addDataEntity("IntLiteral", "IntLiteral", false, Integer.TYPE).getOrdinal(), eds.addDataEntity("StringLiteral", "StringLiteral", false, String.class).getOrdinal());
    EntityDescriptor<?> ne = eds.addDataEntity("Name", "Name", false, String.class);
    eds.addSimpleEntity("AssignmentExpression", "AssignmentExpression", false).withFeature(fds.valueOf("name"), ne.getOrdinal()).withFeature(fds.valueOf("exp"), ExpressionDesc.getOrdinal());
    for (String edName : new String[] { "And", "Or", "Addition", "Division", "Multiplication", "Remainder", "Subtraction", "Equals", "GreaterOrEquals", "GreaterThan", "LessOrEquals", "LessThan", "NotEquals" }) {
        eds.addSimpleEntity(edName, edName, false).withFeature(fds.valueOf("exp1"), ExpressionDesc.getOrdinal()).withFeature(fds.valueOf("exp1"), ExpressionDesc.getOrdinal());
    }
    // TODO configure entity registry
    ReflectionFactory.deploy(DynamicLanguageKit.getDeployer(lk));
    assertEquals(lk, ReflectionFactory.getLanguageKit(lk.getURI()));
    IEntityFactory ef = GenericEntityFactory.instance;
    IEntity p = ef.create(eds.valueOf("WhileStatement"), ef.create(eds.valueOf("GreaterThan"), ef.create(eds.valueOf("Name"), "n"), ef.create(eds.valueOf("IntLiteral"), 0)), ef.create(eds.valueOf("ExpressionStatement"), ef.create(eds.valueOf("AssignmentExpression"), ef.create(eds.valueOf("Name"), "n"), ef.create(eds.valueOf("Subtraction"), ef.create(eds.valueOf("Name"), "n"), ef.create(eds.valueOf("IntLiteral"), 1)))));
    assertEquals(lk, p.wGetLanguageKit());
}
Also used : CommonsFeatureDescriptorEnum(org.whole.lang.commons.reflect.CommonsFeatureDescriptorEnum) IEntity(org.whole.lang.model.IEntity) IEntityFactory(org.whole.lang.factories.IEntityFactory) Test(org.junit.Test)

Example 5 with IEntityFactory

use of org.whole.lang.factories.IEntityFactory in project whole by wholeplatform.

the class DynamicModelDefinitionTest method testTupleDefinition.

@Test
public void testTupleDefinition() {
    DynamicLanguageKit lk = new DynamicLanguageKit();
    lk.setURI("http://lang.whole.org/QueriesTupleResultLanguage");
    lk.setNamespace("org.whole.lang.reflect");
    lk.setName("QueriesTupleResultLanguage");
    EntityDescriptorEnum eds = lk.getEntityDescriptorEnum();
    EntityDescriptor<?> any = eds.addSimpleEntity("Any", "Any", true);
    EntityDescriptor<?> gtd = eds.addCompositeEntity("GenericTuple", "GenericTuple", false, true, false);
    gtd.withFeature(CommonsFeatureDescriptorEnum.composite_element, any.getOrdinal());
    eds.setAssignableFromAll(true, any.getOrdinal());
    ReflectionFactory.deploy(DynamicLanguageKit.getDeployer(lk));
    assertEquals(lk, ReflectionFactory.getLanguageKit(lk.getURI()));
    IEntityFactory ef = GenericEntityFactory.instance;
    IEntity p = ef.create(eds.valueOf("GenericTuple"));
    IEntity[] e = new IEntity[2];
    p.wAdd(e[0] = QueriesEntityFactory.instance.createSelfStep());
    p.wAdd(e[1] = GrammarsEntityFactory.instance.createNonTerminal("myNt"));
    assertEquals(2, p.wSize());
    assertSame(e[0], p.wGet(0));
    assertSame(e[1], p.wGet(1));
}
Also used : IEntity(org.whole.lang.model.IEntity) IEntityFactory(org.whole.lang.factories.IEntityFactory) Test(org.junit.Test)

Aggregations

IEntityFactory (org.whole.lang.factories.IEntityFactory)11 IEntity (org.whole.lang.model.IEntity)10 FeatureDescriptor (org.whole.lang.reflect.FeatureDescriptor)3 TreeSet (java.util.TreeSet)2 Test (org.junit.Test)2 IOException (java.io.IOException)1 Map (java.util.Map)1 TreeMap (java.util.TreeMap)1 ITransactionScope (org.whole.lang.bindings.ITransactionScope)1 CommonsFeatureDescriptorEnum (org.whole.lang.commons.reflect.CommonsFeatureDescriptorEnum)1 IWholeRuntimeException (org.whole.lang.exceptions.IWholeRuntimeException)1 WholeIllegalArgumentException (org.whole.lang.exceptions.WholeIllegalArgumentException)1 IEntityRegistryProvider (org.whole.lang.factories.IEntityRegistryProvider)1 Pair (org.whole.lang.json.model.Pair)1 Value (org.whole.lang.json.model.Value)1 ParseException (org.whole.lang.parsers.ParseException)1 FeatureDescriptorEnum (org.whole.lang.reflect.FeatureDescriptorEnum)1 MissingVariableException (org.whole.lang.visitors.MissingVariableException)1 VisitException (org.whole.lang.visitors.VisitException)1 Arguments (org.whole.lang.workflows.model.Arguments)1