diff options
author | Ansgar Radermacher | 2014-01-27 16:04:54 +0000 |
---|---|---|
committer | Ansgar Radermacher | 2014-01-27 16:24:31 +0000 |
commit | a5a63943134a93d2674100e778e1703ec78b4c25 (patch) | |
tree | 0428a8e7c16dc87b1d1a152decbae078d30c2252 /extraplugins/qompass-designer/org.eclipse.papyrus.qompass.designer.core/src/org/eclipse | |
parent | bc56e957da4deded94425181f3288b98407c5764 (diff) | |
download | org.eclipse.papyrus-a5a63943134a93d2674100e778e1703ec78b4c25.tar.gz org.eclipse.papyrus-a5a63943134a93d2674100e778e1703ec78b4c25.tar.xz org.eclipse.papyrus-a5a63943134a93d2674100e778e1703ec78b4c25.zip |
- 425087 - [QDesigner] Singletons should be part of system class
Diffstat (limited to 'extraplugins/qompass-designer/org.eclipse.papyrus.qompass.designer.core/src/org/eclipse')
4 files changed, 129 insertions, 65 deletions
diff --git a/extraplugins/qompass-designer/org.eclipse.papyrus.qompass.designer.core/src/org/eclipse/papyrus/qompass/designer/core/deployment/AllocUtils.java b/extraplugins/qompass-designer/org.eclipse.papyrus.qompass.designer.core/src/org/eclipse/papyrus/qompass/designer/core/deployment/AllocUtils.java index ef288caaf17..fc920081c0f 100644 --- a/extraplugins/qompass-designer/org.eclipse.papyrus.qompass.designer.core/src/org/eclipse/papyrus/qompass/designer/core/deployment/AllocUtils.java +++ b/extraplugins/qompass-designer/org.eclipse.papyrus.qompass.designer.core/src/org/eclipse/papyrus/qompass/designer/core/deployment/AllocUtils.java @@ -58,8 +58,13 @@ public class AllocUtils { */ public static EList<InstanceSpecification> getAllNodes(InstanceSpecification instance) { EList<InstanceSpecification> nodeList = getNodes(instance); - for(InstanceSpecification containedInstance : DepUtils.getContainedInstances(instance)) { - nodeList.addAll(getAllNodes(containedInstance)); + for(Slot slot : instance.getSlots()) { + if (!DepUtils.isShared(slot)) { + InstanceSpecification containedInstance = DepUtils.getInstance(slot); + if (containedInstance != null) { + nodeList.addAll(getAllNodes(containedInstance)); + } + } } return nodeList; } diff --git a/extraplugins/qompass-designer/org.eclipse.papyrus.qompass.designer.core/src/org/eclipse/papyrus/qompass/designer/core/deployment/DepCreation.java b/extraplugins/qompass-designer/org.eclipse.papyrus.qompass.designer.core/src/org/eclipse/papyrus/qompass/designer/core/deployment/DepCreation.java index 5291a7a4118..b8fa61274d1 100644 --- a/extraplugins/qompass-designer/org.eclipse.papyrus.qompass.designer.core/src/org/eclipse/papyrus/qompass/designer/core/deployment/DepCreation.java +++ b/extraplugins/qompass-designer/org.eclipse.papyrus.qompass.designer.core/src/org/eclipse/papyrus/qompass/designer/core/deployment/DepCreation.java @@ -21,6 +21,7 @@ import org.eclipse.papyrus.qompass.designer.core.Utils; import org.eclipse.papyrus.qompass.designer.core.transformations.TransformationException; import org.eclipse.papyrus.qompass.designer.core.transformations.TransformationRTException; import org.eclipse.papyrus.uml.tools.utils.StereotypeUtil; +import org.eclipse.uml2.uml.AggregationKind; import org.eclipse.uml2.uml.Class; import org.eclipse.uml2.uml.Classifier; import org.eclipse.uml2.uml.Connector; @@ -184,8 +185,47 @@ public class DepCreation { } visitedClassifiers.push(typeOrImplem); - InstanceSpecification is = (InstanceSpecification) - cdp.createPackagedElement(name, UMLPackage.eINSTANCE.getInstanceSpecification()); + InstanceSpecification is; + // treat singleton + if(Utils.isSingleton((Class)typeOrImplem)) { + // is a singleton - exactly one instance exists + InstanceSpecification mainInstance = DepUtils.getMainInstance(cdp); + + // use canonical name for singleton instance - lower case for type-name + String partName = DeployConstants.singletonPrefix + typeOrImplem.getName().toLowerCase(); + name = mainInstance.getName() + DeployConstants.SEP_CHAR + partName; + PackageableElement pe = cdp.getPackagedElement(name); + + if(pe == null) { + // instance specification for singleton does not exist yet => create + + Classifier system = DepUtils.getClassifier(mainInstance); + Property singletonAttr = system.getAttribute(partName, typeOrImplem); + if((singletonAttr == null) && system instanceof Class) { + singletonAttr = ((Class) system).createOwnedAttribute(partName, typeOrImplem); + singletonAttr.setAggregation(AggregationKind.COMPOSITE_LITERAL); + } + + is = (InstanceSpecification) + cdp.createPackagedElement(name, UMLPackage.eINSTANCE.getInstanceSpecification()); + // create slot within main instance + createSlot(mainInstance, is, singletonAttr); + } + else if (pe instanceof InstanceSpecification) { + // exists already, return it without recursing into its sub-specifications + return (InstanceSpecification) pe; + } + else { + // unlikely case that a packaged element with the name + // <singletonISname> exists already, but is not an instance specification + throw new TransformationException(String.format( + "singleton instantiation: element with name %s exists already in deployment plan, but is not an instance specification", name)); + } + } + else { + is = (InstanceSpecification) + cdp.createPackagedElement(name, UMLPackage.eINSTANCE.getInstanceSpecification()); + } if(name.equals(DeployConstants.MAIN_INSTANCE)) { DepUtils.setMainInstance(cdp, is); @@ -255,7 +295,7 @@ public class DepCreation { if(((type instanceof Class) && Utils.isComponent((Class)type)) || type instanceof Node) { Class cl = (Class)type; - // hack: ad-hoc replication support. Better solution via design patterns + // TODO: ad-hoc replication support. Better solution via design patterns int upper = attribute.getUpper(); String infix = ""; //$NON-NLS-1$ @@ -267,8 +307,10 @@ public class DepCreation { } InstanceSpecification partIS = createDepPlan(cdp, cl, partName, createSlotsForConfigValues, visitedClassifiers); - - createSlot(is, partIS, attribute); + // may not create slot for singleton, since automatically done + if(!Utils.isSingleton((Class)type)) { + createSlot(is, partIS, attribute); + } } } else if(StereotypeUtil.isApplied(attribute, ConfigurationProperty.class) @@ -287,34 +329,10 @@ public class DepCreation { Messages.DepCreation_InfoCreateDepPlan, type.getQualifiedName())); if(Utils.isSingleton((Class)type)) { // is a singleton - exactly one instance exists - // use a common instance prefix for singletons - InstanceSpecification mainInstance = DepUtils.getMainInstance(cdp); - String partName = mainInstance.getName() + DeployConstants.SEP_CHAR + DeployConstants.singletonPrefix + attribute.getName(); - PackageableElement pe = cdp.getPackagedElement(partName); - - if(pe instanceof InstanceSpecification) { - // instance specification for singleton exists already - Slot slot = createSlot(is, (InstanceSpecification)pe, - attribute); - slot.setDefiningFeature(attribute); - } else if(type instanceof Class) { - // instance specification for singleton does not exist - // => create - // [case that a non-instance specification with the name - // <partName> exists already - // is not handled] - - Classifier system = DepUtils.getClassifier(mainInstance); - Property singletonAttr = null; - if (system instanceof Class) { - singletonAttr = ((Class) system).createOwnedAttribute(DeployConstants.singletonPrefix + attribute.getName(), type); - } - - InstanceSpecification singletonIS = createDepPlan(cdp, - (Class)type, partName, createSlotsForConfigValues, visitedClassifiers); - createSlot(is, singletonIS, attribute); - createSlot(mainInstance, singletonIS, singletonAttr); - } + // recursive call - pass empty name, since name for singletons is re-calculated. + InstanceSpecification singletonIS = createDepPlan(cdp, + (Class)type, "", createSlotsForConfigValues, visitedClassifiers); //$NON-NLS-1$ + createSlot(is, singletonIS, attribute); } } else if(type == null) { throw new TransformationException(String.format(Messages.DepCreation_TypeInAttributeUndefined, diff --git a/extraplugins/qompass-designer/org.eclipse.papyrus.qompass.designer.core/src/org/eclipse/papyrus/qompass/designer/core/deployment/DepUtils.java b/extraplugins/qompass-designer/org.eclipse.papyrus.qompass.designer.core/src/org/eclipse/papyrus/qompass/designer/core/deployment/DepUtils.java index 246945ce50f..6f04618aec7 100644 --- a/extraplugins/qompass-designer/org.eclipse.papyrus.qompass.designer.core/src/org/eclipse/papyrus/qompass/designer/core/deployment/DepUtils.java +++ b/extraplugins/qompass-designer/org.eclipse.papyrus.qompass.designer.core/src/org/eclipse/papyrus/qompass/designer/core/deployment/DepUtils.java @@ -348,6 +348,21 @@ public class DepUtils { } /** + * This method returns the instances contained within a composite instance + * specification for an assembly. Unlike @see getContainedInstances, this method only + * returns contained instances that are not shared. + */ + public static EList<InstanceSpecification> getContainedNonSharedInstances(InstanceSpecification is) { + EList<InstanceSpecification> contained = new BasicEList<InstanceSpecification>(); + for(Slot slot : is.getSlots()) { + InstanceSpecification instance = getInstance(slot); + if((instance != null) && !DepUtils.isShared(slot)) { + contained.add(instance); + } + } + return contained; + } + /** * return all slots that reference an instance specification * * @param is diff --git a/extraplugins/qompass-designer/org.eclipse.papyrus.qompass.designer.core/src/org/eclipse/papyrus/qompass/designer/core/deployment/Deploy.java b/extraplugins/qompass-designer/org.eclipse.papyrus.qompass.designer.core/src/org/eclipse/papyrus/qompass/designer/core/deployment/Deploy.java index c5cd6f75a70..29c9fd2685e 100644 --- a/extraplugins/qompass-designer/org.eclipse.papyrus.qompass.designer.core/src/org/eclipse/papyrus/qompass/designer/core/deployment/Deploy.java +++ b/extraplugins/qompass-designer/org.eclipse.papyrus.qompass.designer.core/src/org/eclipse/papyrus/qompass/designer/core/deployment/Deploy.java @@ -48,29 +48,45 @@ public class Deploy { * @param instance * @throws TransformationException */ - public static Deploy distributeToNode(Copy copy, ILangSupport langSupport, InstanceSpecification node, - int nodeIndex, int numberOfNodes, InstanceSpecification instance) + public Deploy(Copy copy, ILangSupport langSupport, InstanceSpecification node, + int nodeIndex, int numberOfNodes) throws TransformationException { - Deploy deploy = new Deploy(); - deploy.bootLoaderGen = new BootLoaderGen(copy, nodeIndex, numberOfNodes); - deploy.node = node; + bootLoaderGen = new BootLoaderGen(copy, nodeIndex, numberOfNodes); + this.node = node; // change to flat copy eventually later (not yet working) - deploy.depInstance = new PartialCopy(); + depInstance = new PartialCopy(); - deploy.depInstance.init(copy, deploy.bootLoaderGen, node); + depInstance.init(copy, bootLoaderGen, node); // set a copy listener in order to assure that indirectly added classes // are taken into account as well + this.copy = copy; copy.preCopyListeners.add(new GatherConfigData(langSupport)); - // TODO: not nice at all (make non-static?) + } + + + /** + * distribute an instance, its contained sub-instances and the referenced + * classifiers to a certain node + * + * @param copy + * @param node + * @param nodeIndex + * @param numberOfNodes + * @param instance + * @throws TransformationException + */ + public InstanceSpecification distributeToNode(InstanceSpecification instance) + throws TransformationException + { Stack<Slot> slotPath = new Stack<Slot>(); - deploy.distributeToNode(false, slotPath, instance); + InstanceSpecification newRootIS = distributeToNode(false, slotPath, instance); - deploy.bootLoaderGen.addCreateConnections(); - deploy.bootLoaderGen.addInit(); - return deploy; + bootLoaderGen.addCreateConnections(); + bootLoaderGen.addInit(); + return newRootIS; } /** @@ -106,26 +122,34 @@ public class Deploy { InstanceSpecification containedInstance = DepUtils.getInstance(slot); if(containedInstance != null) { - StructuralFeature sf = slot.getDefiningFeature(); - boolean viaAllocAll = allocAll; - if (allocAll && (sf instanceof Property)) { - // only take allocation of parent instance into account, if composition - // However, problematic, since code gets copied anyway. - // viaAllocAll = (((Property) sf).getAggregation() == AggregationKind.COMPOSITE_LITERAL); + if (!DepUtils.isShared(slot)) { + StructuralFeature sf = slot.getDefiningFeature(); + boolean viaAllocAll = allocAll; + if (allocAll && (sf instanceof Property)) { + // only take allocation of parent instance into account, if composition + // However, problematic, since code gets copied anyway. + // viaAllocAll = (((Property) sf).getAggregation() == AggregationKind.COMPOSITE_LITERAL); + } + if(viaAllocAll || AllocUtils.getAllNodes(containedInstance).contains(node)) { + slotPath.push(slot); + if (sf instanceof Property) { + // place configurator before recursive call. Otherwise + // values put here would be ignored. + // TODO: instances are not copied to node model. Thus, the instances here are the same as in the + // configuration on the intermediate model. + // TODO: MIX of bootloaderGeneration and splitting. + InstanceConfigurator.configureInstance(containedInstance, (Property) sf, tmInstance); + } + // distribute subInstance + distributeToNode(allocAll, slotPath, containedInstance); + slotPath.pop(); + } } - if(viaAllocAll || AllocUtils.getAllNodes(containedInstance).contains(node)) { - // if(!containedInstance.getName().startsWith(singletonPrefix)) { + else if(allocAll || AllocUtils.getAllNodes(containedInstance).contains(node)) { slotPath.push(slot); - if (sf instanceof Property) { - // place configurator before recursive call. Otherwise - // values put here would be ignored. - // TODO: instances are not copied to node model. Thus, the instances here are the same as in the - // configuration on the intermediate model. - // TODO: MIX of bootloaderGeneration and splitting. - InstanceConfigurator.configureInstance(containedInstance, (Property) sf, tmInstance); - } - InstanceSpecification tmSubInstance = distributeToNode(allocAll, slotPath, containedInstance); - slotPath.pop(); + // bootLoaderGen.instanceConfig(slotPath, instance); + bootLoaderGen.addInstance(slotPath, containedInstance, null, node); + slotPath.pop(); } } else { // slot contains configuration of primitive attribute (no @@ -156,4 +180,6 @@ public class Deploy { protected InstanceSpecification node; protected InstanceDeployer depInstance; + + protected Copy copy; } |