Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactoring of XML extensions #1052

Merged
merged 2 commits into from
Dec 5, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,39 +7,25 @@
package com.powsybl.iidm.network.extensions;

import com.google.auto.service.AutoService;
import com.powsybl.commons.extensions.AbstractExtensionXmlSerializer;
import com.powsybl.commons.extensions.ExtensionXmlSerializer;
miovd marked this conversation as resolved.
Show resolved Hide resolved
import com.powsybl.commons.xml.XmlReaderContext;
import com.powsybl.commons.xml.XmlUtil;
import com.powsybl.commons.xml.XmlWriterContext;
import com.powsybl.iidm.network.Generator;

import javax.xml.stream.XMLStreamException;
import java.io.InputStream;

/**
* @author Miora Ralambotiana <miora.ralambotiana at rte-france.com>
*/
@AutoService(ExtensionXmlSerializer.class)
public class CoordinatedReactiveControlXmlSerializer implements ExtensionXmlSerializer<Generator, CoordinatedReactiveControl> {
public class CoordinatedReactiveControlXmlSerializer extends AbstractExtensionXmlSerializer<Generator, CoordinatedReactiveControl> {

@Override
public boolean hasSubElements() {
return false;
}

@Override
public InputStream getXsdAsStream() {
return getClass().getResourceAsStream("/xsd/coordinatedReactiveControl.xsd");
}

@Override
public String getNamespaceUri() {
return "http://www.powsybl.org/schema/iidm/ext/coordinated_reactive_control/1_0";
}

@Override
public String getNamespacePrefix() {
return "crc";
public CoordinatedReactiveControlXmlSerializer() {
super("coordinatedReactiveControl", "network", CoordinatedReactiveControl.class,
false, "coordinatedReactiveControl.xsd",
"http://www.powsybl.org/schema/iidm/ext/coordinated_reactive_control/1_0", "crc");
}

@Override
Expand All @@ -48,23 +34,8 @@ public void write(CoordinatedReactiveControl extension, XmlWriterContext context
}

@Override
public CoordinatedReactiveControl read(Generator extendable, XmlReaderContext context) throws XMLStreamException {
miovd marked this conversation as resolved.
Show resolved Hide resolved
public CoordinatedReactiveControl read(Generator extendable, XmlReaderContext context) {
double qPercent = XmlUtil.readDoubleAttribute(context.getReader(), "qPercent");
return new CoordinatedReactiveControl(extendable, qPercent);
}

@Override
public String getExtensionName() {
return "coordinatedReactiveControl";
}

@Override
public String getCategoryName() {
return "network";
}

@Override
public Class<? super CoordinatedReactiveControl> getExtensionClass() {
return CoordinatedReactiveControl.class;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,41 +7,27 @@
package com.powsybl.iidm.network.extensions;

import com.google.auto.service.AutoService;
import com.powsybl.commons.extensions.AbstractExtensionXmlSerializer;
import com.powsybl.commons.extensions.ExtensionXmlSerializer;
miovd marked this conversation as resolved.
Show resolved Hide resolved
import com.powsybl.commons.xml.XmlReaderContext;
import com.powsybl.commons.xml.XmlUtil;
import com.powsybl.commons.xml.XmlWriterContext;
import com.powsybl.iidm.network.ThreeWindingsTransformer;

import java.io.InputStream;

import javax.xml.stream.XMLStreamException;

/**
* @author José Antonio Marqués <marquesja at aia.es>
*/
@AutoService(ExtensionXmlSerializer.class)
public class ThreeWindingsTransformerPhaseAngleClockXmlSerializer
implements ExtensionXmlSerializer<ThreeWindingsTransformer, ThreeWindingsTransformerPhaseAngleClock> {

@Override
public boolean hasSubElements() {
return false;
}

@Override
public InputStream getXsdAsStream() {
return getClass().getResourceAsStream("/xsd/threeWindingsTransformerPhaseAngleClock.xsd");
}

@Override
public String getNamespaceUri() {
return "http://www.powsybl.org/schema/iidm/ext/three_windings_transformer_phase_angle_clock/1_0";
}
extends AbstractExtensionXmlSerializer<ThreeWindingsTransformer, ThreeWindingsTransformerPhaseAngleClock> {

@Override
public String getNamespacePrefix() {
return "threewtpac";
public ThreeWindingsTransformerPhaseAngleClockXmlSerializer() {
super("threeWindingsTransformerPhaseAngleClock", "network", ThreeWindingsTransformerPhaseAngleClock.class,
false, "threeWindingsTransformerPhaseAngleClock.xsd",
"http://www.powsybl.org/schema/iidm/ext/three_windings_transformer_phase_angle_clock/1_0",
"threewtpac");
}

@Override
Expand All @@ -51,24 +37,9 @@ public void write(ThreeWindingsTransformerPhaseAngleClock extension, XmlWriterCo
}

@Override
public ThreeWindingsTransformerPhaseAngleClock read(ThreeWindingsTransformer extendable, XmlReaderContext context) throws XMLStreamException {
public ThreeWindingsTransformerPhaseAngleClock read(ThreeWindingsTransformer extendable, XmlReaderContext context) {
int phaseAngleClockLeg2 = XmlUtil.readOptionalIntegerAttribute(context.getReader(), "phaseAngleClockLeg2", 0);
int phaseAngleClockLeg3 = XmlUtil.readOptionalIntegerAttribute(context.getReader(), "phaseAngleClockLeg3", 0);
return new ThreeWindingsTransformerPhaseAngleClock(extendable, phaseAngleClockLeg2, phaseAngleClockLeg3);
}

@Override
public String getExtensionName() {
return "threeWindingsTransformerPhaseAngleClock";
}

@Override
public String getCategoryName() {
return "network";
}

@Override
public Class<? super ThreeWindingsTransformerPhaseAngleClock> getExtensionClass() {
return ThreeWindingsTransformerPhaseAngleClock.class;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,41 +7,26 @@
package com.powsybl.iidm.network.extensions;

import com.google.auto.service.AutoService;
import com.powsybl.commons.extensions.AbstractExtensionXmlSerializer;
import com.powsybl.commons.extensions.ExtensionXmlSerializer;
miovd marked this conversation as resolved.
Show resolved Hide resolved
import com.powsybl.commons.xml.XmlReaderContext;
import com.powsybl.commons.xml.XmlUtil;
import com.powsybl.commons.xml.XmlWriterContext;
import com.powsybl.iidm.network.TwoWindingsTransformer;

import java.io.InputStream;

import javax.xml.stream.XMLStreamException;

/**
* @author José Antonio Marqués <marquesja at aia.es>
*/
@AutoService(ExtensionXmlSerializer.class)
public class TwoWindingsTransformerPhaseAngleClockXmlSerializer
implements ExtensionXmlSerializer<TwoWindingsTransformer, TwoWindingsTransformerPhaseAngleClock> {

@Override
public boolean hasSubElements() {
return false;
}

@Override
public InputStream getXsdAsStream() {
return getClass().getResourceAsStream("/xsd/twoWindingsTransformerPhaseAngleClock.xsd");
}

@Override
public String getNamespaceUri() {
return "http://www.powsybl.org/schema/iidm/ext/two_windings_transformer_phase_angle_clock/1_0";
}
extends AbstractExtensionXmlSerializer<TwoWindingsTransformer, TwoWindingsTransformerPhaseAngleClock> {

@Override
public String getNamespacePrefix() {
return "twowtpac";
public TwoWindingsTransformerPhaseAngleClockXmlSerializer() {
super("twoWindingsTransformerPhaseAngleClock", "network", TwoWindingsTransformerPhaseAngleClock.class,
false, "twoWindingsTransformerPhaseAngleClock.xsd",
"http://www.powsybl.org/schema/iidm/ext/two_windings_transformer_phase_angle_clock/1_0", "twowtpac");
}

@Override
Expand All @@ -50,23 +35,8 @@ public void write(TwoWindingsTransformerPhaseAngleClock extension, XmlWriterCont
}

@Override
public TwoWindingsTransformerPhaseAngleClock read(TwoWindingsTransformer extendable, XmlReaderContext context) throws XMLStreamException {
public TwoWindingsTransformerPhaseAngleClock read(TwoWindingsTransformer extendable, XmlReaderContext context) {
int phaseAngleClock = XmlUtil.readOptionalIntegerAttribute(context.getReader(), "phaseAngleClock", 0);
return new TwoWindingsTransformerPhaseAngleClock(extendable, phaseAngleClock);
}

@Override
public String getExtensionName() {
return "twoWindingsTransformerPhaseAngleClock";
}

@Override
public String getCategoryName() {
return "network";
}

@Override
public Class<? super TwoWindingsTransformerPhaseAngleClock> getExtensionClass() {
return TwoWindingsTransformerPhaseAngleClock.class;
}
}