summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRainer Pielmann2012-10-25 10:22:57 (EDT)
committer Sven Rottstock2012-10-25 10:22:57 (EDT)
commit36db7563225debf21da00988a26f6860c9703147 (patch)
tree918693b2df10d8df671633af23c3bf14ff2641c4
parent3b4ed521e5db688c65701b5c8c17a3d1a9a2dca6 (diff)
downloadorg.eclipse.stardust.ide-36db7563225debf21da00988a26f6860c9703147.zip
org.eclipse.stardust.ide-36db7563225debf21da00988a26f6860c9703147.tar.gz
org.eclipse.stardust.ide-36db7563225debf21da00988a26f6860c9703147.tar.bz2
CRNT-26128 Pepper: Refactor XpdlModelIoUtils - Get rid of the static maps
git-svn-id: http://emeafrazerg/svn/ipp/product/trunk/stardust/ide@60327 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/WebModelerConnectionHandler.java15
-rw-r--r--model/org.eclipse.stardust.model.xpdl.builder/src/main/java/org/eclipse/stardust/model/xpdl/builder/utils/ModelBuilderFacade.java8
-rw-r--r--model/org.eclipse.stardust.model.xpdl.builder/src/main/java/org/eclipse/stardust/model/xpdl/builder/utils/WebModelerConnectionManager.java67
-rw-r--r--model/org.eclipse.stardust.model.xpdl.builder/src/main/java/org/eclipse/stardust/model/xpdl/builder/utils/WebModelerModelManager.java20
-rw-r--r--model/org.eclipse.stardust.model.xpdl.builder/src/main/java/org/eclipse/stardust/model/xpdl/builder/utils/XpdlModelIoUtils.java80
5 files changed, 86 insertions, 104 deletions
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
index b042484..2586176 100644
--- 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
@@ -51,7 +51,7 @@ import org.eclipse.stardust.modeling.repository.common.util.ImportUtils;
public class WebModelerConnectionHandler implements ConnectionHandler
-{
+{
DocumentManagementService documentManagementService;
private static final String MODELS_DIR = "/process-models/";
@@ -79,13 +79,8 @@ public class WebModelerConnectionHandler implements ConnectionHandler
synchronized ModelType loadModel(String id)
{
-
- return strategy.loadModel(id);
- }
- private byte[] readModelContext(Document modelDocument) {
- return documentManagementService.retrieveDocumentContent(
- modelDocument.getId());
+ return strategy.loadModel(id);
}
public void importObject(ModelType model, IObjectDescriptor[] descriptors, boolean asLink)
@@ -259,9 +254,9 @@ public class WebModelerConnectionHandler implements ConnectionHandler
if(model == null)
{
- throw new IllegalArgumentException("Model not found: " + id);
+ throw new IllegalArgumentException("Model not found: " + id);
}
-
+
IconFactory iconFactory = new PepperIconFactory();
modelDescriptor = new EObjectDescriptor(uri, model, model.getId(), model.getName(),
@@ -290,7 +285,7 @@ public class WebModelerConnectionHandler implements ConnectionHandler
else if (null == uri.getScheme())
{
xpdlName = fileName;
- }
+ }
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 4e78716..16ce350 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
@@ -11,6 +11,7 @@
package org.eclipse.stardust.model.xpdl.builder.utils;
import static org.eclipse.stardust.model.xpdl.builder.BpmModelBuilder.newApplicationActivity;
+import static org.eclipse.stardust.model.xpdl.builder.BpmModelBuilder.newBpmModel;
import static org.eclipse.stardust.model.xpdl.builder.BpmModelBuilder.newCamelApplication;
import static org.eclipse.stardust.model.xpdl.builder.BpmModelBuilder.newConditionalPerformer;
import static org.eclipse.stardust.model.xpdl.builder.BpmModelBuilder.newDocumentVariable;
@@ -2559,6 +2560,13 @@ public class ModelBuilderFacade
return "unknown";
}
+ public ModelType createModel(String modelID, String modelName)
+ {
+ ModelType model = newBpmModel().withIdAndName(modelID, modelName).build();
+ model.setConnectionManager(new WebModelerConnectionManager(model, this.modelManagementStrategy));
+ return model;
+ }
+
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
index a37264a..eadaaac 100644
--- 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
@@ -24,8 +24,6 @@ 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;
@@ -50,7 +48,6 @@ 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;
@@ -68,8 +65,8 @@ import org.eclipse.stardust.modeling.repository.common.descriptors.EObjectDescri
public class WebModelerConnectionManager implements IConnectionManager
{
- private static ModelManagementStrategy strategy;
-
+ private ModelManagementStrategy strategy;
+
private static final IFilter BY_REF_FILTER = new IFilter()
{
public boolean accept(Object object)
@@ -156,7 +153,7 @@ public class WebModelerConnectionManager implements IConnectionManager
return true;
}
};
-
+
private Repository repository;
private Map<Connection, ConnectionHandler> handlers = CollectionUtils.newMap();
@@ -169,7 +166,7 @@ public class WebModelerConnectionManager implements IConnectionManager
public void setModel(ModelType model)
{
this.model = model;
- model.setConnectionManager(this);
+ model.setConnectionManager(this);
}
public WebModelerConnectionManager(ModelType model, ModelManagementStrategy strategy)
@@ -287,7 +284,7 @@ public class WebModelerConnectionManager implements IConnectionManager
i.remove();
}
}
-
+
List<Connection> connections = repository.getConnection();
for (int i = 0; i < connections.size(); i++)
{
@@ -309,13 +306,13 @@ public class WebModelerConnectionManager implements IConnectionManager
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();
@@ -334,13 +331,13 @@ public class WebModelerConnectionManager implements IConnectionManager
if (attribute.getValue().equals("project:/" + filename) || attribute.getValue().equals(filename))
{
return connection;
- }
+ }
}
}
}
return null;
- }
-
+ }
+
public Connection getConnection(String id)
{
for (Connection connection : repository.getConnection())
@@ -429,8 +426,8 @@ public class WebModelerConnectionManager implements IConnectionManager
}
}
-
-
+
+
private ConnectionHandler createHandler(String type) throws CoreException
{
return new WebModelerConnectionHandler(strategy);
@@ -506,10 +503,10 @@ public class WebModelerConnectionManager implements IConnectionManager
}
};
ClassLoader classLoader = desc.getClass().getClassLoader();
- Class<?>[] interfaces = getInterfaces(desc);
+ Class<?>[] interfaces = getInterfaces(desc);
return (IObjectDescriptor) Proxy.newProxyInstance(classLoader, interfaces, handler);
}
-
+
private Class< ? >[] getInterfaces(IObjectDescriptor desc)
{
@@ -533,7 +530,7 @@ public class WebModelerConnectionManager implements IConnectionManager
/**
* TODO describe
* @param filters
- * @param byReference
+ * @param byReference
* @return
*/
private IFilter[] getFilters(IFilter[] filters, boolean byReference)
@@ -645,7 +642,7 @@ public class WebModelerConnectionManager implements IConnectionManager
{
ArrayList<Connection> connections = new ArrayList<Connection>();
UsageDisplayDialog.setUsage(null);
-
+
ChangeRecorder recorder = new ChangeRecorder(model);
String id;
@@ -673,7 +670,7 @@ public class WebModelerConnectionManager implements IConnectionManager
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)
@@ -750,7 +747,7 @@ public class WebModelerConnectionManager implements IConnectionManager
if (object instanceof EObjectImpl)
{
URI uri = ((EObjectImpl) object).eProxyURI();
-
+
// decode uri from the format produced by xpdl transformation
if (uri.opaquePart() != null)
{
@@ -773,7 +770,7 @@ public class WebModelerConnectionManager implements IConnectionManager
// not a special reference
}
}
-
+
resolve(object, uri);
}
}
@@ -835,8 +832,8 @@ public class WebModelerConnectionManager implements IConnectionManager
public void setConnectionManager(Connection connection)
{
connection.setProperty(CONNECTION_MANAGER, this);
- }
-
+ }
+
public static ConnectionManager getConnectionManager(Connection connection)
{
return (ConnectionManager) connection.getProperty(CONNECTION_MANAGER);
@@ -851,7 +848,7 @@ public class WebModelerConnectionManager implements IConnectionManager
{
String uri = ExtendedAttributeUtil.getAttributeValue(pkg,
IConnectionManager.URI_ATTRIBUTE_NAME);
- EObject eObject = find(uri);
+ EObject eObject = find(uri);
if (eObject instanceof IObjectReference)
{
eObject = ((IObjectReference) eObject).getEObject();
@@ -869,14 +866,14 @@ public class WebModelerConnectionManager implements IConnectionManager
{
return model;
}
-
+
public static String createFileConnection(ModelType model, ModelType referencedModel)
{
String id = null;
-
- WebModelerConnectionManager jcrConnectionManager = XpdlModelIoUtils.getJcrConnectionManager(model, strategy);
+
+ WebModelerConnectionManager jcrConnectionManager = (WebModelerConnectionManager) model.getConnectionManager();
IConnection findConnection = jcrConnectionManager.getConnectionForAttribute(referencedModel.getId() + ".xpdl");
-
+
if(findConnection == null)
{
try
@@ -884,11 +881,11 @@ public class WebModelerConnectionManager implements IConnectionManager
Connection connection = jcrConnectionManager.create("file");
id = connection.getId();
RepositoryFactory factory = RepositoryFactory.eINSTANCE;
-
+
Attribute attribute = factory.createAttribute();
attribute.setName("filename");
- attribute.setValue("project:/" + referencedModel.getId() + ".xpdl"); //$NON-NLS-1$
- connection.getAttributes().add(attribute);
+ attribute.setValue("project:/" + referencedModel.getId() + ".xpdl"); //$NON-NLS-1$
+ connection.getAttributes().add(attribute);
}
catch (CoreException e)
{
@@ -898,7 +895,7 @@ public class WebModelerConnectionManager implements IConnectionManager
{
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
index 96a4156..06a2e1c 100644
--- 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
@@ -45,13 +45,17 @@ public class WebModelerModelManager extends WorkflowModelManager
{
saveModel = model;
}
-
+
@Override
public void resolve(ModelType model)
{
if (model != null && model.getId() != null)
{
- manager = XpdlModelIoUtils.getJcrConnectionManager(model, strategy);
+ manager = (WebModelerConnectionManager) model.getConnectionManager();
+ if (manager == null)
+ {
+ manager = new WebModelerConnectionManager(model, strategy);
+ }
manager.resolve();
}
super.resolve(model);
@@ -61,7 +65,7 @@ public class WebModelerModelManager extends WorkflowModelManager
{
if (manager == null)
{
- manager = XpdlModelIoUtils.getJcrConnectionManager(saveModel, strategy);
+ manager = (WebModelerConnectionManager) saveModel.getConnectionManager();
if(saveModel.getConnectionManager() == null)
{
saveModel.setConnectionManager(manager);
@@ -72,7 +76,7 @@ public class WebModelerModelManager extends WorkflowModelManager
manager.setModel(saveModel);
}
manager.save();
-
+
super.save(uri);
}
@@ -80,13 +84,13 @@ public class WebModelerModelManager extends WorkflowModelManager
{
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
{
@@ -96,9 +100,9 @@ public class WebModelerModelManager extends WorkflowModelManager
}
WorkflowModelManager modelMgr = new WorkflowModelManager();
-
+
modelMgr.load(modelXml);
-
+
return modelMgr.getModel();
}
finally
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 6e96d04..7da0698 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
@@ -10,34 +10,32 @@
*******************************************************************************/
package org.eclipse.stardust.model.xpdl.builder.utils;
-import static org.eclipse.stardust.common.StringUtils.isEmpty;
-
-import java.io.BufferedInputStream;
-import java.io.BufferedOutputStream;
-import java.io.ByteArrayInputStream;
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.text.MessageFormat;
-import java.util.HashMap;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Map;
-
-import javax.xml.transform.TransformerFactory;
-
-import org.eclipse.emf.common.util.URI;
-import org.eclipse.stardust.common.config.Parameters;
-import org.eclipse.stardust.common.log.LogManager;
-import org.eclipse.stardust.common.log.Logger;
-import org.eclipse.stardust.common.utils.xml.XmlProperties;
-import org.eclipse.stardust.engine.core.model.xpdl.XpdlUtils;
+import static org.eclipse.stardust.common.StringUtils.isEmpty;
+
+import java.io.BufferedInputStream;
+import java.io.BufferedOutputStream;
+import java.io.ByteArrayInputStream;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.text.MessageFormat;
+import java.util.LinkedList;
+import java.util.List;
+
+import javax.xml.transform.TransformerFactory;
+
+import org.eclipse.emf.common.util.URI;
+import org.eclipse.stardust.common.config.Parameters;
+import org.eclipse.stardust.common.log.LogManager;
+import org.eclipse.stardust.common.log.Logger;
+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.impl.DocumentRootImpl;
-import org.eclipse.stardust.model.xpdl.carnot.util.WorkflowModelManager;
+import org.eclipse.stardust.model.xpdl.carnot.ModelType;
+import org.eclipse.stardust.model.xpdl.carnot.impl.DocumentRootImpl;
+import org.eclipse.stardust.model.xpdl.carnot.util.WorkflowModelManager;
/*
* $Id: XpdlModelIoUtils.java 24348 2007-12-05 09:06:46Z rsauer $
@@ -50,28 +48,13 @@ import org.eclipse.stardust.model.xpdl.carnot.util.WorkflowModelManager;
*/
public class XpdlModelIoUtils
{
- //private static JcrModelManager manager;
+
private static final Logger trace = LogManager.getLogger(XpdlModelIoUtils.class);
public static final byte[] EMPTY_BUFFER = new byte[0];
private static final int COPY_BUFFER_LENGHT = 16 * 1024;
-
- // TODO how is this supposed to be thread/multi-user save?
- private static Map<String, WebModelerConnectionManager> map = new HashMap<String, WebModelerConnectionManager>();
- public static WebModelerConnectionManager getJcrConnectionManager(ModelType model, ModelManagementStrategy strategy)
- {
- WebModelerConnectionManager manager = map.get(model.getId());
- if(manager == null)
- {
- manager = new WebModelerConnectionManager(model, strategy);
- map.put(model.getId(), manager);
- }
-
- return manager;
- }
-
public static ModelType loadModel(byte[] modelXml, ModelManagementStrategy strategy)
{
try
@@ -127,7 +110,7 @@ public class XpdlModelIoUtils
}
WorkflowModelManager modelMgr = new WebModelerModelManager(strategy);
-
+
try
{
modelMgr.load(modelXml);
@@ -291,11 +274,6 @@ public class XpdlModelIoUtils
}
return tmpModel;
- }
-
-
- public static void clearModelsMap()
- {
- map.clear();
- }
+ }
+
} \ No newline at end of file