summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRainer Pielmann2012-08-20 09:07:32 (EDT)
committerManik Kishore2012-08-20 09:07:32 (EDT)
commitcb060f0f2e0b0c43cc225047d7704d65a090f6e7 (patch)
tree032ce8b4c8317c074bdf3ab6b8f33b48b35160fa
parentdf30c9661395c9ccc14d65b1382efe71951680d6 (diff)
downloadorg.eclipse.stardust.ide-cb060f0f2e0b0c43cc225047d7704d65a090f6e7.zip
org.eclipse.stardust.ide-cb060f0f2e0b0c43cc225047d7704d65a090f6e7.tar.gz
org.eclipse.stardust.ide-cb060f0f2e0b0c43cc225047d7704d65a090f6e7.tar.bz2
CRNT-25760 Refactor/Clean up MB Facade: Renamed "JCRxxxxxx" to "WebModelerxxxxxx"
git-svn-id: http://emeafrazerg/svn/ipp/product/trunk/stardust/ide@58554 8100b5e0-4d52-466c-ae9c-bdeccbdeaf6b
-rw-r--r--model/org.eclipse.stardust.model.xpdl.builder/src/main/java/org/eclipse/stardust/model/xpdl/builder/connectionhandler/JcrConnectionHandler.java287
-rw-r--r--model/org.eclipse.stardust.model.xpdl.builder/src/main/java/org/eclipse/stardust/model/xpdl/builder/utils/JcrConnectionManager.java905
-rw-r--r--model/org.eclipse.stardust.model.xpdl.builder/src/main/java/org/eclipse/stardust/model/xpdl/builder/utils/JcrModelManager.java113
-rw-r--r--model/org.eclipse.stardust.model.xpdl.builder/src/main/java/org/eclipse/stardust/model/xpdl/builder/utils/MBFacade.java1757
4 files changed, 0 insertions, 3062 deletions
diff --git a/model/org.eclipse.stardust.model.xpdl.builder/src/main/java/org/eclipse/stardust/model/xpdl/builder/connectionhandler/JcrConnectionHandler.java b/model/org.eclipse.stardust.model.xpdl.builder/src/main/java/org/eclipse/stardust/model/xpdl/builder/connectionhandler/JcrConnectionHandler.java
deleted file mode 100644
index 1767b75..0000000
--- a/model/org.eclipse.stardust.model.xpdl.builder/src/main/java/org/eclipse/stardust/model/xpdl/builder/connectionhandler/JcrConnectionHandler.java
+++ /dev/null
@@ -1,287 +0,0 @@
-/*******************************************************************************
- * 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.JcrConnectionManager;
-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 JcrConnectionHandler 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 JcrConnectionHandler(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 = JcrConnectionManager.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 = JcrConnectionManager.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/JcrConnectionManager.java b/model/org.eclipse.stardust.model.xpdl.builder/src/main/java/org/eclipse/stardust/model/xpdl/builder/utils/JcrConnectionManager.java
deleted file mode 100644
index 26134b8..0000000
--- a/model/org.eclipse.stardust.model.xpdl.builder/src/main/java/org/eclipse/stardust/model/xpdl/builder/utils/JcrConnectionManager.java
+++ /dev/null
@@ -1,905 +0,0 @@
-/*******************************************************************************
- * 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.JcrConnectionHandler;
-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 JcrConnectionManager 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 JcrConnectionManager(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 JcrConnectionHandler(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;
-
- JcrConnectionManager 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/JcrModelManager.java b/model/org.eclipse.stardust.model.xpdl.builder/src/main/java/org/eclipse/stardust/model/xpdl/builder/utils/JcrModelManager.java
deleted file mode 100644
index a4d9e1b..0000000
--- a/model/org.eclipse.stardust.model.xpdl.builder/src/main/java/org/eclipse/stardust/model/xpdl/builder/utils/JcrModelManager.java
+++ /dev/null
@@ -1,113 +0,0 @@
-/*******************************************************************************
- * 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 JcrModelManager extends WorkflowModelManager
-{
- private JcrConnectionManager manager;
- private ModelType saveModel;
- private ModelManagementStrategy strategy;
-
- public JcrModelManager()
- {
- super();
- }
-
- public JcrModelManager(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 JcrConnectionManager 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/MBFacade.java b/model/org.eclipse.stardust.model.xpdl.builder/src/main/java/org/eclipse/stardust/model/xpdl/builder/utils/MBFacade.java
deleted file mode 100644
index 19d465d..0000000
--- a/model/org.eclipse.stardust.model.xpdl.builder/src/main/java/org/eclipse/stardust/model/xpdl/builder/utils/MBFacade.java
+++ /dev/null
@@ -1,1757 +0,0 @@
-/*******************************************************************************
- * 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 static org.eclipse.stardust.engine.api.model.PredefinedConstants.ADMINISTRATOR_ROLE;
-import static org.eclipse.stardust.model.xpdl.builder.BpmModelBuilder.newApplicationActivity;
-import static org.eclipse.stardust.model.xpdl.builder.BpmModelBuilder.newDocumentVariable;
-import static org.eclipse.stardust.model.xpdl.builder.BpmModelBuilder.newManualActivity;
-import static org.eclipse.stardust.model.xpdl.builder.BpmModelBuilder.newManualTrigger;
-import static org.eclipse.stardust.model.xpdl.builder.BpmModelBuilder.newOrganization;
-import static org.eclipse.stardust.model.xpdl.builder.BpmModelBuilder.newPrimitiveVariable;
-import static org.eclipse.stardust.model.xpdl.builder.BpmModelBuilder.newProcessDefinition;
-import static org.eclipse.stardust.model.xpdl.builder.BpmModelBuilder.newRole;
-import static org.eclipse.stardust.model.xpdl.builder.BpmModelBuilder.newRouteActivity;
-import static org.eclipse.stardust.model.xpdl.builder.BpmModelBuilder.newStructVariable;
-import static org.eclipse.stardust.model.xpdl.builder.BpmModelBuilder.newSubProcessActivity;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import org.eclipse.emf.common.util.EList;
-import org.eclipse.emf.common.util.URI;
-import org.eclipse.emf.ecore.EObject;
-import org.eclipse.emf.ecore.xmi.XMLResource;
-import org.eclipse.stardust.common.StringUtils;
-import org.eclipse.stardust.common.error.ObjectNotFoundException;
-import org.eclipse.stardust.engine.core.pojo.data.Type;
-import org.eclipse.stardust.engine.core.struct.StructuredDataConstants;
-import org.eclipse.stardust.model.xpdl.builder.activity.BpmApplicationActivityBuilder;
-import org.eclipse.stardust.model.xpdl.builder.activity.BpmSubProcessActivityBuilder;
-import org.eclipse.stardust.model.xpdl.builder.common.AbstractElementBuilder;
-import org.eclipse.stardust.model.xpdl.builder.strategy.ModelManagementStrategy;
-import org.eclipse.stardust.model.xpdl.builder.variable.BpmDocumentVariableBuilder;
-import org.eclipse.stardust.model.xpdl.builder.variable.BpmStructVariableBuilder;
-import org.eclipse.stardust.model.xpdl.carnot.ActivitySymbolType;
-import org.eclipse.stardust.model.xpdl.carnot.ActivityType;
-import org.eclipse.stardust.model.xpdl.carnot.ApplicationContextTypeType;
-import org.eclipse.stardust.model.xpdl.carnot.ApplicationType;
-import org.eclipse.stardust.model.xpdl.carnot.ApplicationTypeType;
-import org.eclipse.stardust.model.xpdl.carnot.DataMappingConnectionType;
-import org.eclipse.stardust.model.xpdl.carnot.DataPathType;
-import org.eclipse.stardust.model.xpdl.carnot.DataSymbolType;
-import org.eclipse.stardust.model.xpdl.carnot.DataType;
-import org.eclipse.stardust.model.xpdl.carnot.DataTypeType;
-import org.eclipse.stardust.model.xpdl.carnot.DiagramModeType;
-import org.eclipse.stardust.model.xpdl.carnot.DiagramType;
-import org.eclipse.stardust.model.xpdl.carnot.EndEventSymbol;
-import org.eclipse.stardust.model.xpdl.carnot.IIdentifiableModelElement;
-import org.eclipse.stardust.model.xpdl.carnot.IModelParticipant;
-import org.eclipse.stardust.model.xpdl.carnot.LaneSymbol;
-import org.eclipse.stardust.model.xpdl.carnot.ModelType;
-import org.eclipse.stardust.model.xpdl.carnot.OrganizationType;
-import org.eclipse.stardust.model.xpdl.carnot.OrientationType;
-import org.eclipse.stardust.model.xpdl.carnot.ParticipantType;
-import org.eclipse.stardust.model.xpdl.carnot.PoolSymbol;
-import org.eclipse.stardust.model.xpdl.carnot.ProcessDefinitionType;
-import org.eclipse.stardust.model.xpdl.carnot.RoleType;
-import org.eclipse.stardust.model.xpdl.carnot.StartEventSymbol;
-import org.eclipse.stardust.model.xpdl.carnot.TransitionConnectionType;
-import org.eclipse.stardust.model.xpdl.carnot.util.CarnotConstants;
-import org.eclipse.stardust.model.xpdl.carnot.util.ModelUtils;
-import org.eclipse.stardust.model.xpdl.xpdl2.SchemaTypeType;
-import org.eclipse.stardust.model.xpdl.xpdl2.TypeDeclarationType;
-import org.eclipse.stardust.model.xpdl.xpdl2.XpdlFactory;
-import org.eclipse.stardust.model.xpdl.xpdl2.util.TypeDeclarationUtils;
-import org.eclipse.stardust.modeling.repository.common.descriptors.ReplaceModelElementDescriptor;
-import org.eclipse.xsd.XSDComplexTypeDefinition;
-import org.eclipse.xsd.XSDCompositor;
-import org.eclipse.xsd.XSDElementDeclaration;
-import org.eclipse.xsd.XSDFactory;
-import org.eclipse.xsd.XSDModelGroup;
-import org.eclipse.xsd.XSDPackage;
-import org.eclipse.xsd.XSDParticle;
-import org.eclipse.xsd.XSDSchema;
-
-public class MBFacade
-{
- private ModelManagementStrategy modelManagementStrategy;
-
- public MBFacade(ModelManagementStrategy modelManagementStrategy)
- {
- this.modelManagementStrategy = modelManagementStrategy;
- }
-
- public MBFacade()
- {
- // TODO Auto-generated constructor stub
- }
-
- public ModelManagementStrategy getModelManagementStrategy()
- {
- return modelManagementStrategy;
- }
-
- /**
- * Sets the team leader for an organization.
- *
- * @param organization
- * @param role
- * @return
- */
- public void setTeamLeader(OrganizationType organization, RoleType role)
- {
- organization.setTeamLead(role);
- }
-
- /**
- * Adds a participant to an organization.
- *
- * @param organization
- * @param participant
- * @return
- */
- public void addOrganizationParticipant(OrganizationType organization,
- IModelParticipant participant)
- {
- ParticipantType participantType = AbstractElementBuilder.F_CWM
- .createParticipantType();
- participantType.setParticipant(participant);
- organization.getParticipant().add(participantType);
- }
-
- /**
- * Returns a list of organizations a participants belongs to.
- *
- * @param model
- * @param participant
- * @return list of organizations
- */
- public static List<OrganizationType> getParentOrganizations(ModelType model,
- IModelParticipant participant)
- {
- List<OrganizationType> belongsTo = new ArrayList<OrganizationType>();
- EList<OrganizationType> orgs = model.getOrganization();
- if (null != orgs)
- {
- for (OrganizationType org : orgs)
- {
- for (ParticipantType pt : org.getParticipant())
- {
- if (participant.equals(pt.getParticipant()))
- {
- belongsTo.add(org);
- }
- }
- }
- }
-
- return belongsTo;
- }
-
- /**
- * Created a type declaration.
- *
- * @param model model to create the type declaration in
- * @param typeID id of the type
- * @param typeName name of the type
- *
- * @return type declaration created
- */
- public TypeDeclarationType createTypeDeclaration(ModelType model, String typeID,
- String typeName)
- {
- TypeDeclarationType structuredDataType = XpdlFactory.eINSTANCE
- .createTypeDeclarationType();
-
- structuredDataType.setId(typeID);
- structuredDataType.setName(typeName);
-
- SchemaTypeType schema = XpdlFactory.eINSTANCE.createSchemaTypeType();
- structuredDataType.setSchemaType(schema);
-
- XSDSchema xsdSchema = XSDFactory.eINSTANCE.createXSDSchema();
- xsdSchema.getQNamePrefixToNamespaceMap().put(XSDPackage.eNS_PREFIX,
- XMLResource.XML_SCHEMA_URI);
- xsdSchema.setSchemaForSchemaQNamePrefix(XSDPackage.eNS_PREFIX);
-
- xsdSchema.setTargetNamespace(TypeDeclarationUtils.computeTargetNamespace(model,
- structuredDataType.getId()));
- String prefix = TypeDeclarationUtils.computePrefix(structuredDataType.getId(),
- xsdSchema.getQNamePrefixToNamespaceMap().keySet());
- xsdSchema.getQNamePrefixToNamespaceMap()
- .put(prefix, xsdSchema.getTargetNamespace());
- xsdSchema.setSchemaLocation(StructuredDataConstants.URN_INTERNAL_PREFIX
- + structuredDataType.getId());
- schema.setSchema(xsdSchema);
-
- XSDComplexTypeDefinition xsdComplexTypeDefinition = XSDFactory.eINSTANCE
- .createXSDComplexTypeDefinition();
- xsdComplexTypeDefinition.setName(structuredDataType.getId());
- XSDParticle particle = XSDFactory.eINSTANCE.createXSDParticle();
- XSDModelGroup modelGroup = XSDFactory.eINSTANCE.createXSDModelGroup();
- particle.setContent(modelGroup);
- modelGroup.setCompositor(XSDCompositor.SEQUENCE_LITERAL);
- xsdComplexTypeDefinition.setContent(particle);
- xsdSchema.getContents().add(xsdComplexTypeDefinition);
-
- XSDElementDeclaration xsdElementDeclaration = XSDFactory.eINSTANCE
- .createXSDElementDeclaration();
- xsdElementDeclaration.setName(structuredDataType.getId());
- xsdElementDeclaration.setTypeDefinition(xsdComplexTypeDefinition);
- xsdSchema.getContents().add(xsdElementDeclaration);
-
- model.getTypeDeclarations().getTypeDeclaration().add(structuredDataType);
-
- return structuredDataType;
- }
-
- /**
- * Created a data of type <b>Document</b>.
- *
- * @param model model to create the document data in
- * @param dataID id of the data
- * @param dataName name of the data
- * @param typeDeclarationID id of the type declaration assigned to the document
- *
- * @return document data created
- */
- public DataType createDocumentData(ModelType model, String dataID, String dataName,
- String typeDeclarationID)
- {
- DataType data;
- BpmDocumentVariableBuilder documentVariable = newDocumentVariable(model);
- if (!StringUtils.isEmpty(typeDeclarationID))
- {
- documentVariable.setTypeDeclaration(typeDeclarationID);
- }
-
- data = documentVariable.withIdAndName(dataID, dataName).build();
-
- return data;
- }
-
- /**
- * Created a data of type <b>Structured Type</b>.
- *
- * <p>The <i>typeFullID</i> id is provided as <b>ModelID:TypedeclarationID</b>.</p>
- *
- * @param model model to create the document data in
- * @param dataID id of the data
- * @param dataName name of the data
- * @param typeFullID full qualified id of the type declaration assigned to the document
- *
- * @return structured data created
- */
- public DataType createStructuredData(ModelType model, String dataID, String dataName,
- String typeFullID)
- {
- DataType data;
- String sourceModelID = getModelId(typeFullID);
- ModelType typeDeclarationModel = getModelManagementStrategy().getModels().get(
- sourceModelID);
-
- BpmStructVariableBuilder structVariable = newStructVariable(model);
- structVariable.setTypeDeclarationModel(typeDeclarationModel);
-
- data = structVariable.withIdAndName(dataID, dataName)
- .ofType(this.stripFullId(typeFullID)).build();
-
- return data;
- }
-
- /**
- * Created a primitive data.
- *
- * <p>As <b>primitiveTypeID</b> might be set:</p>
- * <p></p>
- * <li>ModelerConstants.STRING_PRIMITIVE_DATA_TYPE</li>
- * <li>ModelerConstants.DATE_PRIMITIVE_DATA_TYPE</li>
- * <li>ModelerConstants.INTEGER_PRIMITIVE_DATA_TYPE</li>
- * <li>ModelerConstants.DOUBLE_PRIMITIVE_DATA_TYPE</li>
- * <li>ModelerConstants.DECIMAL_PRIMITIVE_DATA_TYPE</li>
- * <ul></ul>
- *
- * @param model model to create the data in
- * @param dataID id of the data
- * @param dataName name of the data
- * @param primitiveTypeID id of the data
- *
- * @return primitive data created
- */
- public DataType createPrimitiveData(ModelType model, String dataID, String dataName,
- String primitiveTypeID)
- {
- DataType data;
- long maxOID = XpdlModelUtils.getMaxUsedOid(model);
- Type type = null;
-
- if (primitiveTypeID.equals(ModelerConstants.STRING_PRIMITIVE_DATA_TYPE))
- {
- type = Type.String;
- }
- else if (primitiveTypeID.equals(ModelerConstants.DATE_PRIMITIVE_DATA_TYPE))
- {
- type = Type.Calendar;
- }
- else if (primitiveTypeID.equals(ModelerConstants.INTEGER_PRIMITIVE_DATA_TYPE))
- {
- type = Type.Integer;
- }
- else if (primitiveTypeID.equals(ModelerConstants.DOUBLE_PRIMITIVE_DATA_TYPE))
- {
- type = Type.Double;
- }
- else if (primitiveTypeID.equals(ModelerConstants.DECIMAL_PRIMITIVE_DATA_TYPE))
- {
- type = Type.Money;
- }
-
- data = newPrimitiveVariable(model).withIdAndName(dataID, dataName).ofType(type).build();
- data.setElementOid(++maxOID);
-
- return data;
- }
-
- /**
- * Imports a data into an existing model. The model to import the data from is qualified by a
- * full qualified id of the data. If the data exists in a model which differs from the model
- * to import the data in, then a file connection is established and a reference is created.
- * If the data exists locally in the model this is not necessary.
- *
- * <p>The <i>dataFullID</i> id provided as <b>ModelID:DataID</b>.</p>
- *
- * @param model model to import a data in
- * @param dataFullID full qualified id of the data to be imported
- *
- * @return local or referenced data
- */
- public DataType importData(ModelType model, String dataFullID)
- {
- DataType data;
- // TODO Cross-model references
-
- String dataModelId = getModelId(dataFullID);
-
- ModelType dataModel = getModelManagementStrategy().getModels().get(dataModelId);
-
- data = findData(dataModel, stripFullId(dataFullID));
-
- if (!dataModelId.equals(model.getId()))
- {
- String fileConnectionId = JcrConnectionManager.createFileConnection(model,
- dataModel);
-
- String bundleId = CarnotConstants.DIAGRAM_PLUGIN_ID;
- URI uri = URI.createURI("cnx://" + fileConnectionId + "/");
-
- ReplaceModelElementDescriptor descriptor = new ReplaceModelElementDescriptor(
- uri, data, bundleId, null, true);
-
- PepperIconFactory iconFactory = new PepperIconFactory();
-
- descriptor.importElements(iconFactory, model, true);
-
- }
- return data;
- }
-
- /**
- * Creates lane in a diagram
- *
- * <p>The <i>participantFullID</i> id is provided as <b>ModelID:ParticipantID</b>.</p>
- *
- * <p>As <b>orientation</b> might be set:</p>
- * <p></p>
- * <li>ModelerConstants.DIAGRAM_FLOW_ORIENTATION_HORIZONTAL</li>
- * <li>ModelerConstants.DIAGRAM_FLOW_ORIENTATION_VERTICAL</li>
- * <ul></ul>
- *
- * @param model model to create the lane in
- * @param processDefinition process definition to create the lane in
- * @param participantFullID full qualified id of the participant assigned to the lane
- * @param laneID id of the lane
- * @param laneName name of the lane
- * @param orientationID orientation of the lane
- * @param xProperty x position
- * @param yProperty y position
- * @param widthProperty width
- * @param heightProperty height
- * @return lane created
- */
- public LaneSymbol createLane(ModelType model,
- ProcessDefinitionType processDefinition, String participantFullID, String laneID,
- String laneName, String orientationID, int xProperty, int yProperty, int widthProperty,
- int heightProperty)
- {
- long maxOid = XpdlModelUtils.getMaxUsedOid(model);
-
- LaneSymbol laneSymbol = AbstractElementBuilder.F_CWM.createLaneSymbol();
-
- processDefinition.getDiagram().get(0).getPoolSymbols().get(0).getChildLanes()
- .add(laneSymbol);
-
- laneSymbol.setElementOid(++maxOid);
-
- laneSymbol.setId(laneID);
- laneSymbol.setName(laneName);
- laneSymbol.setXPos(xProperty);
- laneSymbol.setYPos(yProperty);
- laneSymbol.setWidth(widthProperty);
- laneSymbol.setHeight(heightProperty);
-
- if (orientationID.equals(ModelerConstants.DIAGRAM_FLOW_ORIENTATION_HORIZONTAL))
- {
- laneSymbol.setOrientation(OrientationType.HORIZONTAL_LITERAL);
- }
- else
- {
- laneSymbol.setOrientation(OrientationType.VERTICAL_LITERAL);
- }
-
- if (participantFullID != null)
- {
-
- String participantModelID = getModelId(participantFullID);
- if (StringUtils.isEmpty(participantModelID))
- {
- participantModelID = model.getId();
- }
- ModelType participantModel = model;
- if (!participantModelID.equals(model.getId()))
- {
- participantModel = getModelManagementStrategy().getModels().get(
- participantModelID);
- }
-
- IModelParticipant modelParticipant = findParticipant(
- getModelManagementStrategy().getModels().get(participantModelID),
- stripFullId(participantFullID));
-
- if (!participantModelID.equals(model.getId()))
- {
- String fileConnectionId = JcrConnectionManager.createFileConnection(model,
- participantModel);
-
- String bundleId = CarnotConstants.DIAGRAM_PLUGIN_ID;
- URI uri = URI.createURI("cnx://" + fileConnectionId + "/");
-
- ReplaceModelElementDescriptor descriptor = new ReplaceModelElementDescriptor(
- uri, modelParticipant, bundleId, null, true);
-
- PepperIconFactory iconFactory = new PepperIconFactory();
-
- descriptor.importElements(iconFactory, model, true);
- }
-
- laneSymbol.setParticipant(modelParticipant);
- }
- return laneSymbol;
- }
-
- /**
- * Create an activity diagram symbol
- *
- * @param model model to create the symbol in
- * @param activity activity for which the symbol is created
- * @param processDefinition process definition to create the symbol in
- * @param parentLaneID id of the lane to create the symbol in
- * @param xProperty x position
- * @param yProperty y position
- * @param widthProperty width
- * @param heightProperty height
- * @return activity symbol
- */
- public ActivitySymbolType createActivitySymbol(ModelType model,
- ActivityType activity, ProcessDefinitionType processDefinition, String parentLaneID,
- int xProperty, int yProperty, int widthProperty,
- int heightProperty)
- {
- long maxOID = XpdlModelUtils.getMaxUsedOid(model);
-
- ActivitySymbolType activitySymbol = AbstractElementBuilder.F_CWM
- .createActivitySymbolType();
- LaneSymbol parentLaneSymbol = findLaneInProcess(processDefinition, parentLaneID);
-
- activitySymbol.setElementOid(++maxOID);
- activitySymbol.setXPos(xProperty - parentLaneSymbol.getXPos());
- activitySymbol.setYPos(yProperty - parentLaneSymbol.getYPos());
- activitySymbol.setWidth(widthProperty);
- activitySymbol.setHeight(heightProperty);
- activitySymbol.setActivity(activity);
- activity.getActivitySymbols().add(activitySymbol);
-
- processDefinition.getDiagram().get(0).getActivitySymbol().add(activitySymbol);
- parentLaneSymbol.getActivitySymbol().add(activitySymbol);
- return activitySymbol;
- }
-
- /**
- * Create a data diagram symbol
- *
- * @param model model to create the symbol in
- * @param data data for which the symbol is created
- * @param processDefinition process definition to create the symbol in
- * @param parentLaneID id of the lane to create the symbol in
- * @param xProperty x position
- * @param yProperty y position
- * @param widthProperty width
- * @param heightProperty height
- * @return data symbol
- */
- public DataSymbolType createDataSymbol(ModelType model, DataType data,
- ProcessDefinitionType processDefinition, String parentLaneID, int xProperty, int yProperty,
- int widthProperty, int heightProperty)
- {
- long maxOID = XpdlModelUtils.getMaxUsedOid(model);
-
- DataSymbolType dataSymbol = AbstractElementBuilder.F_CWM.createDataSymbolType();
- LaneSymbol parentLaneSymbol = findLaneInProcess(processDefinition, parentLaneID);
-
- dataSymbol.setElementOid(++maxOID);
-
- dataSymbol.setData(data);
-
- processDefinition.getDiagram().get(0).getDataSymbol().add(dataSymbol);
- data.getDataSymbols().add(dataSymbol);
- dataSymbol.setXPos(xProperty - parentLaneSymbol.getXPos());
- dataSymbol.setYPos(yProperty - parentLaneSymbol.getYPos());
- dataSymbol.setWidth(widthProperty);
- dataSymbol.setHeight(heightProperty);
-
- parentLaneSymbol.getDataSymbol().add(dataSymbol);
- return dataSymbol;
- }
-
- /**
- * Creates a role.
- *
- * @param model The model to create the role in.
- * @param roleID id of the role
- * @param roleName name of the role
- * @return role created
- */
- public RoleType createRole(ModelType model, String roleID, String roleName)
- {
- RoleType role = newRole(model).withIdAndName(roleID, roleName).build();
- return role;
- }
-
- /**
- * Creates an organization.
- *
- * @param model The model to create the organization in.
- * @param orgID id of the organization
- * @param orgName name of the organization
- * @return organization created
- */
- public OrganizationType createOrganization(ModelType model, String orgID,
- String orgName)
- {
- OrganizationType org = newOrganization(model).withIdAndName(orgID, orgName).build();
- return org;
- }
-
- /**
- * Creates an application.
- *
- * <p>As <b>applicationTypeID</b> might be set:</p>
- * <p></p>
- * <li>ModelerConstants.WEB_SERVICE_APPLICATION_TYPE_ID</li>
- * <li>ModelerConstants.MESSAGE_TRANSFORMATION_APPLICATION_TYPE_ID</li>
- * <li>ModelerConstants.CAMEL_APPLICATION_TYPE</li>
- * <li>ModelerConstants.MAIL_APPLICATION_TYPE_ID</li>
- * <li>ModelerConstants.INTERACTIVE_APPLICATION_TYPE_KEY</li>
- * <li>ModelerConstants.EXTERNAL_WEB_APP_CONTEXT_TYPE_KEY</li>
- * <ul></ul>
- *
- * @param model model to create the application in.
- * @param applicationID id of the application
- * @param applicationName name of the application
- * @param applicationTypeID id of the application type to be set
- * @return application created
- */
- public ApplicationType createApplication(ModelType model, String applicationID,
- String applicationName, String applicationTypeID)
- {
- ApplicationType application = AbstractElementBuilder.F_CWM.createApplicationType();
- application.setId(applicationID);
- application.setName(applicationName);
- ApplicationTypeType applicationTypeType = null;
- try
- {
- applicationTypeType = findApplicationTypeType(model, applicationTypeID);
- }
- catch (Throwable t)
- {
- if (applicationTypeID
- .equalsIgnoreCase(ModelerConstants.MESSAGE_TRANSFORMATION_APPLICATION_TYPE_ID))
- {
- applicationTypeType = AbstractElementBuilder.F_CWM
- .createApplicationTypeType();
- applicationTypeType.setId(applicationTypeID);
- applicationTypeType.setName("Message Transformation Application");
- applicationTypeType.setIsPredefined(true);
- long maxElementOid = XpdlModelUtils.getMaxUsedOid(model);
- applicationTypeType.setElementOid(++maxElementOid);
- model.getApplicationType().add(applicationTypeType);
- }
- }
- application.setType(applicationTypeType);
- model.getApplication().add(application);
- return application;
- }
-
- /**
- * Creates an activity.
- *
- * <p>As <b>activityTypeID</b> might be set:</p>
- * <p></p>
- * <li>ModelerConstants.MANUAL_ACTIVITY</li>
- * <li>ModelerConstants.APPLICATION_ACTIVITY</li>
- * <li>ModelerConstants.SUBPROCESS_ACTIVITY</li>
- * <ul></ul>
- *
- * <p>The <b>xxxFullID</b> are provided like that:</p>
- * <p></p>
- * <li>The <i>participantFullID</i> id provided as <b>ModelID:ParticipantID</b>.</p></li>
- * <li>The <i>applicationFullID</i> id provided as <b>ModelID:ApplicationID</b>.</p></li>
- * <li>The <i>subProcessFullID</i> id provided as <b>ModelID:ProcessID</b>.</p></li>
- * <ul></ul>
- *
- * @param model model to create the activity in.
- * @param processDefinition process definition to create the activity in.
- * @param activityTypeID id of the activity type
- * @param activityID id of the activity
- * @param activityName name of the activity
- * @param participantFullID full qualified id of the participant to be assigned <i>(MANUAL_ACTIVITY only)</i>
- * @param applicationFullID full qualified id of the application to be assigned <i>(APPLICATION_ACTIVITY only)</i>
- * @param subProcessFullID full qualified id of the process to be assigned <i>(SUBPROCESS_ACTIVITY only)</i>
- * @return activity created
- */
- public ActivityType createActivity(ModelType model,
- ProcessDefinitionType processDefinition, String activityTypeID,
- String activityID, String activityName, String participantFullID,
- String applicationFullID, String subProcessFullID)
- {
- long maxOid = XpdlModelUtils.getMaxUsedOid(model) + 1;
-
- ActivityType activity = null;
-
- if (ModelerConstants.MANUAL_ACTIVITY.equals(activityTypeID))
- {
- if (participantFullID != null)
- {
- activity = newManualActivity(processDefinition)
- .withIdAndName(activityID, activityName)
- .havingDefaultPerformer(stripFullId(participantFullID)).build();
- }
- else
- {
- activity = newManualActivity(processDefinition).withIdAndName(activityID,
- activityName).build();
- }
- }
- else if (ModelerConstants.APPLICATION_ACTIVITY.equals(activityTypeID))
-
- {
-
- String stripFullId_ = getModelId(applicationFullID);
- if (StringUtils.isEmpty(stripFullId_))
- {
- stripFullId_ = model.getId();
- }
-
- ApplicationType application = getApplication(stripFullId_,
- stripFullId(applicationFullID));
- ModelType applicationModel = ModelUtils.findContainingModel(application);
- BpmApplicationActivityBuilder applicationActivity = newApplicationActivity(processDefinition);
- applicationActivity.setApplicationModel(applicationModel);
-
- activity = applicationActivity
- .withIdAndName(activityID, activityName)
- .invokingApplication(
- getApplication(applicationModel.getId(),
- stripFullId(applicationFullID))).build();
- // }
- }
- else if (ModelerConstants.SUBPROCESS_ACTIVITY.equals(activityTypeID))
- {
-
- String stripFullId = getModelId(subProcessFullID);
- if (StringUtils.isEmpty(stripFullId))
- {
- stripFullId = model.getId();
- }
-
- ProcessDefinitionType subProcessDefinition = findProcessDefinition(
- getModelManagementStrategy().getModels().get(stripFullId),
- stripFullId(subProcessFullID));
- ModelType subProcessModel = ModelUtils.findContainingModel(subProcessDefinition);
-
- BpmSubProcessActivityBuilder subProcessActivity = newSubProcessActivity(processDefinition);
- subProcessActivity.setSubProcessModel(subProcessModel);
-
- activity = subProcessActivity
- .withIdAndName(model.getId(), activityName)
- .invokingProcess(
- findProcessDefinition(
- getModelManagementStrategy().getModels().get(
- subProcessModel.getId()), stripFullId(subProcessFullID)))
- .build();
- }
- else
- {
- activity = newRouteActivity(processDefinition).withIdAndName(activityID,
- activityName).build();
- }
- activity.setElementOid(maxOid + 1);
- return activity;
- }
-
- /**
- * Creates a process.
- *
- * @param model model to create the process in
- * @param processID id of the process
- * @param processName name of the process
- * @return process created
- */
- public ProcessDefinitionType createProcess(ModelType model, String processName, String processID)
- {
- ProcessDefinitionType processDefinition = newProcessDefinition(model)
- .withIdAndName(processID, processName).build();
-
- // Create diagram bits too
-
- DiagramType diagram = AbstractElementBuilder.F_CWM.createDiagramType();
- diagram.setMode(DiagramModeType.MODE_450_LITERAL);
- diagram.setOrientation(OrientationType.VERTICAL_LITERAL);
- long maxOid = XpdlModelUtils.getMaxUsedOid(model);
- diagram.setElementOid(++maxOid);
- diagram.setName("Diagram 1");
-
- PoolSymbol poolSymbol = AbstractElementBuilder.F_CWM.createPoolSymbol();
-
- diagram.getPoolSymbols().add(poolSymbol);
-
- poolSymbol.setElementOid(++maxOid);
- poolSymbol.setXPos(0);
- poolSymbol.setYPos(0);
- poolSymbol.setWidth(500);
- poolSymbol.setHeight(600);
- poolSymbol.setName("DEFAULT_POOL");
- poolSymbol.setId("DEFAULT_POOL");
- poolSymbol.setOrientation(OrientationType.VERTICAL_LITERAL);
-
- LaneSymbol laneSymbol = AbstractElementBuilder.F_CWM.createLaneSymbol();
-
- poolSymbol.getChildLanes().add(laneSymbol);
- laneSymbol.setParentPool(poolSymbol);
-
- laneSymbol.setElementOid(++maxOid);
- laneSymbol.setId(ModelerConstants.DEF_LANE_ID);
- laneSymbol.setName(ModelerConstants.DEF_LANE_NAME);
- laneSymbol.setXPos(10);
- laneSymbol.setYPos(10);
- laneSymbol.setWidth(480);
- laneSymbol.setHeight(580);
- laneSymbol.setOrientation(OrientationType.VERTICAL_LITERAL);
-
- processDefinition.getDiagram().add(diagram);
-
- newManualTrigger(processDefinition).accessibleTo(ADMINISTRATOR_ROLE).build();
- return processDefinition;
- }
-
- /**
- *
- * @return
- */
- public DataPathType createDataPath()
- {
- return AbstractElementBuilder.F_CWM.createDataPathType();
- }
-
- /**
- *
- * @param modelId
- * @return
- */
- public ModelType findModel(String modelId)
- {
- return getModelManagementStrategy().getModels().get(modelId);
- }
-
- /**
- *
- * @param model
- * @param id
- * @return
- */
- public ProcessDefinitionType findProcessDefinition(ModelType model, String id)
- {
- for (ProcessDefinitionType processDefinition : model.getProcessDefinition())
- {
- if (processDefinition.getId().equals(id))
- {
- return processDefinition;
- }
- }
-
- throw new ObjectNotFoundException("Process Definition " + id + " does not exist.");
- }
-
- /**
- *
- * @param processFullID
- * @return processDefinition
- */
- public ProcessDefinitionType findProcessDefinition(String processFullID)
- {
- String modelID = this.getModelId(processFullID);
- String processID = stripFullId(processFullID);
- ModelType model = findModel(modelID);
- for (ProcessDefinitionType processDefinition : model.getProcessDefinition())
- {
- if (processDefinition.getId().equals(processID))
- {
- return processDefinition;
- }
- }
-
- throw new ObjectNotFoundException("Process Definition " + processFullID + " does not exist.");
- }
-
- /**
- *
- * @param modelId
- * @param id
- * @return
- */
- public ProcessDefinitionType getProcessDefinition(String modelId, String id)
- {
- return findProcessDefinition(findModel(modelId), id);
- }
-
- /**
- *
- * @param model
- * @param id
- * @return application
- */
- public ApplicationType findApplication(ModelType model, String id)
- {
- for (ApplicationType application : model.getApplication())
- {
- if (application.getId().equals(id))
- {
- return application;
- }
- }
-
- throw new ObjectNotFoundException("Application " + id + " does not exist.");
- }
-
- /**
- *
- * @param model
- * @param fullApplicationID
- * @return application
- */
- public ApplicationType findApplication(String fullApplicationID)
- {
- String modelID = this.getModelId(fullApplicationID);
- String applicationID = stripFullId(fullApplicationID);
- ModelType model = findModel(modelID);
- for (ApplicationType application : model.getApplication())
- {
- if (application.getId().equals(applicationID))
- {
- return application;
- }
- }
-
- throw new ObjectNotFoundException("Application " + fullApplicationID + " does not exist.");
- }
-
- /**
- *
- * @param model
- * @param id
- * @return
- */
- public ApplicationTypeType findApplicationTypeType(ModelType model, String id)
- {
- for (ApplicationTypeType applicationType : model.getApplicationType())
- {
- if (applicationType.getId().equals(id))
- {
- return applicationType;
- }
- }
-
- throw new ObjectNotFoundException("Application type " + id + " does not exist.");
- }
-
- /**
- *
- * @param model
- * @param id
- * @return
- */
- public ApplicationContextTypeType findApplicationContextTypeType(ModelType model,
- String id)
- {
- for (ApplicationContextTypeType applicationContextType : model
- .getApplicationContextType())
- {
- if (applicationContextType.getId().equals(id))
- {
- return applicationContextType;
- }
- }
-
- throw new ObjectNotFoundException("Application Context type " + id
- + " does not exist.");
- }
-
- /**
- *
- * @param model
- * @param id
- * @return
- */
- public TypeDeclarationType findTypeDeclaration(ModelType model, String id)
- {
- for (TypeDeclarationType typeDeclaration : model.getTypeDeclarations()
- .getTypeDeclaration())
- {
- if (typeDeclaration.getId().equals(id))
- {
- return typeDeclaration;
- }
- }
-
- throw new ObjectNotFoundException("Type declaration " + id + " does not exist.");
- }
-
- /**
- *
- * @param fullTypeID
- * @return typeDeclaration
- */
- public TypeDeclarationType findTypeDeclaration(String fullTypeID)
- {
- String modelID = this.getModelId(fullTypeID);
- String typeID = stripFullId(fullTypeID);
- ModelType model = findModel(modelID);
- for (TypeDeclarationType typeDeclaration : model.getTypeDeclarations()
- .getTypeDeclaration())
- {
- if (typeDeclaration.getId().equals(typeID))
- {
- return typeDeclaration;
- }
- }
-
- throw new ObjectNotFoundException("Type declaration " + fullTypeID + " does not exist.");
- }
-
- /**
- *
- * @param model
- * @param id
- * @return
- */
- public DataTypeType findDataType(ModelType model, String id)
- {
- for (DataTypeType dataType : model.getDataType())
- {
- if (dataType.getId().equals(id))
- {
- return dataType;
- }
- }
-
- throw new ObjectNotFoundException("Data type " + id + " does not exist.");
- }
-
- /**
- *
- * @param model
- * @param id
- * @return
- */
- public DataType findData(ModelType model, String id)
- {
- for (DataType data : model.getData())
- {
- if (data.getId().equals(id))
- {
- return data;
- }
- }
-
- throw new ObjectNotFoundException("Data " + id + " does not exist.");
- }
-
- /**
- *
- * @param model
- * @param dataFullID
- * @return data
- */
- public DataType findData(String dataFullID)
- {
- String modelID = this.getModelId(dataFullID);
- String dataID = stripFullId(dataFullID);
- ModelType model = findModel(modelID);
- for (DataType data : model.getData())
- {
- if (data.getId().equals(dataID))
- {
- return data;
- }
- }
-
- throw new ObjectNotFoundException("Data " + dataFullID + " does not exist.");
- }
-
- /**
- *
- * @param model
- * @param id
- * @return
- */
- public IModelParticipant findParticipant(ModelType model, String id)
- {
- for (RoleType role : model.getRole())
- {
- if (role.getId().equals(id))
- {
- return role;
- }
- }
-
- for (OrganizationType organization : model.getOrganization())
- {
- if (organization.getId().equals(id))
- {
- return organization;
- }
- }
-
- throw new ObjectNotFoundException("Participant " + id + " does not exist.");
- }
-
- /**
- *
- * @param model
- * @param fullParticipantID
- * @return participant
- */
- public IModelParticipant findParticipant(String fullParticipantID)
- {
- String modelID = this.getModelId(fullParticipantID);
- String participantID = stripFullId(fullParticipantID);
- ModelType model = findModel(modelID);
- for (RoleType role : model.getRole())
- {
- if (role.getId().equals(participantID))
- {
- return role;
- }
- }
-
- for (OrganizationType organization : model.getOrganization())
- {
- if (organization.getId().equals(participantID))
- {
- return organization;
- }
- }
-
- throw new ObjectNotFoundException("Participant " + fullParticipantID + " does not exist.");
- }
-
- /**
- *
- * @param diagram
- * @param oid
- * @return
- */
- public DataSymbolType findDataSymbol(DiagramType diagram, long oid)
- {
- for (DataSymbolType dataSymbol : diagram.getDataSymbol())
- {
- if (dataSymbol.getElementOid() == oid)
- {
- return dataSymbol;
- }
- }
-
- for (PoolSymbol poolSymbol : diagram.getPoolSymbols())
- {
- for (LaneSymbol childLaneSymbol : poolSymbol.getChildLanes())
- {
- DataSymbolType dataSymbol = findDataSymbolRecursively(childLaneSymbol, oid);
-
- if (dataSymbol != null)
- {
- return dataSymbol;
- }
- }
- }
-
- throw new ObjectNotFoundException("Data Symbol " + oid + " does not exist.");
- }
-
- /**
- *
- * @param laneSymbol
- * @param oid
- * @return
- */
- public DataSymbolType findDataSymbolRecursively(LaneSymbol laneSymbol, long oid)
- {
- for (DataSymbolType dataSymbol : laneSymbol.getDataSymbol())
- {
- if (dataSymbol.getElementOid() == oid)
- {
- return dataSymbol;
- }
- }
-
- for (LaneSymbol childLaneSymbol : laneSymbol.getChildLanes())
- {
- DataSymbolType dataSymbol = findDataSymbolRecursively(childLaneSymbol, oid);
-
- if (dataSymbol != null)
- {
- return dataSymbol;
- }
- }
-
- return null;
- }
-
- /**
- *
- * @param processDefinition
- * @param id
- * @return
- */
- public ActivityType findActivity(ProcessDefinitionType processDefinition, String id)
- {
- for (ActivityType activity : processDefinition.getActivity())
- {
- if (activity.getId().equals(id))
- {
- return activity;
- }
- }
-
- throw new ObjectNotFoundException("Activity " + id + " does not exist.");
- }
-
- /**
- *
- * @param diagram
- * @param oid
- * @return
- */
- public ActivitySymbolType findActivitySymbol(DiagramType diagram, long oid)
- {
- LaneSymbol laneSymbol = findLaneContainingActivitySymbol(diagram, oid);
-
- if (laneSymbol != null)
- {
- return findActivitySymbol(laneSymbol, oid);
- }
-
- return null;
- }
-
- /**
- *
- * @param laneSymbol
- * @param oid
- * @return
- */
- public ActivitySymbolType findActivitySymbol(LaneSymbol laneSymbol, long oid)
- {
- for (ActivitySymbolType activitySymbol : laneSymbol.getActivitySymbol())
- {
- if (activitySymbol.getElementOid() == oid)
- {
- return activitySymbol;
- }
- }
-
- return null;
- }
-
- /**
- *
- * @param diagram
- * @param oid
- * @return
- */
- public LaneSymbol findLaneContainingActivitySymbol(DiagramType diagram, long oid)
- {
- for (PoolSymbol poolSymbol : diagram.getPoolSymbols())
- {
- for (LaneSymbol laneSymbol : poolSymbol.getChildLanes())
- {
- LaneSymbol containingLaneSymbol = findLaneContainingActivitySymbolRecursively(
- laneSymbol, oid);
-
- if (containingLaneSymbol != null)
- {
- return containingLaneSymbol;
- }
- }
- }
-
- return null;
- }
-
- public LaneSymbol findLaneContainingActivitySymbolRecursively(LaneSymbol laneSymbol,
- long oid)
- {
- for (ActivitySymbolType activitySymbol : laneSymbol.getActivitySymbol())
- {
- if (activitySymbol.getElementOid() == oid)
- {
- return laneSymbol;
- }
- }
-
- for (LaneSymbol childLaneSymbol : laneSymbol.getChildLanes())
- {
- LaneSymbol containingLaneSymbol = findLaneContainingActivitySymbolRecursively(
- childLaneSymbol, oid);
-
- if (containingLaneSymbol != null)
- {
- return containingLaneSymbol;
- }
- }
-
- return null;
- }
-
- /**
- *
- * @param model
- * @param id
- * @return
- */
- public LaneSymbol findLaneInProcess(ProcessDefinitionType processDefinition, String id)
- {
- for (PoolSymbol poolSymbol : processDefinition.getDiagram().get(0).getPoolSymbols())
- {
- for (LaneSymbol laneSymbol : poolSymbol.getChildLanes())
- {
- LaneSymbol foundLaneSymbol = findLaneRecursively(laneSymbol, id);
-
- if (foundLaneSymbol != null)
- {
- return foundLaneSymbol;
- }
- }
- }
-
- return null;
- }
-
- /**
- *
- * @param diagram
- * @param oid
- * @return
- */
- public StartEventSymbol findStartEventSymbol(DiagramType diagram, long oid)
- {
- LaneSymbol laneSymbol = findLaneContainingStartEventSymbol(diagram, oid);
-
- if (laneSymbol != null)
- {
- return findStartEventSymbol(laneSymbol, oid);
- }
-
- return null;
- }
-
- /**
- *
- * @param laneSymbol
- * @param oid
- * @return
- */
- public StartEventSymbol findStartEventSymbol(LaneSymbol laneSymbol, long oid)
- {
- for (StartEventSymbol startEventSymbol : laneSymbol.getStartEventSymbols())
- {
- if (startEventSymbol.getElementOid() == oid)
- {
- return startEventSymbol;
- }
- }
-
- return null;
- }
-
- /**
- *
- * @param diagram
- * @param oid
- * @return
- */
- public LaneSymbol findLaneContainingStartEventSymbol(DiagramType diagram, long oid)
- {
- for (PoolSymbol poolSymbol : diagram.getPoolSymbols())
- {
- for (LaneSymbol childLaneSymbol : poolSymbol.getChildLanes())
- {
- LaneSymbol containingLaneSymbol = findLaneContainingStartEventSymbolRecursively(
- childLaneSymbol, oid);
-
- if (containingLaneSymbol != null)
- {
- return containingLaneSymbol;
- }
- }
- }
-
- return null;
- }
-
- /**
- *
- * @param laneSymbol
- * @param oid
- * @return
- */
- public LaneSymbol findLaneContainingStartEventSymbolRecursively(LaneSymbol laneSymbol,
- long oid)
- {
- for (StartEventSymbol startEventSymbol : laneSymbol.getStartEventSymbols())
- {
- if (startEventSymbol.getElementOid() == oid)
- {
- return laneSymbol;
- }
- }
-
- for (LaneSymbol childLaneSymbol : laneSymbol.getChildLanes())
- {
- LaneSymbol containingLaneSymbol = findLaneContainingStartEventSymbolRecursively(
- childLaneSymbol, oid);
-
- if (containingLaneSymbol != null)
- {
- return containingLaneSymbol;
- }
- }
-
- return null;
- }
-
- /**
- *
- * @param diagram
- * @param oid
- * @return
- */
- public EndEventSymbol findEndEventSymbol(DiagramType diagram, long oid)
- {
- LaneSymbol laneSymbol = findLaneContainingEndEventSymbol(diagram, oid);
-
- if (laneSymbol != null)
- {
- return findEndEventSymbol(laneSymbol, oid);
- }
-
- return null;
- }
-
- /**
- *
- * @param laneSymbol
- * @param oid
- * @return
- */
- public EndEventSymbol findEndEventSymbol(LaneSymbol laneSymbol, long oid)
- {
- for (EndEventSymbol endEventSymbol : laneSymbol.getEndEventSymbols())
- {
- if (endEventSymbol.getElementOid() == oid)
- {
- return endEventSymbol;
- }
- }
-
- return null;
- }
-
- /**
- *
- * @param diagram
- * @param oid
- * @return
- */
- public LaneSymbol findLaneContainingEndEventSymbol(DiagramType diagram, long oid)
- {
- for (PoolSymbol poolSymbol : diagram.getPoolSymbols())
- {
- for (LaneSymbol childLaneSymbol : poolSymbol.getChildLanes())
- {
- LaneSymbol containingLaneSymbol = findLaneContainingEndEventSymbolRecursively(
- childLaneSymbol, oid);
-
- if (containingLaneSymbol != null)
- {
- return containingLaneSymbol;
- }
- }
- }
-
- return null;
- }
-
- /**
- *
- * @param laneSymbol
- * @param oid
- * @return
- */
- public LaneSymbol findLaneContainingEndEventSymbolRecursively(LaneSymbol laneSymbol,
- long oid)
- {
- for (EndEventSymbol endEventSymbol : laneSymbol.getEndEventSymbols())
- {
- if (endEventSymbol.getElementOid() == oid)
- {
- return laneSymbol;
- }
- }
-
- for (LaneSymbol childLaneSymbol : laneSymbol.getChildLanes())
- {
- LaneSymbol containingLaneSymbol = findLaneContainingEndEventSymbolRecursively(
- childLaneSymbol, oid);
-
- if (containingLaneSymbol != null)
- {
- return containingLaneSymbol;
- }
- }
-
- return null;
- }
-
- /**
- *
- * @param laneSymbol
- * @param id
- * @return
- */
- public LaneSymbol findLaneRecursively(LaneSymbol laneSymbol, String id)
- {
- if (laneSymbol.getId().equals(id))
- {
- return laneSymbol;
- }
-
- for (LaneSymbol childLaneSymbol : laneSymbol.getChildLanes())
- {
- LaneSymbol foundLaneSymbol = findLaneRecursively(childLaneSymbol, id);
-
- if (foundLaneSymbol != null)
- {
- return foundLaneSymbol;
- }
- }
-
- return null;
- }
-
- /**
- *
- * @param model
- * @param id
- * @return
- */
- public LaneSymbol findLaneContainingActivitySymbol(
- ProcessDefinitionType processDefinition, ActivitySymbolType activitySymbol)
- {
- for (PoolSymbol poolSymbol : processDefinition.getDiagram().get(0).getPoolSymbols())
- {
- for (LaneSymbol laneSymbol : poolSymbol.getChildLanes())
- {
- LaneSymbol foundLaneSymbol = findLaneContainingActivitySymbolRecursively(
- laneSymbol, activitySymbol);
-
- if (foundLaneSymbol != null)
- {
- return foundLaneSymbol;
- }
- }
- }
-
- throw new ObjectNotFoundException(
- "Lane symbol containing Activity Symbol for Activity "
- + activitySymbol.getActivity().getId() + " cannot be found.");
- }
-
- /**
- *
- * @param laneSymbol
- * @param id
- * @return
- */
- public LaneSymbol findLaneContainingActivitySymbolRecursively(LaneSymbol laneSymbol,
- ActivitySymbolType activitySymbol)
- {
- if (laneSymbol.getActivitySymbol().contains(activitySymbol))
- {
- return laneSymbol;
- }
-
- for (LaneSymbol childLaneSymbol : laneSymbol.getChildLanes())
- {
- LaneSymbol foundLaneSymbol = findLaneContainingActivitySymbolRecursively(
- childLaneSymbol, activitySymbol);
-
- if (foundLaneSymbol != null)
- {
- return foundLaneSymbol;
- }
- }
-
- return null;
- }
-
- /**
- *
- * @param processDefinition
- * @param oid
- * @return
- */
- public TransitionConnectionType findTransitionConnectionByModelOid(
- ProcessDefinitionType processDefinition, long oid)
- {
- for (TransitionConnectionType transitionConnection : processDefinition.getDiagram()
- .get(0).getTransitionConnection())
- {
- if (transitionConnection.getElementOid() == oid)
- {
- return transitionConnection;
- }
- }
-
- // Lookup transition in first/default pool
-
- // TODO Support multiple pools
-
- for (TransitionConnectionType transitionConnection : processDefinition.getDiagram()
- .get(0).getPoolSymbols().get(0).getTransitionConnection())
- {
- if (transitionConnection.getElementOid() == oid)
- {
- return transitionConnection;
- }
- }
-
- throw new ObjectNotFoundException("Could not find Transition " + oid + ".");
- }
-
- /**
- *
- * @param processDefinition
- * @param oid
- * @return
- */
- public DataMappingConnectionType findDataMappingConnectionByModelOid(
- ProcessDefinitionType processDefinition, long oid)
- {
- for (DataMappingConnectionType dataMappingConnectionType : processDefinition
- .getDiagram().get(0).getDataMappingConnection())
- {
- if (dataMappingConnectionType.getElementOid() == oid)
- {
- return dataMappingConnectionType;
- }
- }
-
- // TODO Support multiple pools
-
- for (DataMappingConnectionType dataMappingConnectionType : processDefinition.getDiagram()
- .get(0).getPoolSymbols().get(0).getDataMappingConnection())
- {
- if (dataMappingConnectionType.getElementOid() == oid)
- {
- return dataMappingConnectionType;
- }
- }
-
- throw new ObjectNotFoundException("Could not find " + oid + ".");
- }
-
- /**
- *
- * @param processDefinition
- * @param oid
- * @return
- */
- public PoolSymbol findPoolSymbolByElementOid(ProcessDefinitionType processDefinition,
- long oid)
- {
- for (PoolSymbol poolSymbol : processDefinition.getDiagram().get(0).getPoolSymbols())
- {
- if (poolSymbol.getElementOid() == oid)
- {
- return poolSymbol;
- }
- }
-
- throw new ObjectNotFoundException("Could not find Pool Symbol with OID " + oid
- + ".");
- }
-
- /**
- *
- * @param poolSymbol
- * @param oid
- * @return
- */
- public LaneSymbol findLaneSymbolByElementOid(PoolSymbol poolSymbol, long oid)
- {
- for (LaneSymbol laneSymbol : poolSymbol.getLanes())
- {
- if (laneSymbol.getElementOid() == oid)
- {
- return laneSymbol;
- }
- }
-
- throw new ObjectNotFoundException("Could not find Lane Symbol with OID " + oid
- + ".");
- }
-
- /**
- *
- * @param poolSymbol
- * @param oid
- * @return
- */
- public LaneSymbol findLaneSymbolById(ProcessDefinitionType processDefinition, String id)
- {
- for (PoolSymbol poolSymbol : processDefinition.getDiagram().get(0).getPoolSymbols())
- {
- for (LaneSymbol laneSymbol : poolSymbol.getLanes())
- {
-
- // TODO Recursion
-
- if (laneSymbol.getId().equals(id))
- {
- return laneSymbol;
- }
- }
- }
-
- throw new ObjectNotFoundException("Could not find Lane Symbol with ID " + id + ".");
- }
-
- /**
- *
- * @param modelId
- * @param appId
- * @return
- */
- public ApplicationType getApplication(String modelId, String appId)
- {
- ModelType model = getModelManagementStrategy().getModels().get(modelId);
- List<ApplicationType> apps = model.getApplication();
- for (ApplicationType a : apps)
- {
- if (a.getId().equals(appId))
- {
- return a;
- }
- }
-
- return null;
- }
-
- /**
- * TODO Replace by Eclipse modeler logic
- *
- * @param name
- * @return
- */
- public String createIdFromName(String name)
- {
- return name.replace(" ", "_");
- }
-
- /**
- *
- * @param model
- * @param modelElement
- * @return
- */
- public String createFullId(ModelType model, EObject modelElement)
- {
- // TODO Change to {modelId}elementId
- if (null != model && null != modelElement)
- {
- if(modelElement instanceof IIdentifiableModelElement)
- {
- return model.getId() + ":" + ((IIdentifiableModelElement) modelElement).getId();
- }
- if(modelElement instanceof TypeDeclarationType)
- {
- return model.getId() + ":" + ((TypeDeclarationType) modelElement).getId();
- }
- }
- return null;
- }
-
- /**
- * TODO Auxiliary method while cross-model references are not supported
- *
- * @param fullId
- * @return
- */
- public String stripFullId(String fullId)
- {
- String[] ids = fullId.split(":");
-
- return ids[ids.length - 1];
- }
-
- /**
- * Retrieves the model ID of a full ID (e.g. ModelA for ModelA:CreateCustomer).
- *
- * @param fullId
- * @return
- */
- public String getModelId(String fullId)
- {
- String[] ids = fullId.split(":");
-
- return ids[0];
- }
-}