Skip to content

Commit

Permalink
fix updated pom, update parameters parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
lroffia committed Dec 2, 2024
1 parent d8f0b6c commit fc0cfb2
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 60 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,6 @@ public class SPARQL11Properties {
protected SPARQL11ProtocolProperties sparql11protocol;
protected GraphsProperties graphs = null;

private URI uri = null;

/**
* The Enum SPARQLPrimitive (QUERY, UPDATE).
*/
Expand Down Expand Up @@ -170,12 +168,14 @@ public SPARQL11Properties(URI uri,String[] args) throws SEPAPropertiesException
}

if (args != null)
for (int i = 0; i < args.length; i = i + 2) {
Logging.logger.trace("Argument "+args[i]+" : "+args[i+1]);
setParameter(args[i], args[i+1]);
// Setting values: -key=value
for (int i = 0; i < args.length; i++) {
Logging.logger.trace("Argument "+args[i]);
String[] params = args[i].split("=");
if (params.length == 2) {
setParameter(params[0], params[1]);
}
}

this.uri = uri;
}

protected void setParameter(String key,String value) {
Expand Down Expand Up @@ -210,19 +210,6 @@ protected void setParameter(String key,String value) {
}
}

private void parseJSAP(Reader in) throws SEPAPropertiesException {
SPARQL11Properties jsap;
try {
jsap = new Gson().fromJson(in, SPARQL11Properties.class);
} catch (JsonSyntaxException | JsonIOException e) {
Logging.logger.error(e.getMessage());
throw new SEPAPropertiesException(e);
}

this.sparql11protocol = jsap.sparql11protocol;
this.graphs = jsap.graphs;
}

/*
* Applications working with file paths and file URIs should take great care
* to use the appropriate methods to convert between the two.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,22 +85,23 @@ public enum SPARQL11SEPrimitive {
protected SPARQL11SEProtocolProperties sparql11seprotocol;

public SPARQL11SEProperties() throws SEPAPropertiesException {
this((URI) null,null);
this((URI) null, null);
}
public SPARQL11SEProperties(String uri,String[] args) throws SEPAPropertiesException {
this(URI.create(uri),args);

public SPARQL11SEProperties(String uri, String[] args) throws SEPAPropertiesException {
this(URI.create(uri), args);
}

public SPARQL11SEProperties(URI uri) throws SEPAPropertiesException {
this(uri,null);
this(uri, null);
}

public SPARQL11SEProperties(String uri) throws SEPAPropertiesException {
this(URI.create(uri),null);
this(URI.create(uri), null);
}

public SPARQL11SEProperties(URI uri,String[] args) throws SEPAPropertiesException {
super(uri,args);
public SPARQL11SEProperties(URI uri, String[] args) throws SEPAPropertiesException {
super(uri, args);

if (uri != null) {
Reader in = getReaderFromUri(uri);
Expand All @@ -118,44 +119,56 @@ public SPARQL11SEProperties(URI uri,String[] args) throws SEPAPropertiesExceptio
} catch (IOException e) {
throw new SEPAPropertiesException(e);
}
} else sparql11seprotocol = new SPARQL11SEProtocolProperties();
} else
sparql11seprotocol = new SPARQL11SEProtocolProperties();

Map<String, String> envs = System.getenv();
for(String var : envs.keySet()) {
Logging.logger.trace("Environmental variable "+var+" : "+envs.get(var));
setSeParameter("-"+var, envs.get(var));
for (String var : envs.keySet()) {
Logging.logger.trace("Environmental variable " + var + " : " + envs.get(var));
setSeParameter("-" + var, envs.get(var));
}

if (args != null)
for (int i = 0; i < args.length; i = i + 2) {
Logging.logger.trace("Argument "+args[i]+" : "+args[i+1]);
setSeParameter(args[i], args[i+1]);
for (int i = 0; i < args.length; i++) {
Logging.logger.trace("Argument " + args[i]);
String[] params = args[i].split("=");
if (params.length == 2) {
setParameter(params[0], params[1]);
}
}
}

protected void setSeParameter(String key,String value) {
protected void setSeParameter(String key, String value) {
switch (key) {
case "-sparql11seprotocol.host":
sparql11seprotocol.setHost(value);
break;
case "-sparql11seprotocol.protocol":
sparql11seprotocol.setProtocol(value);
break;
case "-sparql11seprotocol.reconnect":
sparql11seprotocol.setReconnect(Boolean.parseBoolean(value));
break;
default:
if (key.startsWith("-sparql11seprotocol.availableProtocols")) {
String[] token = key.split("\\.");
if (sparql11seprotocol == null) sparql11seprotocol = new SPARQL11SEProtocolProperties();
if (sparql11seprotocol.getAvailableProtocols() == null) {
sparql11seprotocol.setAvailableProtocols(new HashMap<>());
case "-sparql11seprotocol.host":
sparql11seprotocol.setHost(value);
break;
case "-sparql11seprotocol.protocol":
sparql11seprotocol.setProtocol(value);
break;
case "-sparql11seprotocol.reconnect":
sparql11seprotocol.setReconnect(Boolean.parseBoolean(value));
break;
default:
if (key.startsWith("-sparql11seprotocol.availableProtocols")) {
String[] token = key.split("\\.");
if (sparql11seprotocol == null)
sparql11seprotocol = new SPARQL11SEProtocolProperties();
if (sparql11seprotocol.getAvailableProtocols() == null) {
sparql11seprotocol.setAvailableProtocols(new HashMap<>());
sparql11seprotocol.getAvailableProtocols().put(token[2], new SubscriptionProtocolProperties());
} else {
if (sparql11seprotocol.getAvailableProtocols().get(token[2]) == null) {
sparql11seprotocol.getAvailableProtocols().put(token[2], new SubscriptionProtocolProperties());
}
if (Objects.equals(token[3], "path")) sparql11seprotocol.getAvailableProtocols().get(token[2]).setPath(value);
else if (Objects.equals(token[3], "port")) sparql11seprotocol.getAvailableProtocols().get(token[2]).setPort(Integer.parseInt(value));
else if (Objects.equals(token[3], "scheme")) sparql11seprotocol.getAvailableProtocols().get(token[2]).setScheme(value);
}
if (Objects.equals(token[3], "path"))
sparql11seprotocol.getAvailableProtocols().get(token[2]).setPath(value);
else if (Objects.equals(token[3], "port"))
sparql11seprotocol.getAvailableProtocols().get(token[2]).setPort(Integer.parseInt(value));
else if (Objects.equals(token[3], "scheme"))
sparql11seprotocol.getAvailableProtocols().get(token[2]).setScheme(value);
}
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
package it.unibo.arces.wot.sepa.commons.properties;

import it.unibo.arces.wot.sepa.api.SubscriptionProtocol;
import it.unibo.arces.wot.sepa.api.protocols.websocket.WebsocketSubscriptionProtocol;

import java.util.HashMap;

public class SPARQL11SEProtocolProperties {
Expand Down
8 changes: 4 additions & 4 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,10 @@
</scm>

<properties>
<java.version>11</java.version>
<maven.compiler.release>11</maven.compiler.release>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
<java.version>23</java.version>
<maven.compiler.release>23</maven.compiler.release>
<maven.compiler.source>23</maven.compiler.source>
<maven.compiler.target>23</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<revision>1.0.0-SNAPSHOT</revision>
<update>0</update>
Expand Down

0 comments on commit fc0cfb2

Please sign in to comment.