- SCL parser/modeviewer: show unused types

pull/6/head
Michael Zillgith 10 years ago
parent a256248930
commit 50115191cc

@ -87,6 +87,8 @@ public class DataAttribute implements DataModelNode {
if (!(this.sclType instanceof EnumerationType)) if (!(this.sclType instanceof EnumerationType))
throw new SclParserException("Wrong type definition for enumerated data attribute"); throw new SclParserException("Wrong type definition for enumerated data attribute");
this.sclType.setUsed(true);
} }
private void createConstructedAttribute(DataAttributeDefinition daDefinition, TypeDeclarations typeDeclarations) private void createConstructedAttribute(DataAttributeDefinition daDefinition, TypeDeclarations typeDeclarations)
@ -98,6 +100,8 @@ public class DataAttribute implements DataModelNode {
if (!(this.sclType instanceof DataAttributeType)) if (!(this.sclType instanceof DataAttributeType))
throw new SclParserException("Wrong type definition for constructed data attribute"); throw new SclParserException("Wrong type definition for constructed data attribute");
this.sclType.setUsed(true);
DataAttributeType dataAttributeType = (DataAttributeType) this.sclType; DataAttributeType dataAttributeType = (DataAttributeType) this.sclType;

@ -55,6 +55,9 @@ public class DataObject implements DataModelNode {
if (sclType == null) if (sclType == null)
throw new SclParserException("type declaration missing for data object."); throw new SclParserException("type declaration missing for data object.");
/* mark type as used */
sclType.setUsed(true);
createDataAttributes(typeDeclarations, sclType); createDataAttributes(typeDeclarations, sclType);

@ -82,6 +82,9 @@ public class LogicalNode implements DataModelNode {
dataObjects = new LinkedList<DataObject>(); dataObjects = new LinkedList<DataObject>();
LogicalNodeType type = (LogicalNodeType) sclType; LogicalNodeType type = (LogicalNodeType) sclType;
/* mark type as used */
type.setUsed(true);
List<DataObjectDefinition> doDefinitions = type.getDataObjectDefinitions(); List<DataObjectDefinition> doDefinitions = type.getDataObjectDefinitions();

@ -30,6 +30,7 @@ public abstract class SclType {
private String id = null; private String id = null;
private String description; private String description;
private boolean isUsed = false;
public SclType(Node xmlNode) throws SclParserException { public SclType(Node xmlNode) throws SclParserException {
this.id = ParserUtils.parseAttribute(xmlNode, "id"); this.id = ParserUtils.parseAttribute(xmlNode, "id");
@ -51,4 +52,12 @@ public abstract class SclType {
public String getDesc() { public String getDesc() {
return description; return description;
} }
public void setUsed(boolean isUsed) {
this.isUsed = isUsed;
}
public boolean isUsed() {
return this.isUsed;
}
} }

@ -26,7 +26,7 @@ import com.libiec61850.scl.types.TypeDeclarations;
public class ModelViewer { public class ModelViewer {
private static void showTypes(InputStream stream, String icdFile, PrintStream output, String iedName, String accessPointName) private static void showTypes(InputStream stream, String icdFile, PrintStream output, String iedName, String accessPointName, boolean unusedOnly)
throws SclParserException { throws SclParserException {
SclParser sclParser = new SclParser(stream, false); SclParser sclParser = new SclParser(stream, false);
@ -34,6 +34,12 @@ public class ModelViewer {
TypeDeclarations typeDecl = sclParser.getTypeDeclarations(); TypeDeclarations typeDecl = sclParser.getTypeDeclarations();
for (SclType type : typeDecl.getTypeDeclarations()) { for (SclType type : typeDecl.getTypeDeclarations()) {
if (unusedOnly) {
if (type.isUsed() == true)
continue;
}
output.print(type.getId()); output.print(type.getId());
if (type.getClass() == LogicalNodeType.class) if (type.getClass() == LogicalNodeType.class)
@ -45,6 +51,10 @@ public class ModelViewer {
else if (type.getClass() == EnumerationType.class) else if (type.getClass() == EnumerationType.class)
output.print(" : Enumeration"); output.print(" : Enumeration");
if (!unusedOnly)
if (type.isUsed() == false)
System.out.print(" UNUSED TYPE!");
output.println(); output.println();
} }
} }
@ -175,6 +185,7 @@ public class ModelViewer {
System.out.println(" -ied select IED"); System.out.println(" -ied select IED");
System.out.println(" -ap select AP"); System.out.println(" -ap select AP");
System.out.println(" -t print type list"); System.out.println(" -t print type list");
System.out.println(" -u print list of unused types");
System.out.println(" -s print IED device model structure"); System.out.println(" -s print IED device model structure");
System.out.println(" -a print list of data attributes (object references)"); System.out.println(" -a print list of data attributes (object references)");
System.exit(1); System.exit(1);
@ -188,6 +199,7 @@ public class ModelViewer {
String iedName = null; String iedName = null;
boolean printTypeList = false; boolean printTypeList = false;
boolean printUnusedTypes = false;
boolean printModelStructure = false; boolean printModelStructure = false;
boolean printDataAttribtues = false; boolean printDataAttribtues = false;
@ -225,6 +237,12 @@ public class ModelViewer {
i++; i++;
}
else if (args[i].equals("-u")) {
printUnusedTypes = true;
i++;
} }
else { else {
outputStream = new PrintStream(new FileOutputStream(new File(args[i]))); outputStream = new PrintStream(new FileOutputStream(new File(args[i])));
@ -237,7 +255,10 @@ public class ModelViewer {
try { try {
if (printTypeList) if (printTypeList)
showTypes(stream, icdFile, outputStream, iedName, accessPointName); showTypes(stream, icdFile, outputStream, iedName, accessPointName, false);
if (printUnusedTypes)
showTypes(stream, icdFile, outputStream, iedName, accessPointName, true);
if (printModelStructure) if (printModelStructure)
printModelStructure(stream, icdFile, outputStream, iedName, accessPointName); printModelStructure(stream, icdFile, outputStream, iedName, accessPointName);

Loading…
Cancel
Save