SclParser now returns list of ServerModels instead of ServerSaps

pull/11/head
Stefan Feuerhahn 7 years ago
parent 00ed96935f
commit 0200a86cb1

@ -692,22 +692,13 @@ public final class ClientAssociation {
} }
/** /**
* Parses the given SCL File and returns the server model that is described by it. This function can be used instead * Set the server model instead of retrieving it from the server device.
* of <code>retrieveModel</code> in order to get the server model that is needed to call the other ACSI services. *
* * @param model
* @param sclFilePath * the server model
* the path to the SCL file that is to be parsed.
* @return The ServerNode that is the root node of the complete server model.
* @throws SclParseException
* if any kind of fatal error occurs in the parsing process.
*/ */
public ServerModel getModelFromSclFile(String sclFilePath) throws SclParseException { public void setServerModel(ServerModel model) {
List<ServerSap> serverSaps = ServerSap.getSapsFromSclFile(sclFilePath); this.serverModel = model;
if (serverSaps == null || serverSaps.size() == 0) {
throw new SclParseException("No AccessPoint found in SCL file.");
}
serverModel = serverSaps.get(0).serverModel;
return serverModel;
} }
/** /**
@ -2010,6 +2001,10 @@ public final class ClientAssociation {
setDataValues(oper); setDataValues(oper);
} }
public boolean isOpen() {
return !closed;
}
/** /**
* Will close the connection simply by closing the TCP socket. * Will close the connection simply by closing the TCP socket.
*/ */

@ -114,6 +114,12 @@ public final class LogicalNode extends ModelNode {
if (fc != null) { if (fc != null) {
return fcDataObjects.get(fc).get(childName); return fcDataObjects.get(fc).get(childName);
} }
for (Map<String, FcDataObject> map : fcDataObjects.values()) {
FcDataObject fcDataObject = map.get(childName);
if (fcDataObject != null) {
return fcDataObject;
}
}
return null; return null;
} }

@ -45,31 +45,36 @@ import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.Node; import org.w3c.dom.Node;
import org.w3c.dom.NodeList; import org.w3c.dom.NodeList;
final class SclParser { public class SclParser {
private TypeDefinitions typeDefinitions; private TypeDefinitions typeDefinitions;
private final Map<String, DataSet> dataSetsMap = new HashMap<>(); private final Map<String, DataSet> dataSetsMap = new HashMap<>();
private Document doc; private Document doc;
private String iedName; private String iedName;
private List<ServerSap> serverSaps = null; private List<ServerModel> serverModels = null;
private boolean useResvTmsAttributes = false; private boolean useResvTmsAttributes = false;
private final List<LnSubDef> dataSetDefs = new ArrayList<>(); private final List<LnSubDef> dataSetDefs = new ArrayList<>();
public List<ServerSap> getServerSaps() { public static List<ServerModel> parse(InputStream is) throws SclParseException {
return serverSaps; SclParser sclParser = new SclParser();
sclParser.parseStream(is);
return sclParser.serverModels;
} }
public void parse(String icdFile) throws SclParseException { public static List<ServerModel> parse(String sclFilePath) throws SclParseException {
try { try {
parse(new FileInputStream(icdFile)); return parse(new FileInputStream(sclFilePath));
} catch (FileNotFoundException e) { } catch (FileNotFoundException e) {
throw new SclParseException(e); throw new SclParseException(e);
} }
} }
public void parse(InputStream icdFileStream) throws SclParseException { private SclParser() {
}
private void parseStream(InputStream icdFileStream) throws SclParseException {
typeDefinitions = new TypeDefinitions(); typeDefinitions = new TypeDefinitions();
@ -104,12 +109,12 @@ final class SclParser {
NodeList iedElements = iedList.item(0).getChildNodes(); NodeList iedElements = iedList.item(0).getChildNodes();
serverSaps = new ArrayList<>(iedElements.getLength()); serverModels = new ArrayList<>(iedElements.getLength());
for (int i = 0; i < iedElements.getLength(); i++) { for (int i = 0; i < iedElements.getLength(); i++) {
Node element = iedElements.item(i); Node element = iedElements.item(i);
String nodeName = element.getNodeName(); String nodeName = element.getNodeName();
if ("AccessPoint".equals(nodeName)) { if ("AccessPoint".equals(nodeName)) {
serverSaps.add(createAccessPoint(element)); serverModels.add(createAccessPoint(element).serverModel);
} }
else if ("Services".equals(nodeName)) { else if ("Services".equals(nodeName)) {
NodeList servicesElements = element.getChildNodes(); NodeList servicesElements = element.getChildNodes();
@ -174,7 +179,7 @@ final class SclParser {
throw new SclParseException("AccessPoint has no name attribute!"); throw new SclParseException("AccessPoint has no name attribute!");
} }
String name = namedItem.getNodeValue(); String name = namedItem.getNodeValue();
serverSap = new ServerSap(102, 0, null, server, name, null); serverSap = new ServerSap(102, 0, null, server, null);
break; break;
} }

@ -17,7 +17,6 @@
package org.openmuc.openiec61850; package org.openmuc.openiec61850;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream;
import java.net.InetAddress; import java.net.InetAddress;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
import java.util.ArrayList; import java.util.ArrayList;
@ -53,7 +52,6 @@ public final class ServerSap {
ServerEventListener serverEventListener; ServerEventListener serverEventListener;
private ServerAcseSap acseSap; private ServerAcseSap acseSap;
private final String name;
private int port = 102; private int port = 102;
private int backlog = 0; private int backlog = 0;
private InetAddress bindAddr = null; private InetAddress bindAddr = null;
@ -66,18 +64,6 @@ public final class ServerSap {
final ServerModel serverModel; final ServerModel serverModel;
public static List<ServerSap> getSapsFromSclFile(String sclFilePath) throws SclParseException {
SclParser sclParserObject = new SclParser();
sclParserObject.parse(sclFilePath);
return sclParserObject.getServerSaps();
}
public static List<ServerSap> getSapsFromSclFile(InputStream sclFileStream) throws SclParseException {
SclParser sclParserObject = new SclParser();
sclParserObject.parse(sclFileStream);
return sclParserObject.getServerSaps();
}
/** /**
* Creates a ServerSap. * Creates a ServerSap.
* *
@ -94,13 +80,12 @@ public final class ServerSap {
* default * default
* *
*/ */
ServerSap(int port, int backlog, InetAddress bindAddr, ServerModel serverModel, String name, public ServerSap(int port, int backlog, InetAddress bindAddr, ServerModel serverModel,
ServerSocketFactory serverSocketFactory) { ServerSocketFactory serverSocketFactory) {
this.port = port; this.port = port;
this.backlog = backlog; this.backlog = backlog;
this.bindAddr = bindAddr; this.bindAddr = bindAddr;
this.serverSocketFactory = serverSocketFactory; this.serverSocketFactory = serverSocketFactory;
this.name = name;
this.serverModel = serverModel; this.serverModel = serverModel;
} }
@ -148,15 +133,6 @@ public final class ServerSap {
return bindAddr; return bindAddr;
} }
/**
* Returns the name of the ServerSap / AccessPoint as specified in the SCL file.
*
* @return the name.
*/
public String getName() {
return name;
}
/** /**
* Sets the factory class to generate the ServerSocket. The ServerSocketFactory could be used to create * Sets the factory class to generate the ServerSocket. The ServerSocketFactory could be used to create
* SSLServerSockets. Set to <code>null</code> to use <code>ServerSocketFactory.getDefault()</code>. * SSLServerSockets. Set to <code>null</code> to use <code>ServerSocketFactory.getDefault()</code>.

@ -17,6 +17,7 @@ import org.openmuc.openiec61850.FcModelNode;
import org.openmuc.openiec61850.ModelNode; import org.openmuc.openiec61850.ModelNode;
import org.openmuc.openiec61850.Report; import org.openmuc.openiec61850.Report;
import org.openmuc.openiec61850.SclParseException; import org.openmuc.openiec61850.SclParseException;
import org.openmuc.openiec61850.SclParser;
import org.openmuc.openiec61850.ServerModel; import org.openmuc.openiec61850.ServerModel;
import org.openmuc.openiec61850.ServiceError; import org.openmuc.openiec61850.ServiceError;
import org.openmuc.openiec61850.Urcb; import org.openmuc.openiec61850.Urcb;
@ -374,12 +375,14 @@ public class ConsoleClient {
System.out.println("reading model from file..."); System.out.println("reading model from file...");
try { try {
serverModel = association.getModelFromSclFile(modelFileParam.getValue()); serverModel = SclParser.parse(modelFileParam.getValue()).get(0);
} catch (SclParseException e1) { } catch (SclParseException e1) {
System.out.println("Error parsing SCL file: " + e1.getMessage()); System.out.println("Error parsing SCL file: " + e1.getMessage());
return; return;
} }
association.setServerModel(serverModel);
System.out.println("successfully read model"); System.out.println("successfully read model");
} }

@ -17,6 +17,7 @@ import org.openmuc.openiec61850.BdaInt8U;
import org.openmuc.openiec61850.Fc; import org.openmuc.openiec61850.Fc;
import org.openmuc.openiec61850.ModelNode; import org.openmuc.openiec61850.ModelNode;
import org.openmuc.openiec61850.SclParseException; import org.openmuc.openiec61850.SclParseException;
import org.openmuc.openiec61850.SclParser;
import org.openmuc.openiec61850.ServerEventListener; import org.openmuc.openiec61850.ServerEventListener;
import org.openmuc.openiec61850.ServerModel; import org.openmuc.openiec61850.ServerModel;
import org.openmuc.openiec61850.ServerSap; import org.openmuc.openiec61850.ServerSap;
@ -212,15 +213,15 @@ public class ConsoleServer {
System.exit(1); System.exit(1);
} }
List<ServerSap> serverSaps = null; List<ServerModel> serverModels = null;
try { try {
serverSaps = ServerSap.getSapsFromSclFile(modelFileParam.getValue()); serverModels = SclParser.parse(modelFileParam.getValue());
} catch (SclParseException e) { } catch (SclParseException e) {
System.out.println("Error parsing SCL/ICD file: " + e.getMessage()); System.out.println("Error parsing SCL/ICD file: " + e.getMessage());
return; return;
} }
serverSap = serverSaps.get(0); serverSap = new ServerSap(102, 0, null, serverModels.get(0), null);
serverSap.setPort(portParam.getValue()); serverSap.setPort(portParam.getValue());
Runtime.getRuntime().addShutdownHook(new Thread() { Runtime.getRuntime().addShutdownHook(new Thread() {

@ -31,6 +31,7 @@ import org.openmuc.openiec61850.FcModelNode;
import org.openmuc.openiec61850.ModelNode; import org.openmuc.openiec61850.ModelNode;
import org.openmuc.openiec61850.Report; import org.openmuc.openiec61850.Report;
import org.openmuc.openiec61850.SclParseException; import org.openmuc.openiec61850.SclParseException;
import org.openmuc.openiec61850.SclParser;
import org.openmuc.openiec61850.ServerEventListener; import org.openmuc.openiec61850.ServerEventListener;
import org.openmuc.openiec61850.ServerModel; import org.openmuc.openiec61850.ServerModel;
import org.openmuc.openiec61850.ServerSap; import org.openmuc.openiec61850.ServerSap;
@ -77,7 +78,8 @@ public class ClientServerITest extends Thread implements ServerEventListener, Cl
clientAssociation = clientSap.associate(InetAddress.getByName(host), port, null, this); clientAssociation = clientSap.associate(InetAddress.getByName(host), port, null, this);
// ServerModel serverModel = clientAssociation.retrieveModel(); // ServerModel serverModel = clientAssociation.retrieveModel();
ServerModel serverModel = clientAssociation.getModelFromSclFile("src/test/resources/openiec61850sample01.icd"); ServerModel serverModel = SclParser.parse("src/test/resources/openiec61850sample01.icd").get(0);
clientAssociation.setServerModel(serverModel);
getAllBdas(serverModel); getAllBdas(serverModel);
@ -366,10 +368,7 @@ public class ClientServerITest extends Thread implements ServerEventListener, Cl
private void runServer(String sclFilePath, int port) throws SclParseException, IOException { private void runServer(String sclFilePath, int port) throws SclParseException, IOException {
List<ServerSap> serverSaps = null; serverSap = new ServerSap(port, 0, null, SclParser.parse(sclFilePath).get(0), null);
serverSaps = ServerSap.getSapsFromSclFile(sclFilePath);
serverSap = serverSaps.get(0);
serverSap.setPort(port); serverSap.setPort(port);
serverSap.startListening(this); serverSap.startListening(this);
serversServerModel = serverSap.getModelCopy(); serversServerModel = serverSap.getModelCopy();

@ -20,6 +20,7 @@ import org.openmuc.openiec61850.FcModelNode;
import org.openmuc.openiec61850.ModelNode; import org.openmuc.openiec61850.ModelNode;
import org.openmuc.openiec61850.Report; import org.openmuc.openiec61850.Report;
import org.openmuc.openiec61850.SclParseException; import org.openmuc.openiec61850.SclParseException;
import org.openmuc.openiec61850.SclParser;
import org.openmuc.openiec61850.ServerEventListener; import org.openmuc.openiec61850.ServerEventListener;
import org.openmuc.openiec61850.ServerModel; import org.openmuc.openiec61850.ServerModel;
import org.openmuc.openiec61850.ServerSap; import org.openmuc.openiec61850.ServerSap;
@ -60,8 +61,8 @@ public class ClientServerITest2 extends Thread implements ServerEventListener, C
clientAssociation = clientSap.associate(InetAddress.getByName(host), port, null, this); clientAssociation = clientSap.associate(InetAddress.getByName(host), port, null, this);
ServerModel serverModel = clientAssociation.getModelFromSclFile("src/test/resources/testModel2.icd"); ServerModel serverModel = SclParser.parse("src/test/resources/testModel2.icd").get(0);
// ServerModel serverModel = clientAssociation.retrieveModel(); clientAssociation.setServerModel(serverModel);
getAllBdas(serverModel); getAllBdas(serverModel);
@ -86,10 +87,8 @@ public class ClientServerITest2 extends Thread implements ServerEventListener, C
private void runServer(String sclFilePath, int port) throws SclParseException, IOException { private void runServer(String sclFilePath, int port) throws SclParseException, IOException {
List<ServerSap> serverSaps = null; serverSap = new ServerSap(port, 0, null, SclParser.parse(sclFilePath).get(0), null);
serverSaps = ServerSap.getSapsFromSclFile(sclFilePath);
serverSap = serverSaps.get(0);
serverSap.setPort(port); serverSap.setPort(port);
serverSap.startListening(this); serverSap.startListening(this);
serversServerModel = serverSap.getModelCopy(); serversServerModel = serverSap.getModelCopy();

@ -22,6 +22,7 @@ import org.openmuc.openiec61850.Fc;
import org.openmuc.openiec61850.FcModelNode; import org.openmuc.openiec61850.FcModelNode;
import org.openmuc.openiec61850.Report; import org.openmuc.openiec61850.Report;
import org.openmuc.openiec61850.SclParseException; import org.openmuc.openiec61850.SclParseException;
import org.openmuc.openiec61850.SclParser;
import org.openmuc.openiec61850.ServerEventListener; import org.openmuc.openiec61850.ServerEventListener;
import org.openmuc.openiec61850.ServerModel; import org.openmuc.openiec61850.ServerModel;
import org.openmuc.openiec61850.ServerSap; import org.openmuc.openiec61850.ServerSap;
@ -57,14 +58,8 @@ public class ReportingTest implements ClientEventListener {
} }
private void startServer() throws SclParseException, IOException { private void startServer() throws SclParseException, IOException {
final List<ServerSap> sapsFromSclFile = ServerSap.getSapsFromSclFile(ICD_FILE);
if (sapsFromSclFile.isEmpty()) {
throw new IllegalArgumentException("Could not create server sap from '" + ICD_FILE + "'.");
}
this.serverSap = sapsFromSclFile.get(0);
this.serverSap.setPort(PORT); serverSap = new ServerSap(PORT, 0, null, SclParser.parse(ICD_FILE).get(0), null);
this.serverSap.startListening(new ServerEventListener() { this.serverSap.startListening(new ServerEventListener() {

@ -2,7 +2,7 @@ package org.openmuc.openiec61850.integrationtests;
import org.junit.Test; import org.junit.Test;
import org.openmuc.openiec61850.SclParseException; import org.openmuc.openiec61850.SclParseException;
import org.openmuc.openiec61850.ServerSap; import org.openmuc.openiec61850.SclParser;
public class SclTests { public class SclTests {
@ -12,8 +12,8 @@ public class SclTests {
@Test @Test
public void testClientServerCom() throws SclParseException { public void testClientServerCom() throws SclParseException {
ServerSap.getSapsFromSclFile(SCL_FILE_PATH_1); SclParser.parse(SCL_FILE_PATH_1);
ServerSap.getSapsFromSclFile(SCL_FILE_PATH_2); SclParser.parse(SCL_FILE_PATH_2);
} }
} }

Loading…
Cancel
Save