diff --git a/com.epistimis.uddl/META-INF/MANIFEST.MF b/com.epistimis.uddl/META-INF/MANIFEST.MF index 43ac99f..0aaee85 100644 --- a/com.epistimis.uddl/META-INF/MANIFEST.MF +++ b/com.epistimis.uddl/META-INF/MANIFEST.MF @@ -24,8 +24,11 @@ Require-Bundle: org.eclipse.xtext, org.eclipse.acceleo.query;bundle-version="7.0.0", org.eclipse.core.resources Bundle-RequiredExecutionEnvironment: JavaSE-17 -Export-Package: com.epistimis.uddl, +Export-Package: com.epistimis.uddl, + com.epistimis.uddl.constraints, + com.epistimis.uddl.constraints.standalone, com.epistimis.uddl.exceptions, + com.epistimis.uddl.extension, com.epistimis.uddl.formatting2, com.epistimis.uddl.generator, com.epistimis.uddl.parser.antlr, @@ -34,10 +37,8 @@ Export-Package: com.epistimis.uddl, com.epistimis.uddl.serializer, com.epistimis.uddl.services, com.epistimis.uddl.uddl, - com.epistimis.uddl.extension, com.epistimis.uddl.uddl.impl, com.epistimis.uddl.uddl.util, - com.epistimis.uddl.validation, - com.epistimis.uddl.constraints, - com.epistimis.uddl.constraints.standalone + com.epistimis.uddl.unrolled, + com.epistimis.uddl.validation Import-Package: org.apache.log4j diff --git a/com.epistimis.uddl/src/com/epistimis/uddl/RealizationResolver.java b/com.epistimis.uddl/src/com/epistimis/uddl/RealizationResolver.java index c623300..a9dd4c7 100644 --- a/com.epistimis.uddl/src/com/epistimis/uddl/RealizationResolver.java +++ b/com.epistimis.uddl/src/com/epistimis/uddl/RealizationResolver.java @@ -5,6 +5,7 @@ import java.lang.invoke.MethodHandles; import java.text.MessageFormat; +import java.util.Map; import org.apache.log4j.Logger; import org.eclipse.emf.ecore.EObject; @@ -14,10 +15,12 @@ import org.eclipse.xtext.naming.IQualifiedNameProvider; import org.eclipse.xtext.xbase.lib.IteratorExtensions; +import com.epistimis.uddl.scoping.IndexUtilities; import com.epistimis.uddl.uddl.PlatformAssociation; import com.epistimis.uddl.uddl.PlatformComposableElement; import com.epistimis.uddl.uddl.PlatformDataType; import com.epistimis.uddl.uddl.PlatformEntity; +import com.epistimis.uddl.unrolled.UnrollingFactoryP; import com.google.common.collect.Iterables; import com.google.inject.Inject; @@ -51,52 +54,79 @@ public static void resolve(Resource resource) { */ public static void resolve(ResourceSet rs) { - /** - * Before doing anything else, resolve all ECore cross references - because we - * don't know if some have been lazy linked - */ - // EcoreUtil2.resolveAll(rs); - - // Before creating new instances, check to see if we already have an instance. - // TODO: We need a way to determine if the AST has changed so we can invalidate the cache. - // How do we do that? Since the cache is keyed by instance ID, it is sufficient that a change - // will cause a new instance to be created, so the old instance won't be found? The problem - // is that approach leaves the old instances in the cache, just unused - which creates a memory - // leak. We need to know to remove old instances. Alternatively, we just always flush the cache - // at this point - which is what we do here. - RealizedComposableElement.allComposable2Realized.clear(); - RealizedComposableElement.allRealized2Composable.clear(); - - for (Resource res : rs.getResources()) { - /** - * This will only collect all the realization info from a PlatformEntity -> - * LogicalEntity -> ConceptualEntity to determine what is available. The results - * can then be used to create instances, generate code, or .... - */ - final Iterable elements = Iterables.filter( - IteratorExtensions.toIterable(res.getAllContents()), PlatformComposableElement.class); - - for (final PlatformComposableElement elem : elements) { - if ((elem instanceof PlatformAssociation)) { - new RealizedAssociation(((PlatformAssociation) elem)); - } else { - if ((elem instanceof PlatformDataType)) { - new RealizedDataType(((PlatformDataType) elem)); - } else { - if ((elem instanceof PlatformEntity)) { - new RealizedEntity(((PlatformEntity) elem)); - } else { - logger.warn(MessageFormat.format("No processing available for type {0}", - elem.getClass().toString())); - } - } - } - } - } - /** - * Now go back and link all the PlatformEntity types - * - */ - RealizedComposableElement.linkTypes(); + UnrollingFactoryP fp = new UnrollingFactoryP(); + fp.resolve(rs); +// /** +// * Before doing anything else, resolve all ECore cross references - because we +// * don't know if some have been lazy linked +// */ +// // EcoreUtil2.resolveAll(rs); +// +// // Before creating new instances, check to see if we already have an instance. +// // TODO: We need a way to determine if the AST has changed so we can invalidate the cache. +// // How do we do that? Since the cache is keyed by instance ID, it is sufficient that a change +// // will cause a new instance to be created, so the old instance won't be found? The problem +// // is that approach leaves the old instances in the cache, just unused - which creates a memory +// // leak. We need to know to remove old instances. Alternatively, we just always flush the cache +// // at this point - which is what we do here. +// UnrolledComposableElement.allComposable2Realized.clear(); +// UnrolledComposableElement.allRealized2Composable.clear(); +// +// for (Resource res : rs.getResources()) { +// /** +// * This will only collect all the realization info from a PlatformEntity -> +// * LogicalEntity -> ConceptualEntity to determine what is available. The results +// * can then be used to create instances, generate code, or .... +// */ +// final Iterable elements = Iterables.filter( +// IteratorExtensions.toIterable(res.getAllContents()), PlatformComposableElement.class); +// +// for (final PlatformComposableElement elem : elements) { +// if ((elem instanceof PlatformAssociation)) { +// new UnrolledAssociation(((PlatformAssociation) elem)); +// } else { +// if ((elem instanceof PlatformDataType)) { +// new UnrolledDataType(((PlatformDataType) elem)); +// } else { +// if ((elem instanceof PlatformEntity)) { +// new RealizedEntity(((PlatformEntity) elem)); +// } else { +// logger.warn(MessageFormat.format("No processing available for type {0}", +// elem.getClass().toString())); +// } +// } +// } +// } +// } +// /** +// * Now go back and link all the PlatformEntity types +// * +// */ +// UnrolledComposableElement.linkTypes(); } + +// static final String FMT_STRING = "Could not find realization for type [{0}] and role [{1}] when processing [{2}] with description [{3}]"; +// /** +// * Use the maps to match types. This uses the PlatformComposableElement instances as keys, not FQNs. This should work but it is based on +// * object identity. +// */ +// public void linkTypes() { +// for (Map.Entry> entry: getC2REntrySet()) { +// ComposableElement ce = entry.getKey(); +// RealizedComposableElement rce = entry.getValue(); +// if (rce instanceof RealizedEntity) { +// RealizedEntity re = (RealizedEntity) rce; +// for (RealizedComposition rc: re.getComposition().values()) { +// ComposableElement type = IndexUtilities.unProxiedEObject(rc.getType(),ce); +// RealizedComposableElement realizedType = allComposable2Unrolled.get(type); +// if (realizedType == null) { +// String typename = (type != null ? type.getName() : "null"); +// logger.warn(MessageFormat.format(FMT_STRING,typename,rc.getRolename(), re.getName(), re.getDescription())); +// } +// rc.setRealizedType(realizedType); +// } +// } +// } +// } + } diff --git a/com.epistimis.uddl/src/com/epistimis/uddl/generator/CommonDataStructureGenerator.xtend b/com.epistimis.uddl/src/com/epistimis/uddl/generator/CommonDataStructureGenerator.xtend index 171ad10..39aa1d3 100644 --- a/com.epistimis.uddl/src/com/epistimis/uddl/generator/CommonDataStructureGenerator.xtend +++ b/com.epistimis.uddl/src/com/epistimis/uddl/generator/CommonDataStructureGenerator.xtend @@ -21,9 +21,10 @@ import org.eclipse.xtext.generator.IFileSystemAccess2 import org.eclipse.xtext.generator.IGenerator2 import org.eclipse.xtext.generator.IGeneratorContext import org.eclipse.xtext.naming.IQualifiedNameProvider -import com.epistimis.uddl.RealizedComposableElement +import com.epistimis.uddl.unrolled.UnrolledComposableElementP import org.apache.log4j.Logger import java.lang.invoke.MethodHandles +import com.epistimis.uddl.unrolled.UnrolledComposableElement /** * NOTE: Need to handle attribute cardinality in a general way - 2 parts of this: determining cardinality and then rendering. @@ -43,9 +44,9 @@ abstract class CommonDataStructureGenerator implements IGenerator2 { List processedEntities; List processedPDMs; - protected Map allComposableElements; + protected Map> allComposableElements; - new(Map ace) { + new(Map> ace) { allComposableElements = ace; } diff --git a/com.epistimis.uddl/src/com/epistimis/uddl/generator/CppDataStructureGenerator.xtend b/com.epistimis.uddl/src/com/epistimis/uddl/generator/CppDataStructureGenerator.xtend index 6169789..a5a6ca9 100644 --- a/com.epistimis.uddl/src/com/epistimis/uddl/generator/CppDataStructureGenerator.xtend +++ b/com.epistimis.uddl/src/com/epistimis/uddl/generator/CppDataStructureGenerator.xtend @@ -22,9 +22,9 @@ import com.epistimis.uddl.uddl.PlatformULong import com.epistimis.uddl.uddl.PlatformULongLong import com.epistimis.uddl.uddl.PlatformUShort import com.epistimis.uddl.uddl.PlatformUnsignedInteger +import com.epistimis.uddl.unrolled.UnrolledComposableElement import java.util.Map import org.eclipse.emf.ecore.EObject -import com.epistimis.uddl.RealizedComposableElement /** * NOTE: Need to handle attribute cardinality in a general way - 2 parts of this: determining cardinality and then rendering. @@ -36,7 +36,7 @@ import com.epistimis.uddl.RealizedComposableElement */ class CppDataStructureGenerator extends CommonDataStructureGenerator { - new(Map ace) { + new(Map> ace) { super(ace); } diff --git a/com.epistimis.uddl/src/com/epistimis/uddl/generator/IDLDataStructureGenerator.xtend b/com.epistimis.uddl/src/com/epistimis/uddl/generator/IDLDataStructureGenerator.xtend index 95aebc0..d9065e1 100644 --- a/com.epistimis.uddl/src/com/epistimis/uddl/generator/IDLDataStructureGenerator.xtend +++ b/com.epistimis.uddl/src/com/epistimis/uddl/generator/IDLDataStructureGenerator.xtend @@ -1,7 +1,6 @@ package com.epistimis.uddl.generator import com.epistimis.uddl.ModelFilters -import com.epistimis.uddl.RealizedComposableElement import com.epistimis.uddl.uddl.LogicalValueTypeUnit import com.epistimis.uddl.uddl.PlatformArray import com.epistimis.uddl.uddl.PlatformBoolean @@ -29,10 +28,11 @@ import com.epistimis.uddl.uddl.PlatformStruct import com.epistimis.uddl.uddl.PlatformULong import com.epistimis.uddl.uddl.PlatformULongLong import com.epistimis.uddl.uddl.PlatformUShort +import com.epistimis.uddl.unrolled.UnrolledComposableElement +import com.google.inject.Inject import java.util.List import java.util.Map import org.eclipse.emf.ecore.EObject -import com.google.inject.Inject /** * NOTE: Need to handle attribute cardinality in a general way - 2 parts of this: determining cardinality and then rendering. @@ -46,7 +46,7 @@ class IDLDataStructureGenerator extends CommonDataStructureGenerator { @Inject ModelFilters modelFilters; - new(Map ace) { + new(Map> ace) { super(ace); } diff --git a/com.epistimis.uddl/src/com/epistimis/uddl/generator/ProtobufDataStructureGenerator.xtend b/com.epistimis.uddl/src/com/epistimis/uddl/generator/ProtobufDataStructureGenerator.xtend index 8f2490d..ef81b9c 100644 --- a/com.epistimis.uddl/src/com/epistimis/uddl/generator/ProtobufDataStructureGenerator.xtend +++ b/com.epistimis.uddl/src/com/epistimis/uddl/generator/ProtobufDataStructureGenerator.xtend @@ -17,9 +17,9 @@ import com.epistimis.uddl.uddl.PlatformParticipant import com.epistimis.uddl.uddl.PlatformString import com.epistimis.uddl.uddl.PlatformULong import com.epistimis.uddl.uddl.PlatformUnsignedInteger +import com.epistimis.uddl.unrolled.UnrolledComposableElement import java.util.Map import org.eclipse.emf.ecore.EObject -import com.epistimis.uddl.RealizedComposableElement /** * NOTE: Need to handle attribute cardinality in a general way - 2 parts of this: determining cardinality and then rendering. @@ -31,7 +31,7 @@ import com.epistimis.uddl.RealizedComposableElement */ class ProtobufDataStructureGenerator extends CommonDataStructureGenerator { - new(Map ace) { + new(Map> ace) { super(ace); } diff --git a/com.epistimis.uddl/src/com/epistimis/uddl/generator/PythonDataStructureGenerator.xtend b/com.epistimis.uddl/src/com/epistimis/uddl/generator/PythonDataStructureGenerator.xtend index 438b282..3aed723 100644 --- a/com.epistimis.uddl/src/com/epistimis/uddl/generator/PythonDataStructureGenerator.xtend +++ b/com.epistimis.uddl/src/com/epistimis/uddl/generator/PythonDataStructureGenerator.xtend @@ -15,9 +15,9 @@ import com.epistimis.uddl.uddl.PlatformFloat import com.epistimis.uddl.uddl.PlatformInteger import com.epistimis.uddl.uddl.PlatformParticipant import com.epistimis.uddl.uddl.PlatformString +import com.epistimis.uddl.unrolled.UnrolledComposableElement import java.util.Map import org.eclipse.emf.ecore.EObject -import com.epistimis.uddl.RealizedComposableElement /** * NOTE: Need to handle attribute cardinality in a general way - 2 parts of this: determining cardinality and then rendering. @@ -29,7 +29,7 @@ import com.epistimis.uddl.RealizedComposableElement */ class PythonDataStructureGenerator extends CommonDataStructureGenerator { - new(Map ace) { + new(Map> ace) { super(ace); } diff --git a/com.epistimis.uddl/src/com/epistimis/uddl/generator/RDBMSDataStructureGenerator.xtend b/com.epistimis.uddl/src/com/epistimis/uddl/generator/RDBMSDataStructureGenerator.xtend index 717a1ac..e6a0648 100644 --- a/com.epistimis.uddl/src/com/epistimis/uddl/generator/RDBMSDataStructureGenerator.xtend +++ b/com.epistimis.uddl/src/com/epistimis/uddl/generator/RDBMSDataStructureGenerator.xtend @@ -4,20 +4,20 @@ import com.epistimis.uddl.uddl.PlatformBoolean import com.epistimis.uddl.uddl.PlatformBoundedString import com.epistimis.uddl.uddl.PlatformChar import com.epistimis.uddl.uddl.PlatformCharArray +import com.epistimis.uddl.uddl.PlatformComposableElement +import com.epistimis.uddl.uddl.PlatformComposition +import com.epistimis.uddl.uddl.PlatformDataModel import com.epistimis.uddl.uddl.PlatformDataType import com.epistimis.uddl.uddl.PlatformDouble +import com.epistimis.uddl.uddl.PlatformEntity import com.epistimis.uddl.uddl.PlatformFixed import com.epistimis.uddl.uddl.PlatformFloat import com.epistimis.uddl.uddl.PlatformInteger +import com.epistimis.uddl.uddl.PlatformParticipant import com.epistimis.uddl.uddl.PlatformShort -import com.epistimis.uddl.uddl.PlatformComposableElement +import com.epistimis.uddl.unrolled.UnrolledComposableElement import java.util.Map -import com.epistimis.uddl.uddl.PlatformDataModel -import com.epistimis.uddl.uddl.PlatformEntity -import com.epistimis.uddl.uddl.PlatformComposition -import com.epistimis.uddl.uddl.PlatformParticipant import org.eclipse.emf.ecore.EObject -import com.epistimis.uddl.RealizedComposableElement /** * NOTE: Need to handle attribute cardinality in a general way - 2 parts of this: determining cardinality and then rendering. @@ -29,7 +29,7 @@ import com.epistimis.uddl.RealizedComposableElement */ class RDBMSDataStructureGenerator extends CommonDataStructureGenerator { - new(Map ace) { + new(Map> ace) { super(ace); } diff --git a/com.epistimis.uddl/src/com/epistimis/uddl/generator/ScalaDataStructureGenerator.xtend b/com.epistimis.uddl/src/com/epistimis/uddl/generator/ScalaDataStructureGenerator.xtend index 9d3ea03..cca1510 100644 --- a/com.epistimis.uddl/src/com/epistimis/uddl/generator/ScalaDataStructureGenerator.xtend +++ b/com.epistimis.uddl/src/com/epistimis/uddl/generator/ScalaDataStructureGenerator.xtend @@ -5,21 +5,21 @@ import com.epistimis.uddl.uddl.PlatformBoundedString import com.epistimis.uddl.uddl.PlatformChar import com.epistimis.uddl.uddl.PlatformCharArray import com.epistimis.uddl.uddl.PlatformComposableElement +import com.epistimis.uddl.uddl.PlatformComposition +import com.epistimis.uddl.uddl.PlatformDataModel import com.epistimis.uddl.uddl.PlatformDataType import com.epistimis.uddl.uddl.PlatformDouble +import com.epistimis.uddl.uddl.PlatformEntity import com.epistimis.uddl.uddl.PlatformFloat import com.epistimis.uddl.uddl.PlatformInteger import com.epistimis.uddl.uddl.PlatformLong import com.epistimis.uddl.uddl.PlatformLongLong +import com.epistimis.uddl.uddl.PlatformParticipant import com.epistimis.uddl.uddl.PlatformShort import com.epistimis.uddl.uddl.PlatformString +import com.epistimis.uddl.unrolled.UnrolledComposableElement import java.util.Map -import com.epistimis.uddl.uddl.PlatformDataModel -import com.epistimis.uddl.uddl.PlatformEntity -import com.epistimis.uddl.uddl.PlatformComposition -import com.epistimis.uddl.uddl.PlatformParticipant import org.eclipse.emf.ecore.EObject -import com.epistimis.uddl.RealizedComposableElement /** * NOTE: Need to handle attribute cardinality in a general way - 2 parts of this: determining cardinality and then rendering. @@ -31,7 +31,7 @@ import com.epistimis.uddl.RealizedComposableElement */ class ScalaDataStructureGenerator extends CommonDataStructureGenerator { - new(Map ace) { + new(Map> ace) { super(ace); } diff --git a/com.epistimis.uddl/src/com/epistimis/uddl/generator/TypescriptDataStructureGenerator.xtend b/com.epistimis.uddl/src/com/epistimis/uddl/generator/TypescriptDataStructureGenerator.xtend index b55cfc9..d1f78dd 100644 --- a/com.epistimis.uddl/src/com/epistimis/uddl/generator/TypescriptDataStructureGenerator.xtend +++ b/com.epistimis.uddl/src/com/epistimis/uddl/generator/TypescriptDataStructureGenerator.xtend @@ -5,16 +5,16 @@ import com.epistimis.uddl.uddl.PlatformBoundedString import com.epistimis.uddl.uddl.PlatformChar import com.epistimis.uddl.uddl.PlatformCharArray import com.epistimis.uddl.uddl.PlatformComposableElement +import com.epistimis.uddl.uddl.PlatformComposition +import com.epistimis.uddl.uddl.PlatformDataModel import com.epistimis.uddl.uddl.PlatformDataType +import com.epistimis.uddl.uddl.PlatformEntity import com.epistimis.uddl.uddl.PlatformNumber +import com.epistimis.uddl.uddl.PlatformParticipant import com.epistimis.uddl.uddl.PlatformString +import com.epistimis.uddl.unrolled.UnrolledComposableElement import java.util.Map -import com.epistimis.uddl.uddl.PlatformDataModel -import com.epistimis.uddl.uddl.PlatformEntity -import com.epistimis.uddl.uddl.PlatformComposition -import com.epistimis.uddl.uddl.PlatformParticipant import org.eclipse.emf.ecore.EObject -import com.epistimis.uddl.RealizedComposableElement /** * NOTE: Need to handle attribute cardinality in a general way - 2 parts of this: determining cardinality and then rendering. @@ -26,7 +26,7 @@ import com.epistimis.uddl.RealizedComposableElement */ class TypescriptDataStructureGenerator extends CommonDataStructureGenerator { - new(Map ace) { + new(Map> ace) { super(ace); } diff --git a/com.epistimis.uddl/src/com/epistimis/uddl/generator/UddlGenerator.xtend b/com.epistimis.uddl/src/com/epistimis/uddl/generator/UddlGenerator.xtend index be85f6a..fe7fb83 100644 --- a/com.epistimis.uddl/src/com/epistimis/uddl/generator/UddlGenerator.xtend +++ b/com.epistimis.uddl/src/com/epistimis/uddl/generator/UddlGenerator.xtend @@ -7,7 +7,7 @@ package com.epistimis.uddl.generator import com.epistimis.uddl.RealizationResolver -import com.epistimis.uddl.RealizedComposableElement +import com.epistimis.uddl.unrolled.UnrolledComposableElementP import java.lang.invoke.MethodHandles import org.apache.log4j.Logger import org.eclipse.emf.ecore.resource.Resource @@ -55,7 +55,7 @@ class UddlGenerator extends AbstractGenerator { // * Now go back and link all the PlatformEntity types // * // */ -// RealizedComposableElement.linkTypes(); +// UnrolledComposableElementP.linkTypes(); /** * @@ -63,21 +63,21 @@ class UddlGenerator extends AbstractGenerator { * is no indication which language a software component will be generated in. */ try { - val gen2 = new ProtobufDataStructureGenerator(RealizedComposableElement.allComposable2Realized); + val gen2 = new ProtobufDataStructureGenerator(UnrolledComposableElementP.allComposable2Unrolled); gen2.doGenerate(resource, fsa, context); } catch (Exception excp) { logger.error("Protobuf exception: " + excp.localizedMessage,excp); //(excp.stackTrace); } try { - val gen1 = new IDLDataStructureGenerator(RealizedComposableElement.allComposable2Realized); + val gen1 = new IDLDataStructureGenerator(UnrolledComposableElementP.allComposable2Unrolled); gen1.doGenerate(resource, fsa, context); } catch (Exception excp) { logger.error("IDL exception: " + excp.localizedMessage,excp); //(excp.stackTrace); } try { - val gen3 = new RDBMSDataStructureGenerator(RealizedComposableElement.allComposable2Realized); + val gen3 = new RDBMSDataStructureGenerator(UnrolledComposableElementP.allComposable2Unrolled); gen3.doGenerate(resource, fsa, context); } catch (Exception excp) { diff --git a/com.epistimis.uddl/src/com/epistimis/uddl/unrolled/UnrolledAssociation.java b/com.epistimis.uddl/src/com/epistimis/uddl/unrolled/UnrolledAssociation.java index 51c2fad..c4a0af3 100644 --- a/com.epistimis.uddl/src/com/epistimis/uddl/unrolled/UnrolledAssociation.java +++ b/com.epistimis.uddl/src/com/epistimis/uddl/unrolled/UnrolledAssociation.java @@ -1,51 +1,66 @@ -package com.epistimis.uddl; +package com.epistimis.uddl.unrolled; import java.util.HashMap; import java.util.Map; +import org.eclipse.emf.common.util.EList; +import org.eclipse.emf.ecore.EObject; import org.eclipse.jdt.annotation.NonNull; -import com.epistimis.uddl.uddl.PlatformComposition; -import com.epistimis.uddl.uddl.PlatformEntity; -import com.epistimis.uddl.uddl.PlatformParticipant; +import com.epistimis.uddl.uddl.UddlElement; import com.epistimis.uddl.scoping.IndexUtilities; -import com.epistimis.uddl.uddl.PlatformAssociation; -public class RealizedAssociation extends RealizedEntity { +public abstract class UnrolledAssociation, + UComposition extends UnrolledComposition, + UParticipant extends UnrolledParticipant> + extends UnrolledEntity + { /** * The key will be the rolename of the participant. If a specialization results in a change in rolename, then the entry will be * removed from the old rolename and reinserted using the new rolename. */ - private Map participant; - - public RealizedAssociation(@NonNull PlatformAssociation pa) { + private Map participant; + + abstract public Entity getSpecializes(Entity e); + abstract public EList getParticipant(Association assoc); + abstract boolean isAssociation(Entity e); + abstract UParticipant createParticipant(Participant c); + + public UnrolledAssociation(@NonNull Association pa) { super(pa); participant = processSpecializationForParticipants(pa); } - protected Map processSpecializationForParticipants(PlatformAssociation pa) { - Map participantsSoFar; + @SuppressWarnings("unchecked") // Cast to Association OK because of isAssociation check + protected Map processSpecializationForParticipants(Association pa) { + Map participantsSoFar; /** * First recurse if this is also specialized, the process locally. That allows locals to override anything * inherited via specialization */ - PlatformEntity specializedEntity = IndexUtilities.unProxiedEObject(pa.getSpecializes(),pa); - if ((specializedEntity != null) && (specializedEntity instanceof PlatformAssociation)) { + Entity specializedEntity = IndexUtilities.unProxiedEObject(getSpecializes(pa),pa); + if ((specializedEntity != null) && isAssociation(specializedEntity)) { /** - * This assumes that once we inherit from PlatformAssociation, everything down the specialization hierarchy - * must also be a PlatformAssociation. + * This assumes that once we inherit from Association, everything down the specialization hierarchy + * must also be a Association. */ - participantsSoFar = processSpecializationForParticipants((PlatformAssociation)specializedEntity); + participantsSoFar = processSpecializationForParticipants((Association)specializedEntity); } else { - participantsSoFar = new HashMap(); + participantsSoFar = new HashMap(); } return processLocalParticipants(pa,participantsSoFar); } - protected Map processLocalParticipants(PlatformAssociation pe, Map participantsSoFar) { + protected Map processLocalParticipants(Association pe, Map participantsSoFar) { /** * NOTE: We do not merge participantsSoFar into results deliberately. Why? Because we might have multiple * compositions that rename on specialization. In fact, we might have several that swap names. If we @@ -54,13 +69,14 @@ protected Map processLocalParticipants(PlatformAsso * By keeping the maps separate, we we can do that safely. Then, at the very end, we merge what is left * of participantsSoFar into results - everything we want to 'override' has already been removed from it. */ - Map results = new HashMap(); - for (PlatformParticipant pc: pe.getParticipant()) { - RealizedParticipant rp = null; - PlatformParticipant specializedPart = (PlatformParticipant) IndexUtilities.unProxiedEObject(pc.getSpecializes(),pc); + Map results = new HashMap(); + for (Participant pc: getParticipant(pe)) { + UParticipant rp = null; + @SuppressWarnings("unchecked") // OCL checks mean participants can only specialize participants + Participant specializedPart = (Participant) IndexUtilities.unProxiedEObject(getSpecializes(pc),pc); if (specializedPart != null) { /** this is already in the map, find it by the rolename */ - rp = participantsSoFar.remove(specializedPart.getRolename()); + rp = participantsSoFar.remove(getRolename(specializedPart)); /** * By removing from the first list under the original rolename and inserting in the * new results by the new rolename, we also address any change to the rolename that might @@ -72,9 +88,9 @@ protected Map processLocalParticipants(PlatformAsso /** * It wasn't specializing anything, so create a new one */ - rp = new RealizedParticipant(pc,null); + rp = createParticipant(pc); } - results.put(pc.getRolename(), rp); + results.put(getRolename(pc), rp); } // Merge remaining previous results @@ -82,7 +98,7 @@ protected Map processLocalParticipants(PlatformAsso return results; } - public Map getParticipant() { + public Map getParticipant() { return participant; } diff --git a/com.epistimis.uddl/src/com/epistimis/uddl/unrolled/UnrolledAssociationP.java b/com.epistimis.uddl/src/com/epistimis/uddl/unrolled/UnrolledAssociationP.java new file mode 100644 index 0000000..43647a6 --- /dev/null +++ b/com.epistimis.uddl/src/com/epistimis/uddl/unrolled/UnrolledAssociationP.java @@ -0,0 +1,90 @@ +/** + * + */ +package com.epistimis.uddl.unrolled; + +import org.eclipse.emf.common.util.EList; +import org.eclipse.jdt.annotation.NonNull; + +import com.epistimis.uddl.uddl.PlatformAssociation; +import com.epistimis.uddl.uddl.PlatformCharacteristic; +import com.epistimis.uddl.uddl.PlatformComposableElement; +import com.epistimis.uddl.uddl.PlatformComposition; +import com.epistimis.uddl.uddl.PlatformEntity; +import com.epistimis.uddl.uddl.PlatformParticipant; + +/** + * + */ +public class UnrolledAssociationP extends + UnrolledAssociation { + + /** + * @param pa + */ + public UnrolledAssociationP(@NonNull PlatformAssociation pa) { + super(pa); + // TODO Auto-generated constructor stub + } + + @Override + public PlatformEntity getSpecializes(PlatformEntity e) { + // TODO Auto-generated method stub + return e.getSpecializes(); + } + + @Override + public EList getParticipant(PlatformAssociation assoc) { + // TODO Auto-generated method stub + return assoc.getParticipant(); + } + + @Override + boolean isAssociation(PlatformEntity e) { + // TODO Auto-generated method stub + return (e instanceof PlatformAssociation); + } + + @Override + UnrolledParticipantP createParticipant(PlatformParticipant c) { + // TODO Auto-generated method stub + return new UnrolledParticipantP(c,null); + } + + @Override + public String getRolename(PlatformCharacteristic c) { + // TODO Auto-generated method stub + return c.getRolename(); + } + + @Override + public PlatformCharacteristic getSpecializes(PlatformCharacteristic c) { + // TODO Auto-generated method stub + return c.getSpecializes(); + } + + @Override + EList getComposition(PlatformEntity entity) { + // TODO Auto-generated method stub + return entity.getComposition(); + } + + @Override + UnrolledCompositionP createComposition(PlatformComposition c) { + // TODO Auto-generated method stub + return new UnrolledCompositionP(c,null); + } + + /** + * NOTE: Because this type is not considered as derived from ``UnrolledComposableElementP`, that version of + * updateMaps isn't inherited - so reimplement it here. + * TODO: Fix this + */ + @Override + void updateMaps(PlatformComposableElement ce) { + UnrolledComposableElementP.allComposable2Unrolled.put(ce, this); + UnrolledComposableElementP.allUnrolled2Composable.put(this,ce); + + } + +} diff --git a/com.epistimis.uddl/src/com/epistimis/uddl/unrolled/UnrolledCharacteristic.java b/com.epistimis.uddl/src/com/epistimis/uddl/unrolled/UnrolledCharacteristic.java index 7025174..6f8dd35 100644 --- a/com.epistimis.uddl/src/com/epistimis/uddl/unrolled/UnrolledCharacteristic.java +++ b/com.epistimis.uddl/src/com/epistimis/uddl/unrolled/UnrolledCharacteristic.java @@ -1,14 +1,16 @@ -package com.epistimis.uddl; +package com.epistimis.uddl.unrolled; //import java.lang.invoke.MethodHandles; import java.text.MessageFormat; +import org.eclipse.emf.ecore.EObject; //import org.apache.log4j.Logger; import org.eclipse.jdt.annotation.NonNull; -import com.epistimis.uddl.uddl.PlatformCharacteristic; +import com.epistimis.uddl.uddl.UddlElement; -public class RealizedCharacteristic { +public abstract class UnrolledCharacteristic> { //private static Logger logger = Logger.getLogger(MethodHandles.lookup().lookupClass()); /** @@ -26,7 +28,12 @@ public class RealizedCharacteristic { * also specializes and has an characteristic that 'overrides' a characteristic from the specialized Entity */ - protected PlatformCharacteristic realizedCharacteristic; + abstract String getRolename(Characteristic c); + abstract String getDescription(Characteristic c); + abstract int getLowerBound(Characteristic c); + abstract int getUpperBound(Characteristic c); + + protected Characteristic referencedCharacteristic; /** * Use the lowest level rolename (Platform) @@ -47,23 +54,25 @@ public class RealizedCharacteristic { private int upperBound; /** - * The realizedType of this composition Element + * The unrolledType of this composition Element + * NOTE: This does not use UComposableElement because that type is not a base class of UEntity or UAssociation. + * UnrolledComposableElement is the base class. */ - private RealizedComposableElement realizedType; + private UnrolledComposableElement unrolledType; - public RealizedCharacteristic(@NonNull String rolename) { + public UnrolledCharacteristic(@NonNull String rolename) { this.rolename = rolename; this.lowerBound = 1; this.upperBound = 1; } - public RealizedCharacteristic(@NonNull PlatformCharacteristic pc, @NonNull RealizedComposableElement rce) { - this.rolename = pc.getRolename(); - this.description= pc.getDescription(); - this.lowerBound = pc.getLowerBound(); - this.upperBound = pc.getUpperBound(); - this.realizedCharacteristic = pc; - this.realizedType = rce; + public UnrolledCharacteristic(@NonNull Characteristic pc, @NonNull UComposableElement rce) { + this.rolename = getRolename(pc); + this.description= getDescription(pc); + this.lowerBound = getLowerBound(pc); + this.upperBound = getUpperBound(pc); + this.referencedCharacteristic = pc; + this.unrolledType = rce; } /** @@ -71,7 +80,7 @@ public RealizedCharacteristic(@NonNull PlatformCharacteristic pc, @NonNull Reali * PlatformComposition * @param pc */ - public void update(@NonNull PlatformCharacteristic pc, RealizedComposableElement rce) { + public void updateChar(Characteristic pc, UComposableElement rce) { /** * Allowed updates: * 1) rolename can change - but can't become empty @@ -79,40 +88,40 @@ public void update(@NonNull PlatformCharacteristic pc, RealizedComposableElement * 3) bounds can be no looser - but they can be more restricted * 4) precision cannot be made better? */ - if (pc.getRolename().trim().length() > 0) { - this.rolename = pc.getRolename(); + if (getRolename(pc).trim().length() > 0) { + this.rolename = getRolename(pc); } - if (pc.getDescription().trim().length() > 0) { - this.description = pc.getDescription(); + if (getDescription(pc).trim().length() > 0) { + this.description = getDescription(pc); } - if (pc.getLowerBound() > this.lowerBound) { - this.lowerBound = pc.getLowerBound(); + if (getLowerBound(pc) > this.lowerBound) { + this.lowerBound = getLowerBound(pc); } /** * If the updating upper bound is unbounded, then it can't narrow the * existing definition, so go no further */ - if (pc.getUpperBound() != -1) { - if ((this.upperBound == -1) || (pc.getUpperBound() < this.upperBound)) { - this.upperBound = pc.getUpperBound(); + if (getUpperBound(pc) != -1) { + if ((this.upperBound == -1) || (getUpperBound(pc) < this.upperBound)) { + this.upperBound = getUpperBound(pc); } } if (rce != null) { - this.realizedType = rce; + this.unrolledType = rce; } } - public PlatformCharacteristic getRealizedCharacteristic() { - return this.realizedCharacteristic; + public Characteristic getCharacteristic() { + return this.referencedCharacteristic; } - public RealizedComposableElement getRealizeType() { - return this.realizedType; + public UnrolledComposableElement getRealizeType() { + return this.unrolledType; } - public void setRealizedType(RealizedComposableElement rce) { - this.realizedType = rce; + public void setUnrolledType(UnrolledComposableElement rce) { + this.unrolledType = rce; } public String getDescription() { @@ -124,24 +133,24 @@ public String getRolename() { } public String toString() { - return MessageFormat.format("{0} {1} [{2}:{3}] \'{4}\' from {5}", realizedType.toString(), rolename, lowerBound, upperBound, description, - realizedCharacteristic.toString()); + return MessageFormat.format("{0} {1} [{2}:{3}] \'{4}\' from {5}", unrolledType.toString(), rolename, lowerBound, upperBound, description, + referencedCharacteristic.toString()); } } /* * ConceptualComposition: - realizedType=[ConceptualComposableElement|QN] rolename=ID '[' (lowerBound=INT)? ':' (upperBound=INT)? ']' (description=STRING)? ':' (specializes=[ConceptualCharacteristic|QN])? ';' + unrolledType=[ConceptualComposableElement|QN] rolename=ID '[' (lowerBound=INT)? ':' (upperBound=INT)? ']' (description=STRING)? ':' (specializes=[ConceptualCharacteristic|QN])? ';' ; */ /* * LogicalComposition: - realizedType=[LogicalComposableElement|QN] rolename=ID '[' lowerBound=INT ':' upperBound=INT ']' (description=STRING)? (':' specializes=[LogicalCharacteristic|QN])? '->' realizes=[ConceptualComposition|QN] + unrolledType=[LogicalComposableElement|QN] rolename=ID '[' lowerBound=INT ':' upperBound=INT ']' (description=STRING)? (':' specializes=[LogicalCharacteristic|QN])? '->' realizes=[ConceptualComposition|QN] ; */ /* PlatformComposition: -realizedType=[PlatformComposableElement|QN] rolename=ID '[' lowerBound=INT ':' upperBound=INT ']' (description=STRING)? (':' specializes=[PlatformCharacteristic|QN])? '->' realizes=[LogicalComposition|QN] +unrolledType=[PlatformComposableElement|QN] rolename=ID '[' lowerBound=INT ':' upperBound=INT ']' (description=STRING)? (':' specializes=[PlatformCharacteristic|QN])? '->' realizes=[LogicalComposition|QN] '{' 'prec:' precision=FLOAT '}'';' diff --git a/com.epistimis.uddl/src/com/epistimis/uddl/unrolled/UnrolledComposableElement.java b/com.epistimis.uddl/src/com/epistimis/uddl/unrolled/UnrolledComposableElement.java index e4981d4..858849e 100644 --- a/com.epistimis.uddl/src/com/epistimis/uddl/unrolled/UnrolledComposableElement.java +++ b/com.epistimis.uddl/src/com/epistimis/uddl/unrolled/UnrolledComposableElement.java @@ -1,43 +1,31 @@ -package com.epistimis.uddl; +package com.epistimis.uddl.unrolled; -import java.lang.invoke.MethodHandles; -import java.text.MessageFormat; -import java.util.HashMap; -import java.util.Map; - -import org.apache.log4j.Logger; +//import org.apache.log4j.Logger; import org.eclipse.jdt.annotation.NonNull; -import com.epistimis.uddl.scoping.IndexUtilities; -import com.epistimis.uddl.uddl.PlatformComposableElement; +import com.epistimis.uddl.uddl.UddlElement; import com.google.common.base.Optional; -public class RealizedComposableElement { +public abstract class UnrolledComposableElement { - private static Logger logger = Logger.getLogger(MethodHandles.lookup().lookupClass()); +// private static Logger logger = Logger.getLogger(MethodHandles.lookup().lookupClass()); - /** - * This is, essentially, a compiler name table. It contains the results of processing all the composable elements in the model to - * get the net realization. This can be used as is, or can be used by the QueryProcessor when selecting Entities, Associations, and Compositions. - * - * Note that this contains Platform level info - */ - public static Map allComposable2Realized = new HashMap(); - public static Map allRealized2Composable = new HashMap(); private String name; private String description; - - public RealizedComposableElement(@NonNull PlatformComposableElement pce) { - this.name = pce.getName(); // Always has to have a name, so just do that + + abstract void updateMaps(ComposableElement element); + + // NOTE: Package private - factories have public methods to create - so they can force cache updates + UnrolledComposableElement(@NonNull ComposableElement ce) { + this.name = ce.getName(); // Always has to have a name, so just do that // Set the description - it might not always have a value - setDescription(pce); + setDescription(ce); - allComposable2Realized.put(pce, this); - allRealized2Composable.put(this,pce); + updateMaps(ce); } public String getName() { @@ -50,35 +38,11 @@ public String getDescription() { /** * Set the description - and give it a default empty value (not null) - * @param pce + * @param ce */ - public void setDescription(PlatformComposableElement pce) { - this.description = Optional.fromNullable(pce.getDescription()).or("").trim(); + public void setDescription(ComposableElement ce) { + this.description = Optional.fromNullable(ce.getDescription()).or("").trim(); } - static final String FMT_STRING = "Could not find realization for type [{0}] and role [{1}] when processing [{2}] with description [{3}]"; - - /** - * Use the maps to match types. This uses the PlatformComposableElement instances as keys, not FQNs. This should work but it is based on - * object identity. - */ - public static void linkTypes() { - for (Map.Entry entry: allComposable2Realized.entrySet()) { - PlatformComposableElement pce = entry.getKey(); - RealizedComposableElement rce = entry.getValue(); - if (rce instanceof RealizedEntity) { - RealizedEntity re = (RealizedEntity) rce; - for (RealizedComposition rc: re.getComposition().values()) { - PlatformComposableElement type = IndexUtilities.unProxiedEObject(rc.getType(),pce); - RealizedComposableElement realizedType = allComposable2Realized.get(type); - if (realizedType == null) { - String typename = (type != null ? type.getName() : "null"); - logger.warn(MessageFormat.format(FMT_STRING,typename,rc.getRolename(), re.getName(), re.getDescription())); - } - rc.setRealizedType(realizedType); - } - } - } - } } diff --git a/com.epistimis.uddl/src/com/epistimis/uddl/unrolled/UnrolledComposableElementP.java b/com.epistimis.uddl/src/com/epistimis/uddl/unrolled/UnrolledComposableElementP.java new file mode 100644 index 0000000..f373a3b --- /dev/null +++ b/com.epistimis.uddl/src/com/epistimis/uddl/unrolled/UnrolledComposableElementP.java @@ -0,0 +1,48 @@ +/** + * + */ +package com.epistimis.uddl.unrolled; + +import java.util.HashMap; +import java.util.Map; + +import org.eclipse.jdt.annotation.NonNull; + +import com.epistimis.uddl.uddl.PlatformComposableElement; + +/** + * + */ +public class UnrolledComposableElementP extends UnrolledComposableElement { + + /** + * This is, essentially, a compiler name table. It contains the results of processing all the composable elements in the model to + * get the net realization. This can be used as is, or can be used by the QueryProcessor when selecting Entities, Associations, and Compositions. + * + * Note that this contains Platform level info + * NOTE also that the 'Object' side of each map contains UnrolledComposableElement(s) or their their 'derivative's. + * Because of how Java generics work, UnrolledComposableElementP, UnrolledEntityP, and UnrolledAssociationP aren't + * considered 'compatible' - at least not in their current form. For now just use type checking to figure out what + * we have and convert as appropriate. + * TODO: fix this so we don't lose type safety. + */ + public static Map> allComposable2Unrolled = new HashMap<>(); + public static Map,PlatformComposableElement> allUnrolled2Composable = new HashMap<>(); + + /** + * @param ce + */ + UnrolledComposableElementP(@NonNull PlatformComposableElement ce) { + super(ce); + // TODO Auto-generated constructor stub + } + + + @Override + void updateMaps(PlatformComposableElement ce) { + allComposable2Unrolled.put(ce, this); + allUnrolled2Composable.put(this,ce); + + } + +} diff --git a/com.epistimis.uddl/src/com/epistimis/uddl/unrolled/UnrolledComposition.java b/com.epistimis.uddl/src/com/epistimis/uddl/unrolled/UnrolledComposition.java index d43aad2..8454cd4 100644 --- a/com.epistimis.uddl/src/com/epistimis/uddl/unrolled/UnrolledComposition.java +++ b/com.epistimis.uddl/src/com/epistimis/uddl/unrolled/UnrolledComposition.java @@ -1,58 +1,70 @@ -package com.epistimis.uddl; +package com.epistimis.uddl.unrolled; import java.lang.invoke.MethodHandles; import org.apache.log4j.Logger; +import org.eclipse.emf.ecore.EObject; import org.eclipse.jdt.annotation.NonNull; import com.epistimis.uddl.scoping.IndexUtilities; import com.epistimis.uddl.uddl.PlatformComposableElement; import com.epistimis.uddl.uddl.PlatformComposition; +import com.epistimis.uddl.uddl.UddlElement; -public class RealizedComposition extends RealizedCharacteristic { +public abstract class UnrolledComposition> + extends UnrolledCharacteristic { private static Logger logger = Logger.getLogger(MethodHandles.lookup().lookupClass()); + abstract public float getPrecision(Composition c); + abstract public ComposableElement getType(Composition c); + /** * Track the original type because we need this later to do linkage */ - private @NonNull PlatformComposableElement type; + private @NonNull ComposableElement type; /** * The max precision - use this to define a rounding function for this composition? + * NOTE: This value is only valid/used at the Platform level */ private float precision; - public RealizedComposition(@NonNull String rolename) { + public UnrolledComposition(@NonNull String rolename) { super(rolename); // TODO Auto-generated constructor stub this.precision = 1; } - public RealizedComposition(@NonNull PlatformComposition pc, RealizedComposableElement rce) { + public UnrolledComposition(@NonNull Composition pc, UComposableElement rce) { super(pc, rce); // TODO Auto-generated constructor stub - this.type = IndexUtilities.unProxiedEObject(pc.getType(), pc); - this.precision = pc.getPrecision(); + this.type = IndexUtilities.unProxiedEObject(getType(pc), pc); + this.precision = getPrecision(pc); } - public void update(@NonNull PlatformComposition pc, RealizedComposableElement rce) { - super.update(pc, rce); + // Forced to change the nam here because Composition extends Characteristic - which produces an override error + // due to type erasure. + public void update( Composition pc, UComposableElement rce) { + super.updateChar(pc, rce); // TODO: https://app.clickup.com/t/86bx15uh4 - // Characteristic type specialization could be tightened on realization - if (pc.getPrecision() > this.precision) { - this.precision = pc.getPrecision(); + // Characteristic type specialization could be tightened on realization. Tightened precision means smaller values. + if (getPrecision(pc) < this.precision) { + this.precision = getPrecision(pc); } } - public PlatformComposableElement getType() { + public ComposableElement getType() { if (type == null) { - logger.error("Returning null type from RealizedComposition " + realizedCharacteristic.toString()); + logger.error("Returning null type from UnrolledComposition " + referencedCharacteristic.toString()); } return this.type; } diff --git a/com.epistimis.uddl/src/com/epistimis/uddl/unrolled/UnrolledCompositionC.java b/com.epistimis.uddl/src/com/epistimis/uddl/unrolled/UnrolledCompositionC.java new file mode 100644 index 0000000..bb0b7f9 --- /dev/null +++ b/com.epistimis.uddl/src/com/epistimis/uddl/unrolled/UnrolledCompositionC.java @@ -0,0 +1,65 @@ +/** + * + */ +package com.epistimis.uddl.unrolled; + +import org.eclipse.jdt.annotation.NonNull; + +import com.epistimis.uddl.uddl.ConceptualCharacteristic; +import com.epistimis.uddl.uddl.ConceptualComposableElement; +import com.epistimis.uddl.uddl.ConceptualComposition; + +/** + * + */ +public class UnrolledCompositionC extends UnrolledComposition> { + + /** + * @param pc + * @param rce + */ + public UnrolledCompositionC(@NonNull ConceptualComposition pc, + UnrolledComposableElement rce) { + super(pc, rce); + // TODO Auto-generated constructor stub + } + + @Override + public float getPrecision(ConceptualComposition c) { + // precision not applicable + return 0; + } + + @Override + public ConceptualComposableElement getType(ConceptualComposition c) { + // TODO Auto-generated method stub + return c.getType(); + } + + + @Override + String getRolename(ConceptualCharacteristic c) { + // TODO Auto-generated method stub + return c.getRolename(); + } + + @Override + String getDescription(ConceptualCharacteristic c) { + // TODO Auto-generated method stub + return c.getDescription(); + } + + @Override + int getLowerBound(ConceptualCharacteristic c) { + // TODO Auto-generated method stub + return c.getLowerBound(); + } + + @Override + int getUpperBound(ConceptualCharacteristic c) { + // TODO Auto-generated method stub + return c.getUpperBound(); + } + +} diff --git a/com.epistimis.uddl/src/com/epistimis/uddl/unrolled/UnrolledCompositionL.java b/com.epistimis.uddl/src/com/epistimis/uddl/unrolled/UnrolledCompositionL.java new file mode 100644 index 0000000..3778950 --- /dev/null +++ b/com.epistimis.uddl/src/com/epistimis/uddl/unrolled/UnrolledCompositionL.java @@ -0,0 +1,65 @@ +/** + * + */ +package com.epistimis.uddl.unrolled; + +import org.eclipse.jdt.annotation.NonNull; + +import com.epistimis.uddl.uddl.LogicalCharacteristic; +import com.epistimis.uddl.uddl.LogicalComposableElement; +import com.epistimis.uddl.uddl.LogicalComposition; + +/** + * + */ +public class UnrolledCompositionL extends UnrolledComposition> { + + /** + * @param pc + * @param rce + */ + public UnrolledCompositionL(@NonNull LogicalComposition pc, + UnrolledComposableElement rce) { + super(pc, rce); + // TODO Auto-generated constructor stub + } + + @Override + public float getPrecision(LogicalComposition c) { + // Not applicable + return 0; + } + + @Override + public LogicalComposableElement getType(LogicalComposition c) { + // TODO Auto-generated method stub + return c.getType(); + } + + + @Override + String getRolename(LogicalCharacteristic c) { + // TODO Auto-generated method stub + return c.getRolename(); + } + + @Override + String getDescription(LogicalCharacteristic c) { + // TODO Auto-generated method stub + return c.getDescription(); + } + + @Override + int getLowerBound(LogicalCharacteristic c) { + // TODO Auto-generated method stub + return c.getLowerBound(); + } + + @Override + int getUpperBound(LogicalCharacteristic c) { + // TODO Auto-generated method stub + return c.getUpperBound(); + } + +} diff --git a/com.epistimis.uddl/src/com/epistimis/uddl/unrolled/UnrolledCompositionP.java b/com.epistimis.uddl/src/com/epistimis/uddl/unrolled/UnrolledCompositionP.java new file mode 100644 index 0000000..b99bbf2 --- /dev/null +++ b/com.epistimis.uddl/src/com/epistimis/uddl/unrolled/UnrolledCompositionP.java @@ -0,0 +1,65 @@ +/** + * + */ +package com.epistimis.uddl.unrolled; + +import org.eclipse.jdt.annotation.NonNull; + +import com.epistimis.uddl.uddl.PlatformCharacteristic; +import com.epistimis.uddl.uddl.PlatformComposableElement; +import com.epistimis.uddl.uddl.PlatformComposition; + +/** + * + */ +public class UnrolledCompositionP extends UnrolledComposition { + + /** + * @param pc + * @param rce + */ + public UnrolledCompositionP(@NonNull PlatformComposition pc, + UnrolledComposableElementP rce) { + super(pc, rce); + // TODO Auto-generated constructor stub + } + + @Override + public float getPrecision(PlatformComposition c) { + // TODO Auto-generated method stub + return c.getPrecision(); + } + + @Override + public PlatformComposableElement getType(PlatformComposition c) { + // TODO Auto-generated method stub + return c.getType(); + } + + + @Override + String getRolename(PlatformCharacteristic c) { + // TODO Auto-generated method stub + return c.getRolename(); + } + + @Override + String getDescription(PlatformCharacteristic c) { + // TODO Auto-generated method stub + return c.getDescription(); + } + + @Override + int getLowerBound(PlatformCharacteristic c) { + // TODO Auto-generated method stub + return c.getLowerBound(); + } + + @Override + int getUpperBound(PlatformCharacteristic c) { + // TODO Auto-generated method stub + return c.getUpperBound(); + } + +} diff --git a/com.epistimis.uddl/src/com/epistimis/uddl/unrolled/UnrolledDataType.java b/com.epistimis.uddl/src/com/epistimis/uddl/unrolled/UnrolledDataType.java index 224c721..45ae63b 100644 --- a/com.epistimis.uddl/src/com/epistimis/uddl/unrolled/UnrolledDataType.java +++ b/com.epistimis.uddl/src/com/epistimis/uddl/unrolled/UnrolledDataType.java @@ -1,4 +1,4 @@ -package com.epistimis.uddl; +package com.epistimis.uddl.unrolled; import org.eclipse.jdt.annotation.NonNull; @@ -12,7 +12,7 @@ * @author stevehickman * */ -public class RealizedDataType extends RealizedComposableElement { +public class UnrolledDataType extends UnrolledComposableElementP { public enum DataType { SEQUENCE("PlatformSequence"), BOOLEAN("PlatformBoolean"), CHAR("PlatformChar"), FIXED("PlatformFixed"), @@ -57,12 +57,12 @@ public static boolean isa(DataType a, DataType b) { private DataType type; - public RealizedDataType(@NonNull PlatformDataType pdt) { + public UnrolledDataType(@NonNull PlatformDataType pdt) { super(pdt); String clzName = pdt.getClass().getSimpleName(); // Strip off 'Platform' and 'Impl' String enumVal = clzName.substring(8,clzName.lastIndexOf("Impl")).toUpperCase(); - this.setType(Enum.valueOf(RealizedDataType.DataType.class,enumVal)); + this.setType(Enum.valueOf(UnrolledDataType.DataType.class,enumVal)); } diff --git a/com.epistimis.uddl/src/com/epistimis/uddl/unrolled/UnrolledEntity.java b/com.epistimis.uddl/src/com/epistimis/uddl/unrolled/UnrolledEntity.java index cefce78..721dba2 100644 --- a/com.epistimis.uddl/src/com/epistimis/uddl/unrolled/UnrolledEntity.java +++ b/com.epistimis.uddl/src/com/epistimis/uddl/unrolled/UnrolledEntity.java @@ -1,73 +1,95 @@ -package com.epistimis.uddl; +package com.epistimis.uddl.unrolled; import java.util.HashMap; import java.util.Map; +import org.eclipse.emf.common.util.EList; +import org.eclipse.emf.ecore.EObject; + import com.epistimis.uddl.scoping.IndexUtilities; -import com.epistimis.uddl.uddl.PlatformComposition; -import com.epistimis.uddl.uddl.PlatformEntity; -import com.google.common.base.Optional; +import com.epistimis.uddl.uddl.UddlElement; +//import com.google.common.base.Optional; + -public class RealizedEntity extends RealizedComposableElement { +public abstract class UnrolledEntity, + UComposition extends UnrolledComposition> + extends UnrolledComposableElement +{ /** * NOTE: (P/L/C) Composition element specialization is interpreted as follows: * If a (P/L/C) Composition element specializes, it must specialize a Composition element from an Entity at the same (P/L/C) - * level. Only realization can bring Compositions from C->L or L->P. Specialization also means that the specialized element + * level. + * + * (Only realization can bring Compositions from C->L or L->P - those are not addressed here). + * + * NOTE: Specialization/ realization should be self consistent - a realizes-specializes + * path should arrive at the same place as a specializes-realizes path (e.g. Given Entity PE2 that + * specializes Entity PE1 and realizes LogicalEntity LE2, then LE2 must specialize LE1, and PE1 must + * realize LE1. ) If they are not self consistent, this is an error + * (these errors should be caught by the OCL - see logical.ocl and platform.ocl) + * + * + * Specialization also means that the specialized element * is not inherited 'as is' - rather, the specialization overrides whatever would have been inherited. + * It should be that specialization only adds compositions/ participants - that nothing is overridden. + * However, we handle the possibility that something is overridden just to be safe. * - * That means that the RealizedEntity must account for this when working through the hierarchy. To do that: + * That means that the UnrolledEntity must account for this when working through the hierarchy. To do that: * - * 1) recursively walk up the realizes/specializes chains. These should be self consistent - a realizes-specializes path should arrive at the - * same place as a specializes-realizes path (e.g. Given PlatformEntity PE2 that specializes PlatformEntity PE1 and realizes LogicalEntity LE2, - * then LE2 must specialize LE1, and PE1 must realize LE1. ) If they are not self consistent, this is an error (these errors should be caught by - * the OCL - see logical.ocl and platform.ocl) + * 1) recursively walk up the specializes chains. * - * 2) Once reaching the root PlatformEntity (the one that does not specialize anything), then realize all of its Composition elements. + * 2) Once reaching the root Entity (the one that does not specialize anything), then unroll all of its Composition elements. * - * 3) Then recursively pop out of /work down the PlatformEntity specializes hierarchy. At each new level, override any Composition element - * realizations we already have if they are specialized at this level. Then add any new Composition elements found at this level that do not + * 3) Then recursively pop out of /work down the Entity specializes hierarchy. At each new level, unroll any Composition elements + * we already have if they are specialized at this level. Then add any new Composition elements found at this level that do not * specialize. * - * Once all the recursion is done, the PlatformEntity should be fully realized - except for the type. + * Once all the recursion is done, the Entity should be fully unrolled - except for the type. * - * 4) Once all the PlatformEntities are realized, we can go back and link the type for each. This requires that we keep track of the - * original relationship between PlatformEntity and RealizedEntity. + * 4) Once all the Entities are unrolled, we can go back and link the type for each. This requires that we keep track of the + * original relationship between Entity and UnrolledEntity. */ - + abstract public String getRolename (Characteristic c); + abstract public Characteristic getSpecializes (Characteristic c); + abstract public Entity getSpecializes (Entity e); + abstract EList getComposition (Entity entity); + abstract UComposition createComposition (Composition c); + /** * The key will be the rolename of the composition. If a specialization results in a change in rolename, then the entry will be * removed from the old rolename and reinserted using the new rolename. */ - private Map composition; - - public static RealizedEntity realize(PlatformEntity pe) { - return new RealizedEntity(pe); - } + private Map composition; - public RealizedEntity(PlatformEntity pe) { + // NOTE: package private. Factories have public creation methods so they can force cache updates + UnrolledEntity(Entity pe) { super(pe); composition = processSpecializationForCompositions(pe); } - protected Map processSpecializationForCompositions(PlatformEntity pe) { - Map compositionSoFar; + protected Map processSpecializationForCompositions(Entity pe) { + Map compositionSoFar; /** * First recurse if this is also specialized, the process locally. That allows locals to override anything * inherited via specialization */ - PlatformEntity specializedEntity = IndexUtilities.unProxiedEObject(pe.getSpecializes(),pe); + Entity specializedEntity = IndexUtilities.unProxiedEObject(getSpecializes(pe),pe); if (specializedEntity != null) { compositionSoFar = processSpecializationForCompositions(specializedEntity); } else { - compositionSoFar = new HashMap(); + compositionSoFar = new HashMap(); } setDescription(pe); return processLocalCompositions(pe,compositionSoFar); } - protected Map processLocalCompositions(PlatformEntity pe, Map compositionSoFar) { + protected Map processLocalCompositions(Entity pe, Map compositionSoFar) { /** * NOTE: We do not merge compositionSoFar into results deliberately. Why? Because we might have multiple * compositions that rename on specialization. In fact, we might have several that swap names. If we @@ -76,16 +98,17 @@ protected Map processLocalCompositions(PlatformEnti * By keeping the maps separate, we we can do that safely. Then, at the very end, we merge what is left * of compositionSoFar into results - everything we want to 'override' has already been removed from it. */ - Map results = new HashMap(); - for (PlatformComposition pc: pe.getComposition()) { - RealizedComposition rc = null; - PlatformComposition specializedComp = (PlatformComposition) IndexUtilities.unProxiedEObject( pc.getSpecializes(),pe); + Map results = new HashMap<>(); + for (Composition pc: getComposition(pe)) { + UComposition rc = null; + @SuppressWarnings("unchecked") // OCL invariants say that compositions can only specialize compositions + Composition specializedComp = (Composition) IndexUtilities.unProxiedEObject( getSpecializes(pc),pe); if (specializedComp != null) { /** this is already in the map, find it by the rolename */ - rc = compositionSoFar.remove(specializedComp.getRolename()); + rc = compositionSoFar.remove(getRolename(specializedComp)); /** * By removing from the first list under the original rolename and inserting in the - * new results by the new rolename (line 92) , we also address any change to the rolename + * new results by the new rolename (line 107) , we also address any change to the rolename * that might occur as part of specialization. */ rc.update(pc, null); @@ -94,9 +117,9 @@ protected Map processLocalCompositions(PlatformEnti /** * It wasn't specializing anything, so create a new one */ - rc = new RealizedComposition(pc,null); + rc = createComposition(pc); } - results.put(pc.getRolename(), rc); + results.put(getRolename(pc), rc); } // Merge in whatever is left of compositionsSoFar @@ -109,7 +132,7 @@ protected Map processLocalCompositions(PlatformEnti * Get all the composition elements. Key is the rolename * @return */ - public Map getComposition() { + public Map getComposition() { return composition; } diff --git a/com.epistimis.uddl/src/com/epistimis/uddl/unrolled/UnrolledEntityP.java b/com.epistimis.uddl/src/com/epistimis/uddl/unrolled/UnrolledEntityP.java new file mode 100644 index 0000000..a7ad574 --- /dev/null +++ b/com.epistimis.uddl/src/com/epistimis/uddl/unrolled/UnrolledEntityP.java @@ -0,0 +1,76 @@ +/** + * + */ +package com.epistimis.uddl.unrolled; + +import org.eclipse.emf.common.util.EList; + +import com.epistimis.uddl.uddl.PlatformCharacteristic; +import com.epistimis.uddl.uddl.PlatformComposableElement; +import com.epistimis.uddl.uddl.PlatformComposition; +import com.epistimis.uddl.uddl.PlatformEntity; + +/** + * + */ +public class UnrolledEntityP extends UnrolledEntity { + + /** + * @param pe + */ + public UnrolledEntityP(PlatformEntity pe) { + super(pe); + // TODO Auto-generated constructor stub + } + + + @Override + public PlatformEntity getSpecializes(PlatformEntity e) { + // TODO Auto-generated method stub + return e.getSpecializes(); + } + + @Override + public String getRolename(PlatformCharacteristic c) { + // TODO Auto-generated method stub + return c.getRolename(); + } + + @Override + EList getComposition(PlatformEntity entity) { + // TODO Auto-generated method stub + return entity.getComposition(); + } + + + @Override + public PlatformCharacteristic getSpecializes(PlatformCharacteristic c) { + // TODO Auto-generated method stub + return c.getSpecializes(); + } + + @Override + UnrolledCompositionP createComposition( + PlatformComposition c) { + // TODO Auto-generated method stub + return new UnrolledCompositionP(c, null); + } + + + /** + * NOTE: Because this type is not considered as derived from ``UnrolledComposableElementP`, that version of + * updateMaps isn't inherited - so reimplement it here. + * TODO: Fix this + */ + @Override + void updateMaps(PlatformComposableElement ce) { + UnrolledComposableElementP.allComposable2Unrolled.put(ce, this); + UnrolledComposableElementP.allUnrolled2Composable.put(this,ce); + + } + + +} diff --git a/com.epistimis.uddl/src/com/epistimis/uddl/unrolled/UnrolledParticipant.java b/com.epistimis.uddl/src/com/epistimis/uddl/unrolled/UnrolledParticipant.java index c2abfcd..5b0cb1b 100644 --- a/com.epistimis.uddl/src/com/epistimis/uddl/unrolled/UnrolledParticipant.java +++ b/com.epistimis.uddl/src/com/epistimis/uddl/unrolled/UnrolledParticipant.java @@ -1,56 +1,67 @@ -package com.epistimis.uddl; +package com.epistimis.uddl.unrolled; import java.lang.invoke.MethodHandles; import org.apache.log4j.Logger; +import org.eclipse.emf.ecore.EObject; import org.eclipse.jdt.annotation.NonNull; import com.epistimis.uddl.scoping.IndexUtilities; -import com.epistimis.uddl.uddl.PlatformEntity; -import com.epistimis.uddl.uddl.PlatformParticipant; +import com.epistimis.uddl.uddl.UddlElement; -public class RealizedParticipant extends RealizedCharacteristic { +public abstract class UnrolledParticipant> + extends UnrolledCharacteristic { private static Logger logger = Logger.getLogger(MethodHandles.lookup().lookupClass()); + + abstract public int getSourceLowerBound(Participant p); + abstract public int getSourceUpperBound(Participant p); + abstract public ComposableElement getType(Participant p); + abstract Entity conv2Entity(ComposableElement ce); + /** * Track the original type because we need this later to do linkage */ - private @NonNull PlatformEntity type; + private @NonNull Entity type; private int sourceLowerBound; private int sourceUpperBound; - public RealizedParticipant(@NonNull String rolename) { + public UnrolledParticipant(@NonNull String rolename) { super(rolename); // TODO Auto-generated constructor stub sourceLowerBound = 1; sourceUpperBound = 1; } - public RealizedParticipant(@NonNull PlatformParticipant pp, RealizedComposableElement rce) { + public UnrolledParticipant(@NonNull Participant pp, UComposableElement rce) { super(pp,rce); - this.type = IndexUtilities.unProxiedEObject(pp.getType(),pp); - sourceLowerBound = pp.getSourceLowerBound(); - sourceUpperBound = pp.getSourceUpperBound(); + this.type = conv2Entity(IndexUtilities.unProxiedEObject(getType(pp),pp)); + sourceLowerBound = getSourceLowerBound(pp); + sourceUpperBound = getSourceUpperBound(pp); } - public void update(@NonNull PlatformParticipant pc, RealizedComposableElement rce) { - super.update(pc, rce); + public void update(@NonNull Participant pc, UComposableElement rce) { + super.updateChar(pc, rce); // TODO: https://app.clickup.com/t/86bx15uh4 // Characteristic type specialization could be tightened on realization - if (pc.getSourceLowerBound() > this.sourceLowerBound) { - this.sourceLowerBound = pc.getSourceLowerBound(); + if (getSourceLowerBound(pc) > this.sourceLowerBound) { + this.sourceLowerBound = getSourceLowerBound(pc); } - if (pc.getSourceUpperBound() < this.sourceUpperBound) { - this.sourceUpperBound = pc.getSourceUpperBound(); + if (getSourceUpperBound(pc) < this.sourceUpperBound) { + this.sourceUpperBound = getSourceUpperBound(pc); } } - public PlatformEntity getType() { + public Entity getType() { if (type == null) { - logger.error("Returning null type from RealizedParticipant " + realizedCharacteristic.toString()); + logger.error("Returning null type from UnrolledParticipant " + referencedCharacteristic.toString()); } return this.type; } diff --git a/com.epistimis.uddl/src/com/epistimis/uddl/unrolled/UnrolledParticipantP.java b/com.epistimis.uddl/src/com/epistimis/uddl/unrolled/UnrolledParticipantP.java new file mode 100644 index 0000000..0483abc --- /dev/null +++ b/com.epistimis.uddl/src/com/epistimis/uddl/unrolled/UnrolledParticipantP.java @@ -0,0 +1,76 @@ +/** + * + */ +package com.epistimis.uddl.unrolled; + +import org.eclipse.jdt.annotation.NonNull; + +import com.epistimis.uddl.uddl.PlatformCharacteristic; +import com.epistimis.uddl.uddl.PlatformComposableElement; +import com.epistimis.uddl.uddl.PlatformEntity; +import com.epistimis.uddl.uddl.PlatformParticipant; + +/** + * + */ +public class UnrolledParticipantP + extends UnrolledParticipant { + + /** + * @param pp + * @param rce + */ + public UnrolledParticipantP(@NonNull PlatformParticipant pp, UnrolledComposableElementP rce) { + super(pp, rce); + // TODO Auto-generated constructor stub + } + + @Override + public int getSourceLowerBound(PlatformParticipant p) { + // TODO Auto-generated method stub + return p.getSourceLowerBound(); + } + + @Override + public int getSourceUpperBound(PlatformParticipant p) { + // TODO Auto-generated method stub + return p.getSourceUpperBound(); + } + + @Override + public PlatformComposableElement getType(PlatformParticipant p) { + // TODO Auto-generated method stub + return p.getType(); + } + + @Override + PlatformEntity conv2Entity(PlatformComposableElement ce) { + // TODO Auto-generated method stub + return (PlatformEntity)ce; + } + + @Override + String getRolename(PlatformCharacteristic c) { + // TODO Auto-generated method stub + return c.getRolename(); + } + + @Override + String getDescription(PlatformCharacteristic c) { + // TODO Auto-generated method stub + return c.getDescription(); + } + + @Override + int getLowerBound(PlatformCharacteristic c) { + // TODO Auto-generated method stub + return c.getLowerBound(); + } + + @Override + int getUpperBound(PlatformCharacteristic c) { + // TODO Auto-generated method stub + return c.getUpperBound(); + } + +} diff --git a/com.epistimis.uddl/src/com/epistimis/uddl/unrolled/UnrollingFactory.java b/com.epistimis.uddl/src/com/epistimis/uddl/unrolled/UnrollingFactory.java new file mode 100644 index 0000000..a80e504 --- /dev/null +++ b/com.epistimis.uddl/src/com/epistimis/uddl/unrolled/UnrollingFactory.java @@ -0,0 +1,202 @@ +/** + * + */ +package com.epistimis.uddl.unrolled; + +import java.lang.invoke.MethodHandles; +import java.lang.reflect.ParameterizedType; +import java.text.MessageFormat; +import java.util.Map; +import java.util.Set; + +import org.apache.log4j.Logger; +import org.eclipse.emf.ecore.EObject; +import org.eclipse.emf.ecore.resource.Resource; +import org.eclipse.emf.ecore.resource.ResourceSet; +import org.eclipse.xtext.xbase.lib.IteratorExtensions; + +//import com.epistimis.uddl.RealizedEntity; +//import com.epistimis.uddl.UnrolledAssociation; +//import com.epistimis.uddl.UnrolledDataType; +import com.epistimis.uddl.scoping.IndexUtilities; +import com.epistimis.uddl.uddl.PlatformAssociation; +import com.epistimis.uddl.uddl.PlatformComposableElement; +import com.epistimis.uddl.uddl.PlatformDataType; +import com.epistimis.uddl.uddl.PlatformEntity; +import com.epistimis.uddl.uddl.UddlElement; +import com.google.common.collect.Iterables; + +/** + * This class handles creation of unrolled (C/L/P) elements + */ +public abstract class UnrollingFactory, + UComposition extends UnrolledComposition, + UEntity extends UnrolledEntity, + UParticipant extends UnrolledParticipant, + UAssociation extends UnrolledAssociation + > { + + private static Logger logger = Logger.getLogger(MethodHandles.lookup().lookupClass()); + + static final String FMT_STRING = "Could not find realization for type [{0}] and role [{1}] when processing [{2}] with description [{3}]"; + + + //abstract void updateMaps(ComposableElement ce, UComposableElement uce); + abstract Set>> getC2REntrySet(); + abstract > UComp getUnrolledForComposable(ComposableElement type); + abstract ComposableElement getType(UComposition uc); + abstract Map getComposition(UEntity entity); + abstract UEntity createEntity(Entity entity); + abstract boolean isUEntity(Object uce); + abstract void clearMaps(); + abstract String getName(ComposableElement obj); + /** + * Get the type parameters for this generic class See also + * https://stackoverflow.com/questions/4213972/java-generics-get-class-of-generic-methods-return-type + * + * @param ndx the index into the list of type parameters + * @return + */ + public Class returnedTypeParameter(int ndx) { + ParameterizedType parameterizedType = (ParameterizedType) getClass().getGenericSuperclass(); + return (Class) parameterizedType.getActualTypeArguments()[ndx]; + } + + /** + * Methods to return each of the parameter types - these warnings must remain + * because the alternative is a compile error when these values get used. + * + * @return + */ + @SuppressWarnings("rawtypes") + public Class getComposableElementType() { + return returnedTypeParameter(0); + } + + @SuppressWarnings("rawtypes") + public Class getCharacteristicType() { + return returnedTypeParameter(1); + } + + @SuppressWarnings("rawtypes") + public Class getEntityType() { + return returnedTypeParameter(2); + } + + @SuppressWarnings("rawtypes") + public Class getAssociationType() { + return returnedTypeParameter(3); + } + + @SuppressWarnings("rawtypes") + public Class getCompositionType() { + return returnedTypeParameter(4); + } + + @SuppressWarnings("rawtypes") + public Class getParticipantType() { + return returnedTypeParameter(5); + } + + @SuppressWarnings("rawtypes") + public Class getElementalComposableType() { + return returnedTypeParameter(6); + } + + @SuppressWarnings("rawtypes") + public Class getContainerType() { + return returnedTypeParameter(7); + } + + + + /** + * Use the maps to match types. This uses the PlatformComposableElement instances as keys, not FQNs. This should work but it is based on + * object identity. + */ + public void linkTypes() { + for (Map.Entry> entry: getC2REntrySet()) { + ComposableElement ce = entry.getKey(); + Object rce = entry.getValue(); + if (isUEntity(rce)) { + @SuppressWarnings("unchecked") + UEntity re = (UEntity) rce; + for (UComposition rc: re.getComposition().values()) { + ComposableElement type = IndexUtilities.unProxiedEObject(rc.getType(),ce); + UnrolledComposableElement unrolledType = getUnrolledForComposable(type); + if (unrolledType == null) { + String typename = type != null ? getName(type) : "null"; + logger.warn(MessageFormat.format(FMT_STRING,typename,rc.getRolename(), re.getName(), re.getDescription())); + } + rc.setUnrolledType(unrolledType); + } + } + } + } + + /** + * 'Realize' and resolve all the EObjects in the specified ResourceSet. The + * results are cached. + * + * @param resource + */ + public void resolve(ResourceSet rs) { + + /** + * Before doing anything else, resolve all ECore cross references - because we + * don't know if some have been lazy linked + */ + // EcoreUtil2.resolveAll(rs); + + // Before creating new instances, check to see if we already have an instance. + // TODO: We need a way to determine if the AST has changed so we can invalidate the cache. + // How do we do that? Since the cache is keyed by instance ID, it is sufficient that a change + // will cause a new instance to be created, so the old instance won't be found? The problem + // is that approach leaves the old instances in the cache, just unused - which creates a memory + // leak. We need to know to remove old instances. Alternatively, we just always flush the cache + // at this point - which is what we do here. +// UnrolledComposableElement.allComposable2Realized.clear(); +// UnrolledComposableElement.allRealized2Composable.clear(); + clearMaps(); + for (Resource res : rs.getResources()) { + /** + * This will only collect all the realization info from a PlatformEntity -> + * LogicalEntity -> ConceptualEntity to determine what is available. The results + * can then be used to create instances, generate code, or .... + */ + final Iterable elements = Iterables.filter( + IteratorExtensions.toIterable(res.getAllContents()), getComposableElementType()); + + for (final ComposableElement elem : elements) { + if ((elem instanceof PlatformAssociation)) { + new UnrolledAssociationP(((PlatformAssociation) elem)); + } else { + if ((elem instanceof PlatformDataType)) { + new UnrolledDataType(((PlatformDataType) elem)); + } else { + if ((elem instanceof PlatformEntity)) { + new UnrolledEntityP(((PlatformEntity) elem)); + } else { + logger.warn(MessageFormat.format("No processing available for type {0}", + elem.getClass().toString())); + } + } + } + } + } + /** + * Now go back and link all the PlatformEntity types + * + */ + linkTypes(); + } + +} diff --git a/com.epistimis.uddl/src/com/epistimis/uddl/unrolled/UnrollingFactoryP.java b/com.epistimis.uddl/src/com/epistimis/uddl/unrolled/UnrollingFactoryP.java new file mode 100644 index 0000000..31c5eac --- /dev/null +++ b/com.epistimis.uddl/src/com/epistimis/uddl/unrolled/UnrollingFactoryP.java @@ -0,0 +1,114 @@ +/** + * + */ +package com.epistimis.uddl.unrolled; + +import java.util.Map.Entry; +import java.util.HashMap; +import java.util.Map; +import java.util.Set; + +import org.eclipse.emf.common.util.EList; + +import com.epistimis.uddl.uddl.PlatformAssociation; +import com.epistimis.uddl.uddl.PlatformCharacteristic; +import com.epistimis.uddl.uddl.PlatformComposableElement; +import com.epistimis.uddl.uddl.PlatformComposition; +import com.epistimis.uddl.uddl.PlatformDataModel; +import com.epistimis.uddl.uddl.PlatformDataType; +import com.epistimis.uddl.uddl.PlatformEntity; +import com.epistimis.uddl.uddl.PlatformParticipant; + +/** + * + */ +public class UnrollingFactoryP extends + UnrollingFactory { + + + + @Override + UnrolledEntityP createEntity(PlatformEntity entity) { + // TODO Auto-generated method stub + UnrolledEntityP retval = new UnrolledEntityP(entity); +// updateMaps(entity, retval); + return retval; + } + + + @Override + public Set>> getC2REntrySet() { + return UnrolledComposableElementP.allComposable2Unrolled.entrySet(); + } + + @SuppressWarnings("unchecked") // Return type matches type of map values + @Override + public UnrolledComposableElement getUnrolledForComposable(PlatformComposableElement type) { + // TODO Auto-generated method stub + return UnrolledComposableElementP.allComposable2Unrolled.get(type); + } + + @Override + PlatformComposableElement getType(UnrolledCompositionP uc) { + // TODO Auto-generated method stub + return null; + } + + @Override + Map getComposition(UnrolledEntityP entity) { + // TODO Auto-generated method stub + return null; + } + + @Override + boolean isUEntity(Object uce) { + // TODO Auto-generated method stub + return (uce instanceof UnrolledEntityP); + } + + + @Override + void clearMaps() { + // TODO Auto-generated method stub + UnrolledComposableElementP.allComposable2Unrolled.clear(); + UnrolledComposableElementP.allUnrolled2Composable.clear(); + } + + + @Override + String getName(PlatformComposableElement obj) { + return obj.getName(); +// // TODO Auto-generated method stub +// if (obj instanceof UnrolledComposableElementP) { +// return ((UnrolledComposableElementP)obj).getName(); +// } +// if (obj instanceof UnrolledEntityP) { +// return ((UnrolledEntityP)obj).getName(); +// } +// if (obj instanceof UnrolledAssociationP) { +// return ((UnrolledAssociationP)obj).getName(); +// } +// +// return ""; + } + +// @Override +// UnrolledEntityP createEntity(PlatformEntity entity) { +// // TODO Auto-generated method stub +// return null; +// } + +}