1 /*******************************************************************************
2 * Copyright (c) 2012-2013,2015 University of Stuttgart.
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Eclipse Public License v1.0
5 * and the Apache License 2.0 which both accompany this distribution,
6 * and are available at http://www.eclipse.org/legal/epl-v10.html
7 * and http://www.apache.org/licenses/LICENSE-2.0
10 * Oliver Kopp - initial API and implementation
11 *******************************************************************************/
12 package org.eclipse.winery.repository.resources.artifacts;
14 import java.util.ArrayList;
15 import java.util.Collection;
16 import java.util.List;
18 import javax.xml.namespace.QName;
20 import org.eclipse.winery.model.tosca.TImplementationArtifacts.ImplementationArtifact;
21 import org.eclipse.winery.repository.resources.INodeTypeImplementationResourceOrRelationshipTypeImplementationResource;
22 import org.eclipse.winery.repository.resources.entitytypeimplementations.nodetypeimplementations.NodeTypeImplementationResource;
23 import org.eclipse.winery.repository.resources.entitytypeimplementations.relationshiptypeimplementations.RelationshipTypeImplementationResource;
24 import org.eclipse.winery.repository.resources.entitytypes.nodetypes.NodeTypeResource;
25 import org.eclipse.winery.repository.resources.entitytypes.nodetypes.NodeTypesResource;
26 import org.eclipse.winery.repository.resources.entitytypes.relationshiptypes.RelationshipTypeResource;
27 import org.eclipse.winery.repository.resources.entitytypes.relationshiptypes.RelationshipTypesResource;
28 import org.eclipse.winery.repository.resources.interfaces.InterfaceResource;
31 * ImplementationArtifact instead of TImplementationArtifact has to be used
32 * because of difference in the XSD at tImplementationArtifacts vs.
33 * tDeploymentArtifacts
35 public class ImplementationArtifactsResource extends GenericArtifactsResource<ImplementationArtifactResource, ImplementationArtifact> {
37 private List<ImplementationArtifact> implementationArtifacts;
40 public ImplementationArtifactsResource(List<ImplementationArtifact> implementationArtifact, INodeTypeImplementationResourceOrRelationshipTypeImplementationResource res) {
41 super(ImplementationArtifactResource.class, ImplementationArtifact.class, implementationArtifact, res);
42 this.implementationArtifacts = implementationArtifact;
46 * @return a cast to TNodeTypeImplementationResource of the parent of this
49 protected NodeTypeImplementationResource getNTI() {
50 return (NodeTypeImplementationResource) this.res;
54 * @return a cast to TNodeTypeImplementationResource of the parent of this
57 protected RelationshipTypeImplementationResource getRTI() {
58 return (RelationshipTypeImplementationResource) this.res;
62 public Collection<ImplementationArtifactResource> getAllArtifactResources() {
63 Collection<ImplementationArtifactResource> res = new ArrayList<ImplementationArtifactResource>(this.implementationArtifacts.size());
64 for (ImplementationArtifact da : this.implementationArtifacts) {
65 ImplementationArtifactResource r = new ImplementationArtifactResource(da, this.implementationArtifacts, this.res);
71 /** required by artifacts.jsp **/
72 public List<InterfaceResource> getInterfacesOfAssociatedType() {
73 boolean isNodeTypeImplementation = this.res instanceof NodeTypeImplementationResource;
75 List<InterfaceResource> interfaces = new ArrayList<InterfaceResource>();
76 if (isNodeTypeImplementation) {
77 type = this.getNTI().getType();
78 NodeTypeResource typeResource = (NodeTypeResource) new NodeTypesResource().getComponentInstaceResource(type);
79 interfaces.addAll(typeResource.getInterfaces().getAllEntityResources());
81 type = this.getRTI().getType();
82 RelationshipTypeResource typeResource = (RelationshipTypeResource) new RelationshipTypesResource().getComponentInstaceResource(type);
83 interfaces.addAll(typeResource.getSourceInterfaces().getAllEntityResources());
84 interfaces.addAll(typeResource.getTargetInterfaces().getAllEntityResources());
90 public String getId(ImplementationArtifact entity) {
91 return entity.getName();