use of org.eclipse.winery.common.ids.definitions.RequirementTypeId in project winery by eclipse.
the class BackendUtils method createWrapperDefinitionsAndInitialEmptyElement.
public static Definitions createWrapperDefinitionsAndInitialEmptyElement(IRepository repository, DefinitionsChildId id) {
final Definitions definitions = createWrapperDefinitions(id);
HasIdInIdOrNameField element;
if (id instanceof RelationshipTypeImplementationId) {
element = new TRelationshipTypeImplementation();
} else if (id instanceof NodeTypeImplementationId) {
element = new TNodeTypeImplementation();
} else if (id instanceof RequirementTypeId) {
element = new TRequirementType();
} else if (id instanceof NodeTypeId) {
element = new TNodeType();
} else if (id instanceof RelationshipTypeId) {
element = new TRelationshipType();
} else if (id instanceof CapabilityTypeId) {
element = new TCapabilityType();
} else if (id instanceof ArtifactTypeId) {
element = new TArtifactType();
} else if (id instanceof PolicyTypeId) {
element = new TPolicyType();
} else if (id instanceof PolicyTemplateId) {
element = new TPolicyTemplate();
} else if (id instanceof ServiceTemplateId) {
element = new TServiceTemplate();
} else if (id instanceof ArtifactTemplateId) {
element = new TArtifactTemplate();
} else if (id instanceof XSDImportId) {
// TImport has no id; thus directly generating it without setting an id
TImport tImport = new TImport();
definitions.setElement(tImport);
return definitions;
} else {
throw new IllegalStateException("Unhandled id branch. Could happen for XSDImportId");
}
copyIdToFields(element, id);
definitions.setElement((TExtensibleElements) element);
return definitions;
}
use of org.eclipse.winery.common.ids.definitions.RequirementTypeId in project winery by eclipse.
the class IGenericRepository method getReferencedDefinitionsChildIds.
default Collection<DefinitionsChildId> getReferencedDefinitionsChildIds(ComplianceRuleId id) {
// We have to use a HashSet to ensure that no duplicate ids are added
// E.g., there may be multiple relationship templates having the same type
Collection<DefinitionsChildId> ids = new HashSet<>();
TComplianceRule complianceRule = this.getElement(id);
// TODO extend to required Structure
if (complianceRule.getIdentifier() != null) {
for (TEntityTemplate entityTemplate : complianceRule.getIdentifier().getNodeTemplateOrRelationshipTemplate()) {
QName qname = entityTemplate.getType();
if (entityTemplate instanceof TNodeTemplate) {
ids.add(new NodeTypeId(qname));
TNodeTemplate n = (TNodeTemplate) entityTemplate;
// crawl through deployment artifacts
TDeploymentArtifacts deploymentArtifacts = n.getDeploymentArtifacts();
if (deploymentArtifacts != null) {
List<TDeploymentArtifact> das = deploymentArtifacts.getDeploymentArtifact();
for (TDeploymentArtifact da : das) {
ids.add(new ArtifactTypeId(da.getArtifactType()));
if ((qname = da.getArtifactRef()) != null) {
ids.add(new ArtifactTemplateId(qname));
}
}
}
// crawl through reqs/caps
TNodeTemplate.Requirements requirements = n.getRequirements();
if (requirements != null) {
for (TRequirement req : requirements.getRequirement()) {
QName type = req.getType();
RequirementTypeId rtId = new RequirementTypeId(type);
ids.add(rtId);
}
}
TNodeTemplate.Capabilities capabilities = n.getCapabilities();
if (capabilities != null) {
for (TCapability cap : capabilities.getCapability()) {
QName type = cap.getType();
CapabilityTypeId ctId = new CapabilityTypeId(type);
ids.add(ctId);
}
}
// crawl through policies
org.eclipse.winery.model.tosca.TNodeTemplate.Policies policies = n.getPolicies();
if (policies != null) {
for (TPolicy pol : policies.getPolicy()) {
QName type = pol.getPolicyType();
PolicyTypeId ctId = new PolicyTypeId(type);
ids.add(ctId);
}
}
} else {
assert (entityTemplate instanceof TRelationshipTemplate);
ids.add(new RelationshipTypeId(qname));
}
}
}
return ids;
}
use of org.eclipse.winery.common.ids.definitions.RequirementTypeId in project winery by eclipse.
the class IGenericRepository method getReferencedDefinitionsChildIds.
default Collection<DefinitionsChildId> getReferencedDefinitionsChildIds(NodeTypeId id) {
Collection<DefinitionsChildId> ids = new ArrayList<>();
Collection<NodeTypeImplementationId> allNodeTypeImplementations = this.getAllElementsReferencingGivenType(NodeTypeImplementationId.class, id.getQName());
for (NodeTypeImplementationId ntiId : allNodeTypeImplementations) {
ids.add(ntiId);
}
final TNodeType nodeType = this.getElement(id);
// add all referenced requirement types
TNodeType.RequirementDefinitions reqDefsContainer = nodeType.getRequirementDefinitions();
if (reqDefsContainer != null) {
List<TRequirementDefinition> reqDefs = reqDefsContainer.getRequirementDefinition();
for (TRequirementDefinition reqDef : reqDefs) {
RequirementTypeId reqTypeId = new RequirementTypeId(reqDef.getRequirementType());
ids.add(reqTypeId);
}
}
// add all referenced capability types
TNodeType.CapabilityDefinitions capDefsContainer = nodeType.getCapabilityDefinitions();
if (capDefsContainer != null) {
List<TCapabilityDefinition> capDefs = capDefsContainer.getCapabilityDefinition();
for (TCapabilityDefinition capDef : capDefs) {
CapabilityTypeId capTypeId = new CapabilityTypeId(capDef.getCapabilityType());
ids.add(capTypeId);
}
}
return ids;
}
use of org.eclipse.winery.common.ids.definitions.RequirementTypeId in project winery by eclipse.
the class IGenericRepository method getReferencedDefinitionsChildIds.
default Collection<DefinitionsChildId> getReferencedDefinitionsChildIds(RelationshipTypeId id) {
Collection<DefinitionsChildId> ids = new ArrayList<>();
// add all implementations
Collection<RelationshipTypeImplementationId> allTypeImplementations = this.getAllElementsReferencingGivenType(RelationshipTypeImplementationId.class, id.getQName());
for (RelationshipTypeImplementationId ntiId : allTypeImplementations) {
ids.add(ntiId);
}
final TRelationshipType relationshipType = this.getElement(id);
TRelationshipType.ValidSource validSource = relationshipType.getValidSource();
if (validSource != null) {
QName typeRef = validSource.getTypeRef();
// can be a node type or a requirement type
// similar code as for valid target (difference: req/cap)
NodeTypeId ntId = new NodeTypeId(typeRef);
if (this.exists(ntId)) {
ids.add(ntId);
} else {
RequirementTypeId rtId = new RequirementTypeId(typeRef);
ids.add(rtId);
}
}
TRelationshipType.ValidTarget validTarget = relationshipType.getValidTarget();
if (validTarget != null) {
QName typeRef = validTarget.getTypeRef();
// can be a node type or a capability type
// similar code as for valid target (difference: req/cap)
NodeTypeId ntId = new NodeTypeId(typeRef);
if (this.exists(ntId)) {
ids.add(ntId);
} else {
CapabilityTypeId capId = new CapabilityTypeId(typeRef);
ids.add(capId);
}
}
return ids;
}
use of org.eclipse.winery.common.ids.definitions.RequirementTypeId in project winery by eclipse.
the class Splitting method getRequiredCapabilityTypeQNameOfRequirement.
private QName getRequiredCapabilityTypeQNameOfRequirement(TRequirement requirement) {
QName reqTypeQName = requirement.getType();
RequirementTypeId reqTypeId = new RequirementTypeId(reqTypeQName);
TRequirementType requirementType = RepositoryFactory.getRepository().getElement(reqTypeId);
return requirementType.getRequiredCapabilityType();
}
Aggregations