Search in sources :

Example 1 with DynamicLanguageKit

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();
                }
            });
        }
    });
}
Also used : IOperation(org.whole.lang.operations.IOperation) GrammarBasedDataTypeParser(org.whole.lang.grammars.parsers.GrammarBasedDataTypeParser) LanguageDescriptor(org.whole.lang.grammars.model.LanguageDescriptor) AbstractLanguageExtensionDeployer(org.whole.lang.reflect.AbstractLanguageExtensionDeployer) IVisitorFactory(org.whole.lang.visitors.IVisitorFactory) ILanguageKit(org.whole.lang.reflect.ILanguageKit) DynamicLanguageKit(org.whole.lang.reflect.DynamicLanguageKit) ReflectionFactory(org.whole.lang.reflect.ReflectionFactory) IBindingManager(org.whole.lang.bindings.IBindingManager) TargetLanguage(org.whole.lang.grammars.model.TargetLanguage)

Example 2 with DynamicLanguageKit

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));
}
Also used : DynamicLanguageKit(org.whole.lang.reflect.DynamicLanguageKit)

Example 3 with DynamicLanguageKit

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();
                }
            });
        }
    });
}
Also used : IOperation(org.whole.lang.operations.IOperation) IMappingStrategy(org.whole.lang.xsd.codebase.IMappingStrategy) DynamicLanguageKit(org.whole.lang.reflect.DynamicLanguageKit) ReflectionFactory(org.whole.lang.reflect.ReflectionFactory) XsiDataTypeParser(org.whole.lang.xsd.parsers.XsiDataTypeParser) AbstractLanguageExtensionDeployer(org.whole.lang.reflect.AbstractLanguageExtensionDeployer) XsiPrettyPrinterVisitor(org.whole.lang.xsd.visitors.XsiPrettyPrinterVisitor) IDataTypeParser(org.whole.lang.parsers.IDataTypeParser) IVisitorFactory(org.whole.lang.visitors.IVisitorFactory) ILanguageKit(org.whole.lang.reflect.ILanguageKit)

Aggregations

DynamicLanguageKit (org.whole.lang.reflect.DynamicLanguageKit)3 IOperation (org.whole.lang.operations.IOperation)2 AbstractLanguageExtensionDeployer (org.whole.lang.reflect.AbstractLanguageExtensionDeployer)2 ILanguageKit (org.whole.lang.reflect.ILanguageKit)2 ReflectionFactory (org.whole.lang.reflect.ReflectionFactory)2 IVisitorFactory (org.whole.lang.visitors.IVisitorFactory)2 IBindingManager (org.whole.lang.bindings.IBindingManager)1 LanguageDescriptor (org.whole.lang.grammars.model.LanguageDescriptor)1 TargetLanguage (org.whole.lang.grammars.model.TargetLanguage)1 GrammarBasedDataTypeParser (org.whole.lang.grammars.parsers.GrammarBasedDataTypeParser)1 IDataTypeParser (org.whole.lang.parsers.IDataTypeParser)1 IMappingStrategy (org.whole.lang.xsd.codebase.IMappingStrategy)1 XsiDataTypeParser (org.whole.lang.xsd.parsers.XsiDataTypeParser)1 XsiPrettyPrinterVisitor (org.whole.lang.xsd.visitors.XsiPrettyPrinterVisitor)1