blob: 6c573a559c8c701ddb4ffa395daf4b04f44d602f (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
|
/*******************************************************************************
* Copyright (c) 2012-2013 University of Stuttgart.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* and the Apache License 2.0 which both accompany this distribution,
* and are available at http://www.eclipse.org/legal/epl-v10.html
* and http://www.apache.org/licenses/LICENSE-2.0
*
* Contributors:
* Oliver Kopp - initial API and implementation
*******************************************************************************/
package org.eclipse.winery.repository.resources.entitytypes.nodetypes;
import javax.ws.rs.Path;
import org.eclipse.winery.model.tosca.TExtensibleElements;
import org.eclipse.winery.model.tosca.TNodeType;
import org.eclipse.winery.model.tosca.TNodeType.CapabilityDefinitions;
import org.eclipse.winery.model.tosca.TNodeType.Interfaces;
import org.eclipse.winery.model.tosca.TNodeType.RequirementDefinitions;
import org.eclipse.winery.model.tosca.TTopologyElementInstanceStates;
import org.eclipse.winery.common.ids.definitions.NodeTypeId;
import org.eclipse.winery.repository.resources.entitytypes.InstanceStatesResource;
import org.eclipse.winery.repository.resources.entitytypes.TopologyGraphElementEntityTypeResource;
import org.eclipse.winery.repository.resources.entitytypes.nodetypes.reqandcapdefs.CapabilityDefinitionsResource;
import org.eclipse.winery.repository.resources.entitytypes.nodetypes.reqandcapdefs.RequirementDefinitionsResource;
import org.eclipse.winery.repository.resources.interfaces.InterfacesResource;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class NodeTypeResource extends TopologyGraphElementEntityTypeResource {
private static final Logger logger = LoggerFactory.getLogger(NodeTypeResource.class);
public NodeTypeResource(NodeTypeId id) {
super(id);
}
/**
* Convenience method to avoid casting at the caller's side.
*/
public TNodeType getNodeType() {
return (TNodeType) this.getElement();
}
/** sub-resources **/
@Path("implementations/")
public ImplementationsOfOneNodeTypeResource getImplementations() {
return new ImplementationsOfOneNodeTypeResource((NodeTypeId) this.id);
}
@Path("instancestates/")
public InstanceStatesResource getInstanceStatesResource() {
TTopologyElementInstanceStates instanceStates = this.getNodeType().getInstanceStates();
if (instanceStates == null) {
// if an explicit (empty) list does not exist, create it
instanceStates = new TTopologyElementInstanceStates();
this.getNodeType().setInstanceStates(instanceStates);
}
return new InstanceStatesResource(instanceStates, this);
}
@Path("interfaces/")
public InterfacesResource getInterfaces() {
Interfaces interfaces = this.getNodeType().getInterfaces();
if (interfaces == null) {
interfaces = new Interfaces();
this.getNodeType().setInterfaces(interfaces);
}
return new InterfacesResource(null, interfaces.getInterface(), this);
}
@Path("requirementdefinitions/")
public RequirementDefinitionsResource getRequirementDefinitions() {
RequirementDefinitions definitions = this.getNodeType().getRequirementDefinitions();
if (definitions == null) {
definitions = new RequirementDefinitions();
this.getNodeType().setRequirementDefinitions(definitions);
}
return new RequirementDefinitionsResource(this, definitions.getRequirementDefinition());
}
@Path("capabilitydefinitions/")
public CapabilityDefinitionsResource getCapabilityDefinitions() {
CapabilityDefinitions definitions = this.getNodeType().getCapabilityDefinitions();
if (definitions == null) {
definitions = new CapabilityDefinitions();
this.getNodeType().setCapabilityDefinitions(definitions);
}
return new CapabilityDefinitionsResource(this, definitions.getCapabilityDefinition());
}
@Path("visualappearance/")
public VisualAppearanceResource getVisualAppearanceResource() {
return new VisualAppearanceResource(this, this.getElement().getOtherAttributes(), (NodeTypeId) this.id);
}
@Override
protected TExtensibleElements createNewElement() {
return new TNodeType();
}
}
|