73d559c798d2685dcdd01d3098cef489cc919d7f
[platform/upstream/iotivity.git] / service / simulator / java / eclipse-plugin / ServiceProviderPlugin / src / oic / simulator / serviceprovider / utils / Utility.java
1 /*
2  * Copyright 2015 Samsung Electronics All Rights Reserved.
3  *
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
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16
17 package oic.simulator.serviceprovider.utils;
18
19 import java.util.ArrayList;
20 import java.util.Comparator;
21 import java.util.Date;
22 import java.util.Enumeration;
23 import java.util.HashSet;
24 import java.util.Iterator;
25 import java.util.List;
26 import java.util.Set;
27 import java.util.Vector;
28
29 import oic.simulator.serviceprovider.Activator;
30 import oic.simulator.serviceprovider.model.CollectionResource;
31 import oic.simulator.serviceprovider.model.Device;
32 import oic.simulator.serviceprovider.model.LocalResourceAttribute;
33 import oic.simulator.serviceprovider.model.Resource;
34 import oic.simulator.serviceprovider.model.SingleResource;
35
36 import org.oic.simulator.AttributeValue;
37 import org.oic.simulator.AttributeValue.TypeInfo;
38 import org.oic.simulator.AttributeValue.ValueType;
39 import org.oic.simulator.ILogger.Level;
40 import org.oic.simulator.InvalidArgsException;
41 import org.oic.simulator.SimulatorException;
42 import org.oic.simulator.SimulatorResourceAttribute;
43 import org.oic.simulator.SimulatorResourceModel;
44
45 /**
46  * This class has common utility methods.
47  */
48 public class Utility {
49
50     public static String fileNameToDisplay(String fileName) {
51         if (null == fileName || fileName.length() < 1) {
52             return null;
53         }
54         // Remove the RAML file standard prefix
55         int len = Constants.RAML_FILE_PREFIX.length();
56         if (len > 0) {
57             if (fileName.startsWith(Constants.RAML_FILE_PREFIX)) {
58                 fileName = fileName.substring(len);
59             }
60         }
61
62         // Removing the file extension
63         int index = fileName.lastIndexOf('.');
64         fileName = fileName.substring(0, index);
65         return fileName;
66     }
67
68     public static String displayToFileName(String displayName) {
69         if (null == displayName || displayName.length() < 1) {
70             return null;
71         }
72         String fileName;
73         // Adding the prefix
74         fileName = Constants.RAML_FILE_PREFIX + displayName;
75
76         // Adding the file extension
77         fileName = fileName + Constants.RAML_FILE_EXTENSION;
78
79         return fileName;
80     }
81
82     public static String getAutomationStatus(boolean status) {
83         if (status) {
84             return Constants.ENABLED;
85         } else {
86             return Constants.DISABLED;
87         }
88     }
89
90     public static String getAutomationString(boolean status) {
91         if (status) {
92             return Constants.ENABLE;
93         } else {
94             return Constants.DISABLE;
95         }
96     }
97
98     public static boolean getAutomationBoolean(String status) {
99         if (null != status) {
100             if (status.equals(Constants.ENABLE)) {
101                 return true;
102             }
103         }
104         return false;
105     }
106
107     public static int getUpdateIntervalFromString(String value) {
108         int result = Constants.DEFAULT_AUTOMATION_INTERVAL;
109         if (null != value) {
110             try {
111                 result = Integer.parseInt(value);
112             } catch (NumberFormatException e) {
113                 Activator
114                         .getDefault()
115                         .getLogManager()
116                         .log(Level.ERROR.ordinal(),
117                                 new Date(),
118                                 getSimulatorErrorString(
119                                         e,
120                                         "Update interval convertion failed."
121                                                 + "Taking the default value("
122                                                 + Constants.DEFAULT_AUTOMATION_INTERVAL
123                                                 + ")"));
124             }
125         }
126         return result;
127     }
128
129     public static List<String> convertSetToList(Set<String> typeSet) {
130         if (null == typeSet) {
131             return null;
132         }
133         List<String> list = new ArrayList<String>();
134         Iterator<String> typeItr = typeSet.iterator();
135         while (typeItr.hasNext()) {
136             list.add(typeItr.next());
137         }
138         return list;
139     }
140
141     public static List<SingleResource> getSingleResourceListFromSet(
142             Set<SingleResource> resources) {
143         if (null == resources) {
144             return null;
145         }
146         List<SingleResource> list = new ArrayList<SingleResource>();
147         Iterator<SingleResource> typeItr = resources.iterator();
148         while (typeItr.hasNext()) {
149             list.add(typeItr.next());
150         }
151         return list;
152     }
153
154     public static List<CollectionResource> getCollectionResourceListFromSet(
155             Set<CollectionResource> resources) {
156         if (null == resources) {
157             return null;
158         }
159         List<CollectionResource> list = new ArrayList<CollectionResource>();
160         Iterator<CollectionResource> typeItr = resources.iterator();
161         while (typeItr.hasNext()) {
162             list.add(typeItr.next());
163         }
164         return list;
165     }
166
167     public static List<Device> getDeviceListFromSet(Set<Device> devices) {
168         if (null == devices) {
169             return null;
170         }
171         List<Device> list = new ArrayList<Device>();
172         Iterator<Device> typeItr = devices.iterator();
173         while (typeItr.hasNext()) {
174             list.add(typeItr.next());
175         }
176         return list;
177     }
178
179     public static Set<String> convertVectorToSet(Vector<String> vector) {
180         if (null == vector || vector.isEmpty()) {
181             return null;
182         }
183         Set<String> resultSet = new HashSet<String>();
184         Enumeration<String> e = vector.elements();
185         while (e.hasMoreElements()) {
186             resultSet.add(e.nextElement().toString());
187         }
188         return resultSet;
189     }
190
191     public static String getSimulatorErrorString(Exception e, String info) {
192         if (null == e) {
193             return null;
194         }
195         String detail;
196         if (e instanceof SimulatorException) {
197             SimulatorException simEx = (SimulatorException) e;
198             detail = simEx.message() + "\n";
199             detail += "Exception Type: " + simEx.getClass().getSimpleName()
200                     + "\n";
201             detail += "Error code: " + simEx.code().toString();
202         } else {
203             detail = info + "\n";
204             detail += "Exception Type: " + e.getClass().getSimpleName() + "\n";
205             detail += "Message: " + e.getMessage();
206         }
207         return detail;
208     }
209
210     public static Set<String> getAttributeTypes() {
211         Set<String> attTypes = new HashSet<String>();
212         ValueType[] types = ValueType.values();
213         if (null != types) {
214             attTypes.add(Constants.INT);
215             attTypes.add(Constants.DOUBLE);
216             attTypes.add(Constants.BOOL);
217             attTypes.add(Constants.STRING);
218         }
219         return attTypes;
220     }
221
222     public static ValueType getAttributeTypeEnum(String type) {
223         if (null != type && type.trim().length() > 0) {
224             if (type.equalsIgnoreCase(Constants.INT)) {
225                 return ValueType.INTEGER;
226             }
227             if (type.equalsIgnoreCase(Constants.DOUBLE)) {
228                 return ValueType.DOUBLE;
229             }
230             if (type.equalsIgnoreCase(Constants.BOOL)) {
231                 return ValueType.BOOLEAN;
232             }
233             if (type.equalsIgnoreCase(Constants.STRING)) {
234                 return ValueType.STRING;
235             }
236         }
237         return ValueType.UNKNOWN;
238     }
239
240     public static int[] convertSetToArrayInt(Set<Object> allowedValues) {
241         if (null == allowedValues || allowedValues.size() < 1) {
242             return null;
243         }
244         int[] arr = new int[allowedValues.size()];
245         Iterator<Object> itr = allowedValues.iterator();
246         try {
247             int i = 0;
248             while (itr.hasNext()) {
249                 arr[i++] = (int) itr.next();
250             }
251         } catch (Exception e) {
252             return null;
253         }
254         return arr;
255     }
256
257     public static double[] convertSetToArrayDouble(Set<Object> allowedValues) {
258         if (null == allowedValues || allowedValues.size() < 1) {
259             return null;
260         }
261         double[] arr = new double[allowedValues.size()];
262         Iterator<Object> itr = allowedValues.iterator();
263         try {
264             int i = 0;
265             while (itr.hasNext()) {
266                 arr[i++] = (double) itr.next();
267             }
268         } catch (Exception e) {
269             return null;
270         }
271         return arr;
272     }
273
274     public static boolean[] convertSetToArrayBoolean(Set<Object> allowedValues) {
275         if (null == allowedValues || allowedValues.size() < 1) {
276             return null;
277         }
278         boolean[] arr = new boolean[allowedValues.size()];
279         Iterator<Object> itr = allowedValues.iterator();
280         try {
281             int i = 0;
282             while (itr.hasNext()) {
283                 arr[i++] = (boolean) itr.next();
284             }
285         } catch (Exception e) {
286             return null;
287         }
288         return arr;
289     }
290
291     public static String[] convertSetToArrayString(Set<Object> allowedValues) {
292         if (null == allowedValues || allowedValues.size() < 1) {
293             return null;
294         }
295         String[] arr = new String[allowedValues.size()];
296         Iterator<Object> itr = allowedValues.iterator();
297         try {
298             int i = 0;
299             while (itr.hasNext()) {
300                 arr[i++] = (String) itr.next();
301             }
302         } catch (Exception e) {
303             return null;
304         }
305         return arr;
306     }
307
308     public static Vector<Integer> convertSetToVectorInt(
309             Set<Object> allowedValues) {
310         if (null == allowedValues || allowedValues.size() < 1) {
311             return null;
312         }
313         Vector<Integer> resultVec = new Vector<Integer>();
314         Iterator<Object> itr = allowedValues.iterator();
315         try {
316             while (itr.hasNext()) {
317                 resultVec.add((Integer) itr.next());
318             }
319         } catch (Exception e) {
320             return null;
321         }
322         return resultVec;
323     }
324
325     public static Vector<Double> convertSetToVectorDouble(
326             Set<Object> allowedValues) {
327         if (null == allowedValues || allowedValues.size() < 1) {
328             return null;
329         }
330         Vector<Double> resultVec = new Vector<Double>();
331         Iterator<Object> itr = allowedValues.iterator();
332         try {
333             while (itr.hasNext()) {
334                 resultVec.add((Double) itr.next());
335             }
336         } catch (Exception e) {
337             return null;
338         }
339         return resultVec;
340     }
341
342     public static Vector<String> convertSetToVectorString(
343             Set<Object> allowedValues) {
344         if (null == allowedValues || allowedValues.size() < 1) {
345             return null;
346         }
347         Vector<String> resultVec = new Vector<String>();
348         Iterator<Object> itr = allowedValues.iterator();
349         try {
350             while (itr.hasNext()) {
351                 resultVec.add((String) itr.next());
352             }
353         } catch (Exception e) {
354             return null;
355         }
356         return resultVec;
357     }
358
359     public static Set<Object> convertSetStringToSetObject(Set<String> values,
360             ValueType type) {
361         if (null == values || values.isEmpty()) {
362             return null;
363         }
364         Set<Object> resultSet = new HashSet<Object>();
365         if (type.equals(Constants.INT)) {
366             int val;
367             Iterator<String> itr = values.iterator();
368             while (itr.hasNext()) {
369                 try {
370                     val = Integer.parseInt(itr.next());
371                     resultSet.add(val);
372                 } catch (NumberFormatException nfe) {
373                     // Added for safety. Nothing to do.
374                 }
375             }
376         } else if (type.equals(Constants.DOUBLE)) {
377             double val;
378             Iterator<String> itr = values.iterator();
379             while (itr.hasNext()) {
380                 try {
381                     val = Double.parseDouble(itr.next());
382                     resultSet.add(val);
383                 } catch (NumberFormatException nfe) {
384                     // Added for safety. Nothing to do.
385                 }
386             }
387         } else if (type.equals(Constants.BOOL)) {
388             resultSet.add(true);
389             resultSet.add(false);
390         } else {
391             Iterator<String> itr = values.iterator();
392             while (itr.hasNext()) {
393                 resultSet.add(itr.next());
394             }
395         }
396         return resultSet;
397     }
398
399     public static List<Resource> convertSingleTypeResourceListToBaseType(
400             List<SingleResource> resources) {
401         if (null == resources || resources.isEmpty()) {
402             return null;
403         }
404         List<Resource> resultSet = new ArrayList<Resource>();
405         Iterator<SingleResource> itr = resources.iterator();
406         while (itr.hasNext()) {
407             resultSet.add(itr.next());
408         }
409         return resultSet;
410     }
411
412     public static List<Resource> convertCollectionTypeResourceListToBaseType(
413             List<CollectionResource> resources) {
414         if (null == resources || resources.isEmpty()) {
415             return null;
416         }
417         List<Resource> resultSet = new ArrayList<Resource>();
418         Iterator<CollectionResource> itr = resources.iterator();
419         while (itr.hasNext()) {
420             resultSet.add(itr.next());
421         }
422         return resultSet;
423     }
424
425     public static Comparator<Resource>           resourceComparator           = new Comparator<Resource>() {
426                                                                                   public int compare(
427                                                                                           Resource res1,
428                                                                                           Resource res2) {
429                                                                                       String s1 = res1
430                                                                                               .getResourceName();
431                                                                                       String s2 = res2
432                                                                                               .getResourceName();
433
434                                                                                       String s1Part = s1
435                                                                                               .replaceAll(
436                                                                                                       "\\d",
437                                                                                                       "");
438                                                                                       String s2Part = s2
439                                                                                               .replaceAll(
440                                                                                                       "\\d",
441                                                                                                       "");
442
443                                                                                       if (s1Part
444                                                                                               .equalsIgnoreCase(s2Part)) {
445                                                                                           return extractInt(s1)
446                                                                                                   - extractInt(s2);
447                                                                                       }
448                                                                                       return s1
449                                                                                               .compareTo(s2);
450                                                                                   }
451
452                                                                                   int extractInt(
453                                                                                           String s) {
454                                                                                       String num = s
455                                                                                               .replaceAll(
456                                                                                                       "\\D",
457                                                                                                       "");
458                                                                                       // return
459                                                                                       // 0
460                                                                                       // if
461                                                                                       // no
462                                                                                       // digits
463                                                                                       // found
464                                                                                       return num
465                                                                                               .isEmpty() ? 0
466                                                                                               : Integer
467                                                                                                       .parseInt(num);
468                                                                                   }
469                                                                               };
470
471     public static Comparator<SingleResource>     singleResourceComparator     = new Comparator<SingleResource>() {
472                                                                                   public int compare(
473                                                                                           SingleResource res1,
474                                                                                           SingleResource res2) {
475                                                                                       String s1 = res1
476                                                                                               .getResourceName();
477                                                                                       String s2 = res2
478                                                                                               .getResourceName();
479
480                                                                                       String s1Part = s1
481                                                                                               .replaceAll(
482                                                                                                       "\\d",
483                                                                                                       "");
484                                                                                       String s2Part = s2
485                                                                                               .replaceAll(
486                                                                                                       "\\d",
487                                                                                                       "");
488
489                                                                                       if (s1Part
490                                                                                               .equalsIgnoreCase(s2Part)) {
491                                                                                           return extractInt(s1)
492                                                                                                   - extractInt(s2);
493                                                                                       }
494                                                                                       return s1
495                                                                                               .compareTo(s2);
496                                                                                   }
497
498                                                                                   int extractInt(
499                                                                                           String s) {
500                                                                                       String num = s
501                                                                                               .replaceAll(
502                                                                                                       "\\D",
503                                                                                                       "");
504                                                                                       // return
505                                                                                       // 0
506                                                                                       // if
507                                                                                       // no
508                                                                                       // digits
509                                                                                       // found
510                                                                                       return num
511                                                                                               .isEmpty() ? 0
512                                                                                               : Integer
513                                                                                                       .parseInt(num);
514                                                                                   }
515                                                                               };
516
517     public static Comparator<CollectionResource> collectionResourceComparator = new Comparator<CollectionResource>() {
518                                                                                   public int compare(
519                                                                                           CollectionResource res1,
520                                                                                           CollectionResource res2) {
521                                                                                       String s1 = res1
522                                                                                               .getResourceName();
523                                                                                       String s2 = res2
524                                                                                               .getResourceName();
525
526                                                                                       String s1Part = s1
527                                                                                               .replaceAll(
528                                                                                                       "\\d",
529                                                                                                       "");
530                                                                                       String s2Part = s2
531                                                                                               .replaceAll(
532                                                                                                       "\\d",
533                                                                                                       "");
534
535                                                                                       if (s1Part
536                                                                                               .equalsIgnoreCase(s2Part)) {
537                                                                                           return extractInt(s1)
538                                                                                                   - extractInt(s2);
539                                                                                       }
540                                                                                       return s1
541                                                                                               .compareTo(s2);
542                                                                                   }
543
544                                                                                   int extractInt(
545                                                                                           String s) {
546                                                                                       String num = s
547                                                                                               .replaceAll(
548                                                                                                       "\\D",
549                                                                                                       "");
550                                                                                       // return
551                                                                                       // 0
552                                                                                       // if
553                                                                                       // no
554                                                                                       // digits
555                                                                                       // found
556                                                                                       return num
557                                                                                               .isEmpty() ? 0
558                                                                                               : Integer
559                                                                                                       .parseInt(num);
560                                                                                   }
561                                                                               };
562
563     public static Comparator<Device>             deviceComparator             = new Comparator<Device>() {
564                                                                                   public int compare(
565                                                                                           Device res1,
566                                                                                           Device res2) {
567                                                                                       String s1 = res1
568                                                                                               .getDeviceName();
569                                                                                       String s2 = res2
570                                                                                               .getDeviceName();
571
572                                                                                       String s1Part = s1
573                                                                                               .replaceAll(
574                                                                                                       "\\d",
575                                                                                                       "");
576                                                                                       String s2Part = s2
577                                                                                               .replaceAll(
578                                                                                                       "\\d",
579                                                                                                       "");
580
581                                                                                       if (s1Part
582                                                                                               .equalsIgnoreCase(s2Part)) {
583                                                                                           return extractInt(s1)
584                                                                                                   - extractInt(s2);
585                                                                                       }
586                                                                                       return s1
587                                                                                               .compareTo(s2);
588                                                                                   }
589
590                                                                                   int extractInt(
591                                                                                           String s) {
592                                                                                       String num = s
593                                                                                               .replaceAll(
594                                                                                                       "\\D",
595                                                                                                       "");
596                                                                                       // return
597                                                                                       // 0
598                                                                                       // if
599                                                                                       // no
600                                                                                       // digits
601                                                                                       // found
602                                                                                       return num
603                                                                                               .isEmpty() ? 0
604                                                                                               : Integer
605                                                                                                       .parseInt(num);
606                                                                                   }
607                                                                               };
608
609     // This method only works for attributes whose values are of type int,
610     // double, bool, string and 1-D array of primitive types
611     public static String getAttributeValueAsString(AttributeValue val) {
612         if (null == val) {
613             return null;
614         }
615         Object value = val.get();
616         if (null == value) {
617             return null;
618         }
619         TypeInfo type = val.typeInfo();
620         if (type.mType == ValueType.RESOURCEMODEL
621                 || (type.mType == ValueType.ARRAY && type.mBaseType == ValueType.RESOURCEMODEL)
622                 || (type.mType == ValueType.ARRAY && type.mDepth > 1)) {
623             return null;
624         }
625         if (type.mType == ValueType.ARRAY) {
626             if (type.mBaseType == ValueType.INTEGER) {
627                 Integer[] values = (Integer[]) value;
628                 if (null == values || values.length < 1) {
629                     return null;
630                 }
631                 List<Integer> list = new ArrayList<Integer>();
632                 for (Integer i : values) {
633                     list.add(i);
634                 }
635                 return list.toString();
636             } else if (type.mBaseType == ValueType.DOUBLE) {
637                 Double[] values = (Double[]) value;
638                 if (null == values || values.length < 1) {
639                     return null;
640                 }
641                 List<Double> list = new ArrayList<Double>();
642                 for (Double i : values) {
643                     list.add(i);
644                 }
645                 return list.toString();
646             } else if (type.mBaseType == ValueType.BOOLEAN) {
647                 Boolean[] values = (Boolean[]) value;
648                 if (null == values || values.length < 1) {
649                     return null;
650                 }
651                 List<Boolean> list = new ArrayList<Boolean>();
652                 for (Boolean i : values) {
653                     list.add(i);
654                 }
655                 return list.toString();
656             } else if (type.mBaseType == ValueType.STRING) {
657                 String[] values = (String[]) value;
658                 if (null == values || values.length < 1) {
659                     return null;
660                 }
661                 List<String> list = new ArrayList<String>();
662                 for (String i : values) {
663                     list.add(i);
664                 }
665                 return list.toString();
666             } else {
667                 return null;
668             }
669         } else {
670             return String.valueOf(value);
671         }
672     }
673
674     public static List<LocalResourceAttribute> getDummyAttributes() {
675         List<LocalResourceAttribute> attributes = null;
676         attributes = new ArrayList<LocalResourceAttribute>();
677
678         // Integer attribute
679         SimulatorResourceAttribute attribute = new SimulatorResourceAttribute(
680                 "integer", new AttributeValue(2), null);
681         attributes.add(addAttribute(attribute));
682
683         // Boolean attribute
684         attribute = new SimulatorResourceAttribute("boolean",
685                 new AttributeValue(false), null);
686         attributes.add(addAttribute(attribute));
687
688         // String attribute
689         attribute = new SimulatorResourceAttribute("string",
690                 new AttributeValue("india"), null);
691         attributes.add(addAttribute(attribute));
692
693         // Integer array attribute
694         int iarr[] = { 1, 2, 3 };
695         attribute = new SimulatorResourceAttribute("integerArr",
696                 new AttributeValue(iarr), null);
697         attributes.add(addAttribute(attribute));
698
699         // Double array attribute
700         double darr[] = { 1.5, 2.51, 3.15 };
701         attribute = new SimulatorResourceAttribute("doubleArr",
702                 new AttributeValue(darr), null);
703         attributes.add(addAttribute(attribute));
704
705         // Boolean array attribute
706         boolean barr[] = { false, true, false };
707         attribute = new SimulatorResourceAttribute("boolArr",
708                 new AttributeValue(barr), null);
709         attributes.add(addAttribute(attribute));
710
711         // String array attribute
712         String sarr[] = { "senthil", "muruga", "sriram" };
713         attribute = new SimulatorResourceAttribute("stringArr",
714                 new AttributeValue(sarr), null);
715         attributes.add(addAttribute(attribute));
716
717         // Model type complex attribute
718         attribute = new SimulatorResourceAttribute("subAtt1",
719                 new AttributeValue("chennai"), null);
720         SimulatorResourceModel model = new SimulatorResourceModel();
721         try {
722             model.addAttribute(attribute);
723         } catch (InvalidArgsException e) {
724             // TODO Auto-generated catch block
725             e.printStackTrace();
726         }
727         attribute = new SimulatorResourceAttribute("subAtt2",
728                 new AttributeValue("madurai"), null);
729         try {
730             model.addAttribute(attribute);
731         } catch (InvalidArgsException e) {
732             // TODO Auto-generated catch block
733             e.printStackTrace();
734         }
735
736         SimulatorResourceModel subModel = new SimulatorResourceModel();
737         try {
738             subModel.addAttribute(attribute);
739         } catch (InvalidArgsException e) {
740             // TODO Auto-generated catch block
741             e.printStackTrace();
742         }
743         attribute = new SimulatorResourceAttribute("modelsubAtt3",
744                 new AttributeValue(subModel), null);
745         try {
746             model.addAttribute(attribute);
747         } catch (InvalidArgsException e) {
748             // TODO Auto-generated catch block
749             e.printStackTrace();
750         }
751
752         SimulatorResourceAttribute modelAtt = new SimulatorResourceAttribute(
753                 "modelAtt1", new AttributeValue(model));
754         attributes.add(addAttribute(modelAtt));
755
756         // 1-D array of model
757         attribute = new SimulatorResourceAttribute("subAtt1",
758                 new AttributeValue("chennai"), null);
759         SimulatorResourceModel[] modelArr = new SimulatorResourceModel[2];
760         model = new SimulatorResourceModel();
761         try {
762             model.addAttribute(attribute);
763             modelArr[0] = model;
764         } catch (InvalidArgsException e) {
765             // TODO Auto-generated catch block
766             e.printStackTrace();
767         }
768         attribute = new SimulatorResourceAttribute("subAtt2",
769                 new AttributeValue("madurai"), null);
770         model = new SimulatorResourceModel();
771         try {
772             model.addAttribute(attribute);
773             modelArr[1] = model;
774         } catch (InvalidArgsException e) {
775             // TODO Auto-generated catch block
776             e.printStackTrace();
777         }
778         modelAtt = new SimulatorResourceAttribute("modelAtt2",
779                 new AttributeValue(modelArr));
780         attributes.add(addAttribute(modelAtt));
781
782         return attributes;
783     }
784
785     private static LocalResourceAttribute addAttribute(
786             SimulatorResourceAttribute att) {
787         LocalResourceAttribute localAtt = new LocalResourceAttribute();
788
789         localAtt = new LocalResourceAttribute();
790
791         localAtt.setResourceAttributeRef(att);
792
793         // Initially disabling the automation
794         localAtt.setAutomationInProgress(false);
795
796         // Assigning the default automation interval
797         localAtt.setAutomationUpdateInterval(Constants.DEFAULT_AUTOMATION_INTERVAL);
798
799         // Setting the default automation type
800         localAtt.setAutomationType(Constants.DEFAULT_AUTOMATION_TYPE);
801
802         return localAtt;
803     }
804
805 }