| |
---|
| | import models.dataConstraintModel.ChannelMember; |
---|
| | import models.dataConstraintModel.DataConstraintModel; |
---|
| | import models.dataConstraintModel.IdentifierTemplate; |
---|
| | import models.dataFlowModel.DataFlowModel; |
---|
| | import models.dataFlowModel.DataflowChannelGenerator; |
---|
| | import models.dataFlowModel.DataflowChannelGenerator.IResourceStateAccessor; |
---|
| | import models.dataFlowModel.PushPullAttribute; |
---|
| | import models.dataFlowModel.PushPullValue; |
---|
| | import models.dataFlowModel.ResourceDependency; |
---|
| |
---|
| | if (rn.getIndegree() > 1) { |
---|
| | // Declare a field to cash the state of the source resource in the type of the destination resource. |
---|
| | String cashInitializer = null; |
---|
| | Type cashType = ((ResourceNode) re.getSource()).getIdentifierTemplate().getResourceStateType(); |
---|
| | if (DataConstraintModel.typeList.isAncestorOf(cashType) || DataConstraintModel.typeTuple.isAncestorOf(cashType)) { |
---|
| | if (DataConstraintModel.typeList.isAncestorOf(cashType)) { |
---|
| | cashInitializer = "new " + cashType.getImplementationTypeName() + "()"; |
---|
| | } |
---|
| | type.addField(new FieldDeclaration( |
---|
| | cashType, ((ResourceNode) re.getSource()).getIdentifierTemplate().getResourceName(), cashInitializer)); |
---|
| | } |
---|
| | } |
---|
| | } |
---|
| | Set<IdentifierTemplate> refs = new HashSet<>(); |
---|
| | for (ChannelGenerator cg : model.getChannelGenerators()) { |
---|
| | DataflowChannelGenerator c = (DataflowChannelGenerator) cg; |
---|
| | if (c.getOutputIdentifierTemplates().contains(rn.getIdentifierTemplate())) { |
---|
| | for (IdentifierTemplate id: c.getReferenceIdentifierTemplates()) { |
---|
| | if (!refs.contains(id)) { |
---|
| | refs.add(id); |
---|
| | String refResName = id.getResourceName(); |
---|
| | fieldInitializer += refResName.toLowerCase() + ","; |
---|
| | f = true; |
---|
| | } |
---|
| | } |
---|
| | } |
---|
| | } |
---|
| | if (f) |
---|
| |
---|
| | vars.add(new VariableDeclaration( |
---|
| | ((ResourceNode) re.getSource()).getIdentifierTemplate().getResourceStateType(), |
---|
| | ((ResourceNode) re.getSource()).getIdentifierTemplate().getResourceName())); |
---|
| | type.addMethod(new MethodDeclaration("update" + srcResName, false, typeVoid, vars)); |
---|
| | } |
---|
| | } |
---|
| | // Declare a field to refer to the reference resource. |
---|
| | refs = new HashSet<>(); |
---|
| | for (ChannelGenerator cg : model.getChannelGenerators()) { |
---|
| | DataflowChannelGenerator c = (DataflowChannelGenerator) cg; |
---|
| | if (c.getOutputIdentifierTemplates().contains(rn.getIdentifierTemplate())) { |
---|
| | for (IdentifierTemplate id: c.getReferenceIdentifierTemplates()) { |
---|
| | if (!refs.contains(id)) { |
---|
| | refs.add(id); |
---|
| | String refResName = id.getResourceName(); |
---|
| | refResName = refResName.substring(0, 1).toUpperCase() + refResName.substring(1); |
---|
| | type.addField(new FieldDeclaration(new Type(refResName, refResName), id.getResourceName())); |
---|
| | constructor.addParameter(new VariableDeclaration(new Type(refResName, refResName), id.getResourceName())); |
---|
| | block.addStatement("this." + refResName.toLowerCase() + " = " + refResName.toLowerCase() + ";"); |
---|
| | constructor.setBody(block); |
---|
| | } |
---|
| | } |
---|
| | } |
---|
| | } |
---|
| | if (constructor.getParameters() != null) |
---|
| | type.addMethod(constructor); |
---|
| |
---|
| | } |
---|
| | |
---|
| | // Declare the field to store the state in the type of each resource. |
---|
| | if (((StoreAttribute) rn.getAttribute()).isStored()) { |
---|
| | String str = "new " + rn.getIdentifierTemplate().getResourceStateType().getImplementationTypeName() |
---|
| | + "()"; |
---|
| | String initializer = "new " + rn.getIdentifierTemplate().getResourceStateType().getImplementationTypeName() + "()"; |
---|
| | Type stateType = rn.getIdentifierTemplate().getResourceStateType(); |
---|
| | if (!DataConstraintModel.typeList.isAncestorOf(stateType) && !DataConstraintModel.typeTuple.isAncestorOf(stateType)) |
---|
| | str = null; |
---|
| | type.addField(new FieldDeclaration(stateType, rn.getIdentifierTemplate().getResourceName(), str)); |
---|
| | if (!DataConstraintModel.typeList.isAncestorOf(stateType)) initializer = null; |
---|
| | type.addField(new FieldDeclaration(stateType, rn.getIdentifierTemplate().getResourceName(), initializer)); |
---|
| | } |
---|
| | |
---|
| | // Declare the getter method to obtain the state in the type of each resource. |
---|
| | type.addMethod(new MethodDeclaration("get" + type.getTypeName(), |
---|
| |
---|
| | |