2016-07-06 21 views
0

URLをCoAPサーバに動的に追加するための方法を作成しました。これは私が実装した現在のアプローチです。しかし、CoAPサーバにリソースを追加する適切な方法はこれを知る必要がありますか? coapendpoints/home/room1/sensor1を追加する必要があるとします。CoAPサーバにリソースを動的に追加する適切な方法

// endpoint--> coapendpoints/home/room1/sensor1 
    String[] resources = endpoint.split("/"); 
    Resource childResource = coapServer.getRoot().getChild(resources[0]); 
    Resource parentResource = childResource; 
    if (parentResource == null && (resources.length > 1)) { 
     coapServer.add(new CoAPResourcePath(resources)); 
    } 
    if (parentResource == null && (resources.length == 1)) { 
     coapServer.add(new CoAPResourceServlet(resources[0])); 
    } else if (parentResource != null && resources.length > 1) { 
     int j = 1; 
     for (; j < resources.length; j++) { 
      if (childResource != null) { 
       parentResource = childResource; 
       childResource = childResource.getChild(resources[j]); 
      } else { 
       break; 
      } 
     } 
     String[] coapEndpoint = Arrays.copyOfRange(resources, j - 1, resources.length); 
     if (coapEndpoint.length > 1) { 
      parentResource.add(new CoAPResourcePath(coapEndpoint)); 
     } else if (coapEndpoint.length == 1) { 
      parentResource.add(new CoAPResourceServlet(coapEndpoint[0])); 
     } 
    } else if (parentResource != null && resources.length == 1) { 
     parentResource.add(new CoAPResourceServlet(resources[0])); 
    } 

ここで、CoAPResourcePathおよびCoAPResourceServletクラスは、CoapResourceから拡張されています。

これは、この方法でリソースを追加した後の出力です。
enter image description here

答えて

0

私は同様のアプローチで終了しました。現在、カリフォルニアにはネストされたリソースを手軽に作成するオプションはありません。

関連する問題