Search in sources :

Example 26 with IBindingManager

use of org.whole.lang.bindings.IBindingManager in project whole by wholeplatform.

the class ArtifactsSynchronizerVisitor method createFilesystemModel.

private IEntity createFilesystemModel(IArtifactsEntity model, IEntity basePath, boolean append) {
    T parentContext = getResource();
    IEntity artifact = basePath;
    if (basePath != null) {
        parentContext = getArtifactsOperations().getParent(parentContext);
        if (getArtifactsOperations().getChild(parentContext, basePath) == null)
            throw new IllegalArgumentException("invalid root resource");
        while (artifact != null && EntityUtils.isNotResolver(artifact) && !EntityUtils.isVariable(artifact)) {
            parentContext = getArtifactsOperations().getChild(parentContext, artifact);
            if (parentContext == null)
                break;
            IEntity children = getChildren(artifact);
            artifact = children.wIsEmpty() ? null : children.wGet(0);
        }
    }
    if (parentContext == null) {
        // cannot find path on file system
        if (artifact == basePath)
            // no file system root at all
            getChildren(basePath).wRemove(0);
        else
            // partial file system path
            artifact.wGetParent().wRemove(artifact);
    } else {
        // empty path or exists on file system
        IEntity fsModel = getArtifactsOperations().toArtifactsModel(parentContext);
        if (append && artifact != basePath) {
            IBindingManager bindings = BindingManagerFactory.instance.createBindingManager();
            IEntityIterator<IEntity> iterator = IteratorFactory.childIterator();
            iterator.reset(getChildren(fsModel));
            for (IEntity child : iterator) {
                bindings.wDef(SUB_TREE_ROOT, child);
                iterator.remove();
                Matcher.substitute(basePath, bindings, false);
            }
            Matcher.removeVars(basePath, true);
        } else
            basePath = fsModel;
    }
    return basePath;
}
Also used : IEntity(org.whole.lang.model.IEntity) IBindingManager(org.whole.lang.bindings.IBindingManager)

Example 27 with IBindingManager

use of org.whole.lang.bindings.IBindingManager in project whole by wholeplatform.

the class PojoUtils method getReadOnlyFields.

public static Set<Name> getReadOnlyFields(PojoDeclaration pojoDeclaration) {
    Set<Name> readOnlyFields = new HashSet<Name>();
    IBindingManager bindings = BindingManagerFactory.instance.createArguments();
    Expression findAllReadOnlyFields = (Expression) PojoTemplateManager.instance().create("findAllReadOnlyFields");
    for (Name readOnlyField : BehaviorUtils.<Name>compileAndLazyEvaluate(findAllReadOnlyFields, pojoDeclaration, bindings)) readOnlyFields.add(readOnlyField);
    return readOnlyFields;
}
Also used : Expression(org.whole.lang.queries.model.Expression) PathExpression(org.whole.lang.queries.model.PathExpression) IBindingManager(org.whole.lang.bindings.IBindingManager) Name(org.whole.lang.pojo.model.Name) HashSet(java.util.HashSet)

Example 28 with IBindingManager

use of org.whole.lang.bindings.IBindingManager in project whole by wholeplatform.

the class PojoUtils method findConstructor.

public static Constructor findConstructor(PojoDeclaration pojoDeclaration) {
    IBindingManager bindings = BindingManagerFactory.instance.createArguments();
    Expression findParameterByTemplate = (Expression) PojoTemplateManager.instance().create("findParameterByTemplate");
    List<Constructor> constructors = getConstructors(pojoDeclaration);
    int[] supportedFields = new int[constructors.size()];
    Expression findAllReadOnlyFields = (Expression) PojoTemplateManager.instance().create("findAllReadOnlyFields");
    IEntityIterator<Name> iterator = BehaviorUtils.<Name>compileAndLazyEvaluate(findAllReadOnlyFields, pojoDeclaration, bindings);
    int readOnlyFieldCount = 0;
    while (iterator.hasNext()) {
        iterator.next();
        for (int i = 0; i < supportedFields.length; i++) if (BehaviorUtils.evaluateFirstResult(findParameterByTemplate, constructors.get(i), bindings) != null)
            supportedFields[i]++;
        readOnlyFieldCount++;
    }
    for (int i = 0; i < supportedFields.length; i++) if (supportedFields[i] >= readOnlyFieldCount)
        return constructors.get(i);
    return constructors.get(supportedFields.length - 1);
}
Also used : Expression(org.whole.lang.queries.model.Expression) PathExpression(org.whole.lang.queries.model.PathExpression) Constructor(org.whole.lang.pojo.model.Constructor) IBindingManager(org.whole.lang.bindings.IBindingManager) Name(org.whole.lang.pojo.model.Name)

Example 29 with IBindingManager

use of org.whole.lang.bindings.IBindingManager in project whole by wholeplatform.

the class SQLInterpreterVisitor method visit.

@Override
public void visit(ISQLEntity entity) {
    if (statement != null)
        return;
    try {
        if (!Matcher.isAssignableAsIsFrom(SQLEntityDescriptorEnum.SQLStatement, entity) && !Matcher.match(SQLEntityDescriptorEnum.SQLStatements, entity))
            throw new IllegalArgumentException("cannot interpret.");
        IBindingManager env = getBindings();
        if (!env.wIsSet("connection"))
            throw new IllegalArgumentException("database connection undefined.");
        connection = (Connection) env.wGetValue("connection");
        statement = connection.createStatement();
    } catch (Exception e) {
        throw new VisitException(SQL_INTERPRETER_ERROR_MESSAGE, e);
    }
}
Also used : VisitException(org.whole.lang.visitors.VisitException) IBindingManager(org.whole.lang.bindings.IBindingManager) VisitException(org.whole.lang.visitors.VisitException)

Example 30 with IBindingManager

use of org.whole.lang.bindings.IBindingManager in project whole by wholeplatform.

the class AbstractXsiPersistenceKit method doReadModel.

@Override
protected IEntity doReadModel(IPersistenceProvider pp) throws Exception {
    IBindingManager bm = pp.getBindings();
    ModelBuilderOperation mop = new ModelBuilderOperation(RegistryConfigurations.RESOLVER);
    IBuilderOperation xsiBuilderOperation = getBuilderOperation(mop, bm);
    bm.wDefValue("mergeCDataSect", true);
    XmlNormalizerBuilderOperation normalizerOp = new XmlNormalizerBuilderOperation(xsiBuilderOperation, bm);
    SaxConsumerHandler.parse(pp.getInputStream(), pp.getEncoding(), normalizerOp);
    return mop.wGetResult();
}
Also used : ModelBuilderOperation(org.whole.lang.builders.ModelBuilderOperation) IBuilderOperation(org.whole.lang.builders.IBuilderOperation) XmlNormalizerBuilderOperation(org.whole.lang.xml.codebase.XmlNormalizerBuilderOperation) IBindingManager(org.whole.lang.bindings.IBindingManager)

Aggregations

IBindingManager (org.whole.lang.bindings.IBindingManager)223 IEntity (org.whole.lang.model.IEntity)141 Test (org.junit.Test)91 PathExpression (org.whole.lang.queries.model.PathExpression)49 ITemplateManager (org.whole.lang.templates.ITemplateManager)40 Grammar (org.whole.lang.grammars.model.Grammar)28 TestXmlGrammar (org.whole.lang.grammars.util.TestXmlGrammar)27 ESelectionService (org.eclipse.e4.ui.workbench.modeling.ESelectionService)17 Model (org.whole.lang.models.model.Model)15 Production (org.whole.lang.grammars.model.Production)14 IEntityPartViewer (org.whole.lang.ui.viewers.IEntityPartViewer)14 File (java.io.File)12 QueriesGrammar (org.whole.lang.grammars.codebase.QueriesGrammar)12 XmlModel (org.whole.lang.models.codebase.XmlModel)11 SimpleEntity (org.whole.lang.models.model.SimpleEntity)10 VisitException (org.whole.lang.visitors.VisitException)9 IBindingScope (org.whole.lang.bindings.IBindingScope)6 ModelBuilderOperation (org.whole.lang.builders.ModelBuilderOperation)6 HashMap (java.util.HashMap)5 IFile (org.eclipse.core.resources.IFile)5