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

cim1.model.IdentifiedObject 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 "IdentifiedObject.java" represents the
 * class IdentifiedObject : CIMInstance
 *
 *    + description   0..1   String 
 *    + aliasName   0..1   String 
 *    + name   0..1   String 

 */
public class IdentifiedObject extends CIMInstance {

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

    /**
     * Attribute "description"
     *
     * Comment from profile:
     * The description is a free human readable text describing or naming the object. It may be non unique and may not correlate to a naming hierarchy.
     */
    public String description;

    /**
     * Attribute "aliasName"
     *
     * Comment from profile:
     * The aliasName is free text human readable name of the object alternative to IdentifiedObject.name. It may be non unique and may not correlate to a naming hierarchy.In the UCTE profile the aliasName is used to hold the EIC code.    The code length is 16 characters.    Not all CIM classes have an EIC code so the attribute is optional.   
     */
    public String aliasName;

    /**
     * Attribute "name"
     *
     * Comment from profile:
     * The name is a free text human readable name of the object. It may be non unique and may not correlate to a naming hierarchy.This attribute is required on all instances in this Profile that inherit from IdentifiedObject except for the following Classes: 1) BaseVoltage; 2) Terminal; 3) TransformerWinding; 4) RatioTapChanger; 5) PhaseTapChanger; 6) OperationalLImitSet; 7) CurrentLimit; and, 8) VoltageLimit.
     */
    public String name;

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

    /**
     * Utility to set the "description" value
     *
     * @param descriptionValue 
     *            value to set
     */
    public void setDescription(String descriptionValue) {
        this.description = descriptionValue;
        this.currentBitset.set(0);
    }

    /**
     * Utility to test if the value of "description" has been set
     *
     * @return boolean
     *            if true the attribute "description" is already set
     *            if false isn't yet
     */
    public boolean descriptionIsSet() {
        return this.currentBitset.get(0);
     }
    
    /**
     * Utility to return the "aliasName" value
     *
     * @return the value of the attribute "aliasName"
     */
    public String getAliasName() {
        return this.aliasName;
    }

    /**
     * Utility to set the "aliasName" value
     *
     * @param aliasNameValue 
     *            value to set
     */
    public void setAliasName(String aliasNameValue) {
        this.aliasName = aliasNameValue;
        this.currentBitset.set(1);
    }

    /**
     * Utility to test if the value of "aliasName" has been set
     *
     * @return boolean
     *            if true the attribute "aliasName" is already set
     *            if false isn't yet
     */
    public boolean aliasNameIsSet() {
        return this.currentBitset.get(1);
     }
    
    /**
     * Utility to return the "name" value
     *
     * @return the value of the attribute "name"
     */
    public String getName() {
        return this.name;
    }

    /**
     * Utility to set the "name" value
     *
     * @param nameValue 
     *            value to set
     */
    public void setName(String nameValue) {
        this.name = nameValue;
        this.currentBitset.set(2);
    }

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


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

    /**
     * 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);


        // The function has been called by a concrete class :
        // the checking has already been done so we can clear everything !

        this.currentBitset.clear(0);
        this.currentBitset.clear(1);
        this.currentBitset.clear(2);

    }

    /**
     * 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("IdentifiedObject")) {

        if (attr_name.equals("description")) {
            this.setDescription(value);
            return;
        }

        if (attr_name.equals("aliasName")) {
            this.setAliasName(value);
            return;
        }

        if (attr_name.equals("name")) {
            this.setName(value);
            return;
        }
            StringBuilder errorMessage = new StringBuilder("The attribute \"");
            errorMessage.append(attr_name);
            errorMessage.append("\" in class \"");
            errorMessage.append(class_name);
            errorMessage.append("\" could not be found in the model !");
            throw new InterpretationException(errorMessage.toString());
        } else {
            StringBuilder errorMessage = new StringBuilder("The attribute \"");
            errorMessage.append(attr_name);
            errorMessage.append("\" in class \"");
            errorMessage.append(class_name);
            errorMessage.append("\" could not be found in the model !");
            throw new InterpretationException(errorMessage.toString());
        }
    }

    /**
     * Utility to read a reference to a resource
     * This function is called by the CIMModel
     *
     * @param class_name
     *            the read name of class
     * @param resource_name
     *            the read name of the associated resource
     * @param id
     *            the id of the associated resource
     * @param model
     *            the model this class belongs to
     * @throws InterpretationException
     */
    @Override
    public void readResource(final String class_name,
            final String resource_name, final String id, CIMModel model)
            throws InterpretationException, LinkageException {
        if (class_name.equals("IdentifiedObject")) {
        } else {
            StringBuilder errorMessage = new StringBuilder("The association \"");
            errorMessage.append(resource_name);
            errorMessage.append("\" in class \"");
            errorMessage.append(class_name);
            errorMessage.append("\" could not be found in the model !");
            throw new InterpretationException(errorMessage.toString());
        }
    }

    /**
     * Utility to write the content into the CIM XML format
     *
     * @param writeID
     *            specifies whether to write the XML "id" attribute (this is used for describing concrete class)
     * @param xmlsw
     *            XMLStreamWriter where are stored the elements to write
     */
    @Override
    public void write(XMLStreamWriter xmlsw, boolean writeID) {

        /*
         * In previous versions, we used to check the consistency
         * of the instance in the context but this task is now
         * performed by the model before attempting to write.
         * Therefore each instance can now be written even if
         * it is not consistent !
         */

        writeClass(xmlsw);
        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 !
         */

        // abstract class
        writeClass(xmlsw);
        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 {
        removeFromUnresolved();
    }

    /**
     * Utility to check whether this class is consistent according to a subset
     *
     * @param subset
     *            the subset defining the context in which to check whether this class is consistent
     * @return a ConsistencyCheck instance whose boolean attribute (consistent)
     *         indicates if this class is consistent and whose String attribute
     *         (message)
     *         indicates why this class is not consistent if it is not
     */
    @Override
    public ConsistencyCheck modelConsistency(final Subset subset) {
        BitSet intersection = new BitSet(this.minBitsets.get(subset).length());
        intersection.or(this.minBitsets.get(subset));
        // we create a copy of minBitsets.get(subset)
        intersection.and(this.currentBitset);
        boolean consistent = (this.minBitsets.get(subset).equals(intersection));
        StringBuilder message = new StringBuilder("");

        if (!consistent) {
            message.append(getMessageForConsistency(this.minBitsets.get(subset)));
        }

        return new ConsistencyCheck(consistent, message.toString());
    }

    /**
     * Utility to check whether this class is consistent in a "merged" context
     *
     * @return a ConsistencyCheck instance whose boolean attribute (consistent)
     *         indicates if this class is consistent and whose String attribute
     *         (message)
     *         indicates why this class is not consistent if it is not
     */
    @Override
    public ConsistencyCheck modelConsistency() {
        BitSet intersection = new BitSet(this.minBitset.length());
        intersection.or(this.minBitset);
        // we create a copy of minBitSet
        intersection.and(this.currentBitset);
        boolean consistent = (this.minBitset.equals(intersection));
        StringBuilder message = new StringBuilder("");

        if (!consistent) {
        message.append(getMessageForConsistency(this.minBitset));
        }

        return new ConsistencyCheck(consistent, message.toString());
    }

    /**
     * Utility to copy the "base" of an other instance of the same class
     * This utility does not copy the associations with other instances from
     * the instance to copy
     *
     * @param otherIdentifiedObject
     *            the instance to copy
     */
    public void copyBase(final IdentifiedObject otherIdentifiedObject) {
        String newdescription;
        // assigning primitive type :
        if (otherIdentifiedObject.currentBitset.get(0)) {
            newdescription = otherIdentifiedObject.getDescription();
            this.setDescription(newdescription);
          }
        String newaliasName;
        // assigning primitive type :
        if (otherIdentifiedObject.currentBitset.get(1)) {
            newaliasName = otherIdentifiedObject.getAliasName();
            this.setAliasName(newaliasName);
          }
        String newname;
        // assigning primitive type :
        if (otherIdentifiedObject.currentBitset.get(2)) {
            newname = otherIdentifiedObject.getName();
            this.setName(newname);
          }
        // 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.

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

    }

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

        if (currentBitset.get(2)) {

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

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

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

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

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

         // This class is not "concrete" : it is not supposed to be instanciated directly
         // subset is not set : it will be set by subclass
        // attribute "description" is optional :
        this.minBitset.clear(0);
        // attribute "aliasName" is optional :
        this.minBitset.clear(1);
        // attribute "name" is optional :
        this.minBitset.clear(2);
        // every subset has the same minsubset :
        this.minBitsets.put(Subset.StateVariables, this.minBitset);
        // every subset has the same minsubset :
        this.minBitsets.put(Subset.Topology, this.minBitset);
        // every subset has the same minsubset :
        this.minBitsets.put(Subset.Equipment, this.minBitset);
    }



    /**
     * Utility to clear the associations of this class belonging to a
     * specific subset
     *
     * @param subset
     *            the subset from which to clear the associations of this class
     */
    @Override
    protected void clearAssociations(final Subset subset) {

        switch (subset) {
            case StateVariables: {
                break;
            }
            case Topology: {
                break;
            }
            case Equipment: {
                break;
            }
            default: // nothing to clear
        }
    }

    /**
     * Utility returning a copy of the "base" of this instance
     * This utility does not copy the associations with other instances
     *
     * @return a clone of this instance
     */
    public IdentifiedObject clone() {
        IdentifiedObject newInstance = new IdentifiedObject(this);
        IdentifiedObject newInstanceSP = newInstance;
        return newInstanceSP;
    }

}







© 2015 - 2024 Weber Informatics LLC | Privacy Policy