Convert the value according the type of DeviceData.

@param booleanValue
the value to insert on DeviceData
@param deviceDataArgin
the DeviceData attribute to write
@param dataType
the type of inserted data
@throws DevFailed
162063
public static void insertFromBoolean(final Boolean booleanValue,
	    final DeviceData deviceDataArgin, final int dataType) throws DevFailed {

	Integer integerValue = 0;
	if (booleanValue.booleanValue()) {
	    integerValue = 1;
	}

	switch (dataType) {
	case TangoConst.Tango_DEV_SHORT:
	    deviceDataArgin.insert(integerValue.shortValue());
	    break;
	case TangoConst.Tango_DEV_USHORT:
	    deviceDataArgin.insert_us(integerValue.shortValue());
	    break;
	case TangoConst.Tango_DEV_CHAR:
	    Except.throw_exception("TANGO_WRONG_DATA_ERROR",
		    "input type Tango_DEV_CHAR not supported",
		    "CommandHelper.insertFromBoolean(Boolean value,deviceDataArgin)");
	    break;
	case TangoConst.Tango_DEV_UCHAR:
	    deviceDataArgin.insert(integerValue.shortValue());
	    break;
	case TangoConst.Tango_DEV_LONG:
	    deviceDataArgin.insert(integerValue.intValue());
	    break;
	case TangoConst.Tango_DEV_ULONG:
	    deviceDataArgin.insert_ul(integerValue.longValue());
	    break;
	case TangoConst.Tango_DEV_LONG64:
	    deviceDataArgin.insert_ul(integerValue.intValue());
	    break;
	case TangoConst.Tango_DEV_ULONG64:
	    deviceDataArgin.insert_u64(integerValue.longValue());
	    break;
	case TangoConst.Tango_DEV_INT:
	    deviceDataArgin.insert(integerValue.intValue());
	    break;
	case TangoConst.Tango_DEV_FLOAT:
	    deviceDataArgin.insert(integerValue.floatValue());
	    break;
	case TangoConst.Tango_DEV_DOUBLE:
	    deviceDataArgin.insert(integerValue.doubleValue());
	    break;
	case TangoConst.Tango_DEV_STRING:
	    deviceDataArgin.insert(Boolean.toString(booleanValue.booleanValue()));
	    break;
	case TangoConst.Tango_DEV_BOOLEAN:
	    deviceDataArgin.insert(booleanValue.booleanValue());
	    break;
	case TangoConst.Tango_DEV_STATE:
	    deviceDataArgin.insert(DevState.from_int(integerValue.intValue()));
	    break;
	default:
	    Except.throw_exception("TANGO_WRONG_DATA_ERROR", "input type "
		    + deviceDataArgin.getType() + " not supported",
		    "CommandHelper.insertFromBoolean(Boolean value,deviceDataArgin)");
	    break;
	}
    }
334898
public int getType(final DeviceData deviceData) throws DevFailed {
        int type = Tango_DEV_VOID;
        boolean is_array = false;
        boolean is_struct = false;
        TypeCode tc = deviceData.getAny().type();
        TCKind kind;
        try {

            // Special case for state
            if (tc.kind().value()==TCKind._tk_enum) {
                return Tango_DEV_STATE;
            }

            // Check if struct
            if (tc.kind().value()==TCKind._tk_struct) {
                is_struct = true;
                // Get first element of struct
                tc = tc.member_type(0);
            }

            // Check if array
            if (tc.kind().value()==TCKind._tk_alias) {
                final TypeCode tc_alias = tc.content_type();
                if (tc_alias.kind().value()==TCKind._tk_sequence) {
                    final TypeCode tc_seq = tc_alias.content_type();
                    kind = tc_seq.kind();
                    is_array = true;
                } else {
                    kind = tc_alias.kind();
                }
            } else {
                kind = tc.kind();
            }

            // Set Tango type from TypeCode
            switch (kind.value()) {
                case TCKind._tk_void:
                    type = Tango_DEV_VOID;
                    break;

                case TCKind._tk_boolean:
                    if (is_array) {
                        type = Tango_DEVVAR_BOOLEANARRAY;
                    }
                    else {
                        type = Tango_DEV_BOOLEAN;
                    }
                    break;

                case TCKind._tk_char:
                case TCKind._tk_octet:
                    if (is_array) {
                        type = Tango_DEVVAR_CHARARRAY;
                    } else {
                        type = Tango_DEV_CHAR;
                    }
                    break;

                case TCKind._tk_short:
                    if (is_array) {
                        type = Tango_DEVVAR_SHORTARRAY;
                    } else {
                        type = Tango_DEV_SHORT;
                    }
                    break;

                case TCKind._tk_ushort:
                    if (is_array) {
                        type = Tango_DEVVAR_USHORTARRAY;
                    } else {
                        type = Tango_DEV_USHORT;
                    }
                    break;

                case TCKind._tk_long:
                    if (is_struct) {
                        type = Tango_DEVVAR_LONGSTRINGARRAY;
                    } else if (is_array) {
                        type = Tango_DEVVAR_LONGARRAY;
                    } else {
                        type = Tango_DEV_LONG;
                    }
                    break;

                case TCKind._tk_ulong:
                    if (is_array) {
                        type = Tango_DEVVAR_ULONGARRAY;
                    } else {
                        type = Tango_DEV_ULONG;
                    }
                    break;

                case TCKind._tk_longlong:
                    if (is_array) {
                        type = Tango_DEVVAR_LONG64ARRAY;
                    } else {
                        type = Tango_DEV_LONG64;
                    }
                    break;

                case TCKind._tk_ulonglong:
                    if (is_array) {
                        type = Tango_DEVVAR_ULONG64ARRAY;
                    } else {
                        type = Tango_DEV_ULONG64;
                    }
                    break;

                case TCKind._tk_float:
                    if (is_array) {
                        type = Tango_DEVVAR_FLOATARRAY;
                    } else {
                        type = Tango_DEV_FLOAT;
                    }
                    break;

                case TCKind._tk_double:
                    if (is_struct) {
                        type = Tango_DEVVAR_DOUBLESTRINGARRAY;
                    } else if (is_array) {
                        type = Tango_DEVVAR_DOUBLEARRAY;
                    } else {
                        type = Tango_DEV_DOUBLE;
                    }
                    break;

                case TCKind._tk_string:
                    if (is_array) {
                        type = Tango_DEVVAR_STRINGARRAY;
                    } else {
                        type = Tango_DEV_STRING;
                    }
                    break;
            }
        } catch (final org.omg.CORBA.TypeCodePackage.BadKind e) {
            // e.printStackTrace();
            Except.throw_exception("Api_TypeCodePackage.BadKind", "Bad or unknown type ",
                    "DeviceAttribute.getType()");
        } catch (final org.omg.CORBA.TypeCodePackage.Bounds e) {
            Except.throw_exception("Api_TypeCodePackage.BadKind", "Bad or unknown type ",
                    "DeviceAttribute.getType()");
        }
        return type;
    }
549664
public void insert(final Object... value) throws DevFailed {
        if (value.length == 1) {
            for (int i = 0; i < group.get_size(true); i++) {
                final int arginType = group.get_device(i + 1).command_query(commandName).in_type;
                InsertExtractUtils.insert(inData[i], arginType, value);
            }
        } else {
            if (value.length != group.get_size(true)) {
                throw DevFailedUtils.newDevFailed(TANGO_WRONG_DATA_ERROR, group.get_size(true) + " values must be provided");
            }
            for (int i = 0; i < group.get_size(true); i++) {
                final int arginType = group.get_device(i + 1).command_query(commandName).in_type;
                InsertExtractUtils.insert(inData[i], arginType, value[i]);
            }
        }
    }
152162
public static void set_value(final Object value, final Attribute attribute) throws DevFailed {
	try {

	    if (value instanceof Short) {
		attribute.set_value(((Short) value).shortValue());
	    } else if (value instanceof Byte) {
		attribute.set_value(((Byte) value).shortValue());
	    } else if (value instanceof String) {
		attribute.set_value((String) value);
	    } else if (value instanceof Integer) {
		attribute.set_value(((Integer) value).intValue());
	    } else if (value instanceof Long) {
		attribute.set_value(((Long) value).longValue());
	    } else if (value instanceof Float) {
		attribute.set_value(((Float) value).doubleValue());
	    } else if (value instanceof Boolean) {
		attribute.set_value(((Boolean) value).booleanValue());
	    } else if (value instanceof Double) {
		attribute.set_value(((Double) value).doubleValue());
	    } else if (value instanceof DevState) {
		attribute.set_value((DevState) value);
	    } else {
		// System.out.println(value.getClass().getName());
		Except.throw_exception("TANGO_WRONG_DATA_ERROR", "input type " + value.getClass()
			+ " not supported",
			"AttributeHelper.insert(Object value,deviceAttributeWritten)");
	    }
	} catch (final Exception e) {
	    e.printStackTrace();
	}
    }
1248438
public static AttrValUnion set(final int tangoType, final Object value) throws DevFailed {
        final AttributeDataType discriminator = AttributeTangoType.getTypeFromTango(tangoType).getAttributeDataType();
        final AttrValUnion union = new AttrValUnion();
        Object array = null;
        if (value.getClass().isArray()) {
            // convert to array of primitives if necessary
            array = org.tango.utils.ArrayUtils.toPrimitiveArray(value);
        } else {
            // put in an array before inserting for scalars
            array = Array.newInstance(AttributeTangoType.getTypeFromTango(tangoType).getType(), 1);
            try {
                Array.set(array, 0, value);
            } catch (final IllegalArgumentException e) {
                throw DevFailedUtils.newDevFailed(ExceptionMessages.ATTR_OPT_PROP, value.getClass().getCanonicalName()
                        + " is not of the good type");
            }
        }
        try {
            final Method method = union.getClass().getMethod(METHOD_MAP.get(discriminator),
                    PARAM_MAP.get(discriminator));
            method.invoke(union, array);
        } catch (final IllegalArgumentException e) {
            throw DevFailedUtils.newDevFailed(ExceptionMessages.ATTR_OPT_PROP, value.getClass().getCanonicalName()
                    + " is not of the good type");
        } catch (final IllegalAccessException e) {
            throw DevFailedUtils.newDevFailed(e);
        } catch (final InvocationTargetException e) {
            throw DevFailedUtils.newDevFailed(e.getCause());
        } catch (final SecurityException e) {
            throw DevFailedUtils.newDevFailed(e);
        } catch (final NoSuchMethodException e) {
            throw DevFailedUtils.newDevFailed(e);
        }
        return union;
    }
872225
protected void logIncompatibleValueError(PropertyIdValue propertyIdValue,
			String datatype, String valueType) {
		logger.warn("Property " + propertyIdValue.getId() + " has type \""
				+ datatype + "\" but a value of type " + valueType
				+ ". Data ignored.");
	}
1357221
public void write(final Object value) throws DevFailed {
        initDeviceAttributes();

        for (final DeviceAttribute deviceAttribute : deviceAttributes) {
            if (deviceAttribute != null) {
                // may be null if read failed and throwExceptions is false
                InsertExtractUtils.insert(deviceAttribute, value);
            }
        }
        group.write(deviceAttributes);
    }
1000705
public void put_device_attribute_property(Database database, String deviceName, DbAttribute[] attr)
            throws DevFailed {
        if (!database.isAccess_checked()) checkAccess(database);

        DeviceData argIn = new DeviceData();
        try {
            //	value is an array
            argIn.insert(ApiUtil.toStringArray(deviceName, attr, 2));
            command_inout(database, "DbPutDeviceAttributeProperty2", argIn);
        } catch (DevFailed e) {
            if (e.errors[0].reason.equals("API_CommandNotFound")) {
                //	Value is just one element
                argIn.insert(ApiUtil.toStringArray(deviceName, attr, 1));
                command_inout(database, "DbPutDeviceAttributeProperty", argIn);
            } else
                throw e;
        }
    }
513222
public void insert(final DeviceData deviceData, final DevState argin) {
        DevStateHelper.insert(deviceData.getAny(), argin);
    }
75263
public static Integer extractToInteger(final DeviceAttribute deviceAttributeRead)
	    throws DevFailed {
	final Object value = AttributeHelper.extract(deviceAttributeRead);
	Integer argout = null;
	if (value instanceof Short) {
	    argout = Integer.valueOf(((Short) value).intValue());
	} else if (value instanceof String) {
	    try {
		argout = Integer.valueOf((String) value);
	    } catch (final Exception e) {
		Except.throw_exception("TANGO_WRONG_DATA_ERROR", "output type " + value
			+ " is not a numerical",
			"AttributeHelper.extractToInteger(deviceAttributeWritten)");
	    }
	} else if (value instanceof Integer) {
	    argout = (Integer) value;
	} else if (value instanceof Long) {
	    argout = Integer.valueOf(((Long) value).intValue());
	} else if (value instanceof Float) {
	    argout = Integer.valueOf(((Float) value).intValue());
	} else if (value instanceof Boolean) {
	    if (((Boolean) value).booleanValue()) {
		argout = Integer.valueOf(1);
	    } else {
		argout = Integer.valueOf(0);
	    }
	} else if (value instanceof Double) {
	    argout = Integer.valueOf(((Double) value).intValue());
	} else if (value instanceof DevState) {
	    argout = Integer.valueOf(((DevState) value).value());
	} else {
	    Except.throw_exception("TANGO_WRONG_DATA_ERROR", "output type " + value.getClass()
		    + " not supported",
		    "AttributeHelper.extractToInteger(Object value,deviceAttributeWritten)");
	}

	return argout;
    }
488386
public void insert(final Object value) throws DevFailed {
        logger.debug(LOG_INSERTING, this);
        attributeImpl.insert(value);
    }
1014604
@SuppressWarnings("unchecked")
    public static <T> T castToType(final Class<T> type, final Object val) throws DevFailed {

	T result;
	if (val == null) {
	    result = null;
	} else if (type.isAssignableFrom(val.getClass())) {
	    result = (T) val;
	} else {
	    LOGGER.debug("converting {} to {}", val.getClass().getCanonicalName(), type.getCanonicalName());
	    // if input is not an array and we want to convert it to an array.
	    // Put
	    // the value in an array
	    Object array = val;
	    if (!val.getClass().isArray() && type.isArray()) {
		array = Array.newInstance(val.getClass(), 1);
		Array.set(array, 0, val);
	    }
	    final Transmorph transmorph = new Transmorph(creatConv());
	    try {
		result = transmorph.convert(array, type);
	    } catch (final ConverterException e) {
		LOGGER.error("convertion error", e);
		throw DevFailedUtils.newDevFailed(e);
	    }
	}
	return result;
    }
476613
public AttributeValue_3 getAttributeValueObject_3() throws DevFailed {
		// Build a DeviceAttribute_3 from this
		final DeviceAttribute_3 att = new DeviceAttribute_3();
		att.setAttributeValue(this);
		// And return the AttributeValue_3 object
		return att.getAttributeValueObject_3();
    }
887601
public static void insertFromArray(final Object[] values, final DeviceData deviceDataArgin,
	    final int dataType) throws DevFailed {
	if (values.length > 0) {
	    final Object firstValue = values[0];
	    if (firstValue instanceof Short) {
		final short[] tmpValues = new short[values.length];
		for (int i = 0; i < tmpValues.length; i++) {
		    tmpValues[i] = ((Short) values[i]).shortValue();
		}
		CommandHelper.insertFromShortArray(tmpValues, deviceDataArgin, dataType);
	    } else if (firstValue instanceof String) {
		final String[] tmpValues = new String[values.length];
		for (int i = 0; i < tmpValues.length; i++) {
		    tmpValues[i] = (String) values[i];
		}
		CommandHelper.insertFromStringArray(tmpValues, deviceDataArgin, dataType);
	    } else if (firstValue instanceof Integer) {
		final int[] tmpValues = new int[values.length];
		for (int i = 0; i < tmpValues.length; i++) {
		    tmpValues[i] = ((Integer) values[i]).intValue();
		}
		CommandHelper.insertFromIntegerArray(tmpValues, deviceDataArgin, dataType);
	    } else if (firstValue instanceof Long) {
		final long[] tmpValues = new long[values.length];
		for (int i = 0; i < tmpValues.length; i++) {
		    tmpValues[i] = ((Long) values[i]).intValue();
		}
		CommandHelper.insertFromLongArray(tmpValues, deviceDataArgin, dataType);
	    } else if (firstValue instanceof Float) {
		final float[] tmpValues = new float[values.length];
		for (int i = 0; i < tmpValues.length; i++) {
		    tmpValues[i] = ((Float) values[i]).floatValue();
		}
		CommandHelper.insertFromFloatArray(tmpValues, deviceDataArgin, dataType);
	    } else if (firstValue instanceof Byte) {
		final byte[] tmpValues = new byte[values.length];
		for (int i = 0; i < tmpValues.length; i++) {
		    tmpValues[i] = ((Byte) values[i]).byteValue();
		}
		CommandHelper.insertFromByteArray(tmpValues, deviceDataArgin, dataType);
	    } else if (firstValue instanceof Boolean) {
		final boolean[] tmpValues = new boolean[values.length];
		for (int i = 0; i < tmpValues.length; i++) {
		    tmpValues[i] = ((Boolean) values[i]).booleanValue();
		}

		CommandHelper.insertFromBooleanArray(tmpValues, deviceDataArgin, dataType);
	    } else if (firstValue instanceof Double) {
		final double[] tmpValues = new double[values.length];
		for (int i = 0; i < tmpValues.length; i++) {
		    tmpValues[i] = ((Double) values[i]).doubleValue();
		}

		CommandHelper.insertFromDoubleArray(tmpValues, deviceDataArgin, dataType);
	    }
	}
    }
12908
public static void insertFromShortArray(final short[] shortValues,
	    final DeviceData deviceDataArgin, final int dataType) throws DevFailed {
	// by default for xdim = 1, send the sum.
	Double doubleSum = new Double(0);
	for (final short shortValue : shortValues) {
	    doubleSum = doubleSum + shortValue;
	}

	switch (dataType) {
	case TangoConst.Tango_DEV_SHORT:
	    deviceDataArgin.insert(doubleSum.shortValue());
	    break;
	case TangoConst.Tango_DEV_USHORT:
	    deviceDataArgin.insert_us(doubleSum.intValue());
	    break;
	case TangoConst.Tango_DEV_CHAR:
	    Except.throw_exception("TANGO_WRONG_DATA_ERROR",
		    "input type Tango_DEV_CHAR not supported",
		    "CommandHelper.insertFromShortArray(short[] values,deviceDataArgin)");
	    break;
	case TangoConst.Tango_DEV_UCHAR:
	    deviceDataArgin.insert(doubleSum.shortValue());
	    break;
	case TangoConst.Tango_DEV_LONG:
	    deviceDataArgin.insert(doubleSum.intValue());
	    break;
	case TangoConst.Tango_DEV_ULONG:
	    deviceDataArgin.insert_ul(doubleSum.longValue());
	    break;
	case TangoConst.Tango_DEV_LONG64:
	    deviceDataArgin.insert(doubleSum.intValue());
	    break;
	case TangoConst.Tango_DEV_ULONG64:
	    deviceDataArgin.insert_u64(doubleSum.longValue());
	    break;
	case TangoConst.Tango_DEV_INT:
	    deviceDataArgin.insert(doubleSum.intValue());
	    break;
	case TangoConst.Tango_DEV_FLOAT:
	    deviceDataArgin.insert(doubleSum.floatValue());
	    break;
	case TangoConst.Tango_DEV_DOUBLE:
	    deviceDataArgin.insert(doubleSum.doubleValue());
	    break;
	case TangoConst.Tango_DEV_STRING:
	    deviceDataArgin.insert(doubleSum.toString());
	    break;
	case TangoConst.Tango_DEV_BOOLEAN:
	    if (doubleSum.doubleValue() == 1) {
		deviceDataArgin.insert(true);
	    } else {
		deviceDataArgin.insert(false);
	    }
	    break;
	case TangoConst.Tango_DEV_STATE:
	    DevState devStateValue = DevState.UNKNOWN;
	    if (shortValues.length > 0) {
		try {
		    devStateValue = DevState.from_int(Short.valueOf(shortValues[0]).intValue());
		} catch (final org.omg.CORBA.BAD_PARAM badParam) {
		    devStateValue = DevState.UNKNOWN;
		}
	    }
	    deviceDataArgin.insert(devStateValue);
	    break;

	// Array input type
	case TangoConst.Tango_DEVVAR_SHORTARRAY:
	    deviceDataArgin.insert(shortValues);
	    break;
	case TangoConst.Tango_DEVVAR_USHORTARRAY:
	    deviceDataArgin.insert_us(shortValues);
	    break;
	case TangoConst.Tango_DEVVAR_CHARARRAY:
	    final byte[] byteValues = new byte[shortValues.length];
	    for (int i = 0; i < shortValues.length; i++) {
		byteValues[i] = Short.valueOf(shortValues[i]).byteValue();
	    }
	    deviceDataArgin.insert(byteValues);
	    break;
	case TangoConst.Tango_DEVVAR_LONGARRAY:
	    final int[] longValues = new int[shortValues.length];
	    for (int i = 0; i < shortValues.length; i++) {
		longValues[i] = Short.valueOf(shortValues[i]).intValue();
	    }
	    deviceDataArgin.insert(longValues);
	    break;
	case TangoConst.Tango_DEVVAR_ULONGARRAY:
	    final long[] ulongValues = new long[shortValues.length];
	    for (int i = 0; i < shortValues.length; i++) {
		ulongValues[i] = Short.valueOf(shortValues[i]).longValue();
	    }
	    deviceDataArgin.insert_ul(ulongValues);
	    break;
	case TangoConst.Tango_DEVVAR_LONG64ARRAY:
	    final int[] long64Values = new int[shortValues.length];
	    for (int i = 0; i < shortValues.length; i++) {
		long64Values[i] = Short.valueOf(shortValues[i]).intValue();
	    }
	    deviceDataArgin.insert(long64Values);
	    break;
	case TangoConst.Tango_DEVVAR_ULONG64ARRAY:
	    final long[] uLong64Values = new long[shortValues.length];
	    for (int i = 0; i < shortValues.length; i++) {
		uLong64Values[i] = Short.valueOf(shortValues[i]).longValue();
	    }
	    deviceDataArgin.insert_u64(uLong64Values);
	    break;
	case TangoConst.Tango_DEVVAR_FLOATARRAY:
	    final float[] floatValues = new float[shortValues.length];
	    for (int i = 0; i < shortValues.length; i++) {
		floatValues[i] = Short.valueOf(shortValues[i]).floatValue();
	    }
	    deviceDataArgin.insert(floatValues);
	    break;
	case TangoConst.Tango_DEVVAR_DOUBLEARRAY:
	    final double[] doubleValues = new double[shortValues.length];
	    for (int i = 0; i < shortValues.length; i++) {
		doubleValues[i] = Short.valueOf(shortValues[i]).doubleValue();
	    }
	    deviceDataArgin.insert(doubleValues);
	    break;
	case TangoConst.Tango_DEVVAR_STRINGARRAY:
	    final String[] stringValues = new String[shortValues.length];
	    for (int i = 0; i < shortValues.length; i++) {
		stringValues[i] = Short.valueOf(shortValues[i]).toString();
	    }
	    deviceDataArgin.insert(stringValues);
	    break;

	default:
	    Except.throw_exception("TANGO_WRONG_DATA_ERROR", "input type "
		    + deviceDataArgin.getType() + " not supported",
		    "CommandHelper.insertFromShortArray(short[] values,deviceDataArgin)");
	    break;
	}
    }
569942
public void delete_device_attribute(String devname, String attname) throws DevFailed {
		databaseDAO.delete_device_attribute(this, devname, attname);
	}
828417
protected void pushAttributeDataReadyEvent(final int counter, ZMQ.Socket eventSocket)
            throws DevFailed {
        xlogger.entry();
        try {
            final AttDataReady dataReady = new AttDataReady(attribute.getName(), attribute.getTangoType(), counter);
            synchronized (eventSocket) {
                EventUtilities.sendToSocket(eventSocket, fullName, counter, EventUtilities.marshall(dataReady));
            }
        } catch (final org.zeromq.ZMQException e) {
            throw DevFailedUtils.newDevFailed(e);
        }

        xlogger.exit();
    }