summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRainer Pielmann2012-07-17 03:44:10 (EDT)
committer Manik Kishore2012-07-19 01:37:47 (EDT)
commit7a67734a5e4348d1c04578bc70a5c4f2469cc548 (patch)
treedef100014a827af7e82c979cd7cacda234c1fc71
parent26c2280220907790ae72c66015e334d7a832d3f1 (diff)
downloadorg.eclipse.stardust.ide-7a67734a5e4348d1c04578bc70a5c4f2469cc548.zip
org.eclipse.stardust.ide-7a67734a5e4348d1c04578bc70a5c4f2469cc548.tar.gz
org.eclipse.stardust.ide-7a67734a5e4348d1c04578bc70a5c4f2469cc548.tar.bz2
CRNT-25134 Pepper: Cross-Model Support: Refactor Model Service
git-svn-id: http://emeafrazerg/svn/ipp/product/trunk/stardust/ide@57696 8100b5e0-4d52-466c-ae9c-bdeccbdeaf6b
-rw-r--r--model/org.eclipse.stardust.model.xpdl.builder/src/main/java/org/eclipse/stardust/model/xpdl/builder/strategy/InMemoryModelManagementStrategy.java165
-rw-r--r--model/org.eclipse.stardust.model.xpdl.builder/src/main/java/org/eclipse/stardust/model/xpdl/builder/strategy/ModelManagementHelper.java2
2 files changed, 166 insertions, 1 deletions
diff --git a/model/org.eclipse.stardust.model.xpdl.builder/src/main/java/org/eclipse/stardust/model/xpdl/builder/strategy/InMemoryModelManagementStrategy.java b/model/org.eclipse.stardust.model.xpdl.builder/src/main/java/org/eclipse/stardust/model/xpdl/builder/strategy/InMemoryModelManagementStrategy.java
new file mode 100644
index 0000000..5999a04
--- /dev/null
+++ b/model/org.eclipse.stardust.model.xpdl.builder/src/main/java/org/eclipse/stardust/model/xpdl/builder/strategy/InMemoryModelManagementStrategy.java
@@ -0,0 +1,165 @@
+/*******************************************************************************
+ * Copyright (c) 2011 SunGard CSA LLC and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * SunGard CSA LLC - initial API and implementation and/or initial documentation
+ *******************************************************************************/
+
+package org.eclipse.stardust.model.xpdl.builder.strategy;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+import org.eclipse.stardust.engine.api.runtime.DmsUtils;
+import org.eclipse.stardust.engine.api.runtime.Document;
+import org.eclipse.stardust.engine.api.runtime.DocumentInfo;
+import org.eclipse.stardust.engine.api.runtime.DocumentManagementService;
+import org.eclipse.stardust.engine.api.runtime.Folder;
+import org.eclipse.stardust.engine.api.runtime.ServiceFactory;
+import org.eclipse.stardust.engine.api.runtime.ServiceFactoryLocator;
+import org.eclipse.stardust.model.xpdl.builder.strategy.AbstractModelManagementStrategy;
+import org.eclipse.stardust.model.xpdl.builder.utils.XpdlModelIoUtils;
+import org.eclipse.stardust.model.xpdl.carnot.ModelType;
+
+/**
+ *
+ * @author Marc.Gille
+ *
+ */
+public class InMemoryModelManagementStrategy extends
+ AbstractModelManagementStrategy {
+
+ private static final String MODELS_DIR = "/process-models/";
+
+ private ServiceFactory serviceFactory;
+ private DocumentManagementService documentManagementService;
+ private List<ModelType> models = new ArrayList<ModelType>();
+
+
+ public Map<String, ModelType> getModels()
+ {
+ return getModels(true);
+ }
+ /**
+ *
+ */
+ public List<ModelType> loadModels() {
+ return models;
+ }
+
+ /**
+ *
+ */
+ public ModelType loadModel(String id) {
+ for (Iterator<ModelType> i = models.iterator(); i.hasNext();) {
+ ModelType model = i.next();
+ if (model.getId().equalsIgnoreCase(id)) {
+ return model;
+ }
+ }
+ return null;
+ }
+
+
+
+ /**
+ *
+ */
+ public ModelType attachModel(String id) {
+ ModelType model = this.loadModel(id);
+ models.add(model);
+ return model;
+ }
+
+ /**
+ *
+ */
+ public void saveModel(ModelType model) {
+ String modelContent = new String(XpdlModelIoUtils.saveModel(model));
+ Document modelDocument;
+
+ modelDocument = getDocumentManagementService().getDocument(
+ MODELS_DIR + model.getName() + ".xpdl");
+
+ if (null == modelDocument) {
+ DocumentInfo docInfo = DmsUtils.createDocumentInfo(model.getName()
+ + ".xpdl");
+
+ docInfo.setOwner(getServiceFactory().getWorkflowService().getUser()
+ .getAccount());
+ docInfo.setContentType("text/xhtml");
+
+ modelDocument = getDocumentManagementService().createDocument(
+ MODELS_DIR, docInfo, modelContent.getBytes(), null);
+
+ // Create initial version
+
+ getDocumentManagementService().versionDocument(
+ modelDocument.getId(), null);
+ } else {
+ getDocumentManagementService().updateDocument(modelDocument,
+ modelContent.getBytes(), null, false, null, false);
+ }
+ }
+
+ /**
+ *
+ * @param model
+ */
+ public void deleteModel(ModelType model) {
+ Document modelDocument = getDocumentManagementService().getDocument(
+ MODELS_DIR + model.getName() + ".xpdl");
+
+ if (modelDocument != null)
+ {
+ getDocumentManagementService().removeDocument(modelDocument.getId());
+ }
+
+ getModels().remove(model.getId());
+ }
+
+ /**
+ *
+ */
+ public void versionizeModel(ModelType model) {
+ }
+
+ /**
+ *
+ * @return
+ */
+ private DocumentManagementService getDocumentManagementService() {
+ if (documentManagementService == null) {
+ documentManagementService = getServiceFactory()
+ .getDocumentManagementService();
+ }
+
+ return documentManagementService;
+ }
+
+ private ServiceFactory getServiceFactory() {
+ // TODO Replace
+
+ if (serviceFactory == null) {
+ serviceFactory = ServiceFactoryLocator.get("motu", "motu");
+ }
+
+ return serviceFactory;
+ }
+
+ /**
+ *
+ * @param modelDocument
+ * @return
+ */
+ private byte[] readModelContext(Document modelDocument) {
+ return getDocumentManagementService().retrieveDocumentContent(
+ modelDocument.getId());
+ }
+}
diff --git a/model/org.eclipse.stardust.model.xpdl.builder/src/main/java/org/eclipse/stardust/model/xpdl/builder/strategy/ModelManagementHelper.java b/model/org.eclipse.stardust.model.xpdl.builder/src/main/java/org/eclipse/stardust/model/xpdl/builder/strategy/ModelManagementHelper.java
index 9893aaf..1549cd4 100644
--- a/model/org.eclipse.stardust.model.xpdl.builder/src/main/java/org/eclipse/stardust/model/xpdl/builder/strategy/ModelManagementHelper.java
+++ b/model/org.eclipse.stardust.model.xpdl.builder/src/main/java/org/eclipse/stardust/model/xpdl/builder/strategy/ModelManagementHelper.java
@@ -45,7 +45,7 @@ public class ModelManagementHelper
public synchronized ModelManagementStrategy getModelManagementStrategy()
{
if (strategy == null) {
- //TODO: Move Modelmanagemant Strategy to this plugin
+ //Default Strategy?
}
return strategy;
}