use of org.whole.lang.visitors.IVisitor in project whole by wholeplatform.
the class SQLInterpreterVisitor method visit.
@Override
public void visit(SQLStatement entity) {
try {
IVisitor ov = getOperation().setVisitor(entity, 0, getOperation().getVisitor(entity, 1));
getOperation().stagedVisit(entity);
getOperation().setVisitor(entity, 0, ov);
entity = (SQLStatement) getResult();
String sql = toPrettyPrintString(entity);
if (batchMode)
statement.addBatch(sql);
else {
String[] names;
if (entity.wGetEntityDescriptor().equals(SQLEntityDescriptorEnum.Select)) {
IEntity columnExprs = entity.wGet(SQLFeatureDescriptorEnum.columnExprs);
int size = columnExprs.wSize();
names = new String[size];
for (int i = 0; i < size; i++) {
IEntity columnExpr = columnExprs.wGet(i);
if (Matcher.matchImpl(SQLEntityDescriptorEnum.ColumnExpression, columnExpr)) {
IEntity alias = columnExpr.wGet(SQLFeatureDescriptorEnum.alias);
if (DataTypeUtils.getDataKind(alias).isString())
names[i] = alias.wStringValue();
else {
IEntity expr = columnExpr.wGet(SQLFeatureDescriptorEnum.expression);
if (Matcher.matchImpl(SQLEntityDescriptorEnum.ColumnName, expr))
names[i] = expr.wStringValue();
}
}
}
} else
names = new String[0];
if (statement.execute(sql))
setResultIterator(new ResultSetIterator(statement.getResultSet(), names));
else {
setResult(null);
statement.close();
}
}
} catch (Exception e) {
try {
statement.close();
} catch (Exception e1) {
}
throw new VisitException(SQL_INTERPRETER_ERROR_MESSAGE, e);
} finally {
if (!batchMode)
statement = null;
}
}
use of org.whole.lang.visitors.IVisitor in project whole by wholeplatform.
the class LegacyOperationsDeployer method deploy.
public void deploy(ReflectionFactory platform) {
// TODO move to MappingStrategyRegistry?
MappingStrategyRegistry.instance().putMappingStrategy(new CommonsMappingStrategy());
InterpreterOperation.interpret(new SchemaActions().create());
platform.addOperationFactory(XsdLanguageKit.URI, PrettyPrinterOperation.ID, new IVisitorFactory() {
public IVisitor create(IOperation operation, int stage) {
return new XsdPrettyPrinterVisitor();
}
});
// TODO rewrite using queries/actions in SchemaActions
// platform.addOperationFactory(XsdLanguageKit.ID, ArtifactsGeneratorOperation.ID,
// new IVisitorFactory() {
// public IVisitor create(IOperation operation, int stage) {
// return new Xsd2ModelsArtifactsGeneratorVisitor((ArtifactsGeneratorOperation) operation);
// }
// });
InterpreterOperation.interpret(new MappingActions().create());
// FIXME requires WorkflowsInterpreter see WorkflowsInterpreterDeployer
XsdRegistry.initialize();
platform.addPersistenceKit("org.whole.lang.xsd.XsdSourceEditor", XsdPersistenceKit.instance());
platform.addPersistenceKit("org.whole.lang.xsd.XsiSourceEditor", XsiPersistenceKit.instance());
InterpreterOperation.interpret(new SchemaModelsActions().create());
}
use of org.whole.lang.visitors.IVisitor in project whole by wholeplatform.
the class TextInterpreterVisitor method visit.
@Override
public void visit(ITextEntity entity) {
IVisitor ov = op().setVisitor(entity, 0, op().getVisitor(entity, 1));
op().stagedVisit(entity);
op().setVisitor(entity, 0, ov);
IBindingManager bm = getBindings();
bm.setResult(TextEntityFactory.instance.createText(toPrettyPrintString(bm.getResult())));
}
use of org.whole.lang.visitors.IVisitor in project whole by wholeplatform.
the class IteratorFactoryTest method testTopDownIterator.
@Test
public void testTopDownIterator() throws Exception {
Grammar g = new TestXmlGrammar().create();
final Productions productions = g.getPhraseStructure();
final IEntityIterator<IEntity> ci = IteratorFactory.<IEntity>descendantOrSelfIterator();
ci.reset(productions);
IVisitor v = GenericTraversalFactory.instance.topDown(new GenericIdentityVisitor() {
public void visit(IEntity entity) {
if (ci.hasNext())
assertSame(entity, ci.next());
else
fail();
}
}, false);
v.visit(productions);
final IEntityIterator<IEntity> ci2 = IteratorFactory.<IEntity>descendantOrSelfScannerIterator();
ci2.reset(productions);
v = GenericTraversalFactory.instance.topDown(new GenericIdentityVisitor() {
public void visit(IEntity entity) {
if (EntityUtils.isResolver(entity))
return;
if (ci2.hasNext())
assertSame(entity, ci2.next());
else
fail();
}
}, false);
v.visit(productions);
final IEntityIterator<IEntity> ci3 = IteratorFactory.<IEntity>descendantOrSelfMatcherIterator().withPattern(GrammarsEntityDescriptorEnum.Production);
ci3.reset(productions);
v = GenericTraversalFactory.instance.topDown(new GenericIdentityVisitor() {
public void visit(IEntity entity) {
if (!Matcher.match(GrammarsEntityDescriptorEnum.Production, entity))
return;
if (ci3.hasNext())
assertSame(entity, ci3.next());
else
fail();
}
}, false);
v.visit(productions);
IEntity artifactsModel = XmlBuilderPersistenceKit.instance().readModel(new ClasspathPersistenceProvider("org/whole/lang/artifacts/ArtifactsModel.xwl"));
Set<Type> typeSet = new HashSet<Type>();
IEntityIterator<Type> ci4 = IteratorFactory.<Type>descendantOrSelfMatcherIterator().withPattern(ModelsEntityFactory.instance.createSimpleName("Atifacts"));
ci4.reset(artifactsModel);
while (ci4.hasNext()) assertTrue(typeSet.add(ci4.next()));
}
use of org.whole.lang.visitors.IVisitor in project whole by wholeplatform.
the class EntityMatchers method defined.
@Factory
public static <T> Matcher<IEntity> defined(IBindingManager bindings) {
IVisitor v = TestsMatcherFactory.instance.defined();
v.setBindings(bindings);
return new VisitorMatcher(v);
}
Aggregations