summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRainer Pielmann2012-08-20 08:47:23 (EDT)
committer Manik Kishore2012-08-20 08:47:23 (EDT)
commitdf30c9661395c9ccc14d65b1382efe71951680d6 (patch)
tree4e98574c6f4c040622babced028918ed20864a2d
parenta74d1821ab2f78874c4951358876d6f36c27b73c (diff)
downloadorg.eclipse.stardust.ide-df30c9661395c9ccc14d65b1382efe71951680d6.zip
org.eclipse.stardust.ide-df30c9661395c9ccc14d65b1382efe71951680d6.tar.gz
org.eclipse.stardust.ide-df30c9661395c9ccc14d65b1382efe71951680d6.tar.bz2
CRNT-25760 Refactor/Clean up MB Facade: Renamed "JCRxxxxxx" to "WebModelerxxxxxx"
git-svn-id: http://emeafrazerg/svn/ipp/product/trunk/stardust/ide@58550 8100b5e0-4d52-466c-ae9c-bdeccbdeaf6b
-rw-r--r--model/org.eclipse.stardust.model.xpdl.builder/src/main/java/org/eclipse/stardust/model/xpdl/builder/activity/BpmApplicationActivityBuilder.java4
-rw-r--r--model/org.eclipse.stardust.model.xpdl.builder/src/main/java/org/eclipse/stardust/model/xpdl/builder/activity/BpmSubProcessActivityBuilder.java4
-rw-r--r--model/org.eclipse.stardust.model.xpdl.builder/src/main/java/org/eclipse/stardust/model/xpdl/builder/connectionhandler/WebModelerConnectionHandler.java287
-rw-r--r--model/org.eclipse.stardust.model.xpdl.builder/src/main/java/org/eclipse/stardust/model/xpdl/builder/utils/ModelBuilderFacade.java4
-rw-r--r--model/org.eclipse.stardust.model.xpdl.builder/src/main/java/org/eclipse/stardust/model/xpdl/builder/utils/WebModelerConnectionManager.java905
-rw-r--r--model/org.eclipse.stardust.model.xpdl.builder/src/main/java/org/eclipse/stardust/model/xpdl/builder/utils/WebModelerModelManager.java113
-rw-r--r--model/org.eclipse.stardust.model.xpdl.builder/src/main/java/org/eclipse/stardust/model/xpdl/builder/utils/XpdlModelIoUtils.java12
-rw-r--r--model/org.eclipse.stardust.model.xpdl.builder/src/main/java/org/eclipse/stardust/model/xpdl/builder/variable/BpmStructVariableBuilder.java4
8 files changed, 1319 insertions, 14 deletions
diff --git a/model/org.eclipse.stardust.model.xpdl.builder/src/main/java/org/eclipse/stardust/model/xpdl/builder/activity/BpmApplicationActivityBuilder.java b/model/org.eclipse.stardust.model.xpdl.builder/src/main/java/org/eclipse/stardust/model/xpdl/builder/activity/BpmApplicationActivityBuilder.java
index 0ddc24a..9abb8d0 100644
--- a/model/org.eclipse.stardust.model.xpdl.builder/src/main/java/org/eclipse/stardust/model/xpdl/builder/activity/BpmApplicationActivityBuilder.java
+++ b/model/org.eclipse.stardust.model.xpdl.builder/src/main/java/org/eclipse/stardust/model/xpdl/builder/activity/BpmApplicationActivityBuilder.java
@@ -11,7 +11,7 @@
package org.eclipse.stardust.model.xpdl.builder.activity;
import org.eclipse.emf.common.util.URI;
-import org.eclipse.stardust.model.xpdl.builder.utils.JcrConnectionManager;
+import org.eclipse.stardust.model.xpdl.builder.utils.WebModelerConnectionManager;
import org.eclipse.stardust.model.xpdl.carnot.*;
import org.eclipse.stardust.model.xpdl.carnot.util.AttributeUtil;
import org.eclipse.stardust.model.xpdl.carnot.util.CarnotConstants;
@@ -59,7 +59,7 @@ public class BpmApplicationActivityBuilder
}
else
{
- String fileConnectionId = JcrConnectionManager.createFileConnection(model, applicationModel);
+ String fileConnectionId = WebModelerConnectionManager.createFileConnection(model, applicationModel);
String bundleId = CarnotConstants.DIAGRAM_PLUGIN_ID;
URI uri = URI.createURI("cnx://" + fileConnectionId + "/");
diff --git a/model/org.eclipse.stardust.model.xpdl.builder/src/main/java/org/eclipse/stardust/model/xpdl/builder/activity/BpmSubProcessActivityBuilder.java b/model/org.eclipse.stardust.model.xpdl.builder/src/main/java/org/eclipse/stardust/model/xpdl/builder/activity/BpmSubProcessActivityBuilder.java
index cb3dcee..3efaa64 100644
--- a/model/org.eclipse.stardust.model.xpdl.builder/src/main/java/org/eclipse/stardust/model/xpdl/builder/activity/BpmSubProcessActivityBuilder.java
+++ b/model/org.eclipse.stardust.model.xpdl.builder/src/main/java/org/eclipse/stardust/model/xpdl/builder/activity/BpmSubProcessActivityBuilder.java
@@ -12,7 +12,7 @@ package org.eclipse.stardust.model.xpdl.builder.activity;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.emf.common.util.URI;
-import org.eclipse.stardust.model.xpdl.builder.utils.JcrConnectionManager;
+import org.eclipse.stardust.model.xpdl.builder.utils.WebModelerConnectionManager;
import org.eclipse.stardust.model.xpdl.builder.utils.XpdlModelIoUtils;
import org.eclipse.stardust.model.xpdl.carnot.*;
import org.eclipse.stardust.model.xpdl.carnot.util.AttributeUtil;
@@ -70,7 +70,7 @@ public class BpmSubProcessActivityBuilder
}
else
{
- String fileConnectionId = JcrConnectionManager.createFileConnection(model, processModel);
+ String fileConnectionId = WebModelerConnectionManager.createFileConnection(model, processModel);
String bundleId = CarnotConstants.DIAGRAM_PLUGIN_ID;
diff --git a/model/org.eclipse.stardust.model.xpdl.builder/src/main/java/org/eclipse/stardust/model/xpdl/builder/connectionhandler/WebModelerConnectionHandler.java b/model/org.eclipse.stardust.model.xpdl.builder/src/main/java/org/eclipse/stardust/model/xpdl/builder/connectionhandler/WebModelerConnectionHandler.java
new file mode 100644
index 0000000..83897f1
--- /dev/null
+++ b/model/org.eclipse.stardust.model.xpdl.builder/src/main/java/org/eclipse/stardust/model/xpdl/builder/connectionhandler/WebModelerConnectionHandler.java
@@ -0,0 +1,287 @@
+/*******************************************************************************
+ * Copyright (c) 2012 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
+ *******************************************************************************/
+/*
+ * $Id$
+ * (C) 2000 - 2012 CARNOT AG
+ */
+package org.eclipse.stardust.model.xpdl.builder.connectionhandler;
+
+import java.io.IOException;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.UndeclaredThrowableException;
+import java.text.MessageFormat;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.emf.common.util.URI;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.stardust.common.CollectionUtils;
+import org.eclipse.stardust.engine.api.runtime.Document;
+import org.eclipse.stardust.engine.api.runtime.DocumentManagementService;
+import org.eclipse.stardust.model.xpdl.builder.strategy.ModelManagementStrategy;
+import org.eclipse.stardust.model.xpdl.builder.utils.WebModelerConnectionManager;
+import org.eclipse.stardust.model.xpdl.builder.utils.PepperIconFactory;
+import org.eclipse.stardust.model.xpdl.carnot.ModelType;
+import org.eclipse.stardust.model.xpdl.carnot.util.CarnotConstants;
+import org.eclipse.stardust.model.xpdl.carnot.util.IconFactory;
+import org.eclipse.stardust.model.xpdl.carnot.util.ModelUtils;
+import org.eclipse.stardust.modeling.repository.common.Connection;
+import org.eclipse.stardust.modeling.repository.common.ConnectionHandler;
+import org.eclipse.stardust.modeling.repository.common.IFilter;
+import org.eclipse.stardust.modeling.repository.common.IObjectDescriptor;
+import org.eclipse.stardust.modeling.repository.common.ImportCancelledException;
+import org.eclipse.stardust.modeling.repository.common.ImportableDescriptor;
+import org.eclipse.stardust.modeling.repository.common.ObjectRepositoryActivator;
+import org.eclipse.stardust.modeling.repository.common.descriptors.CategoryDescriptor;
+import org.eclipse.stardust.modeling.repository.common.descriptors.EObjectDescriptor;
+import org.eclipse.stardust.modeling.repository.common.descriptors.ModelElementDescriptor;
+import org.eclipse.stardust.modeling.repository.common.util.ImportUtils;
+
+
+public class WebModelerConnectionHandler implements ConnectionHandler
+{
+ DocumentManagementService documentManagementService;
+
+ private static final String MODELS_DIR = "/process-models/";
+
+
+ private boolean open;
+ private URI uri;
+ private IObjectDescriptor[] children = null;
+ private Connection connection;
+ private ModelManagementStrategy strategy;
+
+ private static final List<String> PARTICIPANTS = Arrays.asList(new String[] {
+ "role", "organization", "conditionalPerformer"
+ });
+
+ private boolean init = false;
+
+ private EObjectDescriptor modelDescriptor;
+ private ModelType model;
+
+ public WebModelerConnectionHandler(ModelManagementStrategy strategy)
+ {
+ this.strategy = strategy;
+ }
+
+ synchronized ModelType loadModel(String id)
+ {
+
+ return strategy.loadModel(id);
+ }
+
+ private byte[] readModelContext(Document modelDocument) {
+ return documentManagementService.retrieveDocumentContent(
+ modelDocument.getId());
+ }
+
+ public void importObject(ModelType model, IObjectDescriptor[] descriptors, boolean asLink)
+ {
+ for (int i = 0; i < descriptors.length; i++)
+ {
+ IObjectDescriptor descriptor = descriptors[i];
+ if (descriptor instanceof ImportableDescriptor)
+ {
+ try
+ {
+ ((ImportableDescriptor) descriptor).importElements(null, model, asLink);
+ }
+ catch (Exception f)
+ {
+ if (f instanceof UndeclaredThrowableException)
+ {
+ Throwable undeclaredThrowable = ((UndeclaredThrowableException) f).getUndeclaredThrowable();
+ if (undeclaredThrowable instanceof InvocationTargetException)
+ {
+ Throwable targetException = ((InvocationTargetException) undeclaredThrowable).getTargetException();
+ if (targetException instanceof ImportCancelledException)
+ {
+ throw new ImportCancelledException();
+ }
+ }
+ }
+ else if (f instanceof ImportCancelledException)
+ {
+ throw new ImportCancelledException();
+ }
+ }
+ }
+ }
+ }
+
+ public EObject resolve(ModelType model, EObject object)
+ {
+ URI uri = WebModelerConnectionManager.getURI(object);
+ {
+ IObjectDescriptor node = find(uri);
+ if (node != null)
+ {
+ return ((ModelElementDescriptor) node).resolveElement(object);
+ }
+ }
+ return object;
+ }
+
+ public IObjectDescriptor find(URI uri)
+ {
+ if (uri.equals(this.uri))
+ {
+ return modelDescriptor;
+ }
+ for (IObjectDescriptor child : children)
+ {
+ if (uri.equals(child.getURI()))
+ {
+ return child;
+ }
+ else if (child instanceof CategoryDescriptor)
+ {
+ URI categoryUri = child.getURI();
+ if (isChildOf(categoryUri, uri))
+ {
+ return ((CategoryDescriptor) child).find(uri);
+ }
+ }
+ }
+ return null;
+ }
+
+ public boolean isChildOf(URI categoryUri, URI uri)
+ {
+ if (uri.toString().startsWith(categoryUri.toString()))
+ {
+ return true;
+ }
+ if ("participants".equals(categoryUri.lastSegment()) && uri.segmentCount() > categoryUri.segmentCount())
+ {
+ return PARTICIPANTS.contains(uri.segment(categoryUri.segmentCount() - 1));
+ }
+ return false;
+ }
+
+ public void open(Connection connection) throws CoreException
+ {
+ if (open)
+ {
+ throw new CoreException(new Status(IStatus.ERROR, ObjectRepositoryActivator.PLUGIN_ID,
+ 0, MessageFormat.format("EXC_ALREADY_OPEN", new Object[]{connection.getId()}),null));
+ }
+
+ uri = WebModelerConnectionManager.makeURI(connection);
+ String filename = connection.getAttribute("filename"); //$NON-NLS-1$
+
+ String xpdlId = null;
+
+ if(filename != null)
+ {
+ xpdlId = resolve(filename);
+ }
+
+ this.connection = connection;
+ try
+ {
+ if(xpdlId != null)
+ {
+ updateCache(xpdlId);
+ }
+ }
+ catch (IOException ex)
+ {
+ throw new CoreException(new Status(IStatus.WARNING,
+ "org.eclipse.stardust.modeling.repository.file", "EXC_UNABLE_TO_LOAD_MD", ex)); //$NON-NLS-1$
+ }
+ open = true;
+ }
+
+ // close file
+ public void close(Connection connection) throws CoreException
+ {
+ if (!open)
+ {
+ throw new CoreException(new Status(IStatus.ERROR, ObjectRepositoryActivator.PLUGIN_ID,
+ 0, MessageFormat.format("EXC_ALREADY_CLOSED", new Object[]{connection.getId()}),null));
+ }
+ open = false;
+ this.connection = null;
+ }
+
+ public List<IObjectDescriptor> select(IFilter[] filters) throws CoreException
+ {
+ List<IObjectDescriptor> result = CollectionUtils.newList();
+ if (filters == null || filters.length == 0)
+ {
+ for (int i = 0; i < children.length; i++)
+ {
+ result.add(children[i]);
+ }
+ }
+ else
+ {
+ for (int i = 0; i < children.length; i++)
+ {
+ IObjectDescriptor descriptor = children[i];
+ for (int j = 0; j < filters.length; j++)
+ {
+ if (filters[j] != null && filters[j].accept(descriptor))
+ {
+ result.add(descriptor);
+ break;
+ }
+ }
+ }
+ }
+ IObjectDescriptor searchDescriptor = (IObjectDescriptor) connection.getProperty("search.result"); //$NON-NLS-1$
+ if (searchDescriptor != null)
+ {
+ result.add(searchDescriptor);
+ }
+ return Collections.unmodifiableList(result);
+ }
+
+ // open the selected file from the file connection
+ // check, if file is valid file
+ private void updateCache(String id) throws IOException
+ {
+ model = loadModel(id);
+
+ IconFactory iconFactory = new PepperIconFactory();
+
+ modelDescriptor = new EObjectDescriptor(uri, model, model.getId(), model.getName(),
+ ModelUtils.getDescriptionText(model.getDescription()),
+ CarnotConstants.DIAGRAM_PLUGIN_ID, null);
+ List<IObjectDescriptor> descriptors = ImportUtils.createObjectDescriptors(iconFactory, model, uri);
+ if (descriptors.size() > 0)
+ {
+ children = descriptors.toArray(new IObjectDescriptor[0]);
+ }
+ }
+
+ private String resolve(String fileName)
+ {
+ String xpdlName = null;
+ java.net.URI uri = java.net.URI.create(fileName);
+ if ("project".equals(uri.getScheme())) //$NON-NLS-1$
+ {
+ String path = uri.getPath();
+ xpdlName = path.substring(1);
+ }
+ else if ("platform".equals(uri.getScheme())) //$NON-NLS-1$
+ {
+ // uri.getPath();
+ }
+ return xpdlName;
+ }
+} \ No newline at end of file
diff --git a/model/org.eclipse.stardust.model.xpdl.builder/src/main/java/org/eclipse/stardust/model/xpdl/builder/utils/ModelBuilderFacade.java b/model/org.eclipse.stardust.model.xpdl.builder/src/main/java/org/eclipse/stardust/model/xpdl/builder/utils/ModelBuilderFacade.java
index 5a6853a..3e51cbc 100644
--- a/model/org.eclipse.stardust.model.xpdl.builder/src/main/java/org/eclipse/stardust/model/xpdl/builder/utils/ModelBuilderFacade.java
+++ b/model/org.eclipse.stardust.model.xpdl.builder/src/main/java/org/eclipse/stardust/model/xpdl/builder/utils/ModelBuilderFacade.java
@@ -347,7 +347,7 @@ public class ModelBuilderFacade
if (!dataModelId.equals(model.getId()))
{
- String fileConnectionId = JcrConnectionManager.createFileConnection(model,
+ String fileConnectionId = WebModelerConnectionManager.createFileConnection(model,
dataModel);
String bundleId = CarnotConstants.DIAGRAM_PLUGIN_ID;
@@ -438,7 +438,7 @@ public class ModelBuilderFacade
if (!participantModelID.equals(model.getId()))
{
- String fileConnectionId = JcrConnectionManager.createFileConnection(model,
+ String fileConnectionId = WebModelerConnectionManager.createFileConnection(model,
participantModel);
String bundleId = CarnotConstants.DIAGRAM_PLUGIN_ID;
diff --git a/model/org.eclipse.stardust.model.xpdl.builder/src/main/java/org/eclipse/stardust/model/xpdl/builder/utils/WebModelerConnectionManager.java b/model/org.eclipse.stardust.model.xpdl.builder/src/main/java/org/eclipse/stardust/model/xpdl/builder/utils/WebModelerConnectionManager.java
new file mode 100644
index 0000000..e11e4ac
--- /dev/null
+++ b/model/org.eclipse.stardust.model.xpdl.builder/src/main/java/org/eclipse/stardust/model/xpdl/builder/utils/WebModelerConnectionManager.java
@@ -0,0 +1,905 @@
+/*******************************************************************************
+ * Copyright (c) 2011, 2012 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.utils;
+
+import java.lang.reflect.InvocationHandler;
+import java.lang.reflect.Method;
+import java.lang.reflect.Proxy;
+import java.text.MessageFormat;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+import javax.xml.namespace.QName;
+
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.emf.common.notify.Notification;
+import org.eclipse.emf.common.notify.impl.NotificationImpl;
+import org.eclipse.emf.common.util.URI;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.InternalEObject;
+import org.eclipse.emf.ecore.impl.EObjectImpl;
+import org.eclipse.stardust.common.CollectionUtils;
+import org.eclipse.stardust.engine.api.model.PredefinedConstants;
+import org.eclipse.stardust.model.xpdl.builder.connectionhandler.WebModelerConnectionHandler;
+import org.eclipse.stardust.model.xpdl.builder.strategy.ModelManagementStrategy;
+import org.eclipse.stardust.model.xpdl.carnot.ApplicationType;
+import org.eclipse.stardust.model.xpdl.carnot.AttributeType;
+import org.eclipse.stardust.model.xpdl.carnot.ConditionalPerformerType;
+import org.eclipse.stardust.model.xpdl.carnot.DataType;
+import org.eclipse.stardust.model.xpdl.carnot.IExtensibleElement;
+import org.eclipse.stardust.model.xpdl.carnot.ModelType;
+import org.eclipse.stardust.model.xpdl.carnot.OrganizationType;
+import org.eclipse.stardust.model.xpdl.carnot.ProcessDefinitionType;
+import org.eclipse.stardust.model.xpdl.carnot.RoleType;
+import org.eclipse.stardust.model.xpdl.carnot.util.AttributeUtil;
+import org.eclipse.stardust.model.xpdl.carnot.util.ModelUtils;
+import org.eclipse.stardust.model.xpdl.util.IConnection;
+import org.eclipse.stardust.model.xpdl.util.IConnectionManager;
+import org.eclipse.stardust.model.xpdl.util.IObjectReference;
+import org.eclipse.stardust.model.xpdl.xpdl2.ExtendedAttributeType;
+import org.eclipse.stardust.model.xpdl.xpdl2.ExternalPackage;
+import org.eclipse.stardust.model.xpdl.xpdl2.ExternalPackages;
+import org.eclipse.stardust.model.xpdl.xpdl2.TypeDeclarationType;
+import org.eclipse.stardust.model.xpdl.xpdl2.util.ExtendedAttributeUtil;
+import org.eclipse.stardust.modeling.repository.common.Attribute;
+import org.eclipse.stardust.modeling.repository.common.Connection;
+import org.eclipse.stardust.modeling.repository.common.ConnectionHandler;
+import org.eclipse.stardust.modeling.repository.common.ConnectionManager;
+import org.eclipse.stardust.modeling.repository.common.ExternalPackageResolver;
+import org.eclipse.stardust.modeling.repository.common.IFilter;
+import org.eclipse.stardust.modeling.repository.common.IObjectDescriptor;
+import org.eclipse.stardust.modeling.repository.common.ObjectRepositoryActivator;
+import org.eclipse.stardust.modeling.repository.common.Repository;
+import org.eclipse.stardust.modeling.repository.common.RepositoryFactory;
+import org.eclipse.stardust.modeling.repository.common.Repository_Messages;
+import org.eclipse.stardust.modeling.repository.common.descriptors.EObjectDescriptor;
+
+public class WebModelerConnectionManager implements IConnectionManager
+{
+ private static ModelManagementStrategy strategy;
+
+ private static final IFilter BY_REF_FILTER = new IFilter()
+ {
+ public boolean accept(Object object)
+ {
+ if (object instanceof EObjectDescriptor)
+ {
+ EObjectDescriptor eObjectdescriptor = (EObjectDescriptor) object;
+ if (eObjectdescriptor.getEObject() instanceof TypeDeclarationType)
+ {
+ TypeDeclarationType typeDeclaration = eObjectdescriptor.getEObject();
+ ExtendedAttributeType visibility = ExtendedAttributeUtil.getAttribute(
+ typeDeclaration.getExtendedAttributes(),
+ PredefinedConstants.MODELELEMENT_VISIBILITY);
+ if (visibility != null && "Private".equals(visibility.getValue())) //$NON-NLS-1$
+ {
+ return false;
+ }
+ }
+ if (eObjectdescriptor.getEObject() instanceof ApplicationType)
+ {
+ ApplicationType applicationType = eObjectdescriptor.getEObject();
+ AttributeType visibility = AttributeUtil.getAttribute(
+ (IExtensibleElement) applicationType,
+ PredefinedConstants.MODELELEMENT_VISIBILITY);
+ if (visibility != null && "Private".equals(visibility.getValue())) //$NON-NLS-1$
+ {
+ return false;
+ }
+ }
+ if (eObjectdescriptor.getEObject() instanceof RoleType)
+ {
+ RoleType roleType = eObjectdescriptor.getEObject();
+ AttributeType visibility = AttributeUtil.getAttribute(
+ (IExtensibleElement) roleType,
+ PredefinedConstants.MODELELEMENT_VISIBILITY);
+ if (visibility != null && "Private".equals(visibility.getValue())) //$NON-NLS-1$
+ {
+ return false;
+ }
+ }
+ if (eObjectdescriptor.getEObject() instanceof OrganizationType)
+ {
+ OrganizationType orgType = eObjectdescriptor.getEObject();
+ AttributeType visibility = AttributeUtil.getAttribute(
+ (IExtensibleElement) orgType,
+ PredefinedConstants.MODELELEMENT_VISIBILITY);
+ if (visibility != null && "Private".equals(visibility.getValue())) //$NON-NLS-1$
+ {
+ return false;
+ }
+ }
+ if (eObjectdescriptor.getEObject() instanceof ConditionalPerformerType)
+ {
+ ConditionalPerformerType conPerfType = eObjectdescriptor.getEObject();
+ AttributeType visibility = AttributeUtil.getAttribute(
+ (IExtensibleElement) conPerfType,
+ PredefinedConstants.MODELELEMENT_VISIBILITY);
+ if (visibility != null && "Private".equals(visibility.getValue())) //$NON-NLS-1$
+ {
+ return false;
+ }
+ }
+ if (eObjectdescriptor.getEObject() instanceof DataType)
+ {
+ DataType dataType = eObjectdescriptor.getEObject();
+ AttributeType visibility = AttributeUtil.getAttribute(
+ (IExtensibleElement) dataType,
+ PredefinedConstants.MODELELEMENT_VISIBILITY);
+ if (visibility != null && "Private".equals(visibility.getValue())) //$NON-NLS-1$
+ {
+ return false;
+ }
+ }
+ if (eObjectdescriptor.getEObject() instanceof ProcessDefinitionType)
+ {
+ ProcessDefinitionType process = (ProcessDefinitionType) eObjectdescriptor
+ .getEObject();
+ if (process.getFormalParameters() == null)
+ {
+ return false;
+ }
+ }
+ }
+ return true;
+ }
+ };
+
+ private Repository repository;
+
+ private Map<Connection, ConnectionHandler> handlers = CollectionUtils.newMap();
+
+ private ModelType model;
+
+
+ // attribute name
+
+ public void setModel(ModelType model)
+ {
+ this.model = model;
+ model.setConnectionManager(this);
+ }
+
+ public WebModelerConnectionManager(ModelType model, ModelManagementStrategy strategy)
+ {
+ this.strategy = strategy;
+ this.model = model;
+ this.model.setConnectionManager(this);
+
+ RepositoryFactory factory = RepositoryFactory.eINSTANCE;
+ repository = factory.createRepository();
+
+ Map<String, Object> infoMap = CollectionUtils.newMap(); // contains the actual
+ // attributes
+ List<String> infoList = CollectionUtils.newList(); // used to preserve the order
+
+ List<AttributeType> list = model.getAttribute();
+ for (int i = 0; i < list.size(); i++)
+ {
+ AttributeType att = (AttributeType) list.get(i);
+ String name = att.getName();
+ if (name.startsWith(CONNECTION_SCOPE))
+ {
+ name = name.substring(CONNECTION_SCOPE.length());
+ handleAttribute(infoMap, infoList, att, name);
+ }
+ }
+
+ ExternalPackageResolver externalPackageResolver = new ExternalPackageResolver(model);
+ model.eAdapters().add(externalPackageResolver);
+
+ for (int i = 0; i < infoList.size(); i++)
+ {
+ String identifier = (String) infoList.get(i);
+ @SuppressWarnings("unchecked")
+ Map<String, Object> attributes = (Map<String, Object>) infoMap.get(identifier);
+
+ Connection connection = factory.createConnection();
+ connection.setProperty(CONNECTION_MANAGER, this);
+ connection.setId((String) attributes.get("id")); //$NON-NLS-1$
+ connection.setName((String) attributes.get("name")); //$NON-NLS-1$
+ connection.setType((String) attributes.get("type")); //$NON-NLS-1$
+ @SuppressWarnings("unchecked")
+ Map<String, String> connectionAttributes = (Map<String, String>) attributes
+ .get("attribute"); //$NON-NLS-1$
+ if (connectionAttributes != null)
+ {
+ for (Iterator<Map.Entry<String, String>> itr = connectionAttributes
+ .entrySet().iterator(); itr.hasNext();)
+ {
+ Map.Entry<String, String> entry = itr.next();
+ Attribute attr = factory.createAttribute();
+ attr.setName(entry.getKey());
+ attr.setValue(entry.getValue());
+ connection.getAttributes().add(attr);
+ }
+ }
+ repository.getConnection().add(connection);
+ connection.eAdapters().add(externalPackageResolver);
+ }
+
+ }
+
+ private void handleAttribute(Map<String, Object> infoMap, List<String> infoList,
+ AttributeType att, String name)
+ {
+ int ix = name.indexOf(':');
+ if (ix > 0)
+ {
+ String identifier = name.substring(0, ix);
+ if (infoList != null && !infoList.contains(identifier))
+ {
+ infoList.add(identifier);
+ }
+ name = name.substring(ix + 1);
+ @SuppressWarnings("unchecked")
+ Map<String, Object> map = (Map<String, Object>) infoMap.get(identifier);
+ if (map == null)
+ {
+ map = CollectionUtils.newMap();
+ infoMap.put(identifier, map);
+ }
+ handleAttribute(map, null, att, name);
+ }
+ else
+ {
+ infoMap.put(name, att.getValue());
+ }
+ }
+
+ public void close()
+ {
+ for (Map.Entry<Connection, ConnectionHandler> entry : handlers.entrySet())
+ {
+ try
+ {
+ entry.getValue().close(entry.getKey());
+ }
+ catch (CoreException e)
+ {
+ e.printStackTrace();
+ }
+ }
+ save();
+ }
+
+ public void save()
+ {
+ List<AttributeType> list = model.getAttribute();
+ for (Iterator<AttributeType> i = list.iterator(); i.hasNext();)
+ {
+ AttributeType att = i.next();
+ String name = att.getName();
+ if (name.startsWith(CONNECTION_SCOPE))
+ {
+ i.remove();
+ }
+ }
+
+ List<Connection> connections = repository.getConnection();
+ for (int i = 0; i < connections.size(); i++)
+ {
+ Connection connection = (Connection) connections.get(i);
+ String identifier = CONNECTION_SCOPE + String.valueOf(i + 1) + ':';
+ AttributeUtil.setAttribute(model, identifier + "id", connection.getId()); //$NON-NLS-1$
+ AttributeUtil.setAttribute(model, identifier + "name", connection.getName()); //$NON-NLS-1$
+ AttributeUtil.setAttribute(model, identifier + "type", connection.getType()); //$NON-NLS-1$
+ List<Attribute> attributes = connection.getAttributes();
+ for (int j = 0; j < attributes.size(); j++)
+ {
+ Attribute attribute = (Attribute) attributes.get(j);
+ AttributeUtil.setAttribute(model, identifier + "attribute:" //$NON-NLS-1$
+ + attribute.getName(), attribute.getValue());
+ }
+ }
+ }
+
+ public void setAllConnections(List<Connection> connections)
+ {
+ repository.getConnection().addAll(connections);
+ }
+
+ public List<Connection> getAllConnections()
+ {
+ return repository.getConnection();
+ }
+
+ public Iterator<Connection> getConnections()
+ {
+ return repository.getConnection().iterator();
+ }
+
+ public Connection getConnectionForAttribute(String filename)
+ {
+ for (Connection connection : repository.getConnection())
+ {
+ List<Attribute> attributes = connection.getAttributes();
+ for (int j = 0; j < attributes.size(); j++)
+ {
+ Attribute attribute = (Attribute) attributes.get(j);
+ if(attribute.getName().equals("filename"))
+ {
+ if (attribute.getValue().equals(filename))
+ {
+ return connection;
+ }
+ }
+ }
+ }
+ return null;
+ }
+
+
+ public Connection getConnection(String id)
+ {
+ for (Connection connection : repository.getConnection())
+ {
+ if (id.equals(connection.getId()))
+ {
+ return connection;
+ }
+ }
+ return null;
+ }
+
+ public Connection create(String type) throws CoreException
+ {
+ Connection connection = createConnection(type);
+ connection.setProperty(CONNECTION_MANAGER_CREATED, "true"); //$NON-NLS-1$
+ repository.getConnection().add(connection);
+ return connection;
+ }
+
+ private Connection createConnection(String type) throws CoreException
+ {
+ //IConfigurationElement config = getConfigurationElement(type);
+ String baseId = type;
+ String baseName = type; // config.getAttribute(SpiConstants.NAME);
+
+ int counter = 0;
+ for (Connection connection : repository.getConnection())
+ {
+ counter = getPostfixNumber(connection.getId(), baseId, '_', counter);
+ counter = getPostfixNumber(connection.getName(), baseName, ' ', counter);
+ }
+
+ RepositoryFactory factory = RepositoryFactory.eINSTANCE;
+ Connection connection = factory.createConnection();
+ connection.setProperty(CONNECTION_MANAGER, this);
+ connection.setId(counter == 0 ? baseId : baseId + '_' + counter);
+ connection.setName(counter == 0 ? baseName : baseName + ' ' + counter);
+ connection.setType(type);
+ Attribute attribute = factory.createAttribute();
+ attribute.setName(BY_REFERENCE);
+ attribute.setValue("true"); //$NON-NLS-1$
+ connection.getAttributes().add(attribute);
+
+ return connection;
+ }
+
+ private int getPostfixNumber(String actual, String base, char separator, int c)
+ {
+ if (base.equals(actual) && c == 0)
+ {
+ c = 1;
+ }
+ else if (actual != null && actual.startsWith(base + separator))
+ {
+ try
+ {
+ int number = Integer.parseInt(actual.substring(base.length() + 1));
+ c = Math.max(c, number + 1);
+ }
+ catch (Exception ex)
+ {
+ }
+ }
+ return c;
+ }
+
+ public ConnectionHandler getConnectionHandler(Connection connection)
+ {
+ return (ConnectionHandler) handlers.get(connection);
+ }
+
+ public boolean isOpen(Connection connection)
+ {
+ return handlers.containsKey(connection);
+ }
+
+ public void open(Connection connection) throws CoreException
+ {
+ ConnectionHandler handler = (ConnectionHandler) handlers.get(connection);
+ if (handler == null)
+ {
+ handler = createHandler(connection.getType());
+ handler.open(connection);
+ handlers.put(connection, handler);
+ }
+ }
+
+
+
+ private ConnectionHandler createHandler(String type) throws CoreException
+ {
+ return new WebModelerConnectionHandler(strategy);
+ }
+
+ public void close(Connection connection) throws CoreException
+ {
+ ConnectionHandler handler = (ConnectionHandler) handlers.get(connection);
+ if (handler != null)
+ {
+ handler.close(connection);
+ handlers.remove(connection);
+ }
+ }
+
+ public Repository getRepository()
+ {
+ return repository;
+ }
+
+ public List<IObjectDescriptor> select(Connection connection, IFilter[] filters)
+ throws CoreException
+ {
+ /*if (isLinked)
+ {
+ filters = new IFilter[] {new LinkedFilter(filters)};
+ }*/
+ filters = getFilters(filters, "true".equals(connection.getAttribute(BY_REFERENCE))); //$NON-NLS-1$
+ ConnectionHandler handler = (ConnectionHandler) handlers.get(connection);
+ if (handler != null)
+ {
+ List<IObjectDescriptor> result = handler.select(filters);
+ return filters == null ? result : decorateWithFilters(result, filters);
+ }
+ String message = MessageFormat.format(Repository_Messages.MSG_FORMAT_CONNECTION_NULL_IS_CLOSED,
+ new Object[] {connection.getId()});
+ throw new CoreException(new Status(IStatus.ERROR,
+ ObjectRepositoryActivator.PLUGIN_ID, 0, message, null));
+ }
+
+ private List<IObjectDescriptor> decorateWithFilters(List<IObjectDescriptor> result, IFilter[] filters)
+ {
+ List<IObjectDescriptor> descriptors = CollectionUtils.newList(result.size());
+ for (IObjectDescriptor desc : result)
+ {
+ descriptors.add(getFilteredObjectDescriptor(desc, filters));
+ }
+ return descriptors;
+ }
+
+ private IObjectDescriptor getFilteredObjectDescriptor(final IObjectDescriptor desc,
+ final IFilter[] filters)
+ {
+ InvocationHandler handler = new InvocationHandler()
+ {
+ public Object invoke(Object proxy, Method method, Object[] args)
+ throws Throwable
+ {
+ if (IObjectDescriptor.class.equals(method.getDeclaringClass()) && "getChildren".equals(method.getName())) //$NON-NLS-1$
+ {
+ IObjectDescriptor[] children = desc.getChildren();
+ List<IObjectDescriptor> filtered = CollectionUtils.newList();
+ for (int i = 0; i < children.length; i++)
+ {
+ if (BY_REF_FILTER.accept(children[i]))
+ {
+ filtered.add(getFilteredObjectDescriptor(children[i], filters));
+ }
+ }
+ return filtered.toArray(new IObjectDescriptor[filtered.size()]);
+ }
+ return method.invoke(desc, args);
+ }
+ };
+ ClassLoader classLoader = desc.getClass().getClassLoader();
+ Class<?>[] interfaces = getInterfaces(desc);
+ return (IObjectDescriptor) Proxy.newProxyInstance(classLoader, interfaces, handler);
+ }
+
+
+ private Class< ? >[] getInterfaces(IObjectDescriptor desc)
+ {
+ List<Class< ? >> result = new ArrayList<Class< ? >>();
+ Class< ? >[] interfaces = desc.getClass().getInterfaces();
+ for (int i = 0; i < interfaces.length; i++)
+ {
+ result.add(interfaces[i]);
+ }
+ if (desc.getClass().getSuperclass() != null)
+ {
+ interfaces = desc.getClass().getSuperclass().getInterfaces();
+ for (int i = 0; i < interfaces.length; i++)
+ {
+ result.add(interfaces[i]);
+ }
+ }
+ return (Class< ? >[]) result.toArray((new Class< ? >[result.size()]));
+ }
+
+ /**
+ * TODO describe
+ * @param filters
+ * @param byReference
+ * @return
+ */
+ private IFilter[] getFilters(IFilter[] filters, boolean byReference)
+ {
+ if (filters != null || byReference)
+ {
+ List<IFilter> list = CollectionUtils.newList();
+ if (filters != null)
+ {
+ for (int i = 0; i < filters.length; i++)
+ {
+ if (filters[i] != null)
+ {
+ list.add(filters[i]);
+ }
+ }
+ }
+ if (byReference)
+ {
+ list.add(BY_REF_FILTER);
+ }
+ if (list.size() > 0)
+ {
+ return list.toArray(new IFilter[list.size()]);
+ }
+ }
+ return null;
+ }
+
+ public static URI makeURI(Connection connection)
+ {
+ String id = connection.getId();
+ return URI.createURI(SCHEME + "://" + id + "/"); //$NON-NLS-1$ //$NON-NLS-2$
+ // return URI.createHierarchicalURI(SCHEME, id == null ? "_" : id, null, null,
+ // null);
+ }
+
+ public EObject find(String uri)
+ {
+ try
+ {
+ return find(URI.createURI(uri));
+ }
+ catch (Exception ex)
+ {
+ // ignore
+ }
+ return null;
+ }
+
+ public IConnection findConnection(String uri)
+ {
+ try
+ {
+ return findConnection(URI.createURI(uri));
+ }
+ catch (Exception ex)
+ {
+ // ignore
+ }
+ return null;
+ }
+
+ public EObject find(URI uri)
+ {
+ Connection connection = (Connection) findConnection(uri);
+ if (connection != null)
+ {
+ try
+ {
+ open(connection);
+ }
+ catch (CoreException e)
+ {
+ }
+ ConnectionHandler handler = (ConnectionHandler) handlers.get(connection);
+ if (handler != null)
+ {
+ return handler.find(uri);
+ }
+ }
+ return null;
+ }
+
+ public IConnection findConnection(URI uri)
+ {
+ if (SCHEME.equals(uri.scheme()))
+ {
+ String id = uri.authority();
+ return getConnection(id);
+ }
+ return null;
+ }
+
+ public boolean mustLink(IObjectDescriptor descriptor)
+ {
+ URI uri = descriptor.getURI();
+ String id = uri.authority();
+ Connection connection = getConnection(id);
+ if (connection == null)
+ {
+ return false;
+ }
+ return "true".equals(connection.getAttribute(BY_REFERENCE)); //$NON-NLS-1$
+ }
+
+ /*public Command linkObject(ModelType model, IObjectDescriptor[] descriptors)
+ throws CoreException
+ {
+ ArrayList<Connection> connections = new ArrayList<Connection>();
+ UsageDisplayDialog.setUsage(null);
+
+ ChangeRecorder recorder = new ChangeRecorder(model);
+
+ String id;
+ IObjectDescriptor[] entryValues;
+ Map<String, ArrayList<IObjectDescriptor>> container = CollectionUtils.newMap();
+ Connection connection;
+
+ // collect descriptors for each connection
+ sortDescriptors(descriptors, container);
+
+ // here loop through all connections found
+ Iterator<Map.Entry<String, ArrayList<IObjectDescriptor>>> it = container.entrySet()
+ .iterator();
+ while (it.hasNext())
+ {
+ Map.Entry<String, ArrayList<IObjectDescriptor>> entry = it.next();
+ id = entry.getKey();
+ entryValues = (IObjectDescriptor[]) entry.getValue().toArray(
+ new IObjectDescriptor[0]);
+
+ connection = getConnection(id);
+ if (connection == null)
+ {
+ String message = MessageFormat.format(Repository_Messages.MSG_FORMAT_CONNECTION_NULL_DOES_NOT_EXIST,
+ new Object[] {id});
+ throw new CoreException(new Status(IStatus.ERROR,
+ ObjectRepositoryActivator.PLUGIN_ID, 0, message, null));
+ }
+ connections.add(connection);
+ ConnectionHandler handler = (ConnectionHandler) handlers.get(connection);
+ if (handler != null)
+ {
+ try
+ {
+ handler.importObject(model, entryValues, "true".equals(connection //$NON-NLS-1$
+ .getAttribute(BY_REFERENCE)));
+ }
+ catch (ImportCancelledException ice)
+ {
+ recorder.dispose();
+ return null;
+ }
+ }
+ }
+ final ChangeDescription changes = recorder.endRecording();
+ //rp: Workaround for CRNT-23880
+ reloadConnections(connections);
+ return new Command()
+ {
+ public void execute()
+ {
+ // nothing to be done as the changes are already applied
+ }
+
+ public void undo()
+ {
+ changes.applyAndReverse();
+ }
+
+ public void redo()
+ {
+ changes.applyAndReverse();
+ }
+ };
+ }*/
+
+ private void sortDescriptors(IObjectDescriptor[] descriptors,
+ Map<String, ArrayList<IObjectDescriptor>> container)
+ {
+ URI uri;
+ String id;
+ IObjectDescriptor descriptor;
+ ArrayList<IObjectDescriptor> descriptorValues;
+ for (int i = 0; i < descriptors.length; i++)
+ {
+ descriptor = descriptors[i];
+ uri = descriptor.getURI();
+ id = uri.authority();
+ // is the key inside?
+ if (container.containsKey(id))
+ {
+ descriptorValues = container.get(id);
+ descriptorValues.add(descriptors[i]);
+ container.put(id, descriptorValues);
+ }
+ else
+ {
+ descriptorValues = new ArrayList<IObjectDescriptor>();
+ descriptorValues.add(descriptors[i]);
+ container.put(id, descriptorValues);
+ }
+ }
+ }
+
+ public void resolve()
+ {
+ for (Iterator<EObject> i = model.eContents().iterator(); i.hasNext();)
+ {
+ EObject object = i.next();
+ if (object.eIsProxy())
+ {
+ if (object instanceof EObjectImpl)
+ {
+ URI uri = ((EObjectImpl) object).eProxyURI();
+
+ // decode uri from the format produced by xpdl transformation
+ if (uri.opaquePart() != null)
+ {
+ try
+ {
+ QName qname = QName.valueOf(uri.opaquePart());
+ if (model.getExternalPackages() != null)
+ {
+ ExternalPackage pkg = model.getExternalPackages().getExternalPackage(qname.getNamespaceURI());
+ if (pkg != null)
+ {
+ String pkgConnectionUri = ExtendedAttributeUtil.getAttributeValue(pkg, IConnectionManager.URI_ATTRIBUTE_NAME);
+ uri = URI.createURI(pkgConnectionUri + uri.scheme() + '/' + qname.getLocalPart());
+ ((InternalEObject) object).eSetProxyURI(uri);
+ }
+ }
+ }
+ catch (Exception ex)
+ {
+ // not a special reference
+ }
+ }
+
+ resolve(object, uri);
+ }
+ }
+ /*
+ * else if (object instanceof IExtensibleElement) { String uriValue =
+ * AttributeUtil.getAttributeValue((IExtensibleElement) object,
+ * URI_ATTRIBUTE_NAME); if (uriValue != null) { URI uri =
+ * URI.createURI(uriValue); resolve(object, uri); } }
+ */
+ }
+ }
+
+ private void resolve(EObject object, URI uri)
+ {
+ if (SCHEME.equals(uri.scheme()))
+ {
+ String id = uri.authority();
+ Connection connection = getConnection(id);
+ if (connection != null)
+ {
+ try
+ {
+ open(connection);
+ }
+ catch (CoreException e)
+ {
+ }
+ ConnectionHandler handler = (ConnectionHandler) handlers.get(connection);
+ if (handler != null)
+ {
+ handler.resolve(model, object);
+ }
+ }
+ }
+ }
+
+ public static URI getURI(EObject object)
+ {
+ if (object.eIsProxy() && object instanceof InternalEObject)
+ {
+ return ((InternalEObject) object).eProxyURI();
+ }
+ if (object instanceof IExtensibleElement)
+ {
+ String uri = AttributeUtil.getAttributeValue((IExtensibleElement) object,
+ URI_ATTRIBUTE_NAME);
+ try
+ {
+ return URI.createURI(uri);
+ }
+ catch (Exception ex)
+ {
+ // ignore
+ }
+ }
+ return null;
+ }
+
+ public void setConnectionManager(Connection connection)
+ {
+ connection.setProperty(CONNECTION_MANAGER, this);
+ }
+
+ public static ConnectionManager getConnectionManager(Connection connection)
+ {
+ return (ConnectionManager) connection.getProperty(CONNECTION_MANAGER);
+ }
+
+ public ModelType find(ExternalPackage pkg)
+ {
+ if (pkg != null)
+ {
+ ModelType model = ModelUtils.findContainingModel(pkg);
+ if (model != null)
+ {
+ String uri = ExtendedAttributeUtil.getAttributeValue(pkg,
+ IConnectionManager.URI_ATTRIBUTE_NAME);
+ EObject eObject = find(uri);
+ if (eObject instanceof IObjectReference)
+ {
+ eObject = ((IObjectReference) eObject).getEObject();
+ }
+ if (eObject instanceof ModelType)
+ {
+ return (ModelType) eObject;
+ }
+ }
+ }
+ return null;
+ }
+
+ public ModelType getModel()
+ {
+ return model;
+ }
+
+ public static String createFileConnection(ModelType model, ModelType referencedModel)
+ {
+ String id = null;
+
+ WebModelerConnectionManager jcrConnectionManager = XpdlModelIoUtils.getJcrConnectionManager(model, strategy);
+ IConnection findConnection = jcrConnectionManager.getConnectionForAttribute("project:/" + referencedModel.getName() + ".xpdl");
+
+ if(findConnection == null)
+ {
+ try
+ {
+ Connection connection = jcrConnectionManager.create("file");
+ id = connection.getId();
+ RepositoryFactory factory = RepositoryFactory.eINSTANCE;
+
+ Attribute attribute = factory.createAttribute();
+ attribute.setName("filename");
+ attribute.setValue("project:/" + referencedModel.getName() + ".xpdl"); //$NON-NLS-1$
+ connection.getAttributes().add(attribute);
+ }
+ catch (CoreException e)
+ {
+ }
+ }
+ else
+ {
+ id = findConnection.getId();
+ }
+
+ return id;
+ }
+} \ No newline at end of file
diff --git a/model/org.eclipse.stardust.model.xpdl.builder/src/main/java/org/eclipse/stardust/model/xpdl/builder/utils/WebModelerModelManager.java b/model/org.eclipse.stardust.model.xpdl.builder/src/main/java/org/eclipse/stardust/model/xpdl/builder/utils/WebModelerModelManager.java
new file mode 100644
index 0000000..96a4156
--- /dev/null
+++ b/model/org.eclipse.stardust.model.xpdl.builder/src/main/java/org/eclipse/stardust/model/xpdl/builder/utils/WebModelerModelManager.java
@@ -0,0 +1,113 @@
+/*******************************************************************************
+ * Copyright (c) 2012 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.utils;
+
+import java.io.File;
+import java.io.IOException;
+
+import javax.xml.transform.TransformerFactory;
+
+import org.eclipse.emf.common.util.URI;
+import org.eclipse.stardust.common.StringUtils;
+import org.eclipse.stardust.common.config.Parameters;
+import org.eclipse.stardust.common.utils.xml.XmlProperties;
+import org.eclipse.stardust.engine.core.model.xpdl.XpdlUtils;
+import org.eclipse.stardust.model.xpdl.builder.strategy.ModelManagementStrategy;
+import org.eclipse.stardust.model.xpdl.carnot.ModelType;
+import org.eclipse.stardust.model.xpdl.carnot.util.WorkflowModelManager;
+
+public class WebModelerModelManager extends WorkflowModelManager
+{
+ private WebModelerConnectionManager manager;
+ private ModelType saveModel;
+ private ModelManagementStrategy strategy;
+
+ public WebModelerModelManager()
+ {
+ super();
+ }
+
+ public WebModelerModelManager(ModelManagementStrategy strategy)
+ {
+ this.strategy = strategy;
+ }
+
+ public void setModel(ModelType model)
+ {
+ saveModel = model;
+ }
+
+ @Override
+ public void resolve(ModelType model)
+ {
+ if (model != null && model.getId() != null)
+ {
+ manager = XpdlModelIoUtils.getJcrConnectionManager(model, strategy);
+ manager.resolve();
+ }
+ super.resolve(model);
+ }
+
+ public void save(URI uri) throws IOException
+ {
+ if (manager == null)
+ {
+ manager = XpdlModelIoUtils.getJcrConnectionManager(saveModel, strategy);
+ if(saveModel.getConnectionManager() == null)
+ {
+ saveModel.setConnectionManager(manager);
+ }
+ }
+ else
+ {
+ manager.setModel(saveModel);
+ }
+ manager.save();
+
+ super.save(uri);
+ }
+
+ public WebModelerConnectionManager getConnectionManager()
+ {
+ return manager;
+ }
+
+ public static ModelType loadModel(File modelXml) throws IOException
+ {
+ // optionally override default TraxFactory to get rid of a Xalan related bug of loosing namespace alias declarations
+ final String ippTraxFactory = Parameters.instance().getString(
+ XmlProperties.XSLT_TRANSFORMER_FACTORY);
+
+ final String traxFactoryOverride = System.getProperty(TransformerFactory.class.getName());
+ try
+ {
+ if ( !StringUtils.isEmpty(ippTraxFactory))
+ {
+ System.setProperty(TransformerFactory.class.getName(), ippTraxFactory);
+ }
+
+ WorkflowModelManager modelMgr = new WorkflowModelManager();
+
+ modelMgr.load(modelXml);
+
+ return modelMgr.getModel();
+ }
+ finally
+ {
+ if ( !StringUtils.isEmpty(ippTraxFactory) && !StringUtils.isEmpty(traxFactoryOverride))
+ {
+ System.setProperty(TransformerFactory.class.getName(),
+ traxFactoryOverride);
+ }
+ }
+ }
+} \ No newline at end of file
diff --git a/model/org.eclipse.stardust.model.xpdl.builder/src/main/java/org/eclipse/stardust/model/xpdl/builder/utils/XpdlModelIoUtils.java b/model/org.eclipse.stardust.model.xpdl.builder/src/main/java/org/eclipse/stardust/model/xpdl/builder/utils/XpdlModelIoUtils.java
index 9901f84..9342122 100644
--- a/model/org.eclipse.stardust.model.xpdl.builder/src/main/java/org/eclipse/stardust/model/xpdl/builder/utils/XpdlModelIoUtils.java
+++ b/model/org.eclipse.stardust.model.xpdl.builder/src/main/java/org/eclipse/stardust/model/xpdl/builder/utils/XpdlModelIoUtils.java
@@ -56,7 +56,7 @@ public class XpdlModelIoUtils
public static final byte[] EMPTY_BUFFER = new byte[0];
private static final int COPY_BUFFER_LENGHT = 16 * 1024;
- private static Map<String, JcrConnectionManager> map = new HashMap<String, JcrConnectionManager>();
+ private static Map<String, WebModelerConnectionManager> map = new HashMap<String, WebModelerConnectionManager>();
private static Map<String, ModelType> modelMap = new HashMap<String, ModelType>();
public static ModelType getModelById(String id)
@@ -64,17 +64,17 @@ public class XpdlModelIoUtils
return modelMap.get(id);
}
- public static JcrConnectionManager getJcrConnectionManager(ModelType model, ModelManagementStrategy strategy)
+ public static WebModelerConnectionManager getJcrConnectionManager(ModelType model, ModelManagementStrategy strategy)
{
if(modelMap.get(model.getId()) == null)
{
modelMap.put(model.getId(), model);
}
- JcrConnectionManager manager = map.get(model.getId());
+ WebModelerConnectionManager manager = map.get(model.getId());
if(manager == null)
{
- manager = new JcrConnectionManager(model, strategy);
+ manager = new WebModelerConnectionManager(model, strategy);
map.put(model.getId(), manager);
}
@@ -135,7 +135,7 @@ public class XpdlModelIoUtils
System.setProperty(TransformerFactory.class.getName(), ippTraxFactory);
}
- WorkflowModelManager modelMgr = new JcrModelManager(strategy);
+ WorkflowModelManager modelMgr = new WebModelerModelManager(strategy);
try
{
@@ -166,7 +166,7 @@ public class XpdlModelIoUtils
File tmpModel = null;
try
{
- JcrModelManager modelMgr = new JcrModelManager();
+ WebModelerModelManager modelMgr = new WebModelerModelManager();
tmpModel = File.createTempFile("tmp-xpdl-model-", "." + XpdlUtils.EXT_XPDL);
tmpModel.deleteOnExit();
diff --git a/model/org.eclipse.stardust.model.xpdl.builder/src/main/java/org/eclipse/stardust/model/xpdl/builder/variable/BpmStructVariableBuilder.java b/model/org.eclipse.stardust.model.xpdl.builder/src/main/java/org/eclipse/stardust/model/xpdl/builder/variable/BpmStructVariableBuilder.java
index 7d26fa9..af1a5f5 100644
--- a/model/org.eclipse.stardust.model.xpdl.builder/src/main/java/org/eclipse/stardust/model/xpdl/builder/variable/BpmStructVariableBuilder.java
+++ b/model/org.eclipse.stardust.model.xpdl.builder/src/main/java/org/eclipse/stardust/model/xpdl/builder/variable/BpmStructVariableBuilder.java
@@ -16,7 +16,7 @@ import org.eclipse.emf.common.util.URI;
import org.eclipse.stardust.engine.api.model.PredefinedConstants;
import org.eclipse.stardust.engine.core.struct.StructuredDataConstants;
import org.eclipse.stardust.model.xpdl.builder.common.AbstractModelElementBuilder;
-import org.eclipse.stardust.model.xpdl.builder.utils.JcrConnectionManager;
+import org.eclipse.stardust.model.xpdl.builder.utils.WebModelerConnectionManager;
import org.eclipse.stardust.model.xpdl.builder.utils.XpdlModelUtils;
import org.eclipse.stardust.model.xpdl.carnot.DataType;
import org.eclipse.stardust.model.xpdl.carnot.DataTypeType;
@@ -110,7 +110,7 @@ public class BpmStructVariableBuilder
{
TypeDeclarationType typeDeclaration = getTypeDeclaration(typeDeclarationModel, declId);
- String fileConnectionId = JcrConnectionManager.createFileConnection(model, typeDeclarationModel);
+ String fileConnectionId = WebModelerConnectionManager.createFileConnection(model, typeDeclarationModel);
String bundleId = CarnotConstants.DIAGRAM_PLUGIN_ID;
URI uri = URI.createURI("cnx://" + fileConnectionId + "/");