protected static void writeTerminalRef(Terminal t, NetworkXmlWriterContext context, String elementName) throws XMLStreamException {
Connectable c = t.getConnectable();
if (!context.getFilter().test(c)) {
throw new PowsyblException("Oups, terminal ref point to a filtered equipment " + c.getId());
}
context.getWriter().writeEmptyElement(IIDM_URI, elementName);
context.getWriter().writeAttribute("id", context.getAnonymizer().anonymizeString(c.getId()));
if (c.getTerminals().size() > 1) {
if (c instanceof Injection) {
} else if (c instanceof Branch) {
Branch branch = (Branch) c;
context.getWriter().writeAttribute("side", branch.getSide(t).name());
} else if (c instanceof ThreeWindingsTransformer) {
ThreeWindingsTransformer twt = (ThreeWindingsTransformer) c;
context.getWriter().writeAttribute("side", twt.getSide(t).name());
} else {
throw new AssertionError("Unexpected Connectable instance: " + c.getClass());
}
}
}