Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCamille Letavernier2019-03-14 10:31:13 +0000
committerPatrick Tessier2019-05-06 11:58:35 +0000
commitf13d47654fd242d83b6e7db2d2aac29fc478bbdf (patch)
treed215d8578015a2d6dd601f3e436d92ff974f3a61 /plugins/infra/architecture
parent89bc31de7736a1bfe9add4fdb050a98fa22ef697 (diff)
downloadorg.eclipse.papyrus-f13d47654fd242d83b6e7db2d2aac29fc478bbdf.tar.gz
org.eclipse.papyrus-f13d47654fd242d83b6e7db2d2aac29fc478bbdf.tar.xz
org.eclipse.papyrus-f13d47654fd242d83b6e7db2d2aac29fc478bbdf.zip
Bug 543723: [Performances] Improve the ClassLoaderHelper
https://bugs.eclipse.org/bugs/show_bug.cgi?id=543723 - Add a context URI or Bundle to all methods in ClassLoaderHelper - The context is used to find the most appropriate bundle to load the given class, to avoid relying on a very expensive Eclipse Buddy Policy Change-Id: Ia3c7cc86397643ff3fad634391dce68e5d509d4c Signed-off-by: Camille Letavernier <cletavernier@eclipsesource.com>
Diffstat (limited to 'plugins/infra/architecture')
-rw-r--r--plugins/infra/architecture/org.eclipse.papyrus.infra.architecture/src/org/eclipse/papyrus/infra/architecture/ArchitectureDescriptionUtils.java89
-rw-r--r--plugins/infra/architecture/org.eclipse.papyrus.infra.architecture/src/org/eclipse/papyrus/infra/core/architecture/merged/MergedArchitectureContext.java11
2 files changed, 58 insertions, 42 deletions
diff --git a/plugins/infra/architecture/org.eclipse.papyrus.infra.architecture/src/org/eclipse/papyrus/infra/architecture/ArchitectureDescriptionUtils.java b/plugins/infra/architecture/org.eclipse.papyrus.infra.architecture/src/org/eclipse/papyrus/infra/architecture/ArchitectureDescriptionUtils.java
index 31f6e751410..122227344a6 100644
--- a/plugins/infra/architecture/org.eclipse.papyrus.infra.architecture/src/org/eclipse/papyrus/infra/architecture/ArchitectureDescriptionUtils.java
+++ b/plugins/infra/architecture/org.eclipse.papyrus.infra.architecture/src/org/eclipse/papyrus/infra/architecture/ArchitectureDescriptionUtils.java
@@ -1,17 +1,17 @@
/**
* Copyright (c) 2017,2018 CEA LIST.
- *
+ *
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
- *
+ *
* Contributors:
* Maged Elaasar - Initial API and implementation
* Benoit Maggi - Bug 535393
- *
+ *
*/
package org.eclipse.papyrus.infra.architecture;
@@ -48,33 +48,34 @@ public class ArchitectureDescriptionUtils {
* The model set in context
*/
private ModelSet modelSet;
-
+
/**
* The architecture domain manager
*/
private ArchitectureDomainManager manager = ArchitectureDomainManager.getInstance();
-
+
/**
* Constructs an instance of this class given a model set
*
- * @param modelSet The given model set
+ * @param modelSet
+ * The given model set
*/
public ArchitectureDescriptionUtils(ModelSet modelSet) {
this.modelSet = modelSet;
}
-
+
/**
* Gets the model set in context
- *
+ *
* @return a model set
*/
public ModelSet getModelSet() {
return modelSet;
}
-
+
/**
* Gets the architecture context set in the model set
- *
+ *
* @return architecture context
*/
public MergedArchitectureContext getArchitectureContext() {
@@ -84,34 +85,36 @@ public class ArchitectureDescriptionUtils {
/**
* Gets the architecture context id set in the model set
- *
+ *
* @return architecture context id
*/
public String getArchitectureContextId() {
ArchitectureDescription description = DiModelUtils.getArchitectureDescription(modelSet);
- if (description != null)
+ if (description != null) {
return description.getContextId();
+ }
return ArchitectureDomainManager.getInstance().getDefaultArchitectureContextId();
}
/**
* Gets the architecture viewpoints set in the model set
- *
+ *
* @return a collection of architecture viewpoints
*/
public Collection<MergedArchitectureViewpoint> getArchitectureViewpoints() {
List<MergedArchitectureViewpoint> viewpoints = new ArrayList<>();
for (String viewpointId : getArchitectureViewpointIds()) {
MergedArchitectureViewpoint viewpoint = manager.getArchitectureViewpointById(viewpointId);
- if (viewpoint != null)
+ if (viewpoint != null) {
viewpoints.add(viewpoint);
+ }
}
return viewpoints;
}
/**
* Gets the architecture viewpoint ids set in the model set
- *
+ *
* @return a collection of architecture viewpoint ids
*/
public Collection<String> getArchitectureViewpointIds() {
@@ -137,12 +140,14 @@ public class ArchitectureDescriptionUtils {
/**
* Returns a command that applies the given contextId and viewpoint ids to the model set
* and creates a new model in the set based on them
- *
+ *
* Model creation is based on the creation command configured with the architecture context
* and contribution commands registered in extensions
- *
- * @param contextId the context id to apply to the model set
- * @param viewpointIds the viewpoint ids to apply to the model set
+ *
+ * @param contextId
+ * the context id to apply to the model set
+ * @param viewpointIds
+ * the viewpoint ids to apply to the model set
* @return a command to create a new model
*/
public Command createNewModel(final String contextId, final String[] viewpointIds) {
@@ -161,11 +166,12 @@ public class ArchitectureDescriptionUtils {
/**
* Returns a command that switches the contextId of the model set to the given id and
* converts the semantic model as a result
- *
+ *
* Model conversion is based on the conversion command configured with the architecture context
* and contribution commands registered in extensions
- *
- * @param contextId the context id to apply to the model set
+ *
+ * @param contextId
+ * the context id to apply to the model set
* @return a command that switches the model set to the given context id
*/
public Command switchArchitectureContextId(final String contextId) {
@@ -181,8 +187,9 @@ public class ArchitectureDescriptionUtils {
/**
* Returns a command that switches the viewpoints of the model set to the given id
- *
- * @param viewpointIds the new viewpoint ids to apply to the model set
+ *
+ * @param viewpointIds
+ * the new viewpoint ids to apply to the model set
* @return a command that switches the model set to the given viewpoint ids
*/
public Command switchArchitectureViewpointIds(final String[] viewpointIds) {
@@ -194,8 +201,9 @@ public class ArchitectureDescriptionUtils {
/**
* Returns a command to set the context id in the model set
- *
- * @param contextId the new context id
+ *
+ * @param contextId
+ * the new context id
* @return a command that sets the context id in the model set
*/
protected Command getSetContextCommand(String contextId) {
@@ -210,19 +218,21 @@ public class ArchitectureDescriptionUtils {
/**
* Returns a command to create a new model in the model set based on the given context id
- *
- * @param contextId the context id
+ *
+ * @param contextId
+ * the context id
* @return a command that creates a new model
*/
protected Command getModelCreationCommand(String contextId) {
final MergedArchitectureContext context = manager.getArchitectureContextById(contextId);
- if (context.getCreationCommandClassName() == null)
+ if (context.getCreationCommandClassName() == null) {
return UnexecutableCommand.INSTANCE;
+ }
return new RecordingCommand(modelSet.getTransactionalEditingDomain()) {
@Override
protected void doExecute() {
try {
- IModelCreationCommand creationCommand = (IModelCreationCommand) context.getCreationCommandClass().newInstance();
+ IModelCreationCommand creationCommand = context.getCreationCommandClass().newInstance();
creationCommand.createModel(modelSet);
} catch (Exception e) {
Activator.log.error(e);
@@ -230,22 +240,24 @@ public class ArchitectureDescriptionUtils {
}
};
}
-
+
/**
* Returns a command to converts a new model in the model set based on the given new context id
- *
- * @param contextId the new context id
+ *
+ * @param contextId
+ * the new context id
* @return a command that converts a model
*/
protected Command getModelConversionCommand(String contextId) {
MergedArchitectureContext context = manager.getArchitectureContextById(contextId);
- if (context.getConversionCommandClassName() == null)
+ if (context.getConversionCommandClassName() == null) {
return null;
+ }
return new RecordingCommand(modelSet.getTransactionalEditingDomain()) {
@Override
protected void doExecute() {
try {
- IModelConversionCommand conversionCommand = (IModelConversionCommand) context.getConversionCommandClass().newInstance();
+ IModelConversionCommand conversionCommand = context.getConversionCommandClass().newInstance();
conversionCommand.convertModel(modelSet);
} catch (Exception e) {
Activator.log.error(e);
@@ -256,8 +268,9 @@ public class ArchitectureDescriptionUtils {
/**
* Returns a command that sets the given viewpoint ids to the model set
- *
- * @param viewpointIds The new viewpoint ids
+ *
+ * @param viewpointIds
+ * The new viewpoint ids
* @return a command to set the viewpoint ids
*/
protected Command getSetViewpointCommand(String[] viewpointIds) {
@@ -270,5 +283,5 @@ public class ArchitectureDescriptionUtils {
}
};
}
-
+
}
diff --git a/plugins/infra/architecture/org.eclipse.papyrus.infra.architecture/src/org/eclipse/papyrus/infra/core/architecture/merged/MergedArchitectureContext.java b/plugins/infra/architecture/org.eclipse.papyrus.infra.architecture/src/org/eclipse/papyrus/infra/core/architecture/merged/MergedArchitectureContext.java
index 23e9b5cfa88..f7c0799ea4a 100644
--- a/plugins/infra/architecture/org.eclipse.papyrus.infra.architecture/src/org/eclipse/papyrus/infra/core/architecture/merged/MergedArchitectureContext.java
+++ b/plugins/infra/architecture/org.eclipse.papyrus.infra.architecture/src/org/eclipse/papyrus/infra/core/architecture/merged/MergedArchitectureContext.java
@@ -22,6 +22,9 @@ import java.util.LinkedHashSet;
import java.util.Map;
import java.util.Set;
+import org.eclipse.emf.ecore.util.EcoreUtil;
+import org.eclipse.papyrus.infra.architecture.commands.IModelConversionCommand;
+import org.eclipse.papyrus.infra.architecture.commands.IModelCreationCommand;
import org.eclipse.papyrus.infra.core.architecture.ADElement;
import org.eclipse.papyrus.infra.core.architecture.ArchitectureContext;
import org.eclipse.papyrus.infra.core.architecture.ArchitectureViewpoint;
@@ -71,11 +74,11 @@ public abstract class MergedArchitectureContext extends MergedADElement {
*
* @return a creation command class
*/
- public Class<?> getCreationCommandClass() throws ClassNotFoundException {
+ public Class<? extends IModelCreationCommand> getCreationCommandClass() throws ClassNotFoundException {
for (ADElement element : elements) {
ArchitectureContext context = (ArchitectureContext) element;
if (context.getCreationCommandClass() != null) {
- return ClassLoaderHelper.loadClass(context.getCreationCommandClass());
+ return ClassLoaderHelper.loadClass(context.getCreationCommandClass(), IModelCreationCommand.class, EcoreUtil.getURI(context));
}
}
return null;
@@ -86,11 +89,11 @@ public abstract class MergedArchitectureContext extends MergedADElement {
*
* @return a conversion command class
*/
- public Class<?> getConversionCommandClass() throws ClassNotFoundException {
+ public Class<? extends IModelConversionCommand> getConversionCommandClass() throws ClassNotFoundException {
for (ADElement element : elements) {
ArchitectureContext context = (ArchitectureContext) element;
if (context.getConversionCommandClass() != null) {
- return ClassLoaderHelper.loadClass(context.getConversionCommandClass());
+ return ClassLoaderHelper.loadClass(context.getConversionCommandClass(), IModelConversionCommand.class, EcoreUtil.getURI(context));
}
}
return null;

Back to the top