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