- Add ConnectionParam.java to extract the connection parameters under ConnectedAP tag in the CID/SCD file while parsing it.

- Add the ConnectionParam to the ServerModel.java to be retrieved after parsing the CID/SCD file.
- Enhance the SclParser.java to parse the ConnectionParam under the ConnectedAP tag.
- Optimize imports in the SclParser.java
- Remove the unnecessary .toStrings in the SclParser.java
- Replace the If-else with switch case in the SclParser.java
pull/30/head
Abdelaziz Said 4 years ago
parent f9f34cde0c
commit c8f49bdc47

@ -0,0 +1,148 @@
package com.beanit.iec61850bean;
import java.util.Objects;
public class ConnectionParam {
private String iedName;
private String IP;
private String IP_SUBNET;
private String OSI_AP_Title;
private String OSI_AE_Qualifier;
private String OSI_PSEL;
private String OSI_SSEL;
private String OSI_TSEL;
private String IP_GATEWAY;
private String S_Profile;
private String MAC_Address;
public String getIedName() {
return iedName;
}
public void setIedName(String iedName) {
this.iedName = iedName;
}
public String getIP() {
return IP;
}
public void setIP(String IP) {
this.IP = IP;
}
public String getIP_SUBNET() {
return IP_SUBNET;
}
public void setIP_SUBNET(String IP_SUBNET) {
this.IP_SUBNET = IP_SUBNET;
}
public String getOSI_AP_Title() {
return OSI_AP_Title;
}
public void setOSI_AP_Title(String OSI_AP_Title) {
this.OSI_AP_Title = OSI_AP_Title;
}
public String getOSI_AE_Qualifier() {
return OSI_AE_Qualifier;
}
public void setOSI_AE_Qualifier(String OSI_AE_Qualifier) {
this.OSI_AE_Qualifier = OSI_AE_Qualifier;
}
public String getOSI_PSEL() {
return OSI_PSEL;
}
public void setOSI_PSEL(String OSI_PSEL) {
this.OSI_PSEL = OSI_PSEL;
}
public String getOSI_SSEL() {
return OSI_SSEL;
}
public void setOSI_SSEL(String OSI_SSEL) {
this.OSI_SSEL = OSI_SSEL;
}
public String getOSI_TSEL() {
return OSI_TSEL;
}
public void setOSI_TSEL(String OSI_TSEL) {
this.OSI_TSEL = OSI_TSEL;
}
public String getIP_GATEWAY() {
return IP_GATEWAY;
}
public void setIP_GATEWAY(String IP_GATEWAY) {
this.IP_GATEWAY = IP_GATEWAY;
}
public String getS_Profile() {
return S_Profile;
}
public void setS_Profile(String s_Profile) {
S_Profile = s_Profile;
}
public String getMAC_Address() {
return MAC_Address;
}
public void setMAC_Address(String MAC_Address) {
this.MAC_Address = MAC_Address;
}
@Override
public String toString() {
return "iedName = " + iedName + '\n' +
"IP = " + IP + '\n' +
"IP_SUBNET = " + IP_SUBNET + '\n' +
"OSI_AP_Title = " + OSI_AP_Title + '\n' +
"OSI_AE_Qualifier = " + OSI_AE_Qualifier + '\n' +
"OSI_PSEL = " + OSI_PSEL + '\n' +
"OSI_SSEL = " + OSI_SSEL + '\n' +
"OSI_TSEL = " + OSI_TSEL + '\n' +
"IP_GATEWAY = " + IP_GATEWAY + '\n' +
"S_Profile = " + S_Profile + '\n' +
"MAC-Address = " + MAC_Address
;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
ConnectionParam that = (ConnectionParam) o;
return iedName.equals(that.iedName) &&
IP.equals(that.IP) &&
Objects.equals(IP_SUBNET, that.IP_SUBNET) &&
Objects.equals(OSI_AP_Title, that.OSI_AP_Title) &&
Objects.equals(OSI_AE_Qualifier, that.OSI_AE_Qualifier) &&
Objects.equals(OSI_PSEL, that.OSI_PSEL) &&
Objects.equals(OSI_SSEL, that.OSI_SSEL) &&
Objects.equals(OSI_TSEL, that.OSI_TSEL) &&
Objects.equals(IP_GATEWAY, that.IP_GATEWAY) &&
Objects.equals(S_Profile, that.S_Profile) &&
Objects.equals(MAC_Address, that.MAC_Address);
}
@Override
public int hashCode() {
return Objects.hash(iedName, IP, IP_SUBNET, OSI_AP_Title, OSI_AE_Qualifier, OSI_PSEL, OSI_SSEL,
OSI_TSEL, IP_GATEWAY, S_Profile, MAC_Address);
}
}

@ -1,3 +1,4 @@
/* /*
* Copyright 2011 The IEC61850bean Authors * Copyright 2011 The IEC61850bean Authors
* *
@ -13,34 +14,20 @@
*/ */
package com.beanit.iec61850bean; package com.beanit.iec61850bean;
import static java.nio.charset.StandardCharsets.UTF_8; import com.beanit.iec61850bean.internal.scl.*;
import com.beanit.iec61850bean.internal.scl.AbstractDataAttribute;
import com.beanit.iec61850bean.internal.scl.Bda;
import com.beanit.iec61850bean.internal.scl.Da;
import com.beanit.iec61850bean.internal.scl.DaType;
import com.beanit.iec61850bean.internal.scl.Do;
import com.beanit.iec61850bean.internal.scl.DoType;
import com.beanit.iec61850bean.internal.scl.EnumType;
import com.beanit.iec61850bean.internal.scl.EnumVal;
import com.beanit.iec61850bean.internal.scl.LnSubDef;
import com.beanit.iec61850bean.internal.scl.LnType;
import com.beanit.iec61850bean.internal.scl.Sdo;
import com.beanit.iec61850bean.internal.scl.TypeDefinitions;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import javax.xml.parsers.DocumentBuilderFactory;
import org.w3c.dom.Document; import org.w3c.dom.Document;
import org.w3c.dom.NamedNodeMap; 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;
import javax.xml.parsers.DocumentBuilderFactory;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.InputStream;
import java.util.*;
import static java.nio.charset.StandardCharsets.UTF_8;
public class SclParser { public class SclParser {
private final Map<String, DataSet> dataSetsMap = new HashMap<>(); private final Map<String, DataSet> dataSetsMap = new HashMap<>();
@ -48,10 +35,15 @@ public class SclParser {
private TypeDefinitions typeDefinitions; private TypeDefinitions typeDefinitions;
private Document doc; private Document doc;
private String iedName; private String iedName;
private List<ServerModel> serverModels = new ArrayList<>(); private final List<ServerModel> serverModels = new ArrayList<>();
private boolean useResvTmsAttributes = false; private boolean useResvTmsAttributes = false;
private SclParser() {} private String iedConnectedAP;
ConnectionParam connectionParm;
private final Map<String, ConnectionParam> iedConnectionMap = new HashMap<>();
private SclParser() {
}
public static List<ServerModel> parse(InputStream is) throws SclParseException { public static List<ServerModel> parse(InputStream is) throws SclParseException {
SclParser sclParser = new SclParser(); SclParser sclParser = new SclParser();
@ -88,6 +80,39 @@ public class SclParser {
readTypeDefinitions(); readTypeDefinitions();
NodeList connectedAPs = doc.getElementsByTagName("ConnectedAP");
for (int zz = 0; zz < connectedAPs.getLength(); zz++) {
Node connectedAP = connectedAPs.item(zz);
Node attributeName = connectedAP.getAttributes().getNamedItem("iedName");
iedConnectedAP = attributeName.getNodeValue();
connectionParm = new ConnectionParam();
if ((iedConnectedAP == null) || (iedConnectedAP.length() == 0)) {
throw new SclParseException("ConnectedAP must has a name");
}
NodeList elementsConnectedAP = connectedAP.getChildNodes();
for (int yy = 0; yy < elementsConnectedAP.getLength(); yy++) {
Node elementConnectedAP = elementsConnectedAP.item(yy);
String nodeAddress = elementConnectedAP.getNodeName();
if (nodeAddress.equals("Address")) {
NodeList address = elementConnectedAP.getChildNodes();
for (int ii = 0; ii < address.getLength(); ii++) {
Node elementAddress = address.item(ii);
String nodeCheck = elementAddress.getNodeName();
if ("P".equals(nodeCheck)) {
setConnectionParm(elementAddress);
}
}
connectionParm.setIedName(iedConnectedAP);
iedConnectionMap.put(iedConnectedAP, connectionParm);
}
}
}
NodeList iedList = doc.getElementsByTagName("IED"); NodeList iedList = doc.getElementsByTagName("IED");
if (iedList.getLength() == 0) { if (iedList.getLength() == 0) {
throw new SclParseException("No IED section found!"); throw new SclParseException("No IED section found!");
@ -131,6 +156,48 @@ public class SclParser {
} }
} }
public void setConnectionParm(Node P) {
String nodeValue;
P.getAttributes().getNamedItem("type");
String typeValue = P.getAttributes().getNamedItem("type").getNodeValue();
nodeValue = P.getTextContent();
switch (typeValue) {
case "IP":
connectionParm.setIP(nodeValue);
break;
case "IP-SUBNET":
connectionParm.setIP_SUBNET(nodeValue);
break;
case "OSI-AP-Title":
connectionParm.setOSI_AP_Title(nodeValue);
break;
case "OSI-AE-Qualifier":
connectionParm.setOSI_AE_Qualifier(nodeValue);
break;
case "OSI-PSEL":
connectionParm.setOSI_PSEL(nodeValue);
break;
case "OSI-SSEL":
connectionParm.setOSI_SSEL(nodeValue);
break;
case "OSI-TSEL":
connectionParm.setOSI_TSEL(nodeValue);
break;
case "IP-GATEWAY":
connectionParm.setIP_GATEWAY(nodeValue);
break;
case "S-Profile":
connectionParm.setS_Profile(nodeValue);
break;
case "MAC-Address":
connectionParm.setMAC_Address(nodeValue);
break;
}
}
private void readTypeDefinitions() throws SclParseException { private void readTypeDefinitions() throws SclParseException {
NodeList dttSections = doc.getElementsByTagName("DataTypeTemplates"); NodeList dttSections = doc.getElementsByTagName("DataTypeTemplates");
@ -148,14 +215,19 @@ public class SclParser {
String nodeName = element.getNodeName(); String nodeName = element.getNodeName();
if (nodeName.equals("LNodeType")) { switch (nodeName) {
case "LNodeType":
typeDefinitions.putLNodeType(new LnType(element)); typeDefinitions.putLNodeType(new LnType(element));
} else if (nodeName.equals("DOType")) { break;
case "DOType":
typeDefinitions.putDOType(new DoType(element)); typeDefinitions.putDOType(new DoType(element));
} else if (nodeName.equals("DAType")) { break;
case "DAType":
typeDefinitions.putDAType(new DaType(element)); typeDefinitions.putDAType(new DaType(element));
} else if (nodeName.equals("EnumType")) { break;
case "EnumType":
typeDefinitions.putEnumType(new EnumType(element)); typeDefinitions.putEnumType(new EnumType(element));
break;
} }
} }
} }
@ -212,6 +284,8 @@ public class SclParser {
dataSetDefs.clear(); dataSetDefs.clear();
serverModel.setConnectionParam(iedConnectionMap.get(iedName));
return serverModel; return serverModel;
} }
@ -378,25 +452,33 @@ public class SclParser {
Node node = attributes.item(j); Node node = attributes.item(j);
String nodeName = node.getNodeName(); String nodeName = node.getNodeName();
if (nodeName.equals("ldInst")) { switch (nodeName) {
case "ldInst":
ldInst = node.getNodeValue(); ldInst = node.getNodeValue();
} else if (nodeName.equals("lnInst")) { break;
case "lnInst":
lnInst = node.getNodeValue(); lnInst = node.getNodeValue();
} else if (nodeName.equals("lnClass")) { break;
case "lnClass":
lnClass = node.getNodeValue(); lnClass = node.getNodeValue();
} else if (nodeName.equals("prefix")) { break;
case "prefix":
prefix = node.getNodeValue(); prefix = node.getNodeValue();
} else if (nodeName.equals("doName")) { break;
case "doName":
doName = node.getNodeValue(); doName = node.getNodeValue();
} else if (nodeName.equals("daName")) { break;
case "daName":
if (!node.getNodeValue().isEmpty()) { if (!node.getNodeValue().isEmpty()) {
daName = "." + node.getNodeValue(); daName = "." + node.getNodeValue();
} }
} else if (nodeName.equals("fc")) { break;
case "fc":
fc = Fc.fromString(node.getNodeValue()); fc = Fc.fromString(node.getNodeValue());
if (fc == null) { if (fc == null) {
throw new SclParseException("FCDA contains invalid FC: " + node.getNodeValue()); throw new SclParseException("FCDA contains invalid FC: " + node.getNodeValue());
} }
break;
} }
} }
@ -588,7 +670,7 @@ public class SclParser {
BdaVisibleString rptId = BdaVisibleString rptId =
new BdaVisibleString( new BdaVisibleString(
new ObjectReference(reportObjRef.toString() + ".RptID"), fc, "", 129, false, false); new ObjectReference(reportObjRef + ".RptID"), fc, "", 129, false, false);
attribute = rcbNodeAttributes.getNamedItem("rptID"); attribute = rcbNodeAttributes.getNamedItem("rptID");
if (attribute != null) { if (attribute != null) {
rptId.setValue(attribute.getNodeValue().getBytes(UTF_8)); rptId.setValue(attribute.getNodeValue().getBytes(UTF_8));
@ -600,17 +682,17 @@ public class SclParser {
children.add( children.add(
new BdaBoolean( new BdaBoolean(
new ObjectReference(reportObjRef.toString() + ".RptEna"), fc, "", false, false)); new ObjectReference(reportObjRef + ".RptEna"), fc, "", false, false));
if (fc == Fc.RP) { if (fc == Fc.RP) {
children.add( children.add(
new BdaBoolean( new BdaBoolean(
new ObjectReference(reportObjRef.toString() + ".Resv"), fc, "", false, false)); new ObjectReference(reportObjRef + ".Resv"), fc, "", false, false));
} }
BdaVisibleString datSet = BdaVisibleString datSet =
new BdaVisibleString( new BdaVisibleString(
new ObjectReference(reportObjRef.toString() + ".DatSet"), fc, "", 129, false, false); new ObjectReference(reportObjRef + ".DatSet"), fc, "", 129, false, false);
attribute = xmlNode.getAttributes().getNamedItem("datSet"); attribute = xmlNode.getAttributes().getNamedItem("datSet");
if (attribute != null) { if (attribute != null) {
@ -622,7 +704,7 @@ public class SclParser {
BdaInt32U confRef = BdaInt32U confRef =
new BdaInt32U( new BdaInt32U(
new ObjectReference(reportObjRef.toString() + ".ConfRev"), fc, "", false, false); new ObjectReference(reportObjRef + ".ConfRev"), fc, "", false, false);
attribute = xmlNode.getAttributes().getNamedItem("confRev"); attribute = xmlNode.getAttributes().getNamedItem("confRev");
if (attribute == null) { if (attribute == null) {
throw new SclParseException( throw new SclParseException(
@ -635,7 +717,7 @@ public class SclParser {
BdaInt32U bufTm = BdaInt32U bufTm =
new BdaInt32U( new BdaInt32U(
new ObjectReference(reportObjRef.toString() + ".BufTm"), fc, "", false, false); new ObjectReference(reportObjRef + ".BufTm"), fc, "", false, false);
attribute = xmlNode.getAttributes().getNamedItem("bufTime"); attribute = xmlNode.getAttributes().getNamedItem("bufTime");
if (attribute != null) { if (attribute != null) {
bufTm.setValue(Long.parseLong(attribute.getNodeValue())); bufTm.setValue(Long.parseLong(attribute.getNodeValue()));
@ -644,13 +726,13 @@ public class SclParser {
children.add( children.add(
new BdaInt8U( new BdaInt8U(
new ObjectReference(reportObjRef.toString() + ".SqNum"), fc, "", false, false)); new ObjectReference(reportObjRef + ".SqNum"), fc, "", false, false));
children.add(trigOps); children.add(trigOps);
BdaInt32U intgPd = BdaInt32U intgPd =
new BdaInt32U( new BdaInt32U(
new ObjectReference(reportObjRef.toString() + ".IntgPd"), fc, "", false, false); new ObjectReference(reportObjRef + ".IntgPd"), fc, "", false, false);
attribute = xmlNode.getAttributes().getNamedItem("intgPd"); attribute = xmlNode.getAttributes().getNamedItem("intgPd");
if (attribute != null) { if (attribute != null) {
intgPd.setValue(Long.parseLong(attribute.getNodeValue())); intgPd.setValue(Long.parseLong(attribute.getNodeValue()));
@ -659,19 +741,19 @@ public class SclParser {
children.add( children.add(
new BdaBoolean( new BdaBoolean(
new ObjectReference(reportObjRef.toString() + ".GI"), fc, "", false, false)); new ObjectReference(reportObjRef + ".GI"), fc, "", false, false));
Rcb rcb = null; Rcb rcb;
if (fc == Fc.BR) { if (fc == Fc.BR) {
children.add( children.add(
new BdaBoolean( new BdaBoolean(
new ObjectReference(reportObjRef.toString() + ".PurgeBuf"), fc, "", false, false)); new ObjectReference(reportObjRef + ".PurgeBuf"), fc, "", false, false));
children.add( children.add(
new BdaOctetString( new BdaOctetString(
new ObjectReference(reportObjRef.toString() + ".EntryID"), new ObjectReference(reportObjRef + ".EntryID"),
fc, fc,
"", "",
8, 8,
@ -680,7 +762,7 @@ public class SclParser {
children.add( children.add(
new BdaEntryTime( new BdaEntryTime(
new ObjectReference(reportObjRef.toString() + ".TimeOfEntry"), new ObjectReference(reportObjRef + ".TimeOfEntry"),
fc, fc,
"", "",
false, false,
@ -689,19 +771,19 @@ public class SclParser {
if (useResvTmsAttributes) { if (useResvTmsAttributes) {
children.add( children.add(
new BdaInt16( new BdaInt16(
new ObjectReference(reportObjRef.toString() + ".ResvTms"), fc, "", false, false)); new ObjectReference(reportObjRef + ".ResvTms"), fc, "", false, false));
} }
children.add( children.add(
new BdaOctetString( new BdaOctetString(
new ObjectReference(reportObjRef.toString() + ".Owner"), fc, "", 64, false, false)); new ObjectReference(reportObjRef + ".Owner"), fc, "", 64, false, false));
rcb = new Brcb(reportObjRef, children); rcb = new Brcb(reportObjRef, children);
} else { } else {
children.add( children.add(
new BdaOctetString( new BdaOctetString(
new ObjectReference(reportObjRef.toString() + ".Owner"), fc, "", 64, false, false)); new ObjectReference(reportObjRef + ".Owner"), fc, "", 64, false, false));
rcb = new Urcb(reportObjRef, children); rcb = new Urcb(reportObjRef, children);
} }
@ -821,7 +903,9 @@ public class SclParser {
return new Array(new ObjectReference(ref), fc, arrayItems); return new Array(new ObjectReference(ref), fc, arrayItems);
} }
/** returns a ConstructedDataAttribute or BasicDataAttribute */ /**
* returns a ConstructedDataAttribute or BasicDataAttribute
*/
private FcModelNode createDataAttribute( private FcModelNode createDataAttribute(
String ref, String ref,
Fc fc, Fc fc,

@ -17,13 +17,8 @@ import com.beanit.iec61850bean.internal.mms.asn1.AlternateAccessSelection;
import com.beanit.iec61850bean.internal.mms.asn1.ObjectName; import com.beanit.iec61850bean.internal.mms.asn1.ObjectName;
import com.beanit.iec61850bean.internal.mms.asn1.ObjectName.DomainSpecific; import com.beanit.iec61850bean.internal.mms.asn1.ObjectName.DomainSpecific;
import com.beanit.iec61850bean.internal.mms.asn1.VariableDefs; import com.beanit.iec61850bean.internal.mms.asn1.VariableDefs;
import java.util.ArrayList;
import java.util.Collection; import java.util.*;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
public final class ServerModel extends ModelNode { public final class ServerModel extends ModelNode {
@ -32,6 +27,8 @@ public final class ServerModel extends ModelNode {
private final Map<String, Urcb> urcbs = new HashMap<>(); private final Map<String, Urcb> urcbs = new HashMap<>();
private final Map<String, Brcb> brcbs = new HashMap<>(); private final Map<String, Brcb> brcbs = new HashMap<>();
private ConnectionParam connectionParam;
public ServerModel(List<LogicalDevice> logicalDevices, Collection<DataSet> dataSets) { public ServerModel(List<LogicalDevice> logicalDevices, Collection<DataSet> dataSets) {
children = new LinkedHashMap<>(); children = new LinkedHashMap<>();
objectReference = null; objectReference = null;
@ -397,4 +394,12 @@ public final class ServerModel extends ModelNode {
((Array) modelNode).getChild(altAccIt.getSelectAccess().getIndex().intValue()); ((Array) modelNode).getChild(altAccIt.getSelectAccess().getIndex().intValue());
} }
} }
public ConnectionParam getConnectionParam() {
return connectionParam;
}
public void setConnectionParam(ConnectionParam connectionParam) {
this.connectionParam = connectionParam;
}
} }
Loading…
Cancel
Save