1 /*******************************************************************************
2 * Copyright (c) 2012-2013 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.entitytypeimplementations.relationshiptypeimplementations;
14 import javax.ws.rs.Path;
15 import javax.ws.rs.core.Response;
16 import javax.xml.namespace.QName;
18 import org.eclipse.winery.common.ids.definitions.RelationshipTypeImplementationId;
19 import org.eclipse.winery.model.tosca.TExtensibleElements;
20 import org.eclipse.winery.model.tosca.TImplementationArtifacts;
21 import org.eclipse.winery.model.tosca.TRelationshipTypeImplementation;
22 import org.eclipse.winery.repository.backend.BackendUtils;
23 import org.eclipse.winery.repository.resources.INodeTypeImplementationResourceOrRelationshipTypeImplementationResource;
24 import org.eclipse.winery.repository.resources.artifacts.ImplementationArtifactsResource;
25 import org.eclipse.winery.repository.resources.entitytypeimplementations.EntityTypeImplementationResource;
27 public class RelationshipTypeImplementationResource extends EntityTypeImplementationResource implements INodeTypeImplementationResourceOrRelationshipTypeImplementationResource {
29 public RelationshipTypeImplementationResource(RelationshipTypeImplementationId id) {
33 public TRelationshipTypeImplementation getRTI() {
34 return (TRelationshipTypeImplementation) this.getElement();
38 * Even if both node type implementations and relationship type
39 * implementations have implementation artifacts, there is no common
40 * supertype. To avoid endless casts, we just implement the method here
42 @Path("implementationartifacts/")
43 public ImplementationArtifactsResource getImplementationArtifacts() {
44 TImplementationArtifacts implementationArtifacts;
45 implementationArtifacts = this.getRTI().getImplementationArtifacts();
46 if (implementationArtifacts == null) {
47 implementationArtifacts = new TImplementationArtifacts();
48 this.getRTI().setImplementationArtifacts(implementationArtifacts);
50 return new ImplementationArtifactsResource(implementationArtifacts.getImplementationArtifact(), this);
54 protected TExtensibleElements createNewElement() {
55 return new TRelationshipTypeImplementation();
59 protected void copyIdToFields() {
60 this.getRTI().setTargetNamespace(this.getId().getNamespace().getDecoded());
61 this.getRTI().setName(this.getId().getXmlId().getDecoded());
65 public QName getType() {
66 return this.getRTI().getRelationshipType();
70 public Response setType(QName type) {
71 this.getRTI().setRelationshipType(type);
72 return BackendUtils.persist(this);
76 public Response setType(String typeStr) {
77 QName qname = QName.valueOf(typeStr);
78 return this.setType(qname);