Integrated resource model related changes with eclipse plug-ins.
[platform/upstream/iotivity.git] / service / simulator / java / eclipse-plugin / ServiceProviderPlugin / src / oic / simulator / serviceprovider / model / Resource.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.util.HashMap;
20 import java.util.HashSet;
21 import java.util.Map;
22 import java.util.Set;
23
24 import org.oic.simulator.SimulatorResourceAttribute;
25 import org.oic.simulator.SimulatorResourceModel;
26 import org.oic.simulator.server.Observer;
27 import org.oic.simulator.server.SimulatorResource;
28
29 public abstract class Resource {
30
31     // Java SDK object reference
32     SimulatorResource                    simulatorResource;
33     private SimulatorResourceModel       resourceModel;
34     private ResourceRepresentation       mResourceRepresentation;
35
36     private String                       resourceURI;
37     private String                       resourceName;
38     private String                       resourceType;
39     private Set<String>                  resourceInterfaces;
40     private boolean                      started;
41     private boolean                      observable;
42     private boolean                      discoverable;
43
44     private Map<Integer, ObserverDetail> observers;
45
46     public Resource() {
47         resourceInterfaces = new HashSet<String>();
48         observers = new HashMap<Integer, ObserverDetail>();
49     }
50
51     public SimulatorResource getSimulatorResource() {
52         return simulatorResource;
53     }
54
55     public void setSimulatorResource(SimulatorResource simulatorResource) {
56         this.simulatorResource = simulatorResource;
57     }
58
59     public SimulatorResourceModel getResourceModel() {
60         return resourceModel;
61     }
62
63     public void setResourceModel(SimulatorResourceModel resourceModel) {
64         this.resourceModel = resourceModel;
65     }
66
67     public String getResourceURI() {
68         return resourceURI;
69     }
70
71     public void setResourceURI(String resourceURI) {
72         this.resourceURI = resourceURI;
73     }
74
75     public String getResourceName() {
76         return resourceName;
77     }
78
79     public void setResourceName(String resourceName) {
80         this.resourceName = resourceName;
81     }
82
83     public String getResourceType() {
84         return resourceType;
85     }
86
87     public void setResourceType(String resourceType) {
88         this.resourceType = resourceType;
89     }
90
91     public Set<String> getResourceInterfaces() {
92         if (null != resourceInterfaces) {
93             return new HashSet<String>(resourceInterfaces);
94         }
95         return null;
96     }
97
98     public void setResourceInterfaces(Set<String> resourceInterfaces) {
99         this.resourceInterfaces = resourceInterfaces;
100     }
101
102     public boolean isStarted() {
103         return started;
104     }
105
106     public void setStarted(boolean started) {
107         this.started = started;
108     }
109
110     public boolean isObservable() {
111         return observable;
112     }
113
114     public void setObservable(boolean observable) {
115         this.observable = observable;
116     }
117
118     public boolean isDiscoverable() {
119         return discoverable;
120     }
121
122     public void setDiscoverable(boolean discoverable) {
123         this.discoverable = discoverable;
124     }
125
126     public void addInterfaceType(String ifType) {
127         if (null == ifType) {
128             return;
129         }
130         if (null == resourceInterfaces) {
131             resourceInterfaces = new HashSet<String>();
132         }
133         resourceInterfaces.add(ifType);
134     }
135
136     public void removeInterfaceType(String ifType) {
137         if (null == ifType || null == resourceInterfaces) {
138             return;
139         }
140         resourceInterfaces.remove(ifType);
141     }
142
143     public boolean isInterfaceTypeExist(String ifType) {
144         if (null == ifType || null == resourceInterfaces) {
145             return false;
146         }
147         return resourceInterfaces.contains(ifType);
148     }
149
150     public Map<Integer, ObserverDetail> getObserver() {
151         return observers;
152     }
153
154     public void addObserverInfo(Observer observer) {
155         if (null == observer) {
156             return;
157         }
158         int id = observer.getId();
159         if (!observers.containsKey(id)) {
160             ObserverDetail obsDetail = new ObserverDetail();
161             obsDetail.setObserverInfo(observer);
162             observers.put(id, obsDetail);
163         }
164     }
165
166     public void removeObserverInfo(Observer observer) {
167         if (null == observer) {
168             return;
169         }
170         observers.remove(observer.getId());
171     }
172
173     public void createResourceRepresentation(
174             Map<String, SimulatorResourceAttribute> attributes)
175             throws NullPointerException {
176         if (mResourceRepresentation == null)
177             mResourceRepresentation = new ResourceRepresentation(attributes);
178     }
179
180     public void updateResourceRepresentation(SimulatorResourceModel model)
181             throws NullPointerException {
182         mResourceRepresentation.update(model);
183     }
184
185     public ResourceRepresentation getResourceRepresentation() {
186         return mResourceRepresentation;
187     }
188 }