1 //******************************************************************
3 // Copyright 2014 Intel Corporation All Rights Reserved.
4 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
9 import java.util.ArrayList;
12 * Static methods allow you to call to the OC stack, while non-static methods provide traversal
13 * through the tree of hierarchical resources. Non-static methods also retrieve properties of the
14 * current OCResource object.
16 public class OCResource {
17 private OCResource _parent = null;
18 private ArrayList<OCResource> _children = null;
19 private boolean _isContainer = false;
21 public OCResource(OCResource parent, ArrayList<OCResource> children, boolean isContainer) {
24 _isContainer = isContainer;
27 OCResource getParent() {
31 ArrayList<OCResource> getChildren() {
36 * Recursively gets all the operable resources below this in the tree to a depth of 2.
38 * @return Returns an ArrayList of operable OCResource objects below this OCResource's position in
41 ArrayList<OCResource> getResource() {
42 return getResources(2);
46 * Recursively gets all the operable resources below this in the tree.
48 * @param depth - The depth to traverse the tree downward.
49 * @return Returns an ArrayList of operable OCResource objects below this OCResource's position in
52 ArrayList<OCResource> getResources(int depth) {
56 ArrayList<OCResource> retRes = new ArrayList<OCResource>();
57 if (_isContainer == true) { // If this is a resource container, add all the resources below me
59 for (OCResource child : getChildren()) {
60 retRes.addAll(child.getResources(depth - 1));
63 retRes.add(OCResource.this);
69 * Recursively gets all the container (i.e. inoperable) resources below this in the tree to a
72 * @return Returns an ArrayList of inoperable OCResource objects below this OCResource's position
75 ArrayList<OCResource> getResourceContainers() {
76 return getResourceContainers(2);
80 * Recursively gets all the container (i.e. inoperable) resources below this in the tree.
82 * @param depth - The depth to traverse the tree downward.
84 * @return Returns an ArrayList of inoperable OCResource objects below this OCResource's position
87 ArrayList<OCResource> getResourceContainers(int depth) {
91 ArrayList<OCResource> retRes = new ArrayList<OCResource>();
92 if (_isContainer == true) {
93 for (OCResource child : getChildren()) {
94 retRes.addAll(child.getResourceContainers(depth - 1));
96 retRes.add(OCResource.this);
101 * Recursively gets all the resources (operable & inoperable) resources below this in the tree
104 * @return Returns an ArrayList of operable & inoperable OCResource objects below this
105 * OCResource's position in the tree.
107 ArrayList<OCResource> getAllResources() {
108 return getAllResources(2);
112 * Recursively gets all the resources (operable & inoperable) resources below this in the tree.
114 * @param depth - The depth to traverse the tree downward.
116 * @return Returns an ArrayList of operable & inoperable OCResource objects below this
117 * OCResource's position in the tree.
119 ArrayList<OCResource> getAllResources(int depth) {
120 if (depth - 1 <= 0) {
123 ArrayList<OCResource> retRes = new ArrayList<OCResource>();
124 if (_isContainer == true) {
125 for (OCResource child : getChildren()) {
126 retRes.addAll(child.getAllResources(depth - 1));
128 retRes.add(OCResource.this);
130 retRes.add(OCResource.this);
137 * @return Returns the resource URI to address this Resource. You can determine the service that
138 * is hosting this resource by parsing this URI.
145 * Returns the requested interface for this resource
147 * @param interfaceClass - The interface that is desired.
149 * @return The interface requested or NULL if not supported.
151 public <T> T getInterface(java.lang.Class<T> interfaceClass) {