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.serviceprovider.model;
19 import java.util.HashMap;
20 import java.util.HashSet;
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;
29 public abstract class Resource {
31 // Java SDK object reference
32 SimulatorResource simulatorResource;
33 private SimulatorResourceModel resourceModel;
34 private ResourceRepresentation mResourceRepresentation;
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;
44 private Map<Integer, ObserverDetail> observers;
47 resourceInterfaces = new HashSet<String>();
48 observers = new HashMap<Integer, ObserverDetail>();
51 public SimulatorResource getSimulatorResource() {
52 return simulatorResource;
55 public void setSimulatorResource(SimulatorResource simulatorResource) {
56 this.simulatorResource = simulatorResource;
59 public SimulatorResourceModel getResourceModel() {
63 public void setResourceModel(SimulatorResourceModel resourceModel) {
64 this.resourceModel = resourceModel;
67 public String getResourceURI() {
71 public void setResourceURI(String resourceURI) {
72 this.resourceURI = resourceURI;
75 public String getResourceName() {
79 public void setResourceName(String resourceName) {
80 this.resourceName = resourceName;
83 public String getResourceType() {
87 public void setResourceType(String resourceType) {
88 this.resourceType = resourceType;
91 public Set<String> getResourceInterfaces() {
92 if (null != resourceInterfaces) {
93 return new HashSet<String>(resourceInterfaces);
98 public void setResourceInterfaces(Set<String> resourceInterfaces) {
99 this.resourceInterfaces = resourceInterfaces;
102 public boolean isStarted() {
106 public void setStarted(boolean started) {
107 this.started = started;
110 public boolean isObservable() {
114 public void setObservable(boolean observable) {
115 this.observable = observable;
118 public boolean isDiscoverable() {
122 public void setDiscoverable(boolean discoverable) {
123 this.discoverable = discoverable;
126 public void addInterfaceType(String ifType) {
127 if (null == ifType) {
130 if (null == resourceInterfaces) {
131 resourceInterfaces = new HashSet<String>();
133 resourceInterfaces.add(ifType);
136 public void removeInterfaceType(String ifType) {
137 if (null == ifType || null == resourceInterfaces) {
140 resourceInterfaces.remove(ifType);
143 public boolean isInterfaceTypeExist(String ifType) {
144 if (null == ifType || null == resourceInterfaces) {
147 return resourceInterfaces.contains(ifType);
150 public Map<Integer, ObserverDetail> getObserver() {
154 public void addObserverInfo(Observer observer) {
155 if (null == observer) {
158 int id = observer.getId();
159 if (!observers.containsKey(id)) {
160 ObserverDetail obsDetail = new ObserverDetail();
161 obsDetail.setObserverInfo(observer);
162 observers.put(id, obsDetail);
166 public void removeObserverInfo(Observer observer) {
167 if (null == observer) {
170 observers.remove(observer.getId());
173 public void createResourceRepresentation(
174 Map<String, SimulatorResourceAttribute> attributes)
175 throws NullPointerException {
176 if (mResourceRepresentation == null)
177 mResourceRepresentation = new ResourceRepresentation(attributes);
180 public void updateResourceRepresentation(SimulatorResourceModel model)
181 throws NullPointerException {
182 mResourceRepresentation.update(model);
185 public ResourceRepresentation getResourceRepresentation() {
186 return mResourceRepresentation;