All Downloads are FREE. Search and download functionalities are using the official Maven repository.

cim1.model.PhaseTapChanger Maven / Gradle / Ivy

There is a newer version: 2.4.1
Show newest version
/**
 * 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 "PhaseTapChanger.java" represents the
 * class PhaseTapChanger extends TapChanger
 *    + windingConnectionAngle   0..1   float 
 *    + voltageStepIncrementOutOfPhase   0..1   float 
 *    + phaseTapChangerType   1..1   PhaseTapChangerKind 
 *    + stepPhaseShiftIncrement   0..1   float 
 *    + TransformerWinding   1..1   TransformerWinding 
 *    + xStepMin   0..1   float 
 *    + xStepMax   0..1   float 

 */
public class PhaseTapChanger extends TapChanger {

    private static Logger LOGGER = LoggerFactory.getLogger(PhaseTapChanger.class);

    /**
     * Attribute "windingConnectionAngle"
     *
     * Comment from profile:
     * The phase angle between the in-phase winding and the out-of -phase winding used for creating phase shift.   It is only possible to have a symmemtrical transformer if this angle is 90 degrees.This is required if PST is Asymmetrical
     */
    public float windingConnectionAngle;

    /**
     * Attribute "voltageStepIncrementOutOfPhase"
     *
     * Comment from profile:
     * The voltage step increment on the out of phase winding.    This voltage step on the out of phase winding of the phase shifter.  Similar to TapChanger.voltageStepIncrement, but it is applied only to the out of phase winding.This is required if PST is Asymmetrical.
     */
    public float voltageStepIncrementOutOfPhase;

    /**
     * Attribute "phaseTapChangerType"
     *
     * Comment from profile:
     * The type of phase shifter construction.
     */
    public PhaseTapChangerKind phaseTapChangerType;

    /**
     * Attribute "stepPhaseShiftIncrement"
     *
     * Comment from profile:
     * Phase shift per step position. A positive value indicates a positive phase shift from the winding where the tap is located to the other winding (for a two-winding transformer).The actual phase shift increment might be more accureatly computed from the symmetrical or asymmetrical models or a tap step table lookup if those are available.
     */
    public float stepPhaseShiftIncrement;

    /**
     * Attribute "transformerWinding"
     *
     * Comment from profile:
     * The transformer winding to which the phase tap changer belongs.
     */
    public TransformerWinding transformerWinding;

    /**
     * The id of the attribute "transformerWinding"
     * This id is mainly used to resolve links after parsing an instance
     */

    public String idTransformerWinding;

    /**
     * Attribute "xStepMin"
     *
     * Comment from profile:
     * The reactance at the minimum tap step.
     */
    public float xStepMin;

    /**
     * Attribute "xStepMax"
     *
     * Comment from profile:
     * The reactance at the maximum tap step.
     */
    public float xStepMax;

    /**
     * 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 "windingConnectionAngle" value
     *
     * @return the value of the attribute "windingConnectionAngle"
     */
    public float getWindingConnectionAngle() {
        return this.windingConnectionAngle;
    }

    /**
     * Utility to set the "windingConnectionAngle" value
     *
     * @param windingConnectionAngleValue 
     *            value to set
     */
    public void setWindingConnectionAngle(float windingConnectionAngleValue) {
        this.windingConnectionAngle = windingConnectionAngleValue;
        this.currentBitset.set(0);
    }

    /**
     * Utility to test if the value of "windingConnectionAngle" has been set
     *
     * @return boolean
     *            if true the attribute "windingConnectionAngle" is already set
     *            if false isn't yet
     */
    public boolean windingConnectionAngleIsSet() {
        return this.currentBitset.get(0);
     }
    
    /**
     * Utility to return the "voltageStepIncrementOutOfPhase" value
     *
     * @return the value of the attribute "voltageStepIncrementOutOfPhase"
     */
    public float getVoltageStepIncrementOutOfPhase() {
        return this.voltageStepIncrementOutOfPhase;
    }

    /**
     * Utility to set the "voltageStepIncrementOutOfPhase" value
     *
     * @param voltageStepIncrementOutOfPhaseValue 
     *            value to set
     */
    public void setVoltageStepIncrementOutOfPhase(float voltageStepIncrementOutOfPhaseValue) {
        this.voltageStepIncrementOutOfPhase = voltageStepIncrementOutOfPhaseValue;
        this.currentBitset.set(1);
    }

    /**
     * Utility to test if the value of "voltageStepIncrementOutOfPhase" has been set
     *
     * @return boolean
     *            if true the attribute "voltageStepIncrementOutOfPhase" is already set
     *            if false isn't yet
     */
    public boolean voltageStepIncrementOutOfPhaseIsSet() {
        return this.currentBitset.get(1);
     }
    
    /**
     * Utility to return the "phaseTapChangerType" enum
     *
     * @return the value of the attribute "phaseTapChangerType"
     */
    public PhaseTapChangerKind getPhaseTapChangerType() {
        return this.phaseTapChangerType;
    }

    /**
     * Utility to set the "phaseTapChangerType" enum
     *
     * @param phaseTapChangerTypeValue operand to set
     */
    public void setPhaseTapChangerType(PhaseTapChangerKind phaseTapChangerTypeValue) {
        this.phaseTapChangerType = phaseTapChangerTypeValue;
        this.currentBitset.set(2);
    }

    /**
     * Utility to test if the value of "phaseTapChangerType" has been set
     *
     * @return boolean
     *            if true the attribute "phaseTapChangerType" is already set
     *            if false it isn't yet
     */
    public boolean phaseTapChangerTypeIsSet() {
        return this.currentBitset.get(2);
    }
    
    /**
     * Utility to return the "stepPhaseShiftIncrement" value
     *
     * @return the value of the attribute "stepPhaseShiftIncrement"
     */
    public float getStepPhaseShiftIncrement() {
        return this.stepPhaseShiftIncrement;
    }

    /**
     * Utility to set the "stepPhaseShiftIncrement" value
     *
     * @param stepPhaseShiftIncrementValue 
     *            value to set
     */
    public void setStepPhaseShiftIncrement(float stepPhaseShiftIncrementValue) {
        this.stepPhaseShiftIncrement = stepPhaseShiftIncrementValue;
        this.currentBitset.set(3);
    }

    /**
     * Utility to test if the value of "stepPhaseShiftIncrement" has been set
     *
     * @return boolean
     *            if true the attribute "stepPhaseShiftIncrement" is already set
     *            if false isn't yet
     */
    public boolean stepPhaseShiftIncrementIsSet() {
        return this.currentBitset.get(3);
     }
    
    /**
     * Utility to return the "transformerWinding"
     *
     * @return the value of the attribute "transformerWinding"
     */
    public TransformerWinding getTransformerWinding() {
        return this.transformerWinding;
    }

    /**
     * Utility to test if the value of "transformerWinding" has been set
     *
     * @return boolean
     *            if true the attribute "transformerWinding" is already set
     *            if false it isn't yet
     */
    public boolean transformerWindingIsSet() {
        return this.currentBitset.get(4);
    }

    /**
     * Utility to set the "transformerWindingValue"
     *
     * @param transformerWindingValue
     *            instance to set
     * @param setInverse
     *            boolean to specify whether to set the inverse association
     *            or not
     * @throws LinkageException
     */
    public void setTransformerWinding(
            TransformerWinding transformerWindingValue,
            boolean setInverse) throws LinkageException {
        this.transformerWinding = transformerWindingValue;
        this.currentBitset.set(4);
        if (setInverse) {
            
            if (transformerWindingValue != null) {
                transformerWindingValue.setPhaseTapChanger(this, false);
            }
        }
    }
    
    /**
     * Utility to return the "xStepMin" value
     *
     * @return the value of the attribute "xStepMin"
     */
    public float getXStepMin() {
        return this.xStepMin;
    }

    /**
     * Utility to set the "xStepMin" value
     *
     * @param xStepMinValue 
     *            value to set
     */
    public void setXStepMin(float xStepMinValue) {
        this.xStepMin = xStepMinValue;
        this.currentBitset.set(5);
    }

    /**
     * Utility to test if the value of "xStepMin" has been set
     *
     * @return boolean
     *            if true the attribute "xStepMin" is already set
     *            if false isn't yet
     */
    public boolean xStepMinIsSet() {
        return this.currentBitset.get(5);
     }
    
    /**
     * Utility to return the "xStepMax" value
     *
     * @return the value of the attribute "xStepMax"
     */
    public float getXStepMax() {
        return this.xStepMax;
    }

    /**
     * Utility to set the "xStepMax" value
     *
     * @param xStepMaxValue 
     *            value to set
     */
    public void setXStepMax(float xStepMaxValue) {
        this.xStepMax = xStepMaxValue;
        this.currentBitset.set(6);
    }

    /**
     * Utility to test if the value of "xStepMax" has been set
     *
     * @return boolean
     *            if true the attribute "xStepMax" is already set
     *            if false isn't yet
     */
    public boolean xStepMaxIsSet() {
        return this.currentBitset.get(6);
     }


    /**
     * Factory of the class
     *
     * @param id
     *            id of the class PhaseTapChanger to create
     * @return the class created
     */
    public static PhaseTapChanger create(final String id) {
        PhaseTapChanger newPhaseTapChanger = new PhaseTapChanger();
        newPhaseTapChanger.setId(id);
        return newPhaseTapChanger;
    }

    /**
     * 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("PhaseTapChanger")) {
            if (attr_name.equals("windingConnectionAngle")) {

                if (!(model.isCurrentSubsetSet())
                        || (model.getCurrentSubset() == Subset.Equipment)) {
                    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 windingConnectionAngle in class "
                                + "PhaseTapChanger is supposed to be a Float"
                                + " but has not the expected NumberFormat");
                        }

                    } else {
                        throw new InterpretationException("The field of float"
                            + " in PhaseTapChanger was found empty");
                    }

                    this.setWindingConnectionAngle(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("\"Equipment\".");
                    throw new InterpretationException(errorMessage.toString());
                }
            }
            if (attr_name.equals("voltageStepIncrementOutOfPhase")) {

                if (!(model.isCurrentSubsetSet())
                        || (model.getCurrentSubset() == Subset.Equipment)) {
                    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 voltageStepIncrementOutOfPhase in class "
                                + "PhaseTapChanger is supposed to be a Float"
                                + " but has not the expected NumberFormat");
                        }

                    } else {
                        throw new InterpretationException("The field of float"
                            + " in PhaseTapChanger was found empty");
                    }

                    this.setVoltageStepIncrementOutOfPhase(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("\"Equipment\".");
                    throw new InterpretationException(errorMessage.toString());
                }
            }
            if (attr_name.equals("stepPhaseShiftIncrement")) {

                if (!(model.isCurrentSubsetSet())
                        || (model.getCurrentSubset() == Subset.Equipment)) {
                    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 stepPhaseShiftIncrement in class "
                                + "PhaseTapChanger is supposed to be a Float"
                                + " but has not the expected NumberFormat");
                        }

                    } else {
                        throw new InterpretationException("The field of float"
                            + " in PhaseTapChanger was found empty");
                    }

                    this.setStepPhaseShiftIncrement(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("\"Equipment\".");
                    throw new InterpretationException(errorMessage.toString());
                }
            }
            if (attr_name.equals("xStepMin")) {

                if (!(model.isCurrentSubsetSet())
                        || (model.getCurrentSubset() == Subset.Equipment)) {
                    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 xStepMin in class "
                                + "PhaseTapChanger is supposed to be a Float"
                                + " but has not the expected NumberFormat");
                        }

                    } else {
                        throw new InterpretationException("The field of float"
                            + " in PhaseTapChanger was found empty");
                    }

                    this.setXStepMin(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("\"Equipment\".");
                    throw new InterpretationException(errorMessage.toString());
                }
            }
            if (attr_name.equals("xStepMax")) {

                if (!(model.isCurrentSubsetSet())
                        || (model.getCurrentSubset() == Subset.Equipment)) {
                    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 xStepMax in class "
                                + "PhaseTapChanger is supposed to be a Float"
                                + " but has not the expected NumberFormat");
                        }

                    } else {
                        throw new InterpretationException("The field of float"
                            + " in PhaseTapChanger was found empty");
                    }

                    this.setXStepMax(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("\"Equipment\".");
                    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 {
                // We do not check if we are in the proper subset
                // to call the function on
                // the parent class
                super.readAttribute(class_name, attr_name, value, model);

            }
    }

    /**
     * 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("PhaseTapChanger")) {
    // Particular case : enum !
            if (resource_name.equals("phaseTapChangerType")) {

                if (!(model.isCurrentSubsetSet())
                        || (model.getCurrentSubset() == Subset.Equipment)) {
                    int pos = id.lastIndexOf('.');
                    String operand = id.substring(++pos);

                    try {
                        this.setPhaseTapChangerType(PhaseTapChangerKind
                                .valueOf(PhaseTapChangerKind.class, operand));
                    } catch (IllegalArgumentException e) {
                        StringBuilder errorMessage
                                = new StringBuilder("The value \"");
                        errorMessage.append(operand);
                        errorMessage
                                .append("\" could not be found in the enum Class \"");
                        errorMessage.append("PhaseTapChangerKind");
                        throw new InterpretationException(errorMessage.toString());
                    }

                    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());
                }

            }

            if (resource_name.equals("TransformerWinding")) {

                if (!(model.isCurrentSubsetSet())
                        || (model.getCurrentSubset() == Subset.Equipment)) {
                    idTransformerWinding = 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 {
            super.readResource(class_name, resource_name, id, model);
        }
    }

    /**
     * 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, "PhaseTapChanger");
                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("PhaseTapChanger ");
                errorMessage.append("which ID has been initialized to : ");
                errorMessage.append(getId());
                LOGGER.error(errorMessage.toString());
                LOGGER.error(e.toString(), e);
            }
        }
        writeClass(xmlsw);
        super.write(xmlsw, false);

        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("PhaseTapChanger ");
                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 Equipment: {

            if (writeID) {
                try {
                    xmlsw.writeStartElement(CIMURI.CIMURI, "PhaseTapChanger");
                    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("PhaseTapChanger ");
                    errorMessage.append("which ID has been initialized to : ");
                    errorMessage.append(getId());
                    errorMessage.append(" in the subset ");
                    errorMessage.append("Equipment");
                   LOGGER.error(errorMessage.toString());
                   LOGGER.error(e.toString(), e);
                }
            }

            writeClass(xmlsw);
            super.write(xmlsw, subset, false);
            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("PhaseTapChanger ");
                    errorMessage.append("which ID has been initialized to : ");
                    errorMessage.append(getId());
                    errorMessage.append(" in the subset ");
                    errorMessage.append("Equipment");
                    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 (idTransformerWinding != null) {
            TransformerWinding attributeToSet =
                    model.searchTransformerWinding
                    (idTransformerWinding);

            if (attributeToSet != null) {
                boolean setInverse = true;

                try {
                    this.setTransformerWinding(attributeToSet, setInverse);
                } catch(LinkageException e) {
                   LOGGER.error(e.toString(), e);
                    throw new LinkageException(e.getMessage());
                }
            } else if (boundaryModel != null) {
                TransformerWinding attributeToSetFromBoundary = boundaryModel.searchTransformerWinding(idTransformerWinding);
                if(attributeToSetFromBoundary != null) {
                    attributeToSetFromBoundary.setFromBoundary(true);
                    try {
                        model.createTransformerWinding(idTransformerWinding, attributeToSetFromBoundary);
                    } catch (InterpretationException e) {
                       LOGGER.error(e.toString(), e);
                    }
                    boolean setInverse = true;
                    try {
                        this.setTransformerWinding(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 \"TransformerWinding\" and id \"");
                    errorMessage.append(idTransformerWinding);
                    errorMessage.append("\" in \"PhaseTapChanger\" 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 \"TransformerWinding\" and id \"");
                errorMessage.append(idTransformerWinding);
                errorMessage.append("\" in \"PhaseTapChanger\" of id \"");
                errorMessage.append(this.getId());
                errorMessage.append("\" !");
                throw new LinkageException(errorMessage.toString());
            }
        }


        super.resolveLinks(model, boundaryModel);
        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)));
        }
        // consistent = (super.modelConsistency().getLeft()) ? (consistent &&
        // (true)):(consistent && (false))
        // message.append((super.modelConsistency(subset)).getRight());

        if (super.modelConsistency().isConsistent()) {
            consistent = consistent && (true);
            message.append((super.modelConsistency(subset)).getMessage());
        } else {
            consistent = consistent && (false);
            message.append((super.modelConsistency(subset)).getMessage());
        }

        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));
        }
        // consistent = (super.modelConsistency().getLeft()) ? (consistent &&
        // (true)):(consistent && (false))
        // message += (super.modelConsistency(subset)).getRight();

        if (super.modelConsistency().isConsistent()) {
            consistent = consistent && (true);
            message.append((super.modelConsistency()).getMessage());
        } else {
            consistent = consistent && (false);
            message.append((super.modelConsistency()).getMessage());
        }

        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 otherPhaseTapChanger
     *            the instance to copy
     */
    public void copyBase(final PhaseTapChanger otherPhaseTapChanger) {
        float newwindingConnectionAngle;
        // assigning primitive type :
        if (otherPhaseTapChanger.currentBitset.get(0)) {
            newwindingConnectionAngle = otherPhaseTapChanger.getWindingConnectionAngle();
            this.setWindingConnectionAngle(newwindingConnectionAngle);
          }
        float newvoltageStepIncrementOutOfPhase;
        // assigning primitive type :
        if (otherPhaseTapChanger.currentBitset.get(1)) {
            newvoltageStepIncrementOutOfPhase = otherPhaseTapChanger.getVoltageStepIncrementOutOfPhase();
            this.setVoltageStepIncrementOutOfPhase(newvoltageStepIncrementOutOfPhase);
          }
        // assigning enum type :

        PhaseTapChangerKind newphaseTapChangerType;

        if (otherPhaseTapChanger.currentBitset.get(2)) {
            newphaseTapChangerType = otherPhaseTapChanger.getPhaseTapChangerType();
            this.setPhaseTapChangerType(newphaseTapChangerType);
        }
        float newstepPhaseShiftIncrement;
        // assigning primitive type :
        if (otherPhaseTapChanger.currentBitset.get(3)) {
            newstepPhaseShiftIncrement = otherPhaseTapChanger.getStepPhaseShiftIncrement();
            this.setStepPhaseShiftIncrement(newstepPhaseShiftIncrement);
          }

        float newxStepMin;
        // assigning primitive type :
        if (otherPhaseTapChanger.currentBitset.get(5)) {
            newxStepMin = otherPhaseTapChanger.getXStepMin();
            this.setXStepMin(newxStepMin);
          }
        float newxStepMax;
        // assigning primitive type :
        if (otherPhaseTapChanger.currentBitset.get(6)) {
            newxStepMax = otherPhaseTapChanger.getXStepMax();
            this.setXStepMax(newxStepMax);
          }
        // 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 (otherPhaseTapChanger.currentBitset.get(4)) {
            TransformerWinding transformerWindingAssociation = otherPhaseTapChanger.getTransformerWinding();

            //this.idTransformerWinding = (transformerWindingAssociation != null) ? transformerWindingAssociation.getId() : "";
            if (transformerWindingAssociation != null) {
                this.idTransformerWinding = transformerWindingAssociation.getId();
                // the proper bit will be set when the setter is called
            } else {
                this.idTransformerWinding = "";
            }
        }

        // TODO : Call the parent copy constructor instead ?
        super.copyBase(otherPhaseTapChanger);

    }

    /**
     * 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,
                    "PhaseTapChanger.windingConnectionAngle");
            xmlsw.writeCharacters(String.valueOf(getWindingConnectionAngle()));
            xmlsw.writeEndElement();
            // xmlsw.writeCharacters("\n");
        } catch(XMLStreamException e) {
            StringBuilder errorMessage = new StringBuilder(
                    "Error while trying to write the value of the attribute ");
            errorMessage.append("WindingConnectionAngle");
            errorMessage.append(" in class ");
            errorMessage.append("PhaseTapChanger ");
            errorMessage.append("which ID has been initialized to : ");
            errorMessage.append(getId());
            LOGGER.error(errorMessage.toString());
            LOGGER.error(e.toString(), e);
        }
        }

        if (currentBitset.get(1)) {

        try {
            // xmlsw.writeCharacters("\t");
            xmlsw.writeStartElement(CIMURI.CIMURI,
                    "PhaseTapChanger.voltageStepIncrementOutOfPhase");
            xmlsw.writeCharacters(String.valueOf(getVoltageStepIncrementOutOfPhase()));
            xmlsw.writeEndElement();
            // xmlsw.writeCharacters("\n");
        } catch(XMLStreamException e) {
            StringBuilder errorMessage = new StringBuilder(
                    "Error while trying to write the value of the attribute ");
            errorMessage.append("VoltageStepIncrementOutOfPhase");
            errorMessage.append(" in class ");
            errorMessage.append("PhaseTapChanger ");
            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.writeEmptyElement(CIMURI.CIMURI,
                    "PhaseTapChanger.phaseTapChangerType");
            xmlsw.writeAttribute(CIMModel.rdfURI, "resource",
                    "http://iec.ch/TC57/2009/CIM-schema-cim14#PhaseTapChangerKind."
                    + getPhaseTapChangerType());
            // xmlsw.writeCharacters("\n");
        } catch(XMLStreamException e) {
            StringBuilder errorMessage = new StringBuilder(
                    "Error while trying to write the Enum attribute ");
            errorMessage.append("phaseTapChangerType");
            errorMessage.append(" in class ");
            errorMessage.append("PhaseTapChanger ");
            errorMessage.append("which ID has been initialized to : ");
            errorMessage.append(getId());
            LOGGER.error(errorMessage.toString());
            LOGGER.error(e.toString(), e);
        }
        }

        if (currentBitset.get(3)) {

        try {
            // xmlsw.writeCharacters("\t");
            xmlsw.writeStartElement(CIMURI.CIMURI,
                    "PhaseTapChanger.stepPhaseShiftIncrement");
            xmlsw.writeCharacters(String.valueOf(getStepPhaseShiftIncrement()));
            xmlsw.writeEndElement();
            // xmlsw.writeCharacters("\n");
        } catch(XMLStreamException e) {
            StringBuilder errorMessage = new StringBuilder(
                    "Error while trying to write the value of the attribute ");
            errorMessage.append("StepPhaseShiftIncrement");
            errorMessage.append(" in class ");
            errorMessage.append("PhaseTapChanger ");
            errorMessage.append("which ID has been initialized to : ");
            errorMessage.append(getId());
            LOGGER.error(errorMessage.toString());
            LOGGER.error(e.toString(), e);
        }
        }

        if (currentBitset.get(4)) {

    /*
     * 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 (idTransformerWinding != null &&
                !idTransformerWinding.isEmpty()) {

            try {
                // xmlsw.writeCharacters("\t");
                xmlsw.writeEmptyElement(CIMURI.CIMURI,
                        "PhaseTapChanger.TransformerWinding");
                xmlsw.writeAttribute(CIMModel.rdfURI, "resource", "#"
                        + idTransformerWinding);
                // xmlsw.writeCharacters("\n");
            } catch(XMLStreamException e) {
                StringBuilder errorMessage = new StringBuilder(
                        "Error while trying to write the resource attribute ");
                errorMessage.append("TransformerWinding");
                errorMessage.append(" in class ");
                errorMessage.append("PhaseTapChanger ");
                errorMessage.append("which ID has been initialized to : ");
                errorMessage.append(getId());
                LOGGER.error(errorMessage.toString());
                LOGGER.error(e.toString(), e);
            }
        }
        }

        if (currentBitset.get(5)) {

        try {
            // xmlsw.writeCharacters("\t");
            xmlsw.writeStartElement(CIMURI.CIMURI,
                    "PhaseTapChanger.xStepMin");
            xmlsw.writeCharacters(String.valueOf(getXStepMin()));
            xmlsw.writeEndElement();
            // xmlsw.writeCharacters("\n");
        } catch(XMLStreamException e) {
            StringBuilder errorMessage = new StringBuilder(
                    "Error while trying to write the value of the attribute ");
            errorMessage.append("XStepMin");
            errorMessage.append(" in class ");
            errorMessage.append("PhaseTapChanger ");
            errorMessage.append("which ID has been initialized to : ");
            errorMessage.append(getId());
            LOGGER.error(errorMessage.toString());
            LOGGER.error(e.toString(), e);
        }
        }

        if (currentBitset.get(6)) {

        try {
            // xmlsw.writeCharacters("\t");
            xmlsw.writeStartElement(CIMURI.CIMURI,
                    "PhaseTapChanger.xStepMax");
            xmlsw.writeCharacters(String.valueOf(getXStepMax()));
            xmlsw.writeEndElement();
            // xmlsw.writeCharacters("\n");
        } catch(XMLStreamException e) {
            StringBuilder errorMessage = new StringBuilder(
                    "Error while trying to write the value of the attribute ");
            errorMessage.append("XStepMax");
            errorMessage.append(" in class ");
            errorMessage.append("PhaseTapChanger ");
            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 \"PhaseTapChanger\" 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\"windingConnectionAngle\" needs to be set\n");
        }

        if (isNotSet.get(1)) {
            message.append("\t\"voltageStepIncrementOutOfPhase\" needs to be set\n");
        }

        if (isNotSet.get(2)) {
            message.append("\t\"phaseTapChangerType\" needs to be set\n");
        }

        if (isNotSet.get(3)) {
            message.append("\t\"stepPhaseShiftIncrement\" needs to be set\n");
        }

        if (isNotSet.get(4)) {
            message.append("\t\"TransformerWinding\" needs to be set\n");
        }

        if (isNotSet.get(5)) {
            message.append("\t\"xStepMin\" needs to be set\n");
        }

        if (isNotSet.get(6)) {
            message.append("\t\"xStepMax\" needs to be set\n");
        }
        return message.toString();
    }

    /**
     * Copy constructor
     * The associations with other objects are not copied
     *
     * @param PhaseTapChanger
     *            the reference to the class to copy
     * @return the class constructed
     */
    private PhaseTapChanger(final PhaseTapChanger otherPhaseTapChanger) {
        // TODO : check exception safe
        this.copyBase(otherPhaseTapChanger);
    }

   /**
    * Constructor of the class PhaseTapChanger
    */
    protected PhaseTapChanger() {

        super.subset = Subset.Equipment;
        this.minBitsets.put(Subset.StateVariables, new BitSet(7));
        this.minBitsets.put(Subset.Topology, new BitSet(7));
        BitSet classBitset = new BitSet(7);
        classBitset.set(2);
        classBitset.set(4);
        this.minBitsets.put(Subset.Equipment, classBitset);
    }



    /**
     * 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: {
                super.clearAssociations(subset);
                break;
            }
            case Topology: {
                super.clearAssociations(subset);
                break;
            }
            case Equipment: {
                // reset the Reference
                transformerWinding = null;
                idTransformerWinding = "";
                this.currentBitset.clear(4);
                super.clearAssociations(subset);
                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 PhaseTapChanger clone() {
        PhaseTapChanger newInstance = new PhaseTapChanger(this);
        PhaseTapChanger newInstanceSP = newInstance;
        return newInstanceSP;
    }

}







© 2015 - 2024 Weber Informatics LLC | Privacy Policy