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.nodetypeimplementations;
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.NodeTypeImplementationId;
19 import org.eclipse.winery.model.tosca.TDeploymentArtifacts;
20 import org.eclipse.winery.model.tosca.TExtensibleElements;
21 import org.eclipse.winery.model.tosca.TImplementationArtifacts;
22 import org.eclipse.winery.model.tosca.TNodeTypeImplementation;
23 import org.eclipse.winery.repository.backend.BackendUtils;
24 import org.eclipse.winery.repository.resources.INodeTemplateResourceOrNodeTypeImplementationResource;
25 import org.eclipse.winery.repository.resources.INodeTypeImplementationResourceOrRelationshipTypeImplementationResource;
26 import org.eclipse.winery.repository.resources.artifacts.DeploymentArtifactsResource;
27 import org.eclipse.winery.repository.resources.artifacts.ImplementationArtifactsResource;
28 import org.eclipse.winery.repository.resources.entitytypeimplementations.EntityTypeImplementationResource;
30 public class NodeTypeImplementationResource extends EntityTypeImplementationResource implements INodeTemplateResourceOrNodeTypeImplementationResource, INodeTypeImplementationResourceOrRelationshipTypeImplementationResource {
32 public NodeTypeImplementationResource(NodeTypeImplementationId id) {
37 * public because of exporter
39 public TNodeTypeImplementation getNTI() {
40 return (TNodeTypeImplementation) this.getElement();
44 * Even if both node type implementations and relationship type
45 * implementations have implementation artifacts, there is no common
46 * supertype. To avoid endless casts, we just implement the method here
50 @Path("implementationartifacts/")
51 public ImplementationArtifactsResource getImplementationArtifacts() {
52 TImplementationArtifacts implementationArtifacts;
53 implementationArtifacts = this.getNTI().getImplementationArtifacts();
54 if (implementationArtifacts == null) {
55 implementationArtifacts = new TImplementationArtifacts();
56 this.getNTI().setImplementationArtifacts(implementationArtifacts);
58 return new ImplementationArtifactsResource(implementationArtifacts.getImplementationArtifact(), this);
62 * Only NodeTypes have deployment artifacts, not RelationshipType.
63 * Therefore, this method is declared in
64 * {@link NodeTypeImplementationResource} and not in
65 * {@link EntityTypeImplementationResource}
67 @Path("deploymentartifacts/")
68 public DeploymentArtifactsResource getDeploymentArtifacts() {
69 TDeploymentArtifacts deploymentArtifacts;
70 deploymentArtifacts = this.getNTI().getDeploymentArtifacts();
71 if (deploymentArtifacts == null) {
72 deploymentArtifacts = new TDeploymentArtifacts();
73 this.getNTI().setDeploymentArtifacts(deploymentArtifacts);
75 return new DeploymentArtifactsResource(deploymentArtifacts.getDeploymentArtifact(), this);
79 protected TExtensibleElements createNewElement() {
80 return new TNodeTypeImplementation();
84 protected void copyIdToFields() {
85 this.getNTI().setTargetNamespace(this.getId().getNamespace().getDecoded());
86 this.getNTI().setName(this.getId().getXmlId().getDecoded());
90 public QName getType() {
91 return this.getNTI().getNodeType();
95 public Response setType(QName type) {
96 this.getNTI().setNodeType(type);
97 return BackendUtils.persist(this);
101 public Response setType(String typeStr) {
102 QName type = QName.valueOf(typeStr);
103 return this.setType(type);