Search in sources :

Example 31 with ILanguageKit

use of org.whole.lang.reflect.ILanguageKit in project whole by wholeplatform.

the class PersistenceLibraryDeployer method derivePersistenceKit.

protected static IPersistenceKit derivePersistenceKit(IBindingManager bm, StringPersistenceProvider pp) {
    String persistenceKitId = null;
    if (bm.wIsSet("grammarURI")) {
        pp.getBindings().wDefValue("grammarURI", bm.wStringValue("grammarURI"));
        persistenceKitId = "org.whole.lang.grammars.codebase.GrammarsPersistenceKit";
    } else if (bm.wIsSet("persistenceId"))
        persistenceKitId = bm.wStringValue("persistenceId");
    if (bm.wIsSet("entityURI")) {
        String entityURI = bm.wStringValue("entityURI");
        pp.getBindings().wDefValue("entityURI", entityURI);
    }
    if (pp.getBindings().wIsSet("entityURI")) {
        String entityURI = pp.getBindings().wStringValue("entityURI");
        ILanguageKit languageKit = ResourceUtils.hasFragmentPart(entityURI) ? CommonsDataTypePersistenceParser.getEntityDescriptor(entityURI, true, bm).getLanguageKit() : ReflectionFactory.getLanguageKit(entityURI, true, bm);
        if (persistenceKitId == null)
            for (IPersistenceKit persistenceKit : languageKit.getPersistenceKits()) if (!persistenceKit.isGeneric()) {
                persistenceKitId = persistenceKit.getId();
                break;
            }
        if (persistenceKitId == null)
            persistenceKitId = languageKit.getDefaultPersistenceKit().getId();
    }
    if (persistenceKitId == null)
        persistenceKitId = "org.whole.lang.xml.codebase.XmlBuilderPersistenceKit";
    if (!ReflectionFactory.hasPersistenceKit(persistenceKitId))
        throw new IllegalArgumentException("Missing persistence");
    return ReflectionFactory.getPersistenceKit(persistenceKitId);
}
Also used : IPersistenceKit(org.whole.lang.codebase.IPersistenceKit) ILanguageKit(org.whole.lang.reflect.ILanguageKit)

Example 32 with ILanguageKit

use of org.whole.lang.reflect.ILanguageKit in project whole by wholeplatform.

the class CommonsDataTypePersistenceParser method getFeatureDescriptor.

public static FeatureDescriptor getFeatureDescriptor(String fdUri, boolean loadOnDemand, IBindingManager bm) {
    int index = fdUri.indexOf('#');
    if (index > 0) {
        String languageUri = fdUri.substring(0, index);
        if (ReflectionFactory.hasLanguageKit(languageUri, loadOnDemand, bm)) {
            ILanguageKit lk = ReflectionFactory.getLanguageKit(languageUri, loadOnDemand, bm);
            FeatureDescriptor fd = lk.getFeatureDescriptorEnum().valueOf(fdUri.substring(index + 1));
            if (fd != null)
                return fd;
        }
    }
    return null;
}
Also used : FeatureDescriptor(org.whole.lang.reflect.FeatureDescriptor) ILanguageKit(org.whole.lang.reflect.ILanguageKit)

Example 33 with ILanguageKit

use of org.whole.lang.reflect.ILanguageKit in project whole by wholeplatform.

the class CommonsDataTypePersistenceParser method getEntityDescriptor.

public static EntityDescriptor<? extends IEntity> getEntityDescriptor(String edUri, boolean loadOnDemand, IBindingManager bm) {
    int index = edUri.indexOf('#');
    if (index > 0) {
        String languageUri = edUri.substring(0, index);
        if (ReflectionFactory.hasLanguageKit(languageUri, loadOnDemand, bm)) {
            ILanguageKit lk = ReflectionFactory.getLanguageKit(languageUri, loadOnDemand, bm);
            EntityDescriptor<?> ed = lk.getEntityDescriptorEnum().valueOf(edUri.substring(index + 1));
            if (ed != null)
                return ed;
        }
    }
    return null;
}
Also used : ILanguageKit(org.whole.lang.reflect.ILanguageKit)

Example 34 with ILanguageKit

use of org.whole.lang.reflect.ILanguageKit 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)

Example 35 with ILanguageKit

use of org.whole.lang.reflect.ILanguageKit in project whole by wholeplatform.

the class WholeModelWizardPage1 method createControl.

public void createControl(Composite parent) {
    super.createControl(parent);
    Composite composite = (Composite) getControl();
    Group group = new Group(composite, SWT.NONE);
    group.setLayout(new GridLayout());
    group.setText("Choose options");
    group.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    GridLayout gridLayout = new GridLayout();
    gridLayout.numColumns = 2;
    group.setLayout(gridLayout);
    new Label(group, SWT.LEFT).setText("Language:");
    languageCombo = new Combo(group, SWT.DROP_DOWN | SWT.READ_ONLY);
    languageCombo.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    new Label(group, SWT.LEFT).setText("Template:");
    templateCombo = new Combo(group, SWT.DROP_DOWN | SWT.READ_ONLY);
    templateCombo.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    new Label(group, SWT.LEFT).setText("Save As:");
    saveAsCombo = new Combo(group, SWT.DROP_DOWN | SWT.READ_ONLY);
    saveAsCombo.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    IResourceRegistry<ILanguageKit> registry = ReflectionFactory.getLanguageKitRegistry();
    languageKits = new ArrayList<ILanguageKit>(registry.getResources(false, ResourceUtils.SIMPLE_COMPARATOR));
    for (ILanguageKit languageKit : languageKits) languageCombo.add(ResourceUtils.SIMPLE_NAME_PROVIDER.toString(registry, languageKit));
    languageCombo.addSelectionListener(new SelectionListener() {

        public void widgetDefaultSelected(SelectionEvent e) {
        }

        public void widgetSelected(SelectionEvent e) {
            ILanguageKit languageKit = languageKits.get(languageCombo.getSelectionIndex());
            fireLanguageSelected(languageKit);
        }
    });
    languageCombo.select(0);
    ILanguageKit languageKit = languageKits.get(0);
    fireLanguageSelected(languageKit);
    saveAsCombo.addSelectionListener(new SelectionListener() {

        public void widgetDefaultSelected(SelectionEvent e) {
        }

        public void widgetSelected(SelectionEvent e) {
            String name = getFileName();
            name = StringUtils.replaceExtension(name, getPersistenceKit(saveAsCombo).getFileExtension());
            // TODO mediated by languageKit
            setFileName(name);
        }
    });
    setPageComplete(validatePage());
}
Also used : Group(org.eclipse.swt.widgets.Group) GridLayout(org.eclipse.swt.layout.GridLayout) Composite(org.eclipse.swt.widgets.Composite) GridData(org.eclipse.swt.layout.GridData) Label(org.eclipse.swt.widgets.Label) SelectionEvent(org.eclipse.swt.events.SelectionEvent) Combo(org.eclipse.swt.widgets.Combo) ILanguageKit(org.whole.lang.reflect.ILanguageKit) SelectionListener(org.eclipse.swt.events.SelectionListener)

Aggregations

ILanguageKit (org.whole.lang.reflect.ILanguageKit)41 IEntity (org.whole.lang.model.IEntity)12 EntityDescriptorEnum (org.whole.lang.reflect.EntityDescriptorEnum)8 Actions (org.whole.lang.actions.model.Actions)7 GroupAction (org.whole.lang.actions.model.GroupAction)7 EntityDescriptor (org.whole.lang.reflect.EntityDescriptor)7 FeatureDescriptor (org.whole.lang.reflect.FeatureDescriptor)6 ArrayList (java.util.ArrayList)5 ActionsUIEntityFactory (org.whole.lang.actions.ui.factories.ActionsUIEntityFactory)5 Test (org.junit.Test)4 QueriesEntityFactory (org.whole.lang.queries.factories.QueriesEntityFactory)4 IVisitor (org.whole.lang.visitors.IVisitor)4 HashMap (java.util.HashMap)3 IBindingManager (org.whole.lang.bindings.IBindingManager)3 Grammar (org.whole.lang.grammars.model.Grammar)3 IDataTypeParser (org.whole.lang.parsers.IDataTypeParser)3 HashSet (java.util.HashSet)2 SelectionEvent (org.eclipse.swt.events.SelectionEvent)2 SelectionListener (org.eclipse.swt.events.SelectionListener)2 IPersistenceKit (org.whole.lang.codebase.IPersistenceKit)2