2 * Copyright 2015 Samsung Electronics All Rights Reserved.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 package oic.simulator.clientcontroller.utils;
21 import org.oic.simulator.AttributeValue;
22 import org.oic.simulator.AttributeValueVisitor;
23 import org.oic.simulator.SimulatorResourceModel;
25 public class AttributeValueStringConverter implements
26 AttributeValueVisitor.VisitingMethods<String> {
28 private AttributeValue mValue;
30 public AttributeValueStringConverter(AttributeValue value) {
35 public String toString() {
36 AttributeValueVisitor visitor = new AttributeValueVisitor(mValue, this);
37 return (String) visitor.visit();
41 public String visitingValue(Integer value) {
42 return value.toString();
46 public String visitingValue(Double value) {
47 return value.toString();
51 public String visitingValue(Boolean value) {
52 return value.toString();
56 public String visitingValue(String value) {
57 return new String(value);
61 public String visitingValue(SimulatorResourceModel value) {
62 StringBuilder result = new StringBuilder();
65 for (Map.Entry<String, AttributeValue> entry : value.get().entrySet()) {
69 result.append("\"" + entry.getKey() + "\":");
70 AttributeValue attributeValue = entry.getValue();
71 result.append(new AttributeValueStringConverter(attributeValue)
76 return result.toString();
80 public String visitingValue(Integer[] values) {
81 StringBuilder result = new StringBuilder();
84 for (Integer value : values) {
88 result.append(value.toString());
92 return result.toString();
96 public String visitingValue(Double[] values) {
97 StringBuilder result = new StringBuilder();
100 for (Double value : values) {
104 result.append(value.toString());
108 return result.toString();
112 public String visitingValue(Boolean[] values) {
113 StringBuilder result = new StringBuilder();
115 boolean first = true;
116 for (Boolean value : values) {
120 result.append(value.toString());
124 return result.toString();
128 public String visitingValue(String[] values) {
129 StringBuilder result = new StringBuilder();
131 boolean first = true;
132 for (String value : values) {
136 result.append(value);
140 return result.toString();
144 public String visitingValue(SimulatorResourceModel[] values) {
145 StringBuilder result = new StringBuilder();
147 boolean first = true;
148 for (SimulatorResourceModel value : values) {
152 AttributeValue attributeValue = new AttributeValue(value);
153 result.append(new AttributeValueStringConverter(attributeValue)
158 return result.toString();
162 public String visitingValue(Integer[][] values) {
163 StringBuilder result = new StringBuilder();
165 boolean first = true;
166 for (Integer[] value : values) {
170 AttributeValue attributeValue = new AttributeValue(value);
171 result.append(new AttributeValueStringConverter(attributeValue)
176 return result.toString();
180 public String visitingValue(Double[][] values) {
181 StringBuilder result = new StringBuilder();
183 boolean first = true;
184 for (Double[] value : values) {
188 AttributeValue attributeValue = new AttributeValue(value);
189 result.append(new AttributeValueStringConverter(attributeValue)
194 return result.toString();
198 public String visitingValue(Boolean[][] values) {
199 StringBuilder result = new StringBuilder();
201 boolean first = true;
202 for (Boolean[] value : values) {
206 AttributeValue attributeValue = new AttributeValue(value);
207 result.append(new AttributeValueStringConverter(attributeValue)
212 return result.toString();
216 public String visitingValue(String[][] values) {
217 StringBuilder result = new StringBuilder();
219 boolean first = true;
220 for (String[] value : values) {
224 AttributeValue attributeValue = new AttributeValue(value);
225 result.append(new AttributeValueStringConverter(attributeValue)
230 return result.toString();
234 public String visitingValue(SimulatorResourceModel[][] values) {
235 StringBuilder result = new StringBuilder();
237 boolean first = true;
238 for (SimulatorResourceModel[] value : values) {
242 AttributeValue attributeValue = new AttributeValue(value);
243 result.append(new AttributeValueStringConverter(attributeValue)
248 return result.toString();
252 public String visitingValue(Integer[][][] values) {
253 StringBuilder result = new StringBuilder();
255 boolean first = true;
256 for (Integer[][] value : values) {
260 AttributeValue attributeValue = new AttributeValue(value);
261 result.append(new AttributeValueStringConverter(attributeValue)
266 return result.toString();
270 public String visitingValue(Double[][][] values) {
271 StringBuilder result = new StringBuilder();
273 boolean first = true;
274 for (Double[][] value : values) {
278 AttributeValue attributeValue = new AttributeValue(value);
279 result.append(new AttributeValueStringConverter(attributeValue)
284 return result.toString();
288 public String visitingValue(Boolean[][][] values) {
289 StringBuilder result = new StringBuilder();
291 boolean first = true;
292 for (Boolean[][] value : values) {
296 AttributeValue attributeValue = new AttributeValue(value);
297 result.append(new AttributeValueStringConverter(attributeValue)
302 return result.toString();
306 public String visitingValue(String[][][] values) {
307 StringBuilder result = new StringBuilder();
309 boolean first = true;
310 for (String[][] value : values) {
314 AttributeValue attributeValue = new AttributeValue(value);
315 result.append(new AttributeValueStringConverter(attributeValue)
320 return result.toString();
324 public String visitingValue(SimulatorResourceModel[][][] values) {
325 StringBuilder result = new StringBuilder();
327 boolean first = true;
328 for (SimulatorResourceModel[][] value : values) {
332 AttributeValue attributeValue = new AttributeValue(value);
333 result.append(new AttributeValueStringConverter(attributeValue)
338 return result.toString();