NodeConfiguration.java
Go to the documentation of this file.
00001 
00009 package org.rosbuilding.zeroconf;
00010 
00011 import java.util.ArrayList;
00012 import java.util.HashMap;
00013 import java.util.List;
00014 
00020 public class NodeConfiguration {
00021     private static final String MASTER_ADDRESS = "MASTER_ADDRESS";
00022     private static final String NODE_TYPE = "NODE_TYPE";
00023     private static final String NODE_PATH = "NODE_PATH";
00024     private static final String NODE_PERMISSION_NAME = "NODE_PERMISSION_NAME";
00025     private static final String NODE_PERMISSION_EXCLUDE = "NODE_PERMISSION_EXCLUDE";
00026     private static final String NODE_CAPABILITY = "NODE_CAPABILITY";
00027 
00028     private String nodeType;
00029     private String nodePath;
00030     private String masterAddress;
00031 
00032     private List<NodePermission> permissions =
00033             new ArrayList<NodeConfiguration.NodePermission>();
00034 
00035     private List<NodeCapability> capabilities =
00036             new ArrayList<NodeConfiguration.NodeCapability>();
00037 
00038     public NodeConfiguration() {
00039 
00040     }
00041 
00042     public NodeConfiguration(DiscoveredService service) {
00043         this();
00044 
00045         HashMap<String,String> properties = service.properties;
00046 
00047         if (!properties.isEmpty() && properties.containsKey(NODE_TYPE)) {
00048             this.masterAddress = properties.get(MASTER_ADDRESS);
00049             this.nodeType = properties.get(NODE_TYPE);
00050             this.nodePath = properties.get(NODE_PATH);
00051 
00052             int index = 0;
00053             while (properties.containsKey(NODE_CAPABILITY + "_" + index)) {
00054                 String value = properties.get(NODE_CAPABILITY + "_" + index);
00055                 this.capabilities.add(NodeCapability.fromValue(Integer.valueOf(value)));
00056                 index++;
00057             }
00058 
00059             index = 0;
00060             while (properties.containsKey(NODE_PERMISSION_NAME + "_" + index)) {
00061                 String value = properties.get(NODE_PERMISSION_NAME + "_" + index);
00062                 NodePermission permission = new NodePermission();
00063                 permission.name = value;
00064                 if (properties.containsKey(NODE_PERMISSION_EXCLUDE + "_" + index)) {
00065                     permission.exclude = Boolean.valueOf(properties.get(NODE_PERMISSION_EXCLUDE + "_" + index));
00066                 }
00067                 this.permissions.add(permission);
00068                 index++;
00069             }
00070         }
00071     }
00072 
00073     public String getMasterAddress() {
00074         return this.masterAddress;
00075     }
00076 
00077     public void setMasterAddress(String masterAddress) {
00078         this.masterAddress = masterAddress;
00079     }
00080 
00081     public String getNodeType() {
00082         return this.nodeType;
00083     }
00084 
00085     public void setNodeType(String nodeType) {
00086         this.nodeType = nodeType;
00087     }
00088 
00089     public String getNodePath() {
00090         return this.nodePath;
00091     }
00092 
00093     public void setNodePath(String nodePath) {
00094         this.nodePath = nodePath;
00095     }
00096 
00097     public List<NodePermission> getPermissions() {
00098         return this.permissions;
00099     }
00100 
00101     public void setPermissions(List<NodePermission> permissions) {
00102         this.permissions = permissions;
00103     }
00104 
00105     public List<NodeCapability> getCapabilities() {
00106         return this.capabilities;
00107     }
00108 
00109     public void setCapabilities(List<NodeCapability> capabilities) {
00110         this.capabilities = capabilities;
00111     }
00112 
00113     public DiscoveredService toDiscoveredService() {
00114         DiscoveredService result = new DiscoveredService();
00115 
00116         HashMap<String, String> map = new HashMap<String, String>();
00117 
00118         map.put(MASTER_ADDRESS, this.masterAddress);
00119         map.put(NODE_TYPE, this.nodeType);
00120         map.put(NODE_PATH, this.nodePath);
00121 
00122         for (int i = 0; i < this.permissions.size(); i++) {
00123             NodePermission permission = this.permissions.get(i);
00124             map.put(NODE_PERMISSION_NAME + "_" + i, permission.name);
00125             map.put(NODE_PERMISSION_EXCLUDE + "_" + i, String.valueOf(permission.exclude));
00126         }
00127 
00128         for (int i = 0; i < this.capabilities.size(); i++) {
00129             NodeCapability capability = this.capabilities.get(i);
00130             map.put(NODE_CAPABILITY + "_" + i, String.valueOf(capability.value));
00131         }
00132 
00133         result.properties = map;
00134 
00135         return result;
00136     }
00137 
00138     public static class NodePermission {
00139         private String name;
00140         private boolean exclude;
00141 
00142         public String getName() {
00143             return name;
00144         }
00145 
00146         public void setName(String name) {
00147             this.name = name;
00148         }
00149 
00150         public boolean isExclude() {
00151             return exclude;
00152         }
00153 
00154         public void setExclude(boolean exclude) {
00155             this.exclude = exclude;
00156         }
00157     }
00158 
00159     public static enum NodeCapability {
00160         ALL(0),
00161         NODE(1);
00162 
00163         private final int value;
00164 
00165         private NodeCapability(int value) {
00166             this.value = value;
00167         }
00168 
00169         public int getValue() {
00170             return this.value;
00171         }
00172 
00173         public static NodeCapability fromValue(int value) {
00174             NodeCapability result = null;
00175 
00176             for (NodeCapability capability : NodeCapability.values()) {
00177                 if (capability.value == value) {
00178                     result = capability;
00179                     break;
00180                 }
00181             }
00182 
00183             return result;
00184         }
00185     }
00186 }


smarthome_network_zeroconf
Author(s): Mickael Gaillard , Erwan Le Huitouze
autogenerated on Sat Jun 8 2019 18:23:02