/*
Copyright 2002-2006 The Members of the OSS through Java(TM) Initiative.
All rights reserved. Use is subject to license terms.
 */
package ossj.common.cbe;

import javax.oss.cbe.CBEManagedEntityKey;
import javax.oss.cbe.CharacteristicSpecification;
import javax.oss.cbe.CharacteristicValue;
import javax.oss.cbe.CBEManagedEntityValue;
import ossj.common.AttributeManager;
import ossj.common.Utils;
import java.util.Map;
import java.util.HashMap;
import java.util.Iterator;
/**
 * An implementation class for the <CODE>javax.oss.cbe.CBEManagedEntityValue</CODE> interface.
 *
 * @see javax.oss.AttributeAccess
 *
 * @see javax.oss.cbe.CBEManagedEntityValue
 *
 * @see javax.oss.ManagedEntityValue
 *
 * @author OSS through Java(tm) Initiative, Vincent Perrot Sun Microsystems Inc.
 * @version 1.3
 * @since January 2006
 */


public class CBEManagedEntityValueImpl
        extends ossj.common.ManagedEntityValueImpl
        implements CBEManagedEntityValue {
    
    /**
     * Constructs a new CBEManagedEntityValueImpl with empty attributes.
     *
     */
    
    public CBEManagedEntityValueImpl() {
        super();
        setManagedEntityKeyInstance( new CBEManagedEntityKeyImpl());
    }
    
    private static final String[] attributeNames = {
        CBEManagedEntityValue.SUB_GRAPH_ID,
        CBEManagedEntityValue.CHARACTERIZED_BY,
        CBEManagedEntityValue.DESCRIBED_BY
    };
    
    private static final String[] settableAttributeNames = {
        CBEManagedEntityValue.SUB_GRAPH_ID,
        CBEManagedEntityValue.CHARACTERIZED_BY,
        CBEManagedEntityValue.DESCRIBED_BY
    };
    
    private static final String[] optionalAttributeNames = {
        CBEManagedEntityValue.CHARACTERIZED_BY,
        CBEManagedEntityValue.DESCRIBED_BY
    };
    
    //
    // Configuration of AttributeManager and AttributeAccess
    //
    protected void addAttributesTo(AttributeManager anAttributeManager) {
        if (CBEManagedEntityValueImpl.attributeNames != null) {
            anAttributeManager.addAttributes(this.attributeNames);
            super.addAttributesTo(anAttributeManager);
        }
    }
    
    protected void configureAttributes(AttributeManager anAttributeManager) {
        if (CBEManagedEntityValueImpl.settableAttributeNames != null) {
            anAttributeManager.setSettableAttributes(CBEManagedEntityValueImpl.settableAttributeNames);
            anAttributeManager.setSupportedOptionalAttributes(CBEManagedEntityValueImpl.optionalAttributeNames);
            super.configureAttributes(anAttributeManager);
        }
    }
    
    /**
     * Holds the Attribute manager that manage the optional fields
     */
    private static AttributeManager attributemanager = null;
    
    protected AttributeManager getAttributeManager() {
        return attributemanager;
    }
    protected AttributeManager makeAttributeManager() {
        attributemanager = new AttributeManager();
        return attributemanager;
    }
    
    
    //==================================================================
    // FACTORIES AND ATTRIBUTE TYPE FOR ================================
    //==================================================================
    
    public javax.oss.cbe.CBEManagedEntityKey makeCBEManagedEntityKey(){
        return (CBEManagedEntityKey) makeManagedEntityKey();
    }
    
    /**
     * Init the Map Attribute Name/Attribute Type
     * Init the enumeration Map
     */
    protected void initAttributeTypes(){
        String[] list = new String[1];
        list[0] = "long";
        addAttributeTypes("subGraphId", list);
        list[0] = "[Ljavax.oss.cbe.CharacteristicSpecification;";
        addAttributeTypes(CBEManagedEntityValue.CHARACTERIZED_BY, list);
        list[0] = "[Ljavax.oss.cbe.CharacteristicValue;";
        addAttributeTypes(CBEManagedEntityValue.DESCRIBED_BY, list);
        super.initAttributeTypes();
    }
    
    private long _cbemanagedentityvalueimpl_subGraphId;
    private CharacteristicSpecification[] _cbemanagedentityvalueimpl_characterizedBy=null;
    
    /**
     * Changes the CBEManagedEntityKey to be equal to the given argument.
     *
     * This method support a null argument.
     *
     * @param value the new CBEManagedEntityKey for this object.
     * @exception java.lang.IllegalArgumentException - Is thrown to report
     * that a bad argument was provided to the method.
     */
    
    public void setCBEManagedEntityKey(javax.oss.cbe.CBEManagedEntityKey value)
    throws java.lang.IllegalArgumentException    {
        setManagedEntityKey(value);
    }
    
    
    /**
     * Returns this CBEManagedEntityValueImpl's CBEManagedEntityKey
     *
     * @return the CBEManagedEntityKey
     *
     */
    
    public javax.oss.cbe.CBEManagedEntityKey getCBEManagedEntityKey()
    throws java.lang.IllegalStateException {
        return (javax.oss.cbe.CBEManagedEntityKey)getManagedEntityKey();
    }
    
    /**
     * Changes the subGraphId to be equal to the given argument.
     *
     * This method support a null argument.
     *
     * @param value the new subGraphId for this object.
     * @exception java.lang.IllegalArgumentException - Is thrown to report
     * that a bad argument was provided to the method.
     */
    
    public void setSubGraphId(long value)
    throws java.lang.IllegalArgumentException    {
        setDirtyAttribute(CBEManagedEntityValue.SUB_GRAPH_ID);
        _cbemanagedentityvalueimpl_subGraphId = value;
    }
    
    
    /**
     * Returns this CBEManagedEntityValueImpl's subGraphId
     *
     * @return the subGraphId
     *
     */
    
    public long getSubGraphId()
    throws java.lang.IllegalStateException {
        checkAttribute(CBEManagedEntityValue.SUB_GRAPH_ID);
        return _cbemanagedentityvalueimpl_subGraphId;
    }
    
    /**
     *
     * Attribute getter for characterizedBy.
     *
     *  Contains the list of CharacteristicSpecification associated with this entity.
     * The populated flag of this attribute is not managed as the other attribute, as it potentially contains other dynamic attribute names also known as CharacteristicSpecification.
     * IllegalStateException is thrown only when the hidden value is empty and when ispopulated(CBEManagedEntityValue.CHARACTERIZED_BY) return false.
     *
     *
     * @return the value of the characterizedBy field.
     * @throws java.lang.IllegalStateException - if the attribute is not populated.
     * @throws javax.oss.OssUnsupportedAttributeException - if the attribute is not supported.
     *
     */
    public javax.oss.cbe.CharacteristicSpecification[] getCharacterizedBy()
    throws  java.lang.IllegalStateException, javax.oss.OssUnsupportedAttributeException{
        try {
            checkAttribute(CBEManagedEntityValue.CHARACTERIZED_BY);
        } catch (java.lang.IllegalStateException e) {
            if (_cbemanagedentityvalueimpl_characterizedBy == null
                    || _cbemanagedentityvalueimpl_characterizedBy.length == 0)
                throw new java.lang.IllegalStateException("Attribute \"" + CBEManagedEntityValue.CHARACTERIZED_BY
                        + "\" is not populated and no CharacteristicSpecification have been provided");
        }
        return _cbemanagedentityvalueimpl_characterizedBy;
    }
    
    /**
     *
     * Attribute Type getter for characterizedBy.
     *
     * @return the valid set of types for the characterizedBy field.
     *
     */
    public String[] attributeTypeForCharacterizedBy() {
        return attributeTypeFor(CBEManagedEntityValue.CHARACTERIZED_BY);
    }
    
    /**
     * Attribute setter for characterizedBy.
     *
     *  Contains the list of CharacteristicSpecification associated with this entity.
     * @param value - the value to use to set the characterizedBy attribute.
     * @throws java.lang.IllegalArgumentException
     *         Thrown to report that a bad argument was provided to the method.
     * @throws javax.oss.OssUnsupportedAttributeException - if the attribute is not supported.
     *
     */
    public void setCharacterizedBy(javax.oss.cbe.CharacteristicSpecification[] value)
    throws  javax.oss.OssUnsupportedAttributeException,
            java.lang.IllegalArgumentException{
        setDirtyAttribute(CBEManagedEntityValue.CHARACTERIZED_BY);
        _cbemanagedentityvalueimpl_characterizedBy = value;
    }
    
    
    
    /**
     * Factory method for CharacteristicSpecification.
     *
     * @param howMany - Number of instances to make
     * @param typeToMake - name of the type to be made
     * @return a new instance of CharacteristicSpecification
     *
     * @throws java.lang.IllegalArgumentException - if the argument is invalid
     */
    public javax.oss.cbe.CharacteristicSpecification[] makeCharacteristicSpecifications(int nb, String type){
        if(type.equals("javax.oss.cbe.CharacteristicSpecification") || type.equals("ossj.common.cbe.CharacteristicSpecificationImpl")) {
            CharacteristicSpecificationImpl[] theArray = new CharacteristicSpecificationImpl[nb];
            for (int i = nb-1;i>=0;i--){
                theArray[i] = new CharacteristicSpecificationImpl();
            }
            return theArray;
        } else {
            return null;
        }
    }
    
    /**
     *
     * Attribute getter for describedBy.
     *
     *  Contains the list of CharacteristicValues associated with this entity.
     *
     *
     * @return the value of the describedBy field.
     * @throws java.lang.IllegalStateException - if the attribute is not populated.
     * @throws javax.oss.OssUnsupportedAttributeException - if the attribute is not supported.
     *
     */
    public javax.oss.cbe.CharacteristicValue[] getDescribedBy()
    throws  java.lang.IllegalStateException, javax.oss.OssUnsupportedAttributeException{
        checkAttribute(CBEManagedEntityValue.DESCRIBED_BY);
        int i = 0;
        CharacteristicValueImpl[] theArray = new CharacteristicValueImpl[simpleCharacteristicMap.size()];
        for (String key : this.simpleCharacteristicMap.keySet()){
            
            theArray[i++] = new CharacteristicValueImpl(key,this.simpleCharacteristicMap.get(key));
        }
        return theArray;
    }
    
    /**
     *
     * Attribute Type getter for characterizedBy.
     *
     * @return the valid set of types for the characterizedBy field.
     *
     */
    public String[] attributeTypeForDescribedBy() {
        return attributeTypeFor(CBEManagedEntityValue.DESCRIBED_BY);
    }
    
    /**
     * Attribute setter for describedBy.
     *
     *  Contains the list of CharacteristicValue associated with this entity.
     * @param value - the value to use to set the describedBy attribute.
     * @throws java.lang.IllegalArgumentException
     *         Thrown to report that a bad argument was provided to the method.
     * @throws javax.oss.OssUnsupportedAttributeException - if the attribute is not supported.
     *
     */
    public void setDescribedBy(javax.oss.cbe.CharacteristicValue[] value)
    throws  javax.oss.OssUnsupportedAttributeException,
            java.lang.IllegalArgumentException{
        //VP is it necessary?
        setDirtyAttribute(CBEManagedEntityValue.DESCRIBED_BY);
        if (value == null) {
            simpleCharacteristicMap.clear();
        }else{
            for (int j = value.length - 1; j >= 0 ; j--) {
                simpleCharacteristicMap.put(value[j].getCharacteristic(),value[j].getValue());
            }
        }
    }
    
    
    
    /**
     * Factory method for CharacteristicValue.
     *
     * @param howMany - Number of instances to make
     * @param typeToMake - name of the type to be made
     * @return a new instance of CharacteristicValue
     *
     * @throws java.lang.IllegalArgumentException - if the argument is invalid
     */
    public javax.oss.cbe.CharacteristicValue[] makeCharacteristicValues(int nb, String type){
        if(type.equals("javax.oss.cbe.CharacteristicValue") || type.equals("ossj.common.cbe.CharacteristicValueImpl")) {
            CharacteristicValueImpl[] theArray = new CharacteristicValueImpl[nb];
            for (int i = nb-1;i>=0;i--){
                theArray[i] = new CharacteristicValueImpl();
            }
            return theArray;
        } else {
            return null;
        }
    }
    
    /**
     *  This method helps the client to distinguish between static attributes,
     *   i.e. those wich are defined in a java interface, and characteristics,
     *  which are the way SID models dynamic attributes.
     *
     *
     * @return boolean true when the given name correspond to a CharacteristicSpecification.getName() of the characterizedBy attribute
     * @param characteristicSpecName - is compared to CharacteristicSpecification.getName() of the CharacteristicSpecifications list returned by getCharacterzedBy()
     *
     * @throws javax.oss.OssIllegalArgumentException
     */
    public boolean isCharacteristic(java.lang.String characteristicSpecName) {
        if (characteristicSpecName != null
                && characteristicSpecName != ""
                && _cbemanagedentityvalueimpl_characterizedBy != null
                && _cbemanagedentityvalueimpl_characterizedBy.length >0){
            for (int i = _cbemanagedentityvalueimpl_characterizedBy.length - 1; i >=0 ; i--) {
                if (characteristicSpecName.equals(_cbemanagedentityvalueimpl_characterizedBy[i].getName())){
                    return true;
                }
            }
        }
        return false;
    }
    
    //========================================================================
    // over load the AttributeAcces methods to handle Characteristic content as
    // attribute of entityValue.
    //
    // the population flag is determine by the presence or the absence of the
    // attribute in the haskMap.
    // The CharacteristicSpecification.getName is used as attributeName.
    
    // TODO i need this for the AAImpl initialization - it's a duplo of base class's private memeber
    
    protected java.util.Map<String, Object> simpleCharacteristicMap = new java.util.HashMap<String, Object>();
    
    /**
     * Check if the method applies to Characteristc first, else call the AttributeAccess one.
     * Assume that null is not valid for CharacteristicSpecification
     * @see javax.oss.AttributeAccess#setAttributeValue
     */
    
    public void setAttributeValue(java.lang.String attributeName, java.lang.Object newValue)
    throws java.lang.IllegalArgumentException {
        if (attributeName != null
                && _cbemanagedentityvalueimpl_characterizedBy != null
                && _cbemanagedentityvalueimpl_characterizedBy.length >0){
            String[] list = new String[1];
            int i = _cbemanagedentityvalueimpl_characterizedBy.length - 1;
            for (; i >=0 ; i--) {
                if (attributeName.equals(_cbemanagedentityvalueimpl_characterizedBy[i].getName())){
                    if (newValue == null){
                        // equivalent to unpopulated
                        setDirtyAttribute(CBEManagedEntityValue.DESCRIBED_BY);
                        simpleCharacteristicMap.put(attributeName, newValue);
                    } else {
                        if (_cbemanagedentityvalueimpl_characterizedBy[i].getType().equals(newValue.getClass().getName())){
                            setDirtyAttribute(CBEManagedEntityValue.DESCRIBED_BY);
                            simpleCharacteristicMap.put(attributeName, newValue);
                            // to be sure that only one attribute is set ....
                            return;
                        } else {
                            throw new java.lang.IllegalArgumentException("Provided value of Type ["+newValue.getClass().getName()
                            +"] is not valid for type ["+_cbemanagedentityvalueimpl_characterizedBy[i].getType()+"]");
                        }
                    }
                }
            }
            // if i < 0  then no attribute found in the Characteristic list call the default anyway....
            if (i < 0) {
                super.setAttributeValue(attributeName, newValue);
            }
        } else {
            super.setAttributeValue(attributeName, newValue);
        }
    }
    
    /**
     * Check if the method applies to Characteristc first, else call the AttributeAccess one.
     * @see javax.oss.AttributeAccess#getAttributeValue
     */
    public java.lang.Object getAttributeValue(java.lang.String attributeName)
    throws java.lang.IllegalArgumentException {
        if (isCharacteristic(attributeName)) {
            Object value = simpleCharacteristicMap.get(attributeName);
            if (value == null){
                throw new java.lang.IllegalStateException("Attribute \"" + attributeName
                        + "\" is not populated");
            }else{
                return value;
            }
        } else {
            return super.getAttributeValue(attributeName);
        }
    }
    
    /**
     * Check if the method applies to Characteristc first, else call the AttributeAccess one.
     * @see javax.oss.AttributeAccess#getAttributeNames
     */
    public String[] getAttributeNames() {
        String[] superAttr = super.getAttributeNames();
        if (_cbemanagedentityvalueimpl_characterizedBy == null
                ||  _cbemanagedentityvalueimpl_characterizedBy.length == 0 ){
            return superAttr;
        } else {
            String[] newAttrs = new String[superAttr.length + this._cbemanagedentityvalueimpl_characterizedBy.length];
            System.arraycopy(superAttr,0,newAttrs,0,superAttr.length);
            int i = superAttr.length;
            for (CharacteristicSpecification key : this._cbemanagedentityvalueimpl_characterizedBy){
                newAttrs[i++] = key.getName();
            }
            return newAttrs;
        }
    }
    
    /**
     * Check if the method applies to Characteristc first, else call the AttributeAccess one.
     * @see javax.oss.AttributeAccess#getPopulatedAttributeNames
     */
    public String[] getPopulatedAttributeNames() {
        String[] superAttr = super.getPopulatedAttributeNames();
        
        int nbOfpopulatedCharact = 0;
        for (String key : this.simpleCharacteristicMap.keySet()){
            if (this.simpleCharacteristicMap.get(key) != null) nbOfpopulatedCharact++;
        }
        
        String[] newAttrs = new String[superAttr.length + nbOfpopulatedCharact];
        
        System.arraycopy(superAttr,0,newAttrs,0,superAttr.length);
        int i = superAttr.length;
        for (String key : this.simpleCharacteristicMap.keySet()){
            if (this.simpleCharacteristicMap.get(key) != null)
                newAttrs[i++] = key;
        }
        return newAttrs;
    }
    
    /**
     * Check if the method applies to Characteristc first, else call the AttributeAccess one.
     * @see javax.oss.AttributeAccess#attributeTypeFor
     */
    public String[] attributeTypeFor(String attributeName) {
        if (attributeName != null
                && _cbemanagedentityvalueimpl_characterizedBy != null
                && _cbemanagedentityvalueimpl_characterizedBy.length >0){
            String[] list = new String[1];
            list[0] = null;
            for (int i = _cbemanagedentityvalueimpl_characterizedBy.length - 1; i >=0 ; i--) {
                if (attributeName.equals(_cbemanagedentityvalueimpl_characterizedBy[i].getName())){
                    list[0] = _cbemanagedentityvalueimpl_characterizedBy[i].getType();
                    return list;
                }
            }
        }
        return super.attributeTypeFor(attributeName);
    }
    
    /**
     * Check if the method applies to Characteristc first, else call the AttributeAccess one.
     * @see javax.oss.AttributeAccess#getAllPopulatedAttributes
     */
    public Map 	getAllPopulatedAttributes() {
        Map superAttr = super.getAllPopulatedAttributes();
        
        for (String key : this.simpleCharacteristicMap.keySet()){
            if (simpleCharacteristicMap.get(key) != null )
                superAttr.put(key,simpleCharacteristicMap.get(key));
        }
        return superAttr;
    }
    
    /**
     * Check if the method applies to Characteristc first, else call the AttributeAccess one.
     * @see javax.oss.AttributeAccess#getAttributeValues
     */
    public Map getAttributeValues(String[] attributeNames) {
        Map<String,Object> newValues = new HashMap<String,Object>();
        for (String name:attributeNames){
            newValues.put(name,getAttributeValue(name));
        }
        return newValues;
    }
    
    /**
     * Check if the method applies to Characteristc first, else call the AttributeAccess one.
     * @see javax.oss.AttributeAccess#getSupportedOptionalAttributeNames
     */
    public String[] getSupportedOptionalAttributeNames() {
        String[] superAttr = super.getSupportedOptionalAttributeNames();
        if (_cbemanagedentityvalueimpl_characterizedBy == null) {
            return superAttr;
        } else {
            String[] newAttrs = new String[superAttr.length + _cbemanagedentityvalueimpl_characterizedBy.length];
            
            System.arraycopy(superAttr,0,newAttrs,0,superAttr.length);
            int i = superAttr.length;
            for (CharacteristicSpecification key : _cbemanagedentityvalueimpl_characterizedBy){
                newAttrs[i++] = key.getName();
            }
            return newAttrs;
        }
    }
    
    /**
     * Check if the method applies to Characteristc first, else call the AttributeAccess one.
     * isEnumrationBased return always false for attribute of the CharacteristicSpecification type
     * @see javax.oss.AttributeAccess#isEnumerationBased
     */
    public boolean isEnumerationBased(String attributeName) {
        if (isCharacteristic(attributeName)) {
            return false;
        } else {
            return super.isEnumerationBased(attributeName);
        }
    }
    /**
     * Check if the method applies to Characteristc first, else call the AttributeAccess one.
     * @see javax.oss.AttributeAccess#isFullyPopulated
     */
    public boolean isFullyPopulated() {
        return ((simpleCharacteristicMap.size() == _cbemanagedentityvalueimpl_characterizedBy.length)
        && super.isFullyPopulated());
    }
    
    /**
     * Check if the method applies to Characteristc first, else call the AttributeAccess one.
     * @see javax.oss.AttributeAccess#isPopulated
     */
    public boolean isPopulated(String attributeName) {
        if (isCharacteristic(attributeName)) {
            return (simpleCharacteristicMap.containsKey(attributeName) && simpleCharacteristicMap.get(attributeName)!= null);
        } else {
            return super.isPopulated(attributeName);
        }
    }
    
    /**
     * Check if the method applies to Characteristc first, else call the AttributeAccess one.
     * @see javax.oss.AttributeAccess#make
     */
    public  Object make(String typeName) {
        if (typeName != null && typeName != ""
                && _cbemanagedentityvalueimpl_characterizedBy != null
                && _cbemanagedentityvalueimpl_characterizedBy.length >0){
            int i = _cbemanagedentityvalueimpl_characterizedBy.length - 1;
            for (; i >=0 ; i--) {
                if (typeName.equals(_cbemanagedentityvalueimpl_characterizedBy[i].getType())){
                    return super.make(_cbemanagedentityvalueimpl_characterizedBy[i].getType());
                }
            }
            return super.make(typeName);
        } else {
            return super.make(typeName);
        }
    }
    
    /**
     * Check if the method applies to Characteristc first, else call the AttributeAccess one.
     * @see javax.oss.AttributeAccess#setAttributeValues
     */
    public void setAttributeValues(Map attributeNamesAndValuePairs){
        Iterator it = attributeNamesAndValuePairs.entrySet().iterator();
        Map.Entry anEntry;
        
        while (it.hasNext()) {
            anEntry = (Map.Entry) it.next();
            setAttributeValue((String) anEntry.getKey(), anEntry.getValue());
        }
    }
    
    /**
     * Check if the method applies to Characteristc first, else call the AttributeAccess one.
     * @see javax.oss.AttributeAccess#unpopulateAllAttributes
     */
    public void unpopulateAllAttributes() {
        super.unpopulateAllAttributes();
        for (String key:simpleCharacteristicMap.keySet())
            simpleCharacteristicMap.put(key, null);
    }
    
    /**
     * Check if the method applies to Characteristc first, else call the AttributeAccess one.
     * @see javax.oss.AttributeAccess#unpopulateAttribute
     */
    public void unpopulateAttribute(String attributeName){
        if ((attributeName == null) || attributeName.equals("")) {
            throw new java.lang.IllegalArgumentException(
                    "Null or empty String are invalid attribute names.");
        }
        if (isCharacteristic(attributeName)) {
            if (simpleCharacteristicMap.containsKey(attributeName))
                simpleCharacteristicMap.put(attributeName, null);
        } else {
            super.unpopulateAttribute(attributeName);
        }
    }
//=========================== end section ==========================
    
    
    
    /**
     * Creates a new object of the same class and with the same contents as this object.
     * @return a clone of this instance.
     */
    public Object clone() {
        CBEManagedEntityValue val = null;
        val = (CBEManagedEntityValue)super.clone();
        
        if( isPopulated(CBEManagedEntityValue.CHARACTERIZED_BY)) {
            if( this.getCharacterizedBy()!=null)
                val.setCharacterizedBy((javax.oss.cbe.CharacteristicSpecification[])((javax.oss.cbe.CharacteristicSpecification[]) this.getCharacterizedBy()).clone());
            else
                val.setCharacterizedBy( null );
        }
        if( isPopulated(CBEManagedEntityValue.DESCRIBED_BY)) {
            if( this.getDescribedBy()!=null)
                val.setDescribedBy((javax.oss.cbe.CharacteristicValue[])((javax.oss.cbe.CharacteristicValue[]) this.getDescribedBy()).clone());
            else
                val.setDescribedBy( null );
        }
        
        return val;
    }
    
    /**
     * Checks whether two CBEManagedEntityValue are equal.
     * The result is true if and only if the argument is not null
     * and is an CBEManagedEntityValue object that has the arguments.
     *
     * @param value the Object to compare with this CBEManagedEntityValue
     * @return if the objects are equal; false otherwise.
     */
    
    public boolean equals(Object value) {
        if ( this == value ){ return true;}
        if ( (value != null) && ( value instanceof CBEManagedEntityValue)) {
            CBEManagedEntityValue argVal = (CBEManagedEntityValue) value;
            return Utils.compareAttributeAccess( this, argVal );
        }
        return false;
    }
    
    public String toString(){
        String[] names = getAttributeNames();
        String res = "";
        for (int i = names.length-1;i>=0;i--){
            res+=names[i]+" = ";
            try {
                res+=getAttributeValue(names[i]);
            } catch (Exception e) {
                res+=e.getClass().getName();
            }
            res+="\n";
        }
        if (_cbemanagedentityvalueimpl_characterizedBy != null){
            res+="CharacteristicSpecification ("+_cbemanagedentityvalueimpl_characterizedBy.length+")=\n";
            for (int i = _cbemanagedentityvalueimpl_characterizedBy.length -1 ; i>=0;i--)
                res+="    ("+_cbemanagedentityvalueimpl_characterizedBy[i].getType()+")"+_cbemanagedentityvalueimpl_characterizedBy[i].getName()+"\n";
        } else {
            res+="no CharacteristicSpecification";
        }
        return res;
    }
}
