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 SimulatorResourceServer} - 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 SimulatorResourceServer} objects one
59 * for 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 * Path to RAML configuration file.
77 * @return {@link SimulatorResourceServer} - Created resource on success,
80 * @throws InvalidArgsException
81 * Thrown if the input parameters are empty.
82 * @throws SimulatorException
83 * Thrown for other errors.
85 public static SimulatorResource createResource(SimulatorResource.Type type,
86 String name, String uri, String resourceType)
87 throws InvalidArgsException, SimulatorException {
88 SimulatorResource resource = null;
89 if (type == SimulatorResource.Type.SINGLE)
90 resource = createSingleResource(name, uri, resourceType);
92 resource = createCollectionResource(name, uri, resourceType);
97 * API for discovering all types of resources in the network. Callback is
98 * called when a resource is discovered in the network.
101 * Interface to receive the discovered remote resources.
103 * @throws InvalidArgsException
104 * Thrown if the input parameter is empty.
105 * @throws SimulatorException
106 * Thrown for other errors.
108 public static void findResource(FindResourceListener listener)
109 throws InvalidArgsException, SimulatorException {
110 searchResource(null, listener);
114 * API for discovering specific type of resources in the network. Callback
115 * is called when a resource is discovered in the network.
117 * @param resourceType
118 * Required resource type
120 * Interface to receive the discovered remote resources.
122 * @throws InvalidArgsException
123 * Thrown if the input parameter is empty.
124 * @throws SimulatorException
125 * Thrown for other errors.
127 public static void findResource(String resourceType,
128 FindResourceListener listener) throws InvalidArgsException,
130 if (null == resourceType || resourceType.isEmpty()) {
131 throw new InvalidArgsException(
132 SimulatorResult.SIMULATOR_INVALID_PARAM,
133 "Invalid resource type!");
136 searchResource(resourceType, listener);
140 * API to set the device information.
143 * Device information.
145 public static native void setDeviceInfo(String deviceInfo)
146 throws InvalidArgsException, SimulatorException;
149 * API to search for devices in the network.
152 * Listener for receiving the device information.
154 public static native void findDevices(DeviceListener listener)
155 throws InvalidArgsException, SimulatorException;
158 * API to set the platform information.
160 * @param platformInfo
161 * {@link PlatformInfo} - Platform information.
163 public static native void setPlatformInfo(PlatformInfo platformInfo)
164 throws InvalidArgsException, SimulatorException;
167 * API to find all devices' platform information in the network.
170 * Listener for receiving the platform information.
172 public static native void getPlatformInformation(PlatformListener listener)
173 throws InvalidArgsException, SimulatorException;
176 * API to set the listener for receiving log messages.
179 * {@link ILogger} to receive the log messages.
181 public static native void setLogger(ILogger logger)
182 throws SimulatorException;
184 private static native Vector<SimulatorResource> createResources(
185 String configPath, int count);
187 private static native SimulatorResource createSingleResource(String name,
188 String uri, String resourceType);
190 private static native SimulatorResource createCollectionResource(
191 String name, String uri, String resourceType);
193 private static native void searchResource(String resourceType,
194 FindResourceListener listener);