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(")");
}
};
}
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";
}
};
}
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";
}
};
}
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();
}
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);
}
Aggregations