Search in sources :

Example 31 with VisitException

use of org.whole.lang.visitors.VisitException in project whole by wholeplatform.

the class GenericMatcherFactory method matchInScope.

public IVisitor matchInScope(final IEntity pattern) {
    return new AbstractVisitor() {

        public void visit(IEntity entity) {
            if (!Matcher.match(pattern, entity, getBindings()))
                throw new VisitException();
        }

        public void toString(StringBuilder sb) {
            sb.append("match(");
            // TODO startOf
            sb.append(pattern);
            sb.append(")");
        }
    };
}
Also used : AbstractVisitor(org.whole.lang.visitors.AbstractVisitor) IEntity(org.whole.lang.model.IEntity) VisitException(org.whole.lang.visitors.VisitException)

Example 32 with VisitException

use of org.whole.lang.visitors.VisitException in project whole by wholeplatform.

the class GenericMatcherFactory method isExtendedLanguageSubtypeOfMatcher.

public IVisitor isExtendedLanguageSubtypeOfMatcher(String edUri) {
    return new AbstractEntityDescriptorBasedMatcher(edUri) {

        public void visit(IEntity entity) {
            EntityDescriptor<?> entityEd = entity.wGetEntityDescriptor();
            EntityDescriptor<?> ed = getOtherEntityDescriptor(entityEd);
            if (ed == null || !ed.isExtendedLanguageSupertypeOf(entityEd))
                throw new VisitException();
        }

        protected String predicateName() {
            return "isExtendedLanguageSubtypeOf";
        }
    };
}
Also used : IEntity(org.whole.lang.model.IEntity) VisitException(org.whole.lang.visitors.VisitException)

Example 33 with VisitException

use of org.whole.lang.visitors.VisitException in project whole by wholeplatform.

the class GenericMatcherFactory method isExtendedLanguageSupertypeOfMatcher.

public IVisitor isExtendedLanguageSupertypeOfMatcher(String edUri) {
    return new AbstractEntityDescriptorBasedMatcher(edUri) {

        public void visit(IEntity entity) {
            EntityDescriptor<?> entityEd = entity.wGetEntityDescriptor();
            EntityDescriptor<?> ed = getOtherEntityDescriptor(entityEd);
            if (ed == null || !entityEd.isExtendedLanguageSupertypeOf(ed))
                throw new VisitException();
        }

        protected String predicateName() {
            return "isExtendedLanguageSupertypeOf";
        }
    };
}
Also used : IEntity(org.whole.lang.model.IEntity) VisitException(org.whole.lang.visitors.VisitException)

Example 34 with VisitException

use of org.whole.lang.visitors.VisitException in project whole by wholeplatform.

the class ResourceArtifactsGeneratorVisitor method visit.

public void visit(PackageArtifact entity) {
    env().wEnterScope();
    if (!Matcher.matchImplAndBind(ArtifactsEntityDescriptorEnum.Name, entity.getName(), env(), "packageName"))
        throw new VisitException("No Package name");
    entity.getMetadata().accept(this);
    File parentFolder = getParentFolder();
    String path = parentFolder.getAbsolutePath();
    String packagePath = path + File.separatorChar + env().wStringValue("packageName").replace('.', File.separatorChar);
    File folder = new File(packagePath);
    if (!folder.exists())
        folder.mkdirs();
    env().wDefValue("folder", folder);
    if (env().wIsSet("derived"))
        // not implemented yet
        ;
    if (env().wIsSet("readonly"))
        folder.setReadOnly();
    entity.getArtifacts().accept(this);
    env().wExitScope();
}
Also used : VisitException(org.whole.lang.visitors.VisitException) File(java.io.File)

Example 35 with VisitException

use of org.whole.lang.visitors.VisitException in project whole by wholeplatform.

the class JavaScriptInterpreterVisitor method visit.

@Override
public void visit(IJavaScriptEntity entity) {
    final IBindingManager bm = getBindings();
    IEntity sourceEntity = entity;
    String sourceString = PrettyPrinterOperation.toPrettyPrintString(sourceEntity);
    boolean useAutoboxing = true;
    do {
        Context context = Context.enter();
        context.setApplicationClassLoader(ReflectionFactory.getClassLoader(bm));
        Scriptable scope = context.initStandardObjects();
        try {
            for (String name : bm.wNames()) {
                IEntity valueEntity = bm.wGet(name);
                ScriptableObject.putProperty(scope, name, Context.javaToJS(useAutoboxing && valueEntity != null && EntityUtils.isData(valueEntity) ? valueEntity.wGetValue() : valueEntity, scope));
            }
            Object result = context.evaluateString(scope, sourceString, "<fragment>", 1, null);
            if (result instanceof IEntity)
                bm.setResult((IEntity) result);
            else if (result != null)
                bm.setResult(BindingManagerFactory.instance.createSpecificValue(result));
            for (Object id : scope.getIds()) {
                if (!(id instanceof String))
                    continue;
                String name = (String) id;
                Object value = ScriptableObject.getProperty(scope, name);
                if (bm.wIsSet(name)) {
                    IEntity valueEntity = bm.wGet(name);
                    if (useAutoboxing && valueEntity != null && EntityUtils.isData(valueEntity))
                        valueEntity.wSetValue(value);
                    else if (value != valueEntity)
                        bm.wSet(name, (IEntity) value);
                } else if (value instanceof IEntity)
                    bm.wDef(name, (IEntity) value);
                else
                    bm.wDef(name, BindingManagerFactory.instance.createSpecificValue(value));
            }
            return;
        } catch (Exception e) {
            if (!useAutoboxing)
                throw new VisitException("JavaScript Interpreter failure.", e);
            useAutoboxing = false;
        } finally {
            Context.exit();
        }
    } while (true);
}
Also used : Context(org.mozilla.javascript.Context) IEntity(org.whole.lang.model.IEntity) VisitException(org.whole.lang.visitors.VisitException) IBindingManager(org.whole.lang.bindings.IBindingManager) ScriptableObject(org.mozilla.javascript.ScriptableObject) Scriptable(org.mozilla.javascript.Scriptable) VisitException(org.whole.lang.visitors.VisitException)

Aggregations

VisitException (org.whole.lang.visitors.VisitException)35 IEntity (org.whole.lang.model.IEntity)25 IBindingManager (org.whole.lang.bindings.IBindingManager)6 File (java.io.File)4 AbstractVisitor (org.whole.lang.visitors.AbstractVisitor)4 HashSet (java.util.HashSet)3 GenericIdentityVisitor (org.whole.lang.visitors.GenericIdentityVisitor)3 IOException (java.io.IOException)2 PrintWriter (java.io.PrintWriter)2 PrettyPrinterOperation.toPrettyPrintString (org.whole.lang.operations.PrettyPrinterOperation.toPrettyPrintString)2 GenericTraversalFactory (org.whole.lang.visitors.GenericTraversalFactory)2 IVisitor (org.whole.lang.visitors.IVisitor)2 EvalError (bsh.EvalError)1 Interpreter (bsh.Interpreter)1 BufferedReader (java.io.BufferedReader)1 Reader (java.io.Reader)1 StringReader (java.io.StringReader)1 Writer (java.io.Writer)1 URI (java.net.URI)1 URISyntaxException (java.net.URISyntaxException)1