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

cim1.model.RegulatingControl 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.ArrayList;
import java.util.List;
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 "RegulatingControl.java" represents the
 * class RegulatingControl extends IdentifiedObject
 *    + TapChanger   0..-1   TapChanger   (inverseAssociation) 
 *    + discrete   1..1   boolean 
 *    + RegulatingCondEq   0..-1   RegulatingCondEq   (inverseAssociation) 
 *    + targetRange   1..1   float 
 *    + mode   1..1   RegulatingControlModeKind 
 *    + targetValue   1..1   float 
 *    + Terminal   1..1   Terminal 

 */
public class RegulatingControl extends IdentifiedObject {

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

    /**
     * Attribute "tapChanger"
     *
     * Comment from profile:
     * copy from reg conduting eq
     */
    public List tapChanger;

    /**
     * Attribute "discrete"
     *
     * Comment from profile:
     * The regulation is performed in a discrete mode.
     */
    public boolean discrete;

    /**
     * Attribute "regulatingCondEq"
     *
     * Comment from profile:
     * copy from reg cond eq
     */
    public List regulatingCondEq;

    /**
     * Attribute "targetRange"
     *
     * Comment from profile:
     * This is the case input target range.   This performs the same function as the value2 attribute on the regulation schedule in the case that schedules are not used.   The units of those appropriate for the mode.
     */
    public float targetRange;

    /**
     * Attribute "mode"
     *
     * Comment from profile:
     * The regulating control mode presently available.  This specifications allows for determining the kind of regualation without need for obtaining the units from a schedule.
     */
    public RegulatingControlModeKind mode;

    /**
     * Attribute "targetValue"
     *
     * Comment from profile:
     * The target value specified for case input.   This value can be used for the target value wihout the use of schedules. The value has the units appropriate to the mode attribute.
     */
    public float targetValue;

    /**
     * Attribute "terminal"
     *
     * Comment from profile:
     * The terminal associated with this regulating control.
     */
    public Terminal terminal;

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

    public String idTerminal;

    /**
     * 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 "tapChanger" List of 
   * "TapChanger" enum
   *
   * @return the list of the attributes "tapChanger"
   */
    public List getTapChanger() {
        return this.tapChanger;
    }

    /**
     * Utility to add a value within the "tapChanger" ArrayList of 
     * "TapChanger"
     *
     * @param tapChangerValue 
     *            value to add within the ArrayList
     * @param setInverse
     *            boolean to specify whether to set the inverse association or not
     * @throws LinkageException
     */
    public void addTapChanger(
            TapChanger tapChangerValue, 
            boolean setInverse) throws LinkageException {
        
        if (tapChanger == null) {
            tapChanger = new ArrayList();
        }
        
        this.tapChanger.add(tapChangerValue);
        this.currentBitset.set(0);
       
        if (setInverse) {
            
            if (tapChangerValue != null) {
                tapChangerValue.setRegulatingControl(this, false);
            }
        }
    }

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

    /**
     * Utility to set the "discrete" value
     *
     * @param discreteValue 
     *            value to set
     */
    public void setDiscrete(boolean discreteValue) {
        this.discrete = discreteValue;
        this.currentBitset.set(1);
    }

    /**
     * Utility to test if the value of "discrete" has been set
     *
     * @return boolean
     *            if true the attribute "discrete" is already set
     *            if false isn't yet
     */
    public boolean discreteIsSet() {
        return this.currentBitset.get(1);
     }
  /**
   * Utility to return the "regulatingCondEq" List of 
   * "RegulatingCondEq" enum
   *
   * @return the list of the attributes "regulatingCondEq"
   */
    public List getRegulatingCondEq() {
        return this.regulatingCondEq;
    }

    /**
     * Utility to add a value within the "regulatingCondEq" ArrayList of 
     * "RegulatingCondEq"
     *
     * @param regulatingCondEqValue 
     *            value to add within the ArrayList
     * @param setInverse
     *            boolean to specify whether to set the inverse association or not
     * @throws LinkageException
     */
    public void addRegulatingCondEq(
            RegulatingCondEq regulatingCondEqValue, 
            boolean setInverse) throws LinkageException {
        
        if (regulatingCondEq == null) {
            regulatingCondEq = new ArrayList();
        }
        
        this.regulatingCondEq.add(regulatingCondEqValue);
        this.currentBitset.set(2);
       
        if (setInverse) {
            
            if (regulatingCondEqValue != null) {
                regulatingCondEqValue.setRegulatingControl(this, false);
            }
        }
    }

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

    /**
     * Utility to set the "targetRange" value
     *
     * @param targetRangeValue 
     *            value to set
     */
    public void setTargetRange(float targetRangeValue) {
        this.targetRange = targetRangeValue;
        this.currentBitset.set(3);
    }

    /**
     * Utility to test if the value of "targetRange" has been set
     *
     * @return boolean
     *            if true the attribute "targetRange" is already set
     *            if false isn't yet
     */
    public boolean targetRangeIsSet() {
        return this.currentBitset.get(3);
     }
    
    /**
     * Utility to return the "mode" enum
     *
     * @return the value of the attribute "mode"
     */
    public RegulatingControlModeKind getMode() {
        return this.mode;
    }

    /**
     * Utility to set the "mode" enum
     *
     * @param modeValue operand to set
     */
    public void setMode(RegulatingControlModeKind modeValue) {
        this.mode = modeValue;
        this.currentBitset.set(4);
    }

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

    /**
     * Utility to set the "targetValue" value
     *
     * @param targetValueValue 
     *            value to set
     */
    public void setTargetValue(float targetValueValue) {
        this.targetValue = targetValueValue;
        this.currentBitset.set(5);
    }

    /**
     * Utility to test if the value of "targetValue" has been set
     *
     * @return boolean
     *            if true the attribute "targetValue" is already set
     *            if false isn't yet
     */
    public boolean targetValueIsSet() {
        return this.currentBitset.get(5);
     }
    
    /**
     * Utility to return the "terminal"
     *
     * @return the value of the attribute "terminal"
     */
    public Terminal getTerminal() {
        return this.terminal;
    }

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

    /**
     * Utility to set the "terminalValue"
     *
     * @param terminalValue
     *            instance to set
     * @param setInverse
     *            boolean to specify whether to set the inverse association
     *            or not
     * @throws LinkageException
     */
    public void setTerminal(
            Terminal terminalValue,
            boolean setInverse) throws LinkageException {
        this.terminal = terminalValue;
        this.currentBitset.set(6);
        if (setInverse) {
            
            if (terminalValue != null) {
                terminalValue.addRegulatingControl(this, false);
            }
        }
    }


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

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

                if (!(model.isCurrentSubsetSet())
                        || (model.getCurrentSubset() == Subset.Equipment)) {
                     boolean typedValue;
                    if (!value.isEmpty()) {
                        typedValue = Boolean
                                .parseBoolean(value);

                        if (!value.equalsIgnoreCase("true")
                                && !value.equalsIgnoreCase("false")) {
                            StringBuilder warnMessage = new StringBuilder(
                                    "The boolean attribute");
                            warnMessage
                                    .append("in class RegulatingControl whose");
                            warnMessage.append(" field is equal to ");
                            warnMessage.append(value);
                            warnMessage
                                    .append("has been interpreted as : false");
                           LOGGER.warn(warnMessage.toString());
                        }

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



                    this.setDiscrete(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("targetRange")) {

                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 targetRange in class "
                                + "RegulatingControl is supposed to be a Float"
                                + " but has not the expected NumberFormat");
                        }

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

                    this.setTargetRange(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("targetValue")) {

                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 targetValue in class "
                                + "RegulatingControl is supposed to be a Float"
                                + " but has not the expected NumberFormat");
                        }

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

                    this.setTargetValue(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("RegulatingControl")) {
            // Particular case : enum !
            if (resource_name.equals("mode")) {

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

                    try {
                        this.setMode(RegulatingControlModeKind
                                .valueOf(RegulatingControlModeKind.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("RegulatingControlModeKind");
                        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("Terminal")) {

                if (!(model.isCurrentSubsetSet())
                        || (model.getCurrentSubset() == Subset.Equipment)) {
                    idTerminal = 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, "RegulatingControl");
                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("RegulatingControl ");
                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("RegulatingControl ");
                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, "RegulatingControl");
                    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("RegulatingControl ");
                    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("RegulatingControl ");
                    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 {

        // TODO : implement vectors (not required according to CIM
        // specifications)

        // TODO : implement vectors (not required according to CIM
        // specifications)
        if (idTerminal != null) {
            Terminal attributeToSet =
                    model.searchTerminal
                    (idTerminal);

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

                try {
                    this.setTerminal(attributeToSet, setInverse);
                } catch(LinkageException e) {
                   LOGGER.error(e.toString(), e);
                    throw new LinkageException(e.getMessage());
                }
            } else if (boundaryModel != null) {
                Terminal attributeToSetFromBoundary = boundaryModel.searchTerminal(idTerminal);
                if(attributeToSetFromBoundary != null) {
                    attributeToSetFromBoundary.setFromBoundary(true);
                    try {
                        model.createTerminal(idTerminal, attributeToSetFromBoundary);
                    } catch (InterpretationException e) {
                       LOGGER.error(e.toString(), e);
                    }
                    boolean setInverse = true;
                    try {
                        this.setTerminal(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 \"Terminal\" and id \"");
                    errorMessage.append(idTerminal);
                    errorMessage.append("\" in \"RegulatingControl\" 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 \"Terminal\" and id \"");
                errorMessage.append(idTerminal);
                errorMessage.append("\" in \"RegulatingControl\" 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 otherRegulatingControl
     *            the instance to copy
     */
    public void copyBase(final RegulatingControl otherRegulatingControl) {
        boolean newdiscrete;
        // assigning primitive type :
        if (otherRegulatingControl.currentBitset.get(1)) {
            newdiscrete = otherRegulatingControl.isDiscrete();
            this.setDiscrete(newdiscrete);
          }
        float newtargetRange;
        // assigning primitive type :
        if (otherRegulatingControl.currentBitset.get(3)) {
            newtargetRange = otherRegulatingControl.getTargetRange();
            this.setTargetRange(newtargetRange);
          }
        // assigning enum type :

        RegulatingControlModeKind newmode;

        if (otherRegulatingControl.currentBitset.get(4)) {
            newmode = otherRegulatingControl.getMode();
            this.setMode(newmode);
        }
        float newtargetValue;
        // assigning primitive type :
        if (otherRegulatingControl.currentBitset.get(5)) {
            newtargetValue = otherRegulatingControl.getTargetValue();
            this.setTargetValue(newtargetValue);
          }

        // 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 (otherRegulatingControl.currentBitset.get(6)) {
            Terminal terminalAssociation = otherRegulatingControl.getTerminal();

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

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

    }

    /**
     * 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)) {
      for (TapChanger tapChanger : this.tapChanger){
               try {
                 xmlsw.writeEmptyElement(CIMURI.CIMURI,"RegulatingControl.TapChanger");
                 xmlsw.writeAttribute(CIMModel.rdfURI, "resource", "#"
                           + tapChanger.getId());
               } catch (XMLStreamException e) {
                 StringBuilder errorMessage = new StringBuilder(
                                    "Error while trying to write the reference to ");
                 errorMessage.append("RegulatingControl ");
                 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);
               }
      }
        }

        if (currentBitset.get(1)) {

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

        if (currentBitset.get(2)) {
      for (RegulatingCondEq regulatingCondEq : this.regulatingCondEq){
               try {
                 xmlsw.writeEmptyElement(CIMURI.CIMURI,"RegulatingControl.RegulatingCondEq");
                 xmlsw.writeAttribute(CIMModel.rdfURI, "resource", "#"
                           + regulatingCondEq.getId());
               } catch (XMLStreamException e) {
                 StringBuilder errorMessage = new StringBuilder(
                                    "Error while trying to write the reference to ");
                 errorMessage.append("RegulatingControl ");
                 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);
               }
      }
        }

        if (currentBitset.get(3)) {

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

        if (currentBitset.get(4)) {
        try {
            // xmlsw.writeCharacters("\t");
            xmlsw.writeEmptyElement(CIMURI.CIMURI,
                    "RegulatingControl.mode");
            xmlsw.writeAttribute(CIMModel.rdfURI, "resource",
                    "http://iec.ch/TC57/2009/CIM-schema-cim14#RegulatingControlModeKind."
                    + getMode());
            // xmlsw.writeCharacters("\n");
        } catch(XMLStreamException e) {
            StringBuilder errorMessage = new StringBuilder(
                    "Error while trying to write the Enum attribute ");
            errorMessage.append("mode");
            errorMessage.append(" in class ");
            errorMessage.append("RegulatingControl ");
            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,
                    "RegulatingControl.targetValue");
            xmlsw.writeCharacters(String.valueOf(getTargetValue()));
            xmlsw.writeEndElement();
            // xmlsw.writeCharacters("\n");
        } catch(XMLStreamException e) {
            StringBuilder errorMessage = new StringBuilder(
                    "Error while trying to write the value of the attribute ");
            errorMessage.append("TargetValue");
            errorMessage.append(" in class ");
            errorMessage.append("RegulatingControl ");
            errorMessage.append("which ID has been initialized to : ");
            errorMessage.append(getId());
            LOGGER.error(errorMessage.toString());
            LOGGER.error(e.toString(), e);
        }
        }

        if (currentBitset.get(6)) {
        if (idTerminal != null) {
            try {
                // xmlsw.writeCharacters("\t");
                xmlsw.writeEmptyElement(CIMURI.CIMURI,
                        "RegulatingControl.Terminal");
                xmlsw.writeAttribute(CIMModel.rdfURI, "resource", "#"
                        + idTerminal);
                // xmlsw.writeCharacters("\n");
            } catch(XMLStreamException e) {
                StringBuilder errorMessage = new StringBuilder(
                        "Error while trying to write the resource attribute ");
                errorMessage.append("Terminal");
                errorMessage.append(" in class ");
                errorMessage.append("RegulatingControl ");
                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 \"RegulatingControl\" 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\"TapChanger\" needs to be set\n");
        }

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

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

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

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

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

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

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

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

        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(1);
        classBitset.set(3);
        classBitset.set(4);
        classBitset.set(5);
        classBitset.set(6);
        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
                terminal = null;
                idTerminal = "";
                this.currentBitset.clear(6);
                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 RegulatingControl clone() {
        RegulatingControl newInstance = new RegulatingControl(this);
        RegulatingControl newInstanceSP = newInstance;
        return newInstanceSP;
    }

}







© 2015 - 2024 Weber Informatics LLC | Privacy Policy