1 //******************************************************************
3 // Copyright 2014 Intel Mobile Communications GmbH All Rights Reserved.
5 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
7 // Licensed under the Apache License, Version 2.0 (the "License");
8 // you may not use this file except in compliance with the License.
9 // You may obtain a copy of the License at
11 // http://www.apache.org/licenses/LICENSE-2.0
13 // Unless required by applicable law or agreed to in writing, software
14 // distributed under the License is distributed on an "AS IS" BASIS,
15 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 // See the License for the specific language governing permissions and
17 // limitations under the License.
19 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
24 import java.util.ArrayList;
27 * Static methods allow you to call to the OC stack, while non-static methods provide traversal
28 * through the tree of hierarchical resources. Non-static methods also retrieve properties of the
29 * current OCResource object.
31 public class OCResource {
32 private OCResource _parent = null;
33 private ArrayList<OCResource> _children = null;
34 private boolean _isContainer = false;
36 public OCResource(OCResource parent, ArrayList<OCResource> children, boolean isContainer) {
39 _isContainer = isContainer;
42 OCResource getParent() {
46 ArrayList<OCResource> getChildren() {
51 * Recursively gets all the operable resources below this in the tree to a depth of 2.
53 * @return Returns an ArrayList of operable OCResource objects below this OCResource's position in
56 ArrayList<OCResource> getResource() {
57 return getResources(2);
61 * Recursively gets all the operable resources below this in the tree.
63 * @param depth - The depth to traverse the tree downward.
64 * @return Returns an ArrayList of operable OCResource objects below this OCResource's position in
67 ArrayList<OCResource> getResources(int depth) {
71 ArrayList<OCResource> retRes = new ArrayList<OCResource>();
72 if (_isContainer == true) { // If this is a resource container, add all the resources below me
74 for (OCResource child : getChildren()) {
75 retRes.addAll(child.getResources(depth - 1));
78 retRes.add(OCResource.this);
84 * Recursively gets all the container (i.e. inoperable) resources below this in the tree to a
87 * @return Returns an ArrayList of inoperable OCResource objects below this OCResource's position
90 ArrayList<OCResource> getResourceContainers() {
91 return getResourceContainers(2);
95 * Recursively gets all the container (i.e. inoperable) resources below this in the tree.
97 * @param depth - The depth to traverse the tree downward.
99 * @return Returns an ArrayList of inoperable OCResource objects below this OCResource's position
102 ArrayList<OCResource> getResourceContainers(int depth) {
103 if (depth - 1 <= 0) {
106 ArrayList<OCResource> retRes = new ArrayList<OCResource>();
107 if (_isContainer == true) {
108 for (OCResource child : getChildren()) {
109 retRes.addAll(child.getResourceContainers(depth - 1));
111 retRes.add(OCResource.this);
116 * Recursively gets all the resources (operable & inoperable) resources below this in the tree
119 * @return Returns an ArrayList of operable & inoperable OCResource objects below this
120 * OCResource's position in the tree.
122 ArrayList<OCResource> getAllResources() {
123 return getAllResources(2);
127 * Recursively gets all the resources (operable & inoperable) resources below this in the tree.
129 * @param depth - The depth to traverse the tree downward.
131 * @return Returns an ArrayList of operable & inoperable OCResource objects below this
132 * OCResource's position in the tree.
134 ArrayList<OCResource> getAllResources(int depth) {
135 if (depth - 1 <= 0) {
138 ArrayList<OCResource> retRes = new ArrayList<OCResource>();
139 if (_isContainer == true) {
140 for (OCResource child : getChildren()) {
141 retRes.addAll(child.getAllResources(depth - 1));
143 retRes.add(OCResource.this);
145 retRes.add(OCResource.this);
152 * @return Returns the resource URI to address this Resource. You can determine the service that
153 * is hosting this resource by parsing this URI.
160 * Returns the requested interface for this resource
162 * @param interfaceClass - The interface that is desired.
164 * @return The interface requested or NULL if not supported.
166 public <T> T getInterface(java.lang.Class<T> interfaceClass) {