diff --git a/client-api/src/main/java/it/unibo/arces/wot/sepa/commons/properties/SPARQL11SEProperties.java b/client-api/src/main/java/it/unibo/arces/wot/sepa/commons/properties/SPARQL11SEProperties.java index d721aea2..90a31a12 100644 --- a/client-api/src/main/java/it/unibo/arces/wot/sepa/commons/properties/SPARQL11SEProperties.java +++ b/client-api/src/main/java/it/unibo/arces/wot/sepa/commons/properties/SPARQL11SEProperties.java @@ -20,6 +20,7 @@ import java.io.IOException; import java.io.Reader; +import java.util.HashMap; import com.google.gson.Gson; import com.google.gson.JsonIOException; @@ -82,7 +83,7 @@ public enum SPARQL11SEPrimitive { protected SPARQL11SEProtocolProperties sparql11seprotocol; public SPARQL11SEProperties() { - sparql11seprotocol = new SPARQL11SEProtocolProperties(); + super(); override(null); } @@ -150,52 +151,59 @@ private void parseJSAP(Reader in) throws SEPAPropertiesException { } protected final void setParameter(String key,String value) { + super.setParameter(key, value); + switch (key) { - case "-host" : - this.host = value; - break; - case "-sparql11protocol.port": - this.sparql11protocol.port = Integer.valueOf(value); - break; - case "-sparql11protocol.host": - this.sparql11protocol.host = host; - break; - case "-sparql11protocol.protocol": - this.sparql11protocol.protocol = (value == "http" ? ProtocolScheme.http : ProtocolScheme.https); - break; - case "-sparql11protocol.update.method": - this.sparql11protocol.update.method = (value == "post" ? UpdateProperties.UpdateHTTPMethod.POST : UpdateProperties.UpdateHTTPMethod.URL_ENCODED_POST); - break; - case "-sparql11protocol.update.format": - this.sparql11protocol.update.format = (value == "json" ? UpdateProperties.UpdateResultsFormat.JSON : UpdateProperties.UpdateResultsFormat.HTML); - break; - case "-sparql11protocol.update.path": - this.sparql11protocol.update.path = value; - break; - case "-sparql11protocol.query.method": - this.sparql11protocol.query.method = (value == "get" ? QueryProperties.QueryHTTPMethod.GET : (value == "post" ? QueryProperties.QueryHTTPMethod.POST : QueryProperties.QueryHTTPMethod.URL_ENCODED_POST)); - break; - case "-sparql11protocol.query.format": - this.sparql11protocol.query.format = (value == "json" ? QueryProperties.QueryResultsFormat.JSON : (value == "xml" ? QueryProperties.QueryResultsFormat.XML : QueryProperties.QueryResultsFormat.CSV)); - break; - case "-sparql11protocol.query.path": - this.sparql11protocol.query.path = value; - break; +// case "-host" : +// this.host = value; +// break; +// case "-sparql11protocol.port": +// this.sparql11protocol.port = Integer.valueOf(value); +// break; +// case "-sparql11protocol.host": +// this.sparql11protocol.host = host; +// break; +// case "-sparql11protocol.protocol": +// this.sparql11protocol.protocol = (value == "http" ? ProtocolScheme.http : ProtocolScheme.https); +// break; +// case "-sparql11protocol.update.method": +// this.sparql11protocol.update.method = (value == "post" ? UpdateProperties.UpdateHTTPMethod.POST : UpdateProperties.UpdateHTTPMethod.URL_ENCODED_POST); +// break; +// case "-sparql11protocol.update.format": +// this.sparql11protocol.update.format = (value == "json" ? UpdateProperties.UpdateResultsFormat.JSON : UpdateProperties.UpdateResultsFormat.HTML); +// break; +// case "-sparql11protocol.update.path": +// this.sparql11protocol.update.path = value; +// break; +// case "-sparql11protocol.query.method": +// this.sparql11protocol.query.method = (value == "get" ? QueryProperties.QueryHTTPMethod.GET : (value == "post" ? QueryProperties.QueryHTTPMethod.POST : QueryProperties.QueryHTTPMethod.URL_ENCODED_POST)); +// break; +// case "-sparql11protocol.query.format": +// this.sparql11protocol.query.format = (value == "json" ? QueryProperties.QueryResultsFormat.JSON : (value == "xml" ? QueryProperties.QueryResultsFormat.XML : QueryProperties.QueryResultsFormat.CSV)); +// break; +// case "-sparql11protocol.query.path": +// this.sparql11protocol.query.path = value; +// break; case "-sparql11seprotocol.host": - this.sparql11seprotocol.host = value; + this.sparql11seprotocol.setHost(value); break; case "-sparql11seprotocol.protocol": - this.sparql11seprotocol.protocol = value; + this.sparql11seprotocol.setProtocol(value); break; case "-sparql11seprotocol.reconnect": - this.sparql11seprotocol.reconnect = Boolean.valueOf(value); + this.sparql11seprotocol.setReconnect(Boolean.valueOf(value)); break; default: if (key.startsWith("-sparql11seprotocol.availableProtocols")) { String[] token = key.split("\\."); - if (token[3] == "path") this.sparql11seprotocol.availableProtocols.get(token[2]).path = value; - else if (token[3] == "port") this.sparql11seprotocol.availableProtocols.get(token[2]).port = Integer.valueOf(value); - else if (token[3] == "scheme") this.sparql11seprotocol.availableProtocols.get(token[2]).scheme = value; + if (this.sparql11seprotocol == null) sparql11seprotocol = new SPARQL11SEProtocolProperties(); + if (this.sparql11seprotocol.getAvailableProtocols() == null) { + this.sparql11seprotocol.setAvailableProtocols(new HashMap()); + this.sparql11seprotocol.getAvailableProtocols().put(token[2], new SubscriptionProtocolProperties()); + } + if (token[3] == "path") this.sparql11seprotocol.getAvailableProtocols().get(token[2]).setPath(value); + else if (token[3] == "port") this.sparql11seprotocol.getAvailableProtocols().get(token[2]).setPort(Integer.valueOf(value)); + else if (token[3] == "scheme") this.sparql11seprotocol.getAvailableProtocols().get(token[2]).setScheme(value); } } } @@ -205,39 +213,39 @@ public String toString() { } public String getSubscribeHost() { - return (sparql11seprotocol.host != null ? sparql11seprotocol.host : super.host); + return (sparql11seprotocol.getHost() != null ? sparql11seprotocol.getHost() : super.host); } public void setHost(String host) { - sparql11seprotocol.host = host; + sparql11seprotocol.setHost(host); } public String getSubscribePath() { - return sparql11seprotocol.availableProtocols.get(sparql11seprotocol.protocol).path; + return sparql11seprotocol.getAvailableProtocols().get(sparql11seprotocol.getProtocol()).getPath(); } public void setSubscribePath(String path) { - sparql11seprotocol.availableProtocols.get(sparql11seprotocol.protocol).path = path; + sparql11seprotocol.getAvailableProtocols().get(sparql11seprotocol.getProtocol()).setPath(path); } public int getSubscribePort() { - return sparql11seprotocol.availableProtocols.get(sparql11seprotocol.protocol).port; + return sparql11seprotocol.getAvailableProtocols().get(sparql11seprotocol.getProtocol()).getPort(); } public void setSubscribePort(int port) { - sparql11seprotocol.availableProtocols.get(sparql11seprotocol.protocol).port = port; + sparql11seprotocol.getAvailableProtocols().get(sparql11seprotocol.getProtocol()).setPort(port); } public SubscriptionProtocolProperties getSubscriptionProtocol() { - return sparql11seprotocol.availableProtocols.get(sparql11seprotocol.protocol); + return sparql11seprotocol.getAvailableProtocols().get(sparql11seprotocol.getProtocol()); } public boolean getReconnect() { - return sparql11seprotocol.reconnect; + return sparql11seprotocol.isReconnect(); } public void setSubscriptionProtocol(String scheme) { - sparql11seprotocol.protocol = scheme; + sparql11seprotocol.setProtocol(scheme); } } diff --git a/client-api/src/main/java/it/unibo/arces/wot/sepa/commons/properties/SPARQL11SEProtocolProperties.java b/client-api/src/main/java/it/unibo/arces/wot/sepa/commons/properties/SPARQL11SEProtocolProperties.java index 126782b0..ddae5bdf 100644 --- a/client-api/src/main/java/it/unibo/arces/wot/sepa/commons/properties/SPARQL11SEProtocolProperties.java +++ b/client-api/src/main/java/it/unibo/arces/wot/sepa/commons/properties/SPARQL11SEProtocolProperties.java @@ -3,30 +3,62 @@ import java.util.HashMap; public class SPARQL11SEProtocolProperties { - public String protocol = null; - public HashMap availableProtocols = null; - public String host = null; - public boolean reconnect = true; + private String protocol = null; + private HashMap availableProtocols = new HashMap(); + private String host = null; + private boolean reconnect = true; public SPARQL11SEProtocolProperties merge(SPARQL11SEProtocolProperties temp) { if (temp != null) { - protocol = (temp.protocol != null ? temp.protocol : protocol); - host = (temp.host != null ? temp.host : host); - reconnect = temp.reconnect; - availableProtocols = (temp.availableProtocols != null ? temp.availableProtocols : availableProtocols); + setProtocol((temp.getProtocol() != null ? temp.getProtocol() : getProtocol())); + setHost((temp.getHost() != null ? temp.getHost() : getHost())); + setReconnect(temp.isReconnect()); + setAvailableProtocols((temp.getAvailableProtocols() != null ? temp.getAvailableProtocols() : getAvailableProtocols())); } return this; } public int getPort() { - return availableProtocols.get(protocol).port; + return getAvailableProtocols().get(getProtocol()).getPort(); } public String getPath() { - return availableProtocols.get(protocol).path; + return getAvailableProtocols().get(getProtocol()).getPath(); } public SubscriptionProtocolProperties getSubscriptionProtocol() { - return availableProtocols.get(protocol); + return getAvailableProtocols().get(getProtocol()); + } + + public String getHost() { + return host; + } + + public void setHost(String host) { + this.host = host; + } + + public String getProtocol() { + return protocol; + } + + public void setProtocol(String protocol) { + this.protocol = protocol; + } + + public boolean isReconnect() { + return reconnect; + } + + public void setReconnect(boolean reconnect) { + this.reconnect = reconnect; + } + + public HashMap getAvailableProtocols() { + return availableProtocols; + } + + public void setAvailableProtocols(HashMap availableProtocols) { + this.availableProtocols = availableProtocols; } } diff --git a/client-api/src/main/java/it/unibo/arces/wot/sepa/commons/properties/SubscriptionProtocolProperties.java b/client-api/src/main/java/it/unibo/arces/wot/sepa/commons/properties/SubscriptionProtocolProperties.java index c9af4e1c..14c0daa4 100644 --- a/client-api/src/main/java/it/unibo/arces/wot/sepa/commons/properties/SubscriptionProtocolProperties.java +++ b/client-api/src/main/java/it/unibo/arces/wot/sepa/commons/properties/SubscriptionProtocolProperties.java @@ -1,7 +1,28 @@ package it.unibo.arces.wot.sepa.commons.properties; public class SubscriptionProtocolProperties { - public String path = null; - public String scheme = null; - public int port = -1; + private String path = null; + private String scheme = null; + private int port = -1; + + public String getPath() { + return path; + } + public void setPath(String path) { + this.path = path; + } + public String getScheme() { + return scheme; + } + public void setScheme(String scheme) { + this.scheme = scheme; + } + public int getPort() { + return port; + } + public void setPort(int port) { + this.port = port; + } } + + diff --git a/client-api/src/main/java/it/unibo/arces/wot/sepa/pattern/GenericClient.java b/client-api/src/main/java/it/unibo/arces/wot/sepa/pattern/GenericClient.java index c2796500..1805a301 100644 --- a/client-api/src/main/java/it/unibo/arces/wot/sepa/pattern/GenericClient.java +++ b/client-api/src/main/java/it/unibo/arces/wot/sepa/pattern/GenericClient.java @@ -412,13 +412,13 @@ private void _subscribe(String ID, String sparql, Bindings forced, String alias, if (req != null) subLock.wait(); - url = appProfile.getSubscribeProtocol(ID).scheme+ "_" + appProfile.getSubscribeHost(ID) + "_" + appProfile.getSubscribePort(ID) + "_" + url = appProfile.getSubscribeProtocol(ID).getScheme()+ "_" + appProfile.getSubscribeHost(ID) + "_" + appProfile.getSubscribePort(ID) + "_" + appProfile.getSubscribePath(ID); if (activeClients.containsKey(url)) { subscription = activeClients.get(url); } else { - protocol = new WebsocketSubscriptionProtocol(appProfile.getSubscribeProtocol(ID).scheme,appProfile.getSubscribeHost(ID), + protocol = new WebsocketSubscriptionProtocol(appProfile.getSubscribeProtocol(ID).getScheme(),appProfile.getSubscribeHost(ID), appProfile.getSubscribePort(ID), appProfile.getSubscribePath(ID), this, sm); subscription = new SPARQL11SEProtocol(protocol); } diff --git a/client-api/src/main/java/it/unibo/arces/wot/sepa/pattern/JSAP.java b/client-api/src/main/java/it/unibo/arces/wot/sepa/pattern/JSAP.java index 3cb28469..a3f2f3ad 100644 --- a/client-api/src/main/java/it/unibo/arces/wot/sepa/pattern/JSAP.java +++ b/client-api/src/main/java/it/unibo/arces/wot/sepa/pattern/JSAP.java @@ -703,9 +703,9 @@ public void setDefaultGraphURI(String id, Set graph) { public String getSubscribeHost(String id) { try { - return queries.get(id).sparql11seprotocol.host; + return queries.get(id).sparql11seprotocol.getHost(); } catch (Exception e) { - return host; + return sparql11seprotocol.getHost(); } } @@ -714,13 +714,13 @@ public void setSubscribeHost(String id, String host) { return; // if (queries.get(id).sparql11seprotocol == null) // queries.get(id).sparql11seprotocol = new SPARQL11SEProperties(); - queries.get(id).sparql11seprotocol.host = host; + queries.get(id).sparql11seprotocol.setHost(host); } public int getSubscribePort(String id) { try { - return queries.get(id).sparql11seprotocol.availableProtocols - .get(queries.get(id).sparql11seprotocol.protocol).port; + return queries.get(id).sparql11seprotocol.getAvailableProtocols() + .get(queries.get(id).sparql11seprotocol.getProtocol()).getPort(); } catch (Exception e) { return sparql11seprotocol.getPort(); } @@ -731,14 +731,14 @@ public void setSubscribePort(String id, int port) { return; // if (queries.get(id).sparql11seprotocol == null) // queries.get(id).sparql11seprotocol = new SPARQL11SEProperties(); - queries.get(id).sparql11seprotocol.availableProtocols - .get(queries.get(id).sparql11seprotocol.protocol).port = port; + queries.get(id).sparql11seprotocol.getAvailableProtocols() + .get(queries.get(id).sparql11seprotocol.getProtocol()).setPort(port); } public String getSubscribePath(String id) { try { - return queries.get(id).sparql11seprotocol.availableProtocols - .get(queries.get(id).sparql11seprotocol.protocol).path; + return queries.get(id).sparql11seprotocol.getAvailableProtocols() + .get(queries.get(id).sparql11seprotocol.getProtocol()).getPath(); } catch (Exception e) { return sparql11seprotocol.getPath(); } @@ -749,8 +749,8 @@ public void setSubscribePath(String id, String path) { return; // if (queries.get(id).sparql11seprotocol == null) // queries.get(id).sparql11seprotocol = new SPARQL11SEProperties(); - queries.get(id).sparql11seprotocol.availableProtocols - .get(queries.get(id).sparql11seprotocol.protocol).path = path; + queries.get(id).sparql11seprotocol.getAvailableProtocols() + .get(queries.get(id).sparql11seprotocol.getProtocol()).setPath(path); } public SubscriptionProtocolProperties getSubscribeProtocol(String id) { @@ -766,7 +766,7 @@ public void setSubscribeProtocol(String id, SubscriptionProtocolProperties sp) { return; // if (queries.get(id).sparql11seprotocol == null) // queries.get(id).sparql11seprotocol = new SPARQL11SEProperties(); - queries.get(id).sparql11seprotocol.protocol = sp.scheme; + queries.get(id).sparql11seprotocol.setProtocol(sp.getScheme()); } public Set getUpdateIds() { @@ -957,8 +957,8 @@ public String getSubscribeUrl(String id) throws IllegalArgumentException { if (queries.get(id) == null) throw new IllegalArgumentException("Subscribe ID not found: " + id); - String scheme = queries.get(id).sparql11seprotocol.availableProtocols - .get(queries.get(id).sparql11seprotocol.protocol).scheme; + String scheme = queries.get(id).sparql11seprotocol.getAvailableProtocols() + .get(queries.get(id).sparql11seprotocol.getProtocol()).getScheme(); String port = ""; if (getSubscribePort(id) != -1) @@ -1399,7 +1399,7 @@ private static boolean isValidVarChar(int c) { } public void setAutoReconnect(boolean b) { - sparql11seprotocol.reconnect = b; + sparql11seprotocol.setReconnect(b); } }