Add winery source code
[vfc/nfvo/wfengine.git] / winery / org.eclipse.winery.repository / src / main / java / org / eclipse / winery / repository / resources / entitytypes / properties / JSPData.java
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
8  *
9  * Contributors:
10  *     Oliver Kopp - initial API and implementation
11  *******************************************************************************/
12 package org.eclipse.winery.repository.resources.entitytypes.properties;
13
14 import java.util.List;
15
16 import org.eclipse.winery.common.propertydefinitionkv.PropertyDefinitionKV;
17 import org.eclipse.winery.common.propertydefinitionkv.WinerysPropertiesDefinition;
18 import org.eclipse.winery.model.tosca.TEntityType;
19
20 /**
21  * Collects data used by the JSP
22  */
23 public class JSPData {
24         
25         // FIXME: this is a quick hack and provides a fixed list of available
26         // property types only. This list has to be made dynamically updatable (and offer plugins to edit)
27         // currently only http://www.w3.org/TR/2001/REC-xmlschema-2-20010502/#built-in-datatypes are supported
28         private static final String[] availablePropertyTypes = {"xsd:string", "xsd:boolean", "xsd:decimal", "xsd:float", "xsd:anyURI", "xsd:QName"};
29         
30         private final PropertiesDefinitionResource propertiesDefinitionResource;
31         private final WinerysPropertiesDefinition wpd;
32         
33         
34         public JSPData(PropertiesDefinitionResource propertiesDefinitionResource, WinerysPropertiesDefinition wpd) {
35                 this.propertiesDefinitionResource = propertiesDefinitionResource;
36                 this.wpd = wpd;
37         }
38         
39         public List<PropertyDefinitionKV> getPropertyDefinitionKVList() {
40                 // as this method is used by the JSP, we have to initialize the list and not provide a fake list
41                 // in other words: we are in the mode, where the user has chosen the winery property handling
42                 assert (this.getIsWineryKeyValueProperties());
43                 if (this.wpd.getPropertyDefinitionKVList() == null) {
44                         return java.util.Collections.emptyList();
45                 } else {
46                         return this.wpd.getPropertyDefinitionKVList();
47                 }
48         }
49         
50         public Boolean getIsWineryKeyValueProperties() {
51                 return (this.wpd != null);
52                 // the jsp renders list data only if the list is existing
53                 // we could (somehow) also always keep the old list, but we opted for keeping the choice between the four options also in the XML (and not storing stale data)
54                 // in the case, the WPD is derived from XSD, the list is rendered nevertheless
55         }
56         
57         public boolean getIsWineryKeyValuePropertiesDerivedFromXSD() {
58                 return ((this.wpd != null) && (this.wpd.getIsDerivedFromXSD() != null));
59         }
60         
61         public String[] getAvailablePropertyTypes() {
62                 return JSPData.availablePropertyTypes;
63         }
64         
65         public TEntityType getEntityType() {
66                 return this.propertiesDefinitionResource.getEntityType();
67         }
68         
69         public String getElementName() {
70                 if (this.wpd == null) {
71                         return null;
72                 } else {
73                         return this.wpd.getElementName();
74                 }
75         }
76         
77         public String getNamespace() {
78                 if (this.wpd == null) {
79                         return null;
80                 } else {
81                         return this.wpd.getNamespace();
82                 }
83         }
84         
85 }