ee9064b56437ef4f589daa2d8bf50a2934579a5e
[vfc/nfvo/wfengine.git] / winery / org.eclipse.winery.repository / src / main / java / org / eclipse / winery / repository / resources / entitytemplates / TEntityTemplateResource.java
1 /*******************************************************************************
2  * Copyright (c) 2012-2014 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
8  *
9  * Contributors:
10  *     Oliver Kopp - initial API and implementation
11  *******************************************************************************/
12 package org.eclipse.winery.repository.resources.entitytemplates;
13
14 import java.util.List;
15
16 import javax.ws.rs.GET;
17 import javax.ws.rs.Path;
18 import javax.ws.rs.core.Response;
19 import javax.xml.namespace.QName;
20
21 import org.eclipse.winery.model.tosca.TEntityTemplate;
22 import org.eclipse.winery.repository.backend.BackendUtils;
23 import org.eclipse.winery.repository.resources.AbstractComponentInstanceResource;
24 import org.eclipse.winery.repository.resources.IHasTypeReference;
25 import org.eclipse.winery.repository.resources._support.IPersistable;
26 import org.eclipse.winery.repository.resources._support.collections.IIdDetermination;
27 import org.eclipse.winery.repository.resources._support.collections.withid.EntityWithIdResource;
28
29 public class TEntityTemplateResource<E extends TEntityTemplate> extends EntityWithIdResource<E> implements IEntityTemplateResource<E>, IHasTypeReference {
30         
31         /**
32          * This constructor is used for both entity templates nested in an component
33          * instance as well as for entity templates being component instances
34          * itself.
35          * 
36          * As Java does not support multi-inheritance, we implemented a quick hack
37          * to re-use this class as inner implementation at templates extending
38          * AbstractComponentInstanceResourceDefinitionsBacked
39          */
40         public TEntityTemplateResource(IIdDetermination<E> idDetermination, E o, int idx, List<E> list, IPersistable res) {
41                 super(idDetermination, o, idx, list, res);
42         }
43         
44         //      public String getId() {
45         //              return this.template.getId();
46         //      }
47         //
48         //      public void setId(String id) {
49         //              // TODO: There is no check for uniqueness of the given id
50         //              this.template.setId(id);
51         //      }
52         
53         /**
54          * {@inheritDoc}
55          */
56         @Override
57         public QName getType() {
58                 return this.o.getType();
59         }
60         
61         @Path("type")
62         @GET
63         public String getTypeAsQNameString() {
64                 return this.getType().toString();
65         }
66         
67         /**
68          * {@inheritDoc}
69          */
70         @Override
71         public Response setType(QName type) {
72                 this.o.setType(type);
73                 return BackendUtils.persist(this.res);
74         }
75         
76         /**
77          * {@inheritDoc}
78          */
79         @Override
80         public Response setType(String typeStr) {
81                 return this.setType(QName.valueOf(typeStr));
82         }
83         
84         /**
85          * {@inheritDoc}
86          */
87         @Override
88         public PropertiesResource getPropertiesResource() {
89                 return new PropertiesResource(this.o, (AbstractComponentInstanceResource) this.res);
90         }
91         
92 }