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.
18 * This file contains a class which has the methods
19 * for creation and deletion of resources.
21 package org.oic.simulator;
23 import java.util.ArrayList;
24 import java.util.Vector;
26 import org.oic.simulator.clientcontroller.IFindResourceListener;
27 import org.oic.simulator.clientcontroller.SimulatorRemoteResource;
28 import org.oic.simulator.serviceprovider.IResourceModelChangedListener;
29 import org.oic.simulator.serviceprovider.SimulatorResourceServer;
32 * This class provides a set of methods for creation and deletion of resources.
34 public class SimulatorManager {
37 * Set listener for receiving log messages.
40 * {@link ILogger} to receive the log messages.
42 public static void setLogger(ILogger logger) {
43 SimulatorManagerNativeInterface.setLogger(logger);
47 * API for creating a resource from a RAML configuration file whose path is
48 * given as a parameter.
51 * Path to RAML configuration file.
53 * Listener for receiving notifications whenever there is a
54 * change in the resource model.
56 * @return {@link SimulatorResourceServer} - Created resource on success,
59 public static SimulatorResourceServer createResource(String configPath,
60 IResourceModelChangedListener listener) {
61 SimulatorResourceServer simulatorResourceServerObj;
62 simulatorResourceServerObj = SimulatorManagerNativeInterface
63 .createResource(configPath, listener);
64 return simulatorResourceServerObj;
68 * API for creating a set of resources from a RAML configuration file whose
69 * path is given as a parameter.
72 * Path to RAML configuration file.
74 * Number of resources to be created.
76 * Listener for receiving notifications whenever there is a
77 * change in the resource model.
79 * @return Returns an array of {@link SimulatorResourceServer} objects one
80 * for each created resource on success, otherwise null.
82 public static SimulatorResourceServer[] createResource(String configPath,
83 int count, IResourceModelChangedListener listener) {
84 SimulatorResourceServer[] simulatorResourceServers;
85 simulatorResourceServers = SimulatorManagerNativeInterface
86 .createResources(configPath, count, listener);
87 return simulatorResourceServers;
91 * API for getting all locally created resources.
93 * @return Returns a list of {@link SimulatorResourceServer} objects on
94 * success, otherwise null.
96 public static Vector<SimulatorResourceServer> getLocalResources() {
97 Vector<SimulatorResourceServer> simulatorResourceServerVector = null;
98 simulatorResourceServerVector = SimulatorManagerNativeInterface
100 return simulatorResourceServerVector;
104 * API for deleting a specific resource.
107 * {@link SimulatorResourceServer} object of the resource to be
110 public static void deleteResource(SimulatorResourceServer resource) {
111 SimulatorManagerNativeInterface.deleteResource(resource);
115 * API for deleting either all the resources or resources of a specific
116 * type. Ex: If resourceType is oic.light, all resources of oic.light type
117 * will be deleted. If resourceType is null, then all of the resources will
120 * @param resourceType
121 * Type of resource to be deleted.
123 public static void deleteResources(String resourceType) {
124 SimulatorManagerNativeInterface.deleteResources(resourceType);
128 * API for discovering resources in the network. Callback is called whenever
129 * a resource is discovered in the network.
131 * @param resourceType
132 * Required resource type
134 * Interface to receive the discovered remote resources.
136 * @return OCSimulatorResult - return value of this API. It returns
137 * OC_STACK_OK if success.
139 public static OCSimulatorResult findResource(String resourceType,
140 IFindResourceListener listener) {
141 OCSimulatorResult result;
142 int ordinal = SimulatorManagerNativeInterface.findResource(
143 resourceType, listener);
144 result = OCSimulatorResult.conversion(ordinal);
149 * API for getting the list of previously discovered resources in the
152 * @param resourceType
153 * Required resource type
155 * @return A list of {@link SimulatorRemoteResource} - returns list of
156 * SimulatorRemoteResource
159 public static ArrayList<SimulatorRemoteResource> getFoundResources(
160 String resourceType) {
161 ArrayList<SimulatorRemoteResource> resourceList = SimulatorManagerNativeInterface
162 .getFoundResources(resourceType);