Imported Upstream version 1.1.0
[platform/upstream/iotivity.git] / service / simulator / java / eclipse-plugin / ServiceProviderPlugin / src / oic / simulator / serviceprovider / model / SerializedServiceProvider.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.model;
18
19 import java.io.FileInputStream;
20 import java.io.FileNotFoundException;
21 import java.io.FileOutputStream;
22 import java.io.IOException;
23 import java.io.ObjectInputStream;
24 import java.io.ObjectOutputStream;
25 import java.io.Serializable;
26 import java.util.List;
27 import java.util.Map;
28
29 public class SerializedServiceProvider implements Serializable {
30
31     public static class SerializedAttribute implements Serializable {
32
33         public String getName() {
34             return m_name;
35         }
36
37         public void setName(String name) {
38             this.m_name = name;
39         }
40
41         public Object getValue() {
42             return m_value;
43         }
44
45         public void setValue(Object value) {
46             this.m_value = value;
47         }
48
49         public String getType() {
50             return m_type;
51         }
52
53         public void setType(String type) {
54             this.m_type = type;
55         }
56
57         public int getMin() {
58             return m_min;
59         }
60
61         public void setMin(int min) {
62             this.m_min = min;
63         }
64
65         public int getMax() {
66             return m_max;
67         }
68
69         public void setMax(int max) {
70             this.m_max = max;
71         }
72
73         public Object getAllowedValues() {
74             return m_AllowedValues;
75         }
76
77         public void setAllowedValues(Object allowedValues) {
78             this.m_AllowedValues = allowedValues;
79         }
80
81         private String m_name          = null;
82         private Object m_value         = null;
83         private String m_type          = null;
84         private int    m_min           = 0;
85         private int    m_max           = 0;
86         private Object m_AllowedValues = null;
87     }
88
89     public String getResourceName() {
90         return m_resourceName;
91     }
92
93     public void setResourceName(String resourceName) {
94         this.m_resourceName = resourceName;
95     }
96
97     public String getUri() {
98         return m_uri;
99     }
100
101     public void setUri(String uri) {
102         this.m_uri = uri;
103     }
104
105     public String getResourceType() {
106         return m_resourceType;
107     }
108
109     public void setResourceType(String resourceType) {
110         this.m_resourceType = resourceType;
111     }
112
113     public List<String> getInterfaceType() {
114         return m_interfaceType;
115     }
116
117     public void setInterfaceType(List<String> interfaceType) {
118         this.m_interfaceType = interfaceType;
119     }
120
121     public Map<String, SerializedAttribute> getResourceAttributesMap() {
122         return m_resourceAttributesMap;
123     }
124
125     public void setResourceAttributesMap(
126             Map<String, SerializedAttribute> resourceAttributesMap) {
127         this.m_resourceAttributesMap = resourceAttributesMap;
128     }
129
130     public void serialize(String filePath) throws FileNotFoundException,
131             IOException {
132         FileOutputStream fileOut = null;
133         ObjectOutputStream out = null;
134         try {
135             fileOut = new FileOutputStream(filePath);
136             out = new ObjectOutputStream(fileOut);
137             out.writeObject(this);
138         } finally {
139             if (null != fileOut)
140                 fileOut.close();
141
142             if (null != out)
143                 out.close();
144         }
145     }
146
147     public static SerializedServiceProvider deSerialize(String filePath)
148             throws FileNotFoundException, IOException, ClassNotFoundException {
149         FileInputStream fileIn = null;
150         ObjectInputStream in = null;
151         SerializedServiceProvider r;
152         try {
153             fileIn = new FileInputStream(filePath);
154             in = new ObjectInputStream(fileIn);
155             r = (SerializedServiceProvider) in.readObject();
156         } finally {
157             if (null != fileIn)
158                 fileIn.close();
159
160             if (null != in)
161                 in.close();
162         }
163         return r;
164     }
165
166     private String                           m_resourceName;
167     private String                           m_uri;
168     private String                           m_resourceType;
169     private List<String>                     m_interfaceType;
170     private Map<String, SerializedAttribute> m_resourceAttributesMap;
171
172 }