-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
TerminalRefXml with writer param (#815)
Signed-off-by: RALAMBOTIANA MIORA <miora.ralambotiana@rte-france.com> Signed-off-by: Mathieu BAGUE <mathieu.bague@rte-france.com>
- Loading branch information
Showing
13 changed files
with
298 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
iidm/iidm-test/src/main/java/com/powsybl/iidm/network/test/TerminalMockExt.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/** | ||
* Copyright (c) 2019, RTE (http://www.rte-france.com) | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
*/ | ||
package com.powsybl.iidm.network.test; | ||
|
||
import com.powsybl.commons.extensions.AbstractExtension; | ||
import com.powsybl.iidm.network.Load; | ||
import com.powsybl.iidm.network.Terminal; | ||
|
||
import java.util.Objects; | ||
|
||
/** | ||
* @author Miora Ralambotiana <miora.ralambotiana at rte-france.com> | ||
*/ | ||
public class TerminalMockExt extends AbstractExtension<Load> { | ||
|
||
private Terminal terminal; | ||
|
||
public TerminalMockExt(Load load) { | ||
super(load); | ||
terminal = load.getTerminal(); | ||
} | ||
|
||
@Override | ||
public String getName() { | ||
return "terminalMock"; | ||
} | ||
|
||
public Terminal getTerminal() { | ||
return terminal; | ||
} | ||
|
||
public TerminalMockExt setTerminal(Terminal terminal) { | ||
this.terminal = Objects.requireNonNull(terminal); | ||
return this; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
86 changes: 86 additions & 0 deletions
86
iidm/iidm-xml-converter/src/test/java/com/powsybl/iidm/xml/TerminalMockXmlSerializer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
/** | ||
* Copyright (c) 2019, RTE (http://www.rte-france.com) | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
*/ | ||
package com.powsybl.iidm.xml; | ||
|
||
import com.google.auto.service.AutoService; | ||
import com.powsybl.commons.extensions.ExtensionXmlSerializer; | ||
import com.powsybl.commons.xml.XmlReaderContext; | ||
import com.powsybl.commons.xml.XmlUtil; | ||
import com.powsybl.commons.xml.XmlWriterContext; | ||
import com.powsybl.iidm.network.Load; | ||
import com.powsybl.iidm.network.Network; | ||
import com.powsybl.iidm.network.test.TerminalMockExt; | ||
|
||
import javax.xml.stream.XMLStreamException; | ||
import java.io.InputStream; | ||
|
||
/** | ||
* @author Miora Ralambotiana <miora.ralambotiana at rte-france.com> | ||
*/ | ||
@AutoService(ExtensionXmlSerializer.class) | ||
public class TerminalMockXmlSerializer implements ExtensionXmlSerializer<Load, TerminalMockExt> { | ||
|
||
@Override | ||
public boolean hasSubElements() { | ||
return true; | ||
} | ||
|
||
@Override | ||
public InputStream getXsdAsStream() { | ||
return getClass().getResourceAsStream("/xsd/terminalMock.xsd"); | ||
} | ||
|
||
@Override | ||
public String getNamespaceUri() { | ||
return "http://www.itesla_project.eu/schema/iidm/ext/terminal_mock/1_0"; | ||
} | ||
|
||
@Override | ||
public String getNamespacePrefix() { | ||
return "mock"; | ||
} | ||
|
||
@Override | ||
public void write(TerminalMockExt extension, XmlWriterContext context) throws XMLStreamException { | ||
NetworkXmlWriterContext networkContext = (NetworkXmlWriterContext) context; | ||
TerminalRefXml.writeTerminalRef(extension.getTerminal(), networkContext, getNamespaceUri(), "terminal", context.getExtensionsWriter()); | ||
} | ||
|
||
@Override | ||
public TerminalMockExt read(Load extendable, XmlReaderContext context) throws XMLStreamException { | ||
NetworkXmlReaderContext networkContext = (NetworkXmlReaderContext) context; | ||
TerminalMockExt terminalMockExt = new TerminalMockExt(extendable); | ||
XmlUtil.readUntilEndElement(getExtensionName(), networkContext.getReader(), () -> { | ||
if (networkContext.getReader().getLocalName().equals("terminal")) { | ||
String id = networkContext.getAnonymizer().deanonymizeString(networkContext.getReader().getAttributeValue(null, "id")); | ||
String side = networkContext.getReader().getAttributeValue(null, "side"); | ||
networkContext.getEndTasks().add(() -> { | ||
Network network = extendable.getTerminal().getVoltageLevel().getSubstation().getNetwork(); | ||
terminalMockExt.setTerminal(TerminalRefXml.readTerminalRef(network, id, side)); | ||
}); | ||
} else { | ||
throw new AssertionError("Unexpected element: " + networkContext.getReader().getLocalName()); | ||
} | ||
}); | ||
return terminalMockExt; | ||
} | ||
|
||
@Override | ||
public String getExtensionName() { | ||
return "terminalMock"; | ||
} | ||
|
||
@Override | ||
public String getCategoryName() { | ||
return "network"; | ||
} | ||
|
||
@Override | ||
public Class<? super TerminalMockExt> getExtensionClass() { | ||
return TerminalMockExt.class; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.