Search in sources :

Example 16 with IPersistenceKit

use of org.whole.lang.codebase.IPersistenceKit in project whole by wholeplatform.

the class ActionsUIEntityFactory method createPersistencesGroupAction.

public GroupAction createPersistencesGroupAction(ActionKindEnum.Value kind, Set<String> excludeSet, EntityDescriptor<?> resultEd) {
    GroupAction groupAction = createHierarchicalGroupAction(resultEd.getLanguageKit().getName() + ".persistences");
    Actions actions = createActions(0);
    for (IPersistenceKit persistenceKit : ReflectionFactory.getPersistenceKits()) actions.wAdd(createTemplateAction(kind, create(resultEd, persistenceKit.getId()), persistenceKit.getDescription(), IActionConstants.SELECT_PERSISTENCE_ICON, kind == ActionKindEnum.REPLACE));
    groupAction.setActions(actions);
    return groupAction;
}
Also used : GroupAction(org.whole.lang.actions.model.GroupAction) Actions(org.whole.lang.actions.model.Actions) IPersistenceKit(org.whole.lang.codebase.IPersistenceKit)

Example 17 with IPersistenceKit

use of org.whole.lang.codebase.IPersistenceKit in project whole by wholeplatform.

the class AbstractArtifactsGeneratorVisitor method writeContents.

protected void writeContents(IEntity model) {
    IPersistenceProvider pp = (IPersistenceProvider) env().wGetValue("persistenceProvider");
    boolean contentsWritten = false;
    if (env().wIsSet("persistenceKitId")) {
        IPersistenceKit pk = ReflectionFactory.getPersistenceKit(env().wStringValue("persistenceKitId"));
        if (pk.canApply(model))
            try {
                pk.writeModel(model, pp);
                contentsWritten = true;
            } catch (Exception inner) {
                throw new IllegalStateException(inner);
            }
    }
    try {
        if (!contentsWritten)
            PrettyPrintPersistenceKit.instance().writeModel(model, pp);
    } catch (RuntimeException runtime) {
        throw runtime;
    } catch (Exception outer) {
        throw new IllegalStateException(outer);
    }
}
Also used : IPersistenceProvider(org.whole.lang.codebase.IPersistenceProvider) IPersistenceKit(org.whole.lang.codebase.IPersistenceKit)

Example 18 with IPersistenceKit

use of org.whole.lang.codebase.IPersistenceKit in project whole by wholeplatform.

the class ArtifactsLoadFileContentsVisitor method getPersistenceKit.

private IPersistenceKit getPersistenceKit(IEntity entity) {
    String persistenceKitId = getPersistenceKitId(entity);
    IPersistenceKit persistenceKit = persistenceKitId != null ? ReflectionFactory.getPersistenceKit(persistenceKitId) : persistenceKitStack.peek();
    if (persistenceKit == null)
        throw new IllegalStateException("default persistence undefined");
    return persistenceKit;
}
Also used : IPersistenceKit(org.whole.lang.codebase.IPersistenceKit)

Example 19 with IPersistenceKit

use of org.whole.lang.codebase.IPersistenceKit in project whole by wholeplatform.

the class ArtifactsLoadFileContentsVisitor method visit.

@Override
public void visit(FileArtifact entity) {
    if (force || EntityUtils.isResolver(entity.getContent())) {
        InputStream is = getArtifactsOperations().getContents(getResource());
        IPersistenceKit persistenceKit = persistenceKitStack.peek();
        try {
            IEntity model = persistenceKit.readModel(new StreamPersistenceProvider(is));
            entity.setContent(CommonsEntityAdapterFactory.createStageUpFragment(ArtifactsEntityDescriptorEnum.Content, model));
        } catch (Exception e) {
        // TODO parameterize 	throw new IllegalStateException(e);
        }
    }
}
Also used : IEntity(org.whole.lang.model.IEntity) InputStream(java.io.InputStream) StreamPersistenceProvider(org.whole.lang.codebase.StreamPersistenceProvider) IPersistenceKit(org.whole.lang.codebase.IPersistenceKit)

Example 20 with IPersistenceKit

use of org.whole.lang.codebase.IPersistenceKit 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)

Aggregations

IPersistenceKit (org.whole.lang.codebase.IPersistenceKit)33 IEntity (org.whole.lang.model.IEntity)13 IPersistenceProvider (org.whole.lang.codebase.IPersistenceProvider)7 StringPersistenceProvider (org.whole.lang.codebase.StringPersistenceProvider)6 IOException (java.io.IOException)4 IFile (org.eclipse.core.resources.IFile)4 GridData (org.eclipse.swt.layout.GridData)4 Shell (org.eclipse.swt.widgets.Shell)4 IBindingManager (org.whole.lang.bindings.IBindingManager)4 IFilePersistenceProvider (org.whole.lang.codebase.IFilePersistenceProvider)4 IWholeRuntimeException (org.whole.lang.exceptions.IWholeRuntimeException)4 WholeIllegalArgumentException (org.whole.lang.exceptions.WholeIllegalArgumentException)4 ParseException (org.whole.lang.parsers.ParseException)4 IImportAsModelDialog (org.whole.lang.ui.dialogs.IImportAsModelDialog)4 MissingVariableException (org.whole.lang.visitors.MissingVariableException)4 VisitException (org.whole.lang.visitors.VisitException)4 ArrayList (java.util.ArrayList)3 IEclipseContext (org.eclipse.e4.core.contexts.IEclipseContext)3 SelectionEvent (org.eclipse.swt.events.SelectionEvent)3 Label (org.eclipse.swt.widgets.Label)3