use of org.whole.lang.reflect.DynamicLanguageKit in project whole by wholeplatform.
the class GrammarsInterpreterVisitor method visit.
@Override
public void visit(Grammar grammar) {
grammar = normalize(grammar);
GrammarsRegistry.instance().putGrammar(grammar);
TargetLanguage targetLanguage = grammar.getTargetLanguage();
ILanguageKit languageKit = null;
final String languageUri;
IBindingManager bm = getBindings();
if (Matcher.match(GrammarsEntityDescriptorEnum.URI, targetLanguage)) {
languageUri = targetLanguage.wStringValue();
languageKit = ReflectionFactory.getLanguageKit(languageUri, true, bm);
} else {
languageUri = ((LanguageDescriptor) targetLanguage).getUri().getValue();
stagedVisit(GrammarsUtils.deriveModel(grammar, false));
languageKit = (ILanguageKit) bm.getResult().wGetValue();
}
if (languageKit.isDynamic()) {
DynamicLanguageKit dynamicLanguageKit = (DynamicLanguageKit) languageKit;
GrammarBasedDataTypeParser dataTypeParser = new GrammarBasedDataTypeParser(grammar.getUri().getValue());
dynamicLanguageKit.setDataTypeParser(DataTypeParsers.PERSISTENCE, dataTypeParser);
dynamicLanguageKit.setDataTypeParser(DataTypeParsers.PRESENTATION, dataTypeParser);
}
ReflectionFactory.updatePersistenceAndEditorKits(languageKit);
ReflectionFactory.deploy(new AbstractLanguageExtensionDeployer() {
public void deploy(ReflectionFactory platform) {
platform.addOperationFactory(languageUri, PrettyPrinterOperation.ID, new IVisitorFactory() {
public IVisitor create(IOperation operation, int stage) {
return new GenericGrammarBasedPrettyPrinterVisitor((PrettyPrinterOperation) operation);
}
});
platform.addOperationFactory(languageUri, ValidatorOperation.ID, new IVisitorFactory() {
public IVisitor create(IOperation operation, int stage) {
return new GenericGrammarBasedValidatorVisitor();
}
});
}
});
}
use of org.whole.lang.reflect.DynamicLanguageKit in project whole by wholeplatform.
the class ModelsInterpreterVisitor method visit.
@Override
public void visit(Model entity) {
boolean hasArgLanguageKit = getBindings().wIsSet("languageKit");
DynamicLanguageKit argLanguageKit = hasArgLanguageKit ? (DynamicLanguageKit) getBindings().wGetValue("languageKit") : null;
boolean useArgLanguageKit = hasArgLanguageKit && argLanguageKit.getURI().equals(entity.getUri().getValue());
DynamicLanguageKit languageKit;
if (useArgLanguageKit)
languageKit = argLanguageKit;
else {
languageKit = new DynamicLanguageKit();
languageKit.setURI(entity.getUri().getValue());
languageKit.setNamespace(entity.getNamespace().getValue());
languageKit.setName(entity.getName().getValue());
languageKit.setVersion(EntityUtils.isResolver(entity.getVersion()) ? "" : entity.getVersion().getValue());
}
entity = EntityUtils.cloneIfParented(entity);
languageKit.setEntity(entity);
configureLanguageKit(languageKit, entity);
ReflectionFactory.updatePersistenceAndEditorKits(languageKit);
if (!useArgLanguageKit) {
ReflectionFactory.deploy(DynamicLanguageKit.getDeployer(languageKit));
if (hasArgLanguageKit)
getBindings().wSetValue("languageKit", argLanguageKit);
}
setResult(BindingManagerFactory.instance.createValue(languageKit));
}
use of org.whole.lang.reflect.DynamicLanguageKit in project whole by wholeplatform.
the class SchemaHelpers method deploySchemaOperations.
public static void deploySchemaOperations(final String languageUri) {
ILanguageKit lk = ReflectionFactory.getLanguageKit(languageUri, false, null);
if (!lk.isDynamic())
return;
// configure data-type parsers
IMappingStrategy mappingStrategy = MappingStrategyRegistry.instance().getMappingStrategy(languageUri);
IDataTypeParser parser = new XsiDataTypeParser(mappingStrategy.getDataTypeParsers());
DynamicLanguageKit languageKit = (DynamicLanguageKit) lk;
languageKit.setDataTypeParser(DataTypeParsers.PERSISTENCE, parser);
languageKit.setDataTypeParser(DataTypeParsers.PRESENTATION, parser);
// deploy a generic pretty print
ReflectionFactory.deploy(new AbstractLanguageExtensionDeployer() {
public void deploy(ReflectionFactory platform) {
platform.addOperationFactory(languageUri, PrettyPrinterOperation.ID, new IVisitorFactory() {
public IVisitor create(IOperation operation, int stage) {
return new XsiPrettyPrinterVisitor();
}
});
}
});
}
Aggregations