cim1.model.SvVoltage Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of powsybl-cim1-model Show documentation
Show all versions of powsybl-cim1-model Show documentation
CIM ENTSO-E V1 model generated by CIM Gateway tool
/**
* Copyright (c) 2016, All partners of the iTesla project (http://www.itesla-project.eu/consortium)
* 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 cim1.model;
import cim1.exc.InterpretationException;
import cim1.exc.LinkageException;
import java.util.BitSet;
import java.util.Map;
import java.util.EnumMap;
import javax.xml.stream.XMLStreamException;
import cim1.CIMURI;
import javax.xml.stream.XMLStreamWriter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
*
* This file has been automatically generated by CIMGateway
*
* Description :
*
* This class "SvVoltage.java" represents the
* class SvVoltage : CIMInstance
*
* + angle 1..1 float
* + TopologicalNode 1..1 TopologicalNode
* + v 1..1 float
*/
public class SvVoltage extends CIMInstance {
private static Logger LOGGER = LoggerFactory.getLogger(SvVoltage.class);
/**
* Attribute "angle"
*
* Comment from profile:
* The voltage angle in radians of the topological node.
*/
public float angle;
/**
* Attribute "topologicalNode"
*
* Comment from profile:
* The topological node associated with the voltage state.
*/
public TopologicalNode topologicalNode;
/**
* The id of the attribute "topologicalNode"
* This id is mainly used to resolve links after parsing an instance
*/
public String idTopologicalNode;
/**
* Attribute "v"
*
* Comment from profile:
* The voltage magnitude of the topological node.
*/
public float v;
/**
* The current bitset describing the state of each CIM attribute of this
* class
*/
private BitSet currentBitset = new BitSet();
/**
* The bitset describing which CIM attributes of this class have to set to
* be consistent within a "merged" context
*/
private final BitSet minBitset = new BitSet();
/**
* The Map of subset<=>bitset describing which CIM attributes of this class
* have to set to be consistent within a specific subset context
*/
private final Map minBitsets
= new EnumMap(Subset.class);
/**
* Utility to return the "angle" value
*
* @return the value of the attribute "angle"
*/
public float getAngle() {
return this.angle;
}
/**
* Utility to set the "angle" value
*
* @param angleValue
* value to set
*/
public void setAngle(float angleValue) {
this.angle = angleValue;
this.currentBitset.set(0);
}
/**
* Utility to test if the value of "angle" has been set
*
* @return boolean
* if true the attribute "angle" is already set
* if false isn't yet
*/
public boolean angleIsSet() {
return this.currentBitset.get(0);
}
/**
* Utility to return the "topologicalNode"
*
* @return the value of the attribute "topologicalNode"
*/
public TopologicalNode getTopologicalNode() {
return this.topologicalNode;
}
/**
* Utility to test if the value of "topologicalNode" has been set
*
* @return boolean
* if true the attribute "topologicalNode" is already set
* if false it isn't yet
*/
public boolean topologicalNodeIsSet() {
return this.currentBitset.get(1);
}
/**
* Utility to set the "topologicalNodeValue"
*
* @param topologicalNodeValue
* instance to set
* @param setInverse
* boolean to specify whether to set the inverse association
* or not
* @throws LinkageException
*/
public void setTopologicalNode(
TopologicalNode topologicalNodeValue,
boolean setInverse) throws LinkageException {
this.topologicalNode = topologicalNodeValue;
this.currentBitset.set(1);
if (setInverse) {
if (topologicalNodeValue != null) {
topologicalNodeValue.setSvVoltage(this, false);
}
}
}
/**
* Utility to return the "v" value
*
* @return the value of the attribute "v"
*/
public float getV() {
return this.v;
}
/**
* Utility to set the "v" value
*
* @param vValue
* value to set
*/
public void setV(float vValue) {
this.v = vValue;
this.currentBitset.set(2);
}
/**
* Utility to test if the value of "v" has been set
*
* @return boolean
* if true the attribute "v" is already set
* if false isn't yet
*/
public boolean vIsSet() {
return this.currentBitset.get(2);
}
/**
* Factory of the class
*
* @param id
* id of the class SvVoltage to create
* @return the class created
*/
public static SvVoltage create(final String id) {
SvVoltage newSvVoltage = new SvVoltage();
newSvVoltage.setId(id);
return newSvVoltage;
}
/**
* Utility to "clear" the content of a class when a subset is invalidated
*
* @param subset subset to clean
*/
@Override
public void clearContent(Subset subset) {
// First of all, we clear the associations:
this.clearAssociations(subset);
switch (subset) {
default: // nothing to clear
}
}
/**
* Utility to read an attribute
* This function is called by the CIMModel
*
* @param class_name
* the read name of class
* @param attr_name
* the read name of attribute
* @param value
* the read value of the attribute
* @param model
* the interface to the model this class belongs to
* @throws InterpretationException
*/
@Override
public void readAttribute(final String class_name, final String attr_name,
final String value, CIMModel model) throws InterpretationException {
if (class_name.equals("SvVoltage")) {
if (attr_name.equals("angle")) {
if (!(model.isCurrentSubsetSet())
|| (model.getCurrentSubset() == Subset.StateVariables)) {
float typedValue;
if (!value.isEmpty()) {
try {
if (value.equalsIgnoreCase("NaN")) {
throw new NumberFormatException();
}
typedValue = Float
.parseFloat(value);
} catch(NumberFormatException e) {
throw new InterpretationException("The attribute angle in class "
+ "SvVoltage is supposed to be a Float"
+ " but has not the expected NumberFormat");
}
} else {
throw new InterpretationException("The field of float"
+ " in SvVoltage was found empty");
}
this.setAngle(typedValue);
return;
} else {
StringBuilder errorMessage
= new StringBuilder("The attribute \"");
errorMessage.append(attr_name);
errorMessage.append("\" in class \"");
errorMessage.append(class_name);
errorMessage.append("\" cannot be defined in a file ");
errorMessage.append("describing an other subset than ");
errorMessage.append("\"StateVariables\".");
throw new InterpretationException(errorMessage.toString());
}
}
if (attr_name.equals("v")) {
if (!(model.isCurrentSubsetSet())
|| (model.getCurrentSubset() == Subset.StateVariables)) {
float typedValue;
if (!value.isEmpty()) {
try {
if (value.equalsIgnoreCase("NaN")) {
throw new NumberFormatException();
}
typedValue = Float
.parseFloat(value);
} catch(NumberFormatException e) {
throw new InterpretationException("The attribute v in class "
+ "SvVoltage is supposed to be a Float"
+ " but has not the expected NumberFormat");
}
} else {
throw new InterpretationException("The field of float"
+ " in SvVoltage was found empty");
}
this.setV(typedValue);
return;
} else {
StringBuilder errorMessage
= new StringBuilder("The attribute \"");
errorMessage.append(attr_name);
errorMessage.append("\" in class \"");
errorMessage.append(class_name);
errorMessage.append("\" cannot be defined in a file ");
errorMessage.append("describing an other subset than ");
errorMessage.append("\"StateVariables\".");
throw new InterpretationException(errorMessage.toString());
}
}
StringBuilder errorMessage = new StringBuilder("The attribute \"");
errorMessage.append(attr_name);
errorMessage.append("\" in class \"");
errorMessage.append(class_name);
errorMessage
.append("\" could not be found in the model !");
throw new InterpretationException(errorMessage.toString());
} else {
StringBuilder errorMessage = new StringBuilder("The attribute \"");
errorMessage.append(attr_name);
errorMessage.append("\" in class \"");
errorMessage.append(class_name);
errorMessage
.append("\" could not be found in the model !");
throw new InterpretationException(errorMessage.toString());
}
}
/**
* Utility to read a reference to a resource
* This function is called by the CIMModel
*
* @param class_name
* the read name of class
* @param resource_name
* the read name of the associated resource
* @param id
* the id of the associated resource
* @param model
* the model this class belongs to
* @throws InterpretationException
*/
@Override
public void readResource(final String class_name,
final String resource_name, final String id, CIMModel model)
throws InterpretationException, LinkageException {
if (class_name.equals("SvVoltage")) {
if (resource_name.equals("TopologicalNode")) {
if (!(model.isCurrentSubsetSet())
|| (model.getCurrentSubset() == Subset.StateVariables)) {
idTopologicalNode = id.substring(1);
if (!super.isAddedToUnresolved()) {
model.addUnresolved();
super.addToUnresolved();
}
return;
} else {
StringBuilder errorMessage
= new StringBuilder("The association \"");
errorMessage.append(resource_name);
errorMessage.append("\" in class");
errorMessage.append("\""+class_name+" \"");
errorMessage.append("is not supposed to be in the subset \"");
errorMessage.append(model.getCurrentSubset().getIdentifier());
errorMessage.append("\"");
throw new InterpretationException(errorMessage.toString());
}
}
StringBuilder errorMessage = new StringBuilder("The association \"");
errorMessage.append(resource_name);
errorMessage.append("\" in class \"");
errorMessage.append(class_name);
errorMessage.append("\" could not be found in the model !");
throw new InterpretationException(errorMessage.toString());
} else {
StringBuilder errorMessage = new StringBuilder("The association \"");
errorMessage.append(resource_name);
errorMessage.append("\" in class \"");
errorMessage.append(class_name);
errorMessage.append("\" could not be found in the model !");
throw new InterpretationException(errorMessage.toString());
}
}
/**
* Utility to write the content into the CIM XML format
*
* @param writeID
* specifies whether to write the XML "id" attribute (this is used for describing concrete class)
* @param xmlsw
* XMLStreamWriter where are stored the elements to write
*/
@Override
public void write(XMLStreamWriter xmlsw, boolean writeID) {
/*
* In previous versions, we used to check the consistency
* of the instance in the context but this task is now
* performed by the model before attempting to write.
* Therefore each instance can now be written even if
* it is not consistent !
*/
if (writeID) {
try {
xmlsw.writeStartElement(CIMURI.CIMURI, "SvVoltage");
xmlsw.writeAttribute(CIMModel.rdfURI, "ID", getId());
// xmlsw.writeCharacters("\n");
} catch (XMLStreamException e) {
StringBuilder errorMessage = new StringBuilder(
"Error while trying to write the class ");
errorMessage.append("SvVoltage ");
errorMessage.append("which ID has been initialized to : ");
errorMessage.append(getId());
LOGGER.error(errorMessage.toString());
LOGGER.error(e.toString(), e);
}
}
writeClass(xmlsw);
if (writeID) {
try {
xmlsw.writeEndElement();
// xmlsw.writeCharacters("\n");
} catch (XMLStreamException e) {
StringBuilder errorMessage = new StringBuilder(
"Error while trying to write the end Element of the class ");
errorMessage.append("SvVoltage ");
errorMessage.append("which ID has been initialized to : ");
errorMessage.append(getId());
LOGGER.error(errorMessage.toString());
LOGGER.error(e.toString(), e);
}
}
return;
}
/**
* Utility to write the content this class into the CIM/XML format according
* to a subset
*
* @param subset
* the subset defining the context in which to write this class
* @param writeID
* specifies whether to write the XML "id" attribute (this is used for describing concrete class)
* @param xmlsw
* the stream in which are stored the elements to write
*/
@Override
public void write(XMLStreamWriter xmlsw, final Subset subset,
boolean writeID) {
/*
* In previous versions, we used to check the consistency
* of the instance in the context but this task is now
* performed by the model before attempting to write.
* Therefore each instance can now be written even if
* it is not consistent !
*/
switch (subset) {
case StateVariables: {
if (writeID) {
try {
xmlsw.writeStartElement(CIMURI.CIMURI, "SvVoltage");
xmlsw.writeAttribute(CIMModel.rdfURI, "ID", getId());
// xmlsw.writeCharacters("\n");
} catch (XMLStreamException e) {
StringBuilder errorMessage = new StringBuilder(
"Error while trying to write the class ");
errorMessage.append("SvVoltage ");
errorMessage.append("which ID has been initialized to : ");
errorMessage.append(getId());
errorMessage.append(" in the subset ");
errorMessage.append("StateVariables");
LOGGER.error(errorMessage.toString());
LOGGER.error(e.toString(), e);
}
}
writeClass(xmlsw);
if (writeID) {
try {
xmlsw.writeEndElement();
// xmlsw.writeCharacters("\n");
} catch (XMLStreamException e) {
StringBuilder errorMessage = new StringBuilder(
"Error while trying to write end element of ");
errorMessage.append("SvVoltage ");
errorMessage.append("which ID has been initialized to : ");
errorMessage.append(getId());
errorMessage.append(" in the subset ");
errorMessage.append("StateVariables");
LOGGER.error(errorMessage.toString());
LOGGER.error(e.toString(), e);
}
}
break;
}
default: {// Do nothing !
}
}
return;
}
/**
* Utility to resolve the links at the end of parsing
*
* @param model
* the model this class belongs to
* @param boundaryModel
* the model that gather data about the boundarySet, used
* as a resource force links resolving
* @throws Linkage Exception
*/
@Override
public void resolveLinks(CIMModel model, CIMModel boundaryModel) throws LinkageException {
if (idTopologicalNode != null) {
TopologicalNode attributeToSet =
model.searchTopologicalNode
(idTopologicalNode);
if (attributeToSet != null) {
boolean setInverse = true;
try {
this.setTopologicalNode(attributeToSet, setInverse);
} catch(LinkageException e) {
LOGGER.error(e.toString(), e);
throw new LinkageException(e.getMessage());
}
} else if (boundaryModel != null) {
TopologicalNode attributeToSetFromBoundary = boundaryModel.searchTopologicalNode(idTopologicalNode);
if(attributeToSetFromBoundary != null) {
attributeToSetFromBoundary.setFromBoundary(true);
try {
model.createTopologicalNode(idTopologicalNode, attributeToSetFromBoundary);
} catch (InterpretationException e) {
LOGGER.error(e.toString(), e);
}
boolean setInverse = true;
try {
this.setTopologicalNode(attributeToSetFromBoundary, setInverse);
} catch(LinkageException e) {
LOGGER.error(e.toString(), e);
throw new LinkageException(e.getMessage());
}
attributeToSetFromBoundary.resolveLinks(model, boundaryModel);
} else {
StringBuilder errorMessage = new StringBuilder(
"Could not find the reference to object of type \"TopologicalNode\" and id \"");
errorMessage.append(idTopologicalNode);
errorMessage.append("\" in \"SvVoltage\" of id \"");
errorMessage.append(this.getId());
errorMessage.append("\" !");
throw new LinkageException(errorMessage.toString());
}
} else {
StringBuilder errorMessage = new StringBuilder(
"Could not find the reference to object of type \"TopologicalNode\" and id \"");
errorMessage.append(idTopologicalNode);
errorMessage.append("\" in \"SvVoltage\" of id \"");
errorMessage.append(this.getId());
errorMessage.append("\" !");
throw new LinkageException(errorMessage.toString());
}
}
removeFromUnresolved();
}
/**
* Utility to check whether this class is consistent according to a subset
*
* @param subset
* the subset defining the context in which to check whether this class is consistent
* @return a ConsistencyCheck instance whose boolean attribute (consistent)
* indicates if this class is consistent and whose String attribute
* (message)
* indicates why this class is not consistent if it is not
*/
@Override
public ConsistencyCheck modelConsistency(final Subset subset) {
BitSet intersection = new BitSet(this.minBitsets.get(subset).length());
intersection.or(this.minBitsets.get(subset));
// we create a copy of minBitsets.get(subset)
intersection.and(this.currentBitset);
boolean consistent = (this.minBitsets.get(subset).equals(intersection));
StringBuilder message = new StringBuilder("");
if (!consistent) {
message.append(getMessageForConsistency(this.minBitsets.get(subset)));
}
return new ConsistencyCheck(consistent, message.toString());
}
/**
* Utility to check whether this class is consistent in a "merged" context
*
* @return a ConsistencyCheck instance whose boolean attribute (consistent)
* indicates if this class is consistent and whose String attribute
* (message)
* indicates why this class is not consistent if it is not
*/
@Override
public ConsistencyCheck modelConsistency() {
BitSet intersection = new BitSet(this.minBitset.length());
intersection.or(this.minBitset);
// we create a copy of minBitSet
intersection.and(this.currentBitset);
boolean consistent = (this.minBitset.equals(intersection));
StringBuilder message = new StringBuilder("");
if (!consistent) {
message.append(getMessageForConsistency(this.minBitset));
}
return new ConsistencyCheck(consistent, message.toString());
}
/**
* Utility to copy the "base" of an other instance of the same class
* This utility does not copy the associations with other instances from
* the instance to copy
*
* @param otherSvVoltage
* the instance to copy
*/
public void copyBase(final SvVoltage otherSvVoltage) {
float newangle;
// assigning primitive type :
if (otherSvVoltage.currentBitset.get(0)) {
newangle = otherSvVoltage.getAngle();
this.setAngle(newangle);
}
float newv;
// assigning primitive type :
if (otherSvVoltage.currentBitset.get(2)) {
newv = otherSvVoltage.getV();
this.setV(newv);
}
// Memory allocation has done successfully !
// Dropping "old" objects...
// This part may change : we do nothing to allow the user to access
// object by their id from the global model.
if (otherSvVoltage.currentBitset.get(1)) {
TopologicalNode topologicalNodeAssociation = otherSvVoltage.getTopologicalNode();
//this.idTopologicalNode = (topologicalNodeAssociation != null) ? topologicalNodeAssociation.getId() : "";
if (topologicalNodeAssociation != null) {
this.idTopologicalNode = topologicalNodeAssociation.getId();
// the proper bit will be set when the setter is called
} else {
this.idTopologicalNode = "";
}
}
// TODO : Call the parent copy constructor instead ?
super.copyBase(otherSvVoltage);
}
/**
* Utility to return the content of this class into the CIM XML format
*
* @param xmlsw
* the stream in which are stored the elements to write
*/
private void writeClass(XMLStreamWriter xmlsw) {
if (currentBitset.get(0)) {
try {
// xmlsw.writeCharacters("\t");
xmlsw.writeStartElement(CIMURI.CIMURI,
"SvVoltage.angle");
xmlsw.writeCharacters(String.valueOf(getAngle()));
xmlsw.writeEndElement();
// xmlsw.writeCharacters("\n");
} catch(XMLStreamException e) {
StringBuilder errorMessage = new StringBuilder(
"Error while trying to write the value of the attribute ");
errorMessage.append("Angle");
errorMessage.append(" in class ");
errorMessage.append("SvVoltage ");
errorMessage.append("which ID has been initialized to : ");
errorMessage.append(getId());
LOGGER.error(errorMessage.toString());
LOGGER.error(e.toString(), e);
}
}
if (currentBitset.get(1)) {
/*
* Careful here : we may write an association "twice" if
* the association is 1..1 one and if
* both ends belong to the same subset
*/
if (idTopologicalNode != null &&
!idTopologicalNode.isEmpty()) {
try {
// xmlsw.writeCharacters("\t");
xmlsw.writeEmptyElement(CIMURI.CIMURI,
"SvVoltage.TopologicalNode");
xmlsw.writeAttribute(CIMModel.rdfURI, "resource", "#"
+ idTopologicalNode);
// xmlsw.writeCharacters("\n");
} catch(XMLStreamException e) {
StringBuilder errorMessage = new StringBuilder(
"Error while trying to write the resource attribute ");
errorMessage.append("TopologicalNode");
errorMessage.append(" in class ");
errorMessage.append("SvVoltage ");
errorMessage.append("which ID has been initialized to : ");
errorMessage.append(getId());
LOGGER.error(errorMessage.toString());
LOGGER.error(e.toString(), e);
}
}
}
if (currentBitset.get(2)) {
try {
// xmlsw.writeCharacters("\t");
xmlsw.writeStartElement(CIMURI.CIMURI,
"SvVoltage.v");
xmlsw.writeCharacters(String.valueOf(getV()));
xmlsw.writeEndElement();
// xmlsw.writeCharacters("\n");
} catch(XMLStreamException e) {
StringBuilder errorMessage = new StringBuilder(
"Error while trying to write the value of the attribute ");
errorMessage.append("V");
errorMessage.append(" in class ");
errorMessage.append("SvVoltage ");
errorMessage.append("which ID has been initialized to : ");
errorMessage.append(getId());
LOGGER.error(errorMessage.toString());
LOGGER.error(e.toString(), e);
}
}
return;
}
/**
* Utility in charge of creating the message when the class is not
* consistent within a specific context
*
* @param minBitset
* bitset describing which CIM attributes of this class have
* to be set so that it is consistent within a
* specific subset context
* @return the message explaining what is not consistent
*/
private String getMessageForConsistency(final BitSet minBitset) {
StringBuilder message = new StringBuilder(
"Instance of \"SvVoltage\" of id \"");
message.append(this.getId());
message.append("\" is not consistent in this context:\n");
/*
* XOR and then AND
* The result is :
* "1" : has not been set and need to be
* "0" : has been set or is not mandatory
*/
BitSet isNotSet = new BitSet(minBitset.length());
isNotSet.or(minBitset);
// we create a copy of minBitset
isNotSet.xor(this.currentBitset);
isNotSet.and(minBitset);
if (isNotSet.get(0)) {
message.append("\t\"angle\" needs to be set\n");
}
if (isNotSet.get(1)) {
message.append("\t\"TopologicalNode\" needs to be set\n");
}
if (isNotSet.get(2)) {
message.append("\t\"v\" needs to be set\n");
}
return message.toString();
}
/**
* Copy constructor
* The associations with other objects are not copied
*
* @param SvVoltage
* the reference to the class to copy
* @return the class constructed
*/
private SvVoltage(final SvVoltage otherSvVoltage) {
// TODO : check exception safe
this.copyBase(otherSvVoltage);
}
/**
* Constructor of the class SvVoltage
*/
protected SvVoltage() {
super.subset = Subset.StateVariables;
BitSet classBitset = new BitSet(3);
classBitset.set(0);
classBitset.set(1);
classBitset.set(2);
this.minBitsets.put(Subset.StateVariables, classBitset);
this.minBitsets.put(Subset.Topology, new BitSet(3));
this.minBitsets.put(Subset.Equipment, new BitSet(3));
}
/**
* Utility to clear the associations of this class belonging to a
* specific subset
*
* @param subset
* the subset from which to clear the associations of this class
*/
@Override
protected void clearAssociations(final Subset subset) {
switch (subset) {
case StateVariables: {
break;
}
case Topology: {
// reset the Reference
topologicalNode = null;
idTopologicalNode = "";
this.currentBitset.clear(1);
break;
}
case Equipment: {
break;
}
default: // nothing to clear
}
}
/**
* Utility returning a copy of the "base" of this instance
* This utility does not copy the associations with other instances
*
* @return a clone of this instance
*/
public SvVoltage clone() {
SvVoltage newInstance = new SvVoltage(this);
SvVoltage newInstanceSP = newInstance;
return newInstanceSP;
}
}