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 org.oic.simulator;
19 import java.util.Vector;
21 import org.oic.simulator.client.FindResourceListener;
22 import org.oic.simulator.server.SimulatorResource;
25 * This class provides a set of methods for creation, discovery and deletion of
28 public class SimulatorManager {
30 private SimulatorManager() {
34 * API for creating a resource from a RAML configuration file.
37 * Path to RAML configuration file.
39 * @return {@link SimulatorResource} - Created resource on success,
42 * @throws InvalidArgsException
43 * Thrown if the input parameters are empty.
44 * @throws SimulatorException
45 * Thrown for other errors.
47 public static native SimulatorResource createResource(String configPath)
48 throws InvalidArgsException, SimulatorException;
51 * API for creating a set of resources from a RAML configuration file.
54 * Path to RAML configuration file.
56 * Number of resources to be created.
58 * @return Returns an array of {@link SimulatorResource} objects one for
59 * each created resource on success, otherwise null.
61 * @throws InvalidArgsException
62 * Thrown if the input parameters are empty.
63 * @throws SimulatorException
64 * Thrown for other errors.
66 public static Vector<SimulatorResource> createResource(String configPath,
67 int count) throws InvalidArgsException, SimulatorException {
68 return createResources(configPath, count);
72 * API for creating a resource either single or collection type.
75 * Indicates whether single or collection type.
83 * @return {@link SimulatorResource} - Created resource on success,
86 * @throws InvalidArgsException
87 * Thrown if the input parameters are empty.
88 * @throws SimulatorException
89 * Thrown for other errors.
91 public static SimulatorResource createResource(SimulatorResource.Type type,
92 String name, String uri, String resourceType)
93 throws InvalidArgsException, SimulatorException {
94 SimulatorResource resource = null;
95 if (type == SimulatorResource.Type.SINGLE)
96 resource = createSingleResource(name, uri, resourceType);
98 resource = createCollectionResource(name, uri, resourceType);
103 * API for discovering all types of resources in the network. Callback is
104 * called when a resource is discovered in the network.
107 * Interface to receive the discovered remote resources.
109 * @throws InvalidArgsException
110 * Thrown if the input parameter is empty.
111 * @throws SimulatorException
112 * Thrown for other errors.
114 public static void findResource(FindResourceListener listener)
115 throws InvalidArgsException, SimulatorException {
116 searchResource(null, listener);
120 * API for discovering specific type of resources in the network. Callback
121 * is called when a resource is discovered in the network.
123 * @param resourceType
124 * Required resource type.
126 * Interface to receive the discovered remote resources.
128 * @throws InvalidArgsException
129 * Thrown if the input parameter is empty.
130 * @throws SimulatorException
131 * Thrown for other errors.
133 public static void findResource(String resourceType,
134 FindResourceListener listener) throws InvalidArgsException,
136 if (null == resourceType || resourceType.isEmpty()) {
137 throw new InvalidArgsException(
138 SimulatorResult.SIMULATOR_INVALID_PARAM,
139 "Invalid resource type!");
142 searchResource(resourceType, listener);
146 * API to set the device information.
149 * Device information.
151 * @throws InvalidArgsException
152 * Thrown if the input parameter is empty.
153 * @throws SimulatorException
154 * Thrown for other errors.
156 public static native void setDeviceInfo(String deviceInfo)
157 throws InvalidArgsException, SimulatorException;
160 * API to search for devices on the given host in the network.
163 * URI of the host device.
165 * Listener for receiving the device information.
167 * @throws InvalidArgsException
168 * Thrown if the input parameter is empty.
169 * @throws SimulatorException
170 * Thrown for other errors.
172 public static native void findDevices(String hostUri,
173 DeviceListener listener) throws InvalidArgsException,
177 * API to set the platform information.
179 * @param platformInfo
180 * {@link PlatformInfo} - Platform information.
182 * @throws InvalidArgsException
183 * Thrown if the input parameter is empty.
184 * @throws SimulatorException
185 * Thrown for other errors.
187 public static native void setPlatformInfo(PlatformInfo platformInfo)
188 throws InvalidArgsException, SimulatorException;
191 * API to find the platform information of the given host in the network.
194 * URI of the host device.
196 * Listener for receiving the platform information.
198 * @throws InvalidArgsException
199 * Thrown if the input parameter is empty.
200 * @throws SimulatorException
201 * Thrown for other errors.
203 public static native void getPlatformInformation(String hostUri,
204 PlatformListener listener) throws InvalidArgsException,
208 * API to set the listener for receiving log messages.
211 * {@link ILogger} to receive the log messages.
213 public static native void setLogger(ILogger logger);
215 private static native Vector<SimulatorResource> createResources(
216 String configPath, int count);
218 private static native SimulatorResource createSingleResource(String name,
219 String uri, String resourceType);
221 private static native SimulatorResource createCollectionResource(
222 String name, String uri, String resourceType);
224 private static native void searchResource(String resourceType,
225 FindResourceListener listener);